Create JSContext inside setUp
Summary: In practice, it *MUST* be the call to `self.context` within `setUp` that triggers the creation of the context: - It can't come before that point because `_jscWrapper` has not been set up yet - It can't come after that point since `self.context` would create the context there. Just move the creation to be inline, enforced by assert. This makes it easier to reason about where the context is created, and easier to change how it is created later. Reviewed By: javache Differential Revision: D3529843 fbshipit-source-id: 8ed5a9861ebefd4b9e0f7155db8587dcf0442b7a
This commit is contained in:
parent
29f9be6d9c
commit
1ebd9c5dea
|
@ -307,19 +307,10 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
|||
- (RCTJavaScriptContext *)context
|
||||
{
|
||||
RCTAssertThread(_javaScriptThread, @"Must be called on JS thread.");
|
||||
|
||||
if (!self.isValid) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (!_context) {
|
||||
JSContext *context = [_jscWrapper->JSContext new];
|
||||
_context = [[RCTJavaScriptContext alloc] initWithJSContext:context onThread:_javaScriptThread];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptContextCreatedNotification
|
||||
object:context];
|
||||
}
|
||||
|
||||
RCTAssert(_context != nil, @"Fetching context while valid, but before it is created");
|
||||
return _context;
|
||||
}
|
||||
|
||||
|
@ -353,7 +344,11 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
|||
self->_jscWrapper = RCTJSCWrapperCreate(self->_useCustomJSCLibrary);
|
||||
[self->_performanceLogger markStopForTag:RCTPLJSCWrapperOpenLibrary];
|
||||
|
||||
JSContext *context = self.context.context;
|
||||
RCTAssert(self->_context == nil, @"Didn't expect to set up twice");
|
||||
JSContext *context = [self->_jscWrapper->JSContext new];
|
||||
self->_context = [[RCTJavaScriptContext alloc] initWithJSContext:context onThread:self->_javaScriptThread];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptContextCreatedNotification
|
||||
object:context];
|
||||
|
||||
if (self->_jscWrapper->configureJSContextForIOS != NULL) {
|
||||
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
|
||||
|
|
Loading…
Reference in New Issue