diff --git a/doric-android/doric/src/main/java/pub/doric/DoricNativeDriver.java b/doric-android/doric/src/main/java/pub/doric/DoricNativeDriver.java index c4b2031e..a128cde7 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricNativeDriver.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricNativeDriver.java @@ -141,17 +141,25 @@ public class DoricNativeDriver implements IDoricDriver { } } + private DoricPerformanceProfile getDoricPerformanceProfile(String contextId) { + DoricContext doricContext = DoricContextManager.getContext(contextId); + if (doricContext != null) { + return doricContext.getPerformanceProfile(); + } + return new DoricPerformanceProfile("Empty"); + } + @Override public AsyncResult createContext(final String contextId, final String script, final String source) { - final DoricPerformanceProfile performanceProfile = DoricContextManager.getContext(contextId).getPerformanceProfile(); - performanceProfile.prepare(DoricPerformanceProfile.STEP_CREATE); + final DoricPerformanceProfile profile = getDoricPerformanceProfile(contextId); + profile.prepare(DoricPerformanceProfile.STEP_CREATE); return AsyncCall.ensureRunInHandler(mJSHandler, new Callable() { @Override public Boolean call() { try { - performanceProfile.start(DoricPerformanceProfile.STEP_CREATE); + profile.start(DoricPerformanceProfile.STEP_CREATE); doricJSEngine.prepareContext(contextId, script, source); - performanceProfile.end(DoricPerformanceProfile.STEP_CREATE); + profile.end(DoricPerformanceProfile.STEP_CREATE); return true; } catch (Exception e) { doricJSEngine.getRegistry().onException(DoricContextManager.getContext(contextId), e); @@ -164,7 +172,7 @@ public class DoricNativeDriver implements IDoricDriver { @Override public AsyncResult destroyContext(final String contextId) { - final DoricPerformanceProfile profile = DoricContextManager.getContext(contextId).getPerformanceProfile(); + final DoricPerformanceProfile profile = getDoricPerformanceProfile(contextId); profile.prepare(DoricPerformanceProfile.STEP_DESTROY); return AsyncCall.ensureRunInHandler(mJSHandler, new Callable() { @Override diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index b51a29f7..13831eaf 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -97,7 +97,7 @@ - (instancetype)init { }.mutableCopy; self.registry = [[DoricRegistry alloc] initWithJSEngine:self]; [self ensureRunOnJSThread:^() { - [_profile start:@"Init"]; + [self.profile start:@"Init"]; self.timers = [[NSMutableDictionary alloc] init]; self.bridgeExtension = [DoricBridgeExtension new]; self.bridgeExtension.registry = self.registry; @@ -105,7 +105,7 @@ - (instancetype)init { [self initJSExecutor]; [self initDoricEnvironment]; self.initialized = YES; - [_profile end:@"Init"]; + [self.profile end:@"Init"]; }]; [self.registry registerMonitor:[DoricDefaultMonitor new]]; }