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

Unified Diff: third_party/WebKit/Source/bindings/templates/interface_base.cpp.tmpl

Issue 2777183004: Make pair iterators inherit from %IteratorPrototype%. (Closed)
Patch Set: Rebased patch with tests Created 3 years, 8 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/templates/interface_base.cpp.tmpl
diff --git a/third_party/WebKit/Source/bindings/templates/interface_base.cpp.tmpl b/third_party/WebKit/Source/bindings/templates/interface_base.cpp.tmpl
index c4826362fc0bf1e58c88e5ebcfcf6dc89a1bc876..4ebad8415559b43ee94a55e6c31170b253075372 100644
--- a/third_party/WebKit/Source/bindings/templates/interface_base.cpp.tmpl
+++ b/third_party/WebKit/Source/bindings/templates/interface_base.cpp.tmpl
@@ -532,6 +532,29 @@ static void install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWo
{% endfilter %}
{% endif %}
+ {% if interface_name == 'Iterator' %}
+ // The WebIDL spec says when an interface has pair iterators the iterators it returns must be
Yuki 2017/04/07 09:25:03 nit: Could you wrap lines within 80 columns?
Raphael Kubo da Costa (rakuco) 2017/04/07 09:45:45 Done.
+ // instances of the "default iterator object" whose [[Prototype]] points to an "iterator prototype
+ // object" whose [[Prototype]], on its turn, points to %IteratorPrototype%. next() must be
+ // implemented in the "iterator prototype object", while %IteratorPrototype% provides @@iterator.
+ // References: https://heycam.github.io/webidl/#es-default-iterator-object
+ // https://heycam.github.io/webidl/#es-iterator-prototype-object
+ //
+ // The iterators we return from interfaces that have pair interators adhere to the above by:
+ // - Adding the "next()" property to its prototype object.
+ // - Making the prototype object inherit from %IteratorPrototype% with the hack below, which
+ // creates another function template with no prototype and sets the "prototype" property of its
+ // function object.
+ // When |interfaceTemplate|'s function object is created, its prototype.__proto__ will point to
+ // the value of the "prototype" property of |iteratorPrototypeTemplate|, which is exactly what
+ // we want.
+ v8::Local<v8::FunctionTemplate> iteratorPrototypeTemplate = v8::FunctionTemplate::New(isolate);
Yuki 2017/04/07 09:25:03 nit: The name is a bit confusing. Let me suppose
Yuki 2017/04/07 09:25:03 nit: This is okay, but let me elaborate something
Raphael Kubo da Costa (rakuco) 2017/04/07 09:45:45 How about intrinsicIteratorPrototypeInterfaceTempl
Raphael Kubo da Costa (rakuco) 2017/04/07 09:45:45 Thanks for the explanation! I'm still wrapping my
+ iteratorPrototypeTemplate->RemovePrototype();
+ iteratorPrototypeTemplate->SetIntrinsicDataProperty(v8AtomicString(isolate, "prototype"),
+ v8::kIteratorPrototype);
+ interfaceTemplate->Inherit(iteratorPrototypeTemplate);
+ {% endif %}
+
{% if interface_name == 'Location' %}
// Symbol.toPrimitive
// Prevent author scripts to inject Symbol.toPrimitive property into location

Powered by Google App Engine
This is Rietveld 408576698