Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "bindings/core/v8/V8DOMConfiguration.h" | 29 #include "bindings/core/v8/V8DOMConfiguration.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/V8Document.h" | |
| 32 #include "bindings/core/v8/V8EventTarget.h" | |
| 33 #include "bindings/core/v8/V8HTMLDocument.h" | |
| 34 #include "bindings/core/v8/V8Node.h" | |
| 35 #include "bindings/core/v8/V8SnapshotCreator.h" | |
| 36 #include "bindings/core/v8/V8Window.h" | |
| 31 #include "platform/bindings/V8ObjectConstructor.h" | 37 #include "platform/bindings/V8ObjectConstructor.h" |
| 32 #include "platform/bindings/V8PerContextData.h" | 38 #include "platform/bindings/V8PerContextData.h" |
| 33 #include "platform/instrumentation/tracing/TraceEvent.h" | 39 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 34 | 40 |
| 35 namespace blink { | 41 namespace blink { |
| 36 | 42 |
| 37 namespace { | 43 namespace { |
| 38 | 44 |
| 39 template <class Configuration> | 45 template <class Configuration> |
| 40 bool WorldConfigurationApplies(const Configuration& config, | 46 bool WorldConfigurationApplies(const Configuration& config, |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 prototype_template->SetInternalFieldCount(kV8PrototypeInternalFieldcount); | 677 prototype_template->SetInternalFieldCount(kV8PrototypeInternalFieldcount); |
| 672 } | 678 } |
| 673 } | 679 } |
| 674 | 680 |
| 675 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::DomClassTemplate( | 681 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::DomClassTemplate( |
| 676 v8::Isolate* isolate, | 682 v8::Isolate* isolate, |
| 677 const DOMWrapperWorld& world, | 683 const DOMWrapperWorld& world, |
| 678 WrapperTypeInfo* wrapper_type_info, | 684 WrapperTypeInfo* wrapper_type_info, |
| 679 InstallTemplateFunction configure_dom_class_template) { | 685 InstallTemplateFunction configure_dom_class_template) { |
| 680 V8PerIsolateData* data = V8PerIsolateData::From(isolate); | 686 V8PerIsolateData* data = V8PerIsolateData::From(isolate); |
| 681 v8::Local<v8::FunctionTemplate> result = | 687 v8::Local<v8::FunctionTemplate> interface_template = |
| 682 data->FindInterfaceTemplate(world, wrapper_type_info); | 688 data->FindInterfaceTemplate(world, wrapper_type_info); |
| 683 if (!result.IsEmpty()) | 689 if (!interface_template.IsEmpty()) |
| 684 return result; | 690 return interface_template; |
| 685 | 691 |
| 686 result = v8::FunctionTemplate::New( | 692 if (V8SnapshotCreator::TakingSnapshot()) { |
|
Yuki
2017/05/12 15:20:09
Curious. Why V8SnapshotCreator::TakingSnapshot()
peria
2017/05/30 08:25:42
Acknowledged.
| |
| 687 isolate, V8ObjectConstructor::IsValidConstructorMode); | 693 interface_template = |
| 688 configure_dom_class_template(isolate, world, result); | 694 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.
| |
| 689 data->SetInterfaceTemplate(world, wrapper_type_info, result); | 695 if (!interface_template.IsEmpty()) |
| 690 return result; | 696 return interface_template; |
| 697 } else if (data->UseSnapshot()) { | |
| 698 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.
| |
| 699 &V8EventTarget::wrapperTypeInfo, &V8Window::wrapperTypeInfo, | |
| 700 &V8Node::wrapperTypeInfo, &V8Document::wrapperTypeInfo, | |
| 701 &V8HTMLDocument::wrapperTypeInfo, | |
| 702 }; | |
| 703 const int index_offset = | |
| 704 world.IsMainWorld() ? 0 : WTF_ARRAY_LENGTH(snapshot_types); | |
| 705 | |
| 706 // Snapshotted templates are expected to be used just to get | |
| 707 // wrapper_type_info. | |
| 708 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.
| |
| 709 if (snapshot_types[i]->Equals(wrapper_type_info)) { | |
| 710 if (v8::FunctionTemplate::FromSnapshot(isolate, index_offset + i) | |
| 711 .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.
| |
| 712 } | |
| 713 break; | |
| 714 } | |
| 715 } | |
| 716 } | |
| 717 | |
| 718 if (interface_template.IsEmpty()) { | |
| 719 interface_template = v8::FunctionTemplate::New( | |
| 720 isolate, V8ObjectConstructor::IsValidConstructorMode); | |
| 721 configure_dom_class_template(isolate, world, interface_template); | |
| 722 } | |
| 723 CHECK(!interface_template.IsEmpty()); | |
| 724 | |
| 725 if (V8SnapshotCreator::TakingSnapshot()) { | |
| 726 data->SetInterfaceTemplateTemp(world, wrapper_type_info, | |
| 727 interface_template); | |
| 728 } else { | |
| 729 data->SetInterfaceTemplate(world, wrapper_type_info, interface_template); | |
| 730 } | |
| 731 | |
| 732 return interface_template; | |
| 691 } | 733 } |
| 692 | 734 |
| 693 void V8DOMConfiguration::SetClassString( | 735 void V8DOMConfiguration::SetClassString( |
| 694 v8::Isolate* isolate, | 736 v8::Isolate* isolate, |
| 695 v8::Local<v8::ObjectTemplate> object_template, | 737 v8::Local<v8::ObjectTemplate> object_template, |
| 696 const char* class_string) { | 738 const char* class_string) { |
| 697 object_template->Set( | 739 object_template->Set( |
| 698 v8::Symbol::GetToStringTag(isolate), | 740 v8::Symbol::GetToStringTag(isolate), |
| 699 V8AtomicString(isolate, class_string), | 741 V8AtomicString(isolate, class_string), |
| 700 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); | 742 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); |
| 701 } | 743 } |
| 702 | 744 |
| 703 } // namespace blink | 745 } // namespace blink |
| OLD | NEW |