Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(6_1_X) [TIMOB-24796] iOS: Hybrid CommonJS and Native modules don't handl… #9132

Merged
merged 4 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion iphone/Classes/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ - (TiModule *)loadCoreModule:(NSString *)path withContext:(KrollContext *)kroll
- (NSString *)loadFile:(NSString *)path
{
NSURL *url_ = [NSURL URLWithString:path relativeToURL:[[self host] baseURL]];
NSData *data = [TiUtils loadAppResource:url_];
NSData *data = [TiUtils loadAppResource:url_]; // try to load encrypted file

if (data == nil) {
data = [NSData dataWithContentsOfURL:url_];
Expand Down
31 changes: 19 additions & 12 deletions iphone/Classes/TiModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ -(void)unregisterForNotifications
}

-(void)dealloc
{
{
// Have to jump through a hoop here to keep the dealloc block from
// retaining 'self' by creating a __block access ref. Note that
// this is only safe as long as the block until completion is YES.
__block id bself = self;
TiThreadPerformOnMainThread(^{
[bself unregisterForNotifications];
}, YES);

RELEASE_TO_NIL(host);
if (classNameLookup != NULL)
{
Expand Down Expand Up @@ -139,7 +139,7 @@ -(id)createProxy:(NSArray*)args forName:(NSString*)name context:(id<TiEvaluator>
{
return nil;
}

// this is a magic check to see if we're inside a compiled code or not
// and if so, drop the prefix
NSString *prefix = @"Ti";
Expand All @@ -148,23 +148,23 @@ -(id)createProxy:(NSArray*)args forName:(NSString*)name context:(id<TiEvaluator>
{
moduleName_ = [NSString stringWithCString:class_getName([self class]) encoding:NSUTF8StringEncoding];
}
else
else
{
// this is only set in the case of a Plus Module
moduleName_ = moduleName;
prefix = @"";
}
moduleName_ = [moduleName_ stringByReplacingOccurrencesOfString:@"Module" withString:@""];
NSString *className = [NSString stringWithFormat:@"%@%@%@Proxy",prefix,moduleName_,[name substringFromIndex:range.location+6]];
NSString *className = [NSString stringWithFormat:@"%@%@%@Proxy",prefix,moduleName_,[name substringFromIndex:range.location+6]];
resultClass = NSClassFromString(className);
if (resultClass==nil)
{
DebugLog(@"[WARN] Attempted to load %@: Could not find class definition.",className);
@throw [NSException exceptionWithName:@"org.appcelerator.module"
reason:[NSString stringWithFormat:@"invalid method (%@) passed to %@",name,[self class]]
@throw [NSException exceptionWithName:@"org.appcelerator.module"
reason:[NSString stringWithFormat:@"invalid method (%@) passed to %@",name,[self class]]
userInfo:nil];
}
CFDictionarySetValue(classNameLookup, name, resultClass);
CFDictionarySetValue(classNameLookup, name, resultClass);
}

return [[[resultClass alloc] _initWithPageContext:context args:args] autorelease];
Expand All @@ -187,13 +187,13 @@ -(void)loadAssets
{
moduleAssets = [[cls alloc] init];
}
}
}
}

-(NSData*)moduleJS
{
[self loadAssets];

if (moduleAssets!=nil)
{
return [moduleAssets performSelector:@selector(moduleAsset)];
Expand All @@ -205,6 +205,13 @@ -(NSData*)loadModuleAsset:(NSString*)fromPath
{
[self loadAssets];
if ([moduleAssets respondsToSelector:@selector(resolveModuleAsset:)]) {
// Look up the file by it's original name. We preserve the filename in our Node-js based module build
NSData* data = [moduleAssets performSelector:@selector(resolveModuleAsset:) withObject:fromPath];
if (data != nil) {
return data;
}
// FIXME Remove once we no longer support modules built by the old python code!
// This tries to load the "mangled" filename generated by our old module build encryption and minification process!
NSString* assetID = [fromPath stringByReplacingOccurrencesOfString:@"." withString:@"_"];
return [moduleAssets performSelector:@selector(resolveModuleAsset:) withObject:assetID];
}
Expand All @@ -217,7 +224,7 @@ -(BOOL)isJSModule
if (moduleId!=nil)
{
// if we have module js than we're a JS native module
return [self moduleJS]!=nil;
return [self moduleJS]!=nil;
}
return NO;
}
Expand All @@ -232,7 +239,7 @@ -(NSURL*)moduleResourceURL:(NSString*)name
-(id)bindCommonJSModule:(NSString*)code
{
NSString *js = [[NSString alloc] initWithFormat:TitaniumModuleRequireFormat,code];

id result = [[self pageContext] evalJSAndWait:js];
[js release];
if ([result isKindOfClass:[NSDictionary class]])
Expand Down