Commit 6ad51292 authored by yurak's avatar yurak Committed by Commit bot

Implemented HTMLConstructor extended attribute.

Specs: https://html.spec.whatwg.org/#html-element-constructors

Replaced V8HTMLElementCustom with V8HTMLConstructor

Add new extended attribute [HTMLConstructor] to bindings and IDLExtendedAttributes.txt
  Added description to IDLExtendedAttributes.md and re-organized descriptions
  Added checks for conflicting extended attributes with [HTMLConstructor] in v8_interface.py
  Edited jinja templates for [HTMLConstructor] interface

Replaced [CustomConstructor] with [HTMLConstructor] in HTMLElement.idl

BUG=648828

Review-Url: https://codereview.chromium.org/2385073002
Cr-Commit-Position: refs/heads/master@{#423068}
parent cca1838d
......@@ -248,6 +248,63 @@ Calling the non-`[EnforceRange]` version of `setColor()` uses **ToUint8()** to c
Calling the `[EnforceRange]` version of `setColorEnforced()` with an out of range value, such as -1, 256, or Infinity will result in a `TypeError` exception.
### [Exposed] _(i, m, a, c)_
Standard: [Exposed](http://heycam.github.io/webidl/#Exposed)
Summary: Indicates on which global object or objects (e.g., Window, WorkerGlobalScope) the interface property is generated, i.e., in which global scope or scopes an interface exists. This is primarily of interest for the constructor, i.e., the [interface object Call method](https://heycam.github.io/webidl/#es-interface-call). Global context defaults to Window (the primary global scope) if not present, overridden by standard extended attribute `[NoInterfaceObject]` (the value of the property on the global object corresponding to the interface is called the **interface object**), which results in no interface property being generated.
As with `[NoInterfaceObject]` does not affect generated code for the interface itself, only the code for the corresponding global object. A partial interface is generated at build time, containing an attribute for each interface property on that global object.
All non-callback interfaces without `[NoInterfaceObject]` have a corresponding interface property on the global object. Note that in the Web IDL spec, callback interfaces with constants also have interface properties, but in Blink callback interfaces only have methods (no constants or attributes), so this is not applicable. `[Exposed]` can be used with different values to indicate on which global object or objects the property should be generated. Valid values are:
* `Window`
* [Worker](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#the-workerglobalscope-common-interface)
* [SharedWorker](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#dedicated-workers-and-the-dedicatedworkerglobalscope-interface)
* [DedicatedWorker](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#shared-workers-and-the-sharedworkerglobalscope-interface)
* [ServiceWorker](https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/index.html#service-worker-global-scope)
For reference, see [ECMAScript 5.1: 15.1 The Global Object](http://www.ecma-international.org/ecma-262/5.1/#sec-15.1) ([annotated](http://es5.github.io/#x15.1)), [HTML: 10 Web workers](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html), [Web Workers](http://dev.w3.org/html5/workers/), and [Service Workers](https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/index.html) specs.
It is possible to have the global constructor generated on several interfaces by listing them, e.g. `[Exposed=(Window,WorkerGlobalScope)]`.
Usage: `[Exposed]` can be specified on interfaces that do not have the `[NoInterfaceObject]` extended attribute.
```webidl
[
Exposed=DedicatedWorker,
] interface XXX {
...
};
[
Exposed=(Window,Worker),
] interface YYY {
...
};
```
Exposed can also be specified with a method, attribute and constant.
As a Blink-specific extension, we allow `Exposed(Arguments)` form, such as `[Exposed(Window Feature1, DedicatedWorker Feature2)]`. You can use this form to vary the exposing global scope based on runtime enabled features. For example, `[Exposed(Window Feature1, Worker Feature2)]` exposes the qualified element to Window if "Feature1" is enabled and to Worker if "Feature2" is enabled.
### [Global] and [PrimaryGlobal] _(i)_
Standard: [Global](http://heycam.github.io/webidl/#Global)
Summary: The `[Global]` and `[PrimaryGlobal]` extended attributes can be used to give a name to one or more global interfaces, which can then be referenced by the `[Exposed]` extended attribute.
These extended attributes must either take no arguments or take an identifier list.
If the `[Global]` or `[PrimaryGlobal]` extended attribute is declared with an identifier list argument, then those identifiers are the interface’s global names; otherwise, the interface has a single global name, which is the interface's identifier.
### [HTMLConstructor]
Standard: [HTMLConstructor](https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors)
Summary: HTML Elements have special constructor behavior. Interface object of given interface with the `[HTMLConstructor]` attribute will have specific behavior when called.
Usage: Must take no arguments, and must not appear on anything other than an interface. It much appear once on an interface, and the interface cannot be annotated with `[Constructor]` or `[NoInterfaceObject]` extended attributes. It must not be used on a callback interface.
### [NamedConstructor] _(i)_
......@@ -308,56 +365,6 @@ Note that `[NoInterfaceObject]` **MUST** be specified on testing interfaces, as
};
```
### [Global] and [PrimaryGlobal] _(i)_
Standard: [Global](http://heycam.github.io/webidl/#Global)
Summary: The `[Global]` and `[PrimaryGlobal]` extended attributes can be used to give a name to one or more global interfaces, which can then be referenced by the `[Exposed]` extended attribute.
These extended attributes must either take no arguments or take an identifier list.
If the `[Global]` or `[PrimaryGlobal]` extended attribute is declared with an identifier list argument, then those identifiers are the interface’s global names; otherwise, the interface has a single global name, which is the interface's identifier.
### [Exposed] _(i, m, a, c)_
Standard: [Exposed](http://heycam.github.io/webidl/#Exposed)
Summary: Indicates on which global object or objects (e.g., Window, WorkerGlobalScope) the interface property is generated, i.e., in which global scope or scopes an interface exists. This is primarily of interest for the constructor, i.e., the [interface object Call method](https://heycam.github.io/webidl/#es-interface-call). Global context defaults to Window (the primary global scope) if not present, overridden by standard extended attribute `[NoInterfaceObject]` (the value of the property on the global object corresponding to the interface is called the **interface object**), which results in no interface property being generated.
As with `[NoInterfaceObject]` does not affect generated code for the interface itself, only the code for the corresponding global object. A partial interface is generated at build time, containing an attribute for each interface property on that global object.
All non-callback interfaces without `[NoInterfaceObject]` have a corresponding interface property on the global object. Note that in the Web IDL spec, callback interfaces with constants also have interface properties, but in Blink callback interfaces only have methods (no constants or attributes), so this is not applicable. `[Exposed]` can be used with different values to indicate on which global object or objects the property should be generated. Valid values are:
* `Window`
* [Worker](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#the-workerglobalscope-common-interface)
* [SharedWorker](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#dedicated-workers-and-the-dedicatedworkerglobalscope-interface)
* [DedicatedWorker](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#shared-workers-and-the-sharedworkerglobalscope-interface)
* [ServiceWorker](https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/index.html#service-worker-global-scope)
For reference, see [ECMAScript 5.1: 15.1 The Global Object](http://www.ecma-international.org/ecma-262/5.1/#sec-15.1) ([annotated](http://es5.github.io/#x15.1)), [HTML: 10 Web workers](http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html), [Web Workers](http://dev.w3.org/html5/workers/), and [Service Workers](https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/index.html) specs.
It is possible to have the global constructor generated on several interfaces by listing them, e.g. `[Exposed=(Window,WorkerGlobalScope)]`.
Usage: `[Exposed]` can be specified on interfaces that do not have the `[NoInterfaceObject]` extended attribute.
```webidl
[
Exposed=DedicatedWorker,
] interface XXX {
...
};
[
Exposed=(Window,Worker),
] interface YYY {
...
};
```
Exposed can also be specified with a method, attribute and constant.
As a Blink-specific extension, we allow `Exposed(Arguments)` form, such as `[Exposed(Window Feature1, DedicatedWorker Feature2)]`. You can use this form to vary the exposing global scope based on runtime enabled features. For example, `[Exposed(Window Feature1, Worker Feature2)]` exposes the qualified element to Window if "Feature1" is enabled and to Worker if "Feature2" is enabled.
### [OverrideBuiltins] _(i)_
Standard: [OverrideBuiltins](http://heycam.github.io/webidl/#OverrideBuiltins)
......
......@@ -56,6 +56,7 @@ Exposed=*
FeaturePolicy=*
FlexibleArrayBufferView
Global=|*
HTMLConstructor
ImplementedAs=*
ImplementedInPrivateScript
Iterable
......
......@@ -19,7 +19,6 @@ bindings_core_v8_files =
"core/v8/custom/V8ErrorEventCustom.cpp",
"core/v8/custom/V8EventTargetCustom.cpp",
"core/v8/custom/V8HTMLAllCollectionCustom.cpp",
"core/v8/custom/V8HTMLElementCustom.cpp",
"core/v8/custom/V8HTMLPlugInElementCustom.cpp",
"core/v8/custom/V8IntersectionObserverCustom.cpp",
"core/v8/custom/V8MediaQueryListCustom.cpp",
......@@ -122,6 +121,9 @@ bindings_core_v8_files =
"core/v8/ScriptValueSerializer.h",
"core/v8/ScriptWrappable.cpp",
"core/v8/ScriptWrappable.h",
"core/v8/ScriptWrappableVisitor.cpp",
"core/v8/ScriptWrappableVisitor.h",
"core/v8/ScriptWrappableVisitorVerifier.h",
"core/v8/SerializationTag.h",
"core/v8/SerializedScriptValue.cpp",
"core/v8/SerializedScriptValue.h",
......@@ -153,9 +155,6 @@ bindings_core_v8_files =
"core/v8/V8EventListenerInfo.h",
"core/v8/V8GCController.cpp",
"core/v8/V8GCController.h",
"core/v8/ScriptWrappableVisitor.cpp",
"core/v8/ScriptWrappableVisitor.h",
"core/v8/ScriptWrappableVisitorVerifier.h",
"core/v8/V8EventListenerHelper.cpp",
"core/v8/V8EventListenerHelper.h",
"core/v8/V8GCForContextDispose.cpp",
......@@ -163,6 +162,7 @@ bindings_core_v8_files =
"core/v8/V8GlobalValueMap.h",
"core/v8/V8HiddenValue.cpp",
"core/v8/V8HiddenValue.h",
"core/v8/V8HTMLConstructor.cpp",
"core/v8/V8IdleTaskRunner.h",
"core/v8/V8Initializer.cpp",
"core/v8/V8Initializer.h",
......
......@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "bindings/core/v8/V8HTMLElement.h"
#include "bindings/core/v8/DOMWrapperWorld.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptCustomElementDefinition.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8BindingMacros.h"
#include "bindings/core/v8/V8DOMWrapper.h"
#include "bindings/core/v8/V8HTMLElement.h"
#include "bindings/core/v8/V8ThrowException.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
......@@ -20,7 +19,7 @@
namespace blink {
void V8HTMLElement::constructorCustom(
void V8HTMLElement::HTMLConstructor(
const v8::FunctionCallbackInfo<v8::Value>& info) {
DCHECK(info.IsConstructCall());
......
......@@ -291,10 +291,19 @@ def interface_context(interface, interfaces):
number_of_required_arguments(constructor),
} for constructor in interface.custom_constructors]
# [HTMLConstructor]
has_html_constructor = 'HTMLConstructor' in extended_attributes
# https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors
if has_html_constructor:
if ('Constructor' in extended_attributes) or ('NoInterfaceObject' in extended_attributes):
raise Exception('[Constructor] and [NoInterfaceObject] MUST NOT be'
' specified with [HTMLConstructor]: '
'%s' % interface.name)
# [NamedConstructor]
named_constructor = named_constructor_context(interface)
if constructors or custom_constructors or named_constructor:
if constructors or custom_constructors or has_html_constructor or named_constructor:
if interface.is_partial:
raise Exception('[Constructor] and [NamedConstructor] MUST NOT be'
' specified on partial interface definitions: '
......@@ -330,6 +339,7 @@ def interface_context(interface, interfaces):
context.update({
'constructors': constructors,
'has_custom_constructor': bool(custom_constructors),
'has_html_constructor': has_html_constructor,
'interface_length':
interface_length(constructors + custom_constructors),
'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor]
......
......@@ -648,7 +648,7 @@ void {{v8_class}}::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappable* script
{##############################################################################}
{% block constructor_callback %}
{% if constructors or has_custom_constructor or has_event_constructor %}
{% if constructors or has_custom_constructor or has_event_constructor or has_html_constructor %}
void {{v8_class}}::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
{% if measure_as %}
......@@ -666,6 +666,8 @@ void {{v8_class}}::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>
{% if has_custom_constructor %}
{{v8_class}}::constructorCustom(info);
{% elif has_html_constructor %}
{{v8_class}}::HTMLConstructor(info);
{% else %}
{{cpp_class}}V8Internal::constructor(info);
{% endif %}
......
......@@ -90,11 +90,13 @@ public:
static void {{method.name}}MethodEpilogueCustom(const v8::FunctionCallbackInfo<v8::Value>&, {{cpp_class}}*);
{% endif %}
{% endfor %}
{% if constructors or has_custom_constructor or has_event_constructor %}
{% if constructors or has_custom_constructor or has_event_constructor or has_html_constructor %}
static void constructorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
{% endif %}
{% if has_custom_constructor %}
static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&);
{% elif has_html_constructor %}
static void HTMLConstructor(const v8::FunctionCallbackInfo<v8::Value>&);
{% endif %}
{% for attribute in attributes %}
{% if attribute.has_custom_getter %}{# FIXME: and not attribute.implemented_by #}
......
......@@ -283,7 +283,7 @@ static void install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWo
if parent_interface else
'v8::Local<v8::FunctionTemplate>()' %}
V8DOMConfiguration::initializeDOMInterfaceTemplate(isolate, interfaceTemplate, {{v8_class}}::wrapperTypeInfo.interfaceName, {{parent_interface_template}}, {{v8_class}}::internalFieldCount);
{% if constructors or has_custom_constructor or has_event_constructor %}
{% if constructors or has_custom_constructor or has_event_constructor or has_html_constructor %}
interfaceTemplate->SetCallHandler({{v8_class}}::constructorCallback);
interfaceTemplate->SetLength({{interface_length}});
{% endif %}
......
......@@ -19,7 +19,7 @@
*/
// https://html.spec.whatwg.org/#htmlelement
[CustomConstructor]
[HTMLConstructor]
interface HTMLElement : Element {
// metadata attributes
[CEReactions, Reflect] attribute DOMString title;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment