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

Unified Diff: Source/bindings/templates/interface.cpp

Issue 1085453003: IDL: Add support for [Unscopeable] on attributes and methods (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: install @@unscopables on prototype object Created 5 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: Source/bindings/templates/interface.cpp
diff --git a/Source/bindings/templates/interface.cpp b/Source/bindings/templates/interface.cpp
index 5894565abbf1e40edcc3dc18d7bfc34b2827a7ca..e219a57f733523c19a042e0af8fd436c714e1fd4 100644
--- a/Source/bindings/templates/interface.cpp
+++ b/Source/bindings/templates/interface.cpp
@@ -474,7 +474,7 @@ static void {{cpp_class}}OriginSafeMethodSetterCallback(v8::Local<v8::Name> name
{% if named_constructor %}
{% set to_active_dom_object = '%s::toActiveDOMObject' % v8_class
if is_active_dom_object else '0' %}
-const WrapperTypeInfo {{v8_class}}Constructor::wrapperTypeInfo = { gin::kEmbedderBlink, {{v8_class}}Constructor::domTemplate, {{v8_class}}::refObject, {{v8_class}}::derefObject, {{v8_class}}::trace, {{to_active_dom_object}}, 0, {{v8_class}}::installConditionallyEnabledMethods, {{v8_class}}::installConditionallyEnabledProperties, "{{interface_name}}", 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{event_target_inheritance}}, WrapperTypeInfo::{{lifetime}}, WrapperTypeInfo::{{gc_type}} };
+const WrapperTypeInfo {{v8_class}}Constructor::wrapperTypeInfo = { gin::kEmbedderBlink, {{v8_class}}Constructor::domTemplate, {{v8_class}}::refObject, {{v8_class}}::derefObject, {{v8_class}}::trace, {{to_active_dom_object}}, 0, {{v8_class}}::preparePrototypeObject, {{v8_class}}::installConditionallyEnabledProperties, "{{interface_name}}", 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{event_target_inheritance}}, WrapperTypeInfo::{{lifetime}}, WrapperTypeInfo::{{gc_type}} };
{{generate_constructor(named_constructor)}}
v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate* isolate)
@@ -926,6 +926,45 @@ void {{v8_class}}::installConditionallyEnabledProperties(v8::Local<v8::Object> i
{##############################################################################}
+{% block prepare_prototype_object %}
+{% from 'methods.cpp' import install_conditionally_enabled_methods with context %}
haraken 2015/04/22 10:54:51 install_conditionally_enabled_methods => prepare_p
Jens Widell 2015/04/22 13:04:51 My thinking here is that the macro imported from m
haraken 2015/04/22 13:10:32 Makes sense, let's keep it. (Alternately I want to
Jens Widell 2015/04/22 14:22:10 Yes, it would certainly be great to eliminate [Per
+{% if unscopeables or conditionally_enabled_methods %}
+void {{v8_class}}::preparePrototypeObject(v8::Isolate* isolate, v8::Local<v8::Object> prototypeObject)
+{
+{% if unscopeables %}
+ {{install_unscopeables() | indent}}
+{% endif %}
+{% if conditionally_enabled_methods %}
haraken 2015/04/22 10:54:51 Once we remove [PerContextEnabled], can we remove
Jens Widell 2015/04/22 13:04:51 Yes, I imagine we could do that then.
+ {{install_conditionally_enabled_methods() | indent}}
+{% endif %}
+}
+
+{% endif %}
+{% endblock %}
+
+
+{##############################################################################}
+{% macro install_unscopeables() %}
+v8::Local<v8::Context> v8Context(prototypeObject->CreationContext());
+v8::Local<v8::Name> unscopablesSymbol(v8::Symbol::GetUnscopables(isolate));
+{% if is_partial %}
haraken 2015/04/22 10:54:51 Why do we need a different logic between partial a
Jens Widell 2015/04/22 13:04:52 We don't; the partial variant works for both, but
haraken 2015/04/22 13:10:32 Just to confirm: If we have X and PartialX, is it
Jens Widell 2015/04/22 14:22:10 Yes. V8FooPartial::preparePrototypeObject() calls
haraken 2015/04/22 15:36:10 ok, understood. I still prefer not introducing di
Jens Widell 2015/04/22 16:37:07 We need to make sure to only read an own @@unscopa
haraken 2015/04/22 17:02:26 Makes sense. Then shall we use the current is_part
Jens Widell 2015/04/22 17:08:04 Sure, I'll make that change.
Jens Widell 2015/04/22 17:15:13 Done.
+bool hasUnscopables = v8CallBoolean(prototypeObject->HasOwnProperty(v8Context, unscopablesSymbol));
+v8::Local<v8::Object> unscopeables;
+if (hasUnscopables)
haraken 2015/04/22 10:54:51 if (!v8CallBoolean(...)) ?
Jens Widell 2015/04/22 13:04:51 We can inline the HasOwnProperty() call here, yes.
Jens Widell 2015/04/22 17:15:13 Done.
+ unscopeables = prototypeObject->Get(v8Context, unscopablesSymbol).ToLocalChecked();
+else
+ unscopeables = v8::Object::New(isolate);
+{% else %}
+v8::Local<v8::Object> unscopeables(v8::Object::New(isolate));
+{% endif %}
+{% for name in unscopeables %}
+unscopeables->ForceSet(v8Context, v8AtomicString(isolate, "{{name}}"), v8::True(isolate)).FromJust();
+{% endfor %}
+prototypeObject->ForceSet(v8Context, v8::Symbol::GetUnscopables(isolate), unscopeables).FromJust();
+{% endmacro %}
+
+
+{##############################################################################}
{% block to_active_dom_object %}
{% if is_active_dom_object %}
ActiveDOMObject* {{v8_class}}::toActiveDOMObject(v8::Local<v8::Object> wrapper)
@@ -1000,11 +1039,11 @@ void {{v8_class}}::derefObject(ScriptWrappable* scriptWrappable)
{% if has_partial_interface %}
InstallTemplateFunction {{v8_class}}::install{{v8_class}}TemplateFunction = (InstallTemplateFunction)&{{v8_class}}::install{{v8_class}}Template;
-void {{v8_class}}::updateWrapperTypeInfo(InstallTemplateFunction installTemplateFunction, InstallConditionallyEnabledMethodsFunction installConditionallyEnabledMethodsFunction)
+void {{v8_class}}::updateWrapperTypeInfo(InstallTemplateFunction installTemplateFunction, PreparePrototypeObjectFunction preparePrototypeObjectFunction)
{
{{v8_class}}::install{{v8_class}}TemplateFunction = installTemplateFunction;
- if (installConditionallyEnabledMethodsFunction)
- {{v8_class}}::wrapperTypeInfo.installConditionallyEnabledMethodsFunction = installConditionallyEnabledMethodsFunction;
+ if (preparePrototypeObjectFunction)
+ {{v8_class}}::wrapperTypeInfo.preparePrototypeObjectFunction = preparePrototypeObjectFunction;
}
{% for method in methods if method.overloads and method.overloads.has_partial_overloads %}

Powered by Google App Engine
This is Rietveld 408576698