Index: third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp b/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp |
index 6ba91f90f2b367f41ae0b675ab5120949308f498..f56717ff3eb9e760d3ae0f85b00d0a92f5a6dd5e 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp |
@@ -28,6 +28,12 @@ |
#include "bindings/core/v8/V8DOMConfiguration.h" |
+#include "bindings/core/v8/V8Document.h" |
+#include "bindings/core/v8/V8EventTarget.h" |
+#include "bindings/core/v8/V8HTMLDocument.h" |
+#include "bindings/core/v8/V8Node.h" |
+#include "bindings/core/v8/V8SnapshotCreator.h" |
+#include "bindings/core/v8/V8Window.h" |
#include "platform/bindings/V8ObjectConstructor.h" |
#include "platform/bindings/V8PerContextData.h" |
#include "platform/instrumentation/tracing/TraceEvent.h" |
@@ -678,16 +684,52 @@ v8::Local<v8::FunctionTemplate> V8DOMConfiguration::DomClassTemplate( |
WrapperTypeInfo* wrapper_type_info, |
InstallTemplateFunction configure_dom_class_template) { |
V8PerIsolateData* data = V8PerIsolateData::From(isolate); |
- v8::Local<v8::FunctionTemplate> result = |
+ v8::Local<v8::FunctionTemplate> interface_template = |
data->FindInterfaceTemplate(world, wrapper_type_info); |
- if (!result.IsEmpty()) |
- return result; |
- |
- result = v8::FunctionTemplate::New( |
- isolate, V8ObjectConstructor::IsValidConstructorMode); |
- configure_dom_class_template(isolate, world, result); |
- data->SetInterfaceTemplate(world, wrapper_type_info, result); |
- return result; |
+ if (!interface_template.IsEmpty()) |
+ return interface_template; |
+ |
+ if (V8SnapshotCreator::TakingSnapshot()) { |
Yuki
2017/05/12 15:20:09
Curious. Why V8SnapshotCreator::TakingSnapshot()
peria
2017/05/30 08:25:42
Acknowledged.
|
+ interface_template = |
+ data->FindInterfaceTemplateTemp(world, wrapper_type_info); |
Yuki
2017/05/12 15:20:09
I think it's better not to expose FindInterfaceTem
peria
2017/05/30 08:25:41
Done.
|
+ if (!interface_template.IsEmpty()) |
+ return interface_template; |
+ } else if (data->UseSnapshot()) { |
+ static const WrapperTypeInfo* snapshot_types[] = { |
Yuki
2017/05/12 15:20:10
These things should be hidden in V8SnapshotCreator
peria
2017/05/30 08:25:42
Done.
|
+ &V8EventTarget::wrapperTypeInfo, &V8Window::wrapperTypeInfo, |
+ &V8Node::wrapperTypeInfo, &V8Document::wrapperTypeInfo, |
+ &V8HTMLDocument::wrapperTypeInfo, |
+ }; |
+ const int index_offset = |
+ world.IsMainWorld() ? 0 : WTF_ARRAY_LENGTH(snapshot_types); |
+ |
+ // Snapshotted templates are expected to be used just to get |
+ // wrapper_type_info. |
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(snapshot_types); ++i) { |
Yuki
2017/05/12 15:20:09
nit: I think you can use range-based for-loop.
for
peria
2017/05/30 08:25:42
no. this routine requires the index number.
|
+ if (snapshot_types[i]->Equals(wrapper_type_info)) { |
+ if (v8::FunctionTemplate::FromSnapshot(isolate, index_offset + i) |
+ .ToLocal(&interface_template)) { |
Yuki
2017/05/12 15:20:09
nit: ToLocalChecked()?
Or are we really going to
peria
2017/05/30 08:25:42
Done.
|
+ } |
+ break; |
+ } |
+ } |
+ } |
+ |
+ if (interface_template.IsEmpty()) { |
+ interface_template = v8::FunctionTemplate::New( |
+ isolate, V8ObjectConstructor::IsValidConstructorMode); |
+ configure_dom_class_template(isolate, world, interface_template); |
+ } |
+ CHECK(!interface_template.IsEmpty()); |
+ |
+ if (V8SnapshotCreator::TakingSnapshot()) { |
+ data->SetInterfaceTemplateTemp(world, wrapper_type_info, |
+ interface_template); |
+ } else { |
+ data->SetInterfaceTemplate(world, wrapper_type_info, interface_template); |
+ } |
+ |
+ return interface_template; |
} |
void V8DOMConfiguration::SetClassString( |