1 {% extends 'interface_base.cpp' %}
4 {##############################################################################}
5 {% macro attribute_configuration(attribute) %}
6 {% set getter_callback =
7 '%sV8Internal::%sAttributeGetterCallback' %
8 (cpp_class, attribute.name)
9 if not attribute.constructor_type else
10 '{0}V8Internal::{0}ConstructorGetter'.format(cpp_class) %}
11 {% set getter_callback_for_main_world =
12 '%sV8Internal::%sAttributeGetterCallbackForMainWorld' %
13 (cpp_class, attribute.name)
14 if attribute.is_per_world_bindings else '0' %}
15 {% set setter_callback = attribute.setter_callback %}
16 {% set setter_callback_for_main_world =
17 '%sV8Internal::%sAttributeSetterCallbackForMainWorld' %
18 (cpp_class, attribute.name)
19 if attribute.is_per_world_bindings and
20 (not attribute.is_read_only or attribute.put_forwards) else '0' %}
21 {% set wrapper_type_info =
22 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' %
23 attribute.constructor_type
24 if attribute.constructor_type else '0' %}
25 {% set access_control = 'static_cast<v8::AccessControl>(%s)' %
26 ' | '.join(attribute.access_control_list) %}
27 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' %
28 ' | '.join(attribute.property_attributes) %}
29 {% set on_prototype = '1 /* on prototype */'
30 if interface_name == 'Window' and attribute.idl_type == 'EventHandler'
31 else '0 /* on instance */' %}
32 {% set attribute_configuration_list = [
33 '"%s"' % attribute.name,
36 getter_callback_for_main_world,
37 setter_callback_for_main_world,
42 {% if not attribute.is_expose_js_accessors %}
43 {% set attribute_configuration_list = attribute_configuration_list
46 {{'{'}}{{attribute_configuration_list|join(', ')}}{{'}'}}
50 {##############################################################################}
51 {% macro method_configuration(method) %}
52 {% set method_callback =
53 '%sV8Internal::%sMethodCallback' % (cpp_class, method.name) %}
54 {% set method_callback_for_main_world =
55 '%sV8Internal::%sMethodCallbackForMainWorld' % (cpp_class, method.name)
56 if method.is_per_world_bindings else '0' %}
57 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{method.number_of_required_or_variadic_arguments}}}
61 {##############################################################################}
62 {% block constructor_getter %}
63 {% if has_constructor_attributes %}
64 static void {{cpp_class}}ConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
66 v8::Handle<v8::Value> data = info.Data();
67 ASSERT(data->IsExternal());
68 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext());
71 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data)));
78 {##############################################################################}
79 {% block replaceable_attribute_setter_and_callback %}
80 {% if has_replaceable_attributes or has_constructor_attributes %}
81 {# FIXME: rename to ForceSetAttributeOnThis, since also used for Constructors #}
82 static void {{cpp_class}}ReplaceableAttributeSetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
84 {% if is_check_security %}
85 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
86 v8::String::Utf8Value attributeName(name);
87 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "{{interface_name}}", info.Holder(), info.GetIsolate());
88 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame(), exceptionState)) {
89 exceptionState.throwIfNeeded();
93 info.This()->ForceSet(name, jsValue);
96 {# FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors #}
97 static void {{cpp_class}}ReplaceableAttributeSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
99 {{cpp_class}}V8Internal::{{cpp_class}}ReplaceableAttributeSetter(name, jsValue, info);
106 {##############################################################################}
107 {% block security_check_functions %}
108 {% if is_check_security and interface_name != 'Window' %}
109 bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>)
111 {{cpp_class}}* imp = {{v8_class}}::toNative(host);
112 return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), imp->frame(), DoNotReportSecurityError);
115 bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
117 {{cpp_class}}* imp = {{v8_class}}::toNative(host);
118 return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), imp->frame(), DoNotReportSecurityError);
125 {##############################################################################}
126 {% block indexed_property_getter %}
127 {% if indexed_property_getter and not indexed_property_getter.is_custom %}
128 {% set getter = indexed_property_getter %}
129 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
131 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
132 {% if getter.is_raises_exception %}
133 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
135 {% set getter_name = getter.name or 'anonymousIndexedGetter' %}
136 {% set getter_arguments = ['index', 'exceptionState']
137 if getter.is_raises_exception else ['index'] %}
138 {{getter.cpp_type}} result = imp->{{getter_name}}({{getter_arguments|join(', ')}});
139 {% if getter.is_raises_exception %}
140 if (exceptionState.throwIfNeeded())
143 if ({{getter.is_null_expression}})
145 {{getter.v8_set_return_value}};
152 {##############################################################################}
153 {% block indexed_property_getter_callback %}
154 {% if indexed_property_getter %}
155 {% set getter = indexed_property_getter %}
156 static void indexedPropertyGetterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
158 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
159 {% if getter.is_custom %}
160 {{v8_class}}::indexedPropertyGetterCustom(index, info);
162 {{cpp_class}}V8Internal::indexedPropertyGetter(index, info);
164 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
171 {##############################################################################}
172 {% block indexed_property_setter %}
173 {% if indexed_property_setter and not indexed_property_setter.is_custom %}
174 {% set setter = indexed_property_setter %}
175 static void indexedPropertySetter(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
177 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
178 {{setter.v8_value_to_local_cpp_value}};
179 {% if setter.has_exception_state %}
180 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
182 {% if setter.has_strict_type_checking %}
183 {# Type checking for interface types (if interface not implemented, throw
184 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
185 if (!isUndefinedOrNull(jsValue) && !V8{{setter.idl_type}}::hasInstance(jsValue, info.GetIsolate())) {
186 exceptionState.throwTypeError("The provided value is not of type '{{setter.idl_type}}'.");
187 exceptionState.throwIfNeeded();
191 {% set setter_name = setter.name or 'anonymousIndexedSetter' %}
192 {% set setter_arguments = ['index', 'propertyValue', 'exceptionState']
193 if setter.is_raises_exception else ['index', 'propertyValue'] %}
194 bool result = imp->{{setter_name}}({{setter_arguments|join(', ')}});
195 {% if setter.is_raises_exception %}
196 if (exceptionState.throwIfNeeded())
201 v8SetReturnValue(info, jsValue);
208 {##############################################################################}
209 {% block indexed_property_setter_callback %}
210 {% if indexed_property_setter %}
211 {% set setter = indexed_property_setter %}
212 static void indexedPropertySetterCallback(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
214 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
215 {% if setter.is_custom %}
216 {{v8_class}}::indexedPropertySetterCustom(index, jsValue, info);
218 {{cpp_class}}V8Internal::indexedPropertySetter(index, jsValue, info);
220 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
227 {##############################################################################}
228 {% block indexed_property_deleter %}
229 {% if indexed_property_deleter and not indexed_property_deleter.is_custom %}
230 {% set deleter = indexed_property_deleter %}
231 static void indexedPropertyDeleter(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info)
233 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
234 {% if deleter.is_raises_exception %}
235 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
237 {% set deleter_name = deleter.name or 'anonymousIndexedDeleter' %}
238 {% set deleter_arguments = ['index', 'exceptionState']
239 if deleter.is_raises_exception else ['index'] %}
240 DeleteResult result = imp->{{deleter_name}}({{deleter_arguments|join(', ')}});
241 {% if deleter.is_raises_exception %}
242 if (exceptionState.throwIfNeeded())
245 if (result != DeleteUnknownProperty)
246 return v8SetReturnValueBool(info, result == DeleteSuccess);
253 {##############################################################################}
254 {% block indexed_property_deleter_callback %}
255 {% if indexed_property_deleter %}
256 {% set deleter = indexed_property_deleter %}
257 static void indexedPropertyDeleterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info)
259 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
260 {% if deleter.is_custom %}
261 {{v8_class}}::indexedPropertyDeleterCustom(index, info);
263 {{cpp_class}}V8Internal::indexedPropertyDeleter(index, info);
265 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
272 {##############################################################################}
273 {% from 'methods.cpp' import union_type_method_call %}
274 {% block named_property_getter %}
275 {% if named_property_getter and not named_property_getter.is_custom %}
276 {% set getter = named_property_getter %}
277 static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
279 {% if not is_override_builtins %}
280 if (info.Holder()->HasRealNamedProperty(name))
282 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
286 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
287 AtomicString propertyName = toCoreAtomicString(name);
288 {% if getter.is_raises_exception %}
289 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
291 {% if getter.union_arguments %}
292 {{union_type_method_call(getter) | indent}}
294 {{getter.cpp_type}} result = {{getter.cpp_value}};
295 {% if getter.is_raises_exception %}
296 if (exceptionState.throwIfNeeded())
299 if ({{getter.is_null_expression}})
301 {{getter.v8_set_return_value}};
309 {##############################################################################}
310 {% block named_property_getter_callback %}
311 {% if named_property_getter %}
312 {% set getter = named_property_getter %}
313 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
315 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
316 {% if getter.is_custom %}
317 {{v8_class}}::namedPropertyGetterCustom(name, info);
319 {{cpp_class}}V8Internal::namedPropertyGetter(name, info);
321 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
328 {##############################################################################}
329 {% block named_property_setter %}
330 {% if named_property_setter and not named_property_setter.is_custom %}
331 {% set setter = named_property_setter %}
332 static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
334 {% if not is_override_builtins %}
335 if (info.Holder()->HasRealNamedProperty(name))
337 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
341 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
342 {# v8_value_to_local_cpp_value('DOMString', 'name', 'propertyName') #}
343 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, propertyName, name);
344 {{setter.v8_value_to_local_cpp_value}};
345 {% if setter.has_exception_state %}
346 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
348 {% set setter_name = setter.name or 'anonymousNamedSetter' %}
349 {% set setter_arguments =
350 ['propertyName', 'propertyValue', 'exceptionState']
351 if setter.is_raises_exception else
352 ['propertyName', 'propertyValue'] %}
353 bool result = imp->{{setter_name}}({{setter_arguments|join(', ')}});
354 {% if setter.is_raises_exception %}
355 if (exceptionState.throwIfNeeded())
360 v8SetReturnValue(info, jsValue);
367 {##############################################################################}
368 {% block named_property_setter_callback %}
369 {% if named_property_setter %}
370 {% set setter = named_property_setter %}
371 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
373 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
374 {% if setter.is_custom %}
375 {{v8_class}}::namedPropertySetterCustom(name, jsValue, info);
377 {{cpp_class}}V8Internal::namedPropertySetter(name, jsValue, info);
379 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
386 {##############################################################################}
387 {% block named_property_query %}
388 {% if named_property_getter and named_property_getter.is_enumerable and
389 not named_property_getter.is_custom_property_query %}
390 {# If there is an enumerator, there MUST be a query method to properly
391 communicate property attributes. #}
392 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
394 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
395 AtomicString propertyName = toCoreAtomicString(name);
396 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
397 bool result = imp->namedPropertyQuery(propertyName, exceptionState);
398 if (exceptionState.throwIfNeeded())
402 v8SetReturnValueInt(info, v8::None);
409 {##############################################################################}
410 {% block named_property_query_callback %}
411 {% if named_property_getter and named_property_getter.is_enumerable %}
412 {% set getter = named_property_getter %}
413 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
415 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
416 {% if getter.is_custom_property_query %}
417 {{v8_class}}::namedPropertyQueryCustom(name, info);
419 {{cpp_class}}V8Internal::namedPropertyQuery(name, info);
421 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
428 {##############################################################################}
429 {% block named_property_deleter %}
430 {% if named_property_deleter and not named_property_deleter.is_custom %}
431 {% set deleter = named_property_deleter %}
432 static void namedPropertyDeleter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)
434 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
435 AtomicString propertyName = toCoreAtomicString(name);
436 {% if deleter.is_raises_exception %}
437 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
439 {% set deleter_name = deleter.name or 'anonymousNamedDeleter' %}
440 {% set deleter_arguments = ['propertyName', 'exceptionState']
441 if deleter.is_raises_exception else ['propertyName'] %}
442 DeleteResult result = imp->{{deleter_name}}({{deleter_arguments|join(', ')}});
443 {% if deleter.is_raises_exception %}
444 if (exceptionState.throwIfNeeded())
447 if (result != DeleteUnknownProperty)
448 return v8SetReturnValueBool(info, result == DeleteSuccess);
455 {##############################################################################}
456 {% block named_property_deleter_callback %}
457 {% if named_property_deleter %}
458 {% set deleter = named_property_deleter %}
459 static void namedPropertyDeleterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)
461 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
462 {% if deleter.is_custom %}
463 {{v8_class}}::namedPropertyDeleterCustom(name, info);
465 {{cpp_class}}V8Internal::namedPropertyDeleter(name, info);
467 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
474 {##############################################################################}
475 {% block named_property_enumerator %}
476 {% if named_property_getter and named_property_getter.is_enumerable and
477 not named_property_getter.is_custom_property_enumerator %}
478 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
480 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
481 Vector<String> names;
482 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
483 imp->namedPropertyEnumerator(names, exceptionState);
484 if (exceptionState.throwIfNeeded())
486 v8::Handle<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size());
487 for (size_t i = 0; i < names.size(); ++i)
488 v8names->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.GetIsolate(), names[i]));
489 v8SetReturnValue(info, v8names);
496 {##############################################################################}
497 {% block named_property_enumerator_callback %}
498 {% if named_property_getter and named_property_getter.is_enumerable %}
499 {% set getter = named_property_getter %}
500 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info)
502 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
503 {% if getter.is_custom_property_enumerator %}
504 {{v8_class}}::namedPropertyEnumeratorCustom(info);
506 {{cpp_class}}V8Internal::namedPropertyEnumerator(info);
508 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
515 {##############################################################################}
516 {% block origin_safe_method_setter %}
517 {% if has_origin_safe_method_setter %}
518 static void {{cpp_class}}OriginSafeMethodSetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
520 {# FIXME: don't call GetIsolate 3 times #}
521 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain({{v8_class}}::domTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
522 if (holder.IsEmpty())
524 {{cpp_class}}* imp = {{v8_class}}::toNative(holder);
525 v8::String::Utf8Value attributeName(name);
526 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "{{interface_name}}", info.Holder(), info.GetIsolate());
527 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame(), exceptionState)) {
528 exceptionState.throwIfNeeded();
532 setHiddenValue(info.GetIsolate(), info.This(), name, jsValue);
535 static void {{cpp_class}}OriginSafeMethodSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
537 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
538 {{cpp_class}}V8Internal::{{cpp_class}}OriginSafeMethodSetter(name, jsValue, info);
539 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
546 {##############################################################################}
547 {% from 'methods.cpp' import named_constructor_callback with context %}
548 {% block named_constructor %}
549 {% if named_constructor %}
550 {% set to_active_dom_object = '%s::toActiveDOMObject' % v8_class
551 if is_active_dom_object else '0' %}
552 {% set to_event_target = '%s::toEventTarget' % v8_class
553 if is_event_target else '0' %}
554 const WrapperTypeInfo {{v8_class}}Constructor::wrapperTypeInfo = { gin::kEmbedderBlink, {{v8_class}}Constructor::domTemplate, {{v8_class}}::derefObject, {{to_active_dom_object}}, {{to_event_target}}, 0, {{v8_class}}::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
556 {{named_constructor_callback(named_constructor)}}
557 v8::Handle<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
559 // This is only for getting a unique pointer which we can pass to privateTemplate.
560 static int privateTemplateUniqueKey;
561 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
562 v8::Local<v8::FunctionTemplate> result = data->privateTemplateIfExists(currentWorldType, &privateTemplateUniqueKey);
563 if (!result.IsEmpty())
566 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
567 v8::EscapableHandleScope scope(isolate);
568 result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback);
570 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
571 instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount);
572 result->SetClassName(v8AtomicString(isolate, "{{cpp_class}}"));
573 result->Inherit({{v8_class}}::domTemplate(isolate, currentWorldType));
574 data->setPrivateTemplate(currentWorldType, &privateTemplateUniqueKey, result);
576 return scope.Escape(result);
582 {##############################################################################}
583 {% block overloaded_constructor %}
584 {% if constructors|length > 1 %}
585 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
587 {% for constructor in constructors %}
588 if ({{constructor.overload_resolution_expression}}) {
589 {{cpp_class}}V8Internal::constructor{{constructor.overload_index}}(info);
593 {% if interface_length %}
594 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), info.GetIsolate());
595 if (UNLIKELY(info.Length() < {{interface_length}})) {
596 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{interface_length}}, info.Length()));
597 exceptionState.throwIfNeeded();
600 exceptionState.throwTypeError("No matching constructor signature.");
601 exceptionState.throwIfNeeded();
603 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", "No matching constructor signature."), info.GetIsolate());
611 {##############################################################################}
612 {% block event_constructor %}
613 {% if has_event_constructor %}
614 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
616 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), info.GetIsolate());
617 if (info.Length() < 1) {
618 exceptionState.throwTypeError("An event name must be provided.");
619 exceptionState.throwIfNeeded();
623 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]);
624 {% for attribute in any_type_attributes %}
625 v8::Local<v8::Value> {{attribute.name}};
627 {{cpp_class}}Init eventInit;
628 if (info.Length() >= 2) {
629 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate()));
630 if (!initialize{{cpp_class}}(eventInit, options, exceptionState, info)) {
631 exceptionState.throwIfNeeded();
634 {# Store attributes of type |any| on the wrapper to avoid leaking them
635 between isolated worlds. #}
636 {% for attribute in any_type_attributes %}
637 options.get("{{attribute.name}}", {{attribute.name}});
638 if (!{{attribute.name}}.IsEmpty())
639 setHiddenValue(info.GetIsolate(), info.Holder(), "{{attribute.name}}", {{attribute.name}});
642 {% if is_constructor_raises_exception %}
643 RefPtr<{{cpp_class}}> event = {{cpp_class}}::create(type, eventInit, exceptionState);
644 if (exceptionState.throwIfNeeded())
647 RefPtr<{{cpp_class}}> event = {{cpp_class}}::create(type, eventInit);
649 {% if any_type_attributes and not interface_name == 'ErrorEvent' %}
650 {# If we're in an isolated world, create a SerializedScriptValue and store
651 it in the event for later cloning if the property is accessed from
652 another world. The main world case is handled lazily (in custom code).
654 We do not clone Error objects (exceptions), for 2 reasons:
655 1) Errors carry a reference to the isolated world's global object, and
656 thus passing it around would cause leakage.
657 2) Errors cannot be cloned (or serialized):
658 http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#safe-passing-of-structured-data #}
659 if (isolatedWorldForIsolate(info.GetIsolate())) {
660 {% for attribute in any_type_attributes %}
661 if (!{{attribute.name}}.IsEmpty())
662 event->setSerialized{{attribute.name | blink_capitalize}}(SerializedScriptValue::createAndSwallowExceptions({{attribute.name}}, info.GetIsolate()));
667 v8::Handle<v8::Object> wrapper = info.Holder();
668 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(event.release(), &{{v8_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
669 v8SetReturnValue(info, wrapper);
676 {##############################################################################}
677 {% block visit_dom_wrapper %}
678 {% if reachable_node_function or set_wrapper_reference_to_list %}
679 void {{v8_class}}::visitDOMWrapper(void* object, const v8::Persistent<v8::Object>& wrapper, v8::Isolate* isolate)
681 {{cpp_class}}* impl = fromInternalPointer(object);
682 {% if set_wrapper_reference_to_list %}
683 v8::Local<v8::Object> creationContext = v8::Local<v8::Object>::New(isolate, wrapper);
684 V8WrapperInstantiationScope scope(creationContext, isolate);
685 {% for set_wrapper_reference_to in set_wrapper_reference_to_list %}
686 {{set_wrapper_reference_to.idl_type}}* {{set_wrapper_reference_to.name}} = impl->{{set_wrapper_reference_to.name}}();
687 if ({{set_wrapper_reference_to.name}}) {
688 if (!DOMDataStore::containsWrapper<{{set_wrapper_reference_to.v8_type}}>({{set_wrapper_reference_to.name}}, isolate))
689 wrap({{set_wrapper_reference_to.name}}, creationContext, isolate);
690 DOMDataStore::setWrapperReference<{{set_wrapper_reference_to.v8_type}}>(wrapper, {{set_wrapper_reference_to.name}}, isolate);
694 {% if reachable_node_function %}
695 if (Node* owner = impl->{{reachable_node_function}}()) {
696 Node* root = V8GCController::opaqueRootForGC(owner, isolate);
697 isolate->SetReferenceFromGroup(v8::UniqueId(reinterpret_cast<intptr_t>(root)), wrapper);
701 setObjectGroup(object, wrapper, isolate);
708 {##############################################################################}
709 {% block shadow_attributes %}
710 {% if interface_name == 'Window' %}
711 static const V8DOMConfiguration::AttributeConfiguration shadowAttributes[] = {
712 {% for attribute in attributes if attribute.is_unforgeable %}
713 {{attribute_configuration(attribute)}},
721 {##############################################################################}
722 {% block class_attributes %}
723 {# FIXME: rename to install_attributes and put into configure_class_template #}
724 {% if has_attribute_configuration %}
725 static const V8DOMConfiguration::AttributeConfiguration {{v8_class}}Attributes[] = {
726 {% for attribute in attributes
727 if not (attribute.is_expose_js_accessors or
728 attribute.is_static or
729 attribute.runtime_enabled_function or
730 attribute.per_context_enabled_function or
731 (interface_name == 'Window' and attribute.is_unforgeable)) %}
732 {% filter conditional(attribute.conditional_string) %}
733 {{attribute_configuration(attribute)}},
742 {##############################################################################}
743 {% block class_accessors %}
744 {# FIXME: rename install_accessors and put into configure_class_template #}
745 {% if has_accessors %}
746 static const V8DOMConfiguration::AccessorConfiguration {{v8_class}}Accessors[] = {
747 {% for attribute in attributes if attribute.is_expose_js_accessors %}
748 {{attribute_configuration(attribute)}},
756 {##############################################################################}
757 {% block class_methods %}
758 {# FIXME: rename to install_methods and put into configure_class_template #}
759 {% if has_method_configuration %}
760 static const V8DOMConfiguration::MethodConfiguration {{v8_class}}Methods[] = {
761 {% for method in methods if method.do_generate_method_configuration %}
762 {% filter conditional(method.conditional_string) %}
763 {{method_configuration(method)}},
772 {##############################################################################}
773 {% block initialize_event %}
774 {% if has_event_constructor %}
775 bool initialize{{cpp_class}}({{cpp_class}}Init& eventInit, const Dictionary& options, ExceptionState& exceptionState, const v8::FunctionCallbackInfo<v8::Value>& info, const String& forEventName)
777 Dictionary::ConversionContext conversionContext(forEventName.isEmpty() ? String("{{interface_name}}") : forEventName, "", exceptionState);
778 {% if parent_interface %}{# any Event interface except Event itself #}
779 if (!initialize{{parent_interface}}(eventInit, options, exceptionState, info, forEventName.isEmpty() ? String("{{interface_name}}") : forEventName))
783 {% for attribute in attributes
784 if (attribute.is_initialized_by_event_constructor and
785 not attribute.idl_type == 'any')%}
786 {% set is_nullable = 'true' if attribute.is_nullable else 'false' %}
787 {% if attribute.deprecate_as %}
788 if (options.convert(conversionContext.setConversionType("{{attribute.idl_type}}", {{is_nullable}}), "{{attribute.name}}", eventInit.{{attribute.cpp_name}})) {
789 if (options.hasProperty("{{attribute.name}}"))
790 UseCounter::countDeprecation(activeExecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
795 if (!options.convert(conversionContext.setConversionType("{{attribute.idl_type}}", {{is_nullable}}), "{{attribute.name}}", eventInit.{{attribute.cpp_name}}))
806 {##############################################################################}
807 {% block constructor_callback %}
808 {% if constructors or has_custom_constructor or has_event_constructor %}
809 void {{v8_class}}::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
811 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
813 UseCounter::count(activeExecutionContext(info.GetIsolate()), UseCounter::{{measure_as}});
815 if (!info.IsConstructCall()) {
816 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
820 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
821 v8SetReturnValue(info, info.Holder());
825 {% if has_custom_constructor %}
826 {{v8_class}}::constructorCustom(info);
828 {{cpp_class}}V8Internal::constructor(info);
836 {##############################################################################}
837 {% block configure_shadow_object_template %}
838 {% if interface_name == 'Window' %}
839 static void configureShadowObjectTemplate(v8::Handle<v8::ObjectTemplate> templ, v8::Isolate* isolate, WrapperWorldType currentWorldType)
841 V8DOMConfiguration::installAttributes(templ, v8::Handle<v8::ObjectTemplate>(), shadowAttributes, WTF_ARRAY_LENGTH(shadowAttributes), isolate, currentWorldType);
843 // Install a security handler with V8.
844 templ->SetAccessCheckCallbacks(V8Window::namedSecurityCheckCustom, V8Window::indexedSecurityCheckCustom, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&V8Window::wrapperTypeInfo)));
845 templ->SetInternalFieldCount(V8Window::internalFieldCount);
852 {##############################################################################}
853 {% block configure_class_template %}
854 {# FIXME: rename to install_dom_template and Install{{v8_class}}DOMTemplate #}
855 static void configure{{v8_class}}Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
857 functionTemplate->ReadOnlyPrototype();
859 v8::Local<v8::Signature> defaultSignature;
860 {% set parent_template =
861 'V8%s::domTemplate(isolate, currentWorldType)' % parent_interface
862 if parent_interface else 'v8::Local<v8::FunctionTemplate>()' %}
863 {% if runtime_enabled_function %}
864 if (!{{runtime_enabled_function}}())
865 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "", {{parent_template}}, {{v8_class}}::internalFieldCount, 0, 0, 0, 0, 0, 0, isolate, currentWorldType);
868 {% set runtime_enabled_indent = 4 if runtime_enabled_function else 0 %}
869 {% filter indent(runtime_enabled_indent, true) %}
870 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "{{interface_name}}", {{parent_template}}, {{v8_class}}::internalFieldCount,
871 {# Test needed as size 0 constant arrays are not allowed in VC++ #}
872 {% set attributes_name, attributes_length =
873 ('%sAttributes' % v8_class,
874 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class)
875 if has_attribute_configuration else (0, 0) %}
876 {% set accessors_name, accessors_length =
877 ('%sAccessors' % v8_class,
878 'WTF_ARRAY_LENGTH(%sAccessors)' % v8_class)
879 if has_accessors else (0, 0) %}
880 {% set methods_name, methods_length =
881 ('%sMethods' % v8_class,
882 'WTF_ARRAY_LENGTH(%sMethods)' % v8_class)
883 if has_method_configuration else (0, 0) %}
884 {{attributes_name}}, {{attributes_length}},
885 {{accessors_name}}, {{accessors_length}},
886 {{methods_name}}, {{methods_length}},
887 isolate, currentWorldType);
890 {% if constructors or has_custom_constructor or has_event_constructor %}
891 functionTemplate->SetCallHandler({{v8_class}}::constructorCallback);
892 functionTemplate->SetLength({{interface_length}});
894 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
895 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
896 {% if is_check_security and interface_name != 'Window' %}
897 instanceTemplate->SetAccessCheckCallbacks({{cpp_class}}V8Internal::namedSecurityCheck, {{cpp_class}}V8Internal::indexedSecurityCheck, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrapperTypeInfo)));
899 {% for attribute in attributes
900 if attribute.runtime_enabled_function and
901 not attribute.per_context_enabled_function and
902 not attribute.is_static %}
903 {% filter conditional(attribute.conditional_string) %}
904 if ({{attribute.runtime_enabled_function}}()) {
905 static const V8DOMConfiguration::AttributeConfiguration attributeConfiguration =\
906 {{attribute_configuration(attribute)}};
907 V8DOMConfiguration::installAttribute(instanceTemplate, prototypeTemplate, attributeConfiguration, isolate, currentWorldType);
912 {{install_constants() | indent}}
914 {# Special operations #}
915 {# V8 has access-check callback API and it's used on Window instead of
916 deleters or enumerators; see ObjectTemplate::SetAccessCheckCallbacks.
917 In addition, the getter should be set on the prototype template, to get
918 the implementation straight out of the Window prototype, regardless of
919 what prototype is actually set on the object. #}
920 {% set set_on_template = 'PrototypeTemplate' if interface_name == 'Window'
921 else 'InstanceTemplate' %}
922 {% if indexed_property_getter %}
923 {# if have indexed properties, MUST have an indexed property getter #}
924 {% set indexed_property_getter_callback =
925 '%sV8Internal::indexedPropertyGetterCallback' % cpp_class %}
926 {% set indexed_property_setter_callback =
927 '%sV8Internal::indexedPropertySetterCallback' % cpp_class
928 if indexed_property_setter else '0' %}
929 {% set indexed_property_query_callback = '0' %}{# Unused #}
930 {% set indexed_property_deleter_callback =
931 '%sV8Internal::indexedPropertyDeleterCallback' % cpp_class
932 if indexed_property_deleter else '0' %}
933 {% set indexed_property_enumerator_callback =
934 'indexedPropertyEnumerator<%s>' % cpp_class
935 if indexed_property_getter.is_enumerable else '0' %}
936 functionTemplate->{{set_on_template}}()->SetIndexedPropertyHandler({{indexed_property_getter_callback}}, {{indexed_property_setter_callback}}, {{indexed_property_query_callback}}, {{indexed_property_deleter_callback}}, {{indexed_property_enumerator_callback}});
938 {% if named_property_getter %}
939 {# if have named properties, MUST have a named property getter #}
940 {% set named_property_getter_callback =
941 '%sV8Internal::namedPropertyGetterCallback' % cpp_class %}
942 {% set named_property_setter_callback =
943 '%sV8Internal::namedPropertySetterCallback' % cpp_class
944 if named_property_setter else '0' %}
945 {% set named_property_query_callback =
946 '%sV8Internal::namedPropertyQueryCallback' % cpp_class
947 if named_property_getter.is_enumerable else '0' %}
948 {% set named_property_deleter_callback =
949 '%sV8Internal::namedPropertyDeleterCallback' % cpp_class
950 if named_property_deleter else '0' %}
951 {% set named_property_enumerator_callback =
952 '%sV8Internal::namedPropertyEnumeratorCallback' % cpp_class
953 if named_property_getter.is_enumerable else '0' %}
954 functionTemplate->{{set_on_template}}()->SetNamedPropertyHandler({{named_property_getter_callback}}, {{named_property_setter_callback}}, {{named_property_query_callback}}, {{named_property_deleter_callback}}, {{named_property_enumerator_callback}});
956 {# End special operations #}
957 {% if has_custom_legacy_call_as_function %}
958 functionTemplate->InstanceTemplate()->SetCallAsFunctionHandler({{v8_class}}::legacyCallCustom);
960 {% if interface_name == 'HTMLAllCollection' %}
961 {# Needed for legacy support of document.all #}
962 functionTemplate->InstanceTemplate()->MarkAsUndetectable();
964 {% for method in methods if not method.do_not_check_signature %}
965 {# install_custom_signature #}
966 {% if not method.overload_index or method.overload_index == 1 %}
967 {# For overloaded methods, only generate one accessor #}
968 {% filter conditional(method.conditional_string) %}
969 {% if method.is_do_not_check_security %}
970 {% if method.is_per_world_bindings %}
971 if (currentWorldType == MainWorld) {
972 {{install_do_not_check_security_signature(method, 'ForMainWorld')}}
974 {{install_do_not_check_security_signature(method)}}
977 {{install_do_not_check_security_signature(method)}}
979 {% else %}{# is_do_not_check_security #}
980 {% if method.is_per_world_bindings %}
981 if (currentWorldType == MainWorld) {
982 {% filter runtime_enabled(method.runtime_enabled_function) %}
983 {{install_custom_signature(method, 'ForMainWorld')}}
986 {% filter runtime_enabled(method.runtime_enabled_function) %}
987 {{install_custom_signature(method)}}
991 {% filter runtime_enabled(method.runtime_enabled_function) %}
992 {{install_custom_signature(method)}}
995 {% endif %}{# is_do_not_check_security #}
997 {% endif %}{# install_custom_signature #}
999 {% for attribute in attributes if attribute.is_static %}
1000 {% set getter_callback = '%sV8Internal::%sAttributeGetterCallback' %
1001 (cpp_class, attribute.name) %}
1002 {% filter conditional(attribute.conditional_string) %}
1003 functionTemplate->SetNativeDataProperty(v8AtomicString(isolate, "{{attribute.name}}"), {{getter_callback}}, {{attribute.setter_callback}}, v8::External::New(isolate, 0), static_cast<v8::PropertyAttribute>(v8::None), v8::Handle<v8::AccessorSignature>(), static_cast<v8::AccessControl>(v8::DEFAULT));
1006 {# Special interfaces #}
1007 {% if interface_name == 'Window' %}
1009 prototypeTemplate->SetInternalFieldCount(V8Window::internalFieldCount);
1010 functionTemplate->SetHiddenPrototype(true);
1011 instanceTemplate->SetInternalFieldCount(V8Window::internalFieldCount);
1012 // Set access check callbacks, but turned off initially.
1013 // When a context is detached from a frame, turn on the access check.
1014 // Turning on checks also invalidates inline caches of the object.
1015 instanceTemplate->SetAccessCheckCallbacks(V8Window::namedSecurityCheckCustom, V8Window::indexedSecurityCheckCustom, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&V8Window::wrapperTypeInfo)), false);
1016 {% elif interface_name in [
1017 'HTMLDocument', 'DedicatedWorkerGlobalScope',
1018 'SharedWorkerGlobalScope', 'ServiceWorkerGlobalScope'] %}
1019 functionTemplate->SetHiddenPrototype(true);
1022 // Custom toString template
1023 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
1029 {######################################}
1030 {% macro install_do_not_check_security_signature(method, world_suffix) %}
1031 {# FIXME: move to V8DOMConfiguration::installDOMCallbacksWithDoNotCheckSecuritySignature #}
1032 {# Methods that are [DoNotCheckSecurity] are always readable, but if they are
1033 changed and then accessed from a different origin, we do not return the
1034 underlying value, but instead return a new copy of the original function.
1035 This is achieved by storing the changed value as a hidden property. #}
1036 {% set getter_callback =
1037 '%sV8Internal::%sOriginSafeMethodGetterCallback%s' %
1038 (cpp_class, method.name, world_suffix) %}
1039 {% set setter_callback =
1040 '{0}V8Internal::{0}OriginSafeMethodSetterCallback'.format(cpp_class)
1041 if not method.is_read_only else '0' %}
1042 {% set property_attribute =
1043 'static_cast<v8::PropertyAttribute>(%s)' %
1044 ' | '.join(method.property_attributes or ['v8::DontDelete']) %}
1045 {{method.function_template}}->SetAccessor(v8AtomicString(isolate, "{{method.name}}"), {{getter_callback}}, {{setter_callback}}, v8Undefined(), v8::ALL_CAN_READ, {{property_attribute}});
1049 {######################################}
1050 {% macro install_custom_signature(method, world_suffix) %}
1051 {# FIXME: move to V8DOMConfiguration::installDOMCallbacksWithCustomSignature #}
1052 {% set method_callback = '%sV8Internal::%sMethodCallback%s' %
1053 (cpp_class, method.name, world_suffix) %}
1054 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' %
1055 ' | '.join(method.property_attributes) %}
1056 {{method.function_template}}->Set(v8AtomicString(isolate, "{{method.name}}"), v8::FunctionTemplate::New(isolate, {{method_callback}}, v8Undefined(), {{method.signature}}, {{method.number_of_required_or_variadic_arguments}}){% if method.property_attributes %}, {{property_attribute}}{% endif %});
1060 {######################################}
1061 {% macro install_constants() %}
1062 {# FIXME: should use reflected_name instead of name #}
1063 {# Normal (always enabled) constants #}
1064 static const V8DOMConfiguration::ConstantConfiguration {{v8_class}}Constants[] = {
1065 {% for constant in constants if not constant.runtime_enabled_function %}
1066 {"{{constant.name}}", {{constant.value}}},
1069 V8DOMConfiguration::installConstants(functionTemplate, prototypeTemplate, {{v8_class}}Constants, WTF_ARRAY_LENGTH({{v8_class}}Constants), isolate);
1070 {# Runtime-enabled constants #}
1071 {% for constant in constants if constant.runtime_enabled_function %}
1072 if ({{constant.runtime_enabled_function}}()) {
1073 static const V8DOMConfiguration::ConstantConfiguration constantConfiguration = {"{{constant.name}}", static_cast<signed int>({{constant.value}})};
1074 V8DOMConfiguration::installConstants(functionTemplate, prototypeTemplate, &constantConfiguration, 1, isolate);
1077 {# Check constants #}
1078 {% if not do_not_check_constants %}
1079 {% for constant in constants %}
1080 {% set constant_cpp_class = constant.cpp_class or cpp_class %}
1081 COMPILE_ASSERT({{constant.value}} == {{constant_cpp_class}}::{{constant.reflected_name}}, TheValueOf{{cpp_class}}_{{constant.reflected_name}}DoesntMatchWithImplementation);
1087 {##############################################################################}
1088 {% block get_template %}
1089 {# FIXME: rename to get_dom_template and GetDOMTemplate #}
1090 v8::Handle<v8::FunctionTemplate> {{v8_class}}::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
1092 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
1093 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
1094 if (result != data->templateMap(currentWorldType).end())
1095 return result->value.newLocal(isolate);
1097 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
1098 v8::EscapableHandleScope handleScope(isolate);
1099 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
1100 configure{{v8_class}}Template(templ, isolate, currentWorldType);
1101 data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
1102 return handleScope.Escape(templ);
1108 {##############################################################################}
1109 {% block has_instance %}
1110 bool {{v8_class}}::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
1112 return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
1113 || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
1119 {##############################################################################}
1120 {% block install_per_context_attributes %}
1121 {% if has_per_context_enabled_attributes %}
1122 void {{v8_class}}::installPerContextEnabledProperties(v8::Handle<v8::Object> instanceTemplate, {{cpp_class}}* impl, v8::Isolate* isolate)
1124 v8::Local<v8::Object> prototypeTemplate = v8::Local<v8::Object>::Cast(instanceTemplate->GetPrototype());
1125 {% for attribute in attributes if attribute.per_context_enabled_function %}
1126 if ({{attribute.per_context_enabled_function}}(impl->document())) {
1127 static const V8DOMConfiguration::AttributeConfiguration attributeConfiguration =\
1128 {{attribute_configuration(attribute)}};
1129 V8DOMConfiguration::installAttribute(instanceTemplate, prototypeTemplate, attributeConfiguration, isolate);
1138 {##############################################################################}
1139 {% block install_per_context_methods %}
1140 {% if has_per_context_enabled_methods %}
1141 void {{v8_class}}::installPerContextEnabledMethods(v8::Handle<v8::Object> prototypeTemplate, v8::Isolate* isolate)
1143 {# Define per-context enabled operations #}
1144 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, domTemplate(isolate, worldType(isolate)));
1146 ExecutionContext* context = toExecutionContext(prototypeTemplate->CreationContext());
1147 {% for method in methods if method.per_context_enabled_function %}
1148 if (context && context->isDocument() && {{method.per_context_enabled_function}}(toDocument(context)))
1149 prototypeTemplate->Set(v8AtomicString(isolate, "{{method.name}}"), v8::FunctionTemplate::New(isolate, {{cpp_class}}V8Internal::{{method.name}}MethodCallback, v8Undefined(), defaultSignature, {{method.number_of_required_arguments}})->GetFunction());
1157 {##############################################################################}
1158 {% block to_active_dom_object %}
1159 {% if is_active_dom_object %}
1160 ActiveDOMObject* {{v8_class}}::toActiveDOMObject(v8::Handle<v8::Object> wrapper)
1162 return toNative(wrapper);
1169 {##############################################################################}
1170 {% block to_event_target %}
1171 {% if is_event_target %}
1172 EventTarget* {{v8_class}}::toEventTarget(v8::Handle<v8::Object> object)
1174 return toNative(object);
1181 {##############################################################################}
1182 {% block get_shadow_object_template %}
1183 {% if interface_name == 'Window' %}
1184 v8::Handle<v8::ObjectTemplate> V8Window::getShadowObjectTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
1186 if (currentWorldType == MainWorld) {
1187 DEFINE_STATIC_LOCAL(v8::Persistent<v8::ObjectTemplate>, V8WindowShadowObjectCacheForMainWorld, ());
1188 if (V8WindowShadowObjectCacheForMainWorld.IsEmpty()) {
1189 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
1190 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
1191 configureShadowObjectTemplate(templ, isolate, currentWorldType);
1192 V8WindowShadowObjectCacheForMainWorld.Reset(isolate, templ);
1195 return v8::Local<v8::ObjectTemplate>::New(isolate, V8WindowShadowObjectCacheForMainWorld);
1197 DEFINE_STATIC_LOCAL(v8::Persistent<v8::ObjectTemplate>, V8WindowShadowObjectCacheForNonMainWorld, ());
1198 if (V8WindowShadowObjectCacheForNonMainWorld.IsEmpty()) {
1199 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
1200 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
1201 configureShadowObjectTemplate(templ, isolate, currentWorldType);
1202 V8WindowShadowObjectCacheForNonMainWorld.Reset(isolate, templ);
1205 return v8::Local<v8::ObjectTemplate>::New(isolate, V8WindowShadowObjectCacheForNonMainWorld);
1213 {##############################################################################}
1215 {% if special_wrap_for or is_document %}
1216 v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
1219 {% for special_wrap_interface in special_wrap_for %}
1220 if (impl->is{{special_wrap_interface}}())
1221 return wrap(to{{special_wrap_interface}}(impl), creationContext, isolate);
1223 v8::Handle<v8::Object> wrapper = {{v8_class}}::createWrapper(impl, creationContext, isolate);
1224 {% if is_document %}
1225 if (wrapper.IsEmpty())
1227 if (!isolatedWorldForEnteredContext(isolate)) {
1228 if (Frame* frame = impl->frame())
1229 frame->script().windowShell(DOMWrapperWorld::mainWorld())->updateDocumentWrapper(wrapper);
1239 {##############################################################################}
1240 {% block create_wrapper %}
1241 {% if not has_custom_to_v8 %}
1242 v8::Handle<v8::Object> {{v8_class}}::createWrapper({{pass_ref_ptr}}<{{cpp_class}}> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
1245 ASSERT(!DOMDataStore::containsWrapper<{{v8_class}}>(impl.get(), isolate));
1246 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
1247 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
1248 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
1249 // the same object de-ref functions, though, so use that as the basis of the check.
1250 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
1253 {% if is_document %}
1254 if (Frame* frame = impl->frame()) {
1255 if (frame->script().initializeMainWorld()) {
1256 // initializeMainWorld may have created a wrapper for the object, retry from the start.
1257 v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapper<{{v8_class}}>(impl.get(), isolate);
1258 if (!wrapper.IsEmpty())
1263 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
1264 if (UNLIKELY(wrapper.IsEmpty()))
1267 {% if is_audio_buffer %}
1268 {# We only setDeallocationObservers on array buffers that are held by some
1269 object in the V8 heap, not in the ArrayBuffer constructor itself.
1270 This is because V8 GC only cares about memory it can free on GC, and
1271 until the object is exposed to JavaScript, V8 GC doesn't affect it. #}
1272 for (unsigned i = 0, n = impl->numberOfChannels(); i < n; i++) {
1273 Float32Array* channelData = impl->getChannelData(i);
1274 channelData->buffer()->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instanceTemplate());
1277 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
1278 {% set wrapper_configuration = 'WrapperConfiguration::Dependent'
1279 if (has_visit_dom_wrapper or
1280 is_active_dom_object or
1281 is_dependent_lifetime) else
1282 'WrapperConfiguration::Independent' %}
1283 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl, &wrapperTypeInfo, wrapper, isolate, {{wrapper_configuration}});
1291 {##############################################################################}
1292 {% block deref_object_and_to_v8_no_inline %}
1293 void {{v8_class}}::derefObject(void* object)
1295 {% set oilpan_conditional = '!ENABLE(OILPAN)' if is_will_be_garbage_collected
1297 {% filter conditional(oilpan_conditional) %}
1298 fromInternalPointer(object)->deref();
1303 v8::Handle<v8::Value> toV8NoInline({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
1305 return toV8(impl, creationContext, isolate);