Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: third_party/WebKit/Source/platform/bindings/V8DOMWrapper.cpp

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Fix some behaviors Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // cache resulting objects or their constructors. 58 // cache resulting objects or their constructors.
59 const DOMWrapperWorld& world = DOMWrapperWorld::World(scope.GetContext()); 59 const DOMWrapperWorld& world = DOMWrapperWorld::World(scope.GetContext());
60 wrapper = type->domTemplate(isolate, world) 60 wrapper = type->domTemplate(isolate, world)
61 ->InstanceTemplate() 61 ->InstanceTemplate()
62 ->NewInstance(scope.GetContext()) 62 ->NewInstance(scope.GetContext())
63 .ToLocalChecked(); 63 .ToLocalChecked();
64 } 64 }
65 return wrapper; 65 return wrapper;
66 } 66 }
67 67
68 namespace {
69
70 v8::Local<v8::Function> ConstructPlainType(v8::Isolate* isolate,
Yuki 2017/05/12 15:20:10 No one seems using this function?
peria 2017/05/30 08:25:43 Acknowledged.
71 const DOMWrapperWorld& world,
72 v8::Local<v8::Context> context,
73 const WrapperTypeInfo* type) {
74 v8::Context::Scope scope(context);
75 // We shouldn't reach this point for the types that are implemented in v8 such
76 // as typed arrays and hence don't have domTemplateFunction.
77 DCHECK(type->dom_template_function);
78 v8::Local<v8::FunctionTemplate> interface_template =
79 type->domTemplate(isolate, world);
80 // Getting the function might fail if we're running out of stack or memory.
81 v8::Local<v8::Function> interface_object;
82 if (!interface_template->GetFunction(context).ToLocal(&interface_object))
83 return v8::Local<v8::Function>();
84
85 if (type->parent_class) {
86 v8::Local<v8::Object> prototype_template =
87 ConstructPlainType(isolate, world, context, type->parent_class);
88 CHECK(interface_object->SetPrototype(context, prototype_template)
89 .ToChecked());
90 }
91
92 v8::Local<v8::Value> prototype_value;
93 CHECK(interface_object->Get(context, V8AtomicString(isolate, "prototype"))
94 .ToLocal(&prototype_value));
95 CHECK(prototype_value->IsObject());
96 v8::Local<v8::Object> prototype_object = prototype_value.As<v8::Object>();
97 if (prototype_object->InternalFieldCount() ==
98 kV8PrototypeInternalFieldcount &&
99 type->wrapper_type_prototype ==
100 WrapperTypeInfo::kWrapperTypeObjectPrototype) {
101 prototype_object->SetAlignedPointerInInternalField(
102 kV8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type));
103 }
104 type->PreparePrototypeAndInterfaceObject(
105 context, world, prototype_object, interface_object, interface_template);
106
107 return interface_object;
108 }
109
110 } // namespace
111
68 bool V8DOMWrapper::IsWrapper(v8::Isolate* isolate, v8::Local<v8::Value> value) { 112 bool V8DOMWrapper::IsWrapper(v8::Isolate* isolate, v8::Local<v8::Value> value) {
69 if (value.IsEmpty() || !value->IsObject()) 113 if (value.IsEmpty() || !value->IsObject())
70 return false; 114 return false;
71 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 115 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
72 116
73 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount) 117 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount)
74 return false; 118 return false;
75 119
76 const WrapperTypeInfo* untrusted_wrapper_type_info = 120 const WrapperTypeInfo* untrusted_wrapper_type_info =
77 ToWrapperTypeInfo(object); 121 ToWrapperTypeInfo(object);
(...skipping 12 matching lines...) Expand all
90 return false; 134 return false;
91 135
92 const ScriptWrappable* untrusted_script_wrappable = ToScriptWrappable(object); 136 const ScriptWrappable* untrusted_script_wrappable = ToScriptWrappable(object);
93 const WrapperTypeInfo* untrusted_wrapper_type_info = 137 const WrapperTypeInfo* untrusted_wrapper_type_info =
94 ToWrapperTypeInfo(object); 138 ToWrapperTypeInfo(object);
95 return untrusted_script_wrappable && untrusted_wrapper_type_info && 139 return untrusted_script_wrappable && untrusted_wrapper_type_info &&
96 untrusted_wrapper_type_info->gin_embedder == gin::kEmbedderBlink; 140 untrusted_wrapper_type_info->gin_embedder == gin::kEmbedderBlink;
97 } 141 }
98 142
99 } // namespace blink 143 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698