| OLD | NEW |
| 1 {##############################################################################} | 1 {##############################################################################} |
| 2 {% macro generate_method(method, world_suffix) %} | 2 {% macro generate_method(method, world_suffix) %} |
| 3 {% filter conditional(method.conditional_string) %} | 3 {% filter conditional(method.conditional_string) %} |
| 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) | 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) |
| 5 { | 5 { |
| 6 {% if method.is_raises_exception or method.is_check_security_for_frame or | 6 {% if method.is_raises_exception or method.is_check_security_for_frame or |
| 7 method.name in ['addEventListener', 'removeEventListener'] %} | 7 method.name in ['addEventListener', 'removeEventListener'] %} |
| 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
| 9 {% endif %} | 9 {% endif %} |
| 10 {% if method.name in ['addEventListener', 'removeEventListener'] %} | 10 {% if method.name in ['addEventListener', 'removeEventListener'] %} |
| 11 {{add_remove_event_listener_method(method.name) | indent}} | 11 {{add_remove_event_listener_method(method.name) | indent}} |
| 12 {% else %} | 12 {% else %} |
| 13 {% if method.number_of_required_arguments %} | 13 {% if method.number_of_required_arguments %} |
| 14 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 14 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
| 15 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{
interface_name}}", ExceptionMessages::notEnoughArguments({{method.number_of_requ
ired_arguments}}, info.Length())), info.GetIsolate()); | 15 {{throw_type_error(method, |
| 16 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % |
| 17 method.number_of_required_arguments)}} |
| 16 return; | 18 return; |
| 17 } | 19 } |
| 18 {% endif %} | 20 {% endif %} |
| 19 {% if not method.is_static %} | 21 {% if not method.is_static %} |
| 20 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); | 22 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); |
| 21 {% endif %} | 23 {% endif %} |
| 22 {% if method.is_custom_element_callbacks %} | 24 {% if method.is_custom_element_callbacks %} |
| 23 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 25 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 24 {% endif %} | 26 {% endif %} |
| 25 {% if method.is_check_security_for_frame %} | 27 {% if method.is_check_security_for_frame %} |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 if (listener) { | 68 if (listener) { |
| 67 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN
ame, info[0]); | 69 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN
ame, info[0]); |
| 68 impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); | 70 impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); |
| 69 if (!impl->toNode()) | 71 if (!impl->toNode()) |
| 70 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event
ListenerCacheIndex, info.GetIsolate()); | 72 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event
ListenerCacheIndex, info.GetIsolate()); |
| 71 } | 73 } |
| 72 {% endmacro %} | 74 {% endmacro %} |
| 73 | 75 |
| 74 | 76 |
| 75 {######################################} | 77 {######################################} |
| 76 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} | |
| 77 {% if method.is_call_with_script_state %} | |
| 78 ScriptState* currentState = ScriptState::current(); | |
| 79 if (!currentState) | |
| 80 return; | |
| 81 ScriptState& state = *currentState; | |
| 82 {% endif %} | |
| 83 {% if method.is_call_with_execution_context %} | |
| 84 ExecutionContext* scriptContext = getExecutionContext(); | |
| 85 {% endif %} | |
| 86 {% if method.is_call_with_script_arguments %} | |
| 87 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); | |
| 88 {% endif %} | |
| 89 {% if method.idl_type == 'void' %} | |
| 90 {{cpp_value}}; | |
| 91 {% elif method.is_call_with_script_state %} | |
| 92 {# FIXME: consider always using a local variable #} | |
| 93 {{method.cpp_type}} result = {{cpp_value}}; | |
| 94 {% endif %} | |
| 95 {% if method.is_raises_exception %} | |
| 96 if (exceptionState.throwIfNeeded()) | |
| 97 return; | |
| 98 {% endif %} | |
| 99 {% if method.is_call_with_script_state %} | |
| 100 if (state.hadException()) { | |
| 101 v8::Local<v8::Value> exception = state.exception(); | |
| 102 state.clearException(); | |
| 103 throwError(exception, info.GetIsolate()); | |
| 104 return; | |
| 105 } | |
| 106 {% endif %} | |
| 107 {% if v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for void
#} | |
| 108 {% endmacro %} | |
| 109 | |
| 110 | |
| 111 {######################################} | |
| 112 {% macro generate_argument(method, argument) %} | 78 {% macro generate_argument(method, argument) %} |
| 113 {% macro throw_type_error(error_message) %} | |
| 114 {% if method.is_constructor %} | |
| 115 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", "{{err
or_message}}"), info.GetIsolate()); | |
| 116 {%- else %} | |
| 117 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", "{{error_message}}"), info.GetIsolate()); | |
| 118 {%- endif %} | |
| 119 {% endmacro %} | |
| 120 {% if argument.is_optional and not argument.has_default and | 79 {% if argument.is_optional and not argument.has_default and |
| 121 argument.idl_type != 'Dictionary' %} | 80 argument.idl_type != 'Dictionary' %} |
| 122 {# Optional arguments without a default value generate an early call with | 81 {# Optional arguments without a default value generate an early call with |
| 123 fewer arguments if they are omitted. | 82 fewer arguments if they are omitted. |
| 124 Optional Dictionary arguments default to empty dictionary. #} | 83 Optional Dictionary arguments default to empty dictionary. #} |
| 125 if (UNLIKELY(info.Length() <= {{argument.index}})) { | 84 if (UNLIKELY(info.Length() <= {{argument.index}})) { |
| 126 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} | 85 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} |
| 127 return; | 86 return; |
| 128 } | 87 } |
| 129 {% endif %} | 88 {% endif %} |
| 130 {% if method.is_strict_type_checking and argument.is_wrapper_type %} | 89 {% if method.is_strict_type_checking and argument.is_wrapper_type %} |
| 131 {# Type checking for wrapper interface types (if interface not implemented, | 90 {# Type checking for wrapper interface types (if interface not implemented, |
| 132 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} | 91 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} |
| 133 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind
ex}}]) && !V8{{argument.idl_type}}::hasInstance(info[{{argument.index}}], info.G
etIsolate(), worldType(info.GetIsolate()))) { | 92 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind
ex}}]) && !V8{{argument.idl_type}}::hasInstance(info[{{argument.index}}], info.G
etIsolate(), worldType(info.GetIsolate()))) { |
| 134 {{throw_type_error("parameter %s is not of type '%s'." % | 93 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
| 135 (argument.index + 1, argument.idl_type))}} | 94 (argument.index + 1, argument.idl_type))}} |
| 136 return; | 95 return; |
| 137 } | 96 } |
| 138 {% endif %} | 97 {% endif %} |
| 139 {% if argument.is_clamp %} | 98 {% if argument.is_clamp %} |
| 140 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} | 99 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
| 141 {{argument.cpp_type}} {{argument.name}} = 0; | 100 {{argument.cpp_type}} {{argument.name}} = 0; |
| 142 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]->
NumberValue()); | 101 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]->
NumberValue()); |
| 143 if (!std::isnan({{argument.name}}NativeValue)) | 102 if (!std::isnan({{argument.name}}NativeValue)) |
| 144 {# IDL type is used for clamping, for the right bounds, since different | 103 {# IDL type is used for clamping, for the right bounds, since different |
| 145 IDL integer types have same internal C++ type (int or unsigned) #} | 104 IDL integer types have same internal C++ type (int or unsigned) #} |
| 146 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa
lue); | 105 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa
lue); |
| 147 {% elif argument.idl_type == 'SerializedScriptValue' %} | 106 {% elif argument.idl_type == 'SerializedScriptValue' %} |
| 148 bool {{argument.name}}DidThrow = false; | 107 {% set did_throw = argument.name + 'DidThrow' %} |
| 149 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a
rgument.index}}], 0, 0, {{argument.name}}DidThrow, info.GetIsolate()); | 108 bool {{did_throw}} = false; |
| 150 if ({{argument.name}}DidThrow) | 109 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a
rgument.index}}], 0, 0, {{did_throw}}, info.GetIsolate()); |
| 110 if ({{did_throw}}) |
| 151 return; | 111 return; |
| 152 {% elif argument.is_variadic_wrapper_type %} | 112 {% elif argument.is_variadic_wrapper_type %} |
| 153 Vector<{{argument.cpp_type}} > {{argument.name}}; | 113 Vector<{{argument.cpp_type}} > {{argument.name}}; |
| 154 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 114 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
| 155 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate(), worldT
ype(info.GetIsolate()))) { | 115 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate(), worldT
ype(info.GetIsolate()))) { |
| 156 {{throw_type_error("parameter %s is not of type '%s'." % | 116 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
| 157 (argument.index + 1, argument.idl_type))}} | 117 (argument.index + 1, argument.idl_type))}} |
| 158 return; | 118 return; |
| 159 } | 119 } |
| 160 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob
ject>::Cast(info[i]))); | 120 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob
ject>::Cast(info[i]))); |
| 161 } | 121 } |
| 162 {% else %} | 122 {% else %} |
| 163 {{argument.v8_value_to_local_cpp_value}}; | 123 {{argument.v8_value_to_local_cpp_value}}; |
| 164 {% endif %} | 124 {% endif %} |
| 165 {% if argument.enum_validation_expression %} | 125 {% if argument.enum_validation_expression %} |
| 166 {# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums
#} | 126 {# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums
#} |
| 167 String string = {{argument.name}}; | 127 String string = {{argument.name}}; |
| 168 if (!({{argument.enum_validation_expression}})) { | 128 if (!({{argument.enum_validation_expression}})) { |
| 169 {{throw_type_error("parameter %s ('\" + string + \"') is not a valid enum va
lue." % (argument.index + 1))}} | 129 {{throw_type_error(method, |
| 130 '"parameter %s (\'" + string + "\') is not a valid enum value."' % |
| 131 (argument.index + 1))}} |
| 170 return; | 132 return; |
| 171 } | 133 } |
| 172 {% endif %} | 134 {% endif %} |
| 173 {% if argument.idl_type in ['Dictionary', 'Promise'] %} | 135 {% if argument.idl_type in ['Dictionary', 'Promise'] %} |
| 174 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { | 136 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { |
| 175 {{throw_type_error("parameter %s ('%s') is not an object." % | 137 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % |
| 176 (argument.index + 1, argument.name))}} | 138 (argument.index + 1, argument.name))}} |
| 177 return; | 139 return; |
| 178 } | 140 } |
| 179 {% endif %} | 141 {% endif %} |
| 180 {% endmacro %} | 142 {% endmacro %} |
| 181 | 143 |
| 182 | 144 |
| 145 {######################################} |
| 146 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} |
| 147 {% if method.is_call_with_script_state %} |
| 148 ScriptState* currentState = ScriptState::current(); |
| 149 if (!currentState) |
| 150 return; |
| 151 ScriptState& state = *currentState; |
| 152 {% endif %} |
| 153 {% if method.is_call_with_execution_context %} |
| 154 ExecutionContext* scriptContext = getExecutionContext(); |
| 155 {% endif %} |
| 156 {% if method.is_call_with_script_arguments %} |
| 157 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); |
| 158 {% endif %} |
| 159 {% if method.idl_type == 'void' %} |
| 160 {{cpp_value}}; |
| 161 {% elif method.is_call_with_script_state %} |
| 162 {# FIXME: consider always using a local variable #} |
| 163 {{method.cpp_type}} result = {{cpp_value}}; |
| 164 {% endif %} |
| 165 {% if method.is_raises_exception %} |
| 166 if (exceptionState.throwIfNeeded()) |
| 167 return; |
| 168 {% endif %} |
| 169 {% if method.is_call_with_script_state %} |
| 170 if (state.hadException()) { |
| 171 v8::Local<v8::Value> exception = state.exception(); |
| 172 state.clearException(); |
| 173 throwError(exception, info.GetIsolate()); |
| 174 return; |
| 175 } |
| 176 {% endif %} |
| 177 {% if v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for void
#} |
| 178 {% endmacro %} |
| 179 |
| 180 |
| 181 {######################################} |
| 182 {% macro throw_type_error(method, error_message) %} |
| 183 {% if method.is_constructor %} |
| 184 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro
r_message}}), info.GetIsolate()); |
| 185 {%- else %} |
| 186 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", {{error_message}}), info.GetIsolate()); |
| 187 {%- endif %} |
| 188 {% endmacro %} |
| 189 |
| 190 |
| 183 {##############################################################################} | 191 {##############################################################################} |
| 184 {% macro overload_resolution_method(overloads, world_suffix) %} | 192 {% macro overload_resolution_method(overloads, world_suffix) %} |
| 185 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 193 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
| 186 { | 194 { |
| 187 {% for method in overloads.methods %} | 195 {% for method in overloads.methods %} |
| 188 if ({{method.overload_resolution_expression}}) { | 196 if ({{method.overload_resolution_expression}}) { |
| 189 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); | 197 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); |
| 190 return; | 198 return; |
| 191 } | 199 } |
| 192 {% endfor %} | 200 {% endfor %} |
| 193 {% if overloads.minimum_number_of_required_arguments %} | 201 {% if overloads.minimum_number_of_required_arguments %} |
| 194 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads
.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 202 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads
.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
| 195 if (UNLIKELY(info.Length() < {{overloads.minimum_number_of_required_argument
s}})) { | 203 if (UNLIKELY(info.Length() < {{overloads.minimum_number_of_required_argument
s}})) { |
| 196 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov
erloads.minimum_number_of_required_arguments}}, info.Length())); | 204 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov
erloads.minimum_number_of_required_arguments}}, info.Length())); |
| 197 exceptionState.throwIfNeeded(); | 205 exceptionState.throwIfNeeded(); |
| 198 return; | 206 return; |
| 199 } | 207 } |
| 200 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); | 208 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); |
| 201 exceptionState.throwIfNeeded(); | 209 exceptionState.throwIfNeeded(); |
| 202 {% else %} | 210 {% else %} |
| 203 throwTypeError(ExceptionMessages::failedToExecute("{{overloads.name}}", "{{i
nterface_name}}", "No function was found that matched the signature provided."),
info.GetIsolate()); | 211 {{throw_type_error(overloads, '"No function was found that matched the signa
ture provided."')}} |
| 204 {% endif %} | 212 {% endif %} |
| 205 } | 213 } |
| 206 {% endmacro %} | 214 {% endmacro %} |
| 207 | 215 |
| 208 | 216 |
| 209 {##############################################################################} | 217 {##############################################################################} |
| 210 {% macro method_callback(method, world_suffix) %} | 218 {% macro method_callback(method, world_suffix) %} |
| 211 {% filter conditional(method.conditional_string) %} | 219 {% filter conditional(method.conditional_string) %} |
| 212 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) | 220 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) |
| 213 { | 221 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 v8SetReturnValue(info, privateTemplate->GetFunction()); | 282 v8SetReturnValue(info, privateTemplate->GetFunction()); |
| 275 } | 283 } |
| 276 | 284 |
| 277 static void {{method.name}}OriginSafeMethodGetterCallback{{world_suffix}}(v8::Lo
cal<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) | 285 static void {{method.name}}OriginSafeMethodGetterCallback{{world_suffix}}(v8::Lo
cal<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 278 { | 286 { |
| 279 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter"); | 287 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter"); |
| 280 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix
}}(info); | 288 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix
}}(info); |
| 281 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); | 289 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); |
| 282 } | 290 } |
| 283 {% endmacro %} | 291 {% endmacro %} |
| 292 |
| 293 |
| 294 {##############################################################################} |
| 295 {% macro constructor_callback(constructor) %} |
| 296 static void constructor{{constructor.overload_index}}(const v8::FunctionCallback
Info<v8::Value>& info) |
| 297 { |
| 298 {% if interface_length and not constructor.overload_index %} |
| 299 {# FIXME: remove this UNLIKELY: constructors are heavy, so no difference. #} |
| 300 if (UNLIKELY(info.Length() < {{interface_length}})) { |
| 301 {{throw_type_error({'name': 'Constructor'}, |
| 302 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % |
| 303 interface_length)}} |
| 304 return; |
| 305 } |
| 306 {% endif %} |
| 307 {% if is_constructor_raises_exception %} |
| 308 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), info.GetIsolate()); |
| 309 {% endif %} |
| 310 {% for argument in constructor.arguments %} |
| 311 {{generate_argument(constructor, argument) | indent}} |
| 312 {% endfor %} |
| 313 {% if is_constructor_call_with_execution_context %} |
| 314 ExecutionContext* context = getExecutionContext(); |
| 315 {% endif %} |
| 316 {% if is_constructor_call_with_document %} |
| 317 Document& document = *toDocument(getExecutionContext()); |
| 318 {% endif %} |
| 319 RefPtr<{{cpp_class}}> impl = {{cpp_class}}::create({{constructor.argument_li
st | join(', ')}}); |
| 320 v8::Handle<v8::Object> wrapper = info.Holder(); |
| 321 {% if is_constructor_raises_exception %} |
| 322 if (exceptionState.throwIfNeeded()) |
| 323 return; |
| 324 {% endif %} |
| 325 |
| 326 {# FIXME: Should probably be Independent unless [ActiveDOMObject] |
| 327 or [DependentLifetime]. #} |
| 328 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dep
endent); |
| 329 v8SetReturnValue(info, wrapper); |
| 330 } |
| 331 {% endmacro %} |
| OLD | NEW |