Define wrapper versions of all JSC methods
Reviewed By: bnham Differential Revision: D4197369 fbshipit-source-id: 53869fe1b56010c8a5330025d06ef557369e4957
This commit is contained in:
Родитель
1c69b61c26
Коммит
e541d9b108
|
@ -6,11 +6,10 @@
|
|||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
|
||||
#include <folly/json.h>
|
||||
#include <folly/Optional.h>
|
||||
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
#include <jschelpers/JSCHelpers.h>
|
||||
#include <jschelpers/Value.h>
|
||||
|
||||
|
@ -163,7 +162,7 @@ private:
|
|||
void terminateOwnedWebWorker(int worker);
|
||||
Object createMessageObject(const std::string& msgData);
|
||||
|
||||
template< JSValueRef (JSCExecutor::*method)(size_t, const JSValueRef[])>
|
||||
template<JSValueRef (JSCExecutor::*method)(size_t, const JSValueRef[])>
|
||||
void installNativeHook(const char* name);
|
||||
JSValueRef getNativeModule(JSObjectRef object, JSStringRef propertyName);
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
||||
#include <jsc_legacy_profiler.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
#include <jschelpers/JSCHelpers.h>
|
||||
#include <jschelpers/Value.h>
|
||||
#include "JSCLegacyProfiler.h"
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
#ifdef WITH_JSC_EXTRA_TRACING
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
#include "JSCLegacyTracing.h"
|
||||
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
||||
|
||||
#include <fbsystrace.h>
|
||||
|
||||
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
||||
#include <jschelpers/JSCHelpers.h>
|
||||
#include <jschelpers/Value.h>
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
#if defined(WITH_JSC_EXTRA_TRACING)
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
#include "JSCMemory.h"
|
||||
|
||||
#ifdef WITH_FB_MEMORY_PROFILING
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "JSCNativeModules.h"
|
||||
|
||||
#include <jschelpers/JSCWrapper.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace facebook {
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#ifdef JSC_HAS_PERF_STATS_API
|
||||
|
||||
#include <JavaScriptCore/JSPerfStats.h>
|
||||
#include <JavaScriptCore/JSValueRef.h>
|
||||
|
||||
#include <jschelpers/JSCHelpers.h>
|
||||
#include <jschelpers/Value.h>
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#ifdef WITH_JSC_EXTRA_TRACING
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include "JSCTracing.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
#include <fbsystrace.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
#include <jschelpers/JSCHelpers.h>
|
||||
#include <jschelpers/Value.h>
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
|
|
@ -2,23 +2,20 @@
|
|||
|
||||
#include "JSCWebWorker.h"
|
||||
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <folly/Memory.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include <jschelpers/JSCHelpers.h>
|
||||
#include <jschelpers/Value.h>
|
||||
|
||||
#include "MessageQueueThread.h"
|
||||
#include "Platform.h"
|
||||
#include "JSCUtils.h"
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include <JavaScriptCore/JSValueRef.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
#include <thread>
|
||||
#include <queue>
|
||||
|
||||
#include <JavaScriptCore/JSValueRef.h>
|
||||
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
#include <jschelpers/Value.h>
|
||||
|
||||
namespace facebook {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
#include "Executor.h"
|
||||
#include "MessageQueueThread.h"
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
EXPORTED_HEADERS = [
|
||||
'JavaScriptCore.h',
|
||||
'JSCHelpers.h',
|
||||
'Value.h',
|
||||
'JSCWrapper.h',
|
||||
'noncopyable.h',
|
||||
'Unicode.h',
|
||||
'Value.h',
|
||||
]
|
||||
|
||||
if THIS_IS_FBANDROID:
|
||||
|
@ -30,26 +32,26 @@ if THIS_IS_FBANDROID:
|
|||
)
|
||||
|
||||
elif THIS_IS_FBOBJC:
|
||||
ios_library(
|
||||
name = 'jschelpers',
|
||||
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',
|
||||
],
|
||||
deps = [
|
||||
'//xplat/folly:molly',
|
||||
],
|
||||
visibility = [
|
||||
'PUBLIC',
|
||||
],
|
||||
)
|
||||
ios_library(
|
||||
name = 'jschelpers',
|
||||
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',
|
||||
],
|
||||
deps = [
|
||||
'//xplat/folly:molly',
|
||||
],
|
||||
visibility = [
|
||||
'PUBLIC',
|
||||
],
|
||||
)
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
#include <fbsystrace.h>
|
||||
#endif
|
||||
|
||||
#include <JavaScriptCore/JSStringRef.h>
|
||||
#include <folly/String.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "JavaScriptCore.h"
|
||||
#include "Value.h"
|
||||
|
||||
namespace facebook {
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Value.h"
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <JavaScriptCore/JSObjectRef.h>
|
||||
#include <JavaScriptCore/JSValueRef.h>
|
||||
#include <jschelpers/Value.h>
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
|
|
@ -128,4 +128,17 @@ const JSCWrapper *customJSCWrapper();
|
|||
|
||||
} }
|
||||
|
||||
#else
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
template <typename T>
|
||||
bool isCustomJSCPtr(T *x) {
|
||||
// Always use system JSC pointers
|
||||
return false;
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jschelpers/JSCWrapper.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
// Use for methods that are taking JSContextRef as a first param
|
||||
#define __jsc_wrapper(method, ctx, ...) \
|
||||
(facebook::react::isCustomJSCPtr(ctx) ? \
|
||||
facebook::react::customJSCWrapper() : \
|
||||
facebook::react::systemJSCWrapper() \
|
||||
)->method(ctx, ## __VA_ARGS__)
|
||||
|
||||
// Use for methods that don't take a JSContextRef as a first param. The wrapped version
|
||||
// of this method will require context as an additional param, but it will be dropped
|
||||
// before calling into the JSC method.
|
||||
#define __jsc_drop_ctx_wrapper(method, ctx, ...) \
|
||||
(facebook::react::isCustomJSCPtr(ctx) ? \
|
||||
facebook::react::customJSCWrapper() : \
|
||||
facebook::react::systemJSCWrapper() \
|
||||
)->method(__VA_ARGS__)
|
||||
|
||||
// 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() \
|
||||
)->method(__VA_ARGS__)
|
||||
|
||||
// Used for wrapping properties
|
||||
#define __jsc_prop_wrapper(prop, ctx) \
|
||||
(facebook::react::isCustomJSCPtr(ctx) ? \
|
||||
facebook::react::customJSCWrapper() : \
|
||||
facebook::react::systemJSCWrapper() \
|
||||
)->prop
|
||||
|
||||
#else
|
||||
|
||||
#define __jsc_wrapper(method, ctx, ...) method(ctx, ## __VA_ARGS__)
|
||||
#define __jsc_drop_ctx_wrapper(method, ctx, ...) ((void)ctx, method(__VA_ARGS__))
|
||||
#define __jsc_bool_wrapper(method, useCustomJSC, ...) \
|
||||
((void)useCustomJSC, method(__VA_ARGS__))
|
||||
#define __jsc_prop_wrapper(prop, ctx) prop
|
||||
|
||||
#endif
|
||||
|
||||
// JSGlobalContext
|
||||
#define JSC_JSGlobalContextCreateInGroup(...) __jsc_bool_wrapper(JSGlobalContextCreateInGroup, __VA_ARGS__)
|
||||
#define JSC_JSGlobalContextRelease(...) __jsc_wrapper(JSGlobalContextRelease, __VA_ARGS__)
|
||||
#define JSC_JSGlobalContextSetName(...) __jsc_wrapper(JSGlobalContextSetName, __VA_ARGS__)
|
||||
|
||||
// JSContext
|
||||
#define JSC_JSContextGetGlobalContext(...) __jsc_wrapper(JSContextGetGlobalContext, __VA_ARGS__)
|
||||
#define JSC_JSContextGetGlobalObject(...) __jsc_wrapper(JSContextGetGlobalObject, __VA_ARGS__)
|
||||
|
||||
// JSEvaluate
|
||||
#define JSC_JSEvaluateScript(...) __jsc_wrapper(JSEvaluateScript, __VA_ARGS__)
|
||||
#define JSC_JSEvaluateBytecodeBundle(...) __jsc_wrapper(JSEvaluateBytecodeBundle, __VA_ARGS__)
|
||||
|
||||
// JSString
|
||||
#define JSC_JSStringCreateWithCFString(...) __jsc_drop_ctx_wrapper(JSStringCreateWithCFString, __VA_ARGS__)
|
||||
#define JSC_JSStringCreateWithUTF8CString(...) __jsc_drop_ctx_wrapper(JSStringCreateWithUTF8CString, __VA_ARGS__)
|
||||
#define JSC_JSStringCreateWithUTF8CStringExpectAscii(...) __jsc_drop_ctx_wrapper(JSStringCreateWithUTF8CStringExpectAscii, __VA_ARGS__)
|
||||
#define JSC_JSStringCopyCFString(...) __jsc_drop_ctx_wrapper(JSStringCopyCFString, __VA_ARGS__)
|
||||
#define JSC_JSStringGetCharactersPtr(...) __jsc_drop_ctx_wrapper(JSStringGetCharactersPtr, __VA_ARGS__)
|
||||
#define JSC_JSStringGetLength(...) __jsc_drop_ctx_wrapper(JSStringGetLength, __VA_ARGS__)
|
||||
#define JSC_JSStringGetMaximumUTF8CStringSize(...) __jsc_drop_ctx_wrapper(JSStringGetMaximumUTF8CStringSize, __VA_ARGS__)
|
||||
#define JSC_JSStringIsEqualToUTF8CString(...) __jsc_drop_ctx_wrapper(JSStringIsEqualToUTF8CString, __VA_ARGS__)
|
||||
#define JSC_JSStringRelease(...) __jsc_drop_ctx_wrapper(JSStringRelease, __VA_ARGS__)
|
||||
#define JSC_JSStringRetain(...) __jsc_drop_ctx_wrapper(JSStringRetain, __VA_ARGS__)
|
||||
|
||||
// JSValueRef
|
||||
#define JSC_JSValueCreateJSONString(...) __jsc_wrapper(JSValueCreateJSONString, __VA_ARGS__)
|
||||
#define JSC_JSValueGetType(...) __jsc_wrapper(JSValueGetType, __VA_ARGS__)
|
||||
#define JSC_JSValueMakeFromJSONString(...) __jsc_wrapper(JSValueMakeFromJSONString, __VA_ARGS__)
|
||||
#define JSC_JSValueMakeBoolean(...) __jsc_wrapper(JSValueMakeBoolean, __VA_ARGS__)
|
||||
#define JSC_JSValueMakeNull(...) __jsc_wrapper(JSValueMakeNull, __VA_ARGS__)
|
||||
#define JSC_JSValueMakeNumber(...) __jsc_wrapper(JSValueMakeNumber, __VA_ARGS__)
|
||||
#define JSC_JSValueMakeString(...) __jsc_wrapper(JSValueMakeString, __VA_ARGS__)
|
||||
#define JSC_JSValueMakeUndefined(...) __jsc_wrapper(JSValueMakeUndefined, __VA_ARGS__)
|
||||
#define JSC_JSValueProtect(...) __jsc_wrapper(JSValueProtect, __VA_ARGS__)
|
||||
#define JSC_JSValueToBoolean(...) __jsc_wrapper(JSValueToBoolean, __VA_ARGS__)
|
||||
#define JSC_JSValueToNumber(...) __jsc_wrapper(JSValueToNumber, __VA_ARGS__)
|
||||
#define JSC_JSValueToObject(...) __jsc_wrapper(JSValueToObject, __VA_ARGS__)
|
||||
#define JSC_JSValueToStringCopy(...) __jsc_wrapper(JSValueToStringCopy, __VA_ARGS__)
|
||||
#define JSC_JSValueUnprotect(...) __jsc_wrapper(JSValueUnprotect, __VA_ARGS__)
|
||||
|
||||
// JSClass
|
||||
#define JSC_JSClassCreate(...) __jsc_bool_wrapper(JSClassCreate, __VA_ARGS__)
|
||||
#define JSC_JSClassRelease(...) __jsc_bool_wrapper(JSClassRelease, __VA_ARGS__)
|
||||
|
||||
// JSObject
|
||||
#define JSC_JSObjectCallAsConstructor(...) __jsc_wrapper(JSObjectCallAsConstructor, __VA_ARGS__)
|
||||
#define JSC_JSObjectCallAsFunction(...) __jsc_wrapper(JSObjectCallAsFunction, __VA_ARGS__)
|
||||
#define JSC_JSObjectGetPrivate(...) __jsc_bool_wrapper(JSObjectGetPrivate, __VA_ARGS__)
|
||||
#define JSC_JSObjectGetProperty(...) __jsc_wrapper(JSObjectGetProperty, __VA_ARGS__)
|
||||
#define JSC_JSObjectGetPropertyAtIndex(...) __jsc_wrapper(JSObjectGetPropertyAtIndex, __VA_ARGS__)
|
||||
#define JSC_JSObjectIsConstructor(...) __jsc_wrapper(JSObjectIsConstructor, __VA_ARGS__)
|
||||
#define JSC_JSObjectIsFunction(...) __jsc_wrapper(JSObjectIsFunction, __VA_ARGS__)
|
||||
#define JSC_JSObjectMake(...) __jsc_wrapper(JSObjectMake, __VA_ARGS__)
|
||||
#define JSC_JSObjectMakeArray(...) __jsc_wrapper(JSObjectMakeArray, __VA_ARGS__)
|
||||
#define JSC_JSObjectMakeError(...) __jsc_wrapper(JSObjectMakeError, __VA_ARGS__)
|
||||
#define JSC_JSObjectMakeFunctionWithCallback(...) __jsc_wrapper(JSObjectMakeFunctionWithCallback, __VA_ARGS__)
|
||||
#define JSC_JSObjectSetPrivate(...) __jsc_bool_wrapper(JSObjectSetPrivate, __VA_ARGS__)
|
||||
#define JSC_JSObjectSetProperty(...) __jsc_wrapper(JSObjectSetProperty, __VA_ARGS__)
|
||||
|
||||
// JSPropertyNameArray
|
||||
#define JSC_JSObjectCopyPropertyNames(...) __jsc_wrapper(JSObjectCopyPropertyNames, __VA_ARGS__)
|
||||
#define JSC_JSPropertyNameArrayGetCount(...) __jsc_drop_ctx_wrapper(JSPropertyNameArrayGetCount, __VA_ARGS__)
|
||||
#define JSC_JSPropertyNameArrayGetNameAtIndex(...) __jsc_drop_ctx_wrapper(JSPropertyNameArrayGetNameAtIndex, __VA_ARGS__)
|
||||
#define JSC_JSPropertyNameArrayRelease(...) __jsc_drop_ctx_wrapper(JSPropertyNameArrayRelease, __VA_ARGS__)
|
||||
|
||||
// Sampling profiler
|
||||
#define JSC_JSSamplingProfilerEnabled(...) __jsc_drop_ctx_wrapper(JSSamplingProfilerEnabled, __VA_ARGS__)
|
||||
#define JSC_JSPokeSamplingProfiler(...) __jsc_wrapper(JSPokeSamplingProfiler, __VA_ARGS__)
|
||||
#define JSC_JSStartSamplingProfilingOnMainJSCThread(...) __jsc_wrapper(JSStartSamplingProfilingOnMainJSCThread, __VA_ARGS__)
|
||||
|
||||
#define JSC_configureJSCForIOS(...) __jsc_bool_wrapper(configureJSCForIOS, __VA_ARGS__)
|
||||
|
||||
// Objective-C API
|
||||
#define JSC_JSContext(ctx) __jsc_prop_wrapper(JSContext, ctx)
|
||||
#define JSC_JSValue(ctx) __jsc_prop_wrapper(JSValue, ctx)
|
|
@ -5,6 +5,7 @@
|
|||
#include "Value.h"
|
||||
|
||||
#include "JSCHelpers.h"
|
||||
#include "JavaScriptCore.h"
|
||||
|
||||
// See the comment under Value::fromDynamic()
|
||||
#if !defined(__APPLE__) && defined(WITH_FB_JSC_TUNING)
|
||||
|
|
|
@ -7,19 +7,11 @@
|
|||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <JavaScriptCore/JSContextRef.h>
|
||||
#include <JavaScriptCore/JSObjectRef.h>
|
||||
#include <JavaScriptCore/JSStringRef.h>
|
||||
#include <JavaScriptCore/JSValueRef.h>
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
#include "noncopyable.h"
|
||||
#include "Unicode.h"
|
||||
|
||||
#if WITH_FBJSCEXTENSIONS
|
||||
#include <jsc_stringref.h>
|
||||
#endif
|
||||
#include <jschelpers/JavaScriptCore.h>
|
||||
#include <jschelpers/noncopyable.h>
|
||||
#include <jschelpers/Unicode.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
|
Загрузка…
Ссылка в новой задаче