diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index e92795b44..d977a0ef3 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -81,13 +81,20 @@ inline JSObjectCallAsFunctionCallback exceptionWrapMethod() { } +#if DEBUG static JSValueRef nativeInjectHMRUpdate( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], - JSValueRef *exception); + JSValueRef *exception) { + String execJSString = Value(ctx, arguments[0]).toString(); + String jsURL = Value(ctx, arguments[1]).toString(); + evaluateScript(ctx, execJSString, jsURL); + return JSValueMakeUndefined(ctx); +} +#endif std::unique_ptr JSCExecutorFactory::createJSExecutor( std::shared_ptr delegate, std::shared_ptr jsQueue) { @@ -189,6 +196,7 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) { configureJSCForAndroid(m_jscConfig); #endif + // Create a custom global class, so we can store data in it later using JSObjectSetPrivate JSClassRef globalClass = nullptr; { SystraceSection s("JSClassCreate"); @@ -205,15 +213,21 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) { installNativeHook<&JSCExecutor::nativeRequireModuleConfig>("nativeRequireModuleConfig"); installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate"); + installNativeHook<&JSCExecutor::nativeCallSyncHook>("nativeCallSyncHook"); + + // Websorker support installNativeHook<&JSCExecutor::nativeStartWorker>("nativeStartWorker"); installNativeHook<&JSCExecutor::nativePostMessageToWorker>("nativePostMessageToWorker"); installNativeHook<&JSCExecutor::nativeTerminateWorker>("nativeTerminateWorker"); - installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate); installNativeHook<&JSCExecutor::nativeCallSyncHook>("nativeCallSyncHook"); installGlobalFunction(m_context, "nativeLoggingHook", JSNativeHooks::loggingHook); installGlobalFunction(m_context, "nativePerformanceNow", JSNativeHooks::nowHook); + #if DEBUG + installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate); + #endif + #if defined(WITH_JSC_EXTRA_TRACING) || DEBUG addNativeTracingHooks(m_context); #endif @@ -762,16 +776,4 @@ JSValueRef JSCExecutor::nativeCallSyncHook( return Value::fromDynamic(m_context, result.result); } -static JSValueRef nativeInjectHMRUpdate( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], JSValueRef *exception) { - String execJSString = Value(ctx, arguments[0]).toString(); - String jsURL = Value(ctx, arguments[1]).toString(); - evaluateScript(ctx, execJSString, jsURL); - return JSValueMakeUndefined(ctx); -} - } }