From acb9fa8f66d1ab8c7761c3358cfa5175d82d6d1d Mon Sep 17 00:00:00 2001 From: Theo Yaung Date: Fri, 10 Mar 2017 09:08:05 -0800 Subject: [PATCH] Refactor dependencies Reviewed By: mkonicek Differential Revision: D4689351 fbshipit-source-id: 35e6939379dcb6723e7749883ad9613459f9787b --- React/React.xcodeproj/project.pbxproj | 4 + ReactAndroid/DEFS | 3 +- ReactCommon/jschelpers/BUCK | 90 +++++++++---- ReactCommon/jschelpers/JSCWrapper.cpp | 117 ----------------- ReactCommon/jschelpers/systemJSCWrapper.cpp | 136 ++++++++++++++++++++ 5 files changed, 206 insertions(+), 144 deletions(-) create mode 100644 ReactCommon/jschelpers/systemJSCWrapper.cpp diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 6cd5441fd..705d5ecf2 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -687,6 +687,7 @@ 597AD1BE1E577D7800152581 /* RCTRootContentView.h in Headers */ = {isa = PBXBuildFile; fileRef = 597AD1BB1E577D7800152581 /* RCTRootContentView.h */; }; 597AD1BF1E577D7800152581 /* RCTRootContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 597AD1BC1E577D7800152581 /* RCTRootContentView.m */; }; 597AD1C01E577D7800152581 /* RCTRootContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 597AD1BC1E577D7800152581 /* RCTRootContentView.m */; }; + 65F3E41E1E73031C009375BD /* systemJSCWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65F3E41D1E73031C009375BD /* systemJSCWrapper.cpp */; }; 68EFE4EE1CF6EB3900A1DE13 /* RCTBundleURLProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */; }; 830A229E1A66C68A008503DA /* RCTRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 830A229D1A66C68A008503DA /* RCTRootView.m */; }; 83392EB31B6634E10013B15F /* RCTModalHostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 83392EB21B6634E10013B15F /* RCTModalHostViewController.m */; }; @@ -1322,6 +1323,7 @@ 594AD5CC1E46D87500B07237 /* RCTScrollContentViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTScrollContentViewManager.m; sourceTree = ""; }; 597AD1BB1E577D7800152581 /* RCTRootContentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootContentView.h; sourceTree = ""; }; 597AD1BC1E577D7800152581 /* RCTRootContentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRootContentView.m; sourceTree = ""; }; + 65F3E41D1E73031C009375BD /* systemJSCWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = systemJSCWrapper.cpp; sourceTree = ""; }; 68EFE4EC1CF6EB3000A1DE13 /* RCTBundleURLProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBundleURLProvider.h; sourceTree = ""; }; 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBundleURLProvider.m; sourceTree = ""; }; 6A15FB0C1BDF663500531DFB /* RCTRootViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootViewInternal.h; sourceTree = ""; }; @@ -1663,6 +1665,7 @@ 3D4A621D1DDD3985001F41B4 /* jschelpers */ = { isa = PBXGroup; children = ( + 65F3E41D1E73031C009375BD /* systemJSCWrapper.cpp */, 3D7A27DC1DE32541002E3F95 /* JavaScriptCore.h */, 3D7A27DD1DE32541002E3F95 /* JSCWrapper.cpp */, 3D7A27DE1DE32541002E3F95 /* JSCWrapper.h */, @@ -2639,6 +2642,7 @@ 137327E91AA5CF210034F82E /* RCTTabBarItemManager.m in Sources */, 13A1F71E1A75392D00D3D453 /* RCTKeyCommands.m in Sources */, 83CBBA531A601E3B00E9B192 /* RCTUtils.m in Sources */, + 65F3E41E1E73031C009375BD /* systemJSCWrapper.cpp in Sources */, 191E3EC11C29DC3800C180A6 /* RCTRefreshControl.m in Sources */, 13C156051AB1A2840079392D /* RCTWebView.m in Sources */, 83CBBA601A601EAA00E9B192 /* RCTBridge.m in Sources */, diff --git a/ReactAndroid/DEFS b/ReactAndroid/DEFS index 872f103e9..632167ab7 100644 --- a/ReactAndroid/DEFS +++ b/ReactAndroid/DEFS @@ -30,10 +30,11 @@ def react_native_integration_tests_target(path): def react_native_dep(path): return '//ReactAndroid/src/main/' + path -JSC_DEPS = [ +JSC_INTERNAL_DEPS = [ '//native/third-party/jsc:jsc', '//native/third-party/jsc:jsc_legacy_profiler', ] +JSC_DEPS = JSC_INTERNAL_DEPS YOGA_TARGET = '//ReactAndroid/src/main/java/com/facebook:yoga' FBGLOGINIT_TARGET = '//ReactAndroid/src/main/jni/first-party/fbgloginit:fbgloginit' diff --git a/ReactCommon/jschelpers/BUCK b/ReactCommon/jschelpers/BUCK index b829b95df..82577f4f4 100644 --- a/ReactCommon/jschelpers/BUCK +++ b/ReactCommon/jschelpers/BUCK @@ -7,51 +7,89 @@ EXPORTED_HEADERS = [ "Value.h", ] +EXPORTED_HEADER_MAP = subdir_glob( + (("", header) for header in EXPORTED_HEADERS), + prefix = "jschelpers", +) + if THIS_IS_FBANDROID: - include_defs('//ReactAndroid/DEFS') + include_defs("//ReactAndroid/DEFS") cxx_library( - name = 'jschelpers', + name = "jscinternalhelpers", force_static = True, compiler_flags = [ - '-Wall', - '-fexceptions', - '-fvisibility=hidden', - '-std=c++1y', + "-Wall", + "-fexceptions", + "-fvisibility=hidden", + "-std=c++1y", ], exported_headers = EXPORTED_HEADERS, - headers = glob(['*.h'], excludes=EXPORTED_HEADERS), - header_namespace = 'jschelpers', - srcs = glob(['*.cpp']), - deps = JSC_DEPS + [ - '//xplat/folly:molly', + headers = glob(["*.h"], excludes=EXPORTED_HEADERS), + header_namespace = "jschelpers", + srcs = glob(["*.cpp"], excludes=["systemJSCWrapper.cpp"]), + deps = JSC_INTERNAL_DEPS + [ + "//xplat/folly:molly", ], visibility = [ - 'PUBLIC', + "PUBLIC", + ], + ) + + cxx_library( + name = "jschelpers", + force_static = True, + compiler_flags = [ + "-Wall", + "-fexceptions", + "-fvisibility=hidden", + "-std=c++1y", + ], + srcs = [], + deps = [ ":jscinternalhelpers" ], + visibility = [ + "PUBLIC", ], ) if THIS_IS_FBOBJC: + ios_library( - name = 'jschelpers', + name = "jscinternalhelpers", inherited_buck_flags = STATIC_LIBRARY_IOS_FLAGS, compiler_flags = [ - '-Wall', - '-fexceptions', - '-fvisibility=hidden', - '-std=c++1y', - ], - exported_headers = EXPORTED_HEADERS, - headers = glob(['*.h'], excludes=EXPORTED_HEADERS), - header_namespace = 'jschelpers', - srcs = glob(['*.cpp']), - frameworks = [ - '$SDKROOT/System/Library/Frameworks/JavaScriptCore.framework', + "-Wall", + "-fexceptions", + "-fvisibility=hidden", + "-std=c++1y", ], + exported_headers = EXPORTED_HEADER_MAP, + headers = subdir_glob([("", "*.h")], excludes=EXPORTED_HEADERS, prefix="jschelpers"), + header_namespace = "jschelpers", + srcs = glob(["*.cpp"], excludes=["systemJSCWrapper.cpp"]), deps = [ - '//xplat/folly:molly', + "//xplat/folly:molly", ], visibility = [ - 'PUBLIC', + "PUBLIC", + ], + ) + + ios_library( + name = "jschelpers", + inherited_buck_flags = STATIC_LIBRARY_IOS_FLAGS, + compiler_flags = [ + "-Wall", + "-fexceptions", + "-fvisibility=hidden", + "-std=c++1y", + ], + srcs = ["systemJSCWrapper.cpp"], + frameworks = [ + "$SDKROOT/System/Library/Frameworks/JavaScriptCore.framework", + ], + deps = [ ":jscinternalhelpers" ], + visibility = [ + "PUBLIC", ], ) diff --git a/ReactCommon/jschelpers/JSCWrapper.cpp b/ReactCommon/jschelpers/JSCWrapper.cpp index 0da38ae84..422fb7f8e 100644 --- a/ReactCommon/jschelpers/JSCWrapper.cpp +++ b/ReactCommon/jschelpers/JSCWrapper.cpp @@ -11,8 +11,6 @@ #if defined(__APPLE__) -#include - // TODO: use glog in OSS too #if __has_include() #define USE_GLOG 1 @@ -21,36 +19,11 @@ #define USE_GLOG 0 #endif -#include - -// Crash the app (with a descriptive stack trace) if a function that is not supported by -// the system JSC is called. -#define UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(FUNC_NAME) \ -static void Unimplemented_##FUNC_NAME(__unused void* args...) { \ - assert(false); \ -} - -UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSEvaluateBytecodeBundle) -#if WITH_FBJSCEXTENSIONS -UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSStringCreateWithUTF8CStringExpectAscii) -#endif -UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSPokeSamplingProfiler) -UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSStartSamplingProfilingOnMainJSCThread) -UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(configureJSCForIOS) - -bool JSSamplingProfilerEnabled() { - return false; -} - -const int32_t JSNoBytecodeFileFormatVersion = -1; - namespace facebook { namespace react { static const JSCWrapper* s_customWrapper = nullptr; -static JSCWrapper s_systemWrapper = {}; - bool isCustomJSCWrapperSet() { return s_customWrapper != nullptr; } @@ -69,96 +42,6 @@ void setCustomJSCWrapper(const JSCWrapper* wrapper) { s_customWrapper = wrapper; } -const JSCWrapper* systemJSCWrapper() { - // Note that this is not used on Android. All methods are statically linked instead. - // Some fields are lazily initialized - static std::once_flag flag; - std::call_once(flag, []() { - s_systemWrapper = { - .JSGlobalContextCreateInGroup = JSGlobalContextCreateInGroup, - .JSGlobalContextRelease = JSGlobalContextRelease, - .JSGlobalContextSetName = JSGlobalContextSetName, - - .JSContextGetGlobalContext = JSContextGetGlobalContext, - .JSContextGetGlobalObject = JSContextGetGlobalObject, - - .JSEvaluateScript = JSEvaluateScript, - .JSEvaluateBytecodeBundle = - (decltype(&JSEvaluateBytecodeBundle)) - Unimplemented_JSEvaluateBytecodeBundle, - - .JSStringCreateWithUTF8CString = JSStringCreateWithUTF8CString, - .JSStringCreateWithCFString = JSStringCreateWithCFString, - #if WITH_FBJSCEXTENSIONS - .JSStringCreateWithUTF8CStringExpectAscii = - (decltype(&JSStringCreateWithUTF8CStringExpectAscii)) - Unimplemented_JSStringCreateWithUTF8CStringExpectAscii, - #endif - .JSStringCopyCFString = JSStringCopyCFString, - .JSStringGetCharactersPtr = JSStringGetCharactersPtr, - .JSStringGetLength = JSStringGetLength, - .JSStringGetMaximumUTF8CStringSize = JSStringGetMaximumUTF8CStringSize, - .JSStringIsEqualToUTF8CString = JSStringIsEqualToUTF8CString, - .JSStringRelease = JSStringRelease, - .JSStringRetain = JSStringRetain, - - .JSClassCreate = JSClassCreate, - .JSClassRelease = JSClassRelease, - - .JSObjectCallAsConstructor = JSObjectCallAsConstructor, - .JSObjectCallAsFunction = JSObjectCallAsFunction, - .JSObjectGetPrivate = JSObjectGetPrivate, - .JSObjectGetProperty = JSObjectGetProperty, - .JSObjectGetPropertyAtIndex = JSObjectGetPropertyAtIndex, - .JSObjectIsConstructor = JSObjectIsConstructor, - .JSObjectIsFunction = JSObjectIsFunction, - .JSObjectMake = JSObjectMake, - .JSObjectMakeArray = JSObjectMakeArray, - .JSObjectMakeError = JSObjectMakeError, - .JSObjectMakeFunctionWithCallback = JSObjectMakeFunctionWithCallback, - .JSObjectSetPrivate = JSObjectSetPrivate, - .JSObjectSetProperty = JSObjectSetProperty, - - .JSObjectCopyPropertyNames = JSObjectCopyPropertyNames, - .JSPropertyNameArrayGetCount = JSPropertyNameArrayGetCount, - .JSPropertyNameArrayGetNameAtIndex = JSPropertyNameArrayGetNameAtIndex, - .JSPropertyNameArrayRelease = JSPropertyNameArrayRelease, - - .JSValueCreateJSONString = JSValueCreateJSONString, - .JSValueGetType = JSValueGetType, - .JSValueMakeFromJSONString = JSValueMakeFromJSONString, - .JSValueMakeBoolean = JSValueMakeBoolean, - .JSValueMakeNull = JSValueMakeNull, - .JSValueMakeNumber = JSValueMakeNumber, - .JSValueMakeString = JSValueMakeString, - .JSValueMakeUndefined = JSValueMakeUndefined, - .JSValueProtect = JSValueProtect, - .JSValueToBoolean = JSValueToBoolean, - .JSValueToNumber = JSValueToNumber, - .JSValueToObject = JSValueToObject, - .JSValueToStringCopy = JSValueToStringCopy, - .JSValueUnprotect = JSValueUnprotect, - - .JSSamplingProfilerEnabled = JSSamplingProfilerEnabled, - .JSPokeSamplingProfiler = - (decltype(&JSPokeSamplingProfiler)) - Unimplemented_JSPokeSamplingProfiler, - .JSStartSamplingProfilingOnMainJSCThread = - (decltype(&JSStartSamplingProfilingOnMainJSCThread)) - Unimplemented_JSStartSamplingProfilingOnMainJSCThread, - - .configureJSCForIOS = - (decltype(&configureJSCForIOS))Unimplemented_configureJSCForIOS, - - .JSContext = objc_getClass("JSContext"), - .JSValue = objc_getClass("JSValue"), - - .JSBytecodeFileFormatVersion = JSNoBytecodeFileFormatVersion, - }; - }); - return &s_systemWrapper; -} - } } #endif diff --git a/ReactCommon/jschelpers/systemJSCWrapper.cpp b/ReactCommon/jschelpers/systemJSCWrapper.cpp new file mode 100644 index 000000000..80000c3fa --- /dev/null +++ b/ReactCommon/jschelpers/systemJSCWrapper.cpp @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2016-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include + +#if defined(__APPLE__) + +#include + +#include + +// Crash the app (with a descriptive stack trace) if a function that is not supported by +// the system JSC is called. +#define UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(FUNC_NAME) \ +static void Unimplemented_##FUNC_NAME(__unused void* args...) { \ + assert(false); \ +} + +UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSEvaluateBytecodeBundle) +#if WITH_FBJSCEXTENSIONS +UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSStringCreateWithUTF8CStringExpectAscii) +#endif +UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSPokeSamplingProfiler) +UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSStartSamplingProfilingOnMainJSCThread) +UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(configureJSCForIOS) + +bool JSSamplingProfilerEnabled() { + return false; +} + +const int32_t JSNoBytecodeFileFormatVersion = -1; + +namespace facebook { +namespace react { + +static JSCWrapper s_systemWrapper = {}; + +const JSCWrapper* systemJSCWrapper() { + // Note that this is not used on Android. All methods are statically linked instead. + // Some fields are lazily initialized + static std::once_flag flag; + std::call_once(flag, []() { + s_systemWrapper = { + .JSGlobalContextCreateInGroup = JSGlobalContextCreateInGroup, + .JSGlobalContextRelease = JSGlobalContextRelease, + .JSGlobalContextSetName = JSGlobalContextSetName, + + .JSContextGetGlobalContext = JSContextGetGlobalContext, + .JSContextGetGlobalObject = JSContextGetGlobalObject, + + .JSEvaluateScript = JSEvaluateScript, + .JSEvaluateBytecodeBundle = + (decltype(&JSEvaluateBytecodeBundle)) + Unimplemented_JSEvaluateBytecodeBundle, + + .JSStringCreateWithUTF8CString = JSStringCreateWithUTF8CString, + .JSStringCreateWithCFString = JSStringCreateWithCFString, + #if WITH_FBJSCEXTENSIONS + .JSStringCreateWithUTF8CStringExpectAscii = + (decltype(&JSStringCreateWithUTF8CStringExpectAscii)) + Unimplemented_JSStringCreateWithUTF8CStringExpectAscii, + #endif + .JSStringCopyCFString = JSStringCopyCFString, + .JSStringGetCharactersPtr = JSStringGetCharactersPtr, + .JSStringGetLength = JSStringGetLength, + .JSStringGetMaximumUTF8CStringSize = JSStringGetMaximumUTF8CStringSize, + .JSStringIsEqualToUTF8CString = JSStringIsEqualToUTF8CString, + .JSStringRelease = JSStringRelease, + .JSStringRetain = JSStringRetain, + + .JSClassCreate = JSClassCreate, + .JSClassRelease = JSClassRelease, + + .JSObjectCallAsConstructor = JSObjectCallAsConstructor, + .JSObjectCallAsFunction = JSObjectCallAsFunction, + .JSObjectGetPrivate = JSObjectGetPrivate, + .JSObjectGetProperty = JSObjectGetProperty, + .JSObjectGetPropertyAtIndex = JSObjectGetPropertyAtIndex, + .JSObjectIsConstructor = JSObjectIsConstructor, + .JSObjectIsFunction = JSObjectIsFunction, + .JSObjectMake = JSObjectMake, + .JSObjectMakeArray = JSObjectMakeArray, + .JSObjectMakeError = JSObjectMakeError, + .JSObjectMakeFunctionWithCallback = JSObjectMakeFunctionWithCallback, + .JSObjectSetPrivate = JSObjectSetPrivate, + .JSObjectSetProperty = JSObjectSetProperty, + + .JSObjectCopyPropertyNames = JSObjectCopyPropertyNames, + .JSPropertyNameArrayGetCount = JSPropertyNameArrayGetCount, + .JSPropertyNameArrayGetNameAtIndex = JSPropertyNameArrayGetNameAtIndex, + .JSPropertyNameArrayRelease = JSPropertyNameArrayRelease, + + .JSValueCreateJSONString = JSValueCreateJSONString, + .JSValueGetType = JSValueGetType, + .JSValueMakeFromJSONString = JSValueMakeFromJSONString, + .JSValueMakeBoolean = JSValueMakeBoolean, + .JSValueMakeNull = JSValueMakeNull, + .JSValueMakeNumber = JSValueMakeNumber, + .JSValueMakeString = JSValueMakeString, + .JSValueMakeUndefined = JSValueMakeUndefined, + .JSValueProtect = JSValueProtect, + .JSValueToBoolean = JSValueToBoolean, + .JSValueToNumber = JSValueToNumber, + .JSValueToObject = JSValueToObject, + .JSValueToStringCopy = JSValueToStringCopy, + .JSValueUnprotect = JSValueUnprotect, + + .JSSamplingProfilerEnabled = JSSamplingProfilerEnabled, + .JSPokeSamplingProfiler = + (decltype(&JSPokeSamplingProfiler)) + Unimplemented_JSPokeSamplingProfiler, + .JSStartSamplingProfilingOnMainJSCThread = + (decltype(&JSStartSamplingProfilingOnMainJSCThread)) + Unimplemented_JSStartSamplingProfilingOnMainJSCThread, + + .configureJSCForIOS = + (decltype(&configureJSCForIOS))Unimplemented_configureJSCForIOS, + + .JSContext = objc_getClass("JSContext"), + .JSValue = objc_getClass("JSValue"), + + .JSBytecodeFileFormatVersion = JSNoBytecodeFileFormatVersion, + }; + }); + return &s_systemWrapper; +} + +} } + +#endif