| OLD | NEW |
| 1 {% from 'utilities.cpp' import declare_enum_validation_variable, v8_value_to_loc
al_cpp_value %} | 1 {% from 'utilities.cpp' import declare_enum_validation_variable, v8_value_to_loc
al_cpp_value %} |
| 2 | 2 |
| 3 {##############################################################################} | 3 {##############################################################################} |
| 4 {% macro generate_method(method, world_suffix) %} | 4 {% macro generate_method(method, world_suffix) %} |
| 5 {% if method.returns_promise and method.has_exception_state %} | |
| 6 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis
e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat
e) | |
| 7 {% else %} | |
| 8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) | 5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) |
| 9 {% endif %} | 6 {% filter format_remove_duplicates([ |
| 7 'ExceptionState exceptionState', |
| 8 'ScriptState* scriptState = ']) %} |
| 10 { | 9 { |
| 11 {# Local variables #} | 10 {% set define_exception_state -%} |
| 12 {% if method.has_exception_state and not method.returns_promise %} | 11 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo
ntext, "{{interface_name}}", "{{method.name}}"); |
| 13 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 12 {%- endset %} |
| 13 |
| 14 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %} |
| 15 |
| 16 {% if 'exceptionState' in function_call %} |
| 17 {{define_exception_state}} |
| 18 {% if method.returns_promise %} |
| 19 {% if method.is_static %} |
| 20 ScriptState* scriptState = ScriptState::forFunctionObject(info); |
| 21 {% else %} |
| 22 ScriptState* scriptState = ScriptState::forReceiverObject(info); |
| 14 {% endif %} | 23 {% endif %} |
| 15 {# Overloaded methods have length checked during overload resolution #} | 24 ExceptionToRejectPromiseScope rejectPromiseScope(info, scriptState, exceptio
nState); |
| 16 {% if method.number_of_required_arguments and not method.overload_index %} | |
| 17 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | |
| 18 {{throw_minimum_arity_type_error(method, method.number_of_required_argum
ents) | indent(8)}} | |
| 19 } | |
| 20 {% endif %} | 25 {% endif %} |
| 26 {% endif %} |
| 27 |
| 21 {% if not method.is_static %} | 28 {% if not method.is_static %} |
| 22 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); | 29 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); |
| 23 {% endif %} | 30 {% endif %} |
| 24 {% if method.is_custom_element_callbacks %} | 31 |
| 25 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; | |
| 26 {% endif %} | |
| 27 {# Security checks #} | 32 {# Security checks #} |
| 28 {% if method.is_check_security_for_receiver %} | 33 {% if method.is_check_security_for_receiver %} |
| 34 {{define_exception_state}} |
| 29 {% if interface_name == 'EventTarget' %} | 35 {% if interface_name == 'EventTarget' %} |
| 30 // Performance hack for EventTarget. Checking whether it's a Window or not | 36 // Performance hack for EventTarget. Checking whether it's a Window or not |
| 31 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% | 37 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% |
| 32 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE | 38 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE |
| 33 // didn't work in this case. | 39 // didn't work in this case. |
| 34 if (const DOMWindow* window = impl->toDOMWindow()) { | 40 if (const DOMWindow* window = impl->toDOMWindow()) { |
| 35 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsola
te()), window, exceptionState)) { | 41 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsola
te()), window, exceptionState)) { |
| 36 return; | 42 return; |
| 37 } | 43 } |
| 38 } | 44 } |
| 39 {% else %}{# interface_name == 'EventTarget' #} | 45 {% else %}{# interface_name == 'EventTarget' #} |
| 40 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { | 46 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { |
| 41 return; | 47 return; |
| 42 } | 48 } |
| 43 {% endif %}{# interface_name == 'EventTarget' #} | 49 {% endif %}{# interface_name == 'EventTarget' #} |
| 44 {% endif %} | 50 {% endif %} |
| 45 {% if method.is_check_security_for_return_value %} | 51 {% if method.is_check_security_for_return_value %} |
| 52 {{define_exception_state}} |
| 46 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), {{method.cpp_value}}, exceptionState)) { | 53 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), {{method.cpp_value}}, exceptionState)) { |
| 47 v8SetReturnValueNull(info); | 54 v8SetReturnValueNull(info); |
| 48 return; | 55 return; |
| 49 } | 56 } |
| 50 {% endif %} | 57 {% endif %} |
| 51 {# Call method #} | 58 |
| 52 {% if method.arguments %} | 59 {% if 'scriptState' in function_call %} |
| 53 {{generate_arguments(method, world_suffix) | indent}} | 60 {% if method.is_static %} |
| 61 ScriptState* scriptState = ScriptState::forFunctionObject(info); |
| 62 {% else %} |
| 63 ScriptState* scriptState = ScriptState::forReceiverObject(info); |
| 54 {% endif %} | 64 {% endif %} |
| 55 {% if world_suffix %} | |
| 56 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} | |
| 57 {% else %} | |
| 58 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} | |
| 59 {% endif %} | 65 {% endif %} |
| 66 |
| 67 {% if method.is_custom_element_callbacks %} |
| 68 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; |
| 69 {% endif %} |
| 70 |
| 71 {{function_call | indent}} |
| 60 } | 72 } |
| 61 {% if method.returns_promise and method.has_exception_state %} | 73 {% endfilter %} |
| 74 {% endmacro %} |
| 62 | 75 |
| 63 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) | 76 |
| 64 { | 77 {######################################} |
| 65 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 78 {% macro func_call_with_prep_of_args(method, world_suffix) %} |
| 66 {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promise(info,
exceptionState); | 79 {{generate_arguments(method, world_suffix)}} |
| 67 if (exceptionState.hadException()) | 80 {% if world_suffix %} |
| 68 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.G
etIsolate())).v8Value()); | 81 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.cpp_
value)}} |
| 69 } | 82 {% else %} |
| 83 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value)}} |
| 70 {% endif %} | 84 {% endif %} |
| 71 {% endmacro %} | 85 {% endmacro %} |
| 72 | 86 |
| 73 | 87 |
| 74 {######################################} | 88 {######################################} |
| 75 {% macro generate_arguments(method, world_suffix) %} | 89 {% macro generate_arguments(method, world_suffix) %} |
| 90 {% if method.arguments %} |
| 91 |
| 92 {# Overloaded methods/constructors have length checked during overload resolutio
n #} |
| 93 {% if method.number_of_required_arguments and not method.overload_index %} |
| 94 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
| 95 {{throw_type_error(method, |
| 96 'ExceptionMessages::notEnoughArguments(%(expected)d, info.Length())' |
| 97 | format(expected=method.number_of_required_arguments))}} |
| 98 return; |
| 99 } |
| 100 {% endif %} |
| 101 |
| 76 {% for argument in method.arguments %} | 102 {% for argument in method.arguments %} |
| 77 {{argument.cpp_type}} {{argument.name}}; | 103 {{argument.cpp_type}} {{argument.name}}; |
| 78 {% endfor %} | 104 {% endfor %} |
| 79 { | 105 {% if method.has_optional_argument_without_default_value %} |
| 80 {% if method.has_optional_argument_without_default_value %} | 106 {# Count the effective number of arguments. (arg1, arg2, undefined) is |
| 81 {# Count the effective number of arguments. (arg1, arg2, undefined) is | 107 interpreted as two arguments are passed and (arg1, undefined, arg3) is |
| 82 interpreted as two arguments are passed and (arg1, undefined, arg3) is | 108 interpreted as three arguments are passed. #} |
| 83 interpreted as three arguments are passed. #} | 109 int numArgsPassed = info.Length(); |
| 84 int numArgsPassed = info.Length(); | 110 while (numArgsPassed > 0) { |
| 85 while (numArgsPassed > 0) { | 111 if (!info[numArgsPassed - 1]->IsUndefined()) |
| 86 if (!info[numArgsPassed - 1]->IsUndefined()) | 112 break; |
| 87 break; | 113 --numArgsPassed; |
| 88 --numArgsPassed; | 114 } |
| 89 } | 115 {% endif %} |
| 90 {% endif %} | 116 {% for argument in method.arguments %} |
| 91 {% for argument in method.arguments %} | 117 {% if argument.set_default_value %} |
| 92 {% if argument.set_default_value %} | 118 if (!info[{{argument.index}}]->IsUndefined()) { |
| 93 if (!info[{{argument.index}}]->IsUndefined()) { | |
| 94 {{generate_argument(method, argument, world_suffix) | indent(8)}} | |
| 95 } else { | |
| 96 {{argument.set_default_value}}; | |
| 97 } | |
| 98 {% else %} | |
| 99 {{generate_argument(method, argument, world_suffix) | indent}} | 119 {{generate_argument(method, argument, world_suffix) | indent}} |
| 100 {% endif %} | 120 } else { |
| 101 {% endfor %} | 121 {{argument.set_default_value | indent}}; |
| 102 } | 122 } |
| 123 {% else %} |
| 124 {{generate_argument(method, argument, world_suffix)}} |
| 125 {% endif %} |
| 126 {% endfor %} |
| 127 |
| 128 {% endif %}{# method.arguments #} |
| 103 {% endmacro %} | 129 {% endmacro %} |
| 104 | 130 |
| 105 | 131 |
| 106 {######################################} | 132 {######################################} |
| 107 {% macro generate_argument(method, argument, world_suffix) %} | 133 {% macro generate_argument(method, argument, world_suffix) %} |
| 108 {% if argument.is_optional_without_default_value %} | 134 {% if argument.is_optional_without_default_value %} |
| 109 {# Optional arguments without a default value generate an early call with | 135 {# Optional arguments without a default value generate an early call with |
| 110 fewer arguments if they are omitted. | 136 fewer arguments if they are omitted. |
| 111 Optional Dictionary arguments default to empty dictionary. #} | 137 Optional Dictionary arguments default to empty dictionary. #} |
| 112 if (UNLIKELY(numArgsPassed <= {{argument.index}})) { | 138 if (UNLIKELY(numArgsPassed <= {{argument.index}})) { |
| 113 {% if world_suffix %} | 139 {% if world_suffix %} |
| 114 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value) | indent}} | 140 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value) | indent}} |
| 115 {% else %} | 141 {% else %} |
| 116 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} | 142 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} |
| 117 {% endif %} | 143 {% endif %} |
| 118 {% if argument.has_event_listener_argument %} | |
| 119 {{hidden_dependency_action(method.name) | indent}} | |
| 120 {% endif %} | |
| 121 return; | 144 return; |
| 122 } | 145 } |
| 123 {% endif %} | 146 {% endif %} |
| 124 {% if argument.is_callback_interface %} | 147 {% if argument.is_callback_interface %} |
| 125 {# FIXME: remove EventListener special case #} | 148 {# FIXME: remove EventListener special case #} |
| 126 {% if argument.idl_type == 'EventListener' %} | 149 {% if argument.idl_type == 'EventListener' %} |
| 127 {% if method.name == 'removeEventListener' or method.name == 'removeListener' %} | 150 {% if method.name == 'removeEventListener' or method.name == 'removeListener' %} |
| 128 {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(i
nfo.GetIsolate()), info[{{argument.index}}], false, ListenerFindOnly); | 151 {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(i
nfo.GetIsolate()), info[{{argument.index}}], false, ListenerFindOnly); |
| 129 {% else %}{# method.name == 'addEventListener' #} | 152 {% else %}{# method.name == 'addEventListener' #} |
| 130 {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(i
nfo.GetIsolate()), info[{{argument.index}}], false, ListenerFindOrCreate); | 153 {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(i
nfo.GetIsolate()), info[{{argument.index}}], false, ListenerFindOrCreate); |
| 131 {% endif %}{# method.name #} | 154 {% endif %}{# method.name #} |
| 132 {% else %}{# argument.idl_type == 'EventListener' #} | 155 {% else %}{# argument.idl_type == 'EventListener' #} |
| 133 {# Callback functions must be functions: | 156 {# Callback functions must be functions: |
| 134 http://www.w3.org/TR/WebIDL/#es-callback-function #} | 157 http://www.w3.org/TR/WebIDL/#es-callback-function #} |
| 135 {% if argument.is_optional %} | 158 {% if argument.is_optional %} |
| 136 if (!isUndefinedOrNull(info[{{argument.index}}])) { | 159 if (!isUndefinedOrNull(info[{{argument.index}}])) { |
| 137 if (!info[{{argument.index}}]->IsFunction()) { | 160 if (!info[{{argument.index}}]->IsFunction()) { |
| 138 {{throw_type_error(method, | 161 {{throw_argument_error(method, argument, "The callback provided as param
eter %(index)d is not a function.")}} |
| 139 '"The callback provided as parameter %s is not a function."' % | 162 return; |
| 140 (argument.index + 1)) | indent(8)}} | |
| 141 } | 163 } |
| 142 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>:
:Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); | 164 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>:
:Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); |
| 143 } else { | 165 } else { |
| 144 {{argument.name}} = nullptr; | 166 {{argument.name}} = nullptr; |
| 145 } | 167 } |
| 146 {% else %}{# argument.is_optional #} | 168 {% else %}{# argument.is_optional #} |
| 147 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{
{argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else %
}info[{{argument.index}}]->IsFunction(){% endif %}) { | 169 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{
{argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else %
}info[{{argument.index}}]->IsFunction(){% endif %}) { |
| 148 {{throw_type_error(method, | 170 {{throw_argument_error(method, argument, "The callback provided as parameter
%(index)d is not a function.")}} |
| 149 '"The callback provided as parameter %s is not a function."' % | 171 return; |
| 150 (argument.index + 1)) | indent}} | |
| 151 } | 172 } |
| 152 {{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())); | 173 {{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 {% endif %}{# argument.is_optional #} | 174 {% endif %}{# argument.is_optional #} |
| 154 {% endif %}{# argument.idl_type == 'EventListener' #} | 175 {% endif %}{# argument.idl_type == 'EventListener' #} |
| 155 {% elif argument.is_callback_function %} | 176 {% elif argument.is_callback_function %} |
| 156 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf
o[{{argument.index}}]->IsNull(){% endif %}) { | 177 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf
o[{{argument.index}}]->IsNull(){% endif %}) { |
| 157 {{throw_type_error(method, | 178 {{throw_argument_error(method, argument, "The callback provided as parameter
%(index)d is not a function.")}} |
| 158 '"The callback provided as parameter %s is not a function."' % | 179 return; |
| 159 (argument.index + 1)) | indent}} | |
| 160 } | 180 } |
| 161 {{v8_value_to_local_cpp_value(argument)}} | 181 {{v8_value_to_local_cpp_value(argument)}} |
| 162 {% elif argument.is_variadic_wrapper_type %} | 182 {% elif argument.is_variadic_wrapper_type %} |
| 163 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 183 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
| 164 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { | 184 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { |
| 165 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 185 {{throw_argument_error(method, argument, "parameter %(index)d is not of
type '%(type)s'.")}} |
| 166 (argument.index + 1, argument.idl_type)) | in
dent(8)}} | 186 return; |
| 167 } | 187 } |
| 168 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec
t>::Cast(info[i]))); | 188 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec
t>::Cast(info[i]))); |
| 169 } | 189 } |
| 170 {% elif argument.is_dictionary %} | 190 {% elif argument.is_dictionary %} |
| 171 {% if not argument.use_permissive_dictionary_conversion %} | 191 {% if not argument.use_permissive_dictionary_conversion %} |
| 172 {# Dictionaries must have type Undefined, Null or Object: | 192 {# Dictionaries must have type Undefined, Null or Object: |
| 173 http://heycam.github.io/webidl/#es-dictionary #} | 193 http://heycam.github.io/webidl/#es-dictionary #} |
| 174 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I
sObject()) { | 194 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I
sObject()) { |
| 175 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % | 195 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') i
s not an object.")}} |
| 176 (argument.index + 1, argument.name)) | indent}} | 196 return; |
| 177 } | 197 } |
| 178 {% endif %}{# not argument.use_permissive_dictionary_conversion #} | 198 {% endif %}{# not argument.use_permissive_dictionary_conversion #} |
| 179 {{v8_value_to_local_cpp_value(argument)}} | 199 {{v8_value_to_local_cpp_value(argument)}} |
| 180 {% elif argument.is_explicit_nullable %} | 200 {% elif argument.is_explicit_nullable %} |
| 181 if (!isUndefinedOrNull(info[{{argument.index}}])) { | 201 if (!isUndefinedOrNull(info[{{argument.index}}])) { |
| 182 {{v8_value_to_local_cpp_value(argument) | indent}} | 202 {{v8_value_to_local_cpp_value(argument) | indent}} |
| 183 } | 203 } |
| 184 {% else %}{# argument.is_nullable #} | 204 {% else %}{# argument.is_nullable #} |
| 185 {{v8_value_to_local_cpp_value(argument)}} | 205 {{v8_value_to_local_cpp_value(argument)}} |
| 186 {% endif %}{# argument.is_nullable #} | 206 {% endif %}{# argument.is_nullable #} |
| 187 {# Type checking, possibly throw a TypeError, per: | 207 {# Type checking, possibly throw a TypeError, per: |
| 188 http://www.w3.org/TR/WebIDL/#es-type-mapping #} | 208 http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
| 189 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_
type %} | 209 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_
type %} |
| 190 {# Type checking for wrapper interface types (if interface not implemented, | 210 {# Type checking for wrapper interface types (if interface not implemented, |
| 191 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface | 211 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface |
| 192 Note: for variadic arguments, the type checking is done for each matched | 212 Note: for variadic arguments, the type checking is done for each matched |
| 193 argument instead; see argument.is_variadic_wrapper_type code-path above. #} | 213 argument instead; see argument.is_variadic_wrapper_type code-path above. #} |
| 194 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{
{argument.index}}]){% endif %}) { | 214 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{
{argument.index}}]){% endif %}) { |
| 195 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 215 {{throw_argument_error(method, argument, "parameter %(index)d is not of type
'%(type)s'.")}} |
| 196 (argument.index + 1, argument.idl_type)) | indent
}} | 216 return; |
| 197 } | 217 } |
| 198 {% elif argument.enum_values %} | 218 {% elif argument.enum_values %} |
| 199 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} | 219 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} |
| 200 {{declare_enum_validation_variable(argument.enum_values)}} | 220 {{declare_enum_validation_variable(argument.enum_values)}} |
| 201 if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues),
"{{argument.enum_type}}", exceptionState)) { | 221 if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues),
"{{argument.enum_type}}", exceptionState)) { |
| 202 return; | 222 return; |
| 203 } | 223 } |
| 204 {% elif argument.idl_type == 'Promise' %} | 224 {% elif argument.idl_type == 'Promise' %} |
| 205 {# We require this for our implementation of promises, though not in spec: | 225 {# We require this for our implementation of promises, though not in spec: |
| 206 http://heycam.github.io/webidl/#es-promise #} | 226 http://heycam.github.io/webidl/#es-promise #} |
| 207 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { | 227 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { |
| 208 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % | 228 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') i
s not an object.")}} |
| 209 (argument.index + 1, argument.name)) | indent}} | 229 return; |
| 210 } | 230 } |
| 211 {% endif %} | 231 {% endif %} |
| 212 {% endmacro %} | 232 {% endmacro %} |
| 213 | 233 |
| 214 | 234 |
| 215 {######################################} | 235 {######################################} |
| 216 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} | 236 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} |
| 217 {% if method.is_custom_call_prologue %} | 237 {% if method.is_custom_call_prologue %} |
| 218 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl); | 238 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl); |
| 219 {% endif %} | 239 {% endif %} |
| 220 {# Local variables #} | 240 {# Local variables #} |
| 221 {% if method.is_call_with_script_state or method.is_call_with_this_value %} | |
| 222 {# [ConstructorCallWith=ScriptState] #} | |
| 223 {# [CallWith=ScriptState] #} | |
| 224 {% if method.is_static %} | |
| 225 ScriptState* scriptState = ScriptState::forFunctionObject(info); | |
| 226 {% else %} | |
| 227 ScriptState* scriptState = ScriptState::forReceiverObject(info); | |
| 228 {% endif %} | |
| 229 {% endif %} | |
| 230 {% if method.is_call_with_execution_context %} | 241 {% if method.is_call_with_execution_context %} |
| 231 {# [ConstructorCallWith=ExecutionContext] #} | 242 {# [ConstructorCallWith=ExecutionContext] #} |
| 232 {# [CallWith=ExecutionContext] #} | 243 {# [CallWith=ExecutionContext] #} |
| 233 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate()); | 244 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate()); |
| 234 {% endif %} | 245 {% endif %} |
| 235 {% if method.is_call_with_script_arguments %} | 246 {% if method.is_call_with_script_arguments %} |
| 236 {# [CallWith=ScriptArguments] #} | 247 {# [CallWith=ScriptArguments] #} |
| 237 ScriptArguments* scriptArguments(ScriptArguments::create(scriptState, info, {{me
thod.number_of_arguments}})); | 248 ScriptArguments* scriptArguments(ScriptArguments::create(scriptState, info, {{me
thod.number_of_arguments}})); |
| 238 {% endif %} | 249 {% endif %} |
| 239 {% if method.is_call_with_document %} | 250 {% if method.is_call_with_document %} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 251 {{method.cpp_type}} result; | 262 {{method.cpp_type}} result; |
| 252 {{cpp_value}}; | 263 {{cpp_value}}; |
| 253 {% elif method.is_constructor %} | 264 {% elif method.is_constructor %} |
| 254 {{method.cpp_type}} impl = {{cpp_value}}; | 265 {{method.cpp_type}} impl = {{cpp_value}}; |
| 255 {% elif method.use_local_result %} | 266 {% elif method.use_local_result %} |
| 256 {{method.cpp_type}} result = {{cpp_value}}; | 267 {{method.cpp_type}} result = {{cpp_value}}; |
| 257 {% endif %} | 268 {% endif %} |
| 258 {# Post-call #} | 269 {# Post-call #} |
| 259 {% if method.is_raises_exception %} | 270 {% if method.is_raises_exception %} |
| 260 if (exceptionState.hadException()) { | 271 if (exceptionState.hadException()) { |
| 261 {{propagate_error_with_exception_state(method) | indent}} | 272 return; |
| 262 } | 273 } |
| 263 {% endif %} | 274 {% endif %} |
| 264 {# Set return value #} | 275 {# Set return value #} |
| 265 {% if method.is_new_object and not method.do_not_test_new_object %} | 276 {% if method.is_new_object and not method.do_not_test_new_object %} |
| 266 // [NewObject] must always create a new wrapper. Check that a wrapper | 277 // [NewObject] must always create a new wrapper. Check that a wrapper |
| 267 // does not exist yet. | 278 // does not exist yet. |
| 268 DCHECK(!result || DOMDataStore::getWrapper(result, info.GetIsolate()).IsEmpty())
; | 279 DCHECK(!result || DOMDataStore::getWrapper(result, info.GetIsolate()).IsEmpty())
; |
| 269 {% endif %} | 280 {% endif %} |
| 270 {% if method.is_constructor %} | 281 {% if method.is_constructor %} |
| 271 {{generate_constructor_wrapper(method)}} | 282 {{generate_constructor_wrapper(method)}} |
| 272 {%- elif v8_set_return_value %} | 283 {%- elif v8_set_return_value %} |
| 273 {% if method.is_explicit_nullable %} | 284 {% if method.is_explicit_nullable %} |
| 274 if (result.isNull()) | 285 if (result.isNull()) |
| 275 v8SetReturnValueNull(info); | 286 v8SetReturnValueNull(info); |
| 276 else | 287 else |
| 277 {{v8_set_return_value}}; | 288 {{v8_set_return_value}}; |
| 278 {% else %} | 289 {% else %} |
| 279 {{v8_set_return_value}}; | 290 {{v8_set_return_value}}; |
| 280 {% endif %} | 291 {% endif %} |
| 281 {%- endif %}{# None for void #} | 292 {%- endif %}{# None for void #} |
| 282 {% if method.is_custom_call_epilogue %} | 293 {% if method.is_custom_call_epilogue %} |
| 283 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl); | 294 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl); |
| 284 {% endif %} | 295 {% endif %} |
| 285 {% endmacro %} | 296 {% endmacro %} |
| 286 | 297 |
| 287 | 298 |
| 288 {######################################} | 299 {##############################################################################} |
| 289 {% macro throw_type_error(method, error_message) %} | 300 {% macro throw_type_error(method, error_message) %} |
| 290 {% if method.has_exception_state %} | 301 {% if method.has_exception_state or |
| 302 method.returns_promise %} |
| 291 exceptionState.throwTypeError({{error_message}}); | 303 exceptionState.throwTypeError({{error_message}}); |
| 292 {{propagate_error_with_exception_state(method)}} | 304 {%- elif method.is_constructor %} |
| 293 {% elif method.idl_type == 'Promise' %} | 305 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToC
onstruct("{{interface_name}}", {{error_message}})); |
| 294 v8SetReturnValue(info, ScriptPromise::rejectRaw(ScriptState::current(info.GetIso
late()), V8ThrowException::createTypeError(info.GetIsolate(), {{type_error_messa
ge(method, error_message)}}))); | 306 {%- else %} |
| 295 return; | 307 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToE
xecute("{{method.name}}", "{{interface_name}}", {{error_message}})); |
| 296 {% else %} | 308 {%- endif %} |
| 297 V8ThrowException::throwTypeError(info.GetIsolate(), {{type_error_message(method,
error_message)}}); | |
| 298 return; | |
| 299 {% endif %}{# method.has_exception_state #} | |
| 300 {% endmacro %} | 309 {% endmacro %} |
| 301 | 310 |
| 302 | 311 |
| 303 {######################################} | 312 {##############################################################################} |
| 304 {% macro type_error_message(method, error_message) %} | 313 {% macro throw_argument_error(method, argument, error_message) %} |
| 305 {% if method.is_constructor %} | 314 {% set quoted_message = '"%s"' % (error_message | replace('\"', '\\\"')) %} |
| 306 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) | 315 {{throw_type_error(method, quoted_message | format(index=(argument.index + 1), n
ame=argument.name, type=argument.idl_type))}} |
| 307 {%- else %} | 316 {% endmacro %} |
| 308 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er
ror_message}}) | |
| 309 {%- endif %} | |
| 310 {%- endmacro %} | |
| 311 | |
| 312 | |
| 313 {######################################} | |
| 314 {% macro propagate_error_with_exception_state(method_or_overloads) %} | |
| 315 {% if method_or_overloads.returns_promise_all or | |
| 316 method_or_overloads.returns_promise %} | |
| 317 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat
e())).v8Value()); | |
| 318 {% endif %} | |
| 319 return; | |
| 320 {%- endmacro %} | |
| 321 | |
| 322 | |
| 323 {######################################} | |
| 324 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} | |
| 325 {% if method.has_exception_state %} | |
| 326 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{method.num
ber_of_required_arguments}}, info.Length())); | |
| 327 {{propagate_error_with_exception_state(method)}} | |
| 328 {%- elif method.idl_type == 'Promise' %} | |
| 329 v8SetReturnValue(info, ScriptPromise::rejectRaw(ScriptState::current(info.GetIso
late()), {{create_minimum_arity_type_error_without_exception_state(method, numbe
r_of_required_arguments)}})); | |
| 330 return; | |
| 331 {%- else %} | |
| 332 V8ThrowException::throwException(info.GetIsolate(), {{create_minimum_arity_type_
error_without_exception_state(method, number_of_required_arguments)}}); | |
| 333 return; | |
| 334 {%- endif %} | |
| 335 {%- endmacro %} | |
| 336 | |
| 337 | |
| 338 {######################################} | |
| 339 {% macro create_minimum_arity_type_error_without_exception_state(method, number_
of_required_arguments) %} | |
| 340 {% if method.is_constructor %} | |
| 341 V8ThrowException::createTypeError(info.GetIsolate(), ExceptionMessages::failedTo
Construct("{{interface_name}}", ExceptionMessages::notEnoughArguments({{number_o
f_required_arguments}}, info.Length()))) | |
| 342 {%- else %} | |
| 343 V8ThrowException::createTypeError(info.GetIsolate(), ExceptionMessages::failedTo
Execute("{{method.name}}", "{{interface_name}}", ExceptionMessages::notEnoughArg
uments({{number_of_required_arguments}}, info.Length()))) | |
| 344 {%- endif %} | |
| 345 {%- endmacro %} | |
| 346 | 317 |
| 347 | 318 |
| 348 {##############################################################################} | 319 {##############################################################################} |
| 349 {% macro runtime_determined_length_method(overloads) %} | 320 {% macro runtime_determined_length_method(overloads) %} |
| 350 static int {{overloads.name}}MethodLength() | 321 static int {{overloads.name}}MethodLength() |
| 351 { | 322 { |
| 352 {% for length, runtime_enabled_functions in overloads.runtime_determined_len
gths %} | 323 {% for length, runtime_enabled_functions in overloads.runtime_determined_len
gths %} |
| 353 {% for runtime_enabled_function in runtime_enabled_functions %} | 324 {% for runtime_enabled_function in runtime_enabled_functions %} |
| 354 {% filter runtime_enabled(runtime_enabled_function) %} | 325 {% filter runtime_enabled(runtime_enabled_function) %} |
| 355 return {{length}}; | 326 return {{length}}; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 369 {% filter runtime_enabled(runtime_enabled_function) %} | 340 {% filter runtime_enabled(runtime_enabled_function) %} |
| 370 return {{length}}; | 341 return {{length}}; |
| 371 {% endfilter %} | 342 {% endfilter %} |
| 372 {% endfor %} | 343 {% endfor %} |
| 373 {% endfor %} | 344 {% endfor %} |
| 374 } | 345 } |
| 375 {% endmacro %} | 346 {% endmacro %} |
| 376 | 347 |
| 377 | 348 |
| 378 {##############################################################################} | 349 {##############################################################################} |
| 379 {# FIXME: We should return a rejected Promise if an error occurs in this | |
| 380 function when ALL methods in this overload return Promise. In order to do so, | |
| 381 we must ensure either ALL or NO methods in this overload return Promise #} | |
| 382 {% macro overload_resolution_method(overloads, world_suffix) %} | 350 {% macro overload_resolution_method(overloads, world_suffix) %} |
| 383 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 351 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
| 384 { | 352 { |
| 385 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads
.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 353 {% set fall_through_to_partial_overloads = |
| 354 not is_partial and overloads.has_partial_overloads %} |
| 355 |
| 386 {% if overloads.measure_all_as %} | 356 {% if overloads.measure_all_as %} |
| 387 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte
xt(info.GetIsolate()), UseCounter::{{overloads.measure_all_as}}); | 357 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte
xt(info.GetIsolate()), UseCounter::{{overloads.measure_all_as}}); |
| 388 {% endif %} | 358 {% endif %} |
| 389 {% if overloads.deprecate_all_as %} | 359 {% if overloads.deprecate_all_as %} |
| 390 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx
ecutionContext(info.GetIsolate()), UseCounter::{{overloads.deprecate_all_as}}); | 360 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx
ecutionContext(info.GetIsolate()), UseCounter::{{overloads.deprecate_all_as}}); |
| 391 {% endif %} | 361 {% endif %} |
| 362 |
| 392 {# First resolve by length #} | 363 {# First resolve by length #} |
| 364 {% if not fall_through_to_partial_overloads %} |
| 365 bool isArityError = false; |
| 366 {% endif %} |
| 393 {# 2. Initialize argcount to be min(maxarg, n). #} | 367 {# 2. Initialize argcount to be min(maxarg, n). #} |
| 394 switch (std::min({{overloads.maxarg}}, info.Length())) { | 368 switch (std::min({{overloads.maxarg}}, info.Length())) { |
| 395 {# 3. Remove from S all entries whose type list is not of length argcount. #
} | 369 {# 3. Remove from S all entries whose type list is not of length argcount. #
} |
| 396 {% for length, tests_methods in overloads.length_tests_methods %} | 370 {% for length, tests_methods in overloads.length_tests_methods %} |
| 397 {# 10. If i = d, then: #} | 371 {# 10. If i = d, then: #} |
| 398 case {{length}}: | 372 case {{length}}: |
| 399 {# Then resolve by testing argument #} | 373 {# Then resolve by testing argument #} |
| 400 {% for test, method in tests_methods %} | 374 {% for test, method in tests_methods %} |
| 401 {% if method.visible %} | 375 {% if method.visible %} |
| 402 {% filter runtime_enabled(not overloads.runtime_enabled_function_all and | 376 {% filter runtime_enabled(not overloads.runtime_enabled_function_all and |
| 403 method.runtime_enabled_function) %} | 377 method.runtime_enabled_function) %} |
| 404 if ({{test}}) { | 378 if ({{test}}) { |
| 405 {% if method.measure_as and not overloads.measure_all_as %} | 379 {% if method.measure_as and not overloads.measure_all_as %} |
| 406 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecut
ionContext(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}}); | 380 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecut
ionContext(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}}); |
| 407 {% endif %} | 381 {% endif %} |
| 408 {% if method.deprecate_as and not overloads.deprecate_all_as %} | 382 {% if method.deprecate_as and not overloads.deprecate_all_as %} |
| 409 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), c
urrentExecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}}); | 383 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), c
urrentExecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}}); |
| 410 {% endif %} | 384 {% endif %} |
| 411 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info)
; | 385 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info)
; |
| 412 return; | 386 return; |
| 413 } | 387 } |
| 414 {% endfilter %} | 388 {% endfilter %} |
| 415 {% endif %} | 389 {% endif %} |
| 416 {% endfor %} | 390 {% endfor %} |
| 417 break; | 391 break; |
| 418 {% endfor %} | 392 {% endfor %} |
| 419 {% if is_partial or not overloads.has_partial_overloads %} | 393 {% if not fall_through_to_partial_overloads %} |
| 420 default: | 394 default: |
| 421 {# If methods are overloaded between interface and partial interface #} | 395 {# 4. If S is empty, then throw a TypeError. #} |
| 422 {# definitions, need to invoke methods defined in the partial #} | 396 isArityError = true; |
| 423 {# interface. #} | 397 {% endif %} |
| 424 {# FIXME: we do not need to always generate this code. #} | 398 } |
| 425 {# Invalid arity, throw error #} | 399 |
| 426 {# Report full list of valid arities if gaps and above minimum #} | 400 {% if fall_through_to_partial_overloads %} |
| 401 |
| 402 DCHECK({{overloads.name}}MethodForPartialInterface); |
| 403 ({{overloads.name}}MethodForPartialInterface)(info); |
| 404 |
| 405 {% else %}{# fall_through_to_partial_overloads #} |
| 406 |
| 407 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo
ntext, "{{interface_name}}", "{{overloads.name}}"); |
| 408 {% if overloads.returns_promise_all %} |
| 409 {% if overloads.is_static %} |
| 410 ScriptState* scriptState = ScriptState::forFunctionObject(info); |
| 411 {% else %} |
| 412 ScriptState* scriptState = ScriptState::forReceiverObject(info); |
| 413 {% endif %} |
| 414 ExceptionToRejectPromiseScope rejectPromiseScope(info, scriptState, exceptio
nState); |
| 415 {% endif %} |
| 416 |
| 417 if (isArityError) { |
| 418 {% if overloads.length != 0 %} |
| 419 if (info.Length() < {{overloads.length}}) { |
| 420 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(
{{overloads.length}}, info.Length())); |
| 421 return; |
| 422 } |
| 423 {% endif %} |
| 427 {% if overloads.valid_arities %} | 424 {% if overloads.valid_arities %} |
| 428 if (info.Length() >= {{overloads.length}}) { | 425 if (info.Length() >= {{overloads.length}}) { |
| 429 exceptionState.throwTypeError(ExceptionMessages::invalidArity("{{ove
rloads.valid_arities}}", info.Length())); | 426 exceptionState.throwTypeError(ExceptionMessages::invalidArity("{{ove
rloads.valid_arities}}", info.Length())); |
| 430 {{propagate_error_with_exception_state(overloads) | indent(12)}} | 427 return; |
| 431 } | 428 } |
| 432 {% endif %} | 429 {% endif %} |
| 433 break; | |
| 434 {% endif %} | |
| 435 } | 430 } |
| 436 {% if not is_partial and overloads.has_partial_overloads %} | |
| 437 ASSERT({{overloads.name}}MethodForPartialInterface); | |
| 438 ({{overloads.name}}MethodForPartialInterface)(info); | |
| 439 {% else %} | |
| 440 {% if overloads.length != 0 %} | |
| 441 if (info.Length() < {{overloads.length}}) { | |
| 442 {# Otherwise just report "not enough arguments" #} | |
| 443 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov
erloads.length}}, info.Length())); | |
| 444 {{propagate_error_with_exception_state(overloads) | indent(8)}} | |
| 445 } | |
| 446 {% endif %} | |
| 447 {# No match, throw error #} | |
| 448 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); | 431 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); |
| 449 {{propagate_error_with_exception_state(overloads) | indent}} | 432 |
| 450 {% endif %} | 433 {% endif %}{# fall_through_to_partial_overloads #} |
| 451 } | 434 } |
| 452 {% endmacro %} | 435 {% endmacro %} |
| 453 | 436 |
| 454 | 437 |
| 455 {##############################################################################} | 438 {##############################################################################} |
| 456 {% macro generate_post_message_impl(method) %} | 439 {% macro generate_post_message_impl(method) %} |
| 457 static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance,
const v8::FunctionCallbackInfo<v8::Value>& info) | 440 static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance,
const v8::FunctionCallbackInfo<v8::Value>& info) |
| 458 { | 441 { |
| 459 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo
ntext, interfaceName, "postMessage"); | 442 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo
ntext, interfaceName, "postMessage"); |
| 460 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 443 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
| 461 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{me
thod.number_of_required_arguments}}, info.Length())); | 444 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{me
thod.number_of_required_arguments}}, info.Length())); |
| 462 return; | 445 return; |
| 463 } | 446 } |
| 464 Transferables transferables; | 447 Transferables transferables; |
| 465 if (info.Length() > 1) { | 448 if (info.Length() > 1) { |
| 466 const int transferablesArgIndex = 1; | 449 const int transferablesArgIndex = 1; |
| 467 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ | 450 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ |
| 468 return; | 451 return; |
| 469 } | 452 } |
| 470 } | 453 } |
| 471 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); | 454 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); |
| 472 if (exceptionState.hadException()) | 455 if (exceptionState.hadException()) |
| 473 return; | 456 return; |
| 474 // FIXME: Only pass context/exceptionState if instance really requires it. | 457 // FIXME: Only pass context/exceptionState if instance really requires it. |
| 475 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); | 458 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); |
| 476 instance->postMessage(context, message.release(), transferables.messagePorts
, exceptionState); | 459 instance->postMessage(context, message.release(), transferables.messagePorts
, exceptionState); |
| 477 } | 460 } |
| 478 {% endmacro %} | 461 {% endmacro %} |
| 479 | 462 |
| 463 |
| 480 {##############################################################################} | 464 {##############################################################################} |
| 481 {% macro method_callback(method, world_suffix) %} | 465 {% macro method_callback(method, world_suffix) %} |
| 482 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) | 466 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) |
| 483 { | 467 { |
| 484 {% if not method.overloads %}{# Overloaded methods are measured in overload_
resolution_method() #} | 468 {% if not method.overloads %}{# Overloaded methods are measured in overload_
resolution_method() #} |
| 485 {% if method.measure_as %} | 469 {% if method.measure_as %} |
| 486 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte
xt(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}}); | 470 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte
xt(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}}); |
| 487 {% endif %} | 471 {% endif %} |
| 488 {% if method.deprecate_as %} | 472 {% if method.deprecate_as %} |
| 489 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx
ecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}}); | 473 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx
ecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}}); |
| 490 {% endif %} | 474 {% endif %} |
| 491 {% endif %}{# not method.overloads #} | 475 {% endif %}{# not method.overloads #} |
| 492 {% if world_suffix in method.activity_logging_world_list %} | 476 {% if world_suffix in method.activity_logging_world_list %} |
| 493 {% if method.is_static %} | 477 {% if method.is_static %} |
| 494 ScriptState* scriptState = ScriptState::forFunctionObject(info); | 478 ScriptState* scriptState = ScriptState::forFunctionObject(info); |
| 495 {% else %} | 479 {% else %} |
| 496 ScriptState* scriptState = ScriptState::forReceiverObject(info); | 480 ScriptState* scriptState = ScriptState::forReceiverObject(info); |
| 497 {% endif %} | 481 {% endif %} |
| 498 V8PerContextData* contextData = scriptState->perContextData(); | 482 V8PerContextData* contextData = scriptState->perContextData(); |
| 499 {% if method.activity_logging_world_check %} | 483 {% if method.activity_logging_world_check %} |
| 500 if (scriptState->world().isIsolatedWorld() && contextData && contextData->ac
tivityLogger()) | 484 if (scriptState->world().isIsolatedWorld() && contextData && contextData->ac
tivityLogger()) |
| 501 {% else %} | 485 {% else %} |
| 502 if (contextData && contextData->activityLogger()) { | 486 if (contextData && contextData->activityLogger()) { |
| 503 {% endif %} | 487 {% endif %} |
| 504 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{metho
d.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 488 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::Executi
onContext, "{{interface_name}}", "{{method.name}}"); |
| 505 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Loc
al<v8::Value>>>(info, 0, exceptionState); | 489 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Loc
al<v8::Value>>>(info, 0, exceptionState); |
| 506 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.na
me}}", info.Length(), loggerArgs.data()); | 490 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.na
me}}", info.Length(), loggerArgs.data()); |
| 507 } | 491 } |
| 508 {% endif %} | 492 {% endif %} |
| 509 {% if method.is_ce_reactions %} | 493 {% if method.is_ce_reactions %} |
| 510 CEReactionsScope ceReactionsScope; | 494 CEReactionsScope ceReactionsScope; |
| 511 {% endif %} | 495 {% endif %} |
| 512 {% if method.is_custom %} | 496 {% if method.is_custom %} |
| 513 {{v8_class}}::{{method.name}}MethodCustom(info); | 497 {{v8_class}}::{{method.name}}MethodCustom(info); |
| 514 {% elif method.is_post_message %} | 498 {% elif method.is_post_message %} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Globa
l(), scriptState->isolate()); | 555 v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Globa
l(), scriptState->isolate()); |
| 572 {% for argument in method.arguments %} | 556 {% for argument in method.arguments %} |
| 573 v8::Local<v8::Value> {{argument.handle}} = {{argument.private_script_cpp_val
ue_to_v8_value}}; | 557 v8::Local<v8::Value> {{argument.handle}} = {{argument.private_script_cpp_val
ue_to_v8_value}}; |
| 574 {% endfor %} | 558 {% endfor %} |
| 575 {% if method.arguments %} | 559 {% if method.arguments %} |
| 576 v8::Local<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}}
}; | 560 v8::Local<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}}
}; |
| 577 {% else %} | 561 {% else %} |
| 578 {# Empty array initializers are illegal, and don\t compile in MSVC. #} | 562 {# Empty array initializers are illegal, and don\t compile in MSVC. #} |
| 579 v8::Local<v8::Value> *argv = 0; | 563 v8::Local<v8::Value> *argv = 0; |
| 580 {% endif %} | 564 {% endif %} |
| 581 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate()
); | 565 ExceptionState exceptionState(scriptState->isolate(), ExceptionState::Execut
ionContext, "{{cpp_class}}", "{{method.name}}"); |
| 582 v8::Local<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState
, scriptStateInUserScript, "{{cpp_class}}", "{{method.name}}", holder, {{method.
arguments | length}}, argv); | 566 v8::Local<v8::Value> v8Value = PrivateScriptRunner::runDOMMethod(scriptState
, scriptStateInUserScript, "{{cpp_class}}", "{{method.name}}", holder, {{method.
arguments | length}}, argv); |
| 583 if (v8Value.IsEmpty()) | 567 if (v8Value.IsEmpty()) |
| 584 return false; | 568 return false; |
| 585 {% if method.idl_type != 'void' %} | 569 {% if method.idl_type != 'void' %} |
| 586 {{v8_value_to_local_cpp_value(method.private_script_v8_value_to_local_cpp_va
lue) | indent}} | 570 {{v8_value_to_local_cpp_value(method.private_script_v8_value_to_local_cpp_va
lue) | indent}} |
| 587 *result = cppValue; | 571 *result = cppValue; |
| 588 {% endif %} | 572 {% endif %} |
| 589 RELEASE_ASSERT(!exceptionState.hadException()); | 573 CHECK(!exceptionState.hadException()); |
| 590 return true; | 574 return true; |
| 591 } | 575 } |
| 592 {% endmacro %} | 576 {% endmacro %} |
| 593 | 577 |
| 594 | 578 |
| 595 {##############################################################################} | 579 {##############################################################################} |
| 596 {% macro generate_constructor(constructor) %} | 580 {% macro generate_constructor(constructor) %} |
| 597 {% set name = '%sConstructorCallback' % v8_class | 581 {% set name = '%sConstructorCallback' % v8_class |
| 598 if constructor.is_named_constructor else | 582 if constructor.is_named_constructor else |
| 599 'constructor%s' % (constructor.overload_index or '') %} | 583 'constructor%s' % (constructor.overload_index or '') %} |
| 600 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info) | 584 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 601 { | 585 { |
| 586 {% set function_call = func_call_with_prep_of_args(constructor) %} |
| 587 |
| 602 {% if constructor.is_named_constructor %} | 588 {% if constructor.is_named_constructor %} |
| 603 if (!info.IsConstructCall()) { | 589 if (!info.IsConstructCall()) { |
| 604 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::c
onstructorNotCallableAsFunction("{{constructor.name}}")); | 590 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::c
onstructorNotCallableAsFunction("{{constructor.name}}")); |
| 605 return; | 591 return; |
| 606 } | 592 } |
| 607 | 593 |
| 608 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExis
tingObject) { | 594 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExis
tingObject) { |
| 609 v8SetReturnValue(info, info.Holder()); | 595 v8SetReturnValue(info, info.Holder()); |
| 610 return; | 596 return; |
| 611 } | 597 } |
| 612 {% endif %} | 598 {% endif %} |
| 613 {% if constructor.has_exception_state %} | 599 |
| 614 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), info.GetIsolate()); | 600 {% if 'exceptionState' in function_call %} |
| 601 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::Constructio
nContext, "{{interface_name}}"); |
| 615 {% endif %} | 602 {% endif %} |
| 616 {# Overloaded constructors have length checked during overload resolution #} | 603 {% if 'scriptState' in function_call %} |
| 617 {% if constructor.number_of_required_arguments and not constructor.overload_
index %} | 604 ScriptState* scriptState = ScriptState::forReceiverObject(info); |
| 618 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ | |
| 619 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ
ired_arguments) | indent(8)}} | |
| 620 } | |
| 621 {% endif %} | 605 {% endif %} |
| 622 {% if constructor.arguments %} | 606 |
| 623 {{generate_arguments(constructor) | indent}} | 607 {{function_call | indent}} |
| 624 {% endif %} | |
| 625 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor.
cpp_value) | indent}} | |
| 626 } | 608 } |
| 627 {% endmacro %} | 609 {% endmacro %} |
| 628 | 610 |
| 629 | 611 |
| 630 {##############################################################################} | 612 {##############################################################################} |
| 631 {% macro generate_constructor_wrapper(constructor) %} | 613 {% macro generate_constructor_wrapper(constructor) %} |
| 632 {% set constructor_class = v8_class + ('Constructor' | 614 {% set constructor_class = v8_class + ('Constructor' |
| 633 if constructor.is_named_constructor else | 615 if constructor.is_named_constructor else |
| 634 '') %} | 616 '') %} |
| 635 v8::Local<v8::Object> wrapper = info.Holder(); | 617 v8::Local<v8::Object> wrapper = info.Holder(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 653 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m
ethod.length}}, {{property_attribute}}, {{only_exposed_to_private_script}}, {{pr
operty_location(method)}}} | 635 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m
ethod.length}}, {{property_attribute}}, {{only_exposed_to_private_script}}, {{pr
operty_location(method)}}} |
| 654 {%- endmacro %} | 636 {%- endmacro %} |
| 655 | 637 |
| 656 | 638 |
| 657 {######################################} | 639 {######################################} |
| 658 {% macro install_custom_signature(method, instance_template, prototype_template,
interface_template, signature) %} | 640 {% macro install_custom_signature(method, instance_template, prototype_template,
interface_template, signature) %} |
| 659 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
= {{method_configuration(method)}}; | 641 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
= {{method_configuration(method)}}; |
| 660 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto
type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon
figuration); | 642 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto
type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon
figuration); |
| 661 {%- endmacro %} | 643 {%- endmacro %} |
| 662 | 644 |
| 645 |
| 663 {######################################} | 646 {######################################} |
| 664 {% macro install_conditionally_enabled_methods() %} | 647 {% macro install_conditionally_enabled_methods() %} |
| 665 {% if methods | conditionally_exposed(is_partial) %} | 648 {% if methods | conditionally_exposed(is_partial) %} |
| 666 {# Define operations with limited exposure #} | 649 {# Define operations with limited exposure #} |
| 667 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTempla
te); | 650 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTempla
te); |
| 668 ExecutionContext* executionContext = toExecutionContext(prototypeObject->Creatio
nContext()); | 651 ExecutionContext* executionContext = toExecutionContext(prototypeObject->Creatio
nContext()); |
| 669 ASSERT(executionContext); | 652 ASSERT(executionContext); |
| 670 {% for method in methods | conditionally_exposed(is_partial) %} | 653 {% for method in methods | conditionally_exposed(is_partial) %} |
| 671 {% filter secure_context(method.overloads.secure_context_test_all | 654 {% filter secure_context(method.overloads.secure_context_test_all |
| 672 if method.overloads else | 655 if method.overloads else |
| 673 method.secure_context_test) %} | 656 method.secure_context_test) %} |
| 674 {% filter exposed(method.overloads.exposed_test_all | 657 {% filter exposed(method.overloads.exposed_test_all |
| 675 if method.overloads else | 658 if method.overloads else |
| 676 method.exposed_test) %} | 659 method.exposed_test) %} |
| 677 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all | 660 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all |
| 678 if method.overloads else | 661 if method.overloads else |
| 679 method.runtime_enabled_function) %} | 662 method.runtime_enabled_function) %} |
| 680 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
= {{method_configuration(method)}}; | 663 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
= {{method_configuration(method)}}; |
| 681 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto
typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); | 664 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto
typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); |
| 682 {% endfilter %}{# runtime_enabled() #} | 665 {% endfilter %}{# runtime_enabled() #} |
| 683 {% endfilter %}{# exposed() #} | 666 {% endfilter %}{# exposed() #} |
| 684 {% endfilter %}{# secure_context() #} | 667 {% endfilter %}{# secure_context() #} |
| 685 {% endfor %} | 668 {% endfor %} |
| 686 {% endif %} | 669 {% endif %} |
| 687 {%- endmacro %} | 670 {%- endmacro %} |
| OLD | NEW |