Skip to content

Commit

Permalink
fix(ios): hyperloop defineClass() crash
Browse files Browse the repository at this point in the history
Fixes TIMOB-28458
  • Loading branch information
jquick-axway authored and ewanharris committed Jun 17, 2021
1 parent a07c56c commit 90aec65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/Resources/ti.internal/extensions/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function isHijackableModuleId(path) {
return firstChar !== '.' && firstChar !== '/';
}

// Hack require to point to this as a core module "binding"
const originalRequire = global.require;
// Hack require to point to this as core module "binding". (Note that iOS does not have a global require.)
const originalRequire = global.require ? global.require : require;
// This works for Windows as-is, and also intercepts the call on Android/iOS for ti.main.js (the first file executed)
global.require = function (moduleId) {

Expand Down
19 changes: 19 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,25 @@ - (id)krollObjectForProxy:(id)proxy
return result;
}

- (id)require:(KrollContext *)kroll path:(NSString *)path
{
if (!kroll || !path) {
return nil;
}

JSContext *jsContext = [JSContext contextWithJSGlobalContextRef:kroll.context];
JSValue *jsResult = [jsContext.globalObject invokeMethod:@"require" withArguments:@[ path ]];
if (![jsResult isObject]) {
return nil;
}

KrollWrapper *krollResult = [[KrollWrapper alloc] init];
[krollResult setBridge:self];
[krollResult setJsobject:(JSObjectRef)[jsResult JSValueRef]];
[krollResult protectJsobject];
return [krollResult autorelease];
}

+ (NSArray *)krollBridgesUsingProxy:(id)proxy
{
NSMutableArray *results = nil;
Expand Down

0 comments on commit 90aec65

Please sign in to comment.