Bug 1436308 - Generate a ToJSON() method for WebIDL types with records r=bz
authorTim Taubert <ttaubert@mozilla.com>
Wed, 07 Feb 2018 12:01:00 +0100
changeset 402778 13e0088b85fd056b409e79563ac707858662264c
parent 402777 f1a8cafe2ed9702e3e3709d8836bd8b12f93cf12
child 402779 fd15c14e5efb1874591f4e113c1ae1c49154804f
push id33402
push useraciure@mozilla.com
push dateWed, 07 Feb 2018 22:06:27 +0000
treeherdermozilla-central@8cc2427a322c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1436308
milestone60.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 1436308 - Generate a ToJSON() method for WebIDL types with records r=bz We currently don't generate a ::ToJSON() method for WebIDL types with record<K,V> members. These types should be safe to convert to JSON, as long as type V itself is. Per spec, type K is always a DOMString, USVString, or ByteString.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -13818,16 +13818,21 @@ class CGDictionary(CGThing):
             # Strings are always OK.
             return True
 
         if type.isPrimitive():
             # Primitives (numbers and booleans) are ok, as long as
             # they're not unrestricted float/double.
             return not type.isFloat() or not type.isUnrestricted()
 
+        if type.isRecord():
+            # Records are okay, as long as the value type is.
+            # Per spec, only strings are allowed as keys.
+            return CGDictionary.typeSafeToJSONify(type.inner)
+
         return False
 
     @staticmethod
     def dictionarySafeToJSONify(dictionary):
         # The dictionary itself is OK, so we're good if all our types are.
         return all(CGDictionary.typeSafeToJSONify(m.type)
                    for m in dictionary.members)