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

(2_1_X)[TIMOB-10501] iOS: Improve source error logging for CommonJS code #2964

Merged
merged 2 commits into from
Sep 15, 2012
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
6 changes: 3 additions & 3 deletions iphone/Classes/KrollBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,15 @@ - (id)krollObjectForProxy:(id)proxy
return result;
}

-(id)loadCommonJSModule:(NSString*)code withPath:(NSString*)path
-(id)loadCommonJSModule:(NSString*)code withSourceURL:(NSURL *)sourceURL
{
NSString *js = [[NSString alloc] initWithFormat:TitaniumModuleRequireFormat,code];

/* This most likely should be integrated with normal code flow, but to
* minimize impact until a in-depth reconsideration of KrollContext can be
* done, we should have as little footprint
*/
KrollEval *eval = [[KrollEval alloc] initWithCode:js];
KrollEval *eval = [[KrollEval alloc] initWithCode:js sourceURL:sourceURL startingLineNo:1];
TiValueRef exception = NULL;
TiValueRef resultRef = [eval jsInvokeInContext:context exception:&exception];
[js release];
Expand Down Expand Up @@ -832,7 +832,7 @@ -(id)require:(KrollContext*)kroll path:(NSString*)path
}

NSString * dataContents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
wrapper = [self loadCommonJSModule:dataContents withPath:path];
wrapper = [self loadCommonJSModule:dataContents withSourceURL:url_];
[dataContents release];

if ([[self host] debugMode] && ![module isJSModule]) {
Expand Down
4 changes: 4 additions & 0 deletions iphone/Classes/KrollContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@
@interface KrollEval : NSObject {
@private
NSString *code;
NSURL *sourceURL;
NSInteger startingLineNo;
}
-(id)initWithCode:(NSString*)code;
-(id)initWithCode:(NSString*)code sourceURL:(NSURL *)sourceURL;
-(id)initWithCode:(NSString*)code sourceURL:(NSURL *)sourceURL startingLineNo:(NSInteger)startingLineNo;
-(TiValueRef) jsInvokeInContext: (KrollContext*)context exception: (TiValueRef *)exceptionPointer;
-(void)invoke:(KrollContext*)context;
-(id)invokeWithResult:(KrollContext*)context;
Expand Down
35 changes: 28 additions & 7 deletions iphone/Classes/KrollContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -563,27 +563,48 @@ @implementation KrollEval

-(id)initWithCode:(NSString*)code_
{
if (self = [super init])
{
return [self initWithCode:code_ sourceURL:nil];
}

- (id)initWithCode:(NSString *)code_ sourceURL:(NSURL *)sourceURL_
{
return [self initWithCode:code_ sourceURL:sourceURL_ startingLineNo:1];
}

- (id)initWithCode:(NSString *)code_ sourceURL:(NSURL *)sourceURL_ startingLineNo:(NSInteger)startingLineNo_
{
self = [super init];
if (self) {
code = [code_ copy];
}
return self;
sourceURL = [sourceURL_ copy];
startingLineNo = startingLineNo_;
}
return self;
}

-(void)dealloc
{
[code release];
[sourceURL release];
[super dealloc];
}

-(TiValueRef) jsInvokeInContext: (KrollContext*)context exception: (TiValueRef *)exceptionPointer
{
pthread_mutex_lock(&KrollEntryLock);
TiStringRef js = TiStringCreateWithCFString((CFStringRef) code);
TiStringRef jsCode = TiStringCreateWithCFString((CFStringRef) code);
TiStringRef jsURL = NULL;
if (sourceURL != nil) {
jsURL = TiStringCreateWithUTF8CString([[sourceURL absoluteString] UTF8String]);
}
TiObjectRef global = TiContextGetGlobalObject([context context]);

TiValueRef result = TiEvalScript([context context], js, global, NULL, 1, exceptionPointer);
TiValueRef result = TiEvalScript([context context], jsCode, global, jsURL, startingLineNo, exceptionPointer);

TiStringRelease(js);
TiStringRelease(jsCode);
if (jsURL != NULL) {
TiStringRelease(jsURL);
}
pthread_mutex_unlock(&KrollEntryLock);

return result;
Expand Down