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

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

Issue 2640123006: Use the current context as the creation context for cross-origin objects. (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/templates/attributes.cpp.tmpl
diff --git a/third_party/WebKit/Source/bindings/templates/attributes.cpp.tmpl b/third_party/WebKit/Source/bindings/templates/attributes.cpp.tmpl
index 7550a07909499b173d56cb0f3785aa515d5d03f8..971a916947919535dfc217e0662db28dc7d64b00 100644
--- a/third_party/WebKit/Source/bindings/templates/attributes.cpp.tmpl
+++ b/third_party/WebKit/Source/bindings/templates/attributes.cpp.tmpl
@@ -2,6 +2,46 @@
{##############################################################################}
{% macro attribute_getter(attribute, world_suffix) %}
+{% if attribute.has_cross_origin_getter %}
+static void {{attribute.name}}CrossOriginAttributeGetter(
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> holder = info.Holder();
+ {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
+
+ {% if attribute.cpp_value_original %}
+ {{attribute.cpp_type}} {{attribute.cpp_value}}({{attribute.cpp_value_original}});
+ {% endif %}
+
+ {% if attribute.is_keep_alive_for_gc %}
+ // Keep the wrapper object for the return value alive as long as |this|
+ // object is alive in order to save creation time of the wrapper object.
+ if ({{attribute.cpp_value}} && DOMDataStore::setReturnValue(info.GetReturnValue(), {{attribute.cpp_value}}))
+ return;
+
+ // https://whatwg.org/C/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
+ //
+ // If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous
+ // built-in function, created in the current Realm Record, that performs the
+ // same steps as the getter of the IDL attribute P on object O.
+ //
+ // However, the spec doesn't say exactly how this would work. The cross-origin
+ // |holder| object may not have a creation context associated with it. The
+ // current discussion on https://github.com/whatwg/html/issues/2273 suggests
+ // that crossOriginGet should return an origin-appropriate wrapper for Location
+ // associated with the current Realm record.
+ //
+ // This attempts to follow that suggestion by using the current context as the
+ // creation context rather than the creation context of |holder|.
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Local<v8::Value> v8Value(ToV8({{attribute.cpp_value}}, isolate->GetCurrentContext()->Global(), isolate));
+ const char kKeepAliveKey[] = "KeepAlive#{{interface_name}}#{{attribute.name}}";
+ V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), holder, v8AtomicString(info.GetIsolate(), StringView(kKeepAliveKey, sizeof kKeepAliveKey)), v8Value);
+ {% endif %}
+
+ {{attribute.v8_set_return_value}};
+}
+{% endif %}
+
static void {{attribute.name}}AttributeGetter{{world_suffix}}(
{%- if attribute.is_data_type_property %}
const v8::PropertyCallbackInfo<v8::Value>& info

Powered by Google App Engine
This is Rietveld 408576698