Commit e3e4d7e3 authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

Reland "document: Use ElementCreationOptions in Document.createElement()"

This is a reland of 6a1db25d
with fixing the build error.

Original change's description:
> document: Use ElementCreationOptions in Document.createElement()
>
> We used (DOMString or Dictionary) type for |option| parameter,
> but this CL replaces it with (DOMString or ElementCreationOpitons)
> as the spec defined.
>
>
> Bug: 904241
> Change-Id: I9416af83168e7c1f7456ffdbd3141fa97b510706
> Reviewed-on: https://chromium-review.googlesource.com/c/1333094
> Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
> Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
> Reviewed-by: Kentaro Hara <haraken@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#608668}

Bug: 904241
Change-Id: I2ea645814ea80f9989dab93574e70e473b72a10a
Reviewed-on: https://chromium-review.googlesource.com/c/1339499Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608699}
parent d66855ad
...@@ -80,12 +80,12 @@ bindings_core_generated_union_type_files = [ ...@@ -80,12 +80,12 @@ bindings_core_generated_union_type_files = [
"$bindings_core_v8_output_dir/string_or_array_buffer_or_array_buffer_view.h", "$bindings_core_v8_output_dir/string_or_array_buffer_or_array_buffer_view.h",
"$bindings_core_v8_output_dir/string_or_css_variable_reference_value.cc", "$bindings_core_v8_output_dir/string_or_css_variable_reference_value.cc",
"$bindings_core_v8_output_dir/string_or_css_variable_reference_value.h", "$bindings_core_v8_output_dir/string_or_css_variable_reference_value.h",
"$bindings_core_v8_output_dir/string_or_dictionary.cc",
"$bindings_core_v8_output_dir/string_or_dictionary.h",
"$bindings_core_v8_output_dir/string_or_double.cc", "$bindings_core_v8_output_dir/string_or_double.cc",
"$bindings_core_v8_output_dir/string_or_double.h", "$bindings_core_v8_output_dir/string_or_double.h",
"$bindings_core_v8_output_dir/string_or_double_or_performance_measure_options.cc", "$bindings_core_v8_output_dir/string_or_double_or_performance_measure_options.cc",
"$bindings_core_v8_output_dir/string_or_double_or_performance_measure_options.h", "$bindings_core_v8_output_dir/string_or_double_or_performance_measure_options.h",
"$bindings_core_v8_output_dir/string_or_element_creation_options.cc",
"$bindings_core_v8_output_dir/string_or_element_creation_options.h",
"$bindings_core_v8_output_dir/string_or_string_sequence.cc", "$bindings_core_v8_output_dir/string_or_string_sequence.cc",
"$bindings_core_v8_output_dir/string_or_string_sequence.h", "$bindings_core_v8_output_dir/string_or_string_sequence.h",
"$bindings_core_v8_output_dir/string_or_trusted_html.cc", "$bindings_core_v8_output_dir/string_or_trusted_html.cc",
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v0_custom_element_constructor_builder.h" #include "third_party/blink/renderer/bindings/core/v8/v0_custom_element_constructor_builder.h"
#include "third_party/blink/renderer/bindings/core/v8/string_or_dictionary.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_element_creation_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_document.h" #include "third_party/blink/renderer/bindings/core/v8/v8_document.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_html_element.h" #include "third_party/blink/renderer/bindings/core/v8/v8_html_element.h"
...@@ -384,14 +384,13 @@ static void ConstructCustomElement( ...@@ -384,14 +384,13 @@ static void ConstructCustomElement(
maybe_type->IsUndefined()) { maybe_type->IsUndefined()) {
return; return;
} }
TOSTRING_VOID(V8StringResource<>, type, maybe_type); TOSTRING_VOID(V8StringResource<kTreatNullAsNullString>, type, maybe_type);
ExceptionState exception_state(isolate, ExceptionState::kConstructionContext, ExceptionState exception_state(isolate, ExceptionState::kConstructionContext,
"CustomElement"); "CustomElement");
V0CustomElementProcessingStack::CallbackDeliveryScope delivery_scope; V0CustomElementProcessingStack::CallbackDeliveryScope delivery_scope;
Element* element = document->createElementNS( Element* element = document->createElementNS(
namespace_uri, tag_name, namespace_uri, tag_name, StringOrElementCreationOptions::FromString(type),
StringOrDictionary::FromString(maybe_type->IsNull() ? g_null_atom : type),
exception_state); exception_state);
if (element) { if (element) {
UseCounter::Count(document, WebFeature::kV0CustomElementsConstruct); UseCounter::Count(document, WebFeature::kV0CustomElementsConstruct);
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/source_location.h" #include "third_party/blink/renderer/bindings/core/v8/source_location.h"
#include "third_party/blink/renderer/bindings/core/v8/string_or_dictionary.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_element_creation_options.h"
#include "third_party/blink/renderer/bindings/core/v8/usv_string_or_trusted_url.h" #include "third_party/blink/renderer/bindings/core/v8/usv_string_or_trusted_url.h"
#include "third_party/blink/renderer/bindings/core/v8/v0_custom_element_constructor_builder.h" #include "third_party/blink/renderer/bindings/core/v8/v0_custom_element_constructor_builder.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_element_creation_options.h" #include "third_party/blink/renderer/bindings/core/v8/v8_element_creation_options.h"
...@@ -948,9 +948,9 @@ Element* Document::CreateElementForBinding(const AtomicString& name, ...@@ -948,9 +948,9 @@ Element* Document::CreateElementForBinding(const AtomicString& name,
return Element::Create(QualifiedName(g_null_atom, name, g_null_atom), this); return Element::Create(QualifiedName(g_null_atom, name, g_null_atom), this);
} }
AtomicString GetTypeExtension(Document* document, AtomicString GetTypeExtension(
const StringOrDictionary& string_or_options, Document* document,
ExceptionState& exception_state) { const StringOrElementCreationOptions& string_or_options) {
if (string_or_options.IsNull()) if (string_or_options.IsNull())
return AtomicString(); return AtomicString();
...@@ -960,12 +960,11 @@ AtomicString GetTypeExtension(Document* document, ...@@ -960,12 +960,11 @@ AtomicString GetTypeExtension(Document* document,
return AtomicString(string_or_options.GetAsString()); return AtomicString(string_or_options.GetAsString());
} }
if (string_or_options.IsDictionary()) { if (string_or_options.IsElementCreationOptions()) {
Dictionary dict = string_or_options.GetAsDictionary(); const ElementCreationOptions& options =
v8::Local<v8::Value> value; *string_or_options.GetAsElementCreationOptions();
if (dict.HasProperty("is", exception_state) && dict.Get("is", value)) { if (options.hasIs())
return ToCoreAtomicString(v8::Local<v8::String>::Cast(value)); return AtomicString(options.is());
}
} }
return AtomicString(); return AtomicString();
...@@ -974,7 +973,7 @@ AtomicString GetTypeExtension(Document* document, ...@@ -974,7 +973,7 @@ AtomicString GetTypeExtension(Document* document,
// https://dom.spec.whatwg.org/#dom-document-createelement // https://dom.spec.whatwg.org/#dom-document-createelement
Element* Document::CreateElementForBinding( Element* Document::CreateElementForBinding(
const AtomicString& local_name, const AtomicString& local_name,
const StringOrDictionary& string_or_options, const StringOrElementCreationOptions& string_or_options,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (string_or_options.IsNull()) { if (string_or_options.IsNull()) {
return CreateElementForBinding(local_name, exception_state); return CreateElementForBinding(local_name, exception_state);
...@@ -995,14 +994,14 @@ Element* Document::CreateElementForBinding( ...@@ -995,14 +994,14 @@ Element* Document::CreateElementForBinding(
? html_names::xhtmlNamespaceURI ? html_names::xhtmlNamespaceURI
: g_null_atom); : g_null_atom);
bool is_v1 = string_or_options.IsDictionary() || !RegistrationContext(); bool is_v1 =
bool create_v1_builtin = string_or_options.IsDictionary(); string_or_options.IsElementCreationOptions() || !RegistrationContext();
bool create_v1_builtin = string_or_options.IsElementCreationOptions();
bool should_create_builtin = bool should_create_builtin =
create_v1_builtin || string_or_options.IsString(); create_v1_builtin || string_or_options.IsString();
// 3. // 3.
const AtomicString& is = const AtomicString& is = GetTypeExtension(this, string_or_options);
GetTypeExtension(this, string_or_options, exception_state);
// 5. Let element be the result of creating an element given ... // 5. Let element be the result of creating an element given ...
Element* element = Element* element =
...@@ -1057,10 +1056,11 @@ Element* Document::createElementNS(const AtomicString& namespace_uri, ...@@ -1057,10 +1056,11 @@ Element* Document::createElementNS(const AtomicString& namespace_uri,
} }
// https://dom.spec.whatwg.org/#internal-createelementns-steps // https://dom.spec.whatwg.org/#internal-createelementns-steps
Element* Document::createElementNS(const AtomicString& namespace_uri, Element* Document::createElementNS(
const AtomicString& qualified_name, const AtomicString& namespace_uri,
const StringOrDictionary& string_or_options, const AtomicString& qualified_name,
ExceptionState& exception_state) { const StringOrElementCreationOptions& string_or_options,
ExceptionState& exception_state) {
if (string_or_options.IsNull()) if (string_or_options.IsNull())
return createElementNS(namespace_uri, qualified_name, exception_state); return createElementNS(namespace_uri, qualified_name, exception_state);
...@@ -1070,14 +1070,14 @@ Element* Document::createElementNS(const AtomicString& namespace_uri, ...@@ -1070,14 +1070,14 @@ Element* Document::createElementNS(const AtomicString& namespace_uri,
if (q_name == QualifiedName::Null()) if (q_name == QualifiedName::Null())
return nullptr; return nullptr;
bool is_v1 = string_or_options.IsDictionary() || !RegistrationContext(); bool is_v1 =
bool create_v1_builtin = string_or_options.IsDictionary(); string_or_options.IsElementCreationOptions() || !RegistrationContext();
bool create_v1_builtin = string_or_options.IsElementCreationOptions();
bool should_create_builtin = bool should_create_builtin =
create_v1_builtin || string_or_options.IsString(); create_v1_builtin || string_or_options.IsString();
// 2. // 2.
const AtomicString& is = const AtomicString& is = GetTypeExtension(this, string_or_options);
GetTypeExtension(this, string_or_options, exception_state);
if (!IsValidElementName(this, qualified_name)) { if (!IsValidElementName(this, qualified_name)) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidCharacterError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidCharacterError,
......
...@@ -180,7 +180,7 @@ class SerializedScriptValue; ...@@ -180,7 +180,7 @@ class SerializedScriptValue;
class Settings; class Settings;
class SlotAssignmentEngine; class SlotAssignmentEngine;
class SnapCoordinator; class SnapCoordinator;
class StringOrDictionary; class StringOrElementCreationOptions;
class StyleEngine; class StyleEngine;
class StyleResolver; class StyleResolver;
class StylePropertyMapReadOnly; class StylePropertyMapReadOnly;
...@@ -321,14 +321,14 @@ class CORE_EXPORT Document : public ContainerNode, ...@@ -321,14 +321,14 @@ class CORE_EXPORT Document : public ContainerNode,
Element* CreateElementForBinding(const AtomicString& local_name, Element* CreateElementForBinding(const AtomicString& local_name,
ExceptionState& = ASSERT_NO_EXCEPTION); ExceptionState& = ASSERT_NO_EXCEPTION);
Element* CreateElementForBinding(const AtomicString& local_name, Element* CreateElementForBinding(const AtomicString& local_name,
const StringOrDictionary&, const StringOrElementCreationOptions&,
ExceptionState&); ExceptionState&);
Element* createElementNS(const AtomicString& namespace_uri, Element* createElementNS(const AtomicString& namespace_uri,
const AtomicString& qualified_name, const AtomicString& qualified_name,
ExceptionState&); ExceptionState&);
Element* createElementNS(const AtomicString& namespace_uri, Element* createElementNS(const AtomicString& namespace_uri,
const AtomicString& qualified_name, const AtomicString& qualified_name,
const StringOrDictionary&, const StringOrElementCreationOptions&,
ExceptionState&); ExceptionState&);
DocumentFragment* createDocumentFragment(); DocumentFragment* createDocumentFragment();
Text* createTextNode(const String& data); Text* createTextNode(const String& data);
......
...@@ -176,9 +176,8 @@ typedef (HTMLScriptElement or SVGScriptElement) HTMLOrSVGScriptElement; ...@@ -176,9 +176,8 @@ typedef (HTMLScriptElement or SVGScriptElement) HTMLOrSVGScriptElement;
// FIXME: The registerElement return type should be Function. // FIXME: The registerElement return type should be Function.
[RuntimeEnabled=CustomElementsV0, CallWith=ScriptState, CustomElementCallbacks, RaisesException, DeprecateAs=DocumentRegisterElement] any registerElement(DOMString type, optional ElementRegistrationOptions options); [RuntimeEnabled=CustomElementsV0, CallWith=ScriptState, CustomElementCallbacks, RaisesException, DeprecateAs=DocumentRegisterElement] any registerElement(DOMString type, optional ElementRegistrationOptions options);
// https://w3c.github.io/webcomponents/spec/custom/#extensions-to-document-interface-to-instantiate // https://w3c.github.io/webcomponents/spec/custom/#extensions-to-document-interface-to-instantiate
// FIXME: The typeExtension arguments should not be nullable. [CustomElementCallbacks, PerWorldBindings, RaisesException, ImplementedAs=CreateElementForBinding] Element createElement(DOMString localName, (DOMString or ElementCreationOptions) options);
[CustomElementCallbacks, PerWorldBindings, RaisesException, ImplementedAs=CreateElementForBinding] Element createElement(DOMString localName, (DOMString or Dictionary)? options); [CustomElementCallbacks, RaisesException] Element createElementNS(DOMString? namespaceURI, DOMString qualifiedName, (DOMString or ElementCreationOptions) options);
[CustomElementCallbacks, RaisesException] Element createElementNS(DOMString? namespaceURI, DOMString qualifiedName, (DOMString or Dictionary)? options);
// Page Visibility // Page Visibility
// https://w3c.github.io/page-visibility/#extensions-to-the-document-interface // https://w3c.github.io/page-visibility/#extensions-to-the-document-interface
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <memory> #include <memory>
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/string_or_dictionary.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_element_creation_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
...@@ -28,7 +28,7 @@ class CustomElementUpgradeSorterTest : public PageTestBase { ...@@ -28,7 +28,7 @@ class CustomElementUpgradeSorterTest : public PageTestBase {
Element* CreateElementWithId(const char* local_name, const char* id) { Element* CreateElementWithId(const char* local_name, const char* id) {
NonThrowableExceptionState no_exceptions; NonThrowableExceptionState no_exceptions;
Element* element = GetDocument().CreateElementForBinding( Element* element = GetDocument().CreateElementForBinding(
local_name, StringOrDictionary(), no_exceptions); local_name, StringOrElementCreationOptions(), no_exceptions);
element->setAttribute(html_names::kIdAttr, id); element->setAttribute(html_names::kIdAttr, id);
return element; return element;
} }
...@@ -41,7 +41,7 @@ class CustomElementUpgradeSorterTest : public PageTestBase { ...@@ -41,7 +41,7 @@ class CustomElementUpgradeSorterTest : public PageTestBase {
TEST_F(CustomElementUpgradeSorterTest, inOtherDocument_notInSet) { TEST_F(CustomElementUpgradeSorterTest, inOtherDocument_notInSet) {
NonThrowableExceptionState no_exceptions; NonThrowableExceptionState no_exceptions;
Element* element = GetDocument().CreateElementForBinding( Element* element = GetDocument().CreateElementForBinding(
"a-a", StringOrDictionary(), no_exceptions); "a-a", StringOrElementCreationOptions(), no_exceptions);
Document* other_document = HTMLDocument::CreateForTest(); Document* other_document = HTMLDocument::CreateForTest();
other_document->AppendChild(element); other_document->AppendChild(element);
...@@ -60,7 +60,7 @@ TEST_F(CustomElementUpgradeSorterTest, inOtherDocument_notInSet) { ...@@ -60,7 +60,7 @@ TEST_F(CustomElementUpgradeSorterTest, inOtherDocument_notInSet) {
TEST_F(CustomElementUpgradeSorterTest, oneCandidate) { TEST_F(CustomElementUpgradeSorterTest, oneCandidate) {
NonThrowableExceptionState no_exceptions; NonThrowableExceptionState no_exceptions;
Element* element = GetDocument().CreateElementForBinding( Element* element = GetDocument().CreateElementForBinding(
"a-a", StringOrDictionary(), no_exceptions); "a-a", StringOrElementCreationOptions(), no_exceptions);
GetDocument().documentElement()->AppendChild(element); GetDocument().documentElement()->AppendChild(element);
CustomElementUpgradeSorter sorter; CustomElementUpgradeSorter sorter;
......
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