Skip to content

Commit

Permalink
Fix incorrect invocation of JSClassCreate
Browse files Browse the repository at this point in the history
Reviewed By: kathryngray

Differential Revision: D5465118

fbshipit-source-id: 16e1a1af52fb1ef41fa02e380223e9e90c0611ba
  • Loading branch information
javache authored and facebook-github-bot committed Jul 24, 2017
1 parent db3df34 commit 543cd21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions ReactCommon/jschelpers/JSCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<JSFunction*>(JSC_JSObjectGetPrivate(true, object));
delete function;
Expand All @@ -46,7 +48,7 @@ JSClassRef createFuncClass(JSContextRef ctx) {
}
definition.callAsFunction = exceptionWrapMethod<&functionCaller>();

return JSC_JSClassCreate(ctx, &definition);
return JSC_JSClassCreate(isCustomJSC, &definition);
}

JSObjectRef makeFunction(
Expand Down
10 changes: 6 additions & 4 deletions ReactCommon/jschelpers/JavaScriptCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename std::decay<decltype(field)>::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
Expand Down

0 comments on commit 543cd21

Please sign in to comment.