feat:Android and iOS monitor use DoricContext as parameter
This commit is contained in:
@@ -59,13 +59,33 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
|
||||
@Override
|
||||
public AsyncResult<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args) {
|
||||
final AsyncResult<JSDecoder> asyncResult = new AsyncResult<>();
|
||||
final Object[] nArgs = new Object[args.length + 2];
|
||||
nArgs[0] = contextId;
|
||||
nArgs[1] = method;
|
||||
if (args.length > 0) {
|
||||
System.arraycopy(args, 0, nArgs, 2, args.length);
|
||||
}
|
||||
return invokeDoricMethod(DoricConstant.DORIC_CONTEXT_INVOKE, nArgs);
|
||||
invokeDoricMethod(DoricConstant.DORIC_CONTEXT_INVOKE, nArgs).setCallback(new AsyncResult.Callback<JSDecoder>() {
|
||||
@Override
|
||||
public void onResult(JSDecoder result) {
|
||||
asyncResult.setResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
asyncResult.setError(t);
|
||||
getRegistry().onException(
|
||||
DoricContextManager.getContext(contextId),
|
||||
t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
return asyncResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,14 +111,6 @@ 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
|
||||
public AsyncResult<Boolean> createContext(final String contextId, final String script, final String source) {
|
||||
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
|
||||
@@ -108,7 +120,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
doricJSEngine.prepareContext(contextId, script, source);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
doricJSEngine.getRegistry().onException(sourceWithContextId(contextId), e);
|
||||
doricJSEngine.getRegistry().onException(DoricContextManager.getContext(contextId), e);
|
||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("createContext %s error is %s", source, e.getLocalizedMessage()));
|
||||
return false;
|
||||
}
|
||||
@@ -125,7 +137,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
doricJSEngine.destroyContext(contextId);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
doricJSEngine.getRegistry().onException(sourceWithContextId(contextId), e);
|
||||
doricJSEngine.getRegistry().onException(DoricContextManager.getContext(contextId), e);
|
||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("destroyContext %s error is %s", contextId, e.getLocalizedMessage()));
|
||||
return false;
|
||||
}
|
||||
|
@@ -162,9 +162,9 @@ public class DoricRegistry {
|
||||
this.monitors.add(monitor);
|
||||
}
|
||||
|
||||
public void onException(String source, Exception e) {
|
||||
public void onException(DoricContext context, Exception e) {
|
||||
for (IDoricMonitor monitor : this.monitors) {
|
||||
monitor.onException(source, e);
|
||||
monitor.onException(context, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,11 +24,11 @@ public interface IDoricMonitor {
|
||||
/**
|
||||
* Called when native or js exception occurred in doric
|
||||
*
|
||||
* @param source Which source file
|
||||
* @param e exception which is thrown within doric sdk
|
||||
* @param context Which context
|
||||
* @param e exception which is thrown within doric sdk
|
||||
* @see com.github.pengfeizhou.jscore.JSRuntimeException
|
||||
*/
|
||||
void onException(String source, Exception e);
|
||||
void onException(DoricContext context, Exception e);
|
||||
|
||||
/**
|
||||
* @param type The priority/type of this log message.
|
||||
|
@@ -25,6 +25,8 @@ import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JavaFunction;
|
||||
@@ -132,7 +134,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException("Log", e);
|
||||
mDoricRegistry.onException(null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -156,7 +158,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
mDoricJSE.loadJS(packageModuleScript(name, content), "Module://" + name);
|
||||
return new JavaValue(true);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException("Require", e);
|
||||
mDoricRegistry.onException(null, e);
|
||||
return new JavaValue(false);
|
||||
}
|
||||
}
|
||||
@@ -170,7 +172,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
args[1].number().longValue(),
|
||||
args[2].bool());
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException("Timer", e);
|
||||
mDoricRegistry.onException(null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -181,7 +183,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
try {
|
||||
mTimerExtension.clearTimer(args[0].number().longValue());
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException("Timer", e);
|
||||
mDoricRegistry.onException(null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -198,7 +200,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
JSDecoder jsDecoder = args[4];
|
||||
return mDoricBridgeExtension.callNative(contextId, module, method, callbackId, jsDecoder);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException("Bridge", e);
|
||||
mDoricRegistry.onException(null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -212,7 +214,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB);
|
||||
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException("Init Environment", e);
|
||||
mDoricRegistry.onException(null, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +265,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
try {
|
||||
invokeDoricMethod(DoricConstant.DORIC_TIMER_CALLBACK, timerId);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException("Timer", e);
|
||||
mDoricRegistry.onException(null, e);
|
||||
mDoricRegistry.onLog(
|
||||
Log.ERROR,
|
||||
String.format("Timer Callback error:%s", e.getLocalizedMessage()));
|
||||
@@ -275,8 +277,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(String source, Exception e) {
|
||||
Log.e(DoricJSEngine.class.getSimpleName(), "In source file: " + source);
|
||||
public void onException(@Nullable DoricContext context, Exception e) {
|
||||
Log.e(DoricJSEngine.class.getSimpleName(), "In source file: " + (context != null ? context.getSource() : "Unknown"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@@ -98,7 +98,7 @@ public class DoricBridgeExtension {
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
context.getDriver().getRegistry().onException(
|
||||
context.getSource(),
|
||||
context,
|
||||
t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class DoricBridgeExtension {
|
||||
try {
|
||||
return DoricUtils.toJavaObject(clz, jsDecoder);
|
||||
} catch (Exception e) {
|
||||
context.getDriver().getRegistry().onException(context.getSource(), e);
|
||||
context.getDriver().getRegistry().onException(context, e);
|
||||
context.getDriver().getRegistry().onLog(
|
||||
Log.ERROR,
|
||||
String.format("createParam error:%s", e.getLocalizedMessage()));
|
||||
|
@@ -55,7 +55,7 @@ public class DoricPromise {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
context.getDriver().getRegistry().onException(context.getSource(), t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
context.getDriver().getRegistry().onException(context, t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +82,7 @@ public class DoricPromise {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
context.getDriver().getRegistry().onException(context.getSource(), t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
context.getDriver().getRegistry().onException(context, t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -79,7 +79,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
getDoricContext().getDriver().getRegistry().onException(
|
||||
getDoricContext().getSource(),
|
||||
getDoricContext(),
|
||||
t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
getDoricContext().getDriver().getRegistry().onLog(
|
||||
Log.ERROR,
|
||||
@@ -92,7 +92,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
getDoricContext().getDriver().getRegistry().onException(getDoricContext().getSource(), e);
|
||||
getDoricContext().getDriver().getRegistry().onException(getDoricContext(), e);
|
||||
getDoricContext().getDriver().getRegistry().onLog(
|
||||
Log.ERROR,
|
||||
String.format("Shader.render:error%s", e.getLocalizedMessage())
|
||||
@@ -173,7 +173,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
getDoricContext().getDriver().getRegistry().onException(getDoricContext().getSource(), e);
|
||||
getDoricContext().getDriver().getRegistry().onException(getDoricContext(), e);
|
||||
}
|
||||
return new JavaValue(true);
|
||||
}
|
||||
|
@@ -156,7 +156,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
if (errorDrawable != null) {
|
||||
requestBuilder = requestBuilder.apply(RequestOptions.errorOf(errorDrawable));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
DoricLog.e("ImageNode blend error, please check the glide version");
|
||||
}
|
||||
|
Reference in New Issue
Block a user