react-native-windows 0.72.0-preview.7 → 0.72.0-preview.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Directory.Build.props +24 -19
- package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +0 -1
- package/Libraries/Components/TextInput/TextInput.d.ts +121 -86
- package/Libraries/Components/TextInput/TextInput.flow.js +121 -135
- package/Libraries/Components/TextInput/TextInput.js +126 -155
- package/Libraries/Components/TextInput/TextInput.windows.js +126 -155
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/PermissionsAndroid/PermissionsAndroid.js +0 -2
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -13
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +2 -4
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +2 -57
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +22 -17
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +0 -2
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiLoader.cpp +16 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +41 -12
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +17 -6
- package/Microsoft.ReactNative.Managed/packages.lock.json +6 -6
- package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpApp.targets +1 -1
- package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppApp.targets +1 -1
- package/PropertySheets/External/Microsoft.ReactNative.WinAppSDK.CSharpApp.targets +1 -1
- package/PropertySheets/Generated/PackageVersion.g.props +2 -2
- package/PropertySheets/JSEngine.props +4 -4
- package/PropertySheets/Warnings.props +6 -0
- package/ReactCommon/ReactCommon.vcxproj +53 -1
- package/ReactCommon/cgmanifest.json +15 -0
- package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +36 -0
- package/Shared/DevSupportManager.cpp +2 -9
- package/Shared/DevSupportManager.h +2 -6
- package/Shared/HermesRuntimeHolder.cpp +318 -81
- package/Shared/HermesRuntimeHolder.h +15 -19
- package/Shared/HermesSamplingProfiler.cpp +5 -6
- package/Shared/InspectorPackagerConnection.cpp +62 -108
- package/Shared/InspectorPackagerConnection.h +9 -21
- package/Shared/JSI/ScriptStore.h +18 -20
- package/Shared/JSI/V8RuntimeHolder.cpp +262 -0
- package/Shared/JSI/V8RuntimeHolder.h +37 -0
- package/Shared/OInstance.cpp +16 -36
- package/Shared/SafeLoadLibrary.cpp +41 -0
- package/Shared/SafeLoadLibrary.h +15 -0
- package/Shared/Shared.vcxitems +21 -10
- package/Shared/Shared.vcxitems.filters +23 -30
- package/codegen/rnwcoreJSI.h +2 -2
- package/package.json +15 -14
- package/template/cs-app-WinAppSDK/proj/ExperimentalFeatures.props +1 -1
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +0 -2105
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +0 -73
- package/Shared/HermesShim.cpp +0 -122
- package/Shared/HermesShim.h +0 -41
- package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +0 -209
- package/Shared/JSI/NapiJsiV8RuntimeHolder.h +0 -46
- package/Shared/V8JSIRuntimeHolder.cpp +0 -71
- package/Shared/V8JSIRuntimeHolder.h +0 -58
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
#pragma once
|
|
5
|
-
#ifndef MICROSOFT_REACTNATIVE_JSI_NODEAPIJSIRUNTIME
|
|
6
|
-
#define MICROSOFT_REACTNATIVE_JSI_NODEAPIJSIRUNTIME
|
|
7
|
-
|
|
8
|
-
// Standard Library
|
|
9
|
-
#include <memory>
|
|
10
|
-
|
|
11
|
-
// JSI
|
|
12
|
-
#include <js_native_ext_api.h>
|
|
13
|
-
#include <jsi/jsi.h>
|
|
14
|
-
|
|
15
|
-
namespace Microsoft::JSI {
|
|
16
|
-
|
|
17
|
-
///
|
|
18
|
-
// NodeApiJsiRuntime factory function.
|
|
19
|
-
// TODO: Rename as MakeNapiJsiRuntime once code is dropped from V8-JSI.
|
|
20
|
-
///
|
|
21
|
-
std::unique_ptr<facebook::jsi::Runtime> __cdecl MakeNodeApiJsiRuntime(napi_env env) noexcept;
|
|
22
|
-
|
|
23
|
-
template <typename T>
|
|
24
|
-
struct NativeObjectWrapper;
|
|
25
|
-
|
|
26
|
-
template <typename T>
|
|
27
|
-
struct NativeObjectWrapper<std::unique_ptr<T>> {
|
|
28
|
-
static napi_ext_native_data Wrap(std::unique_ptr<T> &&obj) noexcept {
|
|
29
|
-
napi_ext_native_data nativeData{};
|
|
30
|
-
nativeData.data = obj.release();
|
|
31
|
-
nativeData.finalize_cb = [](napi_env /*env*/, void *data, void * /*finalizeHint*/) {
|
|
32
|
-
std::unique_ptr<T> obj{reinterpret_cast<T *>(data)};
|
|
33
|
-
};
|
|
34
|
-
return nativeData;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static T *Unwrap(napi_ext_native_data &nativeData) noexcept {
|
|
38
|
-
return reinterpret_cast<T *>(nativeData.data);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
template <typename T>
|
|
43
|
-
struct NativeObjectWrapper<std::shared_ptr<T>> {
|
|
44
|
-
static napi_ext_native_data Wrap(std::shared_ptr<T> &&obj) noexcept {
|
|
45
|
-
static_assert(
|
|
46
|
-
sizeof(SharedPtrHolder) == sizeof(std::shared_ptr<T>), "std::shared_ptr expected to have size of two pointers");
|
|
47
|
-
SharedPtrHolder ptrHolder;
|
|
48
|
-
new (std::addressof(ptrHolder)) std::shared_ptr(std::move(obj));
|
|
49
|
-
napi_ext_native_data nativeData{};
|
|
50
|
-
nativeData.data = ptrHolder.ptr1;
|
|
51
|
-
nativeData.finalize_hint = ptrHolder.ptr2;
|
|
52
|
-
nativeData.finalize_cb = [](napi_env /*env*/, void *data, void *finalizeHint) {
|
|
53
|
-
SharedPtrHolder ptrHolder{data, finalizeHint};
|
|
54
|
-
std::shared_ptr<T> obj(std::move(*reinterpret_cast<std::shared_ptr<T> *>(std::addressof(ptrHolder))));
|
|
55
|
-
};
|
|
56
|
-
return nativeData;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static std::shared_ptr<T> Unwrap(napi_ext_native_data &nativeData) noexcept {
|
|
60
|
-
SharedPtrHolder ptrHolder{nativeData.data, nativeData.finalize_hint};
|
|
61
|
-
return *reinterpret_cast<std::shared_ptr<T> *>(std::addressof(ptrHolder));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private:
|
|
65
|
-
struct SharedPtrHolder {
|
|
66
|
-
void *ptr1;
|
|
67
|
-
void *ptr2;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
} // namespace Microsoft::JSI
|
|
72
|
-
|
|
73
|
-
#endif // MICROSOFT_REACTNATIVE_JSI_NODEAPIJSIRUNTIME
|
package/Shared/HermesShim.cpp
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
#include "HermesShim.h"
|
|
5
|
-
#include "Crash.h"
|
|
6
|
-
|
|
7
|
-
#define DECLARE_SYMBOL(symbol, importedSymbol) \
|
|
8
|
-
decltype(&importedSymbol) s_##symbol{}; \
|
|
9
|
-
constexpr const char symbol##Symbol[] = #importedSymbol;
|
|
10
|
-
|
|
11
|
-
#define INIT_SYMBOL(symbol) \
|
|
12
|
-
s_##symbol = reinterpret_cast<decltype(s_##symbol)>(GetProcAddress(s_hermesModule, symbol##Symbol)); \
|
|
13
|
-
VerifyElseCrash(s_##symbol);
|
|
14
|
-
|
|
15
|
-
#define CRASH_ON_ERROR(result) VerifyElseCrash(result == hermes_ok);
|
|
16
|
-
|
|
17
|
-
namespace Microsoft::ReactNative {
|
|
18
|
-
|
|
19
|
-
namespace {
|
|
20
|
-
|
|
21
|
-
DECLARE_SYMBOL(createRuntime, hermes_create_runtime);
|
|
22
|
-
DECLARE_SYMBOL(createRuntimeWithWER, hermes_create_runtime_with_wer);
|
|
23
|
-
DECLARE_SYMBOL(deleteRuntime, hermes_delete_runtime);
|
|
24
|
-
DECLARE_SYMBOL(getNonAbiSafeRuntime, hermes_get_non_abi_safe_runtime);
|
|
25
|
-
DECLARE_SYMBOL(dumpCrashData, hermes_dump_crash_data);
|
|
26
|
-
DECLARE_SYMBOL(samplingProfilerEnable, hermes_sampling_profiler_enable);
|
|
27
|
-
DECLARE_SYMBOL(samplingProfilerDisable, hermes_sampling_profiler_disable);
|
|
28
|
-
DECLARE_SYMBOL(samplingProfilerAdd, hermes_sampling_profiler_add);
|
|
29
|
-
DECLARE_SYMBOL(samplingProfilerRemove, hermes_sampling_profiler_remove);
|
|
30
|
-
DECLARE_SYMBOL(samplingProfilerDumpToFile, hermes_sampling_profiler_dump_to_file);
|
|
31
|
-
|
|
32
|
-
HMODULE s_hermesModule{};
|
|
33
|
-
std::once_flag s_hermesLoading;
|
|
34
|
-
|
|
35
|
-
void EnsureHermesLoaded() noexcept {
|
|
36
|
-
std::call_once(s_hermesLoading, []() {
|
|
37
|
-
VerifyElseCrashSz(!s_hermesModule, "Invalid state: \"hermes.dll\" being loaded again.");
|
|
38
|
-
|
|
39
|
-
s_hermesModule = LoadLibrary(L"hermes.dll");
|
|
40
|
-
VerifyElseCrashSz(s_hermesModule, "Could not load \"hermes.dll\"");
|
|
41
|
-
|
|
42
|
-
INIT_SYMBOL(createRuntime);
|
|
43
|
-
INIT_SYMBOL(createRuntimeWithWER);
|
|
44
|
-
INIT_SYMBOL(deleteRuntime);
|
|
45
|
-
INIT_SYMBOL(getNonAbiSafeRuntime);
|
|
46
|
-
INIT_SYMBOL(dumpCrashData);
|
|
47
|
-
INIT_SYMBOL(samplingProfilerEnable);
|
|
48
|
-
INIT_SYMBOL(samplingProfilerDisable);
|
|
49
|
-
INIT_SYMBOL(samplingProfilerAdd);
|
|
50
|
-
INIT_SYMBOL(samplingProfilerRemove);
|
|
51
|
-
INIT_SYMBOL(samplingProfilerDumpToFile);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
struct RuntimeDeleter {
|
|
56
|
-
RuntimeDeleter(std::shared_ptr<const HermesShim> &&hermesShimPtr) noexcept
|
|
57
|
-
: hermesShimPtr_(std::move(hermesShimPtr)) {}
|
|
58
|
-
|
|
59
|
-
void operator()(facebook::hermes::HermesRuntime * /*runtime*/) {
|
|
60
|
-
// Do nothing. Instead, we rely on the RuntimeDeleter destructor.
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private:
|
|
64
|
-
std::shared_ptr<const HermesShim> hermesShimPtr_;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
} // namespace
|
|
68
|
-
|
|
69
|
-
HermesShim::HermesShim(hermes_runtime runtime) noexcept : runtime_(runtime) {
|
|
70
|
-
CRASH_ON_ERROR(s_getNonAbiSafeRuntime(runtime_, reinterpret_cast<void **>(&nonAbiSafeRuntime_)));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
HermesShim::~HermesShim() {
|
|
74
|
-
CRASH_ON_ERROR(s_deleteRuntime(runtime_));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/*static*/ std::shared_ptr<HermesShim> HermesShim::make() noexcept {
|
|
78
|
-
EnsureHermesLoaded();
|
|
79
|
-
hermes_runtime runtime{};
|
|
80
|
-
CRASH_ON_ERROR(s_createRuntime(&runtime));
|
|
81
|
-
return std::make_shared<HermesShim>(runtime);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/*static*/
|
|
85
|
-
std::shared_ptr<HermesShim> HermesShim::makeWithWER() noexcept {
|
|
86
|
-
EnsureHermesLoaded();
|
|
87
|
-
hermes_runtime runtime{};
|
|
88
|
-
CRASH_ON_ERROR(s_createRuntimeWithWER(&runtime));
|
|
89
|
-
return std::make_shared<HermesShim>(runtime);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
std::shared_ptr<facebook::hermes::HermesRuntime> HermesShim::getRuntime() const noexcept {
|
|
93
|
-
return std::shared_ptr<facebook::hermes::HermesRuntime>(nonAbiSafeRuntime_, RuntimeDeleter(shared_from_this()));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
void HermesShim::dumpCrashData(int fileDescriptor) const noexcept {
|
|
97
|
-
CRASH_ON_ERROR(s_dumpCrashData(runtime_, fileDescriptor));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/*static*/ void HermesShim::enableSamplingProfiler() noexcept {
|
|
101
|
-
EnsureHermesLoaded();
|
|
102
|
-
CRASH_ON_ERROR(s_samplingProfilerEnable());
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/*static*/ void HermesShim::disableSamplingProfiler() noexcept {
|
|
106
|
-
EnsureHermesLoaded();
|
|
107
|
-
CRASH_ON_ERROR(s_samplingProfilerDisable());
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/*static*/ void HermesShim::dumpSampledTraceToFile(const std::string &fileName) noexcept {
|
|
111
|
-
EnsureHermesLoaded();
|
|
112
|
-
CRASH_ON_ERROR(s_samplingProfilerDumpToFile(fileName.c_str()));
|
|
113
|
-
}
|
|
114
|
-
void HermesShim::addToProfiling() const noexcept {
|
|
115
|
-
CRASH_ON_ERROR(s_samplingProfilerAdd(runtime_));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
void HermesShim::removeFromProfiling() const noexcept {
|
|
119
|
-
CRASH_ON_ERROR(s_samplingProfilerRemove(runtime_));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
} // namespace Microsoft::ReactNative
|
package/Shared/HermesShim.h
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
#pragma once
|
|
5
|
-
|
|
6
|
-
#include <hermes/hermes_win.h>
|
|
7
|
-
|
|
8
|
-
//! We do not package hermes.dll for projects that do not require it. We cannot
|
|
9
|
-
//! use pure delay-loading to achieve this, since WACK will detect the
|
|
10
|
-
//! non-present DLL. Functions in this namespace shim to the Hermes DLL via
|
|
11
|
-
//! GetProcAddress.
|
|
12
|
-
namespace Microsoft::ReactNative {
|
|
13
|
-
|
|
14
|
-
class HermesShim : public std::enable_shared_from_this<HermesShim> {
|
|
15
|
-
public:
|
|
16
|
-
HermesShim(hermes_runtime runtimeAbiPtr) noexcept;
|
|
17
|
-
~HermesShim();
|
|
18
|
-
|
|
19
|
-
static std::shared_ptr<HermesShim> make() noexcept;
|
|
20
|
-
static std::shared_ptr<HermesShim> makeWithWER() noexcept;
|
|
21
|
-
|
|
22
|
-
std::shared_ptr<facebook::hermes::HermesRuntime> getRuntime() const noexcept;
|
|
23
|
-
|
|
24
|
-
void dumpCrashData(int fileDescriptor) const noexcept;
|
|
25
|
-
|
|
26
|
-
static void enableSamplingProfiler() noexcept;
|
|
27
|
-
static void disableSamplingProfiler() noexcept;
|
|
28
|
-
static void dumpSampledTraceToFile(const std::string &fileName) noexcept;
|
|
29
|
-
void addToProfiling() const noexcept;
|
|
30
|
-
void removeFromProfiling() const noexcept;
|
|
31
|
-
|
|
32
|
-
HermesShim(const HermesShim &) = delete;
|
|
33
|
-
HermesShim &operator=(const HermesShim &) = delete;
|
|
34
|
-
|
|
35
|
-
private:
|
|
36
|
-
// It must be a raw pointer to avoid circular reference.
|
|
37
|
-
facebook::hermes::HermesRuntime *nonAbiSafeRuntime_{};
|
|
38
|
-
hermes_runtime runtime_{};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
} // namespace Microsoft::ReactNative
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
#include "NapiJsiV8RuntimeHolder.h"
|
|
5
|
-
|
|
6
|
-
using namespace facebook::jsi;
|
|
7
|
-
using namespace facebook::react;
|
|
8
|
-
|
|
9
|
-
using std::shared_ptr;
|
|
10
|
-
using std::unique_ptr;
|
|
11
|
-
|
|
12
|
-
namespace Microsoft::JSI {
|
|
13
|
-
|
|
14
|
-
class NapiTask {
|
|
15
|
-
public:
|
|
16
|
-
NapiTask(void *task, v8_task_run_cb onTaskRun, v8_task_release_cb onTaskRelease)
|
|
17
|
-
: task_(task), onTaskRun_(onTaskRun), onTaskRelease_(onTaskRelease) {}
|
|
18
|
-
|
|
19
|
-
NapiTask(NapiTask &&other)
|
|
20
|
-
: task_(std::exchange(other.task_, nullptr)),
|
|
21
|
-
onTaskRun_(std::exchange(other.onTaskRun_, nullptr)),
|
|
22
|
-
onTaskRelease_(std::exchange(other.onTaskRelease_, nullptr)) {}
|
|
23
|
-
|
|
24
|
-
NapiTask &operator=(NapiTask &&other) {
|
|
25
|
-
if (this != &other) {
|
|
26
|
-
NapiTask taskToDelete(std::move(*this));
|
|
27
|
-
task_ = std::exchange(other.task_, nullptr);
|
|
28
|
-
onTaskRun_ = std::exchange(other.onTaskRun_, nullptr);
|
|
29
|
-
onTaskRelease_ = std::exchange(other.onTaskRelease_, nullptr);
|
|
30
|
-
}
|
|
31
|
-
return *this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
NapiTask(const NapiTask &other) = delete;
|
|
35
|
-
NapiTask &operator=(const NapiTask &other) = delete;
|
|
36
|
-
|
|
37
|
-
~NapiTask() {
|
|
38
|
-
if (task_ != nullptr) {
|
|
39
|
-
onTaskRelease_(task_);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
void Run() const {
|
|
44
|
-
if (task_ != nullptr) {
|
|
45
|
-
onTaskRun_(task_);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private:
|
|
50
|
-
void *task_;
|
|
51
|
-
v8_task_run_cb onTaskRun_;
|
|
52
|
-
v8_task_release_cb onTaskRelease_;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
class NapiTaskRunner {
|
|
56
|
-
public:
|
|
57
|
-
NapiTaskRunner(std::shared_ptr<facebook::react::MessageQueueThread> jsQueue) : m_jsQueue(std::move(jsQueue)) {}
|
|
58
|
-
|
|
59
|
-
static v8_task_runner_t Create(std::shared_ptr<facebook::react::MessageQueueThread> jsQueue) {
|
|
60
|
-
NapiTaskRunner *taskRunner = new NapiTaskRunner(std::move(jsQueue));
|
|
61
|
-
return v8_create_task_runner(reinterpret_cast<void *>(taskRunner), &PostTask, &Release);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private:
|
|
65
|
-
static void __cdecl PostTask(
|
|
66
|
-
void *taskRunner,
|
|
67
|
-
void *task,
|
|
68
|
-
v8_task_run_cb onTaskRun,
|
|
69
|
-
v8_task_release_cb onTaskRelease) {
|
|
70
|
-
auto napiTask = std::make_shared<NapiTask>(task, onTaskRun, onTaskRelease);
|
|
71
|
-
reinterpret_cast<NapiTaskRunner *>(taskRunner)->m_jsQueue->runOnQueue([napiTask = std::move(napiTask)] {
|
|
72
|
-
napiTask->Run();
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
static void __cdecl Release(void *taskRunner) {
|
|
77
|
-
delete reinterpret_cast<NapiTaskRunner *>(taskRunner);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private:
|
|
81
|
-
std::shared_ptr<facebook::react::MessageQueueThread> m_jsQueue;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
NapiJsiV8RuntimeHolder::NapiJsiV8RuntimeHolder(
|
|
85
|
-
shared_ptr<DevSettings> devSettings,
|
|
86
|
-
shared_ptr<MessageQueueThread> jsQueue,
|
|
87
|
-
unique_ptr<ScriptStore> &&scriptStore,
|
|
88
|
-
unique_ptr<PreparedScriptStore> &&preparedScriptStore) noexcept
|
|
89
|
-
: m_useDirectDebugger{devSettings->useDirectDebugger},
|
|
90
|
-
m_debuggerBreakOnNextLine{devSettings->debuggerBreakOnNextLine},
|
|
91
|
-
m_debuggerPort{devSettings->debuggerPort},
|
|
92
|
-
m_debuggerRuntimeName{devSettings->debuggerRuntimeName},
|
|
93
|
-
m_jsQueue{jsQueue},
|
|
94
|
-
m_scriptStore{std::move(scriptStore)},
|
|
95
|
-
m_preparedScriptStore{std::move(preparedScriptStore)} {}
|
|
96
|
-
|
|
97
|
-
void NapiJsiV8RuntimeHolder::InitRuntime() noexcept {
|
|
98
|
-
napi_ext_env_settings settings{};
|
|
99
|
-
settings.this_size = sizeof(settings);
|
|
100
|
-
if (m_debuggerPort > 0)
|
|
101
|
-
settings.inspector_port = m_debuggerPort;
|
|
102
|
-
|
|
103
|
-
settings.flags.enable_inspector = m_useDirectDebugger;
|
|
104
|
-
settings.flags.wait_for_debugger = m_debuggerBreakOnNextLine;
|
|
105
|
-
// TODO: args.debuggerRuntimeName = debuggerRuntimeName_;
|
|
106
|
-
settings.foreground_task_runner = NapiTaskRunner::Create(m_jsQueue);
|
|
107
|
-
|
|
108
|
-
napi_ext_script_cache scriptCache = InitScriptCache(std::move(m_preparedScriptStore));
|
|
109
|
-
settings.script_cache = &scriptCache;
|
|
110
|
-
|
|
111
|
-
napi_env env{};
|
|
112
|
-
napi_ext_create_env(&settings, &env);
|
|
113
|
-
// Associate environment to holder.
|
|
114
|
-
napi_set_instance_data(env, this, nullptr /*finalize_cb*/, nullptr /*finalize_hint*/);
|
|
115
|
-
|
|
116
|
-
m_runtime = MakeNodeApiJsiRuntime(env);
|
|
117
|
-
m_ownThreadId = std::this_thread::get_id();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
struct NodeApiJsiBuffer : facebook::jsi::Buffer {
|
|
121
|
-
static std::shared_ptr<const facebook::jsi::Buffer> CreateJsiBuffer(const napi_ext_buffer *buffer) {
|
|
122
|
-
if (buffer && buffer->data) {
|
|
123
|
-
return std::shared_ptr<const facebook::jsi::Buffer>(new NodeApiJsiBuffer(buffer));
|
|
124
|
-
} else {
|
|
125
|
-
return {};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
NodeApiJsiBuffer(const napi_ext_buffer *buffer) noexcept : buffer_(*buffer) {}
|
|
130
|
-
|
|
131
|
-
~NodeApiJsiBuffer() override {
|
|
132
|
-
if (buffer_.buffer_object.finalize_cb) {
|
|
133
|
-
buffer_.buffer_object.finalize_cb(nullptr, buffer_.buffer_object.data, buffer_.buffer_object.finalize_hint);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const uint8_t *data() const override {
|
|
138
|
-
return buffer_.data;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
size_t size() const override {
|
|
142
|
-
return buffer_.byte_size;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private:
|
|
146
|
-
napi_ext_buffer buffer_;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
napi_ext_script_cache NapiJsiV8RuntimeHolder::InitScriptCache(
|
|
150
|
-
unique_ptr<PreparedScriptStore> &&preparedScriptStore) noexcept {
|
|
151
|
-
napi_ext_script_cache scriptCache{};
|
|
152
|
-
scriptCache.cache_object = NativeObjectWrapper<unique_ptr<PreparedScriptStore>>::Wrap(std::move(preparedScriptStore));
|
|
153
|
-
scriptCache.load_cached_script = [](napi_env env,
|
|
154
|
-
napi_ext_script_cache *script_cache,
|
|
155
|
-
napi_ext_cached_script_metadata *script_metadata,
|
|
156
|
-
napi_ext_buffer *result) -> napi_status {
|
|
157
|
-
PreparedScriptStore *scriptStore = reinterpret_cast<PreparedScriptStore *>(script_cache->cache_object.data);
|
|
158
|
-
std::shared_ptr<const facebook::jsi::Buffer> buffer = scriptStore->tryGetPreparedScript(
|
|
159
|
-
ScriptSignature{script_metadata->source_url, script_metadata->source_hash},
|
|
160
|
-
JSRuntimeSignature{script_metadata->runtime_name, script_metadata->runtime_version},
|
|
161
|
-
script_metadata->tag);
|
|
162
|
-
if (buffer) {
|
|
163
|
-
result->buffer_object = NativeObjectWrapper<std::shared_ptr<const facebook::jsi::Buffer>>::Wrap(
|
|
164
|
-
std::shared_ptr<const facebook::jsi::Buffer>{buffer});
|
|
165
|
-
result->data = buffer->data();
|
|
166
|
-
result->byte_size = buffer->size();
|
|
167
|
-
} else {
|
|
168
|
-
*result = napi_ext_buffer{};
|
|
169
|
-
}
|
|
170
|
-
return napi_ok;
|
|
171
|
-
};
|
|
172
|
-
scriptCache.store_cached_script = [](napi_env env,
|
|
173
|
-
napi_ext_script_cache *script_cache,
|
|
174
|
-
napi_ext_cached_script_metadata *script_metadata,
|
|
175
|
-
const napi_ext_buffer *buffer) -> napi_status {
|
|
176
|
-
PreparedScriptStore *scriptStore = reinterpret_cast<PreparedScriptStore *>(script_cache->cache_object.data);
|
|
177
|
-
scriptStore->persistPreparedScript(
|
|
178
|
-
NodeApiJsiBuffer::CreateJsiBuffer(buffer),
|
|
179
|
-
ScriptSignature{script_metadata->source_url, script_metadata->source_hash},
|
|
180
|
-
JSRuntimeSignature{script_metadata->runtime_name, script_metadata->runtime_version},
|
|
181
|
-
script_metadata->tag);
|
|
182
|
-
return napi_ok;
|
|
183
|
-
};
|
|
184
|
-
return scriptCache;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
#pragma region Microsoft::JSI::RuntimeHolderLazyInit
|
|
188
|
-
|
|
189
|
-
facebook::react::JSIEngineOverride NapiJsiV8RuntimeHolder::getRuntimeType() noexcept {
|
|
190
|
-
return facebook::react::JSIEngineOverride::V8NodeApi;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
shared_ptr<Runtime> NapiJsiV8RuntimeHolder::getRuntime() noexcept /*override*/
|
|
194
|
-
{
|
|
195
|
-
std::call_once(m_onceFlag, [this]() { InitRuntime(); });
|
|
196
|
-
|
|
197
|
-
if (!m_runtime)
|
|
198
|
-
std::terminate();
|
|
199
|
-
|
|
200
|
-
// V8 NapiJsiRuntime is not known to be thread safe.
|
|
201
|
-
if (m_ownThreadId != std::this_thread::get_id())
|
|
202
|
-
__fastfail(FAST_FAIL_INVALID_THREAD);
|
|
203
|
-
|
|
204
|
-
return m_runtime;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
#pragma endregion Microsoft::JSI::RuntimeHolderLazyInit
|
|
208
|
-
|
|
209
|
-
} // namespace Microsoft::JSI
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
#pragma once
|
|
5
|
-
|
|
6
|
-
#include <DevSettings.h>
|
|
7
|
-
#include <JSI/NodeApiJsiRuntime.h>
|
|
8
|
-
#include "RuntimeHolder.h"
|
|
9
|
-
#include "ScriptStore.h"
|
|
10
|
-
|
|
11
|
-
#include <cxxreact/MessageQueueThread.h>
|
|
12
|
-
|
|
13
|
-
namespace Microsoft::JSI {
|
|
14
|
-
|
|
15
|
-
class NapiJsiV8RuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
|
|
16
|
-
public:
|
|
17
|
-
std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept override;
|
|
18
|
-
facebook::react::JSIEngineOverride getRuntimeType() noexcept override;
|
|
19
|
-
|
|
20
|
-
NapiJsiV8RuntimeHolder(
|
|
21
|
-
std::shared_ptr<facebook::react::DevSettings> devSettings,
|
|
22
|
-
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue,
|
|
23
|
-
std::unique_ptr<facebook::jsi::ScriptStore> &&scriptStore,
|
|
24
|
-
std::unique_ptr<facebook::jsi::PreparedScriptStore> &&preparedScriptStore) noexcept;
|
|
25
|
-
|
|
26
|
-
private:
|
|
27
|
-
void InitRuntime() noexcept;
|
|
28
|
-
napi_ext_script_cache InitScriptCache(
|
|
29
|
-
std::unique_ptr<facebook::jsi::PreparedScriptStore> &&preparedScriptStore) noexcept;
|
|
30
|
-
|
|
31
|
-
std::shared_ptr<facebook::jsi::Runtime> m_runtime;
|
|
32
|
-
std::shared_ptr<facebook::react::MessageQueueThread> m_jsQueue;
|
|
33
|
-
|
|
34
|
-
std::unique_ptr<facebook::jsi::ScriptStore> m_scriptStore;
|
|
35
|
-
std::unique_ptr<facebook::jsi::PreparedScriptStore> m_preparedScriptStore;
|
|
36
|
-
|
|
37
|
-
std::once_flag m_onceFlag;
|
|
38
|
-
std::thread::id m_ownThreadId;
|
|
39
|
-
|
|
40
|
-
uint16_t m_debuggerPort;
|
|
41
|
-
bool m_useDirectDebugger{false};
|
|
42
|
-
bool m_debuggerBreakOnNextLine{false};
|
|
43
|
-
std::string m_debuggerRuntimeName;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
} // namespace Microsoft::JSI
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
#include "pch.h"
|
|
5
|
-
|
|
6
|
-
#include <V8JsiRuntime.h>
|
|
7
|
-
#include "V8JSIRuntimeHolder.h"
|
|
8
|
-
|
|
9
|
-
#include <atomic>
|
|
10
|
-
#include <queue>
|
|
11
|
-
|
|
12
|
-
using namespace facebook;
|
|
13
|
-
using namespace facebook::react;
|
|
14
|
-
|
|
15
|
-
namespace facebook {
|
|
16
|
-
namespace react {
|
|
17
|
-
|
|
18
|
-
class TaskRunnerAdapter : public v8runtime::JSITaskRunner {
|
|
19
|
-
public:
|
|
20
|
-
TaskRunnerAdapter(std::shared_ptr<facebook::react::MessageQueueThread> jsQueue) : jsQueue_(std::move(jsQueue)) {}
|
|
21
|
-
|
|
22
|
-
void postTask(std::unique_ptr<v8runtime::JSITask> task) override {
|
|
23
|
-
std::shared_ptr<v8runtime::JSITask> shared_task(task.release());
|
|
24
|
-
jsQueue_->runOnQueue([shared_task2 = std::move(shared_task)]() { shared_task2->run(); });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private:
|
|
28
|
-
TaskRunnerAdapter(const TaskRunnerAdapter &) = delete;
|
|
29
|
-
TaskRunnerAdapter &operator=(const TaskRunnerAdapter &) = delete;
|
|
30
|
-
|
|
31
|
-
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue_;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
facebook::react::JSIEngineOverride V8JSIRuntimeHolder::getRuntimeType() noexcept {
|
|
35
|
-
return facebook::react::JSIEngineOverride::V8;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
std::shared_ptr<facebook::jsi::Runtime> V8JSIRuntimeHolder::getRuntime() noexcept {
|
|
39
|
-
std::call_once(once_flag_, [this]() { initRuntime(); });
|
|
40
|
-
|
|
41
|
-
if (!runtime_)
|
|
42
|
-
std::terminate();
|
|
43
|
-
|
|
44
|
-
// V8JsiRuntime is not thread safe as of now.
|
|
45
|
-
if (own_thread_id_ != std::this_thread::get_id())
|
|
46
|
-
std::terminate();
|
|
47
|
-
|
|
48
|
-
return runtime_;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void V8JSIRuntimeHolder::initRuntime() noexcept {
|
|
52
|
-
v8runtime::V8RuntimeArgs args{};
|
|
53
|
-
|
|
54
|
-
if (debuggerPort_ > 0)
|
|
55
|
-
args.inspectorPort = debuggerPort_;
|
|
56
|
-
|
|
57
|
-
args.flags.enableInspector = useDirectDebugger_;
|
|
58
|
-
args.flags.waitForDebugger = debuggerBreakOnNextLine_;
|
|
59
|
-
args.flags.enableMultiThread = enableMultiThreadSupport_;
|
|
60
|
-
args.debuggerRuntimeName = debuggerRuntimeName_;
|
|
61
|
-
|
|
62
|
-
args.foreground_task_runner = std::make_shared<TaskRunnerAdapter>(jsQueue_);
|
|
63
|
-
args.preparedScriptStore = std::move(preparedScriptStore_);
|
|
64
|
-
|
|
65
|
-
runtime_ = v8runtime::makeV8Runtime(std::move(args));
|
|
66
|
-
|
|
67
|
-
own_thread_id_ = std::this_thread::get_id();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
} // namespace react
|
|
71
|
-
} // namespace facebook
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
#pragma once
|
|
5
|
-
|
|
6
|
-
#include <DevSettings.h>
|
|
7
|
-
|
|
8
|
-
#include <JSI/RuntimeHolder.h>
|
|
9
|
-
#include <JSI/ScriptStore.h>
|
|
10
|
-
|
|
11
|
-
#include <Logging.h>
|
|
12
|
-
|
|
13
|
-
#include <cxxreact/MessageQueueThread.h>
|
|
14
|
-
|
|
15
|
-
namespace facebook {
|
|
16
|
-
namespace react {
|
|
17
|
-
|
|
18
|
-
class V8JSIRuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
|
|
19
|
-
public:
|
|
20
|
-
std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept override;
|
|
21
|
-
facebook::react::JSIEngineOverride getRuntimeType() noexcept override;
|
|
22
|
-
|
|
23
|
-
V8JSIRuntimeHolder(
|
|
24
|
-
std::shared_ptr<facebook::react::DevSettings> devSettings,
|
|
25
|
-
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue,
|
|
26
|
-
std::unique_ptr<facebook::jsi::ScriptStore> &&scriptStore,
|
|
27
|
-
std::unique_ptr<facebook::jsi::PreparedScriptStore> &&preparedScriptStore,
|
|
28
|
-
bool enableMultiThreadSupport) noexcept
|
|
29
|
-
: useDirectDebugger_(devSettings->useDirectDebugger),
|
|
30
|
-
debuggerBreakOnNextLine_(devSettings->debuggerBreakOnNextLine),
|
|
31
|
-
debuggerPort_(devSettings->debuggerPort),
|
|
32
|
-
debuggerRuntimeName_(devSettings->debuggerRuntimeName),
|
|
33
|
-
jsQueue_(std::move(jsQueue)),
|
|
34
|
-
scriptStore_(std::move(scriptStore)),
|
|
35
|
-
preparedScriptStore_(std::move(preparedScriptStore)),
|
|
36
|
-
enableMultiThreadSupport_(enableMultiThreadSupport) {}
|
|
37
|
-
|
|
38
|
-
private:
|
|
39
|
-
void initRuntime() noexcept;
|
|
40
|
-
|
|
41
|
-
std::shared_ptr<facebook::jsi::Runtime> runtime_;
|
|
42
|
-
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue_;
|
|
43
|
-
|
|
44
|
-
std::unique_ptr<facebook::jsi::ScriptStore> scriptStore_;
|
|
45
|
-
std::unique_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore_;
|
|
46
|
-
|
|
47
|
-
std::once_flag once_flag_;
|
|
48
|
-
std::thread::id own_thread_id_;
|
|
49
|
-
|
|
50
|
-
uint16_t debuggerPort_;
|
|
51
|
-
bool useDirectDebugger_;
|
|
52
|
-
bool debuggerBreakOnNextLine_;
|
|
53
|
-
bool enableMultiThreadSupport_;
|
|
54
|
-
std::string debuggerRuntimeName_;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
} // namespace react
|
|
58
|
-
} // namespace facebook
|