1f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){##############################################################################} 251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% macro generate_method(method, world_suffix) %} 351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% filter conditional(method.conditional_string) %} 451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 5f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 6a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {% if method.is_raises_exception or method.is_check_security_for_frame or 7a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) method.name in ['addEventListener', 'removeEventListener'] %} 8a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 9a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {% endif %} 1051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if method.name in ['addEventListener', 'removeEventListener'] %} 1151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {{add_remove_event_listener_method(method.name) | indent}} 1251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% else %} 13f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) {% if method.number_of_required_arguments %} 1419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 15e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{throw_type_error(method, 16e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % 17e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) method.number_of_required_arguments)}} 18f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 19f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 20f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) {% endif %} 2151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if not method.is_static %} 22a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); 2351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 2451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if method.is_custom_element_callbacks %} 2551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; 2651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 2751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if method.is_check_security_for_frame %} 2851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState)) { 2951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) exceptionState.throwIfNeeded(); 3051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 3151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 3251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 3351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if method.is_check_security_for_node %} 3451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!BindingSecurity::shouldAllowAccessToNode(imp->{{method.name}}(exceptionState), exceptionState)) { 3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) v8SetReturnValueNull(info); 3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) exceptionState.throwIfNeeded(); 3751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 3951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 40f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) {% for argument in method.arguments %} 41e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{generate_argument(method, argument) | indent}} 42e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% endfor %} 4351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | indent}} 4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %}{# addEventListener, removeEventListener #} 4551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 4651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endfilter %} 4751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endmacro %} 4851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 4951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 5051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){######################################} 5151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% macro add_remove_event_listener_method(method_name) %} 5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){# Set template values for addEventListener vs. removeEventListener #} 5351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% set listener_lookup_type, listener, hidden_dependency_action = 5451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ('ListenerFindOrCreate', 'listener', 'createHiddenDependency') 5551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if method_name == 'addEventListener' else 5651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ('ListenerFindOnly', 'listener.get()', 'removeHiddenDependency') 5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)%} 58a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)EventTarget* impl = {{v8_class}}::toNative(info.Holder()); 5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)if (DOMWindow* window = impl->toDOMWindow()) { 6051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!BindingSecurity::shouldAllowAccessToFrame(window->frame(), exceptionState)) { 6151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) exceptionState.throwIfNeeded(); 6251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 6351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 6451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!window->document()) 6551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 6651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1], false, {{listener_lookup_type}}); 6851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)if (listener) { 6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventName, info[0]); 7051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); 7151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!impl->toNode()) 72a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::eventListenerCacheIndex, info.GetIsolate()); 7351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 7451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endmacro %} 7551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){######################################} 78e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% macro generate_argument(method, argument) %} 79e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% if argument.is_optional and not argument.has_default and 80e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) argument.idl_type != 'Dictionary' %} 81e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){# Optional arguments without a default value generate an early call with 82e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) fewer arguments if they are omitted. 83e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) Optional Dictionary arguments default to empty dictionary. #} 84e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)if (UNLIKELY(info.Length() <= {{argument.index}})) { 85e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}} 86e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 87e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)} 88e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endif %} 89e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% if method.is_strict_type_checking and argument.is_wrapper_type %} 90e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){# Type checking for wrapper interface types (if interface not implemented, 91e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} 92e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.index}}]) && !V8{{argument.idl_type}}::hasInstance(info[{{argument.index}}], info.GetIsolate(), worldType(info.GetIsolate()))) { 93e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 94e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) (argument.index + 1, argument.idl_type))}} 95e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 96e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)} 97e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endif %} 98e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% if argument.is_clamp %} 99e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} 100e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){{argument.cpp_type}} {{argument.name}} = 0; 101e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]->NumberValue()); 102e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)if (!std::isnan({{argument.name}}NativeValue)) 103e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {# IDL type is used for clamping, for the right bounds, since different 104e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) IDL integer types have same internal C++ type (int or unsigned) #} 105e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeValue); 106e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% elif argument.idl_type == 'SerializedScriptValue' %} 107e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% set did_throw = argument.name + 'DidThrow' %} 108e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)bool {{did_throw}} = false; 109e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0, {{did_throw}}, info.GetIsolate()); 110e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)if ({{did_throw}}) 111e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 112e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% elif argument.is_variadic_wrapper_type %} 113e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)Vector<{{argument.cpp_type}} > {{argument.name}}; 114e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)for (int i = {{argument.index}}; i < info.Length(); ++i) { 115e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate(), worldType(info.GetIsolate()))) { 116e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 117e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) (argument.index + 1, argument.idl_type))}} 118e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 119e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) } 120e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Object>::Cast(info[i]))); 121e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)} 122e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% else %} 123e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){{argument.v8_value_to_local_cpp_value}}; 124e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endif %} 125e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% if argument.enum_validation_expression %} 126e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} 127e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)String string = {{argument.name}}; 128e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)if (!({{argument.enum_validation_expression}})) { 129e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{throw_type_error(method, 130e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) '"parameter %s (\'" + string + "\') is not a valid enum value."' % 131e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) (argument.index + 1))}} 132e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 133e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)} 134e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endif %} 135e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% if argument.idl_type in ['Dictionary', 'Promise'] %} 136e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { 137e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % 138e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) (argument.index + 1, argument.name))}} 139e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 140e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)} 141e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endif %} 142e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endmacro %} 143e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 144e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 145e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){######################################} 14651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} 14751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% if method.is_call_with_script_state %} 14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)ScriptState* currentState = ScriptState::current(); 14951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)if (!currentState) 15051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 15151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)ScriptState& state = *currentState; 15251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endif %} 15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% if method.is_call_with_execution_context %} 15451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)ExecutionContext* scriptContext = getExecutionContext(); 15551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endif %} 15651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% if method.is_call_with_script_arguments %} 15751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.number_of_arguments}})); 15851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endif %} 15951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% if method.idl_type == 'void' %} 16051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){{cpp_value}}; 16151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% elif method.is_call_with_script_state %} 16251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){# FIXME: consider always using a local variable #} 16351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){{method.cpp_type}} result = {{cpp_value}}; 16451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endif %} 16551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% if method.is_raises_exception %} 16651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)if (exceptionState.throwIfNeeded()) 16751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 16851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endif %} 16951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% if method.is_call_with_script_state %} 17051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)if (state.hadException()) { 17151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) v8::Local<v8::Value> exception = state.exception(); 17251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) state.clearException(); 17351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) throwError(exception, info.GetIsolate()); 17451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 17551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 17651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endif %} 17751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% if v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for void #} 17851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endmacro %} 17951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 18051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 181e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){######################################} 182e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% macro throw_type_error(method, error_message) %} 183e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% if method.is_constructor %} 184e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}), info.GetIsolate()); 185e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){%- else %} 186e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{error_message}}), info.GetIsolate()); 187e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){%- endif %} 188e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endmacro %} 189e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 190e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 19151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){##############################################################################} 19251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% macro overload_resolution_method(overloads, world_suffix) %} 19351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 19451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 19551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% for method in overloads.methods %} 19651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if ({{method.overload_resolution_expression}}) { 19751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); 19851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 19951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 200f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) {% endfor %} 20151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if overloads.minimum_number_of_required_arguments %} 202e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 20351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (UNLIKELY(info.Length() < {{overloads.minimum_number_of_required_arguments}})) { 204e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{overloads.minimum_number_of_required_arguments}}, info.Length())); 205e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) exceptionState.throwIfNeeded(); 20651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 20751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 208e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) exceptionState.throwTypeError("No function was found that matched the signature provided."); 209e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) exceptionState.throwIfNeeded(); 210e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% else %} 211e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{throw_type_error(overloads, '"No function was found that matched the signature provided."')}} 21251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 213f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 214f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){% endmacro %} 215f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 216f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 217f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){##############################################################################} 21851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% macro method_callback(method, world_suffix) %} 21951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% filter conditional(method.conditional_string) %} 22051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 221f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 222f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); 22351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if method.measure_as %} 22451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) UseCounter::count(activeDOMWindow(), UseCounter::{{method.measure_as}}); 22551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 22651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if method.deprecate_as %} 22751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) UseCounter::countDeprecation(activeExecutionContext(), UseCounter::{{method.deprecate_as}}); 22851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 22951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if world_suffix in method.activity_logging_world_list %} 23051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) V8PerContextData* contextData = V8PerContextData::from(info.GetIsolate()->GetCurrentContext()); 23151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (contextData && contextData->activityLogger()) { 23251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {# FIXME: replace toVectorOfArguments with toNativeArguments(info, 0) 23351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) and delete toVectorOfArguments #} 23451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) Vector<v8::Handle<v8::Value> > loggerArgs = toNativeArguments<v8::Handle<v8::Value> >(info, 0); 23551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) contextData->activityLogger()->log("{{interface_name}}.{{method.name}}", info.Length(), loggerArgs.data(), "Method"); 23651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 23751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 23851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% if method.is_custom %} 239a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {{v8_class}}::{{method.name}}MethodCustom(info); 24051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% else %} 241a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {{cpp_class}}V8Internal::{{method.name}}Method{{world_suffix}}(info); 24251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {% endif %} 24351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 24451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 24551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endfilter %} 24651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% endmacro %} 24751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){##############################################################################} 25051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){% macro origin_safe_method_getter(method, world_suffix) %} 25151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::PropertyCallbackInfo<v8::Value>& info) 25251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 25351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {# FIXME: don't call GetIsolate() so often #} 25451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // This is only for getting a unique pointer which we can pass to privateTemplate. 25551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) static int privateTemplateUniqueKey; 25651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WrapperWorldType currentWorldType = worldType(info.GetIsolate()); 25751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 25851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) {# FIXME: 1 case of [DoNotCheckSignature] in Window.idl may differ #} 259a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) v8::Handle<v8::FunctionTemplate> privateTemplate = data->privateTemplate(currentWorldType, &privateTemplateUniqueKey, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_suffix}}, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8PerIsolateData::from(info.GetIsolate())->rawDOMTemplate(&{{v8_class}}::wrapperTypeInfo, currentWorldType)), {{method.number_of_required_or_variadic_arguments}}); 26051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 261a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain({{v8_class}}::domTemplate(info.GetIsolate(), currentWorldType)); 26251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (holder.IsEmpty()) { 26351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // This is only reachable via |object.__proto__.func|, in which case it 26451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // has already passed the same origin security check 26551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) v8SetReturnValue(info, privateTemplate->GetFunction()); 26651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 26751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 268a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {{cpp_class}}* imp = {{v8_class}}::toNative(holder); 26951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), DoNotReportSecurityError)) { 27051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) static int sharedTemplateUniqueKey; 271a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) v8::Handle<v8::FunctionTemplate> sharedTemplate = data->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_suffix}}, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8PerIsolateData::from(info.GetIsolate())->rawDOMTemplate(&{{v8_class}}::wrapperTypeInfo, currentWorldType)), {{method.number_of_required_or_variadic_arguments}}); 27251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) v8SetReturnValue(info, sharedTemplate->GetFunction()); 27351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 27451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 27551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 276a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8::String::NewFromUtf8(info.GetIsolate(), "{{method.name}}", v8::String::kInternalizedString)); 27751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!hiddenValue.IsEmpty()) { 27851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) v8SetReturnValue(info, hiddenValue); 27951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return; 28051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 28151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 28251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) v8SetReturnValue(info, privateTemplate->GetFunction()); 28351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 28451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 28551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void {{method.name}}OriginSafeMethodGetterCallback{{world_suffix}}(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 28651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 28751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter"); 288a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix}}(info); 289f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 290f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 291f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){% endmacro %} 292e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 293e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 294e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){##############################################################################} 295e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% macro generate_constructor(constructor) %} 296e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)static void constructor{{constructor.overload_index}}(const v8::FunctionCallbackInfo<v8::Value>& info) 297e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){ 298e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% if interface_length and not constructor.overload_index %} 299e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {# FIXME: remove this UNLIKELY: constructors are heavy, so no difference. #} 300e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if (UNLIKELY(info.Length() < {{interface_length}})) { 301e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{throw_type_error({'name': 'Constructor'}, 302e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % 303e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) interface_length)}} 304e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 305e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) } 306e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% endif %} 307e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% if is_constructor_raises_exception %} 308e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), info.GetIsolate()); 309e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% endif %} 310e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% for argument in constructor.arguments %} 311e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {{generate_argument(constructor, argument) | indent}} 312e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% endfor %} 313e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% if is_constructor_call_with_execution_context %} 314e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) ExecutionContext* context = getExecutionContext(); 315e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% endif %} 316e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% if is_constructor_call_with_document %} 317e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) Document& document = *toDocument(getExecutionContext()); 318e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% endif %} 319e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) RefPtr<{{cpp_class}}> impl = {{cpp_class}}::create({{constructor.argument_list | join(', ')}}); 320e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) v8::Handle<v8::Object> wrapper = info.Holder(); 321e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% if is_constructor_raises_exception %} 322e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if (exceptionState.throwIfNeeded()) 323e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 324e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% endif %} 325e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 326e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {# FIXME: Should probably be Independent unless [ActiveDOMObject] 327e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) or [DependentLifetime]. #} 328e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent); 329e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) v8SetReturnValue(info, wrapper); 330e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)} 331e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endmacro %} 332e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 333e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 334e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){##############################################################################} 335e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% macro named_constructor_callback(constructor) %} 336e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 337e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){ 338e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if (!info.IsConstructCall()) { 339e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) throwTypeError(ExceptionMessages::failedToConstruct("{{constructor.name}}", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate()); 340e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 341e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) } 342e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 343e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) { 344e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) v8SetReturnValue(info, info.Holder()); 345e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) return; 346e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) } 347e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 348e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) Document* document = currentDocument(); 349e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) ASSERT(document); 350e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 351e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp_class}} instance 352e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) // may end up being the only node in the map and get garbage-collected prematurely. 353e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) toV8(document, info.Holder(), info.GetIsolate()); 354e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 355e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {# FIXME: arguments #} 356e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) {% set argument_list = ['*document'] %} 357e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) RefPtr<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{argument_list | join(', ')}}); 358e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) v8::Handle<v8::Object> wrapper = info.Holder(); 359e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) 360e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent); 361e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) v8SetReturnValue(info, wrapper); 362e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles)} 363e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles){% endmacro %} 364