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

Side by Side Diff: third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceConstructor.cpp

Issue 2647643002: Fix V8 bindings for named constructors to set prototype object correctly (Closed)
Patch Set: Rebase Created 3 years, 9 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file has been auto-generated by code_generator_v8.py. 5 // This file has been auto-generated by code_generator_v8.py.
6 // DO NOT MODIFY! 6 // DO NOT MODIFY!
7 7
8 // This file has been generated from the Jinja2 template in 8 // This file has been generated from the Jinja2 template in
9 // third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl 9 // third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl
10 10
11 // clang-format off 11 // clang-format off
12 #include "V8TestInterfaceConstructor.h" 12 #include "V8TestInterfaceConstructor.h"
13 13
14 #include "bindings/core/v8/Dictionary.h" 14 #include "bindings/core/v8/Dictionary.h"
15 #include "bindings/core/v8/ExceptionState.h" 15 #include "bindings/core/v8/ExceptionState.h"
16 #include "bindings/core/v8/IDLTypes.h" 16 #include "bindings/core/v8/IDLTypes.h"
17 #include "bindings/core/v8/LongOrTestDictionary.h" 17 #include "bindings/core/v8/LongOrTestDictionary.h"
18 #include "bindings/core/v8/NativeValueTraitsImpl.h" 18 #include "bindings/core/v8/NativeValueTraitsImpl.h"
19 #include "bindings/core/v8/V8DOMConfiguration.h" 19 #include "bindings/core/v8/V8DOMConfiguration.h"
20 #include "bindings/core/v8/V8ObjectConstructor.h" 20 #include "bindings/core/v8/V8ObjectConstructor.h"
21 #include "bindings/core/v8/V8PrivateProperty.h"
21 #include "bindings/core/v8/V8TestDictionary.h" 22 #include "bindings/core/v8/V8TestDictionary.h"
22 #include "bindings/core/v8/V8TestInterfaceEmpty.h" 23 #include "bindings/core/v8/V8TestInterfaceEmpty.h"
23 #include "core/dom/Document.h" 24 #include "core/dom/Document.h"
24 #include "core/frame/LocalDOMWindow.h" 25 #include "core/frame/LocalDOMWindow.h"
25 #include "core/frame/UseCounter.h" 26 #include "core/frame/UseCounter.h"
26 #include "wtf/GetPtr.h" 27 #include "wtf/GetPtr.h"
27 #include "wtf/RefPtr.h" 28 #include "wtf/RefPtr.h"
28 29
29 namespace blink { 30 namespace blink {
30 31
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 v8::Local<v8::FunctionTemplate> V8TestInterfaceConstructorConstructor::domTempla te(v8::Isolate* isolate, const DOMWrapperWorld& world) { 354 v8::Local<v8::FunctionTemplate> V8TestInterfaceConstructorConstructor::domTempla te(v8::Isolate* isolate, const DOMWrapperWorld& world) {
354 static int domTemplateKey; // This address is used for a key to look up the do m template. 355 static int domTemplateKey; // This address is used for a key to look up the do m template.
355 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 356 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
356 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d omTemplateKey); 357 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d omTemplateKey);
357 if (!result.IsEmpty()) 358 if (!result.IsEmpty())
358 return result; 359 return result;
359 360
360 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceConstructorConstruc torCallback); 361 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceConstructorConstruc torCallback);
361 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); 362 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
362 instanceTemplate->SetInternalFieldCount(V8TestInterfaceConstructor::internalFi eldCount); 363 instanceTemplate->SetInternalFieldCount(V8TestInterfaceConstructor::internalFi eldCount);
363 result->SetClassName(v8AtomicString(isolate, "TestInterfaceConstructor")); 364 result->SetClassName(v8AtomicString(isolate, "Audio"));
364 result->Inherit(V8TestInterfaceConstructor::domTemplate(isolate, world)); 365 result->Inherit(V8TestInterfaceConstructor::domTemplate(isolate, world));
365 data->setInterfaceTemplate(world, &domTemplateKey, result); 366 data->setInterfaceTemplate(world, &domTemplateKey, result);
366 return result; 367 return result;
367 } 368 }
368 369
370 void V8TestInterfaceConstructorConstructor::NamedConstructorAttributeGetter(
371 v8::Local<v8::Name> propertyName,
372 const v8::PropertyCallbackInfo<v8::Value>& info) {
373 v8::Local<v8::Context> creationContext = info.Holder()->CreationContext();
374 V8PerContextData* perContextData = V8PerContextData::from(creationContext);
375 if (!perContextData) {
376 // TODO(yukishiino): Return a valid named constructor even after the context is detached
377 return;
378 }
379
380 v8::Local<v8::Function> namedConstructor = perContextData->constructorForType( &V8TestInterfaceConstructorConstructor::wrapperTypeInfo);
381
382 // Set the prototype of named constructors to the regular constructor.
383 auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info. GetIsolate());
384 v8::Local<v8::Context> currentContext = info.GetIsolate()->GetCurrentContext() ;
385 v8::Local<v8::Value> privateValue = privateProperty.get(currentContext, namedC onstructor);
386
387 if (privateValue.IsEmpty()) {
388 v8::Local<v8::Function> interface = perContextData->constructorForType(&V8Te stInterfaceConstructor::wrapperTypeInfo);
389 v8::Local<v8::Value> interfacePrototype = interface->Get(currentContext, v8A tomicString(info.GetIsolate(), "prototype")).ToLocalChecked();
390 bool result = namedConstructor->Set(currentContext, v8AtomicString(info.GetI solate(), "prototype"), interfacePrototype).ToChecked();
391 if (!result)
392 return;
393 privateProperty.set(currentContext, namedConstructor, v8::True(info.GetIsola te()));
394 }
395
396 v8SetReturnValue(info, namedConstructor);
397 }
398
369 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) { 399 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) {
370 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::Test Feature); 400 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::Test Feature);
371 if (!info.IsConstructCall()) { 401 if (!info.IsConstructCall()) {
372 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::const ructorNotCallableAsFunction("TestInterfaceConstructor")); 402 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::const ructorNotCallableAsFunction("TestInterfaceConstructor"));
373 return; 403 return;
374 } 404 }
375 405
376 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExisti ngObject) { 406 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExisti ngObject) {
377 v8SetReturnValue(info, info.Holder()); 407 v8SetReturnValue(info, info.Holder());
378 return; 408 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 441
412 TestInterfaceConstructor* V8TestInterfaceConstructor::toImplWithTypeCheck(v8::Is olate* isolate, v8::Local<v8::Value> value) { 442 TestInterfaceConstructor* V8TestInterfaceConstructor::toImplWithTypeCheck(v8::Is olate* isolate, v8::Local<v8::Value> value) {
413 return hasInstance(value, isolate) ? toImpl(v8::Local<v8::Object>::Cast(value) ) : nullptr; 443 return hasInstance(value, isolate) ? toImpl(v8::Local<v8::Object>::Cast(value) ) : nullptr;
414 } 444 }
415 445
416 TestInterfaceConstructor* NativeValueTraits<TestInterfaceConstructor>::nativeVal ue(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionSt ate) { 446 TestInterfaceConstructor* NativeValueTraits<TestInterfaceConstructor>::nativeVal ue(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionSt ate) {
417 return V8TestInterfaceConstructor::toImplWithTypeCheck(isolate, value); 447 return V8TestInterfaceConstructor::toImplWithTypeCheck(isolate, value);
418 } 448 }
419 449
420 } // namespace blink 450 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698