From e335c1f7974bcecc811d9821e82a14b30bd0f08f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 9 May 2013 13:08:29 -0400 Subject: [PATCH] Bug 869014. Don't allow name collisions between external interfaces and other objects. r=khuey --- dom/bindings/parser/WebIDL.py | 9 +++- dom/bindings/parser/tests/test_interface.py | 43 +++++++++++++++++++ dom/webidl/ClientRectList.webidl | 2 - dom/webidl/Document.webidl | 1 - dom/webidl/FileHandle.webidl | 2 +- dom/webidl/HTMLCollection.webidl | 2 - dom/webidl/HTMLElement.webidl | 2 - dom/webidl/HTMLOptionsCollection.webidl | 2 - dom/webidl/MozNamedAttrMap.webidl | 2 - dom/webidl/PaintRequest.webidl | 2 - dom/webidl/Range.webidl | 2 - dom/webidl/SVGMaskElement.webidl | 1 - dom/webidl/SVGSVGElement.webidl | 1 - dom/webidl/WebComponents.webidl | 3 +- dom/webidl/WebGLRenderingContext.webidl | 7 --- .../XMLStylesheetProcessingInstruction.webidl | 2 - 16 files changed, 53 insertions(+), 30 deletions(-) diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 704c8f218125..83ad06f59d47 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -3396,8 +3396,15 @@ class Parser(Tokenizer): try: if self.globalScope()._lookupIdentifier(identifier): p[0] = self.globalScope()._lookupIdentifier(identifier) + if not isinstance(p[0], IDLExternalInterface): + raise WebIDLError("Name collision between external " + "interface declaration for identifier " + "%s and %s" % (identifier.name, p[0]), + [location, p[0].location]) return - except: + except Exception, ex: + if isinstance(ex, WebIDLError): + raise ex pass p[0] = IDLExternalInterface(location, self.globalScope(), identifier) diff --git a/dom/bindings/parser/tests/test_interface.py b/dom/bindings/parser/tests/test_interface.py index e5c9570674b2..94d575715341 100644 --- a/dom/bindings/parser/tests/test_interface.py +++ b/dom/bindings/parser/tests/test_interface.py @@ -317,6 +317,49 @@ def WebIDLTest(parser, harness): "Should not allow a name collision between interface " "and other object") + parser = parser.reset() + threw = False + try: + parser.parse(""" + dictionary A { + boolean x; + }; + interface A; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow a name collision between external interface " + "and other object") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface A { + readonly attribute boolean x; + }; + interface A; + """) + results = parser.finish() + except: + threw = True + harness.ok(threw, + "Should not allow a name collision between external interface " + "and interface") + + parser = parser.reset() + parser.parse(""" + interface A; + interface A; + """) + results = parser.finish() + harness.ok(len(results) == 1 and + isinstance(results[0], WebIDL.IDLExternalInterface), + "Should allow name collisions between external interface " + "declarations") + parser = parser.reset() threw = False try: diff --git a/dom/webidl/ClientRectList.webidl b/dom/webidl/ClientRectList.webidl index df3f84daf0ff..964425bd0f80 100644 --- a/dom/webidl/ClientRectList.webidl +++ b/dom/webidl/ClientRectList.webidl @@ -4,8 +4,6 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface ClientRect; - interface ClientRectList { readonly attribute unsigned long length; getter ClientRect? item(unsigned long index); diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index 2b7dddf03785..1a8ed54d0ece 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -15,7 +15,6 @@ * http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/core/nsIDOMDocument.idl */ -interface Comment; interface StyleSheetList; interface TouchList; interface WindowProxy; diff --git a/dom/webidl/FileHandle.webidl b/dom/webidl/FileHandle.webidl index 57da19887cd4..ba4f31f45d51 100644 --- a/dom/webidl/FileHandle.webidl +++ b/dom/webidl/FileHandle.webidl @@ -1,8 +1,8 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface DOMRequest; interface LockedFile; enum FileMode { "readonly", "readwrite" }; diff --git a/dom/webidl/HTMLCollection.webidl b/dom/webidl/HTMLCollection.webidl index 5797f85e3924..1e56c3c01aff 100644 --- a/dom/webidl/HTMLCollection.webidl +++ b/dom/webidl/HTMLCollection.webidl @@ -10,8 +10,6 @@ * liability, trademark and document use rules apply. */ -interface Element; - interface HTMLCollection { readonly attribute unsigned long length; getter Element? item(unsigned long index); diff --git a/dom/webidl/HTMLElement.webidl b/dom/webidl/HTMLElement.webidl index 6f0b223519cc..781c75a79dbe 100644 --- a/dom/webidl/HTMLElement.webidl +++ b/dom/webidl/HTMLElement.webidl @@ -12,8 +12,6 @@ * and create derivative works of this document. */ -interface DOMStringMap; - interface HTMLElement : Element { // metadata attributes attribute DOMString title; diff --git a/dom/webidl/HTMLOptionsCollection.webidl b/dom/webidl/HTMLOptionsCollection.webidl index 1a6c3c00702f..d54fd19a4640 100644 --- a/dom/webidl/HTMLOptionsCollection.webidl +++ b/dom/webidl/HTMLOptionsCollection.webidl @@ -10,8 +10,6 @@ * liability, trademark and document use rules apply. */ -interface HTMLOptionElement; - interface HTMLOptionsCollection : HTMLCollection { attribute unsigned long length; [Throws] diff --git a/dom/webidl/MozNamedAttrMap.webidl b/dom/webidl/MozNamedAttrMap.webidl index 9e67f75d8071..fff69106f609 100644 --- a/dom/webidl/MozNamedAttrMap.webidl +++ b/dom/webidl/MozNamedAttrMap.webidl @@ -3,8 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface Attr; - /** * This is a temporary, non-standard interface, to ease the transition to a * world where Attr no longer inherits from Node. diff --git a/dom/webidl/PaintRequest.webidl b/dom/webidl/PaintRequest.webidl index 515cb662a253..4d35e20b3712 100644 --- a/dom/webidl/PaintRequest.webidl +++ b/dom/webidl/PaintRequest.webidl @@ -3,8 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface ClientRect; - /** * These objects are exposed by the MozDOMAfterPaint event. Each one represents * a request to repaint a rectangle that was generated by the browser. diff --git a/dom/webidl/Range.webidl b/dom/webidl/Range.webidl index 9f0f0977b603..99c672a4561b 100644 --- a/dom/webidl/Range.webidl +++ b/dom/webidl/Range.webidl @@ -12,8 +12,6 @@ * liability, trademark and document use rules apply. */ -interface ClientRect; - interface Range { [Throws] readonly attribute Node startContainer; diff --git a/dom/webidl/SVGMaskElement.webidl b/dom/webidl/SVGMaskElement.webidl index cf639b3b3e4c..334f5aba5c90 100644 --- a/dom/webidl/SVGMaskElement.webidl +++ b/dom/webidl/SVGMaskElement.webidl @@ -11,7 +11,6 @@ */ interface SVGAnimatedEnumeration; -interface SVGAnimatedLength; interface SVGMaskElement : SVGElement { diff --git a/dom/webidl/SVGSVGElement.webidl b/dom/webidl/SVGSVGElement.webidl index 634dc29193ab..1c23e8b9309d 100644 --- a/dom/webidl/SVGSVGElement.webidl +++ b/dom/webidl/SVGSVGElement.webidl @@ -12,7 +12,6 @@ interface SVGAnimatedString; interface SVGViewSpec; -interface SVGPoint; interface SVGSVGElement : SVGGraphicsElement { diff --git a/dom/webidl/WebComponents.webidl b/dom/webidl/WebComponents.webidl index 4d946b4e16fd..e165f88909da 100644 --- a/dom/webidl/WebComponents.webidl +++ b/dom/webidl/WebComponents.webidl @@ -1,3 +1,4 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. @@ -9,8 +10,6 @@ * liability, trademark and document use rules apply. */ -interface DocumentFragment; - callback LifecycleCreatedCallback = void(); dictionary LifecycleCallbacks { diff --git a/dom/webidl/WebGLRenderingContext.webidl b/dom/webidl/WebGLRenderingContext.webidl index ce3f08de8458..b458599e5d03 100644 --- a/dom/webidl/WebGLRenderingContext.webidl +++ b/dom/webidl/WebGLRenderingContext.webidl @@ -15,13 +15,6 @@ // This IDL depends on the typed array specification defined at: // https://www.khronos.org/registry/typedarray/specs/latest/typedarrays.idl -// XXXbz all sorts of forward declarations for things that are not new -// bindings yet. -interface Event; -interface HTMLCanvasElement; -interface HTMLVideoElement; -interface ImageData; - typedef unsigned long GLenum; typedef boolean GLboolean; typedef unsigned long GLbitfield; diff --git a/dom/webidl/XMLStylesheetProcessingInstruction.webidl b/dom/webidl/XMLStylesheetProcessingInstruction.webidl index bd67bb3868a2..ec7d64a0d3ae 100644 --- a/dom/webidl/XMLStylesheetProcessingInstruction.webidl +++ b/dom/webidl/XMLStylesheetProcessingInstruction.webidl @@ -4,8 +4,6 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface StyleSheet; - interface XMLStylesheetProcessingInstruction : ProcessingInstruction { readonly attribute StyleSheet? sheet; };