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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp

Issue 2429343004: [CachedAccessor] for window.document. (Closed)
Patch Set: Oh look, layouttests, document is a getter now. Created 4 years, 2 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) 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 static_cast<v8::PropertyAttribute>(attribute.attribute)) 116 static_cast<v8::PropertyAttribute>(attribute.attribute))
117 .ToChecked(); 117 .ToChecked();
118 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) 118 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface)
119 NOTREACHED(); 119 NOTREACHED();
120 } 120 }
121 121
122 template <class FunctionOrTemplate> 122 template <class FunctionOrTemplate>
123 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate( 123 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(
124 v8::Isolate*, 124 v8::Isolate*,
125 v8::FunctionCallback, 125 v8::FunctionCallback,
126 V8DOMConfiguration::CachedAccessorCallback,
126 v8::Local<v8::Value> data, 127 v8::Local<v8::Value> data,
127 v8::Local<v8::Signature>, 128 v8::Local<v8::Signature>,
128 int length); 129 int length);
129 130
130 template <> 131 template <>
131 v8::Local<v8::FunctionTemplate> 132 v8::Local<v8::FunctionTemplate>
132 createAccessorFunctionOrTemplate<v8::FunctionTemplate>( 133 createAccessorFunctionOrTemplate<v8::FunctionTemplate>(
133 v8::Isolate* isolate, 134 v8::Isolate* isolate,
134 v8::FunctionCallback callback, 135 v8::FunctionCallback callback,
136 V8DOMConfiguration::CachedAccessorCallback cachedAccessorCallback,
135 v8::Local<v8::Value> data, 137 v8::Local<v8::Value> data,
136 v8::Local<v8::Signature> signature, 138 v8::Local<v8::Signature> signature,
137 int length) { 139 int length) {
138 v8::Local<v8::FunctionTemplate> functionTemplate; 140 v8::Local<v8::FunctionTemplate> functionTemplate;
139 if (callback) { 141 if (callback) {
140 functionTemplate = 142 if (cachedAccessorCallback) {
141 v8::FunctionTemplate::New(isolate, callback, data, signature, length); 143 functionTemplate = v8::FunctionTemplate::NewWithCache(
144 isolate, callback, cachedAccessorCallback(isolate), data, signature,
145 length);
146 } else {
147 functionTemplate =
148 v8::FunctionTemplate::New(isolate, callback, data, signature, length);
149 }
150
142 if (!functionTemplate.IsEmpty()) { 151 if (!functionTemplate.IsEmpty()) {
143 functionTemplate->RemovePrototype(); 152 functionTemplate->RemovePrototype();
144 functionTemplate->SetAcceptAnyReceiver(false); 153 functionTemplate->SetAcceptAnyReceiver(false);
145 } 154 }
146 } 155 }
147 return functionTemplate; 156 return functionTemplate;
148 } 157 }
149 158
150 template <> 159 template <>
151 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>( 160 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>(
152 v8::Isolate* isolate, 161 v8::Isolate* isolate,
153 v8::FunctionCallback callback, 162 v8::FunctionCallback callback,
163 V8DOMConfiguration::CachedAccessorCallback,
154 v8::Local<v8::Value> data, 164 v8::Local<v8::Value> data,
155 v8::Local<v8::Signature> signature, 165 v8::Local<v8::Signature> signature,
156 int length) { 166 int length) {
157 if (!callback) 167 if (!callback)
158 return v8::Local<v8::Function>(); 168 return v8::Local<v8::Function>();
159 169
160 v8::Local<v8::FunctionTemplate> functionTemplate = 170 v8::Local<v8::FunctionTemplate> functionTemplate =
161 createAccessorFunctionOrTemplate<v8::FunctionTemplate>( 171 createAccessorFunctionOrTemplate<v8::FunctionTemplate>(
162 isolate, callback, data, signature, length); 172 isolate, callback, nullptr, data, signature, length);
163 if (functionTemplate.IsEmpty()) 173 if (functionTemplate.IsEmpty())
164 return v8::Local<v8::Function>(); 174 return v8::Local<v8::Function>();
165 175
166 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 176 v8::Local<v8::Context> context = isolate->GetCurrentContext();
167 v8::Local<v8::Function> function; 177 v8::Local<v8::Function> function;
168 if (!functionTemplate->GetFunction(context).ToLocal(&function)) 178 if (!functionTemplate->GetFunction(context).ToLocal(&function))
169 return v8::Local<v8::Function>(); 179 return v8::Local<v8::Function>();
170 return function; 180 return function;
171 } 181 }
172 182
173 template <class ObjectOrTemplate, class FunctionOrTemplate> 183 template <class ObjectOrTemplate, class FunctionOrTemplate>
174 void installAccessorInternal( 184 void installAccessorInternal(
175 v8::Isolate* isolate, 185 v8::Isolate* isolate,
176 v8::Local<ObjectOrTemplate> instanceOrTemplate, 186 v8::Local<ObjectOrTemplate> instanceOrTemplate,
177 v8::Local<ObjectOrTemplate> prototypeOrTemplate, 187 v8::Local<ObjectOrTemplate> prototypeOrTemplate,
178 v8::Local<FunctionOrTemplate> interfaceOrTemplate, 188 v8::Local<FunctionOrTemplate> interfaceOrTemplate,
179 v8::Local<v8::Signature> signature, 189 v8::Local<v8::Signature> signature,
180 const V8DOMConfiguration::AccessorConfiguration& accessor, 190 const V8DOMConfiguration::AccessorConfiguration& accessor,
181 const DOMWrapperWorld& world) { 191 const DOMWrapperWorld& world) {
182 if (accessor.exposeConfiguration == 192 if (accessor.exposeConfiguration ==
183 V8DOMConfiguration::OnlyExposedToPrivateScript && 193 V8DOMConfiguration::OnlyExposedToPrivateScript &&
184 !world.isPrivateScriptIsolatedWorld()) 194 !world.isPrivateScriptIsolatedWorld())
185 return; 195 return;
186 196
187 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); 197 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name);
188 v8::FunctionCallback getterCallback = accessor.getter; 198 v8::FunctionCallback getterCallback = accessor.getter;
189 v8::FunctionCallback setterCallback = accessor.setter; 199 v8::FunctionCallback setterCallback = accessor.setter;
200 V8DOMConfiguration::CachedAccessorCallback cachedAccessorCallback = nullptr;
190 if (world.isMainWorld()) { 201 if (world.isMainWorld()) {
191 if (accessor.getterForMainWorld) 202 if (accessor.getterForMainWorld)
192 getterCallback = accessor.getterForMainWorld; 203 getterCallback = accessor.getterForMainWorld;
193 if (accessor.setterForMainWorld) 204 if (accessor.setterForMainWorld)
194 setterCallback = accessor.setterForMainWorld; 205 setterCallback = accessor.setterForMainWorld;
206 cachedAccessorCallback = accessor.cachedAccessorCallback;
195 } 207 }
208
196 // Support [LenientThis] by not specifying the signature. V8 does not do 209 // Support [LenientThis] by not specifying the signature. V8 does not do
197 // the type checking against holder if no signature is specified. Note that 210 // the type checking against holder if no signature is specified. Note that
198 // info.Holder() passed to callbacks will be *unsafe*. 211 // info.Holder() passed to callbacks will be *unsafe*.
199 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) 212 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder)
200 signature = v8::Local<v8::Signature>(); 213 signature = v8::Local<v8::Signature>();
201 v8::Local<v8::Value> data = 214 v8::Local<v8::Value> data =
202 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); 215 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data));
203 216
204 DCHECK(accessor.propertyLocationConfiguration); 217 DCHECK(accessor.propertyLocationConfiguration);
205 if (accessor.propertyLocationConfiguration & 218 if (accessor.propertyLocationConfiguration &
206 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { 219 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) {
207 v8::Local<FunctionOrTemplate> getter = 220 v8::Local<FunctionOrTemplate> getter =
208 createAccessorFunctionOrTemplate<FunctionOrTemplate>( 221 createAccessorFunctionOrTemplate<FunctionOrTemplate>(
209 isolate, getterCallback, data, signature, 0); 222 isolate, getterCallback, cachedAccessorCallback, data, signature,
223 0);
210 v8::Local<FunctionOrTemplate> setter = 224 v8::Local<FunctionOrTemplate> setter =
211 createAccessorFunctionOrTemplate<FunctionOrTemplate>( 225 createAccessorFunctionOrTemplate<FunctionOrTemplate>(
212 isolate, setterCallback, data, signature, 1); 226 isolate, setterCallback, nullptr, data, signature, 1);
213 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) 227 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance)
214 instanceOrTemplate->SetAccessorProperty( 228 instanceOrTemplate->SetAccessorProperty(
215 name, getter, setter, 229 name, getter, setter,
216 static_cast<v8::PropertyAttribute>(accessor.attribute), 230 static_cast<v8::PropertyAttribute>(accessor.attribute),
217 static_cast<v8::AccessControl>(accessor.settings)); 231 static_cast<v8::AccessControl>(accessor.settings));
218 if (accessor.propertyLocationConfiguration & 232 if (accessor.propertyLocationConfiguration &
219 V8DOMConfiguration::OnPrototype) 233 V8DOMConfiguration::OnPrototype)
220 prototypeOrTemplate->SetAccessorProperty( 234 prototypeOrTemplate->SetAccessorProperty(
221 name, getter, setter, 235 name, getter, setter,
222 static_cast<v8::PropertyAttribute>(accessor.attribute), 236 static_cast<v8::PropertyAttribute>(accessor.attribute),
223 static_cast<v8::AccessControl>(accessor.settings)); 237 static_cast<v8::AccessControl>(accessor.settings));
224 } 238 }
225 if (accessor.propertyLocationConfiguration & 239 if (accessor.propertyLocationConfiguration &
226 V8DOMConfiguration::OnInterface) { 240 V8DOMConfiguration::OnInterface) {
227 // Attributes installed on the interface object must be static 241 // Attributes installed on the interface object must be static
228 // attributes, so no need to specify a signature, i.e. no need to do 242 // attributes, so no need to specify a signature, i.e. no need to do
229 // type check against a holder. 243 // type check against a holder.
230 v8::Local<FunctionOrTemplate> getter = 244 v8::Local<FunctionOrTemplate> getter =
231 createAccessorFunctionOrTemplate<FunctionOrTemplate>( 245 createAccessorFunctionOrTemplate<FunctionOrTemplate>(
232 isolate, getterCallback, data, v8::Local<v8::Signature>(), 0); 246 isolate, getterCallback, nullptr, data, v8::Local<v8::Signature>(),
haraken 2016/10/20 08:22:23 nullptr => cachedAccessorCallback?
vogelheim 2016/10/20 13:27:59 Well... not sure. :-/ Since this is case is prese
haraken 2016/10/20 13:40:33 OK, let's keep nullptr here.
247 0);
233 v8::Local<FunctionOrTemplate> setter = 248 v8::Local<FunctionOrTemplate> setter =
234 createAccessorFunctionOrTemplate<FunctionOrTemplate>( 249 createAccessorFunctionOrTemplate<FunctionOrTemplate>(
235 isolate, setterCallback, data, v8::Local<v8::Signature>(), 1); 250 isolate, setterCallback, nullptr, data, v8::Local<v8::Signature>(),
251 1);
236 interfaceOrTemplate->SetAccessorProperty( 252 interfaceOrTemplate->SetAccessorProperty(
237 name, getter, setter, 253 name, getter, setter,
238 static_cast<v8::PropertyAttribute>(accessor.attribute), 254 static_cast<v8::PropertyAttribute>(accessor.attribute),
239 static_cast<v8::AccessControl>(accessor.settings)); 255 static_cast<v8::AccessControl>(accessor.settings));
240 } 256 }
241 } 257 }
242 258
243 v8::Local<v8::Primitive> valueForConstant( 259 v8::Local<v8::Primitive> valueForConstant(
244 v8::Isolate* isolate, 260 v8::Isolate* isolate,
245 const V8DOMConfiguration::ConstantConfiguration& constant) { 261 const V8DOMConfiguration::ConstantConfiguration& constant) {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 void V8DOMConfiguration::setClassString( 618 void V8DOMConfiguration::setClassString(
603 v8::Isolate* isolate, 619 v8::Isolate* isolate,
604 v8::Local<v8::ObjectTemplate> objectTemplate, 620 v8::Local<v8::ObjectTemplate> objectTemplate,
605 const char* classString) { 621 const char* classString) {
606 objectTemplate->Set( 622 objectTemplate->Set(
607 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), 623 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString),
608 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); 624 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum));
609 } 625 }
610 626
611 } // namespace blink 627 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698