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

Unified 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: Created 3 years, 11 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/V8TestInterfaceConstructor.cpp
diff --git a/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceConstructor.cpp b/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceConstructor.cpp
index 0a46fdaba5a704908650023e44b801beb369c7ce..e357756448f25fa238a7f2a4bc074de8fb6c1fb8 100644
--- a/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceConstructor.cpp
+++ b/third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceConstructor.cpp
@@ -365,6 +365,41 @@ v8::Local<v8::FunctionTemplate> V8TestInterfaceConstructorConstructor::domTempla
return result;
}
+void V8TestInterfaceConstructorConstructor::NamedConstructorAttributeGetter(
+ v8::Local<v8::Name> propertyName,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionContext, "TestInterfaceConstructor");
+ v8::Local<v8::Value> data = info.Data();
+ DCHECK(data->IsExternal());
+ V8PerContextData* perContextData =
+ V8PerContextData::from(info.Holder()->CreationContext());
+ if (!perContextData)
+ return;
+
+ v8::Local<v8::Function> namedConstructorInterface = perContextData->constructorForType(WrapperTypeInfo::unwrap(data));
+ v8::Local<v8::Function> interface = perContextData->constructorForType(&V8TestInterfaceConstructor::wrapperTypeInfo);
+
+ // Set the prototype of named constructors to the regular constructor.
+ v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
+ auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info.GetIsolate());
+ v8::Local<v8::Value> privateValue = privateProperty.get(context, namedConstructorInterface);
+ if (privateValue.IsEmpty()) {
+ v8::MaybeLocal<v8::Value> interfacePrototype = interface->Get(context, v8AtomicString(info.GetIsolate(), "prototype"));
+ if (interfacePrototype.IsEmpty())
+ exceptionState.throwTypeError("Could not get prototype for V8TestInterfaceConstructor.");
+
+ v8::Maybe<bool> setResult = namedConstructorInterface->Set(context, v8AtomicString(info.GetIsolate(), "prototype"), interfacePrototype.ToLocalChecked());
+ if (setResult.IsNothing() || setResult.ToChecked() != true) {
+ exceptionState.throwTypeError("Could not set prototype for TestInterfaceConstructor.");
+ }
+
+ privateProperty.set(context, namedConstructorInterface, v8::True(info.GetIsolate()));
+ }
+
+ v8SetReturnValue(
+ info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data)));
+}
+
void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
if (!info.IsConstructCall()) {

Powered by Google App Engine
This is Rietveld 408576698