Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 {% from 'conversions.cpp' import v8_value_to_local_cpp_value %} | |
| 2 | |
| 3 | |
| 1 {##############################################################################} | 4 {##############################################################################} |
| 2 {% macro generate_method(method, world_suffix) %} | 5 {% macro generate_method(method, world_suffix) %} |
| 3 {% filter conditional(method.conditional_string) %} | 6 {% filter conditional(method.conditional_string) %} |
| 7 {% if method.returns_promise and method.has_exception_state %} | |
|
haraken
2015/02/24 12:44:57
Is it possible that method returns a promise but d
Jens Widell
2015/02/24 13:36:07
This is the case if the method can't raise excepti
| |
| 8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat e) | |
| 9 {% else %} | |
| 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) | 10 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 11 {% endif %} | |
| 5 { | 12 { |
| 6 {# Local variables #} | 13 {# Local variables #} |
| 7 {% if method.has_exception_state %} | 14 {% if method.has_exception_state and not method.returns_promise %} |
| 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 15 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
| 9 {% endif %} | 16 {% endif %} |
| 10 {# Overloaded methods have length checked during overload resolution #} | 17 {# Overloaded methods have length checked during overload resolution #} |
| 11 {% if method.number_of_required_arguments and not method.overload_index %} | 18 {% if method.number_of_required_arguments and not method.overload_index %} |
| 12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 19 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
| 13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}} | 20 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}} |
| 14 return; | |
| 15 } | 21 } |
| 16 {% endif %} | 22 {% endif %} |
| 17 {% if not method.is_static %} | 23 {% if not method.is_static %} |
| 18 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); | 24 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); |
| 19 {% endif %} | 25 {% endif %} |
| 20 {% if method.is_custom_element_callbacks %} | 26 {% if method.is_custom_element_callbacks %} |
| 21 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; | 27 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; |
| 22 {% endif %} | 28 {% endif %} |
| 23 {# Security checks #} | 29 {# Security checks #} |
| 24 {% if method.is_check_security_for_window %} | 30 {% if method.is_check_security_for_window %} |
| 25 if (LocalDOMWindow* window = impl->toDOMWindow()) { | 31 if (LocalDOMWindow* window = impl->toDOMWindow()) { |
| 26 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window ->frame(), exceptionState)) { | 32 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window ->frame(), exceptionState)) { |
| 27 {{throw_from_exception_state(method)}}; | 33 {{throw_from_exception_state(method) | indent(12)}} |
| 28 return; | |
| 29 } | 34 } |
| 30 if (!window->document()) | 35 if (!window->document()) |
| 31 return; | 36 return; |
| 32 } | 37 } |
| 33 {% elif method.is_check_security_for_frame %} | 38 {% elif method.is_check_security_for_frame %} |
| 34 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) { | 39 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) { |
| 35 {{throw_from_exception_state(method)}}; | 40 {{throw_from_exception_state(method) | indent(8)}} |
| 36 return; | |
| 37 } | 41 } |
| 38 {% endif %} | 42 {% endif %} |
| 39 {% if method.is_check_security_for_node %} | 43 {% if method.is_check_security_for_node %} |
| 40 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) { | 44 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) { |
| 41 v8SetReturnValueNull(info); | 45 v8SetReturnValueNull(info); |
| 42 {{throw_from_exception_state(method)}}; | 46 {{throw_from_exception_state(method) | indent(8)}} |
| 43 return; | |
| 44 } | 47 } |
| 45 {% endif %} | 48 {% endif %} |
| 46 {# Call method #} | 49 {# Call method #} |
| 47 {% if method.arguments %} | 50 {% if method.arguments %} |
| 48 {{generate_arguments(method, world_suffix) | indent}} | 51 {{generate_arguments(method, world_suffix) | indent}} |
| 49 {% endif %} | 52 {% endif %} |
| 50 {% if world_suffix %} | 53 {% if world_suffix %} |
| 51 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} | 54 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} |
| 52 {% else %} | 55 {% else %} |
| 53 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} | 56 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} |
| 54 {% endif %} | 57 {% endif %} |
| 55 } | 58 } |
| 59 {% if method.returns_promise and method.has_exception_state %} | |
| 60 | |
| 61 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) | |
| 62 { | |
| 63 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | |
| 64 {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promise(info, exceptionState); | |
| 65 if (exceptionState.hadException()) | |
| 66 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.G etIsolate())).v8Value()); | |
| 67 } | |
| 68 {% endif %} | |
| 56 {% endfilter %} | 69 {% endfilter %} |
| 57 {% endmacro %} | 70 {% endmacro %} |
| 58 | 71 |
| 59 | 72 |
| 60 {######################################} | 73 {######################################} |
| 61 {% macro generate_arguments(method, world_suffix) %} | 74 {% macro generate_arguments(method, world_suffix) %} |
| 62 {% for argument in method.arguments %} | 75 {% for argument in method.arguments %} |
| 63 {{generate_argument_var_declaration(argument)}}; | 76 {{generate_argument_var_declaration(argument)}}; |
| 64 {% endfor %} | 77 {% endfor %} |
| 65 { | 78 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 {% endif %}{# method.name #} | 132 {% endif %}{# method.name #} |
| 120 {% else %}{# argument.idl_type == 'EventListener' #} | 133 {% else %}{# argument.idl_type == 'EventListener' #} |
| 121 {# Callback functions must be functions: | 134 {# Callback functions must be functions: |
| 122 http://www.w3.org/TR/WebIDL/#es-callback-function #} | 135 http://www.w3.org/TR/WebIDL/#es-callback-function #} |
| 123 {% if argument.is_optional %} | 136 {% if argument.is_optional %} |
| 124 if (!isUndefinedOrNull(info[{{argument.index}}])) { | 137 if (!isUndefinedOrNull(info[{{argument.index}}])) { |
| 125 if (!info[{{argument.index}}]->IsFunction()) { | 138 if (!info[{{argument.index}}]->IsFunction()) { |
| 126 {{throw_type_error(method, | 139 {{throw_type_error(method, |
| 127 '"The callback provided as parameter %s is not a function."' % | 140 '"The callback provided as parameter %s is not a function."' % |
| 128 (argument.index + 1)) | indent(8)}} | 141 (argument.index + 1)) | indent(8)}} |
| 129 return; | |
| 130 } | 142 } |
| 131 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>: :Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); | 143 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>: :Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); |
| 132 } else { | 144 } else { |
| 133 {{argument.name}} = nullptr; | 145 {{argument.name}} = nullptr; |
| 134 } | 146 } |
| 135 {% else %}{# argument.is_optional #} | 147 {% else %}{# argument.is_optional #} |
| 136 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { | 148 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { |
| 137 {{throw_type_error(method, | 149 {{throw_type_error(method, |
| 138 '"The callback provided as parameter %s is not a function."' % | 150 '"The callback provided as parameter %s is not a function."' % |
| 139 (argument.index + 1)) | indent }} | 151 (argument.index + 1)) | indent}} |
| 140 return; | |
| 141 } | 152 } |
| 142 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); | 153 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); |
| 143 {% endif %}{# argument.is_optional #} | 154 {% endif %}{# argument.is_optional #} |
| 144 {% endif %}{# argument.idl_type == 'EventListener' #} | 155 {% endif %}{# argument.idl_type == 'EventListener' #} |
| 145 {% elif argument.is_callback_function %} | 156 {% elif argument.is_callback_function %} |
| 146 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf o[{{argument.index}}]->IsNull(){% endif %}) { | 157 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf o[{{argument.index}}]->IsNull(){% endif %}) { |
| 147 {{throw_type_error(method, | 158 {{throw_type_error(method, |
| 148 '"The callback provided as parameter %s is not a function."' % | 159 '"The callback provided as parameter %s is not a function."' % |
| 149 (argument.index + 1)) | indent(8)}} | 160 (argument.index + 1)) | indent}} |
| 150 return; | |
| 151 } | 161 } |
| 152 {{argument.v8_value_to_local_cpp_value}}; | 162 {{v8_value_to_local_cpp_value(argument)}} |
| 153 {% elif argument.is_variadic_wrapper_type %} | 163 {% elif argument.is_variadic_wrapper_type %} |
| 154 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 164 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
| 155 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { | 165 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { |
| 156 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 166 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
| 157 (argument.index + 1, argument.idl_type)) | in dent(8)}} | 167 (argument.index + 1, argument.idl_type)) | in dent(8)}} |
| 158 return; | |
| 159 } | 168 } |
| 160 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i]))); | 169 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i]))); |
| 161 } | 170 } |
| 162 {% elif argument.is_dictionary %} | 171 {% elif argument.is_dictionary %} |
| 163 {% if not argument.use_permissive_dictionary_conversion %} | 172 {% if not argument.use_permissive_dictionary_conversion %} |
| 164 {# Dictionaries must have type Undefined, Null or Object: | 173 {# Dictionaries must have type Undefined, Null or Object: |
| 165 http://heycam.github.io/webidl/#es-dictionary #} | 174 http://heycam.github.io/webidl/#es-dictionary #} |
| 166 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) { | 175 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) { |
| 167 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % | 176 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % |
| 168 (argument.index + 1, argument.name)) | indent}} | 177 (argument.index + 1, argument.name)) | indent}} |
| 169 return; | |
| 170 } | 178 } |
| 171 {% endif %}{# not argument.use_permissive_dictionary_conversion #} | 179 {% endif %}{# not argument.use_permissive_dictionary_conversion #} |
| 172 {{argument.v8_value_to_local_cpp_value}}; | 180 {{v8_value_to_local_cpp_value(argument)}} |
| 173 {% else %}{# argument.is_nullable #} | 181 {% else %}{# argument.is_nullable #} |
| 174 {{argument.v8_value_to_local_cpp_value}}; | 182 {{v8_value_to_local_cpp_value(argument)}} |
| 175 {% endif %}{# argument.is_nullable #} | 183 {% endif %}{# argument.is_nullable #} |
| 176 {# Type checking, possibly throw a TypeError, per: | 184 {# Type checking, possibly throw a TypeError, per: |
| 177 http://www.w3.org/TR/WebIDL/#es-type-mapping #} | 185 http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
| 178 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %} | 186 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %} |
| 179 {# Type checking for wrapper interface types (if interface not implemented, | 187 {# Type checking for wrapper interface types (if interface not implemented, |
| 180 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface | 188 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface |
| 181 Note: for variadic arguments, the type checking is done for each matched | 189 Note: for variadic arguments, the type checking is done for each matched |
| 182 argument instead; see argument.is_variadic_wrapper_type code-path above. #} | 190 argument instead; see argument.is_variadic_wrapper_type code-path above. #} |
| 183 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) { | 191 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) { |
| 184 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 192 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
| 185 (argument.index + 1, argument.idl_type)) | indent }} | 193 (argument.index + 1, argument.idl_type)) | indent }} |
| 186 return; | |
| 187 } | 194 } |
| 188 {% elif argument.enum_validation_expression %} | 195 {% elif argument.enum_validation_expression %} |
| 189 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} | 196 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} |
| 190 String string = {{argument.name}}; | 197 String string = {{argument.name}}; |
| 191 if (!({{argument.enum_validation_expression}})) { | 198 if (!({{argument.enum_validation_expression}})) { |
| 192 {{throw_type_error(method, | 199 {{throw_type_error(method, |
| 193 '"parameter %s (\'" + string + "\') is not a valid enum value."' % | 200 '"parameter %s (\'" + string + "\') is not a valid enum value."' % |
| 194 (argument.index + 1)) | indent}} | 201 (argument.index + 1)) | indent}} |
| 195 return; | |
| 196 } | 202 } |
| 197 {% elif argument.idl_type == 'Promise' %} | 203 {% elif argument.idl_type == 'Promise' %} |
| 198 {# We require this for our implementation of promises, though not in spec: | 204 {# We require this for our implementation of promises, though not in spec: |
| 199 http://heycam.github.io/webidl/#es-promise #} | 205 http://heycam.github.io/webidl/#es-promise #} |
| 200 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { | 206 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { |
| 201 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % | 207 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % |
| 202 (argument.index + 1, argument.name)) | indent}} | 208 (argument.index + 1, argument.name)) | indent}} |
| 203 return; | |
| 204 } | 209 } |
| 205 {% endif %} | 210 {% endif %} |
| 206 {% endmacro %} | 211 {% endmacro %} |
| 207 | 212 |
| 208 | 213 |
| 209 {######################################} | 214 {######################################} |
| 210 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} | 215 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} |
| 211 {# Local variables #} | 216 {# Local variables #} |
| 212 {% if method.is_call_with_script_state %} | 217 {% if method.is_call_with_script_state %} |
| 213 {# [ConstructorCallWith=ScriptState] #} | 218 {# [ConstructorCallWith=ScriptState] #} |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 238 {{method.cpp_type}} result; | 243 {{method.cpp_type}} result; |
| 239 {{cpp_value}}; | 244 {{cpp_value}}; |
| 240 {% elif method.is_constructor %} | 245 {% elif method.is_constructor %} |
| 241 {{method.cpp_type}} impl = {{cpp_value}}; | 246 {{method.cpp_type}} impl = {{cpp_value}}; |
| 242 {% elif method.use_local_result %} | 247 {% elif method.use_local_result %} |
| 243 {{method.cpp_type}} result = {{cpp_value}}; | 248 {{method.cpp_type}} result = {{cpp_value}}; |
| 244 {% endif %} | 249 {% endif %} |
| 245 {# Post-call #} | 250 {# Post-call #} |
| 246 {% if method.is_raises_exception %} | 251 {% if method.is_raises_exception %} |
| 247 if (exceptionState.hadException()) { | 252 if (exceptionState.hadException()) { |
| 248 {{throw_from_exception_state(method)}}; | 253 {{throw_from_exception_state(method) | indent}} |
| 249 return; | |
| 250 } | 254 } |
| 251 {% endif %} | 255 {% endif %} |
| 252 {# Set return value #} | 256 {# Set return value #} |
| 253 {% if method.is_constructor %} | 257 {% if method.is_constructor %} |
| 254 {{generate_constructor_wrapper(method)}} | 258 {{generate_constructor_wrapper(method)}} |
| 255 {%- elif v8_set_return_value %} | 259 {%- elif v8_set_return_value %} |
| 256 {% if method.is_explicit_nullable %} | 260 {% if method.is_explicit_nullable %} |
| 257 if (result.isNull()) | 261 if (result.isNull()) |
| 258 v8SetReturnValueNull(info); | 262 v8SetReturnValueNull(info); |
| 259 else | 263 else |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 273 if (info.Length() >= {{argument_index}} + 1 && listener && !impl->toNode()) | 277 if (info.Length() >= {{argument_index}} + 1 && listener && !impl->toNode()) |
| 274 {{hidden_dependency_action}}(info.GetIsolate(), info.Holder(), info[{{argume nt_index}}], {{v8_class}}::eventListenerCacheIndex); | 278 {{hidden_dependency_action}}(info.GetIsolate(), info.Holder(), info[{{argume nt_index}}], {{v8_class}}::eventListenerCacheIndex); |
| 275 {% endif %} | 279 {% endif %} |
| 276 {% endmacro %} | 280 {% endmacro %} |
| 277 | 281 |
| 278 | 282 |
| 279 {######################################} | 283 {######################################} |
| 280 {% macro throw_type_error(method, error_message) %} | 284 {% macro throw_type_error(method, error_message) %} |
| 281 {% if method.has_exception_state %} | 285 {% if method.has_exception_state %} |
| 282 exceptionState.throwTypeError({{error_message}}); | 286 exceptionState.throwTypeError({{error_message}}); |
| 283 {{throw_from_exception_state(method)}}; | 287 {{throw_from_exception_state(method)}} |
| 284 {% elif method.idl_type == 'Promise' %} | 288 {% elif method.idl_type == 'Promise' %} |
| 285 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), V8ThrowExcept ion::createTypeError(info.GetIsolate(), {{type_error_message(method, error_messa ge)}}))); | 289 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), V8ThrowExcept ion::createTypeError(info.GetIsolate(), {{type_error_message(method, error_messa ge)}}))); |
| 290 return; | |
| 286 {% else %} | 291 {% else %} |
| 287 V8ThrowException::throwTypeError(info.GetIsolate(), {{type_error_message(method, error_message)}}); | 292 V8ThrowException::throwTypeError(info.GetIsolate(), {{type_error_message(method, error_message)}}); |
| 293 return; | |
| 288 {% endif %}{# method.has_exception_state #} | 294 {% endif %}{# method.has_exception_state #} |
| 289 {% endmacro %} | 295 {% endmacro %} |
| 290 | 296 |
| 291 | 297 |
| 292 {######################################} | 298 {######################################} |
| 293 {% macro type_error_message(method, error_message) %} | 299 {% macro type_error_message(method, error_message) %} |
| 294 {% if method.is_constructor %} | 300 {% if method.is_constructor %} |
| 295 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) | 301 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) |
| 296 {%- else %} | 302 {%- else %} |
| 297 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er ror_message}}) | 303 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er ror_message}}) |
| 298 {%- endif %} | 304 {%- endif %} |
| 299 {%- endmacro %} | 305 {%- endmacro %} |
| 300 | 306 |
| 301 | 307 |
| 302 {######################################} | 308 {######################################} |
| 303 {% macro throw_from_exception_state(method_or_overloads) %} | 309 {% macro throw_from_exception_state(method_or_overloads) %} |
| 304 {% if method_or_overloads.idl_type == 'Promise' or method_or_overloads.returns_p romise_all %} | 310 {% if method_or_overloads.returns_promise_all %} |
| 305 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value()) | 311 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value()); |
| 306 {%- else %} | 312 {% elif not method_or_overloads.returns_promise %} |
| 307 exceptionState.throwIfNeeded() | 313 exceptionState.throwIfNeeded(); |
| 308 {%- endif %} | 314 {% endif %} |
| 315 return; | |
| 309 {%- endmacro %} | 316 {%- endmacro %} |
| 310 | 317 |
| 311 | 318 |
| 312 {######################################} | 319 {######################################} |
| 313 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} | 320 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} |
| 314 {% if method.has_exception_state %} | 321 {% if method.has_exception_state %} |
| 315 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info. Length()); | 322 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info. Length()); |
| 316 {{throw_from_exception_state(method)}}; | 323 {{throw_from_exception_state(method)}} |
| 317 {%- elif method.idl_type == 'Promise' %} | 324 {%- elif method.idl_type == 'Promise' %} |
| 318 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), {{create_mini mum_arity_type_error_without_exception_state(method, number_of_required_argument s)}})); | 325 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), {{create_mini mum_arity_type_error_without_exception_state(method, number_of_required_argument s)}})); |
| 326 return; | |
| 319 {%- else %} | 327 {%- else %} |
| 320 V8ThrowException::throwException({{create_minimum_arity_type_error_without_excep tion_state(method, number_of_required_arguments)}}, info.GetIsolate()); | 328 V8ThrowException::throwException({{create_minimum_arity_type_error_without_excep tion_state(method, number_of_required_arguments)}}, info.GetIsolate()); |
| 329 return; | |
| 321 {%- endif %} | 330 {%- endif %} |
| 322 {%- endmacro %} | 331 {%- endmacro %} |
| 323 | 332 |
| 324 | 333 |
| 325 {######################################} | 334 {######################################} |
| 326 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %} | 335 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %} |
| 327 {% if method.is_constructor %} | 336 {% if method.is_constructor %} |
| 328 createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}} ", {{number_of_required_arguments}}, info.Length()) | 337 createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}} ", {{number_of_required_arguments}}, info.Length()) |
| 329 {%- else %} | 338 {%- else %} |
| 330 createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{in terface_name}}", {{number_of_required_arguments}}, info.Length()) | 339 createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{in terface_name}}", {{number_of_required_arguments}}, info.Length()) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 default: | 401 default: |
| 393 {# If methods are overloaded between interface and partial interface #} | 402 {# If methods are overloaded between interface and partial interface #} |
| 394 {# definitions, need to invoke methods defined in the partial #} | 403 {# definitions, need to invoke methods defined in the partial #} |
| 395 {# interface. #} | 404 {# interface. #} |
| 396 {# FIXME: we do not need to always generate this code. #} | 405 {# FIXME: we do not need to always generate this code. #} |
| 397 {# Invalid arity, throw error #} | 406 {# Invalid arity, throw error #} |
| 398 {# Report full list of valid arities if gaps and above minimum #} | 407 {# Report full list of valid arities if gaps and above minimum #} |
| 399 {% if overloads.valid_arities %} | 408 {% if overloads.valid_arities %} |
| 400 if (info.Length() >= {{overloads.minarg}}) { | 409 if (info.Length() >= {{overloads.minarg}}) { |
| 401 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length()); | 410 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length()); |
| 402 {{throw_from_exception_state(overloads)}}; | 411 {{throw_from_exception_state(overloads) | indent(12)}} |
| 403 return; | |
| 404 } | 412 } |
| 405 {% endif %} | 413 {% endif %} |
| 406 break; | 414 break; |
| 407 {% endif %} | 415 {% endif %} |
| 408 } | 416 } |
| 409 {% if not is_partial and overloads.has_partial_overloads %} | 417 {% if not is_partial and overloads.has_partial_overloads %} |
| 410 ASSERT({{overloads.name}}MethodForPartialInterface); | 418 ASSERT({{overloads.name}}MethodForPartialInterface); |
| 411 ({{overloads.name}}MethodForPartialInterface)(info); | 419 ({{overloads.name}}MethodForPartialInterface)(info); |
| 412 {% else %} | 420 {% else %} |
| 413 {% if overloads.length != 0 %} | 421 {% if overloads.length != 0 %} |
| 414 if (info.Length() < {{overloads.length}}) { | 422 if (info.Length() < {{overloads.length}}) { |
| 415 {# Otherwise just report "not enough arguments" #} | 423 {# Otherwise just report "not enough arguments" #} |
| 416 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.length}}, info.Length())); | 424 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.length}}, info.Length())); |
| 417 {{throw_from_exception_state(overloads)}}; | 425 {{throw_from_exception_state(overloads) | indent(8)}} |
| 418 return; | |
| 419 } | 426 } |
| 420 {% endif %} | 427 {% endif %} |
| 421 {# No match, throw error #} | 428 {# No match, throw error #} |
| 422 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); | 429 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); |
| 423 {{throw_from_exception_state(overloads)}}; | 430 {{throw_from_exception_state(overloads) | indent}} |
| 424 {% endif %} | 431 {% endif %} |
| 425 } | 432 } |
| 426 {% endmacro %} | 433 {% endmacro %} |
| 427 | 434 |
| 428 | 435 |
| 429 {##############################################################################} | 436 {##############################################################################} |
| 430 {% macro method_callback(method, world_suffix) %} | 437 {% macro method_callback(method, world_suffix) %} |
| 431 {% filter conditional(method.conditional_string) %} | 438 {% filter conditional(method.conditional_string) %} |
| 432 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info) | 439 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info) |
| 433 { | 440 { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 v8::Local<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}} }; | 543 v8::Local<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}} }; |
| 537 {% else %} | 544 {% else %} |
| 538 {# Empty array initializers are illegal, and don\t compile in MSVC. #} | 545 {# Empty array initializers are illegal, and don\t compile in MSVC. #} |
| 539 v8::Local<v8::Value> *argv = 0; | 546 v8::Local<v8::Value> *argv = 0; |
| 540 {% endif %} | 547 {% endif %} |
| 541 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate() ); | 548 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate() ); |
| 542 v8::Local<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState , scriptStateInUserScript, "{{cpp_class}}", "{{method.name}}", holder, {{method. arguments | length}}, argv); | 549 v8::Local<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState , scriptStateInUserScript, "{{cpp_class}}", "{{method.name}}", holder, {{method. arguments | length}}, argv); |
| 543 if (v8Value.IsEmpty()) | 550 if (v8Value.IsEmpty()) |
| 544 return false; | 551 return false; |
| 545 {% if method.idl_type != 'void' %} | 552 {% if method.idl_type != 'void' %} |
| 546 {{method.private_script_v8_value_to_local_cpp_value}}; | 553 {{v8_value_to_local_cpp_value(method.private_script_v8_value_to_local_cpp_va lue) | indent}} |
| 547 *result = cppValue; | 554 *result = cppValue; |
| 548 {% endif %} | 555 {% endif %} |
| 549 RELEASE_ASSERT(!exceptionState.hadException()); | 556 RELEASE_ASSERT(!exceptionState.hadException()); |
| 550 return true; | 557 return true; |
| 551 } | 558 } |
| 552 {% endmacro %} | 559 {% endmacro %} |
| 553 | 560 |
| 554 | 561 |
| 555 {##############################################################################} | 562 {##############################################################################} |
| 556 {% macro generate_constructor(constructor) %} | 563 {% macro generate_constructor(constructor) %} |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 570 return; | 577 return; |
| 571 } | 578 } |
| 572 {% endif %} | 579 {% endif %} |
| 573 {% if constructor.has_exception_state %} | 580 {% if constructor.has_exception_state %} |
| 574 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); | 581 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); |
| 575 {% endif %} | 582 {% endif %} |
| 576 {# Overloaded constructors have length checked during overload resolution #} | 583 {# Overloaded constructors have length checked during overload resolution #} |
| 577 {% if constructor.number_of_required_arguments and not constructor.overload_ index %} | 584 {% if constructor.number_of_required_arguments and not constructor.overload_ index %} |
| 578 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { | 585 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { |
| 579 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ ired_arguments) | indent(8)}} | 586 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ ired_arguments) | indent(8)}} |
| 580 return; | |
| 581 } | 587 } |
| 582 {% endif %} | 588 {% endif %} |
| 583 {% if constructor.arguments %} | 589 {% if constructor.arguments %} |
| 584 {{generate_arguments(constructor) | indent}} | 590 {{generate_arguments(constructor) | indent}} |
| 585 {% endif %} | 591 {% endif %} |
| 586 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}} | 592 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}} |
| 587 } | 593 } |
| 588 {% endmacro %} | 594 {% endmacro %} |
| 589 | 595 |
| 590 | 596 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 if method.overloads else | 657 if method.overloads else |
| 652 method.runtime_enabled_function) %} | 658 method.runtime_enabled_function) %} |
| 653 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction()); | 659 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction()); |
| 654 {% endfilter %}{# runtime_enabled() #} | 660 {% endfilter %}{# runtime_enabled() #} |
| 655 {% endfilter %}{# exposed() #} | 661 {% endfilter %}{# exposed() #} |
| 656 {% endfilter %}{# per_context_enabled() #} | 662 {% endfilter %}{# per_context_enabled() #} |
| 657 {% endfor %} | 663 {% endfor %} |
| 658 {% endif %} | 664 {% endif %} |
| 659 } | 665 } |
| 660 {%- endmacro %} | 666 {%- endmacro %} |
| OLD | NEW |