From 2a2e8b176d3c70ebe05c2e46d60112e161a8fd39 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 29 Apr 2015 15:31:06 +0200 Subject: [PATCH 1/2] Properly generate proxy stringifiers --- .../dom/bindings/codegen/CodegenRust.py | 21 +------------------ .../dom/bindings/codegen/Configuration.py | 2 +- components/script/dom/location.rs | 2 +- 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 6b4acd64bd4..02a591fd174 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -4089,25 +4089,6 @@ class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod): CGAbstractExternMethod.__init__(self, descriptor, "obj_toString", "*mut JSString", args) self.descriptor = descriptor def getBody(self): - stringifier = self.descriptor.operations['Stringifier'] - if stringifier: - name = self.descriptor.binaryNameFor(stringifier.identifier.name) - nativeName = MakeNativeName(name) - signature = stringifier.signatures()[0] - returnType = signature[0] - extendedAttributes = self.descriptor.getExtendedAttributes(stringifier) - infallible = 'infallible' in extendedAttributes - if not infallible: - error = CGGeneric( - ('ThrowMethodFailedWithDetails(cx, rv, "%s", "toString");\n' + - "return NULL;") % self.descriptor.interface.identifier.name) - else: - error = None - call = CGCallGenerator(error, [], "", returnType, extendedAttributes, self.descriptor, nativeName, False, object="UnwrapProxy(proxy)") - return call.define() + """\ -JSString* jsresult; -return xpc_qsStringToJsstring(cx, result, &jsresult) ? jsresult : NULL;""" - return """proxyhandler::object_to_string(cx, "%s")""" % self.descriptor.name def definition_body(self): @@ -4247,7 +4228,7 @@ class CGInterfaceTrait(CGThing): if descriptor.proxy: for name, operation in descriptor.operations.iteritems(): - if not operation: + if not operation or operation.isStringifier(): continue assert len(operation.signatures()) == 1 diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py index 5ea521e15b8..8741cb9eacf 100644 --- a/components/script/dom/bindings/codegen/Configuration.py +++ b/components/script/dom/bindings/codegen/Configuration.py @@ -254,7 +254,7 @@ class Descriptor(DescriptorProvider): self._binaryNames = desc.get('binaryNames', {}) self._binaryNames.setdefault('__legacycaller', 'LegacyCall') - self._binaryNames.setdefault('__stringifier', 'Stringify') + self._binaryNames.setdefault('__stringifier', 'Stringifier') for member in self.interface.members: if not member.isAttr() and not member.isMethod(): diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index 97da0a3066a..20ead7dc298 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -53,7 +53,7 @@ impl<'a> LocationMethods for JSRef<'a, Location> { } // https://url.spec.whatwg.org/#URLUtils-stringification-behavior - fn Stringify(self) -> DOMString { + fn Stringifier(self) -> DOMString { self.Href().0 } From 3b82cba0112020979d51333b06e91b7c2c6c6bc1 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 29 Apr 2015 17:56:37 +0200 Subject: [PATCH 2/2] Implement trivial stringifiers --- components/script/dom/domtokenlist.rs | 5 ++++ components/script/dom/urlsearchparams.rs | 5 ++++ .../script/dom/webidls/DOMTokenList.webidl | 2 +- .../script/dom/webidls/URLSearchParams.webidl | 2 +- tests/wpt/metadata/dom/interfaces.html.ini | 3 -- .../dom/nodes/Element-classlist.html.ini | 30 ------------------- 6 files changed, 12 insertions(+), 35 deletions(-) diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index 7ee5e632900..0a42db03d5d 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -159,4 +159,9 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> { } } } + + // https://dom.spec.whatwg.org/#stringification-behavior + fn Stringifier(self) -> DOMString { + self.element.root().r().get_string_attribute(&self.local_name) + } } diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs index f19e936ce54..91c25794716 100644 --- a/components/script/dom/urlsearchparams.rs +++ b/components/script/dom/urlsearchparams.rs @@ -106,6 +106,11 @@ impl<'a> URLSearchParamsMethods for JSRef<'a, URLSearchParams> { self.data.borrow_mut().insert(name, vec!(value)); self.update_steps(); } + + // https://url.spec.whatwg.org/#stringification-behavior + fn Stringifier(self) -> DOMString { + DOMString::from_utf8(self.serialize(None)).unwrap() + } } pub trait URLSearchParamsHelpers { diff --git a/components/script/dom/webidls/DOMTokenList.webidl b/components/script/dom/webidls/DOMTokenList.webidl index 764f18d6dfa..61a3bebff15 100644 --- a/components/script/dom/webidls/DOMTokenList.webidl +++ b/components/script/dom/webidls/DOMTokenList.webidl @@ -17,5 +17,5 @@ interface DOMTokenList { [Throws] boolean toggle(DOMString token, optional boolean force); - //stringifier; + stringifier; }; diff --git a/components/script/dom/webidls/URLSearchParams.webidl b/components/script/dom/webidls/URLSearchParams.webidl index 3d61263cbc9..f0ddafad291 100644 --- a/components/script/dom/webidls/URLSearchParams.webidl +++ b/components/script/dom/webidls/URLSearchParams.webidl @@ -15,5 +15,5 @@ interface URLSearchParams { // sequence getAll(DOMString name); boolean has(DOMString name); void set(DOMString name, DOMString value); - //stringifier; + stringifier; }; diff --git a/tests/wpt/metadata/dom/interfaces.html.ini b/tests/wpt/metadata/dom/interfaces.html.ini index 3abf7a55e5d..14ac6621ede 100644 --- a/tests/wpt/metadata/dom/interfaces.html.ini +++ b/tests/wpt/metadata/dom/interfaces.html.ini @@ -825,9 +825,6 @@ [DOMTokenList interface: operation toggle(DOMString,boolean)] expected: FAIL - [DOMTokenList interface: stringifier] - expected: FAIL - [DOMTokenList interface: calling add(DOMString) on document.body.classList with too few arguments must throw TypeError] expected: FAIL diff --git a/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini b/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini index 9a6f69132ab..2526f96f80b 100644 --- a/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini +++ b/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini @@ -12,42 +12,12 @@ [classList.add must not cause the CSS selector to stop matching] expected: FAIL - [classList must stringify correctly when items have been added] - expected: FAIL - - [classList.add should not add a token if it already exists] - expected: FAIL - - [classList.remove removes arguments passed, if they are present.] - expected: FAIL - - [classList.remove must remove existing tokens] - expected: FAIL - [classList.remove must not break case-sensitive CSS selector matching] expected: FAIL - [classList.remove must collapse whitespace around removed tokens] - expected: FAIL - - [classList.remove must collapse whitespaces around each token] - expected: FAIL - - [classList.remove must collapse whitespaces around each token and remove duplicates] - expected: FAIL - - [classList.remove must collapse whitespace when removing duplicate tokens] - expected: FAIL - - [classList.add must collapse whitespaces and remove duplicates when adding a token that already exists] - expected: FAIL - [classList.toggle must not break case-sensitive CSS selector matching] expected: FAIL [CSS class selectors must stop matching when all classes have been removed] expected: FAIL - [classList must stringify to an empty string when all classes have been removed] - expected: FAIL -