1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
|
{##############################################################################}
{% macro attribute_getter(attribute, world_suffix) %}
{% filter conditional(attribute.conditional_string) %}
static void {{attribute.name}}AttributeGetter{{world_suffix}}(
{%- if attribute.is_expose_js_accessors %}
const v8::FunctionCallbackInfo<v8::Value>& info
{%- else %}
const v8::PropertyCallbackInfo<v8::Value>& info
{%- endif %})
{
{% if attribute.is_reflect and not attribute.is_url
and attribute.idl_type == 'DOMString' and is_node
and not attribute.is_implemented_in_private_script %}
{% set cpp_class, v8_class = 'Element', 'V8Element' %}
{% endif %}
{# holder #}
{% if not attribute.is_static %}
v8::Local<v8::Object> holder = info.Holder();
{% endif %}
{# impl #}
{% if attribute.cached_attribute_validation_method %}
v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{attribute.name}}");
{{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
if (!impl->{{attribute.cached_attribute_validation_method}}()) {
v8::Local<v8::Value> v8Value = V8HiddenValue::getHiddenValue(info.GetIsolate(), holder, propertyName);
if (!v8Value.IsEmpty()) {
v8SetReturnValue(info, v8Value);
return;
}
}
{% elif not attribute.is_static %}
{{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
{% endif %}
{% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %}
if (!impl->document())
return;
{% endif %}
{# Local variables #}
{% if attribute.is_call_with_execution_context %}
ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
{% endif %}
{% if attribute.is_call_with_script_state %}
ScriptState* scriptState = ScriptState::current(info.GetIsolate());
{% endif %}
{% if attribute.is_check_security_for_node or
attribute.is_getter_raises_exception %}
ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.name}}", "{{interface_name}}", holder, info.GetIsolate());
{% endif %}
{% if attribute.is_explicit_nullable %}
bool isNull = false;
{% endif %}
{% if attribute.is_implemented_in_private_script %}
{{attribute.cpp_type}} result{{attribute.cpp_type_initializer}};
if (!{{attribute.cpp_value_original}})
return;
{% elif attribute.cpp_value_original %}
{{attribute.cpp_type}} {{attribute.cpp_value}}({{attribute.cpp_value_original}});
{% endif %}
{# Checks #}
{% if attribute.is_getter_raises_exception %}
if (UNLIKELY(exceptionState.throwIfNeeded()))
return;
{% endif %}
{% if attribute.is_check_security_for_node %}
if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), {{attribute.cpp_value}}, exceptionState)) {
v8SetReturnValueNull(info);
exceptionState.throwIfNeeded();
return;
}
{% endif %}
{% if attribute.reflect_only %}
{{release_only_check(attribute.reflect_only, attribute.reflect_missing,
attribute.reflect_invalid, attribute.reflect_empty,
attribute.cpp_value)
| indent}}
{% endif %}
{% if attribute.is_explicit_nullable %}
if (isNull) {
v8SetReturnValueNull(info);
return;
}
{% endif %}
{% if attribute.cached_attribute_validation_method %}
V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, propertyName, {{attribute.cpp_value_to_v8_value}});
{% endif %}
{# v8SetReturnValue #}
{% if attribute.is_keep_alive_for_gc %}
if ({{attribute.cpp_value}} && DOMDataStore::setReturnValue{{world_suffix}}(info.GetReturnValue(), {{attribute.cpp_value}}.get()))
return;
v8::Local<v8::Value> wrapper = toV8({{attribute.cpp_value}}.get(), holder, info.GetIsolate());
if (!wrapper.IsEmpty()) {
V8HiddenValue::setHiddenValue(info.GetIsolate(), holder, v8AtomicString(info.GetIsolate(), "{{attribute.name}}"), wrapper);
{{attribute.v8_set_return_value}};
}
{% elif world_suffix %}
{{attribute.v8_set_return_value_for_main_world}};
{% else %}
{% if attribute.use_output_parameter_for_result %}
{{attribute.cpp_type}} result;
{{attribute.cpp_value}};
{% endif %}
{{attribute.v8_set_return_value}};
{% endif %}
}
{% endfilter %}
{% endmacro %}
{######################################}
{% macro release_only_check(reflect_only_values, reflect_missing,
reflect_invalid, reflect_empty, cpp_value) %}
{# Attribute is limited to only known values: check that the attribute value is
one of those. If not, set it to the empty string.
http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known-values #}
{% if reflect_empty %}
if ({{cpp_value}}.isNull()) {
{% if reflect_missing %}
{{cpp_value}} = "{{reflect_missing}}";
{% else %}
;
{% endif %}
} else if ({{cpp_value}}.isEmpty()) {
{{cpp_value}} = "{{reflect_empty}}";
{% else %}
if ({{cpp_value}}.isEmpty()) {
{# FIXME: should use [ReflectEmpty] instead; need to change IDL files #}
{% if reflect_missing %}
{{cpp_value}} = "{{reflect_missing}}";
{% else %}
;
{% endif %}
{% endif %}
{% for value in reflect_only_values %}
} else if (equalIgnoringCase({{cpp_value}}, "{{value}}")) {
{{cpp_value}} = "{{value}}";
{% endfor %}
} else {
{{cpp_value}} = "{{reflect_invalid}}";
}
{% endmacro %}
{##############################################################################}
{% macro attribute_getter_callback(attribute, world_suffix) %}
{% filter conditional(attribute.conditional_string) %}
static void {{attribute.name}}AttributeGetterCallback{{world_suffix}}(
{%- if attribute.is_expose_js_accessors %}
const v8::FunctionCallbackInfo<v8::Value>& info
{%- else %}
v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info
{%- endif %})
{
TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
{% if attribute.deprecate_as %}
UseCounter::countDeprecationIfNotPrivateScript(info.GetIsolate(), callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
{% endif %}
{% if attribute.measure_as %}
UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.measure_as}});
{% endif %}
{% if world_suffix in attribute.activity_logging_world_list_for_getter %}
ScriptState* scriptState = ScriptState::from(info.GetIsolate()->GetCurrentContext());
V8PerContextData* contextData = scriptState->perContextData();
{% if attribute.activity_logging_world_check %}
if (scriptState->world().isIsolatedWorld() && contextData && contextData->activityLogger())
{% else %}
if (contextData && contextData->activityLogger())
{% endif %}
contextData->activityLogger()->logGetter("{{interface_name}}.{{attribute.name}}");
{% endif %}
{% if attribute.has_custom_getter %}
{{v8_class}}::{{attribute.name}}AttributeGetterCustom(info);
{% else %}
{{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeGetter{{world_suffix}}(info);
{% endif %}
TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
}
{% endfilter %}
{% endmacro %}
{##############################################################################}
{% macro constructor_getter_callback(attribute, world_suffix) %}
{% filter conditional(attribute.conditional_string) %}
static void {{attribute.name}}ConstructorGetterCallback{{world_suffix}}(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
{
TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
{% if attribute.deprecate_as %}
UseCounter::countDeprecationIfNotPrivateScript(info.GetIsolate(), callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
{% endif %}
{% if attribute.measure_as %}
UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.measure_as}});
{% endif %}
{{cpp_class_or_partial}}V8Internal::{{cpp_class}}ConstructorGetter{{world_suffix}}(property, info);
TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
}
{% endfilter %}
{% endmacro %}
{##############################################################################}
{% macro attribute_setter(attribute, world_suffix) %}
{% filter conditional(attribute.conditional_string) %}
static void {{attribute.name}}AttributeSetter{{world_suffix}}(
{%- if attribute.is_expose_js_accessors %}
v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info
{%- else %}
v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
{%- endif %})
{
{% if attribute.is_reflect and attribute.idl_type == 'DOMString'
and is_node and not attribute.is_implemented_in_private_script %}
{% set cpp_class, v8_class = 'Element', 'V8Element' %}
{% endif %}
{# Local variables #}
{% if not attribute.is_static %}
v8::Local<v8::Object> holder = info.Holder();
{% endif %}
{% if attribute.has_setter_exception_state %}
ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.name}}", "{{interface_name}}", holder, info.GetIsolate());
{% endif %}
{% if attribute.use_output_parameter_for_result %}
{{attribute.cpp_type}} cppValue;
{% endif %}
{# impl #}
{% if attribute.put_forwards %}
{{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder);
{{attribute.cpp_type}} impl = WTF::getPtr(proxyImpl->{{attribute.name}}());
if (!impl)
return;
{% elif not attribute.is_static %}
{{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
{% endif %}
{% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %}
if (!impl->document())
return;
{% endif %}
{# Convert JS value to C++ value #}
{% if attribute.idl_type != 'EventHandler' %}
{{attribute.v8_value_to_local_cpp_value}};
{% elif not is_node %}{# EventHandler hack #}
moveEventListenerToNewWrapper(info.GetIsolate(), holder, {{attribute.event_handler_getter_expression}}, v8Value, {{v8_class}}::eventListenerCacheIndex);
{% endif %}
{# Type checking, possibly throw a TypeError, per:
http://www.w3.org/TR/WebIDL/#es-type-mapping #}
{% if attribute.has_type_checking_unrestricted %}
{# Non-finite floating point values (NaN, +Infinity or −Infinity), per:
http://heycam.github.io/webidl/#es-float
http://heycam.github.io/webidl/#es-double #}
if (!std::isfinite(cppValue)) {
exceptionState.throwTypeError("The provided {{attribute.idl_type}} value is non-finite.");
exceptionState.throwIfNeeded();
return;
}
{% elif attribute.has_type_checking_interface %}
{# Type checking for interface types (if interface not implemented, throw
TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
if (!cppValue{% if attribute.is_nullable %} && !isUndefinedOrNull(v8Value){% endif %}) {
exceptionState.throwTypeError("The provided value is not of type '{{attribute.idl_type}}'.");
exceptionState.throwIfNeeded();
return;
}
{% elif attribute.enum_validation_expression %}
{# Setter ignores invalid enum values:
http://www.w3.org/TR/WebIDL/#idl-enums #}
String string = cppValue;
if (!({{attribute.enum_validation_expression}}))
return;
{% endif %}
{# Pre-set context #}
{% if attribute.is_custom_element_callbacks or
(attribute.is_reflect and
not(attribute.idl_type == 'DOMString' and is_node)) %}
{# Skip on compact node DOMString getters #}
CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
{% endif %}
{% if attribute.is_call_with_execution_context or
attribute.is_setter_call_with_execution_context %}
ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
{% endif %}
{# Set #}
{{attribute.cpp_setter}};
{# Post-set #}
{% if attribute.is_setter_raises_exception %}
exceptionState.throwIfNeeded();
{% endif %}
{% if attribute.cached_attribute_validation_method %}
V8HiddenValue::deleteHiddenValue(info.GetIsolate(), holder, v8AtomicString(info.GetIsolate(), "{{attribute.name}}")); // Invalidate the cached value.
{% endif %}
}
{% endfilter %}
{% endmacro %}
{##############################################################################}
{% macro attribute_setter_callback(attribute, world_suffix) %}
{% filter conditional(attribute.conditional_string) %}
static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}(
{%- if attribute.is_expose_js_accessors %}
const v8::FunctionCallbackInfo<v8::Value>& info
{%- else %}
v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
{%- endif %})
{
{% if attribute.is_expose_js_accessors %}
v8::Local<v8::Value> v8Value = info[0];
{% endif %}
TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
{% if attribute.deprecate_as %}
UseCounter::countDeprecationIfNotPrivateScript(info.GetIsolate(), callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
{% endif %}
{% if attribute.measure_as %}
UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionContext(info.GetIsolate()), UseCounter::{{attribute.measure_as}});
{% endif %}
{% if world_suffix in attribute.activity_logging_world_list_for_setter %}
ScriptState* scriptState = ScriptState::from(info.GetIsolate()->GetCurrentContext());
V8PerContextData* contextData = scriptState->perContextData();
{% if attribute.activity_logging_world_check %}
if (scriptState->world().isIsolatedWorld() && contextData && contextData->activityLogger()) {
{% else %}
if (contextData && contextData->activityLogger()) {
{% endif %}
contextData->activityLogger()->logSetter("{{interface_name}}.{{attribute.name}}", v8Value);
}
{% endif %}
{% if attribute.is_custom_element_callbacks or attribute.is_reflect %}
CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
{% endif %}
{% if attribute.has_custom_setter %}
{{v8_class}}::{{attribute.name}}AttributeSetterCustom(v8Value, info);
{% else %}
{{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(v8Value, info);
{% endif %}
TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
}
{% endfilter %}
{% endmacro %}
{##############################################################################}
{% macro attribute_getter_implemented_in_private_script(attribute) %}
bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.cpp_type}}* result)
{
if (!frame)
return false;
v8::HandleScope handleScope(toIsolate(frame));
ScriptForbiddenScope::AllowUserAgentScript script;
v8::Local<v8::Context> contextInPrivateScript = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
if (contextInPrivateScript.IsEmpty())
return false;
ScriptState* scriptState = ScriptState::from(contextInPrivateScript);
ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
if (!scriptState->executionContext())
return false;
ScriptState::Scope scope(scriptState);
v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global(), scriptState->isolate());
ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.name}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
v8::Local<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holder);
if (v8Value.IsEmpty())
return false;
{{attribute.private_script_v8_value_to_local_cpp_value}};
RELEASE_ASSERT(!exceptionState.hadException());
*result = cppValue;
return true;
}
{% endmacro %}
{% macro attribute_setter_implemented_in_private_script(attribute) %}
bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.argument_cpp_type}} cppValue)
{
if (!frame)
return false;
v8::HandleScope handleScope(toIsolate(frame));
ScriptForbiddenScope::AllowUserAgentScript script;
v8::Local<v8::Context> contextInPrivateScript = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
if (contextInPrivateScript.IsEmpty())
return false;
ScriptState* scriptState = ScriptState::from(contextInPrivateScript);
ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
if (!scriptState->executionContext())
return false;
ScriptState::Scope scope(scriptState);
v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global(), scriptState->isolate());
ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.name}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
return PrivateScriptRunner::runDOMAttributeSetter(scriptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_script_cpp_value_to_v8_value}});
}
{% endmacro %}
{##############################################################################}
{% macro attribute_configuration(attribute) %}
{% set getter_callback =
'%sV8Internal::%sAttributeGetterCallback' %
(cpp_class_or_partial, attribute.name)
if not attribute.constructor_type else
('%sV8Internal::%sConstructorGetterCallback' %
(cpp_class_or_partial, attribute.name)
if attribute.needs_constructor_getter_callback else
'%sV8Internal::%sConstructorGetter' % (cpp_class_or_partial, cpp_class)) %}
{% set getter_callback_for_main_world =
'%sV8Internal::%sAttributeGetterCallbackForMainWorld' %
(cpp_class_or_partial, attribute.name)
if attribute.is_per_world_bindings else '0' %}
{% set setter_callback = attribute.setter_callback %}
{% set setter_callback_for_main_world =
'%sV8Internal::%sAttributeSetterCallbackForMainWorld' %
(cpp_class_or_partial, attribute.name)
if attribute.is_per_world_bindings and
(not attribute.is_read_only or attribute.put_forwards) else '0' %}
{% set wrapper_type_info =
'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' %
attribute.constructor_type
if attribute.constructor_type else '0' %}
{% set access_control = 'static_cast<v8::AccessControl>(%s)' %
' | '.join(attribute.access_control_list) %}
{% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' %
' | '.join(attribute.property_attributes) %}
{% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivateScript' if attribute.only_exposed_to_private_script else 'V8DOMConfiguration::ExposedToAllScripts' %}
{% set on_prototype = 'V8DOMConfiguration::OnPrototype'
if interface_name == 'Window' and attribute.idl_type == 'EventHandler'
else 'V8DOMConfiguration::OnInstance' %}
{% set attribute_configuration_list = [
'"%s"' % attribute.name,
getter_callback,
setter_callback,
getter_callback_for_main_world,
setter_callback_for_main_world,
wrapper_type_info,
access_control,
property_attribute,
only_exposed_to_private_script,
] %}
{% if not attribute.is_expose_js_accessors %}
{% set attribute_configuration_list = attribute_configuration_list
+ [on_prototype] %}
{% endif %}
{{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}}
{%- endmacro %}
|