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

Unified Diff: third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceNamedConstructor2.cpp

Issue 2647643002: Fix V8 bindings for named constructors to set prototype object correctly (Closed)
Patch Set: Review feedback Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceNamedConstructor2.cpp
diff --git a/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceNamedConstructor2.cpp b/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceNamedConstructor2.cpp
index 04bec68bce55b6f09ee8b7af2c6963f4aeca93be..a1759e38ff436df56dd480f37e6ba2943698cd77 100644
--- a/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceNamedConstructor2.cpp
+++ b/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceNamedConstructor2.cpp
@@ -14,6 +14,7 @@
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8ObjectConstructor.h"
+#include "bindings/core/v8/V8PrivateProperty.h"
#include "core/dom/Document.h"
#include "core/frame/LocalDOMWindow.h"
#include "wtf/GetPtr.h"
@@ -108,6 +109,35 @@ v8::Local<v8::FunctionTemplate> V8TestInterfaceNamedConstructor2Constructor::dom
return result;
}
+void V8TestInterfaceNamedConstructor2Constructor::NamedConstructorAttributeGetter(
+ v8::Local<v8::Name> propertyName,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Context> creationContext = info.Holder()->CreationContext();
+ V8PerContextData* perContextData = V8PerContextData::from(creationContext);
+ if (!perContextData) {
+ // TODO(yukishiino): Return a valid named constructor even after the context is detached
+ return;
+ }
+
+ v8::Local<v8::Function> namedConstructor = perContextData->constructorForType(&V8TestInterfaceNamedConstructor2Constructor::wrapperTypeInfo);
+
+ // Set the prototype of named constructors to the regular constructor.
+ auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info.GetIsolate());
+ v8::Local<v8::Context> currentContext = info.GetIsolate()->GetCurrentContext();
+ v8::Local<v8::Value> privateValue = privateProperty.get(currentContext, namedConstructor);
+
+ if (privateValue.IsEmpty()) {
+ v8::Local<v8::Function> interface = perContextData->constructorForType(&V8TestInterfaceNamedConstructor2::wrapperTypeInfo);
+ v8::Local<v8::Value> interfacePrototype = interface->Get(currentContext, v8AtomicString(info.GetIsolate(), "prototype")).ToLocalChecked();
+ bool result = namedConstructor->Set(currentContext, v8AtomicString(info.GetIsolate(), "prototype"), interfacePrototype).ToChecked();
+ if (!result)
+ return;
+ privateProperty.set(currentContext, namedConstructor, v8::True(info.GetIsolate()));
+ }
+
+ v8SetReturnValue(info, namedConstructor);
+}
+
static void installV8TestInterfaceNamedConstructor2Template(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) {
// Initialize the interface object's template.
V8DOMConfiguration::initializeDOMInterfaceTemplate(isolate, interfaceTemplate, V8TestInterfaceNamedConstructor2::wrapperTypeInfo.interfaceName, v8::Local<v8::FunctionTemplate>(), V8TestInterfaceNamedConstructor2::internalFieldCount);

Powered by Google App Engine
This is Rietveld 408576698