Bug 869014. Don't allow name collisions between external interfaces and other objects. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 May 2013 13:08:29 -0400
changeset 142421 9f7d1f298a2a30848385a004b2f9b06f67630e72
parent 142420 d0829a642fd95060ee22c95766d522e50203ad07
child 142422 c74ce1905b96184e35c5328da98d516b8e692b93
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs869014
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 869014. Don't allow name collisions between external interfaces and other objects. r=khuey
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_interface.py
dom/webidl/ClientRectList.webidl
dom/webidl/Document.webidl
dom/webidl/FileHandle.webidl
dom/webidl/HTMLCollection.webidl
dom/webidl/HTMLElement.webidl
dom/webidl/HTMLOptionsCollection.webidl
dom/webidl/MozNamedAttrMap.webidl
dom/webidl/PaintRequest.webidl
dom/webidl/Range.webidl
dom/webidl/SVGMaskElement.webidl
dom/webidl/SVGSVGElement.webidl
dom/webidl/WebComponents.webidl
dom/webidl/WebGLRenderingContext.webidl
dom/webidl/XMLStylesheetProcessingInstruction.webidl
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -3391,18 +3391,25 @@ class Parser(Tokenizer):
             Interface : INTERFACE IDENTIFIER SEMICOLON
         """
         location = self.getLocation(p, 1)
         identifier = IDLUnresolvedIdentifier(self.getLocation(p, 2), p[2])
 
         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)
 
     def p_PartialInterface(self, p):
         """
             PartialInterface : PARTIAL INTERFACE IDENTIFIER LBRACE InterfaceMembers RBRACE SEMICOLON
         """
--- a/dom/bindings/parser/tests/test_interface.py
+++ b/dom/bindings/parser/tests/test_interface.py
@@ -316,16 +316,59 @@ def WebIDLTest(parser, harness):
     harness.ok(threw,
                "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:
+        parser.parse("""
             [SomeRandomAnnotation]
             interface A {
                 readonly attribute boolean y;
             };
         """)
         results = parser.finish()
     except:
         threw = True
--- a/dom/webidl/ClientRectList.webidl
+++ b/dom/webidl/ClientRectList.webidl
@@ -1,12 +1,10 @@
 /* -*- 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 ClientRect;
-
 interface ClientRectList {
   readonly attribute unsigned long length;
   getter ClientRect? item(unsigned long index);
 };
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -10,17 +10,16 @@
  * http://dvcs.w3.org/hg/pointerlock/raw-file/default/index.html#extensions-to-the-document-interface
  * http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html#sec-document-interface
  * http://dev.w3.org/csswg/cssom/#extensions-to-the-document-interface
  * http://dev.w3.org/csswg/cssom-view/#extensions-to-the-document-interface
  *
  * http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/core/nsIDOMDocument.idl
  */
 
-interface Comment;
 interface StyleSheetList;
 interface TouchList;
 interface WindowProxy;
 interface nsISupports;
 
 enum VisibilityState { "hidden", "visible" };
 
 /* http://dom.spec.whatwg.org/#interface-document */
--- a/dom/webidl/FileHandle.webidl
+++ b/dom/webidl/FileHandle.webidl
@@ -1,13 +1,13 @@
+/* -*- 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" };
 
 interface FileHandle : EventTarget {
   readonly attribute DOMString name;
   readonly attribute DOMString type;
 
--- a/dom/webidl/HTMLCollection.webidl
+++ b/dom/webidl/HTMLCollection.webidl
@@ -5,16 +5,14 @@
  *
  * The origin of this IDL file is
  * http://www.w3.org/TR/2012/WD-dom-20120105/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-interface Element;
-
 interface HTMLCollection {
   readonly attribute unsigned long length;
   getter Element? item(unsigned long index);
   [Throws]
   getter object? namedItem(DOMString name); // only returns Element
 };
--- a/dom/webidl/HTMLElement.webidl
+++ b/dom/webidl/HTMLElement.webidl
@@ -7,18 +7,16 @@
  * http://www.whatwg.org/specs/web-apps/current-work/ and
  * http://dev.w3.org/csswg/cssom-view/
  *
  * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
  * Opera Software ASA. You are granted a license to use, reproduce
  * and create derivative works of this document.
  */
 
-interface DOMStringMap;
-
 interface HTMLElement : Element {
   // metadata attributes
            attribute DOMString title;
            attribute DOMString lang;
   //         attribute boolean translate;
   [SetterThrows, Pure]
            attribute DOMString dir;
   [Constant]
--- a/dom/webidl/HTMLOptionsCollection.webidl
+++ b/dom/webidl/HTMLOptionsCollection.webidl
@@ -5,18 +5,16 @@
  *
  * The origin of this IDL file is
  * http://www.w3.org/TR/2012/WD-html5-20120329/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-interface HTMLOptionElement;
-
 interface HTMLOptionsCollection : HTMLCollection {
            attribute unsigned long length;
   [Throws]
   getter object? namedItem(DOMString name);
   [Throws]
   setter creator void (unsigned long index, HTMLOptionElement? option);
   [Throws]
   void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
--- a/dom/webidl/MozNamedAttrMap.webidl
+++ b/dom/webidl/MozNamedAttrMap.webidl
@@ -1,15 +1,13 @@
 /* -*- 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 Attr;
-
 /**
  * This is a temporary, non-standard interface, to ease the transition to a
  * world where Attr no longer inherits from Node.
  */
 interface MozNamedAttrMap {
   getter Attr? getNamedItem(DOMString name);
   [Throws]
   Attr? setNamedItem(Attr arg);
--- a/dom/webidl/PaintRequest.webidl
+++ b/dom/webidl/PaintRequest.webidl
@@ -1,15 +1,13 @@
 /* -*- 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 ClientRect;
-
 /**
  * These objects are exposed by the MozDOMAfterPaint event. Each one represents
  * a request to repaint a rectangle that was generated by the browser.
  */
 interface PaintRequest {
   /**
    * The client rect where invalidation was triggered.
    */
--- a/dom/webidl/Range.webidl
+++ b/dom/webidl/Range.webidl
@@ -7,18 +7,16 @@
  * http://dom.spec.whatwg.org/#range
  * http://domparsing.spec.whatwg.org/#dom-range-createcontextualfragment
  * http://dvcs.w3.org/hg/csswg/raw-file/tip/cssom-view/Overview.html#extensions-to-the-range-interface
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-interface ClientRect;
-
 interface Range {
   [Throws]
   readonly attribute Node startContainer;
   [Throws]
   readonly attribute unsigned long startOffset;
   [Throws]
   readonly attribute Node endContainer;
   [Throws]
--- a/dom/webidl/SVGMaskElement.webidl
+++ b/dom/webidl/SVGMaskElement.webidl
@@ -6,17 +6,16 @@
  * The origin of this IDL file is
  * http://www.w3.org/TR/SVG2/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface SVGAnimatedEnumeration;
-interface SVGAnimatedLength;
 
 interface SVGMaskElement : SVGElement {
 
   // Mask Types
   const unsigned short SVG_MASKTYPE_LUMINANCE = 0;
   const unsigned short SVG_MASKTYPE_ALPHA = 1;
 
   readonly attribute SVGAnimatedEnumeration maskUnits;
--- a/dom/webidl/SVGSVGElement.webidl
+++ b/dom/webidl/SVGSVGElement.webidl
@@ -7,17 +7,16 @@
  * http://www.w3.org/TR/SVG2/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface SVGAnimatedString;
 interface SVGViewSpec;
-interface SVGPoint;
 
 interface SVGSVGElement : SVGGraphicsElement {
 
   readonly attribute SVGAnimatedLength x;
   readonly attribute SVGAnimatedLength y;
   readonly attribute SVGAnimatedLength width;
   readonly attribute SVGAnimatedLength height;
   // readonly attribute SVGRect viewport;
--- a/dom/webidl/WebComponents.webidl
+++ b/dom/webidl/WebComponents.webidl
@@ -1,21 +1,20 @@
+/* -*- 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/.
  *
  * The origin of this IDL file is
  * http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-interface DocumentFragment;
-
 callback LifecycleCreatedCallback = void();
 
 dictionary LifecycleCallbacks {
   LifecycleCreatedCallback? created = null;
 };
 
 dictionary ElementRegistrationOptions {
   object? prototype = null;
--- a/dom/webidl/WebGLRenderingContext.webidl
+++ b/dom/webidl/WebGLRenderingContext.webidl
@@ -10,23 +10,16 @@
  */
 
 // WebGL IDL definitions scraped from the Khronos specification:
 // https://www.khronos.org/registry/webgl/specs/latest/
 //
 // 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;
 typedef byte           GLbyte;         /* 'byte' should be a signed 8 bit type. */
 typedef short          GLshort;
 typedef long           GLint;
 typedef long           GLsizei;
 typedef long long      GLintptr;
--- a/dom/webidl/XMLStylesheetProcessingInstruction.webidl
+++ b/dom/webidl/XMLStylesheetProcessingInstruction.webidl
@@ -1,11 +1,9 @@
 /* -*- 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 StyleSheet;
-
 interface XMLStylesheetProcessingInstruction : ProcessingInstruction {
   readonly attribute StyleSheet? sheet;
 };