Revert "(Reland)[Bindings] Create and use V8 context snapshots."
This reverts commit f6a5016d0313daf6e798a568c31124e159569bb5.
Reason for revert: Speculative revert for failing webkit tests at https://build.chromium.org/p/chromium.webkit/builders/WebKit%20Linux%20Trusty%20%28dbg%29/builds/4057.
Original change's description:
> (Reland)[Bindings] Create and use V8 context snapshots.
>
> This CL does two things.
>
> 1. In compile time, creates a snapshot file, which consists of V8 contexts.
> 2. Creates v8::Context from the snapshot in LocalWindowProxy::CreateContext().
>
> We expect this speeds up context creation for 3 times faster on Android.
> Detailed information is described in the design doc [1].
>
>
> [1] Design doc: https://docs.google.com/document/d/1jpQQX0piaxcHJPWakp_Kr_03g5Gnma5h5-Kdlqu7jVQ/edit#heading=h.k6iklq6rvd30
>
>
> This CL is a re-land of https://chromium-review.googlesource.com/c/594608/
> Test expectations are changed due to http://crbug.com/705364
>
> BUG=588893, 617892, 705364
> TBR=rkc, jochen, dchen, kinuko, eroman, thakis
>
> Change-Id: I8e98ff881a2219380edc3c48de38bc661c139fb1
> Reviewed-on: https://chromium-review.googlesource.com/596167
> Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
> Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Reviewed-by: Kentaro Hara <haraken@chromium.org>
> Reviewed-by: Hitoshi Yoshida <peria@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#495105}
TBR=rkc@chromium.org,dcheng@chromium.org,peria@chromium.org,kinuko@chromium.org,thakis@chromium.org,eroman@chromium.org,yukishiino@chromium.org,haraken@chromium.org,yangguo@chromium.org,jochen@chromium.org
Change-Id: I1050b0b84372ec683f3409ef77b9e9c45e39528f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 588893, 617892, 705364
Reviewed-on: https://chromium-review.googlesource.com/618746
Reviewed-by: Max Morin <maxmorin@chromium.org>
Commit-Queue: Max Morin <maxmorin@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#495122}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: f0d13c9a82041e4c47245aff80556cf3c0c7a7ac
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-2x-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-2x-expected.txt
index 4ca2b4c..1d4cce5 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-2x-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-2x-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=320
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 192dpi
@media device-pixel-ratio = 2
window.devicePixelRatio = 2
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-expected.txt
index 55b8a7e..03ba35c 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=320
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-only-viewport-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-only-viewport-expected.txt
index 78a1df5..7beb25a 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-only-viewport-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-320-only-viewport-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=320
@media orientation = landscape
-window.orientation = 0
+window.orientation
Widths:
doc.docElem.clientWidth = 320px
doc.docElem.offsetWidth = 320px
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-2x-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-2x-expected.txt
index 85d9b5b..b84aa8c 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-2x-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-2x-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=980
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 192dpi
@media device-pixel-ratio = 2
window.devicePixelRatio = 2
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-expected.txt
index a4049a3..bf60f7d 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=980
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-only-viewport-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-only-viewport-expected.txt
index 62484f0..f2017f0 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-only-viewport-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-980-only-viewport-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=980
@media orientation = landscape
-window.orientation = 0
+window.orientation
Widths:
doc.docElem.clientWidth = 980px
doc.docElem.offsetWidth = 980px
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-controls-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-controls-expected.txt
index 53d765e..f30597c 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-controls-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-controls-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?none
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-2x-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-2x-expected.txt
index 99cfdc9..7af4b24 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-2x-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-2x-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=dw
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 192dpi
@media device-pixel-ratio = 2
window.devicePixelRatio = 2
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-expected.txt
index 26cba55..69b3f42 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-dw-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=dw
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-initial-scale-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-initial-scale-expected.txt
index 275c6e3..401808d 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-initial-scale-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-initial-scale-expected.txt
@@ -11,7 +11,7 @@
window.screenY = 0px
Viewport: = ?w=980
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 288dpi
@media device-pixel-ratio = 3
window.devicePixelRatio = 3
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-insets-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-insets-expected.txt
index c758332..f357336 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-insets-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-insets-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 20px
Viewport: = ?none
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-2x-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-2x-expected.txt
index e4adbe1..dfd32a2 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-2x-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-2x-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?none
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 192dpi
@media device-pixel-ratio = 2
window.devicePixelRatio = 2
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-expected.txt
index ca8e4cb..06d447e 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-none-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?none
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-restore-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-restore-expected.txt
index 71012a0..66e8ce4 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-restore-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-restore-expected.txt
@@ -6,7 +6,7 @@
window.screenY = 0px
Viewport: = ?w=320
@media orientation = landscape
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-dw-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-dw-expected.txt
index b4e2cea..9df155a 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-dw-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-dw-expected.txt
@@ -9,7 +9,7 @@
window.screenY = 0px
Viewport: = ?w=dw
@media orientation = portrait
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-expected.txt b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-expected.txt
index 2222e52..8540d74 100644
--- a/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-expected.txt
+++ b/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-small-expected.txt
@@ -9,7 +9,7 @@
window.screenY = 0px
Viewport: = ?none
@media orientation = portrait
-window.orientation = 0
+window.orientation
@media resolution = 96dpi
@media device-pixel-ratio = 1
window.devicePixelRatio = 1
diff --git a/WebKit/Source/bindings/bindings.gni b/WebKit/Source/bindings/bindings.gni
index 743c9be..ac55188 100644
--- a/WebKit/Source/bindings/bindings.gni
+++ b/WebKit/Source/bindings/bindings.gni
@@ -144,8 +144,6 @@
"core/v8/V8PersistentValueVector.h",
"core/v8/V8ScriptRunner.cpp",
"core/v8/V8ScriptRunner.h",
- "core/v8/V8ContextSnapshot.cpp",
- "core/v8/V8ContextSnapshot.h",
"core/v8/V8StringResource.h",
"core/v8/V8V0CustomElementLifecycleCallbacks.cpp",
"core/v8/V8V0CustomElementLifecycleCallbacks.h",
diff --git a/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp b/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
index c2be705..515683e 100644
--- a/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
+++ b/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
@@ -33,7 +33,6 @@
#include "bindings/core/v8/ScriptController.h"
#include "bindings/core/v8/ToV8ForCore.h"
#include "bindings/core/v8/V8BindingForCore.h"
-#include "bindings/core/v8/V8ContextSnapshot.h"
#include "bindings/core/v8/V8DOMActivityLogger.h"
#include "bindings/core/v8/V8GCForContextDispose.h"
#include "bindings/core/v8/V8HTMLDocument.h"
@@ -115,7 +114,7 @@
}
void LocalWindowProxy::Initialize() {
- TRACE_EVENT1("v8", "LocalWindowProxy::Initialize", "IsMainFrame",
+ TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow",
GetFrame()->IsMainFrame());
DEFINE_STATIC_LOCAL(
CustomCountHistogram, main_frame_hist,
@@ -140,8 +139,6 @@
}
SetupWindowPrototypeChain();
- V8ContextSnapshot::InstallRuntimeEnabledFeatures(context,
- GetFrame()->GetDocument());
SecurityOrigin* origin = 0;
if (world_->IsMainWorld()) {
@@ -162,32 +159,31 @@
SetSecurityToken(origin);
}
- {
- TRACE_EVENT1("v8", "ContextCreatedNotification", "IsMainFrame",
- GetFrame()->IsMainFrame());
- MainThreadDebugger::Instance()->ContextCreated(script_state_.Get(),
- GetFrame(), origin);
- GetFrame()->Client()->DidCreateScriptContext(context, world_->GetWorldId());
+ MainThreadDebugger::Instance()->ContextCreated(script_state_.Get(),
+ GetFrame(), origin);
+ GetFrame()->Client()->DidCreateScriptContext(context, world_->GetWorldId());
- InstallConditionalFeaturesOnGlobal(&V8Window::wrapperTypeInfo,
- script_state_.Get());
+ InstallConditionalFeaturesOnGlobal(&V8Window::wrapperTypeInfo,
+ script_state_.Get());
- if (world_->IsMainWorld()) {
- // For the main world, install any remaining conditional bindings (i.e.
- // for origin trials, which do not apply to extensions). Some conditional
- // bindings cannot be enabled until the execution context is available
- // (e.g. parsing the document, inspecting HTTP headers).
- InstallConditionalFeatures(&V8Window::wrapperTypeInfo,
- script_state_.Get(), v8::Local<v8::Object>(),
- v8::Local<v8::Function>());
- GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
- }
+ if (world_->IsMainWorld()) {
+ // For the main world, install any remaining conditional bindings (i.e. for
+ // origin trials, which do not apply to extensions). Some conditional
+ // bindings cannot be enabled until the execution context is available
+ // (e.g. parsing the document, inspecting HTTP headers).
+ InstallConditionalFeatures(&V8Window::wrapperTypeInfo, script_state_.Get(),
+ v8::Local<v8::Object>(),
+ v8::Local<v8::Function>());
+ GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
}
}
void LocalWindowProxy::CreateContext() {
- TRACE_EVENT1("v8", "LocalWindowProxy::CreateContext", "IsMainFrame",
- GetFrame()->IsMainFrame());
+ // Create a new v8::Context with the window object as the global object
+ // (aka the inner global). Reuse the outer global proxy if it already exists.
+ v8::Local<v8::ObjectTemplate> global_template =
+ V8Window::domTemplate(GetIsolate(), *world_)->InstanceTemplate();
+ CHECK(!global_template.IsEmpty());
Vector<const char*> extension_names;
// Dynamically tell v8 about our extensions now.
@@ -214,22 +210,9 @@
v8::Isolate* isolate = GetIsolate();
V8PerIsolateData::UseCounterDisabledScope use_counter_disabled(
V8PerIsolateData::From(isolate));
- Document* document = GetFrame()->GetDocument();
-
- v8::Local<v8::Object> global_proxy = global_proxy_.NewLocal(isolate);
- context = V8ContextSnapshot::CreateContextFromSnapshot(
- isolate, World(), &extension_configuration, global_proxy, document);
-
- // Even if we enable V8 context snapshot feature, we may hit this branch
- // in some cases, e.g. loading XML files.
- if (context.IsEmpty()) {
- v8::Local<v8::ObjectTemplate> global_template =
- V8Window::domTemplate(isolate, *world_)->InstanceTemplate();
- CHECK(!global_template.IsEmpty());
- context = v8::Context::New(isolate, &extension_configuration,
- global_template, global_proxy);
- VLOG(1) << "A context is created NOT from snapshot";
- }
+ context =
+ v8::Context::New(GetIsolate(), &extension_configuration,
+ global_template, global_proxy_.NewLocal(isolate));
}
CHECK(!context.IsEmpty());
@@ -246,9 +229,6 @@
}
void LocalWindowProxy::SetupWindowPrototypeChain() {
- TRACE_EVENT1("v8", "LocalWindowProxy::SetupWindowPrototypeChain",
- "IsMainFrame", GetFrame()->IsMainFrame());
-
// Associate the window wrapper object and its prototype chain with the
// corresponding native DOMWindow object.
DOMWindow* window = GetFrame()->DomWindow();
@@ -293,15 +273,12 @@
void LocalWindowProxy::UpdateDocumentProperty() {
DCHECK(world_->IsMainWorld());
- TRACE_EVENT1("v8", "LocalWindowProxy::UpdateDocumentProperty", "IsMainFrame",
- GetFrame()->IsMainFrame());
ScriptState::Scope scope(script_state_.Get());
v8::Local<v8::Context> context = script_state_->GetContext();
v8::Local<v8::Value> document_wrapper =
ToV8(GetFrame()->GetDocument(), context->Global(), GetIsolate());
DCHECK(document_wrapper->IsObject());
-
// Update the cached accessor for window.document.
CHECK(V8PrivateProperty::GetWindowDocumentCachedAccessor(GetIsolate())
.Set(context->Global(), document_wrapper));
@@ -363,8 +340,8 @@
String frame_security_token = frame_security_origin->ToString();
// We need to check the return value of domainWasSetInDOM() on the
// frame's SecurityOrigin because, if that's the case, only
- // SecurityOrigin::domain_ would have been modified.
- // domain_ is not used by SecurityOrigin::toString(), so we would end
+ // SecurityOrigin::m_domain would have been modified.
+ // m_domain is not used by SecurityOrigin::toString(), so we would end
// up generating the same token that was already set.
if (frame_security_origin->DomainWasSetInDOM() ||
frame_security_token.IsEmpty() || frame_security_token == "null") {
diff --git a/WebKit/Source/bindings/core/v8/V8ContextSnapshot.cpp b/WebKit/Source/bindings/core/v8/V8ContextSnapshot.cpp
deleted file mode 100644
index d415cd8..0000000
--- a/WebKit/Source/bindings/core/v8/V8ContextSnapshot.cpp
+++ /dev/null
@@ -1,514 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "bindings/core/v8/V8ContextSnapshot.h"
-
-#include <array>
-#include <cstring>
-
-#include "bindings/core/v8/GeneratedCodeHelper.h"
-#include "bindings/core/v8/V8Document.h"
-#include "bindings/core/v8/V8EventTarget.h"
-#include "bindings/core/v8/V8HTMLDocument.h"
-#include "bindings/core/v8/V8Initializer.h"
-#include "bindings/core/v8/V8Node.h"
-#include "bindings/core/v8/V8Window.h"
-#include "platform/bindings/DOMWrapperWorld.h"
-#include "platform/bindings/V8ObjectConstructor.h"
-#include "platform/bindings/V8PerIsolateData.h"
-#include "platform/bindings/V8PrivateProperty.h"
-#include "platform/instrumentation/tracing/TraceEvent.h"
-#include "v8/include/v8.h"
-
-#if defined(MEMORY_SANITIZER)
-#include <sanitizer/msan_interface.h> // NOLINT
-#endif
-
-namespace blink {
-
-namespace {
-
-intptr_t* g_v8_context_snapshot_reference_table = nullptr;
-
-// TODO(peria): This method is almost a copy of
-// V8PerContext::ConstructorForTypeSlowCase(), so merge with it.
-v8::Local<v8::Function> ConstructPlainType(v8::Isolate* isolate,
- const DOMWrapperWorld& world,
- v8::Local<v8::Context> context,
- const WrapperTypeInfo* type) {
- v8::Context::Scope scope(context);
- // We shouldn't reach this point for the types that are implemented in v8 such
- // as typed arrays and hence don't have domTemplateFunction.
- DCHECK(type->dom_template_function);
- v8::Local<v8::FunctionTemplate> interface_template =
- type->domTemplate(isolate, world);
- // Getting the function might fail if we're running out of stack or memory.
- v8::Local<v8::Function> interface_object =
- interface_template->GetFunction(context).ToLocalChecked();
-
- if (type->parent_class) {
- v8::Local<v8::Object> prototype_template =
- ConstructPlainType(isolate, world, context, type->parent_class);
- CHECK(interface_object->SetPrototype(context, prototype_template)
- .ToChecked());
- }
-
- v8::Local<v8::Value> prototype_value =
- interface_object->Get(context, V8AtomicString(isolate, "prototype"))
- .ToLocalChecked();
- CHECK(prototype_value->IsObject());
- v8::Local<v8::Object> prototype_object = prototype_value.As<v8::Object>();
- if (prototype_object->InternalFieldCount() ==
- kV8PrototypeInternalFieldcount &&
- type->wrapper_type_prototype ==
- WrapperTypeInfo::kWrapperTypeObjectPrototype) {
- prototype_object->SetAlignedPointerInInternalField(
- kV8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type));
- }
- type->PreparePrototypeAndInterfaceObject(
- context, world, prototype_object, interface_object, interface_template);
-
- return interface_object;
-}
-
-// TODO(peria): This method is almost a copy of
-// V8PerContext::CreateWrapperFromCacheSlowCase(), so merge with it.
-v8::Local<v8::Object> CreatePlainWrapper(v8::Isolate* isolate,
- const DOMWrapperWorld& world,
- v8::Local<v8::Context> context,
- const WrapperTypeInfo* type) {
- CHECK(V8HTMLDocument::wrapperTypeInfo.Equals(type));
-
- v8::Context::Scope scope(context);
- v8::Local<v8::Function> interface_object =
- ConstructPlainType(isolate, world, context, type);
- CHECK(!interface_object.IsEmpty());
- v8::Local<v8::Object> instance_template =
- V8ObjectConstructor::NewInstance(isolate, interface_object)
- .ToLocalChecked();
- v8::Local<v8::Object> wrapper = instance_template->Clone();
- wrapper->SetAlignedPointerInInternalField(kV8DOMWrapperTypeIndex,
- const_cast<WrapperTypeInfo*>(type));
- return wrapper;
-}
-
-int GetSnapshotIndexForWorld(const DOMWrapperWorld& world) {
- return world.IsMainWorld() ? 0 : 1;
-}
-
-// Interface templates of those classes are stored in a snapshot without any
-// runtime enabled features, so we have to install runtime enabled features on
-// them after instantiation.
-struct SnapshotInterface {
- const WrapperTypeInfo* wrapper_type_info;
- InstallRuntimeEnabledFeaturesOnTemplateFunction install_function;
-};
-SnapshotInterface g_snapshot_interfaces[] = {
- {&V8Window::wrapperTypeInfo,
- V8Window::InstallRuntimeEnabledFeaturesOnTemplate},
- {&V8HTMLDocument::wrapperTypeInfo,
- V8HTMLDocument::InstallRuntimeEnabledFeaturesOnTemplate},
- {&V8EventTarget::wrapperTypeInfo,
- V8EventTarget::InstallRuntimeEnabledFeaturesOnTemplate},
- {&V8Node::wrapperTypeInfo, V8Node::InstallRuntimeEnabledFeaturesOnTemplate},
- {&V8Document::wrapperTypeInfo,
- V8Document::InstallRuntimeEnabledFeaturesOnTemplate},
-};
-constexpr size_t kSnapshotInterfaceSize =
- WTF_ARRAY_LENGTH(g_snapshot_interfaces);
-
-enum class InternalFieldType : uint8_t {
- kNone,
- kNodeType,
- kDocumentType,
- kHTMLDocumentType,
- kHTMLDocumentObject,
-};
-
-const WrapperTypeInfo* FieldTypeToWrapperTypeInfo(InternalFieldType type) {
- switch (type) {
- case InternalFieldType::kNone:
- NOTREACHED();
- break;
- case InternalFieldType::kNodeType:
- return &V8Node::wrapperTypeInfo;
- case InternalFieldType::kDocumentType:
- return &V8Document::wrapperTypeInfo;
- case InternalFieldType::kHTMLDocumentType:
- return &V8HTMLDocument::wrapperTypeInfo;
- case InternalFieldType::kHTMLDocumentObject:
- return &V8HTMLDocument::wrapperTypeInfo;
- }
- NOTREACHED();
- return nullptr;
-}
-
-struct DataForDeserializer {
- STACK_ALLOCATED();
- Member<Document> document;
-};
-
-int CountExternalReferenceEntries() {
- if (!g_v8_context_snapshot_reference_table)
- return 0;
-
- int count = 0;
- for (intptr_t* p = g_v8_context_snapshot_reference_table; *p; ++p)
- ++count;
- return count;
-}
-
-} // namespace
-
-v8::Local<v8::Context> V8ContextSnapshot::CreateContextFromSnapshot(
- v8::Isolate* isolate,
- const DOMWrapperWorld& world,
- v8::ExtensionConfiguration* extension_configuration,
- v8::Local<v8::Object> global_proxy,
- Document* document) {
- if (!CanCreateContextFromSnapshot(isolate, world, document)) {
- return v8::Local<v8::Context>();
- }
-
- const int index = GetSnapshotIndexForWorld(world);
- DataForDeserializer data{document};
- v8::DeserializeInternalFieldsCallback callback =
- v8::DeserializeInternalFieldsCallback(&DeserializeInternalField, &data);
- v8::Local<v8::Context> context =
- v8::Context::FromSnapshot(isolate, index, callback,
- extension_configuration, global_proxy)
- .ToLocalChecked();
- VLOG(1) << "A context is created from snapshot for "
- << (world.IsMainWorld() ? "" : "non-") << "main world";
-
- return context;
-}
-
-void V8ContextSnapshot::InstallRuntimeEnabledFeatures(
- v8::Local<v8::Context> context,
- Document* document) {
- ScriptState* script_state = ScriptState::From(context);
- v8::Isolate* isolate = script_state->GetIsolate();
- const DOMWrapperWorld& world = script_state->World();
- if (!CanCreateContextFromSnapshot(isolate, world, document)) {
- return;
- }
-
- TRACE_EVENT1("v8", "V8ContextSnapshot::InstallRuntimeEnabled", "IsMainFrame",
- world.IsMainWorld());
-
- v8::Local<v8::String> prototype_str = V8AtomicString(isolate, "prototype");
- V8PerContextData* data = script_state->PerContextData();
-
- v8::Local<v8::Object> global_proxy = context->Global();
- {
- v8::Local<v8::Object> window_wrapper =
- global_proxy->GetPrototype().As<v8::Object>();
- const WrapperTypeInfo* type = &V8Window::wrapperTypeInfo;
- v8::Local<v8::Function> interface = data->ConstructorForType(type);
- v8::Local<v8::Object> prototype = interface->Get(context, prototype_str)
- .ToLocalChecked()
- .As<v8::Object>();
- V8Window::install_runtime_enabled_features_function_(
- isolate, world, window_wrapper, prototype, interface);
- }
- {
- const WrapperTypeInfo* type = &V8EventTarget::wrapperTypeInfo;
- v8::Local<v8::Function> interface = data->ConstructorForType(type);
- v8::Local<v8::Object> prototype = interface->Get(context, prototype_str)
- .ToLocalChecked()
- .As<v8::Object>();
- V8EventTarget::InstallRuntimeEnabledFeatures(
- isolate, world, v8::Local<v8::Object>(), prototype, interface);
- }
-
- if (!world.IsMainWorld()) {
- return;
- }
-
- // The below code handles window.document on the main world.
- {
- CHECK(document);
- DCHECK(document->IsHTMLDocument());
- CHECK(document->ContainsWrapper());
- v8::Local<v8::Object> document_wrapper =
- ToV8(document, global_proxy, isolate).As<v8::Object>();
- const WrapperTypeInfo* type = &V8HTMLDocument::wrapperTypeInfo;
- v8::Local<v8::Function> interface = data->ConstructorForType(type);
- v8::Local<v8::Object> prototype = interface->Get(context, prototype_str)
- .ToLocalChecked()
- .As<v8::Object>();
- V8HTMLDocument::InstallRuntimeEnabledFeatures(
- isolate, world, document_wrapper, prototype, interface);
- }
- {
- const WrapperTypeInfo* type = &V8Document::wrapperTypeInfo;
- v8::Local<v8::Function> interface = data->ConstructorForType(type);
- v8::Local<v8::Object> prototype = interface->Get(context, prototype_str)
- .ToLocalChecked()
- .As<v8::Object>();
- V8Document::InstallRuntimeEnabledFeatures(
- isolate, world, v8::Local<v8::Object>(), prototype, interface);
- }
- {
- const WrapperTypeInfo* type = &V8Node::wrapperTypeInfo;
- v8::Local<v8::Function> interface = data->ConstructorForType(type);
- v8::Local<v8::Object> prototype = interface->Get(context, prototype_str)
- .ToLocalChecked()
- .As<v8::Object>();
- V8Node::InstallRuntimeEnabledFeatures(
- isolate, world, v8::Local<v8::Object>(), prototype, interface);
- }
-}
-
-void V8ContextSnapshot::EnsureInterfaceTemplates(v8::Isolate* isolate) {
- if (V8PerIsolateData::From(isolate)->GetV8ContextSnapshotMode() !=
- V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot) {
- return;
- }
-
- v8::HandleScope handle_scope(isolate);
- SnapshotInterface& snapshot_window = g_snapshot_interfaces[0];
- DCHECK(V8Window::wrapperTypeInfo.Equals(snapshot_window.wrapper_type_info));
- // Update the install function for V8Window to work for partial interfaces.
- snapshot_window.install_function =
- V8Window::install_runtime_enabled_features_on_template_function_;
-
- EnsureInterfaceTemplatesForWorld(isolate, DOMWrapperWorld::MainWorld());
- // Any world types other than |kMain| are acceptable for this.
- RefPtr<DOMWrapperWorld> isolated_world = DOMWrapperWorld::Create(
- isolate, DOMWrapperWorld::WorldType::kForV8ContextSnapshotNonMain);
- EnsureInterfaceTemplatesForWorld(isolate, *isolated_world);
-}
-
-void V8ContextSnapshot::SetReferenceTable(intptr_t* table) {
- DCHECK(!g_v8_context_snapshot_reference_table);
- g_v8_context_snapshot_reference_table = table;
-}
-
-intptr_t* V8ContextSnapshot::GetReferenceTable() {
- return g_v8_context_snapshot_reference_table;
-}
-
-v8::StartupData V8ContextSnapshot::TakeSnapshot() {
- DCHECK_EQ(V8PerIsolateData::From(V8PerIsolateData::MainThreadIsolate())
- ->GetV8ContextSnapshotMode(),
- V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot);
-
- v8::SnapshotCreator* creator =
- V8PerIsolateData::From(V8PerIsolateData::MainThreadIsolate())
- ->GetSnapshotCreator();
- v8::Isolate* isolate = creator->GetIsolate();
- CHECK_EQ(isolate, v8::Isolate::GetCurrent());
-
- VLOG(1) << "External reference table has " << CountExternalReferenceEntries()
- << " entries.";
-
- // Disable all runtime enabled features
- RuntimeEnabledFeatures::SetStableFeaturesEnabled(false);
- RuntimeEnabledFeatures::SetExperimentalFeaturesEnabled(false);
- RuntimeEnabledFeatures::SetTestFeaturesEnabled(false);
-
- {
- v8::HandleScope handleScope(isolate);
- creator->SetDefaultContext(v8::Context::New(isolate));
-
- TakeSnapshotForWorld(creator, DOMWrapperWorld::MainWorld());
- // For non main worlds, we can use any type to create a context.
- TakeSnapshotForWorld(
- creator,
- *DOMWrapperWorld::Create(
- isolate, DOMWrapperWorld::WorldType::kForV8ContextSnapshotNonMain));
- }
-
- isolate->RemoveMessageListeners(V8Initializer::MessageHandlerInMainThread);
-
- v8::StartupData blob =
- creator->CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
-
-#if defined(MEMORY_SANITIZER)
- // Tell MSan to ignore uninitialized padding in the blob.
- // TODO(crbug.com/v8/3645): Remove this hack when the issue is resolved.
- __msan_unpoison(blob.data, blob.raw_size);
-#endif
-
- return blob;
-}
-
-v8::StartupData V8ContextSnapshot::SerializeInternalField(
- v8::Local<v8::Object> object,
- int index,
- void*) {
- InternalFieldType field_type = InternalFieldType::kNone;
- const WrapperTypeInfo* wrapper_type = ToWrapperTypeInfo(object);
- if (kV8DOMWrapperObjectIndex == index) {
- if (blink::V8HTMLDocument::wrapperTypeInfo.Equals(wrapper_type)) {
- field_type = InternalFieldType::kHTMLDocumentObject;
- }
- DCHECK_LE(kV8DefaultWrapperInternalFieldCount,
- object->InternalFieldCount());
- } else if (kV8DOMWrapperTypeIndex == index) {
- if (blink::V8HTMLDocument::wrapperTypeInfo.Equals(wrapper_type)) {
- field_type = InternalFieldType::kHTMLDocumentType;
- } else if (blink::V8Document::wrapperTypeInfo.Equals(wrapper_type)) {
- field_type = InternalFieldType::kDocumentType;
- } else if (blink::V8Node::wrapperTypeInfo.Equals(wrapper_type)) {
- field_type = InternalFieldType::kNodeType;
- }
- DCHECK_LE(kV8PrototypeInternalFieldcount, object->InternalFieldCount());
- }
- CHECK_NE(field_type, InternalFieldType::kNone);
-
- int size = sizeof(InternalFieldType);
- // Allocated memory on |data| will be released in
- // v8::i::PartialSerializer::SerializeEmbedderFields().
- char* data = new char[size];
- std::memcpy(data, &field_type, size);
-
- return {data, size};
-}
-
-void V8ContextSnapshot::DeserializeInternalField(v8::Local<v8::Object> object,
- int index,
- v8::StartupData payload,
- void* ptr) {
- // DeserializeInternalField() expects to be called in the main world
- // with |document| being HTMLDocument.
- CHECK_EQ(payload.raw_size, static_cast<int>(sizeof(InternalFieldType)));
- InternalFieldType type =
- *reinterpret_cast<const InternalFieldType*>(payload.data);
-
- const WrapperTypeInfo* wrapper_type_info = FieldTypeToWrapperTypeInfo(type);
- switch (type) {
- case InternalFieldType::kNodeType:
- case InternalFieldType::kDocumentType:
- case InternalFieldType::kHTMLDocumentType: {
- CHECK_EQ(index, kV8DOMWrapperTypeIndex);
- object->SetAlignedPointerInInternalField(
- index, const_cast<WrapperTypeInfo*>(wrapper_type_info));
- return;
- }
- case InternalFieldType::kHTMLDocumentObject: {
- // The below code handles window.document on the main world.
- CHECK_EQ(index, kV8DOMWrapperObjectIndex);
- v8::Isolate* isolate = v8::Isolate::GetCurrent();
- DataForDeserializer* data = static_cast<DataForDeserializer*>(ptr);
- ScriptWrappable* document = data->document;
- DCHECK(document);
-
- // Make reference from wrapper to document
- object->SetAlignedPointerInInternalField(index, document);
- // Make reference from document to wrapper
- CHECK(document->SetWrapper(isolate, wrapper_type_info, object));
- WrapperTypeInfo::WrapperCreated();
- return;
- }
- case InternalFieldType::kNone:
- NOTREACHED();
- return;
- }
-
- NOTREACHED();
-}
-
-bool V8ContextSnapshot::CanCreateContextFromSnapshot(
- v8::Isolate* isolate,
- const DOMWrapperWorld& world,
- Document* document) {
- DCHECK(document);
- if (V8PerIsolateData::From(isolate)->GetV8ContextSnapshotMode() !=
- V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot) {
- return false;
- }
-
- // When creating a context for the main world from snapshot, we also need a
- // HTMLDocument instance. If typeof window.document is not HTMLDocument, e.g.
- // SVGDocument or XMLDocument, we can't create contexts from the snapshot.
- return !world.IsMainWorld() || document->IsHTMLDocument();
-}
-
-void V8ContextSnapshot::EnsureInterfaceTemplatesForWorld(
- v8::Isolate* isolate,
- const DOMWrapperWorld& world) {
- V8PerIsolateData* data = V8PerIsolateData::From(isolate);
-
- // A snapshot has some interface templates in it. The first
- // |kSnapshotInterfaceSize| templates are for the main world, and the
- // remaining templates are for isolated worlds.
- const int index_offset = world.IsMainWorld() ? 0 : kSnapshotInterfaceSize;
-
- for (size_t i = 0; i < kSnapshotInterfaceSize; ++i) {
- auto& snapshot_interface = g_snapshot_interfaces[i];
- const WrapperTypeInfo* wrapper_type_info =
- snapshot_interface.wrapper_type_info;
- v8::Local<v8::FunctionTemplate> interface_template =
- v8::FunctionTemplate::FromSnapshot(isolate, index_offset + i)
- .ToLocalChecked();
- snapshot_interface.install_function(isolate, world, interface_template);
- CHECK(!interface_template.IsEmpty());
- data->SetInterfaceTemplate(world, wrapper_type_info, interface_template);
- }
-}
-
-void V8ContextSnapshot::TakeSnapshotForWorld(v8::SnapshotCreator* creator,
- const DOMWrapperWorld& world) {
- v8::Isolate* isolate = creator->GetIsolate();
- CHECK_EQ(isolate, v8::Isolate::GetCurrent());
-
- // Function templates
- v8::HandleScope handleScope(isolate);
- std::array<v8::Local<v8::FunctionTemplate>, kSnapshotInterfaceSize>
- interface_templates;
- v8::Local<v8::FunctionTemplate> window_template;
- for (size_t i = 0; i < kSnapshotInterfaceSize; ++i) {
- const WrapperTypeInfo* wrapper_type_info =
- g_snapshot_interfaces[i].wrapper_type_info;
- v8::Local<v8::FunctionTemplate> interface_template =
- wrapper_type_info->domTemplate(isolate, world);
- CHECK(!interface_template.IsEmpty());
- interface_templates[i] = interface_template;
- if (V8Window::wrapperTypeInfo.Equals(wrapper_type_info)) {
- window_template = interface_template;
- }
- }
- CHECK(!window_template.IsEmpty());
-
- v8::Local<v8::ObjectTemplate> window_instance_template =
- window_template->InstanceTemplate();
- CHECK(!window_instance_template.IsEmpty());
-
- v8::Local<v8::Context> context;
- {
- V8PerIsolateData::UseCounterDisabledScope use_counter_disabled(
- V8PerIsolateData::From(isolate));
- context = v8::Context::New(isolate, nullptr, window_instance_template);
- }
- CHECK(!context.IsEmpty());
-
- // For the main world context, we need to prepare a HTMLDocument wrapper and
- // set it to window.documnt.
- if (world.IsMainWorld()) {
- v8::Context::Scope scope(context);
- v8::Local<v8::Object> document_wrapper = CreatePlainWrapper(
- isolate, world, context, &V8HTMLDocument::wrapperTypeInfo);
- int indices[] = {kV8DOMWrapperObjectIndex, kV8DOMWrapperTypeIndex};
- void* values[] = {nullptr, const_cast<WrapperTypeInfo*>(
- &V8HTMLDocument::wrapperTypeInfo)};
- document_wrapper->SetAlignedPointerInInternalFields(
- WTF_ARRAY_LENGTH(indices), indices, values);
-
- // Set the cached accessor for window.document.
- CHECK(V8PrivateProperty::GetWindowDocumentCachedAccessor(isolate).Set(
- context->Global(), document_wrapper));
- }
-
- for (auto& interface_template : interface_templates) {
- creator->AddTemplate(interface_template);
- }
- creator->AddContext(context, SerializeInternalField);
-
- V8PerIsolateData::From(isolate)->ClearPersistentsForV8ContextSnapshot();
-}
-
-} // namespace blink
diff --git a/WebKit/Source/bindings/core/v8/V8ContextSnapshot.h b/WebKit/Source/bindings/core/v8/V8ContextSnapshot.h
deleted file mode 100644
index 4323358..0000000
--- a/WebKit/Source/bindings/core/v8/V8ContextSnapshot.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef V8ContextSnapshot_h
-#define V8ContextSnapshot_h
-
-#include "core/CoreExport.h"
-#include "platform/wtf/Allocator.h"
-#include "v8/include/v8.h"
-
-namespace blink {
-
-class Document;
-class DOMWrapperWorld;
-
-// This class contains helper functions to take and use a V8 context snapshot.
-//
-// The V8 context snapshot is taken by tools/v8_context_snapshot/ when Chromium
-// is built, and is used when Blink creates a new V8 context. When to build or
-// to use the V8 context snapshot, you have a table of references of C++
-// callbacks exposed to V8.
-//
-// A V8 context snapshot contains:
-// - Interface templates of Window, EventTarget, Node, Document, and
-// HTMLDocument.
-// - Two types of V8 contexts; one is for the main world, and the other is for
-// other worlds.
-// - HTMLDocument's wrapper (window.document) in the context for the main
-// world.
-//
-// Currently, the V8 context snapshot supports only the main thread. If it is
-// the main world, we need a special logic to serialize / deserialize
-// window.document (so only HTMLDocument is supported on the main world).
-// Worker threads are not yet supported.
-class CORE_EXPORT V8ContextSnapshot {
- STATIC_ONLY(V8ContextSnapshot);
-
- public:
- static v8::Local<v8::Context> CreateContextFromSnapshot(
- v8::Isolate*,
- const DOMWrapperWorld&,
- v8::ExtensionConfiguration*,
- v8::Local<v8::Object> global_proxy,
- Document*);
- // Install runtime enabled features on some v8::Object's in a context
- // created from a snapshot.
- static void InstallRuntimeEnabledFeatures(v8::Local<v8::Context>, Document*);
-
- static void EnsureInterfaceTemplates(v8::Isolate*);
-
- static void SetReferenceTable(intptr_t* table);
- static intptr_t* GetReferenceTable();
-
- // Do not call this in production.
- static v8::StartupData TakeSnapshot();
-
- private:
- static v8::StartupData SerializeInternalField(v8::Local<v8::Object> holder,
- int index,
- void* data);
- static void DeserializeInternalField(v8::Local<v8::Object> holder,
- int index,
- v8::StartupData payload,
- void* data);
- static bool CanCreateContextFromSnapshot(v8::Isolate*,
- const DOMWrapperWorld&,
- Document*);
-
- static void EnsureInterfaceTemplatesForWorld(v8::Isolate*,
- const DOMWrapperWorld&);
-
- static void TakeSnapshotForWorld(v8::SnapshotCreator*,
- const DOMWrapperWorld&);
-};
-
-} // namespace blink
-
-#endif // V8ContextSnapshot_h
diff --git a/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp b/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp
index 5e78d3d..9bac226 100644
--- a/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp
+++ b/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp
@@ -470,26 +470,23 @@
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(),
signature, config.length);
function_template->RemovePrototype();
- if (config.access_check_configuration == V8DOMConfiguration::kCheckAccess) {
+ if (config.access_check_configuration == V8DOMConfiguration::kCheckAccess)
function_template->SetAcceptAnyReceiver(false);
- }
v8::Local<v8::Function> function =
function_template->GetFunction(isolate->GetCurrentContext())
.ToLocalChecked();
- if (location & V8DOMConfiguration::kOnInstance && !instance.IsEmpty()) {
+ if (location & V8DOMConfiguration::kOnInstance && !instance.IsEmpty())
instance
->DefineOwnProperty(
isolate->GetCurrentContext(), name, function,
static_cast<v8::PropertyAttribute>(config.attribute))
.ToChecked();
- }
- if (location & V8DOMConfiguration::kOnPrototype && !prototype.IsEmpty()) {
+ if (location & V8DOMConfiguration::kOnPrototype && !prototype.IsEmpty())
prototype
->DefineOwnProperty(
isolate->GetCurrentContext(), name, function,
static_cast<v8::PropertyAttribute>(config.attribute))
.ToChecked();
- }
}
if (location & V8DOMConfiguration::kOnInterface && !interface.IsEmpty()) {
// Operations installed on the interface object must be static
@@ -756,16 +753,16 @@
WrapperTypeInfo* wrapper_type_info,
InstallTemplateFunction configure_dom_class_template) {
V8PerIsolateData* data = V8PerIsolateData::From(isolate);
- v8::Local<v8::FunctionTemplate> interface_template =
+ v8::Local<v8::FunctionTemplate> result =
data->FindInterfaceTemplate(world, wrapper_type_info);
- if (!interface_template.IsEmpty())
- return interface_template;
+ if (!result.IsEmpty())
+ return result;
- interface_template = v8::FunctionTemplate::New(
+ result = v8::FunctionTemplate::New(
isolate, V8ObjectConstructor::IsValidConstructorMode);
- configure_dom_class_template(isolate, world, interface_template);
- data->SetInterfaceTemplate(world, wrapper_type_info, interface_template);
- return interface_template;
+ configure_dom_class_template(isolate, world, result);
+ data->SetInterfaceTemplate(world, wrapper_type_info, result);
+ return result;
}
void V8DOMConfiguration::SetClassString(
diff --git a/WebKit/Source/bindings/core/v8/V8Initializer.cpp b/WebKit/Source/bindings/core/v8/V8Initializer.cpp
index 0847a40..29bbbaf 100644
--- a/WebKit/Source/bindings/core/v8/V8Initializer.cpp
+++ b/WebKit/Source/bindings/core/v8/V8Initializer.cpp
@@ -35,7 +35,6 @@
#include "bindings/core/v8/SourceLocation.h"
#include "bindings/core/v8/UseCounterCallback.h"
#include "bindings/core/v8/V8BindingForCore.h"
-#include "bindings/core/v8/V8ContextSnapshot.h"
#include "bindings/core/v8/V8DOMException.h"
#include "bindings/core/v8/V8ErrorEvent.h"
#include "bindings/core/v8/V8ErrorHandler.h"
@@ -389,8 +388,6 @@
isolate->SetUseCounterCallback(&UseCounterCallback);
isolate->SetWasmModuleCallback(WasmModuleOverride);
isolate->SetWasmInstanceCallback(WasmInstanceOverride);
-
- V8ContextSnapshot::EnsureInterfaceTemplates(isolate);
}
namespace {
@@ -464,7 +461,7 @@
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff);
}
-void V8Initializer::InitializeMainThread(intptr_t* reference_table) {
+void V8Initializer::InitializeMainThread() {
DCHECK(IsMainThread());
WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory);
@@ -478,28 +475,13 @@
// NOTE: Some threads (namely utility threads) don't have a scheduler.
WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler();
-
- V8PerIsolateData::V8ContextSnapshotMode v8_context_snapshot_mode =
- Platform::Current()->IsTakingV8ContextSnapshot()
- ? V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot
- : V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot;
- if (v8_context_snapshot_mode ==
- V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot &&
- !RuntimeEnabledFeatures::V8ContextSnapshotEnabled()) {
- v8_context_snapshot_mode =
- V8PerIsolateData::V8ContextSnapshotMode::kDontUseSnapshot;
- reference_table = nullptr;
- }
- V8ContextSnapshot::SetReferenceTable(reference_table);
-
// When timer task runner is used for PerIsolateData, GC tasks are getting
// throttled and memory usage goes up. For now we're using loading task queue
// to prevent this.
// TODO(altimin): Consider switching to timerTaskRunner here.
v8::Isolate* isolate = V8PerIsolateData::Initialize(
scheduler ? scheduler->LoadingTaskRunner()
- : Platform::Current()->CurrentThread()->GetWebTaskRunner(),
- reference_table, v8_context_snapshot_mode);
+ : Platform::Current()->CurrentThread()->GetWebTaskRunner());
InitializeV8Common(isolate);
diff --git a/WebKit/Source/bindings/core/v8/V8Initializer.h b/WebKit/Source/bindings/core/v8/V8Initializer.h
index 6e27c24..991afda 100644
--- a/WebKit/Source/bindings/core/v8/V8Initializer.h
+++ b/WebKit/Source/bindings/core/v8/V8Initializer.h
@@ -36,7 +36,7 @@
STATIC_ONLY(V8Initializer);
public:
- static void InitializeMainThread(intptr_t* reference_table);
+ static void InitializeMainThread();
static void InitializeWorker(v8::Isolate*);
static void ReportRejectedPromisesOnMainThread();
diff --git a/WebKit/Source/bindings/modules/v8/BUILD.gn b/WebKit/Source/bindings/modules/v8/BUILD.gn
index fb34ae8..28fbedf 100644
--- a/WebKit/Source/bindings/modules/v8/BUILD.gn
+++ b/WebKit/Source/bindings/modules/v8/BUILD.gn
@@ -16,7 +16,6 @@
":generate_bindings_modules_v8_interfaces",
":generate_bindings_modules_v8_partial_interfaces",
":generate_bindings_modules_v8_partial_interfaces_for_testing",
- ":generate_v8_context_snapshot_external_references",
]
}
@@ -109,37 +108,3 @@
split_count = 5
}
}
-
-action("generate_v8_context_snapshot_external_references") {
- script = "$bindings_scripts_dir/generate_v8_context_snapshot_external_references.py"
- idl_files = core_idl_files + core_idl_with_modules_dependency_files +
- modules_definition_idl_files
- output = bindings_generated_v8_context_snapshot_external_references_file
-
- inputs = idl_files + [ script ]
- outputs = [
- output,
- ]
-
- response_file_contents = rebase_path(idl_files, root_build_dir)
- args = [
- "--cache-dir",
- rebase_path(bindings_scripts_output_dir, root_build_dir),
- "--output",
- rebase_path(output, root_build_dir),
- "--idl-files-list",
- "{{response_file_name}}",
- "--info-dir",
- rebase_path("$bindings_output_dir", root_build_dir),
- "--target-component",
- "modules",
- ]
-
- deps = [
- "//third_party/WebKit/Source/bindings/core:interfaces_info_individual_core",
- "//third_party/WebKit/Source/bindings/modules:interfaces_info",
- "//third_party/WebKit/Source/bindings/modules:interfaces_info_individual_modules",
- "//third_party/WebKit/Source/bindings/scripts:cached_jinja_templates",
- "//third_party/WebKit/Source/bindings/scripts:cached_lex_yacc_tables",
- ]
-}
diff --git a/WebKit/Source/bindings/modules/v8/V8ContextSnapshotExternalReferences.h b/WebKit/Source/bindings/modules/v8/V8ContextSnapshotExternalReferences.h
deleted file mode 100644
index 3c7645e..0000000
--- a/WebKit/Source/bindings/modules/v8/V8ContextSnapshotExternalReferences.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef V8ContextSnapshotExternalReferences_h
-#define V8ContextSnapshotExternalReferences_h
-
-#include <cstdint>
-
-#include "modules/ModulesExport.h"
-#include "platform/wtf/Allocator.h"
-
-namespace blink {
-
-// V8ContextSnapshotExternalReferences::GetTable() provides a table of pointers
-// of C++ callbacks exposed to V8. The table contains C++ callbacks for DOM
-// attribute getters, setters, DOM methods, wrapper type info etc.
-class MODULES_EXPORT V8ContextSnapshotExternalReferences {
- STATIC_ONLY(V8ContextSnapshotExternalReferences);
-
- public:
- // The definition of this method is auto-generated in
- // V8ContextSnapshotExternalReferences.cpp.
- static intptr_t* GetTable();
-};
-
-} // namespace blink
-
-#endif // V8ContextSnapshotExternalReferences_h
diff --git a/WebKit/Source/bindings/modules/v8/generated.gni b/WebKit/Source/bindings/modules/v8/generated.gni
index 530cecb..23d68dc 100644
--- a/WebKit/Source/bindings/modules/v8/generated.gni
+++ b/WebKit/Source/bindings/modules/v8/generated.gni
@@ -86,6 +86,3 @@
"$bindings_modules_v8_output_dir/RemotePlaybackAvailabilityCallback.cpp",
"$bindings_modules_v8_output_dir/RemotePlaybackAvailabilityCallback.h",
]
-
-bindings_generated_v8_context_snapshot_external_references_file =
- "$bindings_modules_v8_output_dir/V8ContextSnapshotExternalReferences.cpp"
diff --git a/WebKit/Source/bindings/modules/v8/v8.gni b/WebKit/Source/bindings/modules/v8/v8.gni
index 6cba506..286f5b71 100644
--- a/WebKit/Source/bindings/modules/v8/v8.gni
+++ b/WebKit/Source/bindings/modules/v8/v8.gni
@@ -19,7 +19,6 @@
"ToV8ForModules.h",
"V8BindingForModules.cpp",
"V8BindingForModules.h",
- "V8ContextSnapshotExternalReferences.h",
"wasm/WasmResponseExtensions.cpp",
"wasm/WasmResponseExtensions.h",
"WebGLAny.cpp",
diff --git a/WebKit/Source/bindings/scripts/generate_v8_context_snapshot_external_references.py b/WebKit/Source/bindings/scripts/generate_v8_context_snapshot_external_references.py
deleted file mode 100644
index 3795d1e..0000000
--- a/WebKit/Source/bindings/scripts/generate_v8_context_snapshot_external_references.py
+++ /dev/null
@@ -1,223 +0,0 @@
-# Copyright 2017 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# pylint: disable=relative-import
-
-import argparse
-import os
-
-from code_generator import initialize_jinja_env
-from idl_reader import IdlReader
-from utilities import create_component_info_provider, write_file
-import utilities
-import v8_attributes
-import v8_interface
-import v8_types
-import v8_utilities
-
-
-INCLUDES = frozenset([
- 'bindings/core/v8/GeneratedCodeHelper.h',
- 'bindings/core/v8/V8HTMLDocument.h',
- 'bindings/core/v8/V8Initializer.h',
- 'bindings/core/v8/V8Window.h',
- 'platform/bindings/DOMWrapperWorld.h',
- 'platform/bindings/V8ObjectConstructor.h',
- 'platform/bindings/V8PerIsolateData.h',
- 'platform/bindings/V8PrivateProperty.h',
- 'v8/include/v8.h'])
-
-TEMPLATE_FILE = 'external_reference_table.cpp.tmpl'
-
-WHITE_LIST_INTERFACES = frozenset([
- 'DOMMatrix', # crbug.com/733481
-])
-
-SNAPSHOTTED_INTERFACES = frozenset([
- 'Window',
- 'EventTarget',
- 'HTMLDocument',
- 'Document',
- 'Node',
-])
-
-
-def parse_args():
- parser = argparse.ArgumentParser()
- parser.add_argument('--idl-files-list', type=str, required=True,
- help='file listing IDL files')
- parser.add_argument('--output', type=str, required=True,
- help='output file path')
- parser.add_argument('--info-dir', type=str, required=True,
- help='directory contains component info')
- parser.add_argument('--cache-dir', type=str, required=True,
- help='cache directory')
- parser.add_argument('--target-component', type=str, required=True,
- help='target component')
- return parser.parse_known_args()
-
-
-# This class creates a Jinja template context about an interface.
-class InterfaceTemplateContextBuilder(object):
-
- def __init__(self, opts, info_provider):
- self._opts = opts
- self._info_provider = info_provider
-
- def create_interface_context(self, interface, interfaces):
- '''Creates a Jinja context which is based on an interface.'''
-
- name = '%s%s' % (v8_utilities.cpp_name(interface), 'Partial' if interface.is_partial else '')
-
- # Constructors
- constructors = any(constructor.name == 'Constructor' for constructor in interface.constructors)
- custom_constructors = interface.custom_constructors
- html_constructor = 'HTMLConstructor' in interface.extended_attributes
- has_constructor_callback = constructors or custom_constructors or html_constructor
-
- attributes = []
- methods = []
- has_cross_origin_indexed_getter = False
- has_cross_origin_named_enum = False
- has_cross_origin_named_getter = False
- has_cross_origin_named_setter = False
- has_origin_safe_method_setter = False
- has_security_check = False
- indexed_property_getter = None
- is_global = False
- named_property_getter = None
- if interface.name in SNAPSHOTTED_INTERFACES:
- attributes = [v8_attributes.attribute_context(interface, attribute, interfaces)
- for attribute in interface.attributes]
- methods = v8_interface.methods_context(interface)['methods']
- is_global = ('PrimaryGlobal' in interface.extended_attributes or
- 'Global' in interface.extended_attributes)
-
- named_property_getter = v8_interface.property_getter(
- interface.named_property_getter, ['name'])
- indexed_property_getter = v8_interface.property_getter(
- interface.indexed_property_getter, ['index'])
-
- if not interface.is_partial:
- has_origin_safe_method_setter = is_global and any(
- method['is_check_security_for_receiver'] and not method['is_unforgeable']
- for method in methods)
- has_security_check = ('CheckSecurity' in interface.extended_attributes and
- interface.name != 'EventTarget')
- has_cross_origin_named_getter = (any(method['is_cross_origin'] for method in methods) or
- any(attribute['has_cross_origin_getter'] for attribute in attributes))
- has_cross_origin_named_setter = any(attribute['has_cross_origin_setter'] for attribute in attributes)
- has_cross_origin_indexed_getter = indexed_property_getter and indexed_property_getter['is_cross_origin']
- has_cross_origin_named_enum = has_cross_origin_named_getter or has_cross_origin_named_setter
- if named_property_getter and named_property_getter['is_cross_origin']:
- has_cross_origin_named_getter = True
-
- return {
- 'attributes': attributes,
- 'has_origin_safe_method_setter': has_origin_safe_method_setter,
- 'has_constructor_callback': has_constructor_callback,
- 'has_cross_origin_named_getter': has_cross_origin_named_getter,
- 'has_cross_origin_named_setter': has_cross_origin_named_setter,
- 'has_cross_origin_named_enumerator': has_cross_origin_named_enum,
- 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter,
- 'has_security_check': has_security_check,
- 'indexed_property_getter': indexed_property_getter,
- 'indexed_property_setter': v8_interface.property_setter(interface.indexed_property_setter, interface),
- 'indexed_property_deleter': v8_interface.property_deleter(interface.indexed_property_deleter),
- 'is_array_buffer_or_view': interface.idl_type.is_array_buffer_or_view,
- 'is_callback': interface.is_callback,
- 'is_partial': interface.is_partial,
- 'is_snapshotted': interface in SNAPSHOTTED_INTERFACES,
- 'methods': methods,
- 'name': name,
- 'named_constructor': v8_interface.named_constructor_context(interface),
- 'named_property_getter': named_property_getter,
- 'named_property_setter': v8_interface.property_setter(interface.named_property_setter, interface),
- 'named_property_deleter': v8_interface.property_deleter(interface.named_property_deleter),
- 'v8_name': v8_utilities.v8_class_name_or_partial(interface),
- }
-
-
-# This class applies a Jinja template and creates a .cpp file for the external reference table.
-class ExternalReferenceTableGenerator(object):
- def __init__(self, opts, info_provider):
- self._opts = opts
- self._info_provider = info_provider
- self._reader = IdlReader(
- info_provider.interfaces_info, opts.cache_dir)
- self._interface_contexts = {}
- self._include_files = set(INCLUDES)
- v8_types.set_component_dirs(info_provider.interfaces_info['component_dirs'])
-
- # Creates a Jinja context from an IDL file.
- def process_idl_file(self, idl_filename):
- definitions = self._reader.read_idl_definitions(idl_filename)
- base_name, _ = os.path.splitext(os.path.basename(idl_filename))
- for component in definitions:
- target_definitions = definitions[component]
- interfaces = target_definitions.interfaces
- if base_name in interfaces.keys():
- interface = interfaces[base_name]
- self._process_interface(interface, component, interfaces)
-
- # Creates a Jinja context from an interface. Some interfaces are not used
- # in V8 context snapshot, so we can skip them.
- def _process_interface(self, interface, component, interfaces):
- def has_impl(interface):
- if interface.name in WHITE_LIST_INTERFACES:
- return True
- # Non legacy callback interface does not provide V8 callbacks.
- if interface.is_callback:
- return len(interface.constants) > 0
- if 'RuntimeEnabled' in interface.extended_attributes:
- return False
- return True
-
- if not has_impl(interface):
- return
-
- context_builder = InterfaceTemplateContextBuilder(self._opts, self._info_provider)
- context = context_builder.create_interface_context(interface, interfaces)
- name = '%s%s' % (interface.name, 'Partial' if interface.is_partial else '')
- self._interface_contexts[name] = context
- include_file = 'bindings/%s/v8/%s.h' % (component, context['v8_name'])
- self._include_files.add(include_file)
-
- # Gathers all interface-dependent information and returns as a Jinja template context.
- def _create_template_context(self):
- interfaces = []
- for name in sorted(self._interface_contexts):
- interfaces.append(self._interface_contexts[name])
- return {
- 'class': 'V8ContextSnapshotExternalReferences',
- 'interfaces': interfaces,
- 'include_files': sorted(list(self._include_files)),
- }
-
- # Applies a Jinja template on a context and generates a C++ code.
- def generate(self):
- jinja_env = initialize_jinja_env(self._opts.cache_dir)
- context = self._create_template_context()
- cpp_template = jinja_env.get_template(TEMPLATE_FILE)
- cpp_text = cpp_template.render(context)
- return cpp_text
-
-
-def main():
- opts, _ = parse_args()
- # TODO(peria): get rid of |info_provider|
- info_provider = create_component_info_provider(
- opts.info_dir, opts.target_component)
- generator = ExternalReferenceTableGenerator(opts, info_provider)
-
- idl_files = utilities.read_idl_files_list_from_file(opts.idl_files_list, False)
- for idl_file in idl_files:
- generator.process_idl_file(idl_file)
- output_code = generator.generate()
- output_path = opts.output
- write_file(output_code, output_path)
-
-
-if __name__ == '__main__':
- main()
diff --git a/WebKit/Source/bindings/templates/external_reference_table.cpp.tmpl b/WebKit/Source/bindings/templates/external_reference_table.cpp.tmpl
deleted file mode 100644
index c747660..0000000
--- a/WebKit/Source/bindings/templates/external_reference_table.cpp.tmpl
+++ /dev/null
@@ -1,130 +0,0 @@
-{% filter format_blink_cpp_source_code %}
-
-{% include 'copyright_block.txt' %}
-
-#include "bindings/modules/v8/{{class}}.h"
-
-#include <cstdint>
-
-{% for include_file in include_files %}
-#include "{{include_file}}"
-{% endfor %}
-
-namespace blink {
-
-intptr_t* {{class}}::GetTable() {
- static intptr_t reference_table[] = {
-#if !defined(OS_ANDROID)
- // Android is sensitive on its APK size, and this table improves it.
- // So we drop the table entries until the V8 context snapshot feature
- // is released on Android.
- {% for interface in interfaces %}
- {% if not interface.is_array_buffer_or_view %}
- {% set v8_class = interface.v8_name %}
-
- {# Attributes #}
- {%- for attribute in interface.attributes %}
- {%- for world_suffix in attribute.world_suffixes %}
- {% if not attribute.constructor_type %}
- reinterpret_cast<intptr_t>({{v8_class}}::{{attribute.name}}AttributeGetterCallback{{world_suffix}}),
- {% elif attribute.needs_constructor_getter_callback %}
- reinterpret_cast<intptr_t>({{v8_class}}::{{attribute.name}}ConstructorGetterCallback{{world_suffix}}),
- {% elif attribute.is_named_constructor %}
- reinterpret_cast<intptr_t>(V8{{attribute.constructor_type}}::NamedConstructorAttributeGetter{{world_suffix}}),
- {% endif %}
- {% if attribute.has_setter %}
- reinterpret_cast<intptr_t>({{v8_class}}::{{attribute.name}}AttributeSetterCallback{{world_suffix}}),
- {% endif %}
- {%- endfor %}{# world_suffix #}
- {%- endfor %}{# attributes #}
-
- {# Methods / Operations #}
- {% for method in interface.methods %}
- {%- for world_suffix in method.world_suffixes %}
- {% if not method.overload_index or method.overloads %}
- {% if (method.overloads and method.overloads.visible and
- (not method.overloads.has_partial_overloads or not interface.is_partial)) or
- (not method.overloads and method.visible) %}
- {# TODO(bashi): Remove this 'if' condition when crbug.com/630986 is fixed. #}
- {% if not interface.is_callback %}
- reinterpret_cast<intptr_t>({{v8_class}}::{{method.name}}MethodCallback{{world_suffix}}),
- {% endif %}
- {% endif %}
- {% endif %}{# overload(_index) #}
- {% if method.is_cross_origin and method.visible %}
- reinterpret_cast<intptr_t>({{v8_class}}::{{method.name}}OriginSafeMethodGetterCallback{{world_suffix}}),
- {% endif%}
- {% endfor %}
- {% endfor %}{# method #}
- {% if interface.has_origin_safe_method_setter %}
- reinterpret_cast<intptr_t>({{v8_class}}::{{interface.name}}OriginSafeMethodSetterCallback),
- {% endif %}
- {% if interface.has_cross_origin_named_getter %}
- reinterpret_cast<intptr_t>({{v8_class}}::crossOriginNamedGetter),
- {% endif %}
- {% if interface.has_cross_origin_named_setter %}
- reinterpret_cast<intptr_t>({{v8_class}}::crossOriginNamedSetter),
- {% endif %}
- {% if interface.has_cross_origin_named_enumerator %}
- reinterpret_cast<intptr_t>({{v8_class}}::crossOriginNamedEnumerator),
- {% endif %}
- {% if interface.has_cross_origin_indexed_getter %}
- reinterpret_cast<intptr_t>({{v8_class}}::crossOriginIndexedGetter),
- {% endif %}
- {% if interface.has_security_check %}
- reinterpret_cast<intptr_t>({{v8_class}}::securityCheck),
- {% endif %}
-
- {# Other properties #}
- {% if interface.has_constructor_callback %}
- reinterpret_cast<intptr_t>({{v8_class}}::constructorCallback),
- {% endif %}
- {% if interface.named_property_getter %}
- reinterpret_cast<intptr_t>({{v8_class}}::namedPropertyGetterCallback),
- {% endif %}
- {%- if interface.named_property_setter %}
- reinterpret_cast<intptr_t>({{v8_class}}::namedPropertySetterCallback),
- {% endif %}
- {%- if interface.named_property_deleter %}
- reinterpret_cast<intptr_t>({{v8_class}}::namedPropertyDeleterCallback),
- {% endif %}
- {%- if interface.named_property_getter and interface.named_property_getter.is_enumerable %}
- reinterpret_cast<intptr_t>({{v8_class}}::namedPropertyQueryCallback),
- reinterpret_cast<intptr_t>({{v8_class}}::namedPropertyEnumeratorCallback),
- {% endif %}
- {%- if interface.indexed_property_getter %}
- reinterpret_cast<intptr_t>({{v8_class}}::indexedPropertyGetterCallback),
- reinterpret_cast<intptr_t>({{v8_class}}::indexedPropertyDefinerCallback),
- reinterpret_cast<intptr_t>({{v8_class}}::indexedPropertyDescriptorCallback),
- {% endif %}
- {%- if interface.indexed_property_getter or interface.named_property_setter %}
- reinterpret_cast<intptr_t>({{v8_class}}::indexedPropertySetterCallback),
- {% endif %}
- {%- if interface.indexed_property_deleter %}
- reinterpret_cast<intptr_t>({{v8_class}}::indexedPropertyDeleterCallback),
- {% endif %}
- {% if interface.has_security_check_function %}
- reinterpret_cast<intptr_t>({{v8_class}}::securityCheck),
- {%- endif %}
- {% endif %}{# not is_array_buffer_or_view #}
-
- {% if not interface.is_partial or is_snapshotted %}
- reinterpret_cast<intptr_t>(&{{interface.v8_name}}::wrapperTypeInfo),
- {% endif %}
- {% if interface.named_constructor %}
- reinterpret_cast<intptr_t>(&{{interface.v8_name}}Constructor::wrapperTypeInfo),
- {% endif %}
- {% endfor %}{# interfaces #}
-
- reinterpret_cast<intptr_t>(V8ObjectConstructor::IsValidConstructorMode),
- reinterpret_cast<intptr_t>(V8ConstructorAttributeGetter),
-#endif // OS_ANDROID
- 0 // terminate with a null
- };
-
- return reference_table;
-}
-
-} // namespace blink
-
-{% endfilter %}{# format_blink_cpp_source_code #}
diff --git a/WebKit/Source/bindings/templates/templates.gni b/WebKit/Source/bindings/templates/templates.gni
index ded9ffd..d505e2e 100644
--- a/WebKit/Source/bindings/templates/templates.gni
+++ b/WebKit/Source/bindings/templates/templates.gni
@@ -11,15 +11,15 @@
"callback_interface.cpp.tmpl",
"callback_interface.h.tmpl",
"constants.cpp.tmpl",
+ "utilities.cpp.tmpl",
"copyright_block.txt",
"dictionary_impl.cpp.tmpl",
"dictionary_impl.h.tmpl",
"dictionary_v8.cpp.tmpl",
"dictionary_v8.h.tmpl",
- "external_reference_table.cpp.tmpl",
+ "interface_base.cpp.tmpl",
"interface.cpp.tmpl",
"interface.h.tmpl",
- "interface_base.cpp.tmpl",
"legacy_callback_interface.cpp.tmpl",
"legacy_callback_interface.h.tmpl",
"methods.cpp.tmpl",
@@ -27,7 +27,6 @@
"partial_interface.h.tmpl",
"union_container.cpp.tmpl",
"union_container.h.tmpl",
- "utilities.cpp.tmpl",
"web_agent_api_interface.cc.tmpl",
"web_agent_api_interface.h.tmpl",
],
diff --git a/WebKit/Source/controller/BlinkInitializer.cpp b/WebKit/Source/controller/BlinkInitializer.cpp
index 557b1c4..9377b5c 100644
--- a/WebKit/Source/controller/BlinkInitializer.cpp
+++ b/WebKit/Source/controller/BlinkInitializer.cpp
@@ -29,7 +29,6 @@
*/
#include "bindings/core/v8/V8Initializer.h"
-#include "bindings/modules/v8/V8ContextSnapshotExternalReferences.h"
#include "core/animation/AnimationClock.h"
#include "modules/ModulesInitializer.h"
#include "platform/bindings/Microtask.h"
@@ -69,8 +68,8 @@
void Initialize(Platform* platform) {
Platform::Initialize(platform);
- V8Initializer::InitializeMainThread(
- V8ContextSnapshotExternalReferences::GetTable());
+ V8Initializer::InitializeMainThread();
+
GetModulesInitializer().Initialize();
// currentThread is null if we are running on a thread without a message loop.
diff --git a/WebKit/Source/core/exported/BUILD.gn b/WebKit/Source/core/exported/BUILD.gn
index a6023ce..fdd95e3 100644
--- a/WebKit/Source/core/exported/BUILD.gn
+++ b/WebKit/Source/core/exported/BUILD.gn
@@ -89,7 +89,6 @@
"WebTextCheckingResult.cpp",
"WebUserGestureIndicator.cpp",
"WebUserGestureToken.cpp",
- "WebV8ContextSnapshot.cpp",
"WebViewImpl.cpp",
"WebViewImpl.h",
"WorkerShadowPage.cpp",
diff --git a/WebKit/Source/core/exported/WebV8ContextSnapshot.cpp b/WebKit/Source/core/exported/WebV8ContextSnapshot.cpp
deleted file mode 100644
index 340f78c..0000000
--- a/WebKit/Source/core/exported/WebV8ContextSnapshot.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "public/web/WebV8ContextSnapshot.h"
-
-#include "bindings/core/v8/V8ContextSnapshot.h"
-#include "v8/include/v8.h"
-
-namespace blink {
-
-v8::StartupData WebV8ContextSnapshot::TakeSnapshot() {
- return V8ContextSnapshot::TakeSnapshot();
-}
-
-} // namespace blink
diff --git a/WebKit/Source/core/workers/WorkerBackingThread.cpp b/WebKit/Source/core/workers/WorkerBackingThread.cpp
index e48a33869..a070ff8 100644
--- a/WebKit/Source/core/workers/WorkerBackingThread.cpp
+++ b/WebKit/Source/core/workers/WorkerBackingThread.cpp
@@ -6,7 +6,6 @@
#include <memory>
#include "bindings/core/v8/V8BindingForCore.h"
-#include "bindings/core/v8/V8ContextSnapshot.h"
#include "bindings/core/v8/V8GCController.h"
#include "bindings/core/v8/V8IdleTaskRunner.h"
#include "bindings/core/v8/V8Initializer.h"
@@ -76,12 +75,8 @@
backing_thread_->InitializeOnThread();
DCHECK(!isolate_);
- // TODO(peria): Replace GetReferenceTable with nullptr.
- // (http://crbug.com/v8/6448)
isolate_ = V8PerIsolateData::Initialize(
- backing_thread_->PlatformThread().GetWebTaskRunner(),
- V8ContextSnapshot::GetReferenceTable(),
- V8PerIsolateData::V8ContextSnapshotMode::kDontUseSnapshot);
+ backing_thread_->PlatformThread().GetWebTaskRunner());
AddWorkerIsolate(isolate_);
V8Initializer::InitializeWorker(isolate_);
diff --git a/WebKit/Source/modules/BUILD.gn b/WebKit/Source/modules/BUILD.gn
index dbc03db..a00f1dd 100644
--- a/WebKit/Source/modules/BUILD.gn
+++ b/WebKit/Source/modules/BUILD.gn
@@ -66,10 +66,6 @@
sources += get_target_outputs(":module_names")
sources += bindings_modules_v8_files
- sources += rebase_path(
- [ bindings_generated_v8_context_snapshot_external_references_file ],
- ".",
- "//")
configs += [
":modules_implementation",
diff --git a/WebKit/Source/platform/RuntimeEnabledFeatures.json5 b/WebKit/Source/platform/RuntimeEnabledFeatures.json5
index 91ae785..4fcb7b83 100644
--- a/WebKit/Source/platform/RuntimeEnabledFeatures.json5
+++ b/WebKit/Source/platform/RuntimeEnabledFeatures.json5
@@ -1051,10 +1051,6 @@
status: "stable",
},
{
- name: "V8ContextSnapshot",
- status: "test",
- },
- {
name: "V8IdleTasks",
},
{
diff --git a/WebKit/Source/platform/bindings/DOMWrapperWorld.cpp b/WebKit/Source/platform/bindings/DOMWrapperWorld.cpp
index 98f4f4b..ef4500a 100644
--- a/WebKit/Source/platform/bindings/DOMWrapperWorld.cpp
+++ b/WebKit/Source/platform/bindings/DOMWrapperWorld.cpp
@@ -87,7 +87,6 @@
case WorldType::kGarbageCollector:
case WorldType::kRegExp:
case WorldType::kTesting:
- case WorldType::kForV8ContextSnapshotNonMain:
case WorldType::kWorker: {
WorldMap& map = GetWorldMap();
DCHECK(!map.Contains(world_id_));
@@ -289,7 +288,6 @@
case WorldType::kGarbageCollector:
case WorldType::kRegExp:
case WorldType::kTesting:
- case WorldType::kForV8ContextSnapshotNonMain:
case WorldType::kWorker:
int world_id = *next_world_id;
CHECK_GE(world_id, WorldId::kUnspecifiedWorldIdStart);
diff --git a/WebKit/Source/platform/bindings/DOMWrapperWorld.h b/WebKit/Source/platform/bindings/DOMWrapperWorld.h
index c620e75..77646d1 100644
--- a/WebKit/Source/platform/bindings/DOMWrapperWorld.h
+++ b/WebKit/Source/platform/bindings/DOMWrapperWorld.h
@@ -72,7 +72,6 @@
kGarbageCollector,
kRegExp,
kTesting,
- kForV8ContextSnapshotNonMain,
kWorker,
};
diff --git a/WebKit/Source/platform/bindings/ScriptWrappable.h b/WebKit/Source/platform/bindings/ScriptWrappable.h
index 5ba3117..11f38d5 100644
--- a/WebKit/Source/platform/bindings/ScriptWrappable.h
+++ b/WebKit/Source/platform/bindings/ScriptWrappable.h
@@ -155,7 +155,7 @@
void MarkWrapper(const ScriptWrappableVisitor*) const;
private:
- // These classes are exceptionally allowed to use MainWorldWrapper().
+ // These classes are exceptionally allowed to use mainWorldWrapper().
friend class DOMDataStore;
friend class HeapSnaphotWrapperVisitor;
friend class V8HiddenValue;
diff --git a/WebKit/Source/platform/bindings/V8PerContextData.cpp b/WebKit/Source/platform/bindings/V8PerContextData.cpp
index ed5cbd7..010be97 100644
--- a/WebKit/Source/platform/bindings/V8PerContextData.cpp
+++ b/WebKit/Source/platform/bindings/V8PerContextData.cpp
@@ -136,7 +136,9 @@
// Origin Trials
InstallConditionalFeatures(type, ScriptState::From(current_context),
prototype_object, interface_object);
+
constructor_map_.Set(type, interface_object);
+
return interface_object;
}
diff --git a/WebKit/Source/platform/bindings/V8PerIsolateData.cpp b/WebKit/Source/platform/bindings/V8PerIsolateData.cpp
index 820a40a..8542896 100644
--- a/WebKit/Source/platform/bindings/V8PerIsolateData.cpp
+++ b/WebKit/Source/platform/bindings/V8PerIsolateData.cpp
@@ -27,7 +27,6 @@
#include <memory>
-#include "platform/RuntimeEnabledFeatures.h"
#include "platform/ScriptForbiddenScope.h"
#include "platform/WebTaskRunner.h"
#include "platform/bindings/DOMDataStore.h"
@@ -59,34 +58,18 @@
V8PerIsolateData::From(isolate)->RunEndOfScopeTasks();
}
-V8PerIsolateData::V8PerIsolateData(
- WebTaskRunner* task_runner,
- intptr_t* table,
- V8ContextSnapshotMode v8_context_snapshot_mode)
- : v8_context_snapshot_mode_(v8_context_snapshot_mode),
- isolate_holder_(
+V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner)
+ : isolate_holder_(
task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr,
gin::IsolateHolder::kSingleThread,
IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait
- : gin::IsolateHolder::kAllowAtomicsWait,
- table,
- v8_context_snapshot_mode_ == V8ContextSnapshotMode::kUseSnapshot
- ? &startup_data_
- : nullptr),
- interface_template_map_for_v8_context_snapshot_(GetIsolate()),
+ : gin::IsolateHolder::kAllowAtomicsWait),
string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))),
private_property_(V8PrivateProperty::Create()),
constructor_mode_(ConstructorMode::kCreateNewObject),
use_counter_disabled_(false),
is_handling_recursion_level_error_(false),
is_reporting_exception_(false) {
- // If it fails to load the snapshot file, falls back to kDontUseSnapshot mode.
- // TODO(peria): Remove this fallback routine.
- if (v8_context_snapshot_mode_ == V8ContextSnapshotMode::kUseSnapshot &&
- !startup_data_.data) {
- v8_context_snapshot_mode_ = V8ContextSnapshotMode::kDontUseSnapshot;
- }
-
// FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone.
GetIsolate()->Enter();
GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback);
@@ -95,24 +78,6 @@
g_main_thread_per_isolate_data = this;
}
-// This constructor is used for taking a V8 context snapshot. It must run on the
-// main thread.
-V8PerIsolateData::V8PerIsolateData(intptr_t* reference_table)
- : v8_context_snapshot_mode_(V8ContextSnapshotMode::kTakeSnapshot),
- isolate_holder_(reference_table, nullptr),
- interface_template_map_for_v8_context_snapshot_(GetIsolate()),
- string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))),
- private_property_(V8PrivateProperty::Create()),
- constructor_mode_(ConstructorMode::kCreateNewObject),
- use_counter_disabled_(false),
- is_handling_recursion_level_error_(false),
- is_reporting_exception_(false) {
- CHECK(IsMainThread());
-
- // SnapshotCreator enters the isolate, so we don't call Isolate::Enter() here.
- g_main_thread_per_isolate_data = this;
-}
-
V8PerIsolateData::~V8PerIsolateData() {}
v8::Isolate* V8PerIsolateData::MainThreadIsolate() {
@@ -120,21 +85,8 @@
return g_main_thread_per_isolate_data->GetIsolate();
}
-v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner,
- intptr_t* reference_table,
- V8ContextSnapshotMode context_mode) {
- DCHECK(context_mode == V8ContextSnapshotMode::kDontUseSnapshot ||
- reference_table);
-
- V8PerIsolateData* data = nullptr;
- if (context_mode == V8ContextSnapshotMode::kTakeSnapshot) {
- CHECK(reference_table);
- data = new V8PerIsolateData(reference_table);
- } else {
- data = new V8PerIsolateData(task_runner, reference_table, context_mode);
- }
- DCHECK(data);
-
+v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner) {
+ V8PerIsolateData* data = new V8PerIsolateData(task_runner);
v8::Isolate* isolate = data->GetIsolate();
isolate->SetData(gin::kEmbedderBlink, data);
return isolate;
@@ -218,11 +170,6 @@
v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindInterfaceTemplate(
const DOMWrapperWorld& world,
const void* key) {
- if (GetV8ContextSnapshotMode() == V8ContextSnapshotMode::kTakeSnapshot) {
- const WrapperTypeInfo* type = reinterpret_cast<const WrapperTypeInfo*>(key);
- return interface_template_map_for_v8_context_snapshot_.Get(type);
- }
-
auto& map = SelectInterfaceTemplateMap(world);
auto result = map.find(key);
if (result != map.end())
@@ -234,19 +181,8 @@
const DOMWrapperWorld& world,
const void* key,
v8::Local<v8::FunctionTemplate> value) {
- if (GetV8ContextSnapshotMode() == V8ContextSnapshotMode::kTakeSnapshot) {
- auto& map = interface_template_map_for_v8_context_snapshot_;
- const WrapperTypeInfo* type = reinterpret_cast<const WrapperTypeInfo*>(key);
- map.Set(type, value);
- } else {
- auto& map = SelectInterfaceTemplateMap(world);
- map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value));
- }
-}
-
-void V8PerIsolateData::ClearPersistentsForV8ContextSnapshot() {
- interface_template_map_for_v8_context_snapshot_.Clear();
- private_property_.reset();
+ auto& map = SelectInterfaceTemplateMap(world);
+ map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value));
}
const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache(
diff --git a/WebKit/Source/platform/bindings/V8PerIsolateData.h b/WebKit/Source/platform/bindings/V8PerIsolateData.h
index 2e52788..8af0f25 100644
--- a/WebKit/Source/platform/bindings/V8PerIsolateData.h
+++ b/WebKit/Source/platform/bindings/V8PerIsolateData.h
@@ -60,12 +60,6 @@
WTF_MAKE_NONCOPYABLE(V8PerIsolateData);
public:
- enum class V8ContextSnapshotMode {
- kTakeSnapshot,
- kDontUseSnapshot,
- kUseSnapshot,
- };
-
class EndOfScopeTask {
USING_FAST_MALLOC(EndOfScopeTask);
@@ -107,9 +101,7 @@
virtual ~Data() = default;
};
- static v8::Isolate* Initialize(WebTaskRunner*,
- intptr_t* refernce_table,
- V8ContextSnapshotMode);
+ static v8::Isolate* Initialize(WebTaskRunner*);
static V8PerIsolateData* From(v8::Isolate* isolate) {
DCHECK(isolate);
@@ -152,17 +144,6 @@
const void* key,
v8::Local<v8::FunctionTemplate>);
- // When v8::SnapshotCreator::CreateBlob() is called, we must not have
- // persistent handles in Blink. This method clears them.
- void ClearPersistentsForV8ContextSnapshot();
-
- v8::SnapshotCreator* GetSnapshotCreator() const {
- return isolate_holder_.snapshot_creator();
- }
- V8ContextSnapshotMode GetV8ContextSnapshotMode() const {
- return v8_context_snapshot_mode_;
- }
-
// Accessor to the cache of cross-origin accessible operation's templates.
// Created templates get automatically cached.
v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate(
@@ -243,14 +224,11 @@
}
private:
- V8PerIsolateData(WebTaskRunner*,
- intptr_t* reference_table,
- V8ContextSnapshotMode);
- explicit V8PerIsolateData(intptr_t* reference_table);
+ explicit V8PerIsolateData(WebTaskRunner*);
~V8PerIsolateData();
- using V8FunctionTemplateMap =
- HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>;
+ typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>
+ V8FunctionTemplateMap;
V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&);
V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&);
bool HasInstance(const WrapperTypeInfo* untrusted,
@@ -260,16 +238,12 @@
v8::Local<v8::Value>,
V8FunctionTemplateMap&);
- V8ContextSnapshotMode v8_context_snapshot_mode_;
- // This isolate_holder_ must be initialized before initializing some other
- // members below.
gin::IsolateHolder isolate_holder_;
- // interface_template_map_for_{,non_}main_world holds function templates for
+ // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for
// the inerface objects.
V8FunctionTemplateMap interface_template_map_for_main_world_;
V8FunctionTemplateMap interface_template_map_for_non_main_world_;
-
// m_operationTemplateMapFor{,Non}MainWorld holds function templates for
// the cross-origin accessible DOM operations.
V8FunctionTemplateMap operation_template_map_for_main_world_;
@@ -278,16 +252,6 @@
// Contains lists of eternal names, such as dictionary keys.
HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_;
- // Members required for the V8 context snapshot.
- // v8::Context is created from this blob data image. This needs to be
- // instantiated before |isolate_holder_| gets instantiated.
- v8::StartupData startup_data_;
- // When taking a V8 context snapshot, we can't keep V8 objects with eternal
- // handles. So we use a special interface map that doesn't use eternal handles
- // instead of the default V8FunctionTemplateMap.
- V8GlobalValueMap<const WrapperTypeInfo*, v8::FunctionTemplate, v8::kNotWeak>
- interface_template_map_for_v8_context_snapshot_;
-
std::unique_ptr<StringCache> string_cache_;
std::unique_ptr<V8PrivateProperty> private_property_;
RefPtr<ScriptState> script_regexp_script_state_;
diff --git a/WebKit/public/BUILD.gn b/WebKit/public/BUILD.gn
index d6698c0..d675526 100644
--- a/WebKit/public/BUILD.gn
+++ b/WebKit/public/BUILD.gn
@@ -615,7 +615,6 @@
"web/WebUserGestureToken.h",
"web/WebUserMediaClient.h",
"web/WebUserMediaRequest.h",
- "web/WebV8ContextSnapshot.h",
"web/WebView.h",
"web/WebViewClient.h",
"web/WebWidget.h",
diff --git a/WebKit/public/platform/Platform.h b/WebKit/public/platform/Platform.h
index e16a24a..97204f8 100644
--- a/WebKit/public/platform/Platform.h
+++ b/WebKit/public/platform/Platform.h
@@ -707,13 +707,6 @@
// depending on memory pressure.
virtual void RequestPurgeMemory() {}
- // V8 Context Snapshot --------------------------------------------------
-
- // This method returns true only when
- // tools/v8_context_snapshot/v8_context_snapshot_generator is running (which
- // runs during Chromium's build step).
- virtual bool IsTakingV8ContextSnapshot() { return false; }
-
// Feature Policy -----------------------------------------------------
// Create a new feature policy object for a document, given its parent
diff --git a/WebKit/public/web/WebV8ContextSnapshot.h b/WebKit/public/web/WebV8ContextSnapshot.h
deleted file mode 100644
index 336bedb..0000000
--- a/WebKit/public/web/WebV8ContextSnapshot.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef WebV8ContextSnapshot_h
-#define WebV8ContextSnapshot_h
-
-#include "public/platform/WebCommon.h"
-#include "v8/include/v8.h"
-
-namespace blink {
-
-// WebV8ContextSnapshot is an API to take a snapshot of V8 context.
-// This API should be used only by tools/v8_context_snapshot, which runs during
-// Chromium's build step.
-class BLINK_EXPORT WebV8ContextSnapshot {
- public:
- static v8::StartupData TakeSnapshot();
-};
-
-} // namespace blink
-
-#endif // WebV8ContextSnapshot_h