From 543cd217f633003b3cf1f388ffdbb31116f664a4 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 24 Jul 2017 04:49:37 -0700 Subject: [PATCH] Fix incorrect invocation of JSClassCreate Reviewed By: kathryngray Differential Revision: D5465118 fbshipit-source-id: 16e1a1af52fb1ef41fa02e380223e9e90c0611ba --- ReactCommon/jschelpers/JSCHelpers.cpp | 6 ++++-- ReactCommon/jschelpers/JavaScriptCore.h | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ReactCommon/jschelpers/JSCHelpers.cpp b/ReactCommon/jschelpers/JSCHelpers.cpp index 61e3b49094f..dd0cac467ba 100644 --- a/ReactCommon/jschelpers/JSCHelpers.cpp +++ b/ReactCommon/jschelpers/JSCHelpers.cpp @@ -31,9 +31,11 @@ JSValueRef functionCaller( JSClassRef createFuncClass(JSContextRef ctx) { JSClassDefinition definition = kJSClassDefinitionEmpty; definition.attributes |= kJSClassAttributeNoAutomaticPrototype; + // Need to duplicate the two different finalizer blocks, since there's no way // for it to capture this static information. - if (isCustomJSCPtr(ctx)) { + const bool isCustomJSC = isCustomJSCPtr(ctx); + if (isCustomJSC) { definition.finalize = [](JSObjectRef object) { auto* function = static_cast(JSC_JSObjectGetPrivate(true, object)); delete function; @@ -46,7 +48,7 @@ JSClassRef createFuncClass(JSContextRef ctx) { } definition.callAsFunction = exceptionWrapMethod<&functionCaller>(); - return JSC_JSClassCreate(ctx, &definition); + return JSC_JSClassCreate(isCustomJSC, &definition); } JSObjectRef makeFunction( diff --git a/ReactCommon/jschelpers/JavaScriptCore.h b/ReactCommon/jschelpers/JavaScriptCore.h index dadd73967c8..1d6beb0306d 100644 --- a/ReactCommon/jschelpers/JavaScriptCore.h +++ b/ReactCommon/jschelpers/JavaScriptCore.h @@ -31,10 +31,12 @@ // Use for methods were access to a JSContextRef is impractical. The first bool param // will be dropped before the JSC method is invoked. -#define __jsc_bool_wrapper(method, useCustomJSC, ...) \ - (useCustomJSC ? \ - facebook::react::customJSCWrapper() : \ - facebook::react::systemJSCWrapper() \ +#define __jsc_ensure_bool(field) \ + static_assert(std::is_same::type, bool>::value, "useCustomJSC must be bool"); +#define __jsc_bool_wrapper(method, useCustomJSC, ...) \ + ([]{ __jsc_ensure_bool(useCustomJSC) }, useCustomJSC ? \ + facebook::react::customJSCWrapper() : \ + facebook::react::systemJSCWrapper() \ )->method(__VA_ARGS__) // Used for wrapping properties