提问人:lukehuang 提问时间:4/14/2023 更新时间:4/14/2023 访问量:26
iOS JSC 捕获的 js 异常不完整
The js exception caught by iOS JSC is incomplete
问:
我在 iOS 上使用 JSContext#exceptionHandler 来捕获 JS 异常,但生成的堆栈似乎不完整。
OC代码:
NSString * path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"js"];
NSData * jsData = [[NSData alloc]initWithContentsOfFile:path];
NSString * jsCode = [[NSString alloc]initWithData:jsData encoding:NSUTF8StringEncoding];
self.jsContext = [[JSContext alloc]init];
self.jsContext.exceptionHandler = ^(JSContext *context, JSValue *exception) {
NSString *message = [NSString stringWithFormat:@"[exception msg]:%@", exception];
JSValue *stackTrace = [exception valueForProperty:@"stack"];
NSString *stackTraceStr = [stackTrace toString];
NSLog(@"[JS Exception]:%@", message);
NSLog(@"[JS Exception]:%@",stackTraceStr);
};
[self.jsContext evaluateScript:jsCode];
test.js代码:
(function(){
throw new Error('test');
})();
控制台输出堆栈:
2023-04-14 17:17:26.636593+0800 iosApp[24509:6788200] [JS Exception]:[exception msg]:Error: test
2023-04-14 17:17:26.636686+0800 iosApp[24509:6788200] [JS Exception]:@
global code@
有没有办法输出完整的JS堆栈信息?
答: 暂无答案
评论