OLD | NEW |
(Empty) | |
| 1 {% macro parameters_check(function) %} |
| 2 {% for parameter in function.parameters %}{#### see GenerateParametersCheck #} |
| 3 {# |
| 4 // { {parameter.name} } |
| 5 // { {parameter.is_callback_interface} } |
| 6 #} |
| 7 {% if parameter.early_call %} |
| 8 if (args.Length() <= {{parameter.index}}) { |
| 9 {{function_call(parameter.early_call_statement_parameter) | trim | inden
t}} |
| 10 {# FIXME: whitespace error in V8Entry.cpp, fix Perl CG to remove this line #} |
| 11 } |
| 12 {% endif %} |
| 13 {# TODO if ($parameter->isOptional && !$parameter->extendedAttributes->{"Default
"} && $nativeType ne "Dictionary" && !IsCallbackInterface($parameter->type)) { #
} |
| 14 {# TODO if ($parameter->isOptional and $default eq "NullString") { #} |
| 15 {% if parameter.is_callback_interface %}{###########################} |
| 16 {% if parameter.is_optional %} |
| 17 RefPtr<{{parameter.type}}> {{parameter.name}}; |
| 18 if (args.Length() > {{parameter.index}} && !args[{{parameter.index}}]->IsNul
l() && !args[{{parameter.index}}]->IsUndefined()) { |
| 19 if (!args[{{parameter.index}}]->IsFunction()) { |
| 20 throwTypeError(args.GetIsolate()); |
| 21 return; |
| 22 } |
| 23 {{parameter.name}} = V8{{parameter.type}}::create(args[{{parameter.index
}}], getScriptExecutionContext()); |
| 24 } |
| 25 {% else %} |
| 26 if (args.Length() <= {{parameter.index}} || !args[{{parameter.index}}]->IsFu
nction()) { |
| 27 throwTypeError(args.GetIsolate()); |
| 28 return; |
| 29 } |
| 30 RefPtr<{{parameter.type}}> {{parameter.name}} = V8{{parameter.type}}::create
(args[{{parameter.index}}], getScriptExecutionContext()); |
| 31 {% endif %} |
| 32 {% elif parameter.clamp %}{###########################} |
| 33 {{parameter.type}} {{parameter.name}}NativeValue = 0; |
| 34 V8TRYCATCH_VOID(double, $nativeValue, args[{{parameter.index}}]->NumberValue
()); |
| 35 if (!std::isnan({{parameter.name}}NativeValue)) |
| 36 {{parameter.name}}NativeValue = clampTo<{{parameter.type}}>({{parameter.
name}}NativeValue); |
| 37 {% elif parameter.type == "SerializedScriptValue" %}{###########################
} |
| 38 bool {{parameter.name}}DidThrow = false; |
| 39 {{parameter.naive_type}} {{parameter.name}} = SerializedScriptValue::create(
args[{{parameter.index}}], 0, 0, {{parameter.name}}DidThrow, args.GetIsolate()); |
| 40 if ({{parameter.name}}DidThrow) |
| 41 return; |
| 42 {% elif parameter.is_variadic %}{###########################} |
| 43 {% if parameter.is_wrapper_type %} |
| 44 Vector<{{parameter.native_type}}> {{parameter.name}}; |
| 45 for (int i = {{parameter.index}}; i < args.Length(); ++i) { |
| 46 if (!V8{{parameter.type}}::HasInstance(args[i], args.GetIsolate(), world
Type(args.GetIsolate()))) { |
| 47 throwTypeError(args.GetIsolate()); |
| 48 return; |
| 49 } |
| 50 {{parameter.name}}.append(V8{{parameter.type}}::toNative(v8::Handle<v8::
Object>::Cast(args[i]))); |
| 51 } |
| 52 {% else %} |
| 53 V8TRYCATCH_VOID(Vector<{{parameter.native_element_type}}>, {{parameter.name}
}, toNativeArguments<{{parameter.native_element_type}}>(args, {{parameter.index}
})); |
| 54 {% endif %} |
| 55 {% elif parameter.is_string %}{###########################} |
| 56 {{parameter.convert_to_v8_string_resource}} |
| 57 {% if parameter.is_enum_type %} |
| 58 String string = {{parameter.name}}; |
| 59 if (!({{parameter.enum_validation_expression}})) { |
| 60 throwTypeError(args.GetIsolate()); |
| 61 return; |
| 62 } |
| 63 {% endif %} |
| 64 {% else %}{###########################} |
| 65 {# |
| 66 If the "StrictTypeChecking" extended attribute is present, and the argument'
s type is an |
| 67 interface type, then if the incoming value does not implement that interface
, a TypeError |
| 68 is thrown rather than silently passing NULL to the C++ code. |
| 69 Per the Web IDL and ECMAScript specifications, incoming values can always be
converted |
| 70 to both strings and numbers, so do not throw TypeError if the argument is of
these |
| 71 types. |
| 72 #} |
| 73 {# TODO #} |
| 74 {% if parameter.strict_type_checking and parameter.is_wrapper_type %} |
| 75 if (args.Length() > {{parameter.index}} && !isUndefinedOrNull(arg[{{paramete
r.index}}]) && !V8{{parameter.type}}::HasInstance(arg[{{parameter.index}}], args
.GetIsolate(), worldType(args.GetIsolate()))) { |
| 76 throwTypeError(args.GetIsolate()); |
| 77 return; |
| 78 } |
| 79 {% endif %} |
| 80 {################# JS to native #} |
| 81 {{parameter.js_to_native_statement}} |
| 82 {% if parameter.native_type == "Dictionary" %} |
| 83 if (!{{parameter.name}}.isUndefinedOrNull() && !{{parameter.name}}.isObject(
)) { |
| 84 throwTypeError("Not an object.", args.GetIsolate()); |
| 85 return; |
| 86 } |
| 87 {% endif %} |
| 88 {% endif %} |
| 89 {% if parameter.is_index %} |
| 90 if (UNLIKELY({{parameter.name}} < 0)) { |
| 91 setDOMException(IndexSizeError, args.GetIsolate()); |
| 92 return; |
| 93 } |
| 94 {% endif %} |
| 95 {% endfor %} |
| 96 {% endmacro %} |
| 97 |
| 98 |
| 99 {##############################################################################} |
| 100 {% macro function_call(function_call) %} |
| 101 {{call_with_statements(function_call.call_with) -}} |
| 102 {% for parameter in function_call.parameters %} |
| 103 {% if parameter.svg_tear_off_and_not_list %} |
| 104 if (!{{parameter.name}}) { |
| 105 setDOMException(WebCore::TypeMismatchError, args.GetIsolate()); |
| 106 return; |
| 107 } |
| 108 {% endif %} |
| 109 {% endfor %} |
| 110 {% if function_call.statement %} |
| 111 {{function_call.statement | indent}} |
| 112 {% endif %} |
| 113 {% if function_call.raises_exception %} |
| 114 if (es.throwIfNeeded()) |
| 115 return; |
| 116 {% endif %} |
| 117 {% if function_call.extended_attribute_contains_script_state %} |
| 118 if (state.hadException()) { |
| 119 v8::Local<v8::Value> exception = state.exception(); |
| 120 state.clearException(); |
| 121 throwError(exception); |
| 122 return; |
| 123 } |
| 124 {% endif %} |
| 125 {% if function_call.svg_tear_off_and_not_list %} |
| 126 {% if function_call.is_dom_node_type %} |
| 127 v8SetReturnValue(args, toV8Fast{{function_call.for_main_world_suffix}}(WTF::
getPtr({{function_call.svg_native_type}}::create({{function_call.native_value_ex
pression}})), args, imp)); |
| 128 {% else %} |
| 129 v8SetReturnValue(args, toV8{{function_call.for_main_world_suffix}}(WTF::getP
tr({{function_call.svg_native_type}}::create({{function_call.native_value_expres
sion}})), args.Holder(), args.GetIsolate())); |
| 130 {% endif %} |
| 131 return; |
| 132 {% else %} |
| 133 {% if function_call.return_js_value_statement %} |
| 134 {{function_call.return_js_value_statement | indent}} |
| 135 {% else %} |
| 136 |
| 137 {% endif %} |
| 138 return; |
| 139 {% endif %} |
| 140 {% endmacro %} |
| 141 |
| 142 |
| 143 {##############################################################################} |
| 144 {% macro feature_observation(measure_as) %} |
| 145 {% if measure_as %} |
| 146 UseCounter::count(activeDOMWindow(), UseCounter::{{measure_as}}); |
| 147 {% endif %} |
| 148 {% endmacro %} |
| 149 |
| 150 |
| 151 {##############################################################################} |
| 152 {% macro deprecation_notification(deprecate_as) %} |
| 153 {% if deprecate_as %} |
| 154 UseCounter::countDeprecation(activeDOMWindow(), UseCounter::{{deprecate_as}}
); |
| 155 {% endif %} |
| 156 {% endmacro %} |
| 157 |
| 158 |
| 159 {##############################################################################} |
| 160 {% macro call_with_statements(call_with) %} |
| 161 {% if call_with %} |
| 162 {% if call_with.script_state %} |
| 163 ScriptState* currentState = ScriptState::current(); |
| 164 if (!currentState) |
| 165 return{{script_state_return_value}}; |
| 166 ScriptState& state = *currentState; |
| 167 {% endif %} |
| 168 {% if call_with.script_execution_context %} |
| 169 ScriptExecutionContext* scriptContext = getScriptExecutionContext(); |
| 170 {%- endif %} |
| 171 {% if call_with.function and call_with.script_arguments %} |
| 172 |
| 173 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(args, {{call_w
ith.number_of_function_parameters}})); |
| 174 {% endif %} |
| 175 {% endif %} |
| 176 {%- endmacro %} |
| 177 |
| 178 |
| 179 {##############################################################################} |
| 180 {% macro activity_logging(access_type, property_name) %} |
| 181 {% if access_type == "Method" %} |
| 182 V8PerContextData* contextData = V8PerContextData::from(args.GetIsolate()->Ge
tCurrentContext()); |
| 183 if (contextData && contextData->activityLogger()) { |
| 184 Vector<v8::Handle<v8::Value> > loggerArgs = toVectorOfArguments(args); |
| 185 contextData->activityLogger()->log("{{interface_name}}.{{property_name}}
", args.Length(), loggerArgs.data(), "{{access_type}}"); |
| 186 } |
| 187 {% endif %} |
| 188 {% if access_type == "Setter" %} |
| 189 V8PerContextData* contextData = V8PerContextData::from(info.GetIsolate()->Ge
tCurrentContext()); |
| 190 if (contextData && contextData->activityLogger()) { |
| 191 v8::Handle<v8::Value> loggerArg[] = { value }; |
| 192 contextData->activityLogger()->log("{{interface_name}}.{{property_name}}
", 1, &loggerArg[0], "{{access_type}}"); |
| 193 } |
| 194 {% endif %} |
| 195 {% if access_type == "Getter" %} |
| 196 V8PerContextData* contextData = V8PerContextData::from(info.GetIsolate()->Ge
tCurrentContext()); |
| 197 if (contextData && contextData->activityLogger()) |
| 198 contextData->activityLogger()->log("{{interface_name}}.{{property_name}}
", 0, 0, "{{access_type}}"); |
| 199 {% endif %} |
| 200 {%- endmacro %} |
| 201 |
| 202 |
| 203 {##############################################################################} |
| 204 {# user: replaceable attr setter, normal attr setter, normal attr setter callbac
k, function #} |
| 205 {% macro custom_element_invocation(custom_element_invocation_scope) %} |
| 206 {% if custom_element_invocation_scope %} |
| 207 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 208 {% endif %} |
| 209 {% endmacro %} |
| 210 |
| 211 |
| 212 {##############################################################################} |
| 213 {% macro method(function, for_main_world_suffix) %} |
| 214 {% if function.conditional_string %} |
| 215 #if {{function.conditional_string}} |
| 216 {% endif %} |
| 217 static void {{function.name}}Method{{for_main_world_suffix}}(const v8::FunctionC
allbackInfo<v8::Value>& args) |
| 218 { |
| 219 {% if function.mandatory_parameters %} |
| 220 if (args.Length() < {{function.mandatory_parameters}}) { |
| 221 throwNotEnoughArgumentsError(args.GetIsolate()); |
| 222 return; |
| 223 } |
| 224 {% endif %} |
| 225 {###################### Get imp #} |
| 226 {% if not function.is_static %} |
| 227 {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(args.Holder()); |
| 228 {% endif %} |
| 229 {{custom_element_invocation(function.custom_element_invocation_scope) -}} |
| 230 {% if function.raises_exception %} |
| 231 ExceptionState es(args.GetIsolate()); |
| 232 {% endif %} |
| 233 {% if function.check_security_for_node %} |
| 234 if (!BindingSecurity::shouldAllowAccessToNode(imp->{{function.cpp_name}}(es)
)) { |
| 235 v8SetReturnValueNull(args); |
| 236 return; |
| 237 } |
| 238 {% endif %} |
| 239 {{parameters_check(function) -}} |
| 240 {{function_call(function.function_call_parameter[for_main_world_suffix]) -}} |
| 241 } |
| 242 |
| 243 {% if function.conditional_string %} |
| 244 #endif // {{function.conditional_string}} |
| 245 {% endif %} |
| 246 {% endmacro %} |
| 247 |
| 248 |
| 249 {##############################################################################} |
| 250 {% macro method_callback(function, for_main_world_suffix) %} |
| 251 {% if function.name %} |
| 252 {% if function.conditional_string %} |
| 253 #if {{function.conditional_string}} |
| 254 {% endif %} |
| 255 static void {{function.name}}MethodCallback{{function.for_main_world_suffix}}(co
nst v8::FunctionCallbackInfo<v8::Value>& args) |
| 256 { |
| 257 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); |
| 258 {{feature_observation(function.measure_as) -}} |
| 259 {{deprecation_notification(function.deprecate_as) -}} |
| 260 {% if for_main_world_suffix in function.activity_logging %} |
| 261 {{activity_logging("Method", function.name)}} |
| 262 {% endif %} |
| 263 {% if function.is_custom %} |
| 264 {{v8_class_name}}::{{function.name}}MethodCustom(args); |
| 265 {% else %} |
| 266 {{cpp_class_name}}V8Internal::{{function.name}}Method{{function.for_main_wor
ld_suffix}}(args); |
| 267 {% endif %} |
| 268 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); |
| 269 } |
| 270 |
| 271 {% if function.conditional_string %} |
| 272 #endif // {{function.conditional_string}} |
| 273 {% endif %} |
| 274 {% endif %} |
| 275 {% endmacro %} |
| 276 |
| 277 |
| 278 {##############################################################################} |
| 279 {% macro if_else_statement(type, variable_name, condition_and_statements) %} |
| 280 {% if condition_and_statements | length == 1 %} |
| 281 {{type}} {{variable_name}} = {{condition_and_statements[0]["statement"]}} |
| 282 {% else %} |
| 283 {{type}} {{variable_name}}; |
| 284 {% for condition_and_statement in condition_and_statements %} |
| 285 {% if loop.first %} |
| 286 if{% elif loop.last %} |
| 287 |
| 288 else{% else %} |
| 289 |
| 290 else if{% endif %} |
| 291 {% if condition_and_statement["condition"] %} ({{condition_and_statement["condit
ion"]}}) |
| 292 {% else %} |
| 293 |
| 294 {% endif %} |
| 295 {{variable_name}} = {{condition_and_statement["statement"]}} |
| 296 {%- endfor %} |
| 297 {% endif %} |
| 298 {% endmacro %} |
OLD | NEW |