Commit 7f69e026 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Implement V8 context initialization for the new bind gentor

Implements the V8 context initialization with using the new binding
generator of IDL interfaces.

Bug: 839389
Change-Id: Ic8972b7f654ea80a328db3c4be40b2b7780bafc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2282838
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786189}
parent 0d35ca3c
...@@ -227,6 +227,7 @@ void LocalWindowProxy::CreateContext() { ...@@ -227,6 +227,7 @@ void LocalWindowProxy::CreateContext() {
v8::Local<v8::Object> global_proxy = global_proxy_.NewLocal(isolate); v8::Local<v8::Object> global_proxy = global_proxy_.NewLocal(isolate);
context = V8ContextSnapshot::CreateContextFromSnapshot( context = V8ContextSnapshot::CreateContextFromSnapshot(
isolate, World(), &extension_configuration, global_proxy, document); isolate, World(), &extension_configuration, global_proxy, document);
context_was_created_from_snapshot_ = !context.IsEmpty();
// Even if we enable V8 context snapshot feature, we may hit this branch // Even if we enable V8 context snapshot feature, we may hit this branch
// in some cases, e.g. loading XML files. // in some cases, e.g. loading XML files.
...@@ -257,6 +258,15 @@ void LocalWindowProxy::InstallConditionalFeatures() { ...@@ -257,6 +258,15 @@ void LocalWindowProxy::InstallConditionalFeatures() {
TRACE_EVENT1("v8", "InstallConditionalFeatures", "IsMainFrame", TRACE_EVENT1("v8", "InstallConditionalFeatures", "IsMainFrame",
GetFrame()->IsMainFrame()); GetFrame()->IsMainFrame());
#if defined(USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE)
if (context_was_created_from_snapshot_) {
V8ContextSnapshot::InstallContextIndependentProps(script_state_);
}
V8PerContextData* per_context_data = script_state_->PerContextData();
ignore_result(
per_context_data->ConstructorForType(V8Window::GetWrapperTypeInfo()));
#else // USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE
v8::Local<v8::Context> context = script_state_->GetContext(); v8::Local<v8::Context> context = script_state_->GetContext();
// If the context was created from snapshot, all conditionally // If the context was created from snapshot, all conditionally
...@@ -287,6 +297,7 @@ void LocalWindowProxy::InstallConditionalFeatures() { ...@@ -287,6 +297,7 @@ void LocalWindowProxy::InstallConditionalFeatures() {
v8::Local<v8::Object>(), v8::Local<v8::Object>(),
v8::Local<v8::Function>()); v8::Local<v8::Function>());
} }
#endif // USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE
} }
void LocalWindowProxy::SetupWindowPrototypeChain() { void LocalWindowProxy::SetupWindowPrototypeChain() {
...@@ -318,8 +329,10 @@ void LocalWindowProxy::SetupWindowPrototypeChain() { ...@@ -318,8 +329,10 @@ void LocalWindowProxy::SetupWindowPrototypeChain() {
v8::Local<v8::Object> window_prototype = v8::Local<v8::Object> window_prototype =
window_wrapper->GetPrototype().As<v8::Object>(); window_wrapper->GetPrototype().As<v8::Object>();
CHECK(!window_prototype.IsEmpty()); CHECK(!window_prototype.IsEmpty());
#if !defined(USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE)
V8DOMWrapper::SetNativeInfo(GetIsolate(), window_prototype, wrapper_type_info, V8DOMWrapper::SetNativeInfo(GetIsolate(), window_prototype, wrapper_type_info,
window); window);
#endif
// The named properties object of Window interface. // The named properties object of Window interface.
v8::Local<v8::Object> window_properties = v8::Local<v8::Object> window_properties =
...@@ -328,6 +341,13 @@ void LocalWindowProxy::SetupWindowPrototypeChain() { ...@@ -328,6 +341,13 @@ void LocalWindowProxy::SetupWindowPrototypeChain() {
V8DOMWrapper::SetNativeInfo(GetIsolate(), window_properties, V8DOMWrapper::SetNativeInfo(GetIsolate(), window_properties,
wrapper_type_info, window); wrapper_type_info, window);
#if defined(USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE)
// [CachedAccessor=kWindowProxy]
V8PrivateProperty::GetCachedAccessor(
GetIsolate(), V8PrivateProperty::CachedAccessor::kWindowProxy)
.Set(window_wrapper, global_proxy);
#endif
// TODO(keishi): Remove installPagePopupController and implement // TODO(keishi): Remove installPagePopupController and implement
// PagePopupController in another way. // PagePopupController in another way.
V8PagePopupControllerBinding::InstallPagePopupController(context, V8PagePopupControllerBinding::InstallPagePopupController(context,
......
...@@ -106,6 +106,7 @@ class LocalWindowProxy final : public WindowProxy { ...@@ -106,6 +106,7 @@ class LocalWindowProxy final : public WindowProxy {
} }
Member<ScriptState> script_state_; Member<ScriptState> script_state_;
bool context_was_created_from_snapshot_ = false;
}; };
template <> template <>
......
...@@ -299,6 +299,11 @@ void WorkerOrWorkletScriptController::PrepareForEvaluation() { ...@@ -299,6 +299,11 @@ void WorkerOrWorkletScriptController::PrepareForEvaluation() {
v8::HandleScope handle_scope(isolate_); v8::HandleScope handle_scope(isolate_);
#if defined(USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE)
V8PerContextData* per_context_data = script_state_->PerContextData();
ignore_result(per_context_data->ConstructorForType(
global_scope_->GetWrapperTypeInfo()));
#else // USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE
ScriptState::Scope scope(script_state_); ScriptState::Scope scope(script_state_);
v8::Local<v8::Context> context = script_state_->GetContext(); v8::Local<v8::Context> context = script_state_->GetContext();
...@@ -323,6 +328,7 @@ void WorkerOrWorkletScriptController::PrepareForEvaluation() { ...@@ -323,6 +328,7 @@ void WorkerOrWorkletScriptController::PrepareForEvaluation() {
wrapper_type_info->InstallConditionalFeatures( wrapper_type_info->InstallConditionalFeatures(
context, *world_, global_object, v8::Local<v8::Object>(), context, *world_, global_object, v8::Local<v8::Object>(),
v8::Local<v8::Function>(), global_interface_template); v8::Local<v8::Function>(), global_interface_template);
#endif // USE_BLINK_V8_BINDING_NEW_IDL_INTERFACE
} }
void WorkerOrWorkletScriptController::DisableEvalInternal( void WorkerOrWorkletScriptController::DisableEvalInternal(
......
...@@ -278,6 +278,8 @@ v8::Local<v8::Context> V8ContextSnapshotImpl::CreateContext( ...@@ -278,6 +278,8 @@ v8::Local<v8::Context> V8ContextSnapshotImpl::CreateContext(
v8::ExtensionConfiguration* extension_config, v8::ExtensionConfiguration* extension_config,
v8::Local<v8::Object> global_proxy, v8::Local<v8::Object> global_proxy,
Document* document) { Document* document) {
DCHECK(document);
V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate); V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate);
if (per_isolate_data->GetV8ContextSnapshotMode() != if (per_isolate_data->GetV8ContextSnapshotMode() !=
V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot) { V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot) {
...@@ -301,7 +303,7 @@ v8::Local<v8::Context> V8ContextSnapshotImpl::CreateContext( ...@@ -301,7 +303,7 @@ v8::Local<v8::Context> V8ContextSnapshotImpl::CreateContext(
return v8::Context::FromSnapshot( return v8::Context::FromSnapshot(
isolate, WorldToIndex(world), internal_field_desrializer, isolate, WorldToIndex(world), internal_field_desrializer,
extension_config, global_proxy, extension_config, global_proxy,
html_document->GetExecutionContext()->GetMicrotaskQueue()) document->GetExecutionContext()->GetMicrotaskQueue())
.ToLocalChecked(); .ToLocalChecked();
} }
......
...@@ -77,6 +77,8 @@ class PLATFORM_EXPORT V8PerContextData final { ...@@ -77,6 +77,8 @@ class PLATFORM_EXPORT V8PerContextData final {
: CreateWrapperFromCacheSlowCase(type); : CreateWrapperFromCacheSlowCase(type);
} }
// Returns the interface object that is appropriately initialized (e.g.
// context-dependent properties are installed).
v8::Local<v8::Function> ConstructorForType(const WrapperTypeInfo* type) { v8::Local<v8::Function> ConstructorForType(const WrapperTypeInfo* type) {
v8::Local<v8::Function> interface_object = constructor_map_.Get(type); v8::Local<v8::Function> interface_object = constructor_map_.Get(type);
return (!interface_object.IsEmpty()) ? interface_object return (!interface_object.IsEmpty()) ? interface_object
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment