feat:doric android and iOS's monitor add source parameter when exception
This commit is contained in:
parent
f65b116607
commit
abb1873b49
@ -73,13 +73,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
|||||||
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<JSDecoder>() {
|
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<JSDecoder>() {
|
||||||
@Override
|
@Override
|
||||||
public JSDecoder call() {
|
public JSDecoder call() {
|
||||||
try {
|
|
||||||
return doricJSEngine.invokeDoricMethod(method, args);
|
return doricJSEngine.invokeDoricMethod(method, args);
|
||||||
} catch (Exception e) {
|
|
||||||
doricJSEngine.getRegistry().onException(e);
|
|
||||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("invokeDoricMethod(%s,...),error is %s", method, e.getLocalizedMessage()));
|
|
||||||
return new JSDecoder(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -97,6 +91,14 @@ public class DoricNativeDriver implements IDoricDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String sourceWithContextId(String contextId) {
|
||||||
|
DoricContext context = DoricContextManager.getContext(contextId);
|
||||||
|
if (context == null) {
|
||||||
|
return "Unknown:" + contextId;
|
||||||
|
}
|
||||||
|
return context.getSource();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsyncResult<Boolean> createContext(final String contextId, final String script, final String source) {
|
public AsyncResult<Boolean> createContext(final String contextId, final String script, final String source) {
|
||||||
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
|
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
|
||||||
@ -106,7 +108,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
|||||||
doricJSEngine.prepareContext(contextId, script, source);
|
doricJSEngine.prepareContext(contextId, script, source);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
doricJSEngine.getRegistry().onException(e);
|
doricJSEngine.getRegistry().onException(sourceWithContextId(contextId), e);
|
||||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("createContext %s error is %s", source, e.getLocalizedMessage()));
|
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("createContext %s error is %s", source, e.getLocalizedMessage()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -123,7 +125,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
|||||||
doricJSEngine.destroyContext(contextId);
|
doricJSEngine.destroyContext(contextId);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
doricJSEngine.getRegistry().onException(e);
|
doricJSEngine.getRegistry().onException(sourceWithContextId(contextId), e);
|
||||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("destroyContext %s error is %s", contextId, e.getLocalizedMessage()));
|
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("destroyContext %s error is %s", contextId, e.getLocalizedMessage()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class DoricRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setEnvironmentVariabel(String key, Object val) {
|
public void setEnvironmentVariable(String key, Object val) {
|
||||||
extendedEnvValues.put(key, val);
|
extendedEnvValues.put(key, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,9 +157,9 @@ public class DoricRegistry {
|
|||||||
this.monitors.add(monitor);
|
this.monitors.add(monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onException(Exception e) {
|
public void onException(String source, Exception e) {
|
||||||
for (IDoricMonitor monitor : this.monitors) {
|
for (IDoricMonitor monitor : this.monitors) {
|
||||||
monitor.onException(e);
|
monitor.onException(source, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,11 @@ public interface IDoricMonitor {
|
|||||||
/**
|
/**
|
||||||
* Called when native or js exception occurred in doric
|
* Called when native or js exception occurred in doric
|
||||||
*
|
*
|
||||||
|
* @param source Which source file
|
||||||
* @param e exception which is thrown within doric sdk
|
* @param e exception which is thrown within doric sdk
|
||||||
* @see com.github.pengfeizhou.jscore.JSRuntimeException
|
* @see com.github.pengfeizhou.jscore.JSRuntimeException
|
||||||
*/
|
*/
|
||||||
void onException(Exception e);
|
void onException(String source, Exception e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type The priority/type of this log message.
|
* @param type The priority/type of this log message.
|
||||||
|
@ -34,6 +34,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import pub.doric.Doric;
|
import pub.doric.Doric;
|
||||||
|
import pub.doric.DoricContext;
|
||||||
|
import pub.doric.DoricContextManager;
|
||||||
import pub.doric.DoricRegistry;
|
import pub.doric.DoricRegistry;
|
||||||
import pub.doric.IDoricMonitor;
|
import pub.doric.IDoricMonitor;
|
||||||
import pub.doric.extension.bridge.DoricBridgeExtension;
|
import pub.doric.extension.bridge.DoricBridgeExtension;
|
||||||
@ -130,7 +132,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(e);
|
mDoricRegistry.onException("Log", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -154,7 +156,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
mDoricJSE.loadJS(packageModuleScript(name, content), "Module://" + name);
|
mDoricJSE.loadJS(packageModuleScript(name, content), "Module://" + name);
|
||||||
return new JavaValue(true);
|
return new JavaValue(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(e);
|
mDoricRegistry.onException("Require", e);
|
||||||
return new JavaValue(false);
|
return new JavaValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,7 +170,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
args[1].number().longValue(),
|
args[1].number().longValue(),
|
||||||
args[2].bool());
|
args[2].bool());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(e);
|
mDoricRegistry.onException("Timer", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -179,7 +181,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
try {
|
try {
|
||||||
mTimerExtension.clearTimer(args[0].number().longValue());
|
mTimerExtension.clearTimer(args[0].number().longValue());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(e);
|
mDoricRegistry.onException("Timer", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -187,6 +189,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_BRIDGE, new JavaFunction() {
|
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_BRIDGE, new JavaFunction() {
|
||||||
@Override
|
@Override
|
||||||
public JavaValue exec(JSDecoder[] args) {
|
public JavaValue exec(JSDecoder[] args) {
|
||||||
|
String source = "Unknown";
|
||||||
try {
|
try {
|
||||||
String contextId = args[0].string();
|
String contextId = args[0].string();
|
||||||
String module = args[1].string();
|
String module = args[1].string();
|
||||||
@ -195,7 +198,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
JSDecoder jsDecoder = args[4];
|
JSDecoder jsDecoder = args[4];
|
||||||
return mDoricBridgeExtension.callNative(contextId, module, method, callbackId, jsDecoder);
|
return mDoricBridgeExtension.callNative(contextId, module, method, callbackId, jsDecoder);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(e);
|
mDoricRegistry.onException("Bridge", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -209,7 +212,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB);
|
String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB);
|
||||||
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
|
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(e);
|
mDoricRegistry.onException("Init Environment", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +263,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
try {
|
try {
|
||||||
invokeDoricMethod(DoricConstant.DORIC_TIMER_CALLBACK, timerId);
|
invokeDoricMethod(DoricConstant.DORIC_TIMER_CALLBACK, timerId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mDoricRegistry.onException(e);
|
mDoricRegistry.onException("Timer", e);
|
||||||
mDoricRegistry.onLog(
|
mDoricRegistry.onLog(
|
||||||
Log.ERROR,
|
Log.ERROR,
|
||||||
String.format("Timer Callback error:%s", e.getLocalizedMessage()));
|
String.format("Timer Callback error:%s", e.getLocalizedMessage()));
|
||||||
@ -272,7 +275,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onException(Exception e) {
|
public void onException(String source, Exception e) {
|
||||||
|
Log.e(DoricJSEngine.class.getSimpleName(), "In source file: " + source);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,24 @@ public class DoricBridgeExtension {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
AsyncResult<JavaValue> asyncResult = context.getDriver().asyncCall(callable, doricMethod.thread());
|
AsyncResult<JavaValue> asyncResult = context.getDriver().asyncCall(callable, doricMethod.thread());
|
||||||
|
asyncResult.setCallback(new AsyncResult.Callback<JavaValue>() {
|
||||||
|
@Override
|
||||||
|
public void onResult(JavaValue result) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable t) {
|
||||||
|
context.getDriver().getRegistry().onException(
|
||||||
|
context.getSource(),
|
||||||
|
t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
if (asyncResult.hasResult()) {
|
if (asyncResult.hasResult()) {
|
||||||
return asyncResult.getResult();
|
return asyncResult.getResult();
|
||||||
}
|
}
|
||||||
@ -102,7 +120,7 @@ public class DoricBridgeExtension {
|
|||||||
try {
|
try {
|
||||||
return DoricUtils.toJavaObject(clz, jsDecoder);
|
return DoricUtils.toJavaObject(clz, jsDecoder);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
context.getDriver().getRegistry().onException(e);
|
context.getDriver().getRegistry().onException(context.getSource(), e);
|
||||||
context.getDriver().getRegistry().onLog(
|
context.getDriver().getRegistry().onLog(
|
||||||
Log.ERROR,
|
Log.ERROR,
|
||||||
String.format("createParam error:%s", e.getLocalizedMessage()));
|
String.format("createParam error:%s", e.getLocalizedMessage()));
|
||||||
|
@ -15,9 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package pub.doric.extension.bridge;
|
package pub.doric.extension.bridge;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
|
import pub.doric.async.AsyncResult;
|
||||||
import pub.doric.utils.DoricConstant;
|
import pub.doric.utils.DoricConstant;
|
||||||
|
|
||||||
|
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||||
import com.github.pengfeizhou.jscore.JavaValue;
|
import com.github.pengfeizhou.jscore.JavaValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,9 +43,26 @@ public class DoricPromise {
|
|||||||
params[0] = context.getContextId();
|
params[0] = context.getContextId();
|
||||||
params[1] = callbackId;
|
params[1] = callbackId;
|
||||||
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
||||||
context.getDriver().invokeDoricMethod(
|
context.getDriver()
|
||||||
|
.invokeDoricMethod(
|
||||||
DoricConstant.DORIC_BRIDGE_RESOLVE,
|
DoricConstant.DORIC_BRIDGE_RESOLVE,
|
||||||
params);
|
params)
|
||||||
|
.setCallback(new AsyncResult.Callback<JSDecoder>() {
|
||||||
|
@Override
|
||||||
|
public void onResult(JSDecoder result) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable t) {
|
||||||
|
context.getDriver().getRegistry().onException(context.getSource(), t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reject(JavaValue... javaValue) {
|
public void reject(JavaValue... javaValue) {
|
||||||
@ -49,8 +70,25 @@ public class DoricPromise {
|
|||||||
params[0] = context.getContextId();
|
params[0] = context.getContextId();
|
||||||
params[1] = callbackId;
|
params[1] = callbackId;
|
||||||
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
||||||
context.getDriver().invokeDoricMethod(
|
context.getDriver()
|
||||||
|
.invokeDoricMethod(
|
||||||
DoricConstant.DORIC_BRIDGE_REJECT,
|
DoricConstant.DORIC_BRIDGE_REJECT,
|
||||||
params);
|
params)
|
||||||
|
.setCallback(new AsyncResult.Callback<JSDecoder>() {
|
||||||
|
@Override
|
||||||
|
public void onResult(JSDecoder result) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable t) {
|
||||||
|
context.getDriver().getRegistry().onException(context.getSource(), t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,9 +78,9 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable t) {
|
public void onError(Throwable t) {
|
||||||
if (t instanceof Exception) {
|
getDoricContext().getDriver().getRegistry().onException(
|
||||||
getDoricContext().getDriver().getRegistry().onException((Exception) t);
|
getDoricContext().getSource(),
|
||||||
}
|
t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||||
getDoricContext().getDriver().getRegistry().onLog(
|
getDoricContext().getDriver().getRegistry().onLog(
|
||||||
Log.ERROR,
|
Log.ERROR,
|
||||||
String.format("Shader.render:error%s", t.getLocalizedMessage()));
|
String.format("Shader.render:error%s", t.getLocalizedMessage()));
|
||||||
@ -92,7 +92,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getDoricContext().getDriver().getRegistry().onException(e);
|
getDoricContext().getDriver().getRegistry().onException(getDoricContext().getSource(), e);
|
||||||
getDoricContext().getDriver().getRegistry().onLog(
|
getDoricContext().getDriver().getRegistry().onLog(
|
||||||
Log.ERROR,
|
Log.ERROR,
|
||||||
String.format("Shader.render:error%s", e.getLocalizedMessage())
|
String.format("Shader.render:error%s", e.getLocalizedMessage())
|
||||||
@ -173,7 +173,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ArchiveException e) {
|
} catch (ArchiveException e) {
|
||||||
getDoricContext().getDriver().getRegistry().onException(e);
|
getDoricContext().getDriver().getRegistry().onException(getDoricContext().getSource(), e);
|
||||||
}
|
}
|
||||||
return new JavaValue(true);
|
return new JavaValue(true);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
- (void)disconnectDevKit;
|
- (void)disconnectDevKit;
|
||||||
|
|
||||||
- (void)ensureSyncInMainQueue:(dispatch_block_t)block;
|
- (void)ensureSyncInMainQueue:(dispatch_block_t)block;
|
||||||
|
|
||||||
|
- (NSString *)aliasWithContextId:(NSString *)contextId;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#import "DoricJSEngine.h"
|
#import "DoricJSEngine.h"
|
||||||
#import "DoricConstant.h"
|
#import "DoricConstant.h"
|
||||||
#import "DoricWSClient.h"
|
#import "DoricWSClient.h"
|
||||||
|
#import "DoricContextManager.h"
|
||||||
|
|
||||||
@interface DoricDriver ()
|
@interface DoricDriver ()
|
||||||
@property(nonatomic, strong) DoricJSEngine *jsExecutor;
|
@property(nonatomic, strong) DoricJSEngine *jsExecutor;
|
||||||
@ -62,6 +63,10 @@ + (instancetype)instance {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)aliasWithContextId:(NSString *)contextId {
|
||||||
|
return [[DoricContextManager instance] getContext:contextId].source;
|
||||||
|
}
|
||||||
|
|
||||||
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
|
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
|
||||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||||
@ -78,7 +83,6 @@ + (instancetype)instance {
|
|||||||
[ret setupResult:jsValue];
|
[ret setupResult:jsValue];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
[ret setupError:exception];
|
[ret setupError:exception];
|
||||||
[self.jsExecutor.registry onException:exception];
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
@ -111,7 +115,7 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
|
|||||||
[ret setupResult:jsValue];
|
[ret setupResult:jsValue];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
[ret setupError:exception];
|
[ret setupError:exception];
|
||||||
[self.jsExecutor.registry onException:exception];
|
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
@ -134,7 +138,7 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
|
|||||||
[ret setupResult:jsValue];
|
[ret setupResult:jsValue];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
[ret setupError:exception];
|
[ret setupError:exception];
|
||||||
[self.jsExecutor.registry onException:exception];
|
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
@ -151,7 +155,7 @@ - (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)scr
|
|||||||
[ret setupResult:@YES];
|
[ret setupResult:@YES];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
[ret setupError:exception];
|
[ret setupError:exception];
|
||||||
[self.jsExecutor.registry onException:exception];
|
[self.jsExecutor.registry onException:exception source:source];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
@ -168,7 +172,7 @@ - (DoricAsyncResult *)destroyContext:(NSString *)contextId {
|
|||||||
[ret setupResult:@YES];
|
[ret setupResult:@YES];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
[ret setupError:exception];
|
[ret setupError:exception];
|
||||||
[self.jsExecutor.registry onException:exception];
|
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -11,7 +11,17 @@ typedef NS_ENUM(NSInteger, DoricLogType) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@protocol DoricMonitorProtocol <NSObject>
|
@protocol DoricMonitorProtocol <NSObject>
|
||||||
- (void)onException:(NSException *)exception;
|
/**
|
||||||
|
* Called when native or js exception occurred in doric
|
||||||
|
*
|
||||||
|
* @param source Which source file
|
||||||
|
* @param e exception which is thrown within doric sdk
|
||||||
|
*/
|
||||||
|
- (void)onException:(NSException *)exception source:(NSString *)source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type The priority/type of this log message.
|
||||||
|
* @param message The message you would like logged.
|
||||||
|
*/
|
||||||
- (void)onLog:(DoricLogType)type message:(NSString *)message;
|
- (void)onLog:(DoricLogType)type message:(NSString *)message;
|
||||||
@end
|
@end
|
@ -80,8 +80,8 @@ @interface DoricDefaultMonitor : NSObject <DoricMonitorProtocol>
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricDefaultMonitor
|
@implementation DoricDefaultMonitor
|
||||||
- (void)onException:(NSException *)exception {
|
- (void)onException:(NSException *)exception source:(NSString *)source {
|
||||||
DoricLog(@"DefaultMonitor - onException - %@", exception.reason);
|
DoricLog(@"DefaultMonitor - source: %@- onException - %@", source, exception.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onLog:(DoricLogType)type message:(NSString *)message {
|
- (void)onLog:(DoricLogType)type message:(NSString *)message {
|
||||||
@ -187,9 +187,9 @@ - (void)registerMonitor:(id <DoricMonitorProtocol>)monitor {
|
|||||||
[self.monitors addObject:monitor];
|
[self.monitors addObject:monitor];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onException:(NSException *)exception {
|
- (void)onException:(NSException *)exception source:(NSString *)source {
|
||||||
for (id <DoricMonitorProtocol> monitor in self.monitors) {
|
for (id <DoricMonitorProtocol> monitor in self.monitors) {
|
||||||
[monitor onException:exception];
|
[monitor onException:exception source:source];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ - (void)initDoricEnvironment {
|
|||||||
[self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
|
[self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
|
||||||
source:[@"Module://" stringByAppendingString:DORIC_MODULE_LIB]];
|
source:[@"Module://" stringByAppendingString:DORIC_MODULE_LIB]];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
[self.registry onException:exception];
|
[self.registry onException:exception source:@"InitEnvironment"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ - (void)callbackTimer:(NSTimer *)timer {
|
|||||||
@try {
|
@try {
|
||||||
[self invokeDoricMethod:DORIC_TIMER_CALLBACK, timerId, nil];
|
[self invokeDoricMethod:DORIC_TIMER_CALLBACK, timerId, nil];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
[self.registry onException:exception];
|
[self.registry onException:exception source:@"Timer"];
|
||||||
[self.registry onLog:DoricLogTypeError
|
[self.registry onLog:DoricLogTypeError
|
||||||
message:[NSString stringWithFormat:@"Timer Callback error:%@", exception.reason]];
|
message:[NSString stringWithFormat:@"Timer Callback error:%@", exception.reason]];
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ - (id)findClass:(Class)clz target:(id)target context:(DoricContext *)context met
|
|||||||
[invocation invoke];
|
[invocation invoke];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
DoricLog(@"CallNative Error:%@", exception.reason);
|
DoricLog(@"CallNative Error:%@", exception.reason);
|
||||||
[context.driver.registry onException:exception];
|
[context.driver.registry onException:exception source:context.source];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,10 +40,20 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)resolve:(id)result {
|
- (void)resolve:(id)result {
|
||||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result, nil];
|
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result, nil]
|
||||||
|
setExceptionCallback:^(NSException *e) {
|
||||||
|
[self.context.driver.registry
|
||||||
|
onException:e
|
||||||
|
source:self.context.source];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reject:(id)result {
|
- (void)reject:(id)result {
|
||||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result, nil];
|
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result, nil]
|
||||||
|
setExceptionCallback:^(NSException *e) {
|
||||||
|
[self.context.driver.registry
|
||||||
|
onException:e
|
||||||
|
source:self.context.source];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -108,7 +108,7 @@ - (id)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(Do
|
|||||||
[invocation invoke];
|
[invocation invoke];
|
||||||
} @catch (NSException *exception) {
|
} @catch (NSException *exception) {
|
||||||
DoricLog(@"CallNative Error:%@", exception.reason);
|
DoricLog(@"CallNative Error:%@", exception.reason);
|
||||||
[self.doricContext.driver.registry onException:exception];
|
[self.doricContext.driver.registry onException:exception source:self.doricContext.source];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
Reference in New Issue
Block a user