18abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){##############################################################################}
2bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% macro attribute_getter(attribute, world_suffix) %}
31e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){% filter conditional(attribute.conditional_string) %}
451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{attribute.name}}AttributeGetter{{world_suffix}}(
551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- if attribute.is_expose_js_accessors %}
651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)const v8::FunctionCallbackInfo<v8::Value>& info
751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- else %}
851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)const v8::PropertyCallbackInfo<v8::Value>& info
951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- endif %})
10c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){
11197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {% if attribute.is_reflect and not attribute.is_url
12197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch          and attribute.idl_type == 'DOMString' and is_node
13197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch          and not attribute.is_implemented_in_private_script %}
1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% set cpp_class, v8_class = 'Element', 'V8Element' %}
1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% endif %}
1607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {# holder #}
17197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {% if not attribute.is_static %}
1807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    v8::Handle<v8::Object> holder = info.Holder();
1907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {% endif %}
2007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {# impl #}
2107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {% if attribute.cached_attribute_validation_method %}
2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{attribute.name}}");
237242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
2443e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    if (!impl->{{attribute.cached_attribute_validation_method}}()) {
2507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        v8::Handle<v8::Value> v8Value = V8HiddenValue::getHiddenValue(info.GetIsolate(), holder, propertyName);
2607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        if (!v8Value.IsEmpty()) {
2707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            v8SetReturnValue(info, v8Value);
281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return;
291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        }
301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
3107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {% elif not attribute.is_static %}
327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %}
3543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    if (!impl->document())
3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% endif %}
3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {# Local variables #}
3951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {% if attribute.is_call_with_execution_context %}
405d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
42f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    {% if attribute.is_call_with_script_state %}
43d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    ScriptState* scriptState = ScriptState::current(info.GetIsolate());
446f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    {% endif %}
45a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    {% if attribute.is_check_security_for_node or
46a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)          attribute.is_getter_raises_exception %}
4707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.name}}", "{{interface_name}}", holder, info.GetIsolate());
48a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    {% endif %}
49197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {% if attribute.is_explicit_nullable %}
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    bool isNull = false;
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% endif %}
52197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {% if attribute.is_implemented_in_private_script %}
53197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{attribute.cpp_type}} result{{attribute.cpp_type_initializer}};
54197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!{{attribute.cpp_value_original}})
55197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return;
56197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {% elif attribute.cpp_value_original %}
57197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{attribute.cpp_type}} {{attribute.cpp_value}}({{attribute.cpp_value_original}});
5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% endif %}
5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {# Checks #}
6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if attribute.is_getter_raises_exception %}
6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (UNLIKELY(exceptionState.throwIfNeeded()))
6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% endif %}
641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% if attribute.is_check_security_for_node %}
6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), {{attribute.cpp_value}}, exceptionState)) {
661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        v8SetReturnValueNull(info);
6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        exceptionState.throwIfNeeded();
681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return;
691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if attribute.reflect_only %}
7209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {{release_only_check(attribute.reflect_only, attribute.reflect_missing,
73197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                         attribute.reflect_invalid, attribute.reflect_empty,
74197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                         attribute.cpp_value)
7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)      | indent}}
761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
77197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {% if attribute.is_explicit_nullable %}
781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    if (isNull) {
791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        v8SetReturnValueNull(info);
801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return;
811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% if attribute.cached_attribute_validation_method %}
84d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, propertyName, {{attribute.cpp_value_to_v8_value}});
851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {# v8SetReturnValue #}
871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% if attribute.is_keep_alive_for_gc %}
88e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if ({{attribute.cpp_value}} && DOMDataStore::setReturnValueFromWrapper{{world_suffix}}<V8{{attribute.idl_type}}>(info.GetReturnValue(), {{attribute.cpp_value}}.get()))
89c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        return;
90197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    v8::Handle<v8::Value> wrapper = toV8({{attribute.cpp_value}}.get(), holder, info.GetIsolate());
91c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    if (!wrapper.IsEmpty()) {
9207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, v8AtomicString(info.GetIsolate(), "{{attribute.name}}"), wrapper);
93bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        {{attribute.v8_set_return_value}};
94c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    }
9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% elif world_suffix %}
9609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {{attribute.v8_set_return_value_for_main_world}};
971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% else %}
98bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {{attribute.v8_set_return_value}};
991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
100c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)}
1011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){% endfilter %}
102c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){% endmacro %}
103c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)
10409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){######################################}
10509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% macro release_only_check(reflect_only_values, reflect_missing,
106197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                            reflect_invalid, reflect_empty, cpp_value) %}
10709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){# Attribute is limited to only known values: check that the attribute value is
10809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)   one of those. If not, set it to the empty string.
10909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)   http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known-values #}
11009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% if reflect_empty %}
111197021e6b966cfb06891637935ef33fff06433d1Ben Murdochif ({{cpp_value}}.isNull()) {
11209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% if reflect_missing %}
113197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{cpp_value}} = "{{reflect_missing}}";
11409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% else %}
11509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ;
11609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% endif %}
117197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch} else if ({{cpp_value}}.isEmpty()) {
118197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{cpp_value}} = "{{reflect_empty}}";
11909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% else %}
120197021e6b966cfb06891637935ef33fff06433d1Ben Murdochif ({{cpp_value}}.isEmpty()) {
12109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){# FIXME: should use [ReflectEmpty] instead; need to change IDL files #}
12209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% if reflect_missing %}
123197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{cpp_value}} = "{{reflect_missing}}";
12409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% else %}
12509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ;
12609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% endif %}
12709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% endif %}
12809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% for value in reflect_only_values %}
129197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch} else if (equalIgnoringCase({{cpp_value}}, "{{value}}")) {
130197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{cpp_value}} = "{{value}}";
13109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% endfor %}
13209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} else {
133197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{cpp_value}} = "{{reflect_invalid}}";
13409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
13509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){% endmacro %}
13609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
137c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)
138c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){##############################################################################}
139bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% macro attribute_getter_callback(attribute, world_suffix) %}
1401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){% filter conditional(attribute.conditional_string) %}
14151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{attribute.name}}AttributeGetterCallback{{world_suffix}}(
14251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- if attribute.is_expose_js_accessors %}
14351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)const v8::FunctionCallbackInfo<v8::Value>& info
14451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- else %}
14551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info
14651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- endif %})
147c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){
148197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
1491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% if attribute.deprecate_as %}
150d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
1511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
1521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% if attribute.measure_as %}
153d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.measure_as}});
1541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
155bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if world_suffix in attribute.activity_logging_world_list_for_getter %}
1565d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    ScriptState* scriptState = ScriptState::from(info.GetIsolate()->GetCurrentContext());
1575d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    V8PerContextData* contextData = scriptState->perContextData();
1585d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    {% if attribute.activity_logging_world_check %}
1595d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (scriptState->world().isIsolatedWorld() && contextData && contextData->activityLogger())
1605d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    {% else %}
161f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (contextData && contextData->activityLogger())
1625d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    {% endif %}
163f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        contextData->activityLogger()->logGetter("{{interface_name}}.{{attribute.name}}");
1641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
165bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.has_custom_getter %}
166a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    {{v8_class}}::{{attribute.name}}AttributeGetterCustom(info);
1671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% else %}
168a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    {{cpp_class}}V8Internal::{{attribute.name}}AttributeGetter{{world_suffix}}(info);
169bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
170197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
171bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
172bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% endfilter %}
173bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% endmacro %}
174bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
175bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
176bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){##############################################################################}
177d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){% macro constructor_getter_callback(attribute, world_suffix) %}
178d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){% filter conditional(attribute.conditional_string) %}
179d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)static void {{attribute.name}}ConstructorGetterCallback{{world_suffix}}(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
180d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
181197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
182d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {% if attribute.deprecate_as %}
183d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
184d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {% endif %}
185d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {% if attribute.measure_as %}
186d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.measure_as}});
187d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {% endif %}
188d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {{cpp_class}}V8Internal::{{cpp_class}}ConstructorGetter{{world_suffix}}(property, info);
189197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
190d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
191d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){% endfilter %}
192d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){% endmacro %}
193d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
194d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
195d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){##############################################################################}
196bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% macro attribute_setter(attribute, world_suffix) %}
197bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% filter conditional(attribute.conditional_string) %}
19851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{attribute.name}}AttributeSetter{{world_suffix}}(
19951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- if attribute.is_expose_js_accessors %}
20007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochv8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info
20151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- else %}
20207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochv8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
20351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- endif %})
204bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
205197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {% if attribute.is_reflect and attribute.idl_type == 'DOMString'
206197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch          and is_node and not attribute.is_implemented_in_private_script %}
20709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% set cpp_class, v8_class = 'Element', 'V8Element' %}
20809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% endif %}
20907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {# Local variables #}
21007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {% if not attribute.is_static %}
21107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    v8::Handle<v8::Object> holder = info.Holder();
21207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {% endif %}
21309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if attribute.has_setter_exception_state %}
21407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.name}}", "{{interface_name}}", holder, info.GetIsolate());
215a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    {% endif %}
21607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {# Type checking #}
217f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    {% if attribute.has_type_checking_interface %}
218bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {# Type checking for interface types (if interface not implemented, throw
219bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)       TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
220a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    if ({% if attribute.is_nullable %}!isUndefinedOrNull(v8Value) && {% endif %}!V8{{attribute.idl_type}}::hasInstance(v8Value, info.GetIsolate())) {
221a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        exceptionState.throwTypeError("The provided value is not of type '{{attribute.idl_type}}'.");
222a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)        exceptionState.throwIfNeeded();
223bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        return;
224bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    }
225bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
22643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    {# impl #}
22709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if attribute.put_forwards %}
2287242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder);
2296f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    {{attribute.cpp_type}} impl = WTF::getPtr(proxyImpl->{{attribute.name}}());
23043e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    if (!impl)
23109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
23209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% elif not attribute.is_static %}
2337242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
234d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {% endif %}
235bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %}
23643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    if (!impl->document())
237bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        return;
238bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
239d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {# Convert JS value to C++ value #}
240bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.idl_type != 'EventHandler' %}
241bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {{attribute.v8_value_to_local_cpp_value}};
24209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% elif not is_node %}{# EventHandler hack #}
24307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    moveEventListenerToNewWrapper(holder, {{attribute.event_handler_getter_expression}}, v8Value, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate());
244bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
245323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    {# Type checking, possibly throw a TypeError, per:
246323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)       http://www.w3.org/TR/WebIDL/#es-type-mapping #}
247323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    {% if attribute.has_type_checking_unrestricted %}
248323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    {# Non-finite floating point values (NaN, +Infinity orInfinity), per:
249323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)       http://heycam.github.io/webidl/#es-float
250323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)       http://heycam.github.io/webidl/#es-double #}
251323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    if (!std::isfinite(cppValue)) {
252323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        exceptionState.throwTypeError("The provided {{attribute.idl_type}} value is non-finite.");
253323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        exceptionState.throwIfNeeded();
254323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        return;
255323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    }
256323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    {% elif attribute.enum_validation_expression %}
257323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    {# Setter ignores invalid enum values:
258323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)       http://www.w3.org/TR/WebIDL/#idl-enums #}
259bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    String string = cppValue;
260bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (!({{attribute.enum_validation_expression}}))
261bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        return;
262bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
263d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {# Pre-set context #}
26409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if attribute.is_custom_element_callbacks or
26509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)          (attribute.is_reflect and
26609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)           not(attribute.idl_type == 'DOMString' and is_node)) %}
26709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {# Skip on compact node DOMString getters #}
2687242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
269bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
27009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if attribute.is_call_with_execution_context or
27109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)          attribute.is_setter_call_with_execution_context %}
2725d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
273bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
274d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {# Set #}
275bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {{attribute.cpp_setter}};
276d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {# Post-set #}
277bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.is_setter_raises_exception %}
27851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    exceptionState.throwIfNeeded();
279bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
280bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.cached_attribute_validation_method %}
28107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    V8HiddenValue::deleteHiddenValue(info.GetIsolate(), holder, v8AtomicString(info.GetIsolate(), "{{attribute.name}}")); // Invalidate the cached value.
282bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
283bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
284bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% endfilter %}
285bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% endmacro %}
286bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
287bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
288bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){##############################################################################}
289bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% macro attribute_setter_callback(attribute, world_suffix) %}
290bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){% filter conditional(attribute.conditional_string) %}
29151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}(
29251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- if attribute.is_expose_js_accessors %}
29351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)const v8::FunctionCallbackInfo<v8::Value>& info
29451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- else %}
29507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochv8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
29651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){%- endif %})
297bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
29851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {% if attribute.is_expose_js_accessors %}
29907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    v8::Local<v8::Value> v8Value = info[0];
30051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {% endif %}
301197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
302bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.deprecate_as %}
303d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
304bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
305bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.measure_as %}
306d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.measure_as}});
307bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
308bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if world_suffix in attribute.activity_logging_world_list_for_setter %}
3095d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    ScriptState* scriptState = ScriptState::from(info.GetIsolate()->GetCurrentContext());
3105d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    V8PerContextData* contextData = scriptState->perContextData();
3115d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    {% if attribute.activity_logging_world_check %}
3125d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (scriptState->world().isIsolatedWorld() && contextData && contextData->activityLogger()) {
3135d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    {% else %}
314f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (contextData && contextData->activityLogger()) {
3155d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    {% endif %}
316f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        contextData->activityLogger()->logSetter("{{interface_name}}.{{attribute.name}}", v8Value);
317bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    }
318bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
31909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {% if attribute.is_custom_element_callbacks or attribute.is_reflect %}
3207242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
321bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% endif %}
322bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% if attribute.has_custom_setter %}
32307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {{v8_class}}::{{attribute.name}}AttributeSetterCustom(v8Value, info);
324bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {% else %}
32507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(v8Value, info);
3261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {% endif %}
327197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
328c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)}
3291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){% endfilter %}
330c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){% endmacro %}
331197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
332197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
333197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{##############################################################################}
334197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{% macro attribute_getter_implemented_in_private_script(attribute) %}
335e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.cpp_type}}* result)
336197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{
337197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!frame)
338197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return false;
339c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    v8::HandleScope handleScope(toIsolate(frame));
340c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    ScriptForbiddenScope::AllowUserAgentScript script;
3417242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    v8::Handle<v8::Context> contextInPrivateScript = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
3427242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (contextInPrivateScript.IsEmpty())
343197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return false;
3447242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ScriptState* scriptState = ScriptState::from(contextInPrivateScript);
3457242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
346197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!scriptState->executionContext())
347197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return false;
348197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
349197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ScriptState::Scope scope(scriptState);
350197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    v8::Handle<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global(), scriptState->isolate());
351197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
352197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.name}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
3537242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holder);
3547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (v8Value.IsEmpty())
355197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return false;
356197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {{attribute.private_script_v8_value_to_local_cpp_value}};
357197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    RELEASE_ASSERT(!exceptionState.hadException());
358197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    *result = cppValue;
359197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    return true;
360197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch}
361197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{% endmacro %}
362197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
363197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
364197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{% macro attribute_setter_implemented_in_private_script(attribute) %}
365e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.argument_cpp_type}} cppValue)
366197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{
367197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!frame)
368197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return false;
369c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    v8::HandleScope handleScope(toIsolate(frame));
370c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    ScriptForbiddenScope::AllowUserAgentScript script;
3717242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    v8::Handle<v8::Context> contextInPrivateScript = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
3727242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (contextInPrivateScript.IsEmpty())
373197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return false;
3747242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ScriptState* scriptState = ScriptState::from(contextInPrivateScript);
3757242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
376197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!scriptState->executionContext())
377197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return false;
378197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
379197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ScriptState::Scope scope(scriptState);
380197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    v8::Handle<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global(), scriptState->isolate());
381197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
382197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.name}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
3837242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    return PrivateScriptRunner::runDOMAttributeSetter(scriptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_script_cpp_value_to_v8_value}});
384197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch}
385197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{% endmacro %}
3867242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3877242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3887242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{##############################################################################}
3897242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% macro attribute_configuration(attribute) %}
3907242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set getter_callback =
3917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       '%sV8Internal::%sAttributeGetterCallback' %
3927242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            (cpp_class, attribute.name)
3937242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       if not attribute.constructor_type else
3947242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       ('%sV8Internal::%sConstructorGetterCallback' %
3957242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            (cpp_class, attribute.name)
3967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if attribute.needs_constructor_getter_callback else
3977242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       '{0}V8Internal::{0}ConstructorGetter'.format(cpp_class)) %}
3987242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set getter_callback_for_main_world =
3997242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       '%sV8Internal::%sAttributeGetterCallbackForMainWorld' %
4007242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            (cpp_class, attribute.name)
4017242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       if attribute.is_per_world_bindings else '0' %}
4027242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set setter_callback = attribute.setter_callback %}
4037242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set setter_callback_for_main_world =
4047242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       '%sV8Internal::%sAttributeSetterCallbackForMainWorld' %
4057242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci           (cpp_class, attribute.name)
4067242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       if attribute.is_per_world_bindings and
4077242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci          (not attribute.is_read_only or attribute.put_forwards) else '0' %}
4087242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set wrapper_type_info =
4097242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' %
4107242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            attribute.constructor_type
4117242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if attribute.constructor_type else '0' %}
4127242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set access_control = 'static_cast<v8::AccessControl>(%s)' %
4137242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                        ' | '.join(attribute.access_control_list) %}
4147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' %
4157242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                            ' | '.join(attribute.property_attributes) %}
4167242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivateScript' if attribute.only_exposed_to_private_script else 'V8DOMConfiguration::ExposedToAllScripts' %}
4177242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set on_prototype = 'V8DOMConfiguration::OnPrototype'
4187242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       if interface_name == 'Window' and attribute.idl_type == 'EventHandler'
4197242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       else 'V8DOMConfiguration::OnInstance' %}
4207242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set attribute_configuration_list = [
4217242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       '"%s"' % attribute.name,
4227242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       getter_callback,
4237242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       setter_callback,
4247242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       getter_callback_for_main_world,
4257242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       setter_callback_for_main_world,
4267242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       wrapper_type_info,
4277242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       access_control,
4287242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       property_attribute,
4297242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci       only_exposed_to_private_script,
4307242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci   ] %}
4317242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% if not attribute.is_expose_js_accessors %}
4327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% set attribute_configuration_list = attribute_configuration_list
4337242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                                    + [on_prototype] %}
4347242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{% endif %}
4357242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}}
4367242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{%- endmacro %}
437