2016-11-21 12:30:04 +00:00
|
|
|
/**
|
|
|
|
* 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 "JSCWrapper.h"
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
2016-11-22 17:38:22 +00:00
|
|
|
#include <mutex>
|
2016-11-23 19:33:44 +00:00
|
|
|
|
|
|
|
// TODO: use glog in OSS too
|
|
|
|
#if __has_include(<glog/logging.h>)
|
|
|
|
#define USE_GLOG 1
|
2016-11-21 12:30:04 +00:00
|
|
|
#include <glog/logging.h>
|
2016-11-23 19:33:44 +00:00
|
|
|
#else
|
|
|
|
#define USE_GLOG 0
|
|
|
|
#endif
|
|
|
|
|
2016-11-21 12:30:04 +00:00
|
|
|
#include <objc/runtime.h>
|
|
|
|
|
|
|
|
// Crash the app (with a descriptive stack trace) if a function that is not supported by
|
|
|
|
// the system JSC is called.
|
2016-11-23 15:47:52 +00:00
|
|
|
#define UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(FUNC_NAME) \
|
|
|
|
static void Unimplemented_##FUNC_NAME(__unused void* args...) { \
|
|
|
|
assert(false); \
|
2016-11-21 12:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-23 19:33:44 +00:00
|
|
|
const int32_t JSNoBytecodeFileFormatVersion = -1;
|
|
|
|
|
2016-11-21 12:30:04 +00:00
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
static const JSCWrapper* s_customWrapper = nullptr;
|
|
|
|
|
2016-11-22 17:38:22 +00:00
|
|
|
static JSCWrapper s_systemWrapper = {};
|
2016-11-21 12:30:04 +00:00
|
|
|
|
2016-11-22 17:38:22 +00:00
|
|
|
const JSCWrapper* customJSCWrapper() {
|
2016-11-23 19:33:44 +00:00
|
|
|
#if USE_GLOG
|
2016-11-22 17:38:22 +00:00
|
|
|
CHECK(s_customWrapper != nullptr) << "Accessing custom JSC wrapper before it's set";
|
2016-11-23 19:33:44 +00:00
|
|
|
#endif
|
2016-11-22 17:38:22 +00:00
|
|
|
return s_customWrapper;
|
|
|
|
}
|
2016-11-21 12:30:04 +00:00
|
|
|
|
|
|
|
void setCustomJSCWrapper(const JSCWrapper* wrapper) {
|
2016-11-23 19:33:44 +00:00
|
|
|
#if USE_GLOG
|
2016-11-24 12:02:11 +00:00
|
|
|
CHECK(wrapper != nullptr) << "Can't set null wrapper";
|
2016-11-21 12:30:04 +00:00
|
|
|
CHECK(s_customWrapper == nullptr) << "Can't set custom JSC wrapper multiple times";
|
2016-11-23 19:33:44 +00:00
|
|
|
#endif
|
2016-11-21 12:30:04 +00:00
|
|
|
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, []() {
|
2016-11-22 17:38:22 +00:00
|
|
|
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"),
|
|
|
|
|
2016-11-23 19:33:44 +00:00
|
|
|
.JSBytecodeFileFormatVersion = JSNoBytecodeFileFormatVersion,
|
2016-11-22 17:38:22 +00:00
|
|
|
};
|
2016-11-21 12:30:04 +00:00
|
|
|
});
|
|
|
|
return &s_systemWrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
|
|
|
#endif
|