yeet
This commit is contained in:
5
node_modules/react-native/ReactCommon/jsi/.clang-tidy
generated
vendored
Normal file
5
node_modules/react-native/ReactCommon/jsi/.clang-tidy
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
Checks: '>
|
||||
clang-diagnostic-*,
|
||||
'
|
||||
...
|
35
node_modules/react-native/ReactCommon/jsi/Android.mk
generated
vendored
Normal file
35
node_modules/react-native/ReactCommon/jsi/Android.mk
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := jsi
|
||||
|
||||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/jsi/*.cpp)
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
|
||||
|
||||
LOCAL_CFLAGS := -fexceptions -frtti -O3
|
||||
LOCAL_SHARED_LIBRARIES := libfolly_json glog
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := jscruntime
|
||||
|
||||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
|
||||
|
||||
LOCAL_CFLAGS := -fexceptions -frtti -O3
|
||||
LOCAL_SHARED_LIBRARIES := libfolly_json libjsc glog
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
92
node_modules/react-native/ReactCommon/jsi/BUCK
generated
vendored
Normal file
92
node_modules/react-native/ReactCommon/jsi/BUCK
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
# BUILD FILE SYNTAX: SKYLARK
|
||||
|
||||
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "APPLE", "IOS", "MACOSX")
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_xplat_dep", "rn_xplat_cxx_library")
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "jsi",
|
||||
srcs = [
|
||||
"jsi/jsi.cpp",
|
||||
],
|
||||
header_namespace = "",
|
||||
exported_headers = [
|
||||
"jsi/instrumentation.h",
|
||||
"jsi/jsi.h",
|
||||
"jsi/jsi-inl.h",
|
||||
"jsi/jsilib.h",
|
||||
],
|
||||
compiler_flags = [
|
||||
"-O3",
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
"-std=c++14",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Wextra",
|
||||
"-Wcast-qual",
|
||||
"-Wdelete-non-virtual-dtor",
|
||||
"-Wwrite-strings",
|
||||
],
|
||||
cxx_compiler_flags = [
|
||||
"-Wglobal-constructors",
|
||||
"-Wmissing-prototypes",
|
||||
],
|
||||
fbobjc_compiler_flags = [
|
||||
"-Wglobal-constructors",
|
||||
"-Wmissing-prototypes",
|
||||
],
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "JSIDynamic",
|
||||
srcs = [
|
||||
"jsi/JSIDynamic.cpp",
|
||||
],
|
||||
header_namespace = "",
|
||||
exported_headers = [
|
||||
"jsi/JSIDynamic.h",
|
||||
],
|
||||
compiler_flags = [
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
],
|
||||
fbobjc_force_static = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
xcode_public_headers_symlinks = True,
|
||||
deps = [
|
||||
"//xplat/folly:molly",
|
||||
react_native_xplat_dep("jsi:jsi"),
|
||||
],
|
||||
)
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "JSCRuntime",
|
||||
srcs = [
|
||||
"JSCRuntime.cpp",
|
||||
],
|
||||
header_namespace = "jsi",
|
||||
exported_headers = [
|
||||
"JSCRuntime.h",
|
||||
],
|
||||
apple_sdks = (IOS, MACOSX),
|
||||
fbobjc_compiler_flags = [
|
||||
"-Os",
|
||||
],
|
||||
fbobjc_frameworks = [
|
||||
"$SDKROOT/System/Library/Frameworks/JavaScriptCore.framework",
|
||||
],
|
||||
fbobjc_labels = ["supermodule:ios/default/public.react_native.infra"],
|
||||
# TODO (T55502220): Remove when iOS 9.0 deprecation is complete everywhere.
|
||||
fbobjc_target_sdk_version = "9.0",
|
||||
platforms = APPLE,
|
||||
visibility = ["PUBLIC"],
|
||||
xplat_mangled_args = {
|
||||
"soname": "libjscjsi.$(ext)",
|
||||
},
|
||||
exported_deps = [
|
||||
react_native_xplat_dep("jsi:jsi"),
|
||||
],
|
||||
)
|
1473
node_modules/react-native/ReactCommon/jsi/JSCRuntime.cpp
generated
vendored
Normal file
1473
node_modules/react-native/ReactCommon/jsi/JSCRuntime.cpp
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
19
node_modules/react-native/ReactCommon/jsi/JSCRuntime.h
generated
vendored
Normal file
19
node_modules/react-native/ReactCommon/jsi/JSCRuntime.h
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jsi/jsi.h>
|
||||
#include <memory.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsc {
|
||||
|
||||
std::unique_ptr<jsi::Runtime> makeJSCRuntime();
|
||||
|
||||
} // namespace jsc
|
||||
} // namespace facebook
|
52
node_modules/react-native/ReactCommon/jsi/React-jsi.podspec
generated
vendored
Normal file
52
node_modules/react-native/ReactCommon/jsi/React-jsi.podspec
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
require "json"
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json")))
|
||||
version = package['version']
|
||||
|
||||
source = { :git => 'https://github.com/facebook/react-native.git' }
|
||||
if version == '1000.0.0'
|
||||
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
|
||||
source[:commit] = `git rev-parse HEAD`.strip
|
||||
else
|
||||
source[:tag] = "v#{version}"
|
||||
end
|
||||
|
||||
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
||||
folly_version = '2020.01.13.00'
|
||||
boost_compiler_flags = '-Wno-documentation'
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "React-jsi"
|
||||
s.version = version
|
||||
s.summary = "-" # TODO
|
||||
s.homepage = "https://reactnative.dev/"
|
||||
s.license = package["license"]
|
||||
s.author = "Facebook, Inc. and its affiliates"
|
||||
s.platforms = { :ios => "10.0", :tvos => "10.0" }
|
||||
s.source = source
|
||||
s.source_files = "**/*.{cpp,h}"
|
||||
s.exclude_files = "**/test/*"
|
||||
s.framework = "JavaScriptCore"
|
||||
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
|
||||
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/Folly\" \"$(PODS_ROOT)/DoubleConversion\"" }
|
||||
s.header_dir = "jsi"
|
||||
s.default_subspec = "Default"
|
||||
|
||||
s.dependency "boost-for-react-native", "1.63.0"
|
||||
s.dependency "DoubleConversion"
|
||||
s.dependency "Folly", folly_version
|
||||
s.dependency "glog"
|
||||
|
||||
s.subspec "Default" do
|
||||
# no-op
|
||||
end
|
||||
|
||||
s.subspec "Fabric" do |ss|
|
||||
ss.pod_target_xcconfig = { "OTHER_CFLAGS" => "$(inherited) -DRN_FABRIC_ENABLED" }
|
||||
end
|
||||
end
|
24
node_modules/react-native/ReactCommon/jsi/jsi/CMakeLists.txt
generated
vendored
Normal file
24
node_modules/react-native/ReactCommon/jsi/jsi/CMakeLists.txt
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_library(jsi
|
||||
jsi.cpp)
|
||||
|
||||
include_directories(..)
|
||||
|
||||
|
||||
set(jsi_compile_flags "")
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR
|
||||
"${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||
list(APPEND jsi_compile_flags "-Wno-non-virtual-dtor")
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
|
||||
# Turn on Error Handling in MSVC, otherwise objects are not destructed
|
||||
# when they go out of scope due to exceptions.
|
||||
list(APPEND jsi_compile_flags "/EHsc")
|
||||
endif()
|
||||
target_compile_options(jsi PUBLIC ${jsi_compile_flags})
|
104
node_modules/react-native/ReactCommon/jsi/jsi/JSIDynamic.cpp
generated
vendored
Normal file
104
node_modules/react-native/ReactCommon/jsi/jsi/JSIDynamic.cpp
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "JSIDynamic.h"
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
using namespace facebook::jsi;
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
Value valueFromDynamic(Runtime& runtime, const folly::dynamic& dyn) {
|
||||
switch (dyn.type()) {
|
||||
case folly::dynamic::NULLT:
|
||||
return Value::null();
|
||||
case folly::dynamic::ARRAY: {
|
||||
Array ret = Array(runtime, dyn.size());
|
||||
for (size_t i = 0; i < dyn.size(); ++i) {
|
||||
ret.setValueAtIndex(runtime, i, valueFromDynamic(runtime, dyn[i]));
|
||||
}
|
||||
return std::move(ret);
|
||||
}
|
||||
case folly::dynamic::BOOL:
|
||||
return dyn.getBool();
|
||||
case folly::dynamic::DOUBLE:
|
||||
return dyn.getDouble();
|
||||
case folly::dynamic::INT64:
|
||||
// Can't use asDouble() here. If the int64 value is too bit to be
|
||||
// represented precisely as a double, folly will throw an
|
||||
// exception.
|
||||
return (double)dyn.getInt();
|
||||
case folly::dynamic::OBJECT: {
|
||||
Object ret(runtime);
|
||||
for (const auto& element : dyn.items()) {
|
||||
Value value = valueFromDynamic(runtime, element.second);
|
||||
if (element.first.isNumber() || element.first.isString()) {
|
||||
ret.setProperty(
|
||||
runtime,
|
||||
PropNameID::forUtf8(runtime, element.first.asString()),
|
||||
value);
|
||||
}
|
||||
}
|
||||
return std::move(ret);
|
||||
}
|
||||
case folly::dynamic::STRING:
|
||||
return String::createFromUtf8(runtime, dyn.getString());
|
||||
}
|
||||
CHECK(false);
|
||||
}
|
||||
|
||||
folly::dynamic dynamicFromValue(Runtime& runtime, const Value& value) {
|
||||
if (value.isUndefined() || value.isNull()) {
|
||||
return nullptr;
|
||||
} else if (value.isBool()) {
|
||||
return value.getBool();
|
||||
} else if (value.isNumber()) {
|
||||
return value.getNumber();
|
||||
} else if (value.isString()) {
|
||||
return value.getString(runtime).utf8(runtime);
|
||||
} else {
|
||||
Object obj = value.getObject(runtime);
|
||||
if (obj.isArray(runtime)) {
|
||||
Array array = obj.getArray(runtime);
|
||||
folly::dynamic ret = folly::dynamic::array();
|
||||
for (size_t i = 0; i < array.size(runtime); ++i) {
|
||||
ret.push_back(
|
||||
dynamicFromValue(runtime, array.getValueAtIndex(runtime, i)));
|
||||
}
|
||||
return ret;
|
||||
} else if (obj.isFunction(runtime)) {
|
||||
throw JSError(runtime, "JS Functions are not convertible to dynamic");
|
||||
} else {
|
||||
folly::dynamic ret = folly::dynamic::object();
|
||||
Array names = obj.getPropertyNames(runtime);
|
||||
for (size_t i = 0; i < names.size(runtime); ++i) {
|
||||
String name = names.getValueAtIndex(runtime, i).getString(runtime);
|
||||
Value prop = obj.getProperty(runtime, name);
|
||||
if (prop.isUndefined()) {
|
||||
continue;
|
||||
}
|
||||
// The JSC conversion uses JSON.stringify, which substitutes
|
||||
// null for a function, so we do the same here. Just dropping
|
||||
// the pair might also work, but would require more testing.
|
||||
if (prop.isObject() && prop.getObject(runtime).isFunction(runtime)) {
|
||||
prop = Value::null();
|
||||
}
|
||||
ret.insert(
|
||||
name.utf8(runtime), dynamicFromValue(runtime, std::move(prop)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
25
node_modules/react-native/ReactCommon/jsi/jsi/JSIDynamic.h
generated
vendored
Normal file
25
node_modules/react-native/ReactCommon/jsi/jsi/JSIDynamic.h
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
facebook::jsi::Value valueFromDynamic(
|
||||
facebook::jsi::Runtime& runtime,
|
||||
const folly::dynamic& dyn);
|
||||
|
||||
folly::dynamic dynamicFromValue(
|
||||
facebook::jsi::Runtime& runtime,
|
||||
const facebook::jsi::Value& value);
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
730
node_modules/react-native/ReactCommon/jsi/jsi/decorator.h
generated
vendored
Normal file
730
node_modules/react-native/ReactCommon/jsi/jsi/decorator.h
generated
vendored
Normal file
@ -0,0 +1,730 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include <jsi/instrumentation.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
// This file contains objects to help API users create their own
|
||||
// runtime adapters, i.e. if you want to compose runtimes to add your
|
||||
// own behavior.
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
// Use this to wrap host functions. It will pass the member runtime as
|
||||
// the first arg to the callback. The first argument to the ctor
|
||||
// should be the decorated runtime, not the plain one.
|
||||
class DecoratedHostFunction {
|
||||
public:
|
||||
DecoratedHostFunction(Runtime& drt, HostFunctionType plainHF)
|
||||
: drt_(drt), plainHF_(std::move(plainHF)) {}
|
||||
|
||||
Runtime& decoratedRuntime() {
|
||||
return drt_;
|
||||
}
|
||||
|
||||
Value
|
||||
operator()(Runtime&, const Value& thisVal, const Value* args, size_t count) {
|
||||
return plainHF_(decoratedRuntime(), thisVal, args, count);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Plain, typename Base>
|
||||
friend class RuntimeDecorator;
|
||||
|
||||
Runtime& drt_;
|
||||
HostFunctionType plainHF_;
|
||||
};
|
||||
|
||||
// From the perspective of the caller, a plain HostObject is passed to
|
||||
// the decorated Runtime, and the HostObject methods expect to get
|
||||
// passed that Runtime. But the plain Runtime will pass itself to its
|
||||
// callback, so we need a helper here which curries the decorated
|
||||
// Runtime, and calls the plain HostObject with it.
|
||||
//
|
||||
// If the concrete RuntimeDecorator derives DecoratedHostObject, it
|
||||
// should call the base class get() and set() to invoke the plain
|
||||
// HostObject functionality. The Runtime& it passes does not matter,
|
||||
// as it is not used.
|
||||
class DecoratedHostObject : public HostObject {
|
||||
public:
|
||||
DecoratedHostObject(Runtime& drt, std::shared_ptr<HostObject> plainHO)
|
||||
: drt_(drt), plainHO_(plainHO) {}
|
||||
|
||||
// The derived class methods can call this to get a reference to the
|
||||
// decorated runtime, since the rt passed to the callback will be
|
||||
// the plain runtime.
|
||||
Runtime& decoratedRuntime() {
|
||||
return drt_;
|
||||
}
|
||||
|
||||
Value get(Runtime&, const PropNameID& name) override {
|
||||
return plainHO_->get(decoratedRuntime(), name);
|
||||
}
|
||||
|
||||
void set(Runtime&, const PropNameID& name, const Value& value) override {
|
||||
plainHO_->set(decoratedRuntime(), name, value);
|
||||
}
|
||||
|
||||
std::vector<PropNameID> getPropertyNames(Runtime&) override {
|
||||
return plainHO_->getPropertyNames(decoratedRuntime());
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Plain, typename Base>
|
||||
friend class RuntimeDecorator;
|
||||
|
||||
Runtime& drt_;
|
||||
std::shared_ptr<HostObject> plainHO_;
|
||||
};
|
||||
|
||||
/// C++ variant on a standard Decorator pattern, using template
|
||||
/// parameters. The \c Plain template parameter type is the
|
||||
/// undecorated Runtime type. You can usually use \c Runtime here,
|
||||
/// but if you know the concrete type ahead of time and it's final,
|
||||
/// the compiler can devirtualize calls to the decorated
|
||||
/// implementation. The \c Base template parameter type will be used
|
||||
/// as the base class of the decorated type. Here, too, you can
|
||||
/// usually use \c Runtime, but if you want the decorated type to
|
||||
/// implement a derived class of Runtime, you can specify that here.
|
||||
/// For an example, see threadsafe.h.
|
||||
template <typename Plain = Runtime, typename Base = Runtime>
|
||||
class RuntimeDecorator : public Base, private jsi::Instrumentation {
|
||||
public:
|
||||
Plain& plain() {
|
||||
static_assert(
|
||||
std::is_base_of<Runtime, Plain>::value,
|
||||
"RuntimeDecorator's Plain type must derive from jsi::Runtime");
|
||||
static_assert(
|
||||
std::is_base_of<Runtime, Base>::value,
|
||||
"RuntimeDecorator's Base type must derive from jsi::Runtime");
|
||||
return plain_;
|
||||
}
|
||||
const Plain& plain() const {
|
||||
return plain_;
|
||||
}
|
||||
|
||||
Value evaluateJavaScript(
|
||||
const std::shared_ptr<const Buffer>& buffer,
|
||||
const std::string& sourceURL) override {
|
||||
return plain().evaluateJavaScript(buffer, sourceURL);
|
||||
}
|
||||
std::shared_ptr<const PreparedJavaScript> prepareJavaScript(
|
||||
const std::shared_ptr<const Buffer>& buffer,
|
||||
std::string sourceURL) override {
|
||||
return plain().prepareJavaScript(buffer, std::move(sourceURL));
|
||||
}
|
||||
Value evaluatePreparedJavaScript(
|
||||
const std::shared_ptr<const PreparedJavaScript>& js) override {
|
||||
return plain().evaluatePreparedJavaScript(js);
|
||||
}
|
||||
Object global() override {
|
||||
return plain().global();
|
||||
}
|
||||
std::string description() override {
|
||||
return plain().description();
|
||||
};
|
||||
bool isInspectable() override {
|
||||
return plain().isInspectable();
|
||||
};
|
||||
Instrumentation& instrumentation() override {
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
// plain is generally going to be a reference to an object managed
|
||||
// by a derived class. We cache it here so this class can be
|
||||
// concrete, and avoid making virtual calls to find the plain
|
||||
// Runtime. Note that the ctor and dtor do not access through the
|
||||
// reference, so passing a reference to an object before its
|
||||
// lifetime has started is ok.
|
||||
RuntimeDecorator(Plain& plain) : plain_(plain) {}
|
||||
|
||||
Runtime::PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override {
|
||||
return plain_.cloneSymbol(pv);
|
||||
};
|
||||
Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override {
|
||||
return plain_.cloneString(pv);
|
||||
};
|
||||
Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override {
|
||||
return plain_.cloneObject(pv);
|
||||
};
|
||||
Runtime::PointerValue* clonePropNameID(
|
||||
const Runtime::PointerValue* pv) override {
|
||||
return plain_.clonePropNameID(pv);
|
||||
};
|
||||
|
||||
PropNameID createPropNameIDFromAscii(const char* str, size_t length)
|
||||
override {
|
||||
return plain_.createPropNameIDFromAscii(str, length);
|
||||
};
|
||||
PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length)
|
||||
override {
|
||||
return plain_.createPropNameIDFromUtf8(utf8, length);
|
||||
};
|
||||
PropNameID createPropNameIDFromString(const String& str) override {
|
||||
return plain_.createPropNameIDFromString(str);
|
||||
};
|
||||
std::string utf8(const PropNameID& id) override {
|
||||
return plain_.utf8(id);
|
||||
};
|
||||
bool compare(const PropNameID& a, const PropNameID& b) override {
|
||||
return plain_.compare(a, b);
|
||||
};
|
||||
|
||||
std::string symbolToString(const Symbol& sym) override {
|
||||
return plain_.symbolToString(sym);
|
||||
}
|
||||
|
||||
String createStringFromAscii(const char* str, size_t length) override {
|
||||
return plain_.createStringFromAscii(str, length);
|
||||
};
|
||||
String createStringFromUtf8(const uint8_t* utf8, size_t length) override {
|
||||
return plain_.createStringFromUtf8(utf8, length);
|
||||
};
|
||||
std::string utf8(const String& s) override {
|
||||
return plain_.utf8(s);
|
||||
}
|
||||
|
||||
Object createObject() override {
|
||||
return plain_.createObject();
|
||||
};
|
||||
|
||||
Object createObject(std::shared_ptr<HostObject> ho) override {
|
||||
return plain_.createObject(
|
||||
std::make_shared<DecoratedHostObject>(*this, std::move(ho)));
|
||||
};
|
||||
std::shared_ptr<HostObject> getHostObject(const jsi::Object& o) override {
|
||||
std::shared_ptr<HostObject> dho = plain_.getHostObject(o);
|
||||
return static_cast<DecoratedHostObject&>(*dho).plainHO_;
|
||||
};
|
||||
HostFunctionType& getHostFunction(const jsi::Function& f) override {
|
||||
HostFunctionType& dhf = plain_.getHostFunction(f);
|
||||
// This will fail if a cpp file including this header is not compiled
|
||||
// with RTTI.
|
||||
return dhf.target<DecoratedHostFunction>()->plainHF_;
|
||||
};
|
||||
|
||||
Value getProperty(const Object& o, const PropNameID& name) override {
|
||||
return plain_.getProperty(o, name);
|
||||
};
|
||||
Value getProperty(const Object& o, const String& name) override {
|
||||
return plain_.getProperty(o, name);
|
||||
};
|
||||
bool hasProperty(const Object& o, const PropNameID& name) override {
|
||||
return plain_.hasProperty(o, name);
|
||||
};
|
||||
bool hasProperty(const Object& o, const String& name) override {
|
||||
return plain_.hasProperty(o, name);
|
||||
};
|
||||
void setPropertyValue(Object& o, const PropNameID& name, const Value& value)
|
||||
override {
|
||||
plain_.setPropertyValue(o, name, value);
|
||||
};
|
||||
void setPropertyValue(Object& o, const String& name, const Value& value)
|
||||
override {
|
||||
plain_.setPropertyValue(o, name, value);
|
||||
};
|
||||
|
||||
bool isArray(const Object& o) const override {
|
||||
return plain_.isArray(o);
|
||||
};
|
||||
bool isArrayBuffer(const Object& o) const override {
|
||||
return plain_.isArrayBuffer(o);
|
||||
};
|
||||
bool isFunction(const Object& o) const override {
|
||||
return plain_.isFunction(o);
|
||||
};
|
||||
bool isHostObject(const jsi::Object& o) const override {
|
||||
return plain_.isHostObject(o);
|
||||
};
|
||||
bool isHostFunction(const jsi::Function& f) const override {
|
||||
return plain_.isHostFunction(f);
|
||||
};
|
||||
Array getPropertyNames(const Object& o) override {
|
||||
return plain_.getPropertyNames(o);
|
||||
};
|
||||
|
||||
WeakObject createWeakObject(const Object& o) override {
|
||||
return plain_.createWeakObject(o);
|
||||
};
|
||||
Value lockWeakObject(const WeakObject& wo) override {
|
||||
return plain_.lockWeakObject(wo);
|
||||
};
|
||||
|
||||
Array createArray(size_t length) override {
|
||||
return plain_.createArray(length);
|
||||
};
|
||||
size_t size(const Array& a) override {
|
||||
return plain_.size(a);
|
||||
};
|
||||
size_t size(const ArrayBuffer& ab) override {
|
||||
return plain_.size(ab);
|
||||
};
|
||||
uint8_t* data(const ArrayBuffer& ab) override {
|
||||
return plain_.data(ab);
|
||||
};
|
||||
Value getValueAtIndex(const Array& a, size_t i) override {
|
||||
return plain_.getValueAtIndex(a, i);
|
||||
};
|
||||
void setValueAtIndexImpl(Array& a, size_t i, const Value& value) override {
|
||||
plain_.setValueAtIndexImpl(a, i, value);
|
||||
};
|
||||
|
||||
Function createFunctionFromHostFunction(
|
||||
const PropNameID& name,
|
||||
unsigned int paramCount,
|
||||
HostFunctionType func) override {
|
||||
return plain_.createFunctionFromHostFunction(
|
||||
name, paramCount, DecoratedHostFunction(*this, std::move(func)));
|
||||
};
|
||||
Value call(
|
||||
const Function& f,
|
||||
const Value& jsThis,
|
||||
const Value* args,
|
||||
size_t count) override {
|
||||
return plain_.call(f, jsThis, args, count);
|
||||
};
|
||||
Value callAsConstructor(const Function& f, const Value* args, size_t count)
|
||||
override {
|
||||
return plain_.callAsConstructor(f, args, count);
|
||||
};
|
||||
|
||||
// Private data for managing scopes.
|
||||
Runtime::ScopeState* pushScope() override {
|
||||
return plain_.pushScope();
|
||||
}
|
||||
void popScope(Runtime::ScopeState* ss) override {
|
||||
plain_.popScope(ss);
|
||||
}
|
||||
|
||||
bool strictEquals(const Symbol& a, const Symbol& b) const override {
|
||||
return plain_.strictEquals(a, b);
|
||||
};
|
||||
bool strictEquals(const String& a, const String& b) const override {
|
||||
return plain_.strictEquals(a, b);
|
||||
};
|
||||
bool strictEquals(const Object& a, const Object& b) const override {
|
||||
return plain_.strictEquals(a, b);
|
||||
};
|
||||
|
||||
bool instanceOf(const Object& o, const Function& f) override {
|
||||
return plain_.instanceOf(o, f);
|
||||
};
|
||||
|
||||
// jsi::Instrumentation methods
|
||||
|
||||
std::string getRecordedGCStats() override {
|
||||
return plain().instrumentation().getRecordedGCStats();
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, int64_t> getHeapInfo(
|
||||
bool includeExpensive) override {
|
||||
return plain().instrumentation().getHeapInfo(includeExpensive);
|
||||
}
|
||||
|
||||
void collectGarbage() override {
|
||||
plain().instrumentation().collectGarbage();
|
||||
}
|
||||
|
||||
void startTrackingHeapObjectStackTraces() override {
|
||||
plain().instrumentation().startTrackingHeapObjectStackTraces();
|
||||
}
|
||||
|
||||
void stopTrackingHeapObjectStackTraces() override {
|
||||
plain().instrumentation().stopTrackingHeapObjectStackTraces();
|
||||
}
|
||||
|
||||
void createSnapshotToFile(const std::string& path) override {
|
||||
plain().instrumentation().createSnapshotToFile(path);
|
||||
}
|
||||
|
||||
void createSnapshotToStream(std::ostream& os) override {
|
||||
plain().instrumentation().createSnapshotToStream(os);
|
||||
}
|
||||
|
||||
std::string flushAndDisableBridgeTrafficTrace() override {
|
||||
return const_cast<Plain&>(plain())
|
||||
.instrumentation()
|
||||
.flushAndDisableBridgeTrafficTrace();
|
||||
}
|
||||
|
||||
void writeBasicBlockProfileTraceToFile(
|
||||
const std::string& fileName) const override {
|
||||
const_cast<Plain&>(plain())
|
||||
.instrumentation()
|
||||
.writeBasicBlockProfileTraceToFile(fileName);
|
||||
}
|
||||
|
||||
/// Dump external profiler symbols to the given file name.
|
||||
void dumpProfilerSymbolsToFile(const std::string& fileName) const override {
|
||||
const_cast<Plain&>(plain()).instrumentation().dumpProfilerSymbolsToFile(
|
||||
fileName);
|
||||
}
|
||||
|
||||
private:
|
||||
Plain& plain_;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// This metaprogramming allows the With type's methods to be
|
||||
// optional.
|
||||
|
||||
template <typename T, typename U = void>
|
||||
struct BeforeCaller {
|
||||
static void before(T&) {}
|
||||
};
|
||||
|
||||
template <typename T, typename U = void>
|
||||
struct AfterCaller {
|
||||
static void after(T&) {}
|
||||
};
|
||||
|
||||
// decltype((void)&...) is either SFINAE, or void.
|
||||
// So, if SFINAE does not happen for T, then this specialization exists
|
||||
// for BeforeCaller<T, void>, and always applies. If not, only the
|
||||
// default above exists, and that is used instead.
|
||||
template <typename T>
|
||||
struct BeforeCaller<T, decltype((void)&T::before)> {
|
||||
static void before(T& t) {
|
||||
t.before();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct AfterCaller<T, decltype((void)&T::after)> {
|
||||
static void after(T& t) {
|
||||
t.after();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// A decorator which implements an around idiom. A With instance is
|
||||
// RAII constructed before each call to the undecorated class; the
|
||||
// ctor is passed a single argument of type WithArg&. Plain and Base
|
||||
// are used as in the base class.
|
||||
template <typename With, typename Plain = Runtime, typename Base = Runtime>
|
||||
class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> {
|
||||
public:
|
||||
using RD = RuntimeDecorator<Plain, Base>;
|
||||
|
||||
// The reference arguments to the ctor are stored, but not used by
|
||||
// the ctor, and there is no ctor, so they can be passed members of
|
||||
// the derived class.
|
||||
WithRuntimeDecorator(Plain& plain, With& with) : RD(plain), with_(with) {}
|
||||
|
||||
Value evaluateJavaScript(
|
||||
const std::shared_ptr<const Buffer>& buffer,
|
||||
const std::string& sourceURL) override {
|
||||
Around around{with_};
|
||||
return RD::evaluateJavaScript(buffer, sourceURL);
|
||||
}
|
||||
std::shared_ptr<const PreparedJavaScript> prepareJavaScript(
|
||||
const std::shared_ptr<const Buffer>& buffer,
|
||||
std::string sourceURL) override {
|
||||
Around around{with_};
|
||||
return RD::prepareJavaScript(buffer, std::move(sourceURL));
|
||||
}
|
||||
Value evaluatePreparedJavaScript(
|
||||
const std::shared_ptr<const PreparedJavaScript>& js) override {
|
||||
Around around{with_};
|
||||
return RD::evaluatePreparedJavaScript(js);
|
||||
}
|
||||
Object global() override {
|
||||
Around around{with_};
|
||||
return RD::global();
|
||||
}
|
||||
std::string description() override {
|
||||
Around around{with_};
|
||||
return RD::description();
|
||||
};
|
||||
bool isInspectable() override {
|
||||
Around around{with_};
|
||||
return RD::isInspectable();
|
||||
};
|
||||
|
||||
// The jsi:: prefix is necessary because MSVC compiler complains C2247:
|
||||
// Instrumentation is not accessible because RuntimeDecorator uses private
|
||||
// to inherit from Instrumentation.
|
||||
// TODO(T40821815) Consider removing this workaround when updating MSVC
|
||||
jsi::Instrumentation& instrumentation() override {
|
||||
Around around{with_};
|
||||
return RD::instrumentation();
|
||||
}
|
||||
|
||||
protected:
|
||||
Runtime::PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override {
|
||||
Around around{with_};
|
||||
return RD::cloneSymbol(pv);
|
||||
};
|
||||
Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override {
|
||||
Around around{with_};
|
||||
return RD::cloneString(pv);
|
||||
};
|
||||
Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override {
|
||||
Around around{with_};
|
||||
return RD::cloneObject(pv);
|
||||
};
|
||||
Runtime::PointerValue* clonePropNameID(
|
||||
const Runtime::PointerValue* pv) override {
|
||||
Around around{with_};
|
||||
return RD::clonePropNameID(pv);
|
||||
};
|
||||
|
||||
PropNameID createPropNameIDFromAscii(const char* str, size_t length)
|
||||
override {
|
||||
Around around{with_};
|
||||
return RD::createPropNameIDFromAscii(str, length);
|
||||
};
|
||||
PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length)
|
||||
override {
|
||||
Around around{with_};
|
||||
return RD::createPropNameIDFromUtf8(utf8, length);
|
||||
};
|
||||
PropNameID createPropNameIDFromString(const String& str) override {
|
||||
Around around{with_};
|
||||
return RD::createPropNameIDFromString(str);
|
||||
};
|
||||
std::string utf8(const PropNameID& id) override {
|
||||
Around around{with_};
|
||||
return RD::utf8(id);
|
||||
};
|
||||
bool compare(const PropNameID& a, const PropNameID& b) override {
|
||||
Around around{with_};
|
||||
return RD::compare(a, b);
|
||||
};
|
||||
|
||||
std::string symbolToString(const Symbol& sym) override {
|
||||
Around around{with_};
|
||||
return RD::symbolToString(sym);
|
||||
};
|
||||
|
||||
String createStringFromAscii(const char* str, size_t length) override {
|
||||
Around around{with_};
|
||||
return RD::createStringFromAscii(str, length);
|
||||
};
|
||||
String createStringFromUtf8(const uint8_t* utf8, size_t length) override {
|
||||
Around around{with_};
|
||||
return RD::createStringFromUtf8(utf8, length);
|
||||
};
|
||||
std::string utf8(const String& s) override {
|
||||
Around around{with_};
|
||||
return RD::utf8(s);
|
||||
}
|
||||
|
||||
Object createObject() override {
|
||||
Around around{with_};
|
||||
return RD::createObject();
|
||||
};
|
||||
Object createObject(std::shared_ptr<HostObject> ho) override {
|
||||
Around around{with_};
|
||||
return RD::createObject(std::move(ho));
|
||||
};
|
||||
std::shared_ptr<HostObject> getHostObject(const jsi::Object& o) override {
|
||||
Around around{with_};
|
||||
return RD::getHostObject(o);
|
||||
};
|
||||
HostFunctionType& getHostFunction(const jsi::Function& f) override {
|
||||
Around around{with_};
|
||||
return RD::getHostFunction(f);
|
||||
};
|
||||
|
||||
Value getProperty(const Object& o, const PropNameID& name) override {
|
||||
Around around{with_};
|
||||
return RD::getProperty(o, name);
|
||||
};
|
||||
Value getProperty(const Object& o, const String& name) override {
|
||||
Around around{with_};
|
||||
return RD::getProperty(o, name);
|
||||
};
|
||||
bool hasProperty(const Object& o, const PropNameID& name) override {
|
||||
Around around{with_};
|
||||
return RD::hasProperty(o, name);
|
||||
};
|
||||
bool hasProperty(const Object& o, const String& name) override {
|
||||
Around around{with_};
|
||||
return RD::hasProperty(o, name);
|
||||
};
|
||||
void setPropertyValue(Object& o, const PropNameID& name, const Value& value)
|
||||
override {
|
||||
Around around{with_};
|
||||
RD::setPropertyValue(o, name, value);
|
||||
};
|
||||
void setPropertyValue(Object& o, const String& name, const Value& value)
|
||||
override {
|
||||
Around around{with_};
|
||||
RD::setPropertyValue(o, name, value);
|
||||
};
|
||||
|
||||
bool isArray(const Object& o) const override {
|
||||
Around around{with_};
|
||||
return RD::isArray(o);
|
||||
};
|
||||
bool isArrayBuffer(const Object& o) const override {
|
||||
Around around{with_};
|
||||
return RD::isArrayBuffer(o);
|
||||
};
|
||||
bool isFunction(const Object& o) const override {
|
||||
Around around{with_};
|
||||
return RD::isFunction(o);
|
||||
};
|
||||
bool isHostObject(const jsi::Object& o) const override {
|
||||
Around around{with_};
|
||||
return RD::isHostObject(o);
|
||||
};
|
||||
bool isHostFunction(const jsi::Function& f) const override {
|
||||
Around around{with_};
|
||||
return RD::isHostFunction(f);
|
||||
};
|
||||
Array getPropertyNames(const Object& o) override {
|
||||
Around around{with_};
|
||||
return RD::getPropertyNames(o);
|
||||
};
|
||||
|
||||
WeakObject createWeakObject(const Object& o) override {
|
||||
Around around{with_};
|
||||
return RD::createWeakObject(o);
|
||||
};
|
||||
Value lockWeakObject(const WeakObject& wo) override {
|
||||
Around around{with_};
|
||||
return RD::lockWeakObject(wo);
|
||||
};
|
||||
|
||||
Array createArray(size_t length) override {
|
||||
Around around{with_};
|
||||
return RD::createArray(length);
|
||||
};
|
||||
size_t size(const Array& a) override {
|
||||
Around around{with_};
|
||||
return RD::size(a);
|
||||
};
|
||||
size_t size(const ArrayBuffer& ab) override {
|
||||
Around around{with_};
|
||||
return RD::size(ab);
|
||||
};
|
||||
uint8_t* data(const ArrayBuffer& ab) override {
|
||||
Around around{with_};
|
||||
return RD::data(ab);
|
||||
};
|
||||
Value getValueAtIndex(const Array& a, size_t i) override {
|
||||
Around around{with_};
|
||||
return RD::getValueAtIndex(a, i);
|
||||
};
|
||||
void setValueAtIndexImpl(Array& a, size_t i, const Value& value) override {
|
||||
Around around{with_};
|
||||
RD::setValueAtIndexImpl(a, i, value);
|
||||
};
|
||||
|
||||
Function createFunctionFromHostFunction(
|
||||
const PropNameID& name,
|
||||
unsigned int paramCount,
|
||||
HostFunctionType func) override {
|
||||
Around around{with_};
|
||||
return RD::createFunctionFromHostFunction(
|
||||
name, paramCount, std::move(func));
|
||||
};
|
||||
Value call(
|
||||
const Function& f,
|
||||
const Value& jsThis,
|
||||
const Value* args,
|
||||
size_t count) override {
|
||||
Around around{with_};
|
||||
return RD::call(f, jsThis, args, count);
|
||||
};
|
||||
Value callAsConstructor(const Function& f, const Value* args, size_t count)
|
||||
override {
|
||||
Around around{with_};
|
||||
return RD::callAsConstructor(f, args, count);
|
||||
};
|
||||
|
||||
// Private data for managing scopes.
|
||||
Runtime::ScopeState* pushScope() override {
|
||||
Around around{with_};
|
||||
return RD::pushScope();
|
||||
}
|
||||
void popScope(Runtime::ScopeState* ss) override {
|
||||
Around around{with_};
|
||||
RD::popScope(ss);
|
||||
}
|
||||
|
||||
bool strictEquals(const Symbol& a, const Symbol& b) const override {
|
||||
Around around{with_};
|
||||
return RD::strictEquals(a, b);
|
||||
};
|
||||
bool strictEquals(const String& a, const String& b) const override {
|
||||
Around around{with_};
|
||||
return RD::strictEquals(a, b);
|
||||
};
|
||||
bool strictEquals(const Object& a, const Object& b) const override {
|
||||
Around around{with_};
|
||||
return RD::strictEquals(a, b);
|
||||
};
|
||||
|
||||
bool instanceOf(const Object& o, const Function& f) override {
|
||||
Around around{with_};
|
||||
return RD::instanceOf(o, f);
|
||||
};
|
||||
|
||||
private:
|
||||
// Wrap an RAII type around With& to guarantee after always happens.
|
||||
struct Around {
|
||||
Around(With& with) : with_(with) {
|
||||
detail::BeforeCaller<With>::before(with_);
|
||||
}
|
||||
~Around() {
|
||||
detail::AfterCaller<With>::after(with_);
|
||||
}
|
||||
|
||||
With& with_;
|
||||
};
|
||||
|
||||
With& with_;
|
||||
};
|
||||
|
||||
// Nesting WithRuntimeDecorator will work, but using this as the With
|
||||
// type will be easier to read, write, and understand.
|
||||
template <typename... T>
|
||||
class WithTuple : public std::tuple<T...> {
|
||||
public:
|
||||
using std::tuple<T...>::tuple;
|
||||
|
||||
void before() {
|
||||
all_before<0, T...>();
|
||||
}
|
||||
|
||||
void after() {
|
||||
all_after<0, T...>();
|
||||
}
|
||||
|
||||
private:
|
||||
template <size_t N, typename U, typename... Rest>
|
||||
void all_before() {
|
||||
detail::BeforeCaller<U>::before(std::get<N>(*this));
|
||||
all_before<N + 1, Rest...>();
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
void all_before() {}
|
||||
|
||||
template <size_t N, typename U, typename... Rest>
|
||||
void all_after() {
|
||||
all_after<N + 1, Rest...>();
|
||||
detail::AfterCaller<U>::after(std::get<N>(*this));
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
void all_after() {}
|
||||
};
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
87
node_modules/react-native/ReactCommon/jsi/jsi/instrumentation.h
generated
vendored
Normal file
87
node_modules/react-native/ReactCommon/jsi/jsi/instrumentation.h
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
/// Methods for starting and collecting instrumentation, an \c Instrumentation
|
||||
/// instance is associated with a particular \c Runtime instance, which it
|
||||
/// controls the instrumentation of.
|
||||
/// None of these functions should return newly created jsi values, nor should
|
||||
/// it modify the values of any jsi values in the heap (although GCs are fine).
|
||||
class Instrumentation {
|
||||
public:
|
||||
virtual ~Instrumentation() = default;
|
||||
|
||||
/// Returns GC statistics as a JSON-encoded string, with an object containing
|
||||
/// "type" and "version" fields outermost. "type" is a string, unique to a
|
||||
/// particular implementation of \c jsi::Instrumentation, and "version" is a
|
||||
/// number to indicate any revision to that implementation and its output
|
||||
/// format.
|
||||
///
|
||||
/// \pre This call can only be made on the instrumentation instance of a
|
||||
/// runtime initialised to collect GC statistics.
|
||||
///
|
||||
/// \post All cumulative measurements mentioned in the output are accumulated
|
||||
/// across the entire lifetime of the Runtime.
|
||||
///
|
||||
/// \return the GC statistics collected so far, as a JSON-encoded string.
|
||||
virtual std::string getRecordedGCStats() = 0;
|
||||
|
||||
/// Request statistics about the current state of the runtime's heap. This
|
||||
/// function can be called at any time, and should produce information that is
|
||||
/// correct at the instant it is called (i.e, not stale).
|
||||
///
|
||||
/// \return a map from a string key to a number associated with that
|
||||
/// statistic.
|
||||
virtual std::unordered_map<std::string, int64_t> getHeapInfo(
|
||||
bool includeExpensive) = 0;
|
||||
|
||||
/// perform a full garbage collection
|
||||
virtual void collectGarbage() = 0;
|
||||
|
||||
/// Start capturing JS stack-traces for all JS heap allocated objects. These
|
||||
/// can be accessed via \c ::createSnapshotToFile().
|
||||
virtual void startTrackingHeapObjectStackTraces() = 0;
|
||||
|
||||
/// Stop capture JS stack-traces for JS heap allocated objects.
|
||||
virtual void stopTrackingHeapObjectStackTraces() = 0;
|
||||
|
||||
/// Captures the heap to a file
|
||||
///
|
||||
/// \param path to save the heap capture
|
||||
virtual void createSnapshotToFile(const std::string& path) = 0;
|
||||
|
||||
/// Captures the heap to an output stream
|
||||
///
|
||||
/// \param os output stream to write to.
|
||||
virtual void createSnapshotToStream(std::ostream& os) = 0;
|
||||
|
||||
/// If the runtime has been created to trace to a temp file, flush
|
||||
/// any unwritten parts of the trace of bridge traffic to the file,
|
||||
/// and return the name of the file. Otherwise, return the empty string.
|
||||
/// Tracing is disabled after this call.
|
||||
virtual std::string flushAndDisableBridgeTrafficTrace() = 0;
|
||||
|
||||
/// Write basic block profile trace to the given file name.
|
||||
virtual void writeBasicBlockProfileTraceToFile(
|
||||
const std::string& fileName) const = 0;
|
||||
|
||||
/// Dump external profiler symbols to the given file name.
|
||||
virtual void dumpProfilerSymbolsToFile(const std::string& fileName) const = 0;
|
||||
};
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
312
node_modules/react-native/ReactCommon/jsi/jsi/jsi-inl.h
generated
vendored
Normal file
312
node_modules/react-native/ReactCommon/jsi/jsi/jsi-inl.h
generated
vendored
Normal file
@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
namespace detail {
|
||||
|
||||
inline Value toValue(Runtime&, std::nullptr_t) {
|
||||
return Value::null();
|
||||
}
|
||||
inline Value toValue(Runtime&, bool b) {
|
||||
return Value(b);
|
||||
}
|
||||
inline Value toValue(Runtime&, double d) {
|
||||
return Value(d);
|
||||
}
|
||||
inline Value toValue(Runtime&, float f) {
|
||||
return Value(static_cast<double>(f));
|
||||
}
|
||||
inline Value toValue(Runtime&, int i) {
|
||||
return Value(i);
|
||||
}
|
||||
inline Value toValue(Runtime& runtime, const char* str) {
|
||||
return String::createFromAscii(runtime, str);
|
||||
}
|
||||
inline Value toValue(Runtime& runtime, const std::string& str) {
|
||||
return String::createFromUtf8(runtime, str);
|
||||
}
|
||||
template <typename T>
|
||||
inline Value toValue(Runtime& runtime, const T& other) {
|
||||
static_assert(
|
||||
std::is_base_of<Pointer, T>::value,
|
||||
"This type cannot be converted to Value");
|
||||
return Value(runtime, other);
|
||||
}
|
||||
inline Value toValue(Runtime& runtime, const Value& value) {
|
||||
return Value(runtime, value);
|
||||
}
|
||||
inline Value&& toValue(Runtime&, Value&& value) {
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
inline PropNameID toPropNameID(Runtime& runtime, const char* name) {
|
||||
return PropNameID::forAscii(runtime, name);
|
||||
}
|
||||
inline PropNameID toPropNameID(Runtime& runtime, const std::string& name) {
|
||||
return PropNameID::forUtf8(runtime, name);
|
||||
}
|
||||
inline PropNameID&& toPropNameID(Runtime&, PropNameID&& name) {
|
||||
return std::move(name);
|
||||
}
|
||||
|
||||
void throwJSError(Runtime&, const char* msg);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
inline T Runtime::make(Runtime::PointerValue* pv) {
|
||||
return T(pv);
|
||||
}
|
||||
|
||||
inline const Runtime::PointerValue* Runtime::getPointerValue(
|
||||
const jsi::Pointer& pointer) {
|
||||
return pointer.ptr_;
|
||||
}
|
||||
|
||||
inline const Runtime::PointerValue* Runtime::getPointerValue(
|
||||
const jsi::Value& value) {
|
||||
return value.data_.pointer.ptr_;
|
||||
}
|
||||
|
||||
inline Value Object::getProperty(Runtime& runtime, const char* name) const {
|
||||
return getProperty(runtime, String::createFromAscii(runtime, name));
|
||||
}
|
||||
|
||||
inline Value Object::getProperty(Runtime& runtime, const String& name) const {
|
||||
return runtime.getProperty(*this, name);
|
||||
}
|
||||
|
||||
inline Value Object::getProperty(Runtime& runtime, const PropNameID& name)
|
||||
const {
|
||||
return runtime.getProperty(*this, name);
|
||||
}
|
||||
|
||||
inline bool Object::hasProperty(Runtime& runtime, const char* name) const {
|
||||
return hasProperty(runtime, String::createFromAscii(runtime, name));
|
||||
}
|
||||
|
||||
inline bool Object::hasProperty(Runtime& runtime, const String& name) const {
|
||||
return runtime.hasProperty(*this, name);
|
||||
}
|
||||
|
||||
inline bool Object::hasProperty(Runtime& runtime, const PropNameID& name)
|
||||
const {
|
||||
return runtime.hasProperty(*this, name);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Object::setProperty(Runtime& runtime, const char* name, T&& value) {
|
||||
setProperty(
|
||||
runtime, String::createFromAscii(runtime, name), std::forward<T>(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Object::setProperty(Runtime& runtime, const String& name, T&& value) {
|
||||
setPropertyValue(
|
||||
runtime, name, detail::toValue(runtime, std::forward<T>(value)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Object::setProperty(Runtime& runtime, const PropNameID& name, T&& value) {
|
||||
setPropertyValue(
|
||||
runtime, name, detail::toValue(runtime, std::forward<T>(value)));
|
||||
}
|
||||
|
||||
inline Array Object::getArray(Runtime& runtime) const& {
|
||||
assert(runtime.isArray(*this));
|
||||
(void)runtime; // when assert is disabled we need to mark this as used
|
||||
return Array(runtime.cloneObject(ptr_));
|
||||
}
|
||||
|
||||
inline Array Object::getArray(Runtime& runtime) && {
|
||||
assert(runtime.isArray(*this));
|
||||
(void)runtime; // when assert is disabled we need to mark this as used
|
||||
Runtime::PointerValue* value = ptr_;
|
||||
ptr_ = nullptr;
|
||||
return Array(value);
|
||||
}
|
||||
|
||||
inline ArrayBuffer Object::getArrayBuffer(Runtime& runtime) const& {
|
||||
assert(runtime.isArrayBuffer(*this));
|
||||
(void)runtime; // when assert is disabled we need to mark this as used
|
||||
return ArrayBuffer(runtime.cloneObject(ptr_));
|
||||
}
|
||||
|
||||
inline ArrayBuffer Object::getArrayBuffer(Runtime& runtime) && {
|
||||
assert(runtime.isArrayBuffer(*this));
|
||||
(void)runtime; // when assert is disabled we need to mark this as used
|
||||
Runtime::PointerValue* value = ptr_;
|
||||
ptr_ = nullptr;
|
||||
return ArrayBuffer(value);
|
||||
}
|
||||
|
||||
inline Function Object::getFunction(Runtime& runtime) const& {
|
||||
assert(runtime.isFunction(*this));
|
||||
return Function(runtime.cloneObject(ptr_));
|
||||
}
|
||||
|
||||
inline Function Object::getFunction(Runtime& runtime) && {
|
||||
assert(runtime.isFunction(*this));
|
||||
(void)runtime; // when assert is disabled we need to mark this as used
|
||||
Runtime::PointerValue* value = ptr_;
|
||||
ptr_ = nullptr;
|
||||
return Function(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool Object::isHostObject(Runtime& runtime) const {
|
||||
return runtime.isHostObject(*this) &&
|
||||
std::dynamic_pointer_cast<T>(runtime.getHostObject(*this));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool Object::isHostObject<HostObject>(Runtime& runtime) const {
|
||||
return runtime.isHostObject(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::shared_ptr<T> Object::getHostObject(Runtime& runtime) const {
|
||||
assert(isHostObject<T>(runtime));
|
||||
return std::static_pointer_cast<T>(runtime.getHostObject(*this));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::shared_ptr<T> Object::asHostObject(Runtime& runtime) const {
|
||||
if (!isHostObject<T>(runtime)) {
|
||||
detail::throwJSError(runtime, "Object is not a HostObject of desired type");
|
||||
}
|
||||
return std::static_pointer_cast<T>(runtime.getHostObject(*this));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::shared_ptr<HostObject> Object::getHostObject<HostObject>(
|
||||
Runtime& runtime) const {
|
||||
assert(runtime.isHostObject(*this));
|
||||
return runtime.getHostObject(*this);
|
||||
}
|
||||
|
||||
inline Array Object::getPropertyNames(Runtime& runtime) const {
|
||||
return runtime.getPropertyNames(*this);
|
||||
}
|
||||
|
||||
inline Value WeakObject::lock(Runtime& runtime) {
|
||||
return runtime.lockWeakObject(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Array::setValueAtIndex(Runtime& runtime, size_t i, T&& value) {
|
||||
setValueAtIndexImpl(
|
||||
runtime, i, detail::toValue(runtime, std::forward<T>(value)));
|
||||
}
|
||||
|
||||
inline Value Array::getValueAtIndex(Runtime& runtime, size_t i) const {
|
||||
return runtime.getValueAtIndex(*this, i);
|
||||
}
|
||||
|
||||
inline Function Function::createFromHostFunction(
|
||||
Runtime& runtime,
|
||||
const jsi::PropNameID& name,
|
||||
unsigned int paramCount,
|
||||
jsi::HostFunctionType func) {
|
||||
return runtime.createFunctionFromHostFunction(
|
||||
name, paramCount, std::move(func));
|
||||
}
|
||||
|
||||
inline Value Function::call(Runtime& runtime, const Value* args, size_t count)
|
||||
const {
|
||||
return runtime.call(*this, Value::undefined(), args, count);
|
||||
}
|
||||
|
||||
inline Value Function::call(Runtime& runtime, std::initializer_list<Value> args)
|
||||
const {
|
||||
return call(runtime, args.begin(), args.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline Value Function::call(Runtime& runtime, Args&&... args) const {
|
||||
// A more awesome version of this would be able to create raw values
|
||||
// which can be used directly without wrapping and unwrapping, but
|
||||
// this will do for now.
|
||||
return call(runtime, {detail::toValue(runtime, std::forward<Args>(args))...});
|
||||
}
|
||||
|
||||
inline Value Function::callWithThis(
|
||||
Runtime& runtime,
|
||||
const Object& jsThis,
|
||||
const Value* args,
|
||||
size_t count) const {
|
||||
return runtime.call(*this, Value(runtime, jsThis), args, count);
|
||||
}
|
||||
|
||||
inline Value Function::callWithThis(
|
||||
Runtime& runtime,
|
||||
const Object& jsThis,
|
||||
std::initializer_list<Value> args) const {
|
||||
return callWithThis(runtime, jsThis, args.begin(), args.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline Value Function::callWithThis(
|
||||
Runtime& runtime,
|
||||
const Object& jsThis,
|
||||
Args&&... args) const {
|
||||
// A more awesome version of this would be able to create raw values
|
||||
// which can be used directly without wrapping and unwrapping, but
|
||||
// this will do for now.
|
||||
return callWithThis(
|
||||
runtime, jsThis, {detail::toValue(runtime, std::forward<Args>(args))...});
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline Array Array::createWithElements(Runtime& runtime, Args&&... args) {
|
||||
return createWithElements(
|
||||
runtime, {detail::toValue(runtime, std::forward<Args>(args))...});
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline std::vector<PropNameID> PropNameID::names(
|
||||
Runtime& runtime,
|
||||
Args&&... args) {
|
||||
return names({detail::toPropNameID(runtime, std::forward<Args>(args))...});
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
inline std::vector<PropNameID> PropNameID::names(
|
||||
PropNameID(&&propertyNames)[N]) {
|
||||
std::vector<PropNameID> result;
|
||||
result.reserve(N);
|
||||
for (auto& name : propertyNames) {
|
||||
result.push_back(std::move(name));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Value Function::callAsConstructor(
|
||||
Runtime& runtime,
|
||||
const Value* args,
|
||||
size_t count) const {
|
||||
return runtime.callAsConstructor(*this, args, count);
|
||||
}
|
||||
|
||||
inline Value Function::callAsConstructor(
|
||||
Runtime& runtime,
|
||||
std::initializer_list<Value> args) const {
|
||||
return callAsConstructor(runtime, args.begin(), args.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline Value Function::callAsConstructor(Runtime& runtime, Args&&... args)
|
||||
const {
|
||||
return callAsConstructor(
|
||||
runtime, {detail::toValue(runtime, std::forward<Args>(args))...});
|
||||
}
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
454
node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp
generated
vendored
Normal file
454
node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp
generated
vendored
Normal file
@ -0,0 +1,454 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <jsi/instrumentation.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
namespace {
|
||||
|
||||
// This is used for generating short exception strings.
|
||||
std::string kindToString(const Value& v, Runtime* rt = nullptr) {
|
||||
if (v.isUndefined()) {
|
||||
return "undefined";
|
||||
} else if (v.isNull()) {
|
||||
return "null";
|
||||
} else if (v.isBool()) {
|
||||
return v.getBool() ? "true" : "false";
|
||||
} else if (v.isNumber()) {
|
||||
return "a number";
|
||||
} else if (v.isString()) {
|
||||
return "a string";
|
||||
} else {
|
||||
assert(v.isObject() && "Expecting object.");
|
||||
return rt != nullptr && v.getObject(*rt).isFunction(*rt) ? "a function"
|
||||
: "an object";
|
||||
}
|
||||
}
|
||||
|
||||
// getPropertyAsFunction() will try to create a JSError. If the
|
||||
// failure is in building a JSError, this will lead to infinite
|
||||
// recursion. This function is used in place of getPropertyAsFunction
|
||||
// when building JSError, to avoid that infinite recursion.
|
||||
Value callGlobalFunction(Runtime& runtime, const char* name, const Value& arg) {
|
||||
Value v = runtime.global().getProperty(runtime, name);
|
||||
if (!v.isObject()) {
|
||||
throw JSINativeException(
|
||||
std::string("callGlobalFunction: JS global property '") + name +
|
||||
"' is " + kindToString(v, &runtime) + ", expected a Function");
|
||||
}
|
||||
Object o = v.getObject(runtime);
|
||||
if (!o.isFunction(runtime)) {
|
||||
throw JSINativeException(
|
||||
std::string("callGlobalFunction: JS global property '") + name +
|
||||
"' is a non-callable Object, expected a Function");
|
||||
}
|
||||
Function f = std::move(o).getFunction(runtime);
|
||||
return f.call(runtime, arg);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace detail {
|
||||
|
||||
void throwJSError(Runtime& rt, const char* msg) {
|
||||
throw JSError(rt, msg);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
Buffer::~Buffer() = default;
|
||||
|
||||
PreparedJavaScript::~PreparedJavaScript() = default;
|
||||
|
||||
Value HostObject::get(Runtime&, const PropNameID&) {
|
||||
return Value();
|
||||
}
|
||||
|
||||
void HostObject::set(Runtime& rt, const PropNameID& name, const Value&) {
|
||||
std::string msg("TypeError: Cannot assign to property '");
|
||||
msg += name.utf8(rt);
|
||||
msg += "' on HostObject with default setter";
|
||||
throw JSError(rt, msg);
|
||||
}
|
||||
|
||||
HostObject::~HostObject() {}
|
||||
|
||||
Runtime::~Runtime() {}
|
||||
|
||||
Instrumentation& Runtime::instrumentation() {
|
||||
class NoInstrumentation : public Instrumentation {
|
||||
std::string getRecordedGCStats() override {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, int64_t> getHeapInfo(bool) override {
|
||||
return std::unordered_map<std::string, int64_t>{};
|
||||
}
|
||||
|
||||
void collectGarbage() override {}
|
||||
|
||||
void startTrackingHeapObjectStackTraces() override {}
|
||||
void stopTrackingHeapObjectStackTraces() override {}
|
||||
|
||||
void createSnapshotToFile(const std::string&) override {
|
||||
throw JSINativeException(
|
||||
"Default instrumentation cannot create a heap snapshot");
|
||||
}
|
||||
|
||||
void createSnapshotToStream(std::ostream&) override {
|
||||
throw JSINativeException(
|
||||
"Default instrumentation cannot create a heap snapshot");
|
||||
}
|
||||
|
||||
std::string flushAndDisableBridgeTrafficTrace() override {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
void writeBasicBlockProfileTraceToFile(const std::string&) const override {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
void dumpProfilerSymbolsToFile(const std::string&) const override {
|
||||
std::abort();
|
||||
}
|
||||
};
|
||||
|
||||
static NoInstrumentation sharedInstance;
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
Value Runtime::createValueFromJsonUtf8(const uint8_t* json, size_t length) {
|
||||
Function parseJson = global()
|
||||
.getPropertyAsObject(*this, "JSON")
|
||||
.getPropertyAsFunction(*this, "parse");
|
||||
return parseJson.call(*this, String::createFromUtf8(*this, json, length));
|
||||
}
|
||||
|
||||
Pointer& Pointer::operator=(Pointer&& other) {
|
||||
if (ptr_) {
|
||||
ptr_->invalidate();
|
||||
}
|
||||
ptr_ = other.ptr_;
|
||||
other.ptr_ = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Object Object::getPropertyAsObject(Runtime& runtime, const char* name) const {
|
||||
Value v = getProperty(runtime, name);
|
||||
|
||||
if (!v.isObject()) {
|
||||
throw JSError(
|
||||
runtime,
|
||||
std::string("getPropertyAsObject: property '") + name + "' is " +
|
||||
kindToString(v, &runtime) + ", expected an Object");
|
||||
}
|
||||
|
||||
return v.getObject(runtime);
|
||||
}
|
||||
|
||||
Function Object::getPropertyAsFunction(Runtime& runtime, const char* name)
|
||||
const {
|
||||
Object obj = getPropertyAsObject(runtime, name);
|
||||
if (!obj.isFunction(runtime)) {
|
||||
throw JSError(
|
||||
runtime,
|
||||
std::string("getPropertyAsFunction: property '") + name + "' is " +
|
||||
kindToString(std::move(obj), &runtime) + ", expected a Function");
|
||||
};
|
||||
|
||||
return std::move(obj).getFunction(runtime);
|
||||
}
|
||||
|
||||
Array Object::asArray(Runtime& runtime) const& {
|
||||
if (!isArray(runtime)) {
|
||||
throw JSError(
|
||||
runtime,
|
||||
"Object is " + kindToString(Value(runtime, *this), &runtime) +
|
||||
", expected an array");
|
||||
}
|
||||
return getArray(runtime);
|
||||
}
|
||||
|
||||
Array Object::asArray(Runtime& runtime) && {
|
||||
if (!isArray(runtime)) {
|
||||
throw JSError(
|
||||
runtime,
|
||||
"Object is " + kindToString(Value(runtime, *this), &runtime) +
|
||||
", expected an array");
|
||||
}
|
||||
return std::move(*this).getArray(runtime);
|
||||
}
|
||||
|
||||
Function Object::asFunction(Runtime& runtime) const& {
|
||||
if (!isFunction(runtime)) {
|
||||
throw JSError(
|
||||
runtime,
|
||||
"Object is " + kindToString(Value(runtime, *this), &runtime) +
|
||||
", expected a function");
|
||||
}
|
||||
return getFunction(runtime);
|
||||
}
|
||||
|
||||
Function Object::asFunction(Runtime& runtime) && {
|
||||
if (!isFunction(runtime)) {
|
||||
throw JSError(
|
||||
runtime,
|
||||
"Object is " + kindToString(Value(runtime, *this), &runtime) +
|
||||
", expected a function");
|
||||
}
|
||||
return std::move(*this).getFunction(runtime);
|
||||
}
|
||||
|
||||
Value::Value(Value&& other) : Value(other.kind_) {
|
||||
if (kind_ == BooleanKind) {
|
||||
data_.boolean = other.data_.boolean;
|
||||
} else if (kind_ == NumberKind) {
|
||||
data_.number = other.data_.number;
|
||||
} else if (kind_ >= PointerKind) {
|
||||
new (&data_.pointer) Pointer(std::move(other.data_.pointer));
|
||||
}
|
||||
// when the other's dtor runs, nothing will happen.
|
||||
other.kind_ = UndefinedKind;
|
||||
}
|
||||
|
||||
Value::Value(Runtime& runtime, const Value& other) : Value(other.kind_) {
|
||||
// data_ is uninitialized, so use placement new to create non-POD
|
||||
// types in it. Any other kind of initialization will call a dtor
|
||||
// first, which is incorrect.
|
||||
if (kind_ == BooleanKind) {
|
||||
data_.boolean = other.data_.boolean;
|
||||
} else if (kind_ == NumberKind) {
|
||||
data_.number = other.data_.number;
|
||||
} else if (kind_ == SymbolKind) {
|
||||
new (&data_.pointer) Pointer(runtime.cloneSymbol(other.data_.pointer.ptr_));
|
||||
} else if (kind_ == StringKind) {
|
||||
new (&data_.pointer) Pointer(runtime.cloneString(other.data_.pointer.ptr_));
|
||||
} else if (kind_ >= ObjectKind) {
|
||||
new (&data_.pointer) Pointer(runtime.cloneObject(other.data_.pointer.ptr_));
|
||||
}
|
||||
}
|
||||
|
||||
Value::~Value() {
|
||||
if (kind_ >= PointerKind) {
|
||||
data_.pointer.~Pointer();
|
||||
}
|
||||
}
|
||||
|
||||
bool Value::strictEquals(Runtime& runtime, const Value& a, const Value& b) {
|
||||
if (a.kind_ != b.kind_) {
|
||||
return false;
|
||||
}
|
||||
switch (a.kind_) {
|
||||
case UndefinedKind:
|
||||
case NullKind:
|
||||
return true;
|
||||
case BooleanKind:
|
||||
return a.data_.boolean == b.data_.boolean;
|
||||
case NumberKind:
|
||||
return a.data_.number == b.data_.number;
|
||||
case SymbolKind:
|
||||
return runtime.strictEquals(
|
||||
static_cast<const Symbol&>(a.data_.pointer),
|
||||
static_cast<const Symbol&>(b.data_.pointer));
|
||||
case StringKind:
|
||||
return runtime.strictEquals(
|
||||
static_cast<const String&>(a.data_.pointer),
|
||||
static_cast<const String&>(b.data_.pointer));
|
||||
case ObjectKind:
|
||||
return runtime.strictEquals(
|
||||
static_cast<const Object&>(a.data_.pointer),
|
||||
static_cast<const Object&>(b.data_.pointer));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
double Value::asNumber() const {
|
||||
if (!isNumber()) {
|
||||
throw JSINativeException(
|
||||
"Value is " + kindToString(*this) + ", expected a number");
|
||||
}
|
||||
|
||||
return getNumber();
|
||||
}
|
||||
|
||||
Object Value::asObject(Runtime& rt) const& {
|
||||
if (!isObject()) {
|
||||
throw JSError(
|
||||
rt, "Value is " + kindToString(*this, &rt) + ", expected an Object");
|
||||
}
|
||||
|
||||
return getObject(rt);
|
||||
}
|
||||
|
||||
Object Value::asObject(Runtime& rt) && {
|
||||
if (!isObject()) {
|
||||
throw JSError(
|
||||
rt, "Value is " + kindToString(*this, &rt) + ", expected an Object");
|
||||
}
|
||||
auto ptr = data_.pointer.ptr_;
|
||||
data_.pointer.ptr_ = nullptr;
|
||||
return static_cast<Object>(ptr);
|
||||
}
|
||||
|
||||
Symbol Value::asSymbol(Runtime& rt) const& {
|
||||
if (!isSymbol()) {
|
||||
throw JSError(
|
||||
rt, "Value is " + kindToString(*this, &rt) + ", expected a Symbol");
|
||||
}
|
||||
|
||||
return getSymbol(rt);
|
||||
}
|
||||
|
||||
Symbol Value::asSymbol(Runtime& rt) && {
|
||||
if (!isSymbol()) {
|
||||
throw JSError(
|
||||
rt, "Value is " + kindToString(*this, &rt) + ", expected a Symbol");
|
||||
}
|
||||
|
||||
return std::move(*this).getSymbol(rt);
|
||||
}
|
||||
|
||||
String Value::asString(Runtime& rt) const& {
|
||||
if (!isString()) {
|
||||
throw JSError(
|
||||
rt, "Value is " + kindToString(*this, &rt) + ", expected a String");
|
||||
}
|
||||
|
||||
return getString(rt);
|
||||
}
|
||||
|
||||
String Value::asString(Runtime& rt) && {
|
||||
if (!isString()) {
|
||||
throw JSError(
|
||||
rt, "Value is " + kindToString(*this, &rt) + ", expected a String");
|
||||
}
|
||||
|
||||
return std::move(*this).getString(rt);
|
||||
}
|
||||
|
||||
String Value::toString(Runtime& runtime) const {
|
||||
Function toString = runtime.global().getPropertyAsFunction(runtime, "String");
|
||||
return toString.call(runtime, *this).getString(runtime);
|
||||
}
|
||||
|
||||
Array Array::createWithElements(
|
||||
Runtime& rt,
|
||||
std::initializer_list<Value> elements) {
|
||||
Array result(rt, elements.size());
|
||||
size_t index = 0;
|
||||
for (const auto& element : elements) {
|
||||
result.setValueAtIndex(rt, index++, element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<PropNameID> HostObject::getPropertyNames(Runtime&) {
|
||||
return {};
|
||||
}
|
||||
|
||||
Runtime::ScopeState* Runtime::pushScope() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Runtime::popScope(ScopeState*) {}
|
||||
|
||||
JSError::JSError(Runtime& rt, Value&& value) {
|
||||
setValue(rt, std::move(value));
|
||||
}
|
||||
|
||||
JSError::JSError(Runtime& rt, std::string msg) : message_(std::move(msg)) {
|
||||
try {
|
||||
setValue(
|
||||
rt,
|
||||
callGlobalFunction(rt, "Error", String::createFromUtf8(rt, message_)));
|
||||
} catch (const std::exception& ex) {
|
||||
message_ = std::string(ex.what()) + " (while raising " + message_ + ")";
|
||||
setValue(rt, String::createFromUtf8(rt, message_));
|
||||
} catch (...) {
|
||||
setValue(rt, Value());
|
||||
}
|
||||
}
|
||||
|
||||
JSError::JSError(Runtime& rt, std::string msg, std::string stack)
|
||||
: message_(std::move(msg)), stack_(std::move(stack)) {
|
||||
try {
|
||||
Object e(rt);
|
||||
e.setProperty(rt, "message", String::createFromUtf8(rt, message_));
|
||||
e.setProperty(rt, "stack", String::createFromUtf8(rt, stack_));
|
||||
setValue(rt, std::move(e));
|
||||
} catch (const std::exception& ex) {
|
||||
setValue(rt, String::createFromUtf8(rt, ex.what()));
|
||||
} catch (...) {
|
||||
setValue(rt, Value());
|
||||
}
|
||||
}
|
||||
|
||||
JSError::JSError(std::string what, Runtime& rt, Value&& value)
|
||||
: JSIException(std::move(what)) {
|
||||
setValue(rt, std::move(value));
|
||||
}
|
||||
|
||||
void JSError::setValue(Runtime& rt, Value&& value) {
|
||||
value_ = std::make_shared<jsi::Value>(std::move(value));
|
||||
|
||||
try {
|
||||
if ((message_.empty() || stack_.empty()) && value_->isObject()) {
|
||||
auto obj = value_->getObject(rt);
|
||||
|
||||
if (message_.empty()) {
|
||||
jsi::Value message = obj.getProperty(rt, "message");
|
||||
if (!message.isUndefined()) {
|
||||
message_ =
|
||||
callGlobalFunction(rt, "String", message).getString(rt).utf8(rt);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack_.empty()) {
|
||||
jsi::Value stack = obj.getProperty(rt, "stack");
|
||||
if (!stack.isUndefined()) {
|
||||
stack_ =
|
||||
callGlobalFunction(rt, "String", stack).getString(rt).utf8(rt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (message_.empty()) {
|
||||
message_ =
|
||||
callGlobalFunction(rt, "String", *value_).getString(rt).utf8(rt);
|
||||
}
|
||||
|
||||
if (stack_.empty()) {
|
||||
stack_ = "no stack";
|
||||
}
|
||||
|
||||
if (what_.empty()) {
|
||||
what_ = message_ + "\n\n" + stack_;
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
message_ = std::string("[Exception while creating message string: ") +
|
||||
ex.what() + "]";
|
||||
stack_ = std::string("Exception while creating stack string: ") +
|
||||
ex.what() + "]";
|
||||
what_ =
|
||||
std::string("Exception while getting value fields: ") + ex.what() + "]";
|
||||
} catch (...) {
|
||||
message_ = "[Exception caught creating message string]";
|
||||
stack_ = "[Exception caught creating stack string]";
|
||||
what_ = "[Exception caught getting value fields]";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
1281
node_modules/react-native/ReactCommon/jsi/jsi/jsi.h
generated
vendored
Normal file
1281
node_modules/react-native/ReactCommon/jsi/jsi/jsi.h
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
118
node_modules/react-native/ReactCommon/jsi/jsi/jsilib-posix.cpp
generated
vendored
Normal file
118
node_modules/react-native/ReactCommon/jsi/jsi/jsilib-posix.cpp
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#ifndef _WINDOWS
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cerrno>
|
||||
#include <cstdarg>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <jsi/jsilib.h>
|
||||
|
||||
#if __APPLE__
|
||||
#include <mach/vm_statistics.h>
|
||||
#define MAP_TAG VM_MAKE_TAG(VM_MEMORY_APPLICATION_SPECIFIC_16)
|
||||
#endif // __APPLE__
|
||||
|
||||
#ifndef MAP_TAG
|
||||
#define MAP_TAG 0
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr size_t kErrorBufferSize = 512;
|
||||
|
||||
__attribute__((format(printf, 1, 2))) void throwFormattedError(
|
||||
const char* fmt,
|
||||
...) {
|
||||
char logBuffer[kErrorBufferSize];
|
||||
|
||||
va_list va_args;
|
||||
va_start(va_args, fmt);
|
||||
int result = vsnprintf(logBuffer, sizeof(logBuffer), fmt, va_args);
|
||||
va_end(va_args);
|
||||
|
||||
if (result < 0) {
|
||||
throw JSINativeException(
|
||||
std::string("Failed to format error message: ") + fmt);
|
||||
}
|
||||
|
||||
throw JSINativeException(logBuffer);
|
||||
}
|
||||
|
||||
class ScopedFile {
|
||||
public:
|
||||
ScopedFile(const std::string& path)
|
||||
: path_(path), fd_(::open(path.c_str(), O_RDONLY)) {
|
||||
if (fd_ == -1) {
|
||||
throwFormattedError(
|
||||
"Could not open %s: %s", path.c_str(), strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
~ScopedFile() {
|
||||
::close(fd_);
|
||||
}
|
||||
|
||||
size_t size() {
|
||||
struct stat fileInfo;
|
||||
if (::fstat(fd_, &fileInfo) == -1) {
|
||||
throwFormattedError(
|
||||
"Could not stat %s: %s", path_.c_str(), strerror(errno));
|
||||
}
|
||||
return fileInfo.st_size;
|
||||
}
|
||||
|
||||
uint8_t* mmap(size_t size) {
|
||||
void* result =
|
||||
::mmap(nullptr, size, PROT_READ, MAP_PRIVATE | MAP_TAG, fd_, 0);
|
||||
if (result == MAP_FAILED) {
|
||||
throwFormattedError(
|
||||
"Could not mmap %s: %s", path_.c_str(), strerror(errno));
|
||||
}
|
||||
return reinterpret_cast<uint8_t*>(result);
|
||||
}
|
||||
|
||||
const std::string& path_;
|
||||
const int fd_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
FileBuffer::FileBuffer(const std::string& path) {
|
||||
ScopedFile file(path);
|
||||
size_ = file.size();
|
||||
data_ = file.mmap(size_);
|
||||
}
|
||||
|
||||
FileBuffer::~FileBuffer() {
|
||||
if (::munmap(data_, size_)) {
|
||||
// terminate the program with pending exception
|
||||
try {
|
||||
throwFormattedError(
|
||||
"Could not unmap memory (%p, %zu bytes): %s",
|
||||
data_,
|
||||
size_,
|
||||
strerror(errno));
|
||||
} catch (...) {
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
||||
|
||||
#endif // !defined(_WINDOWS)
|
27
node_modules/react-native/ReactCommon/jsi/jsi/jsilib-windows.cpp
generated
vendored
Normal file
27
node_modules/react-native/ReactCommon/jsi/jsi/jsilib-windows.cpp
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#ifdef _WINDOWS
|
||||
|
||||
#include <jsi/jsilib.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
FileBuffer::FileBuffer(const std::string&) {
|
||||
// TODO(T41045067) Implement this on Windows
|
||||
throw new JSINativeException("FileBuffer is not implemented on Windows");
|
||||
}
|
||||
|
||||
FileBuffer::~FileBuffer() {
|
||||
assert(false && "FileBuffer is not implemented on Windows");
|
||||
}
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
||||
|
||||
#endif //_WINDOWS
|
59
node_modules/react-native/ReactCommon/jsi/jsi/jsilib.h
generated
vendored
Normal file
59
node_modules/react-native/ReactCommon/jsi/jsi/jsilib.h
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
class FileBuffer : public Buffer {
|
||||
public:
|
||||
FileBuffer(const std::string& path);
|
||||
~FileBuffer();
|
||||
|
||||
size_t size() const override {
|
||||
return size_;
|
||||
}
|
||||
|
||||
const uint8_t* data() const override {
|
||||
return data_;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t size_;
|
||||
uint8_t* data_;
|
||||
};
|
||||
|
||||
// A trivial implementation of PreparedJavaScript that simply stores the source
|
||||
// buffer and URL.
|
||||
class SourceJavaScriptPreparation final : public jsi::PreparedJavaScript,
|
||||
public jsi::Buffer {
|
||||
std::shared_ptr<const jsi::Buffer> buf_;
|
||||
std::string sourceURL_;
|
||||
|
||||
public:
|
||||
SourceJavaScriptPreparation(
|
||||
std::shared_ptr<const jsi::Buffer> buf,
|
||||
std::string sourceURL)
|
||||
: buf_(std::move(buf)), sourceURL_(std::move(sourceURL)) {}
|
||||
|
||||
const std::string& sourceURL() const {
|
||||
return sourceURL_;
|
||||
}
|
||||
|
||||
size_t size() const override {
|
||||
return buf_->size();
|
||||
}
|
||||
const uint8_t* data() const override {
|
||||
return buf_->data();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
1359
node_modules/react-native/ReactCommon/jsi/jsi/test/testlib.cpp
generated
vendored
Normal file
1359
node_modules/react-native/ReactCommon/jsi/jsi/test/testlib.cpp
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
49
node_modules/react-native/ReactCommon/jsi/jsi/test/testlib.h
generated
vendored
Normal file
49
node_modules/react-native/ReactCommon/jsi/jsi/test/testlib.h
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
class Runtime;
|
||||
|
||||
using RuntimeFactory = std::function<std::unique_ptr<Runtime>()>;
|
||||
|
||||
std::vector<RuntimeFactory> runtimeGenerators();
|
||||
|
||||
class JSITestBase : public ::testing::TestWithParam<RuntimeFactory> {
|
||||
public:
|
||||
JSITestBase() : factory(GetParam()), runtime(factory()), rt(*runtime) {}
|
||||
|
||||
Value eval(const char* code) {
|
||||
return rt.global().getPropertyAsFunction(rt, "eval").call(rt, code);
|
||||
}
|
||||
|
||||
Function function(const std::string& code) {
|
||||
return eval(("(" + code + ")").c_str()).getObject(rt).getFunction(rt);
|
||||
}
|
||||
|
||||
bool checkValue(const Value& value, const std::string& jsValue) {
|
||||
return function("function(value) { return value == " + jsValue + "; }")
|
||||
.call(rt, std::move(value))
|
||||
.getBool();
|
||||
}
|
||||
|
||||
RuntimeFactory factory;
|
||||
std::unique_ptr<Runtime> runtime;
|
||||
Runtime& rt;
|
||||
};
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
79
node_modules/react-native/ReactCommon/jsi/jsi/threadsafe.h
generated
vendored
Normal file
79
node_modules/react-native/ReactCommon/jsi/jsi/threadsafe.h
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <jsi/decorator.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace jsi {
|
||||
|
||||
class ThreadSafeRuntime : public Runtime {
|
||||
public:
|
||||
virtual void lock() const = 0;
|
||||
virtual void unlock() const = 0;
|
||||
virtual Runtime& getUnsafeRuntime() = 0;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename R, typename L>
|
||||
struct WithLock {
|
||||
L lock;
|
||||
WithLock(R& r) : lock(r) {}
|
||||
void before() {
|
||||
lock.lock();
|
||||
}
|
||||
void after() {
|
||||
lock.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
// The actual implementation of a given ThreadSafeRuntime. It's parameterized
|
||||
// by:
|
||||
//
|
||||
// - R: The actual Runtime type that this wraps
|
||||
// - L: A lock type that has three members:
|
||||
// - L(R& r) // ctor
|
||||
// - void lock()
|
||||
// - void unlock()
|
||||
template <typename R, typename L>
|
||||
class ThreadSafeRuntimeImpl final
|
||||
: public WithRuntimeDecorator<WithLock<R, L>, R, ThreadSafeRuntime> {
|
||||
public:
|
||||
template <typename... Args>
|
||||
ThreadSafeRuntimeImpl(Args&&... args)
|
||||
: WithRuntimeDecorator<WithLock<R, L>, R, ThreadSafeRuntime>(
|
||||
unsafe_,
|
||||
lock_),
|
||||
unsafe_(std::forward<Args>(args)...),
|
||||
lock_(unsafe_) {}
|
||||
|
||||
R& getUnsafeRuntime() override {
|
||||
return WithRuntimeDecorator<WithLock<R, L>, R, ThreadSafeRuntime>::plain();
|
||||
}
|
||||
|
||||
void lock() const override {
|
||||
lock_.before();
|
||||
}
|
||||
|
||||
void unlock() const override {
|
||||
lock_.after();
|
||||
}
|
||||
|
||||
private:
|
||||
R unsafe_;
|
||||
mutable WithLock<R, L> lock_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace jsi
|
||||
} // namespace facebook
|
Reference in New Issue
Block a user