2016-11-21 12:30:04 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-11-21 12:30:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
#include <functional>
|
2017-05-03 04:29:04 +00:00
|
|
|
#include <string>
|
2016-11-21 12:30:04 +00:00
|
|
|
#include <JavaScriptCore/JavaScript.h>
|
|
|
|
|
2017-05-03 04:29:04 +00:00
|
|
|
#if defined(JSCINTERNAL) || (!defined(__APPLE__))
|
|
|
|
#define JSC_IMPORT extern "C"
|
|
|
|
#else
|
|
|
|
#define JSC_IMPORT extern
|
|
|
|
#endif
|
|
|
|
|
2017-05-31 19:41:18 +00:00
|
|
|
#ifndef RN_EXPORT
|
|
|
|
#define RN_EXPORT __attribute__((visibility("default")))
|
|
|
|
#endif
|
|
|
|
|
2017-05-03 04:29:04 +00:00
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
class IInspector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
JSC_IMPORT void JSGlobalContextEnableDebugger(
|
|
|
|
JSGlobalContextRef ctx,
|
|
|
|
facebook::react::IInspector &globalInspector,
|
|
|
|
const char *title,
|
|
|
|
const std::function<bool()> &checkIsInspectedRemote);
|
|
|
|
JSC_IMPORT void JSGlobalContextDisableDebugger(
|
|
|
|
JSGlobalContextRef ctx,
|
|
|
|
facebook::react::IInspector &globalInspector);
|
2017-05-03 04:29:04 +00:00
|
|
|
|
|
|
|
// This is used to substitute an alternate JSC implementation for
|
|
|
|
// testing. These calls must all be ABI compatible with the standard JSC.
|
|
|
|
JSC_IMPORT JSValueRef JSEvaluateBytecodeBundle(JSContextRef, JSObjectRef, int, JSStringRef, JSValueRef*);
|
|
|
|
JSC_IMPORT bool JSSamplingProfilerEnabled();
|
|
|
|
JSC_IMPORT void JSStartSamplingProfilingOnMainJSCThread(JSGlobalContextRef);
|
|
|
|
JSC_IMPORT JSValueRef JSPokeSamplingProfiler(JSContextRef);
|
2017-11-02 15:07:25 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
JSC_IMPORT void configureJSCForIOS(std::string); // TODO: replace with folly::dynamic once supported
|
2017-05-31 18:04:00 +00:00
|
|
|
JSC_IMPORT void FBJSContextStartGCTimers(JSContextRef);
|
2017-11-02 15:07:25 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2017-05-03 04:29:04 +00:00
|
|
|
|
2016-11-21 12:30:04 +00:00
|
|
|
#if defined(__APPLE__)
|
2018-02-28 23:09:33 +00:00
|
|
|
#include <objc/objc.h>
|
|
|
|
#include <JavaScriptCore/JSStringRefCF.h>
|
|
|
|
#include <string>
|
2016-11-21 12:30:04 +00:00
|
|
|
|
2016-11-23 19:33:44 +00:00
|
|
|
/**
|
|
|
|
* JSNoBytecodeFileFormatVersion
|
|
|
|
*
|
|
|
|
* Version number indicating that bytecode is not supported by this runtime.
|
|
|
|
*/
|
2017-05-31 19:41:18 +00:00
|
|
|
RN_EXPORT extern const int32_t JSNoBytecodeFileFormatVersion;
|
2016-11-23 19:33:44 +00:00
|
|
|
|
2016-11-21 12:30:04 +00:00
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2016-11-22 17:38:22 +00:00
|
|
|
#define JSC_WRAPPER_METHOD(m) decltype(&m) m
|
2016-11-21 12:30:04 +00:00
|
|
|
|
|
|
|
struct JSCWrapper {
|
|
|
|
// JSGlobalContext
|
|
|
|
JSC_WRAPPER_METHOD(JSGlobalContextCreateInGroup);
|
|
|
|
JSC_WRAPPER_METHOD(JSGlobalContextRelease);
|
|
|
|
JSC_WRAPPER_METHOD(JSGlobalContextSetName);
|
|
|
|
|
|
|
|
// JSContext
|
|
|
|
JSC_WRAPPER_METHOD(JSContextGetGlobalContext);
|
|
|
|
JSC_WRAPPER_METHOD(JSContextGetGlobalObject);
|
2017-05-31 18:04:00 +00:00
|
|
|
JSC_WRAPPER_METHOD(FBJSContextStartGCTimers);
|
2016-11-21 12:30:04 +00:00
|
|
|
|
|
|
|
// JSEvaluate
|
|
|
|
JSC_WRAPPER_METHOD(JSEvaluateScript);
|
|
|
|
JSC_WRAPPER_METHOD(JSEvaluateBytecodeBundle);
|
|
|
|
|
|
|
|
// JSString
|
|
|
|
JSC_WRAPPER_METHOD(JSStringCreateWithUTF8CString);
|
|
|
|
JSC_WRAPPER_METHOD(JSStringCreateWithCFString);
|
2016-11-22 17:38:22 +00:00
|
|
|
#if WITH_FBJSCEXTENSIONS
|
2016-11-21 12:30:04 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSStringCreateWithUTF8CStringExpectAscii);
|
2016-11-22 17:38:22 +00:00
|
|
|
#endif
|
2016-11-21 12:30:04 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSStringCopyCFString);
|
|
|
|
JSC_WRAPPER_METHOD(JSStringGetCharactersPtr);
|
|
|
|
JSC_WRAPPER_METHOD(JSStringGetLength);
|
|
|
|
JSC_WRAPPER_METHOD(JSStringGetMaximumUTF8CStringSize);
|
|
|
|
JSC_WRAPPER_METHOD(JSStringIsEqualToUTF8CString);
|
|
|
|
JSC_WRAPPER_METHOD(JSStringRelease);
|
|
|
|
JSC_WRAPPER_METHOD(JSStringRetain);
|
|
|
|
|
|
|
|
// JSClass
|
|
|
|
JSC_WRAPPER_METHOD(JSClassCreate);
|
2018-05-15 01:56:51 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSClassRetain);
|
2016-11-21 12:30:04 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSClassRelease);
|
|
|
|
|
|
|
|
// JSObject
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectCallAsConstructor);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectCallAsFunction);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectGetPrivate);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectGetProperty);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectGetPropertyAtIndex);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectIsConstructor);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectIsFunction);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectMake);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectMakeArray);
|
2017-09-19 01:35:48 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSObjectMakeDate);
|
2016-11-21 12:30:04 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSObjectMakeError);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectMakeFunctionWithCallback);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectSetPrivate);
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectSetProperty);
|
2017-05-19 14:05:33 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSObjectSetPropertyAtIndex);
|
2016-11-21 12:30:04 +00:00
|
|
|
|
|
|
|
// JSPropertyNameArray
|
|
|
|
JSC_WRAPPER_METHOD(JSObjectCopyPropertyNames);
|
|
|
|
JSC_WRAPPER_METHOD(JSPropertyNameArrayGetCount);
|
|
|
|
JSC_WRAPPER_METHOD(JSPropertyNameArrayGetNameAtIndex);
|
|
|
|
JSC_WRAPPER_METHOD(JSPropertyNameArrayRelease);
|
|
|
|
|
|
|
|
// JSValue
|
|
|
|
JSC_WRAPPER_METHOD(JSValueCreateJSONString);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueGetType);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueMakeFromJSONString);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueMakeBoolean);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueMakeNull);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueMakeNumber);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueMakeString);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueMakeUndefined);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueProtect);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueToBoolean);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueToNumber);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueToObject);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueToStringCopy);
|
|
|
|
JSC_WRAPPER_METHOD(JSValueUnprotect);
|
2018-02-27 03:42:07 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSValueIsNull);
|
2016-11-21 12:30:04 +00:00
|
|
|
|
|
|
|
// Sampling profiler
|
|
|
|
JSC_WRAPPER_METHOD(JSSamplingProfilerEnabled);
|
|
|
|
JSC_WRAPPER_METHOD(JSPokeSamplingProfiler);
|
|
|
|
JSC_WRAPPER_METHOD(JSStartSamplingProfilingOnMainJSCThread);
|
|
|
|
|
2017-12-15 17:10:47 +00:00
|
|
|
JSC_WRAPPER_METHOD(JSGlobalContextEnableDebugger);
|
|
|
|
JSC_WRAPPER_METHOD(JSGlobalContextDisableDebugger);
|
2017-05-03 04:29:04 +00:00
|
|
|
|
2016-11-21 12:30:04 +00:00
|
|
|
JSC_WRAPPER_METHOD(configureJSCForIOS);
|
|
|
|
|
|
|
|
// Objective-C API
|
|
|
|
Class JSContext;
|
|
|
|
Class JSValue;
|
|
|
|
|
2016-11-22 17:38:22 +00:00
|
|
|
int32_t JSBytecodeFileFormatVersion;
|
2016-11-21 12:30:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool isCustomJSCPtr(T *x) {
|
|
|
|
return (uintptr_t)x & 0x1;
|
|
|
|
}
|
|
|
|
|
2017-05-31 19:41:18 +00:00
|
|
|
RN_EXPORT bool isCustomJSCWrapperSet();
|
|
|
|
RN_EXPORT void setCustomJSCWrapper(const JSCWrapper* wrapper);
|
2016-11-21 12:30:04 +00:00
|
|
|
|
|
|
|
// This will return a single value for the whole life of the process.
|
2017-05-31 19:41:18 +00:00
|
|
|
RN_EXPORT const JSCWrapper *systemJSCWrapper();
|
|
|
|
RN_EXPORT const JSCWrapper *customJSCWrapper();
|
2016-11-21 12:30:04 +00:00
|
|
|
|
|
|
|
} }
|
|
|
|
|
2016-11-22 14:05:36 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool isCustomJSCPtr(T *x) {
|
|
|
|
// Always use system JSC pointers
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
2016-11-21 12:30:04 +00:00
|
|
|
#endif
|