Bug 1465602 part 1. Enforce that the default toJSON can only return 'object'. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 01 Jun 2018 12:17:10 -0400
changeset 475139 916e5914d84acd420f61b5dd48027ddce9465e5d
parent 475138 c78a67ef0566909b2f794c08aff4bc3bca9395f7
child 475140 7c76daa75842e03504329d23ecdfe0b723d02494
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1465602
milestone62.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 1465602 part 1. Enforce that the default toJSON can only return 'object'. r=qdot The spec says: The return type of the default toJSON operation must be object.
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_toJSON.py
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -5126,16 +5126,21 @@ class IDLMethod(IDLInterfaceMember, IDLS
         elif identifier == "Default":
             if not attr.noArguments():
                 raise WebIDLError("[Default] must take no arguments",
                                   [attr.location])
 
             if not self.isToJSON():
                 raise WebIDLError("[Default] is only allowed on toJSON operations",
                                   [attr.location, self.location])
+
+            if self.signatures()[0][0] != BuiltinTypes[IDLBuiltinType.Types.object]:
+                raise WebIDLError("The return type of the default toJSON "
+                                  "operation must be 'object'",
+                                  [attr.location, self.location]);
         elif (identifier == "Throws" or
               identifier == "CanOOM" or
               identifier == "NewObject" or
               identifier == "ChromeOnly" or
               identifier == "Pref" or
               identifier == "Deprecated" or
               identifier == "Func" or
               identifier == "SecureContext" or
--- a/dom/bindings/parser/tests/test_toJSON.py
+++ b/dom/bindings/parser/tests/test_toJSON.py
@@ -42,16 +42,58 @@ def WebIDLTest(parser, harness):
     harness.ok(threw, "Should not allow a toJSON method with arguments.")
 
     parser = parser.reset()
     threw = False
     try:
         parser.parse(
             """
             interface Test {
+              long toJSON();
+            };
+            """)
+        results = parser.finish()
+    except:
+        threw = True
+    harness.ok(not threw, "Should allow a toJSON method with 'long' as return type.")
+
+    parser = parser.reset()
+    threw = False
+    try:
+        parser.parse(
+            """
+            interface Test {
+              [Default] object toJSON();
+            };
+            """)
+        results = parser.finish()
+    except:
+        threw = True
+    harness.ok(not threw, "Should allow a default toJSON method with 'object' as return type.")
+
+    parser = parser.reset()
+    threw = False
+    try:
+        parser.parse(
+            """
+            interface Test {
+              [Default] long toJSON();
+            };
+            """)
+        results = parser.finish()
+    except:
+        threw = True
+    harness.ok(threw, "Should not allow a default toJSON method with non-'object' as return type.")
+
+    parser = parser.reset()
+    threw = False
+    try:
+        parser.parse(
+            """
+            interface Test {
               any toJSON();
             };
             """)
         results = parser.finish()
     except:
         threw = True
     harness.ok(threw, "Should not allow a toJSON method with a non-JSON return type.")