зеркало из https://github.com/microsoft/v8-jsi.git
Delay load v8jsi.dll (#7)
* delay load the dll by default (so that consumers can have a run-time / optional dependency on v8jsi.dll without needing to distribute it if unused); * the Platform must be process-singleton to match v8 internals (V8 is not embedder-friendly and makes several assumptions about objects that are initialized once per process - we're matching that design with our V8Platform to avoid crashes if multiple contexts are created / shut down during a process' lifetime);
This commit is contained in:
Родитель
c011ec543f
Коммит
d7f202bb5d
|
@ -6,6 +6,7 @@
|
|||
<AdditionalLibraryDirectories Condition="'$(Configuration)' == 'Debug' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">$(MSBuildThisFileDirectory)..\..\lib\Debug\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories Condition="'$(Configuration)' == 'Release' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">$(MSBuildThisFileDirectory)..\..\lib\Release\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>v8jsi.dll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>v8jsi.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"version": "0.2.2",
|
||||
"version": "0.2.3",
|
||||
"v8ref": "refs/branch-heads/8.0"
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
$OutputPath = "$PSScriptRoot\out"
|
||||
$SourcesPath = $PSScriptRoot
|
||||
$Platforms = "x64", "x86"
|
||||
$Configurations = "Release", "Debug", "Release-Clang", "EXPERIMENTAL-libcpp-Clang"
|
||||
$Configurations = "Debug", "Release", "Release-Clang", "EXPERIMENTAL-libcpp-Clang"
|
||||
|
||||
Write-Host "Downloading environment..."
|
||||
& ".\scripts\download_depottools.ps1" -SourcesPath $SourcesPath
|
||||
|
|
|
@ -1128,7 +1128,30 @@ bool V8Runtime::isFunction(const jsi::Object &obj) const {
|
|||
|
||||
bool V8Runtime::isHostObject(const jsi::Object &obj) const {
|
||||
_ISOLATE_CONTEXT_ENTER
|
||||
std::abort();
|
||||
if (objectRef(obj)->InternalFieldCount() < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto internalFieldRef = objectRef(obj)->GetInternalField(0);
|
||||
if (internalFieldRef.IsEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
v8::Local<v8::External> internalField = v8::Local<v8::External>::Cast(internalFieldRef);
|
||||
if (!internalField->Value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HostObjectProxy *hostObjectProxy = reinterpret_cast<HostObjectProxy *>(internalField->Value());
|
||||
|
||||
for (const std::shared_ptr<HostObjectLifetimeTracker>& hostObjectLifetimeTracker :
|
||||
host_object_lifetime_tracker_list_) {
|
||||
if (hostObjectLifetimeTracker->IsEqual(hostObjectProxy)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Very expensive
|
||||
|
|
|
@ -98,12 +98,14 @@ while (!use_count_s_.compare_exchange_weak(current, current + 1))
|
|||
;*/
|
||||
|
||||
if (use_count_s_++ == 0) {
|
||||
if (!platform_s_) {
|
||||
#ifdef USE_DEFAULT_PLATFORM
|
||||
platform_s_ = v8::platform::NewDefaultPlatform();
|
||||
platform_s_ = v8::platform::NewDefaultPlatform();
|
||||
#else
|
||||
platform_s_ = std::make_unique<V8Platform>(true);
|
||||
platform_s_ = std::make_unique<V8Platform>(true);
|
||||
#endif
|
||||
v8::V8::InitializePlatform(platform_s_.get());
|
||||
v8::V8::InitializePlatform(platform_s_.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,8 +116,10 @@ while (!use_count_s_.compare_exchange_weak(current, current - 1))
|
|||
;*/
|
||||
|
||||
if (--use_count_s_ == 0) {
|
||||
v8::V8::ShutdownPlatform();
|
||||
platform_s_ = nullptr;
|
||||
// We cannot shutdown the platform once created because V8 internally references bits of the platform from process-globals
|
||||
// This cannot be worked around, the design of V8 is not currently embedder-friendly
|
||||
//v8::V8::ShutdownPlatform();
|
||||
//platform_s_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,6 +194,10 @@ class V8Runtime : public facebook::jsi::Runtime {
|
|||
std::cout << "~HostObjectLifetimeTracker" << std::endl;
|
||||
}
|
||||
|
||||
bool IsEqual(IHostProxy *hostProxy) const noexcept {
|
||||
return hostProxy_ == hostProxy;
|
||||
}
|
||||
|
||||
private:
|
||||
v8::Global<v8::Object> objectTracker_;
|
||||
std::atomic<bool> isReset_{false};
|
||||
|
|
Загрузка…
Ссылка в новой задаче