Bug 647323 - Part b: Implement test harness reporting code and import testharness code from the upstream repository; r=jhammel+ted
authorMs2ger <ms2ger@gmail.com>
Thu, 29 Mar 2012 23:08:43 +0200
changeset 93924 bb0cc19274c5c57b49d025a164ffe47857a86424
parent 93923 fd2549d5d38401ee45f3ca7c9597b79dbebb82ce
child 93925 cd07e609e481ce71b2fedd327fbcd6215d2c2c08
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhammel
bugs647323
milestone14.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 647323 - Part b: Implement test harness reporting code and import testharness code from the upstream repository; r=jhammel+ted
dom/tests/mochitest/Makefile.in
dom/tests/mochitest/w3c/Makefile.in
dom/tests/mochitest/w3c/WebIDLParser.js
dom/tests/mochitest/w3c/failures.txt
dom/tests/mochitest/w3c/idlharness.js
dom/tests/mochitest/w3c/testharness.css
dom/tests/mochitest/w3c/testharness.js
dom/tests/mochitest/w3c/testharnessreport.js.in
dom/tests/mochitest/w3c/updateTestharness.py
dom/tests/mochitest/w3c/writeReporter.py
testing/mochitest/tests/SimpleTest/TestRunner.js
testing/mochitest/tests/SimpleTest/specialpowersAPI.js
--- a/dom/tests/mochitest/Makefile.in
+++ b/dom/tests/mochitest/Makefile.in
@@ -52,16 +52,17 @@ DIRS	+= \
 	chrome \
 	general \
 	whatwg \
 	geolocation \
 	localstorage \
 	orientation \
 	sessionstorage \
 	storageevent \
+	w3c \
 	browser-frame \
 	$(NULL)
 
 #needs IPC support, also tests do not run successfully in Firefox for now
 #ifneq (mobile,$(MOZ_BUILD_APP))
 #DIRS	+= notification
 #endif
 
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/w3c/Makefile.in
@@ -0,0 +1,29 @@
+# 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/.
+
+DEPTH = ../../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+relativesrcdir = dom/tests/mochitest/w3c
+
+DIRS = \
+  $(NULL)
+
+include $(DEPTH)/config/autoconf.mk
+include $(topsrcdir)/config/rules.mk
+
+_SUPPORT_FILES = \
+  testharness.js \
+  testharnessreport.js \
+  testharness.css \
+  idlharness.js \
+  WebIDLParser.js \
+  $(NULL)
+
+testharnessreport.js: testharnessreport.js.in writeReporter.py 
+	$(PYTHON_PATH) $(srcdir)/writeReporter.py $<
+
+libs:: $(_SUPPORT_FILES)
+	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/resources
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/w3c/WebIDLParser.js
@@ -0,0 +1,6020 @@
+// From https://github.com/darobin/webidl.js/tree/, under MIT license
+// Forked at https://github.com/ayg/webidl.js
+window.WebIDLParser = (function(){
+  /* Generated by PEG.js 0.6.2 (http://pegjs.majda.cz/). */
+  
+  var result = {
+    /*
+     * Parses the input with a generated parser. If the parsing is successfull,
+     * returns a value explicitly or implicitly specified by the grammar from
+     * which the parser was generated (see |PEG.buildParser|). If the parsing is
+     * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
+     */
+    parse: function(input, startRule) {
+      var parseFunctions = {
+        "AbsoluteScopedName": parse_AbsoluteScopedName,
+        "Argument": parse_Argument,
+        "Arguments": parse_Arguments,
+        "ArgumentsRest": parse_ArgumentsRest,
+        "ArrayType": parse_ArrayType,
+        "Attribute": parse_Attribute,
+        "BooleanLiteral": parse_BooleanLiteral,
+        "ExtAttr": parse_ExtAttr,
+        "ExtAttrArgList": parse_ExtAttrArgList,
+        "ExtAttrNameValue": parse_ExtAttrNameValue,
+        "ExtAttrNamedArgList": parse_ExtAttrNamedArgList,
+        "ExtAttrNoArg": parse_ExtAttrNoArg,
+        "ExtAttrs": parse_ExtAttrs,
+        "ExtAttrsRest": parse_ExtAttrsRest,
+        "GetRaises": parse_GetRaises,
+        "Nullable": parse_Nullable,
+        "Operation": parse_Operation,
+        "OperationRest": parse_OperationRest,
+        "PrimitiveType": parse_PrimitiveType,
+        "Qualifiers": parse_Qualifiers,
+        "Raises": parse_Raises,
+        "RelativeScopedName": parse_RelativeScopedName,
+        "ReturnType": parse_ReturnType,
+        "ScopedName": parse_ScopedName,
+        "ScopedNameList": parse_ScopedNameList,
+        "ScopedNameListRest": parse_ScopedNameListRest,
+        "ScopedNameRest": parse_ScopedNameRest,
+        "Sequence": parse_Sequence,
+        "SetRaises": parse_SetRaises,
+        "SimpleType": parse_SimpleType,
+        "Special": parse_Special,
+        "Stringifier": parse_Stringifier,
+        "TypeDesc": parse_TypeDesc,
+        "UnsignedIntegerType": parse_UnsignedIntegerType,
+        "attrOrOp": parse_attrOrOp,
+        "const": parse_const,
+        "constExpr": parse_constExpr,
+        "decimal": parse_decimal,
+        "defaultValue": parse_defaultValue,
+        "definition": parse_definition,
+        "definitions": parse_definitions,
+        "dictionary": parse_dictionary,
+        "dictionaryMember": parse_dictionaryMember,
+        "dotFloat": parse_dotFloat,
+        "exMember": parse_exMember,
+        "exception": parse_exception,
+        "expFloat": parse_expFloat,
+        "extendedAttributeList": parse_extendedAttributeList,
+        "field": parse_field,
+        "float": parse_float,
+        "floatEe": parse_floatEe,
+        "hex": parse_hex,
+        "identifier": parse_identifier,
+        "ifInheritance": parse_ifInheritance,
+        "ifMember": parse_ifMember,
+        "implements": parse_implements,
+        "integer": parse_integer,
+        "interface": parse_interface,
+        "leadFloat": parse_leadFloat,
+        "module": parse_module,
+        "octal": parse_octal,
+        "other": parse_other,
+        "partialinterface": parse_partialinterface,
+        "s": parse_s,
+        "space": parse_space,
+        "string": parse_string,
+        "type": parse_type,
+        "typedef": parse_typedef,
+        "w": parse_w
+      };
+      
+      if (startRule !== undefined) {
+        if (parseFunctions[startRule] === undefined) {
+          throw new Error("Invalid rule name: " + quote(startRule) + ".");
+        }
+      } else {
+        startRule = "definitions";
+      }
+      
+      var pos = 0;
+      var reportMatchFailures = true;
+      var rightmostMatchFailuresPos = 0;
+      var rightmostMatchFailuresExpected = [];
+      var cache = {};
+      
+      function padLeft(input, padding, length) {
+        var result = input;
+        
+        var padLength = length - input.length;
+        for (var i = 0; i < padLength; i++) {
+          result = padding + result;
+        }
+        
+        return result;
+      }
+      
+      function escape(ch) {
+        var charCode = ch.charCodeAt(0);
+        
+        if (charCode <= 0xFF) {
+          var escapeChar = 'x';
+          var length = 2;
+        } else {
+          var escapeChar = 'u';
+          var length = 4;
+        }
+        
+        return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
+      }
+      
+      function quote(s) {
+        /*
+         * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
+         * string literal except for the closing quote character, backslash,
+         * carriage return, line separator, paragraph separator, and line feed.
+         * Any character may appear in the form of an escape sequence.
+         */
+        return '"' + s
+          .replace(/\\/g, '\\\\')            // backslash
+          .replace(/"/g, '\\"')              // closing quote character
+          .replace(/\r/g, '\\r')             // carriage return
+          .replace(/\n/g, '\\n')             // line feed
+          .replace(/[\x80-\uFFFF]/g, escape) // non-ASCII characters
+          + '"';
+      }
+      
+      function matchFailed(failure) {
+        if (pos < rightmostMatchFailuresPos) {
+          return;
+        }
+        
+        if (pos > rightmostMatchFailuresPos) {
+          rightmostMatchFailuresPos = pos;
+          rightmostMatchFailuresExpected = [];
+        }
+        
+        rightmostMatchFailuresExpected.push(failure);
+      }
+      
+      function parse_space() {
+        var cacheKey = 'space@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        if (input.substr(pos, 1) === " ") {
+          var result20 = " ";
+          pos += 1;
+        } else {
+          var result20 = null;
+          if (reportMatchFailures) {
+            matchFailed("\" \"");
+          }
+        }
+        if (result20 !== null) {
+          var result0 = result20;
+        } else {
+          if (input.substr(pos, 1) === "	") {
+            var result19 = "	";
+            pos += 1;
+          } else {
+            var result19 = null;
+            if (reportMatchFailures) {
+              matchFailed("\"	\"");
+            }
+          }
+          if (result19 !== null) {
+            var result0 = result19;
+          } else {
+            if (input.substr(pos, 1) === "\r") {
+              var result18 = "\r";
+              pos += 1;
+            } else {
+              var result18 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"\\r\"");
+              }
+            }
+            if (result18 !== null) {
+              var result0 = result18;
+            } else {
+              if (input.substr(pos, 1) === "\n") {
+                var result17 = "\n";
+                pos += 1;
+              } else {
+                var result17 = null;
+                if (reportMatchFailures) {
+                  matchFailed("\"\\n\"");
+                }
+              }
+              if (result17 !== null) {
+                var result0 = result17;
+              } else {
+                if (input.substr(pos, 1) === "") {
+                  var result16 = "";
+                  pos += 1;
+                } else {
+                  var result16 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"\"");
+                  }
+                }
+                if (result16 !== null) {
+                  var result0 = result16;
+                } else {
+                  var savedPos3 = pos;
+                  if (input.substr(pos, 2) === "//") {
+                    var result12 = "//";
+                    pos += 2;
+                  } else {
+                    var result12 = null;
+                    if (reportMatchFailures) {
+                      matchFailed("\"//\"");
+                    }
+                  }
+                  if (result12 !== null) {
+                    var result13 = [];
+                    if (input.substr(pos).match(/^[^\n]/) !== null) {
+                      var result15 = input.charAt(pos);
+                      pos++;
+                    } else {
+                      var result15 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("[^\\n]");
+                      }
+                    }
+                    while (result15 !== null) {
+                      result13.push(result15);
+                      if (input.substr(pos).match(/^[^\n]/) !== null) {
+                        var result15 = input.charAt(pos);
+                        pos++;
+                      } else {
+                        var result15 = null;
+                        if (reportMatchFailures) {
+                          matchFailed("[^\\n]");
+                        }
+                      }
+                    }
+                    if (result13 !== null) {
+                      if (input.substr(pos, 1) === "\n") {
+                        var result14 = "\n";
+                        pos += 1;
+                      } else {
+                        var result14 = null;
+                        if (reportMatchFailures) {
+                          matchFailed("\"\\n\"");
+                        }
+                      }
+                      if (result14 !== null) {
+                        var result11 = [result12, result13, result14];
+                      } else {
+                        var result11 = null;
+                        pos = savedPos3;
+                      }
+                    } else {
+                      var result11 = null;
+                      pos = savedPos3;
+                    }
+                  } else {
+                    var result11 = null;
+                    pos = savedPos3;
+                  }
+                  if (result11 !== null) {
+                    var result0 = result11;
+                  } else {
+                    var savedPos0 = pos;
+                    if (input.substr(pos, 2) === "/*") {
+                      var result2 = "/*";
+                      pos += 2;
+                    } else {
+                      var result2 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\"/*\"");
+                      }
+                    }
+                    if (result2 !== null) {
+                      var result3 = [];
+                      if (input.substr(pos).match(/^[^*]/) !== null) {
+                        var result10 = input.charAt(pos);
+                        pos++;
+                      } else {
+                        var result10 = null;
+                        if (reportMatchFailures) {
+                          matchFailed("[^*]");
+                        }
+                      }
+                      if (result10 !== null) {
+                        var result5 = result10;
+                      } else {
+                        var savedPos1 = pos;
+                        if (input.substr(pos, 1) === "*") {
+                          var result7 = "*";
+                          pos += 1;
+                        } else {
+                          var result7 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\"*\"");
+                          }
+                        }
+                        if (result7 !== null) {
+                          var savedPos2 = pos;
+                          var savedReportMatchFailuresVar0 = reportMatchFailures;
+                          reportMatchFailures = false;
+                          if (input.substr(pos, 1) === "/") {
+                            var result9 = "/";
+                            pos += 1;
+                          } else {
+                            var result9 = null;
+                            if (reportMatchFailures) {
+                              matchFailed("\"/\"");
+                            }
+                          }
+                          reportMatchFailures = savedReportMatchFailuresVar0;
+                          if (result9 === null) {
+                            var result8 = '';
+                          } else {
+                            var result8 = null;
+                            pos = savedPos2;
+                          }
+                          if (result8 !== null) {
+                            var result6 = [result7, result8];
+                          } else {
+                            var result6 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result6 = null;
+                          pos = savedPos1;
+                        }
+                        if (result6 !== null) {
+                          var result5 = result6;
+                        } else {
+                          var result5 = null;;
+                        };
+                      }
+                      while (result5 !== null) {
+                        result3.push(result5);
+                        if (input.substr(pos).match(/^[^*]/) !== null) {
+                          var result10 = input.charAt(pos);
+                          pos++;
+                        } else {
+                          var result10 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("[^*]");
+                          }
+                        }
+                        if (result10 !== null) {
+                          var result5 = result10;
+                        } else {
+                          var savedPos1 = pos;
+                          if (input.substr(pos, 1) === "*") {
+                            var result7 = "*";
+                            pos += 1;
+                          } else {
+                            var result7 = null;
+                            if (reportMatchFailures) {
+                              matchFailed("\"*\"");
+                            }
+                          }
+                          if (result7 !== null) {
+                            var savedPos2 = pos;
+                            var savedReportMatchFailuresVar0 = reportMatchFailures;
+                            reportMatchFailures = false;
+                            if (input.substr(pos, 1) === "/") {
+                              var result9 = "/";
+                              pos += 1;
+                            } else {
+                              var result9 = null;
+                              if (reportMatchFailures) {
+                                matchFailed("\"/\"");
+                              }
+                            }
+                            reportMatchFailures = savedReportMatchFailuresVar0;
+                            if (result9 === null) {
+                              var result8 = '';
+                            } else {
+                              var result8 = null;
+                              pos = savedPos2;
+                            }
+                            if (result8 !== null) {
+                              var result6 = [result7, result8];
+                            } else {
+                              var result6 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result6 = null;
+                            pos = savedPos1;
+                          }
+                          if (result6 !== null) {
+                            var result5 = result6;
+                          } else {
+                            var result5 = null;;
+                          };
+                        }
+                      }
+                      if (result3 !== null) {
+                        if (input.substr(pos, 2) === "*/") {
+                          var result4 = "*/";
+                          pos += 2;
+                        } else {
+                          var result4 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\"*/\"");
+                          }
+                        }
+                        if (result4 !== null) {
+                          var result1 = [result2, result3, result4];
+                        } else {
+                          var result1 = null;
+                          pos = savedPos0;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos0;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos0;
+                    }
+                    if (result1 !== null) {
+                      var result0 = result1;
+                    } else {
+                      var result0 = null;;
+                    };
+                  };
+                };
+              };
+            };
+          };
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_s() {
+        var cacheKey = 's@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var result1 = parse_space();
+        if (result1 !== null) {
+          var result0 = [];
+          while (result1 !== null) {
+            result0.push(result1);
+            var result1 = parse_space();
+          }
+        } else {
+          var result0 = null;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_w() {
+        var cacheKey = 'w@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var result1 = parse_s();
+        var result0 = result1 !== null ? result1 : '';
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_identifier() {
+        var cacheKey = 'identifier@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos).match(/^[A-Z_a-z]/) !== null) {
+          var result3 = input.charAt(pos);
+          pos++;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("[A-Z_a-z]");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = [];
+          if (input.substr(pos).match(/^[0-9A-Z_a-z]/) !== null) {
+            var result5 = input.charAt(pos);
+            pos++;
+          } else {
+            var result5 = null;
+            if (reportMatchFailures) {
+              matchFailed("[0-9A-Z_a-z]");
+            }
+          }
+          while (result5 !== null) {
+            result4.push(result5);
+            if (input.substr(pos).match(/^[0-9A-Z_a-z]/) !== null) {
+              var result5 = input.charAt(pos);
+              pos++;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9A-Z_a-z]");
+              }
+            }
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(nmstart, nmchars) { return nmstart + nmchars.join(""); })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_octal() {
+        var cacheKey = 'octal@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 1) === "0") {
+          var result3 = "0";
+          pos += 1;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"0\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = [];
+          if (input.substr(pos).match(/^[0-7]/) !== null) {
+            var result5 = input.charAt(pos);
+            pos++;
+          } else {
+            var result5 = null;
+            if (reportMatchFailures) {
+              matchFailed("[0-7]");
+            }
+          }
+          while (result5 !== null) {
+            result4.push(result5);
+            if (input.substr(pos).match(/^[0-7]/) !== null) {
+              var result5 = input.charAt(pos);
+              pos++;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-7]");
+              }
+            }
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(value) { return "0" + value.join(""); })(result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_hex() {
+        var cacheKey = 'hex@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 1) === "0") {
+          var result3 = "0";
+          pos += 1;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"0\"");
+          }
+        }
+        if (result3 !== null) {
+          if (input.substr(pos).match(/^[Xx]/) !== null) {
+            var result4 = input.charAt(pos);
+            pos++;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("[Xx]");
+            }
+          }
+          if (result4 !== null) {
+            if (input.substr(pos).match(/^[0-9A-Fa-f]/) !== null) {
+              var result6 = input.charAt(pos);
+              pos++;
+            } else {
+              var result6 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9A-Fa-f]");
+              }
+            }
+            if (result6 !== null) {
+              var result5 = [];
+              while (result6 !== null) {
+                result5.push(result6);
+                if (input.substr(pos).match(/^[0-9A-Fa-f]/) !== null) {
+                  var result6 = input.charAt(pos);
+                  pos++;
+                } else {
+                  var result6 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("[0-9A-Fa-f]");
+                  }
+                }
+              }
+            } else {
+              var result5 = null;
+            }
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(x, value) { return "0" + x + value.join(""); })(result1[1], result1[2])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_decimal() {
+        var cacheKey = 'decimal@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos).match(/^[0-9]/) !== null) {
+          var result3 = input.charAt(pos);
+          pos++;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("[0-9]");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = [];
+          if (input.substr(pos).match(/^[0-9]/) !== null) {
+            var result5 = input.charAt(pos);
+            pos++;
+          } else {
+            var result5 = null;
+            if (reportMatchFailures) {
+              matchFailed("[0-9]");
+            }
+          }
+          while (result5 !== null) {
+            result4.push(result5);
+            if (input.substr(pos).match(/^[0-9]/) !== null) {
+              var result5 = input.charAt(pos);
+              pos++;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9]");
+              }
+            }
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(numStart, numRest) { return numStart + numRest.join(""); })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_integer() {
+        var cacheKey = 'integer@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 1) === "-") {
+          var result8 = "-";
+          pos += 1;
+        } else {
+          var result8 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"-\"");
+          }
+        }
+        var result3 = result8 !== null ? result8 : '';
+        if (result3 !== null) {
+          var result7 = parse_hex();
+          if (result7 !== null) {
+            var result4 = result7;
+          } else {
+            var result6 = parse_octal();
+            if (result6 !== null) {
+              var result4 = result6;
+            } else {
+              var result5 = parse_decimal();
+              if (result5 !== null) {
+                var result4 = result5;
+              } else {
+                var result4 = null;;
+              };
+            };
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(neg, num) { return neg + num; })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_floatEe() {
+        var cacheKey = 'floatEe@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos).match(/^[Ee]/) !== null) {
+          var result3 = input.charAt(pos);
+          pos++;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("[Ee]");
+          }
+        }
+        if (result3 !== null) {
+          if (input.substr(pos).match(/^[+\-]/) !== null) {
+            var result7 = input.charAt(pos);
+            pos++;
+          } else {
+            var result7 = null;
+            if (reportMatchFailures) {
+              matchFailed("[+\\-]");
+            }
+          }
+          var result4 = result7 !== null ? result7 : '';
+          if (result4 !== null) {
+            if (input.substr(pos).match(/^[0-9]/) !== null) {
+              var result6 = input.charAt(pos);
+              pos++;
+            } else {
+              var result6 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9]");
+              }
+            }
+            if (result6 !== null) {
+              var result5 = [];
+              while (result6 !== null) {
+                result5.push(result6);
+                if (input.substr(pos).match(/^[0-9]/) !== null) {
+                  var result6 = input.charAt(pos);
+                  pos++;
+                } else {
+                  var result6 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("[0-9]");
+                  }
+                }
+              }
+            } else {
+              var result5 = null;
+            }
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(e, sign, exp) { return e + sign + exp.join(""); })(result1[0], result1[1], result1[2])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_expFloat() {
+        var cacheKey = 'expFloat@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos).match(/^[0-9]/) !== null) {
+          var result5 = input.charAt(pos);
+          pos++;
+        } else {
+          var result5 = null;
+          if (reportMatchFailures) {
+            matchFailed("[0-9]");
+          }
+        }
+        if (result5 !== null) {
+          var result3 = [];
+          while (result5 !== null) {
+            result3.push(result5);
+            if (input.substr(pos).match(/^[0-9]/) !== null) {
+              var result5 = input.charAt(pos);
+              pos++;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9]");
+              }
+            }
+          }
+        } else {
+          var result3 = null;
+        }
+        if (result3 !== null) {
+          var result4 = parse_floatEe();
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(num, fee) { return num.join("") + fee; })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_leadFloat() {
+        var cacheKey = 'leadFloat@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos).match(/^[0-9]/) !== null) {
+          var result9 = input.charAt(pos);
+          pos++;
+        } else {
+          var result9 = null;
+          if (reportMatchFailures) {
+            matchFailed("[0-9]");
+          }
+        }
+        if (result9 !== null) {
+          var result3 = [];
+          while (result9 !== null) {
+            result3.push(result9);
+            if (input.substr(pos).match(/^[0-9]/) !== null) {
+              var result9 = input.charAt(pos);
+              pos++;
+            } else {
+              var result9 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9]");
+              }
+            }
+          }
+        } else {
+          var result3 = null;
+        }
+        if (result3 !== null) {
+          if (input.substr(pos, 1) === ".") {
+            var result4 = ".";
+            pos += 1;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("\".\"");
+            }
+          }
+          if (result4 !== null) {
+            var result5 = [];
+            if (input.substr(pos).match(/^[0-9]/) !== null) {
+              var result8 = input.charAt(pos);
+              pos++;
+            } else {
+              var result8 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9]");
+              }
+            }
+            while (result8 !== null) {
+              result5.push(result8);
+              if (input.substr(pos).match(/^[0-9]/) !== null) {
+                var result8 = input.charAt(pos);
+                pos++;
+              } else {
+                var result8 = null;
+                if (reportMatchFailures) {
+                  matchFailed("[0-9]");
+                }
+              }
+            }
+            if (result5 !== null) {
+              var result7 = parse_floatEe();
+              var result6 = result7 !== null ? result7 : '';
+              if (result6 !== null) {
+                var result1 = [result3, result4, result5, result6];
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(num, dec, fee) { return num.join("") + "." + dec.join("") + fee; })(result1[0], result1[2], result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_dotFloat() {
+        var cacheKey = 'dotFloat@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = [];
+        if (input.substr(pos).match(/^[0-9]/) !== null) {
+          var result9 = input.charAt(pos);
+          pos++;
+        } else {
+          var result9 = null;
+          if (reportMatchFailures) {
+            matchFailed("[0-9]");
+          }
+        }
+        while (result9 !== null) {
+          result3.push(result9);
+          if (input.substr(pos).match(/^[0-9]/) !== null) {
+            var result9 = input.charAt(pos);
+            pos++;
+          } else {
+            var result9 = null;
+            if (reportMatchFailures) {
+              matchFailed("[0-9]");
+            }
+          }
+        }
+        if (result3 !== null) {
+          if (input.substr(pos, 1) === ".") {
+            var result4 = ".";
+            pos += 1;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("\".\"");
+            }
+          }
+          if (result4 !== null) {
+            if (input.substr(pos).match(/^[0-9]/) !== null) {
+              var result8 = input.charAt(pos);
+              pos++;
+            } else {
+              var result8 = null;
+              if (reportMatchFailures) {
+                matchFailed("[0-9]");
+              }
+            }
+            if (result8 !== null) {
+              var result5 = [];
+              while (result8 !== null) {
+                result5.push(result8);
+                if (input.substr(pos).match(/^[0-9]/) !== null) {
+                  var result8 = input.charAt(pos);
+                  pos++;
+                } else {
+                  var result8 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("[0-9]");
+                  }
+                }
+              }
+            } else {
+              var result5 = null;
+            }
+            if (result5 !== null) {
+              var result7 = parse_floatEe();
+              var result6 = result7 !== null ? result7 : '';
+              if (result6 !== null) {
+                var result1 = [result3, result4, result5, result6];
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(num, dec, fee) { return num.join("") + "." + dec.join("") + fee; })(result1[0], result1[2], result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_float() {
+        var cacheKey = 'float@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 1) === "-") {
+          var result8 = "-";
+          pos += 1;
+        } else {
+          var result8 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"-\"");
+          }
+        }
+        var result3 = result8 !== null ? result8 : '';
+        if (result3 !== null) {
+          var result7 = parse_leadFloat();
+          if (result7 !== null) {
+            var result4 = result7;
+          } else {
+            var result6 = parse_dotFloat();
+            if (result6 !== null) {
+              var result4 = result6;
+            } else {
+              var result5 = parse_expFloat();
+              if (result5 !== null) {
+                var result4 = result5;
+              } else {
+                var result4 = null;;
+              };
+            };
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(neg, num) { return neg + num; })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_string() {
+        var cacheKey = 'string@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 1) === "\"") {
+          var result3 = "\"";
+          pos += 1;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"\\\"\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = [];
+          if (input.substr(pos).match(/^[^""]/) !== null) {
+            var result6 = input.charAt(pos);
+            pos++;
+          } else {
+            var result6 = null;
+            if (reportMatchFailures) {
+              matchFailed("[^\"\"]");
+            }
+          }
+          while (result6 !== null) {
+            result4.push(result6);
+            if (input.substr(pos).match(/^[^""]/) !== null) {
+              var result6 = input.charAt(pos);
+              pos++;
+            } else {
+              var result6 = null;
+              if (reportMatchFailures) {
+                matchFailed("[^\"\"]");
+              }
+            }
+          }
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === "\"") {
+              var result5 = "\"";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"\\\"\"");
+              }
+            }
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(str) { return str.join(""); })(result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_other() {
+        var cacheKey = 'other@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        if (input.substr(pos).match(/^[^	\n\r 0-9A-Z_a-z]/) !== null) {
+          var result3 = input.charAt(pos);
+          pos++;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("[^	\\n\\r 0-9A-Z_a-z]");
+          }
+        }
+        if (result3 !== null) {
+          var result1 = [];
+          while (result3 !== null) {
+            result1.push(result3);
+            if (input.substr(pos).match(/^[^	\n\r 0-9A-Z_a-z]/) !== null) {
+              var result3 = input.charAt(pos);
+              pos++;
+            } else {
+              var result3 = null;
+              if (reportMatchFailures) {
+                matchFailed("[^	\\n\\r 0-9A-Z_a-z]");
+              }
+            }
+          }
+        } else {
+          var result1 = null;
+        }
+        var result2 = result1 !== null
+          ? (function(other) { return other.join(""); })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_type() {
+        var cacheKey = 'type@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_TypeDesc();
+        if (result3 !== null) {
+          var result4 = parse_Nullable();
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(type, nullable) {
+                      if (!type.sequence) type.sequence = false;
+                      type.nullable = nullable;
+                      return type; })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_TypeDesc() {
+        var cacheKey = 'TypeDesc@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result5 = parse_Sequence();
+        if (result5 !== null) {
+          var result1 = result5;
+        } else {
+          var result4 = parse_ArrayType();
+          if (result4 !== null) {
+            var result1 = result4;
+          } else {
+            var result3 = parse_SimpleType();
+            if (result3 !== null) {
+              var result1 = result3;
+            } else {
+              var result1 = null;;
+            };
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(type) { return type; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Sequence() {
+        var cacheKey = 'Sequence@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 9) === "sequence<") {
+          var result3 = "sequence<";
+          pos += 9;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"sequence<\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_type();
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === ">") {
+              var result5 = ">";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\">\"");
+              }
+            }
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(type) { return { sequence: true, array: false, idlType: type }; })(result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ArrayType() {
+        var cacheKey = 'ArrayType@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_SimpleType();
+        if (result3 !== null) {
+          if (input.substr(pos, 2) === "[]") {
+            var result4 = "[]";
+            pos += 2;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("\"[]\"");
+            }
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(type) {
+                      type.array = true;
+                      return type;
+                  })(result1[0])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_SimpleType() {
+        var cacheKey = 'SimpleType@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result5 = parse_PrimitiveType();
+        if (result5 !== null) {
+          var result1 = result5;
+        } else {
+          var result4 = parse_UnsignedIntegerType();
+          if (result4 !== null) {
+            var result1 = result4;
+          } else {
+            var result3 = parse_ScopedName();
+            if (result3 !== null) {
+              var result1 = result3;
+            } else {
+              var result1 = null;;
+            };
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(type) { return { sequence: false, array: false, idlType: type }; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_PrimitiveType() {
+        var cacheKey = 'PrimitiveType@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 3) === "any") {
+          var result12 = "any";
+          pos += 3;
+        } else {
+          var result12 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"any\"");
+          }
+        }
+        if (result12 !== null) {
+          var result3 = result12;
+        } else {
+          if (input.substr(pos, 6) === "object") {
+            var result11 = "object";
+            pos += 6;
+          } else {
+            var result11 = null;
+            if (reportMatchFailures) {
+              matchFailed("\"object\"");
+            }
+          }
+          if (result11 !== null) {
+            var result3 = result11;
+          } else {
+            if (input.substr(pos, 7) === "boolean") {
+              var result10 = "boolean";
+              pos += 7;
+            } else {
+              var result10 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"boolean\"");
+              }
+            }
+            if (result10 !== null) {
+              var result3 = result10;
+            } else {
+              if (input.substr(pos, 5) === "octet") {
+                var result9 = "octet";
+                pos += 5;
+              } else {
+                var result9 = null;
+                if (reportMatchFailures) {
+                  matchFailed("\"octet\"");
+                }
+              }
+              if (result9 !== null) {
+                var result3 = result9;
+              } else {
+                if (input.substr(pos, 5) === "float") {
+                  var result8 = "float";
+                  pos += 5;
+                } else {
+                  var result8 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"float\"");
+                  }
+                }
+                if (result8 !== null) {
+                  var result3 = result8;
+                } else {
+                  if (input.substr(pos, 6) === "double") {
+                    var result7 = "double";
+                    pos += 6;
+                  } else {
+                    var result7 = null;
+                    if (reportMatchFailures) {
+                      matchFailed("\"double\"");
+                    }
+                  }
+                  if (result7 !== null) {
+                    var result3 = result7;
+                  } else {
+                    if (input.substr(pos, 9) === "DOMString") {
+                      var result6 = "DOMString";
+                      pos += 9;
+                    } else {
+                      var result6 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\"DOMString\"");
+                      }
+                    }
+                    if (result6 !== null) {
+                      var result3 = result6;
+                    } else {
+                      var result3 = null;;
+                    };
+                  };
+                };
+              };
+            };
+          };
+        }
+        if (result3 !== null) {
+          var savedPos2 = pos;
+          var savedReportMatchFailuresVar0 = reportMatchFailures;
+          reportMatchFailures = false;
+          if (input.substr(pos).match(/^[A-Za-z0-9]/) !== null) {
+            var result5 = input.charAt(pos);
+            pos++;
+          } else {
+            var result5 = null;
+            if (reportMatchFailures) {
+              matchFailed("[A-Za-z0-9]");
+            }
+          }
+          reportMatchFailures = savedReportMatchFailuresVar0;
+          if (result5 === null) {
+            var result4 = '';
+          } else {
+            var result4 = null;
+            pos = savedPos2;
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(type) { return type; })(result1[0])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_UnsignedIntegerType() {
+        var cacheKey = 'UnsignedIntegerType@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 8) === "unsigned") {
+          var result13 = "unsigned";
+          pos += 8;
+        } else {
+          var result13 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"unsigned\"");
+          }
+        }
+        var result3 = result13 !== null ? result13 : '';
+        if (result3 !== null) {
+          var result4 = parse_s();
+          if (result4 !== null) {
+            var savedPos2 = pos;
+            if (input.substr(pos, 4) === "long") {
+              var result10 = "long";
+              pos += 4;
+            } else {
+              var result10 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"long\"");
+              }
+            }
+            if (result10 !== null) {
+              var result11 = parse_s();
+              if (result11 !== null) {
+                if (input.substr(pos, 4) === "long") {
+                  var result12 = "long";
+                  pos += 4;
+                } else {
+                  var result12 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"long\"");
+                  }
+                }
+                if (result12 !== null) {
+                  var result9 = [result10, result11, result12];
+                } else {
+                  var result9 = null;
+                  pos = savedPos2;
+                }
+              } else {
+                var result9 = null;
+                pos = savedPos2;
+              }
+            } else {
+              var result9 = null;
+              pos = savedPos2;
+            }
+            if (result9 !== null) {
+              var result5 = result9;
+            } else {
+              if (input.substr(pos, 4) === "long") {
+                var result8 = "long";
+                pos += 4;
+              } else {
+                var result8 = null;
+                if (reportMatchFailures) {
+                  matchFailed("\"long\"");
+                }
+              }
+              if (result8 !== null) {
+                var result5 = result8;
+              } else {
+                if (input.substr(pos, 5) === "short") {
+                  var result7 = "short";
+                  pos += 5;
+                } else {
+                  var result7 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"short\"");
+                  }
+                }
+                if (result7 !== null) {
+                  var result5 = result7;
+                } else {
+                  if (input.substr(pos, 4) === "byte") {
+                    var result6 = "byte";
+                    pos += 4;
+                  } else {
+                    var result6 = null;
+                    if (reportMatchFailures) {
+                      matchFailed("\"byte\"");
+                    }
+                  }
+                  if (result6 !== null) {
+                    var result5 = result6;
+                  } else {
+                    var result5 = null;;
+                  };
+                };
+              };
+            }
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(uns, kind) { return (uns ? "unsigned " : "") + (kind.join ? kind.join("") : kind); })(result1[0], result1[2])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ScopedNameList() {
+        var cacheKey = 'ScopedNameList@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_ScopedName();
+        if (result3 !== null) {
+          var result4 = [];
+          var result5 = parse_ScopedNameListRest();
+          while (result5 !== null) {
+            result4.push(result5);
+            var result5 = parse_ScopedNameListRest();
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(first, others) {   var ret = [first];
+                      for (var i = 0, n = others.length; i < n; i++) { ret.push(others[i]); }
+                      return ret; })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ScopedNameListRest() {
+        var cacheKey = 'ScopedNameListRest@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_w();
+        if (result3 !== null) {
+          if (input.substr(pos, 1) === ",") {
+            var result4 = ",";
+            pos += 1;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("\",\"");
+            }
+          }
+          if (result4 !== null) {
+            var result5 = parse_w();
+            if (result5 !== null) {
+              var result6 = parse_ScopedName();
+              if (result6 !== null) {
+                var result1 = [result3, result4, result5, result6];
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(rest) { return rest; })(result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ScopedName() {
+        var cacheKey = 'ScopedName@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result4 = parse_AbsoluteScopedName();
+        if (result4 !== null) {
+          var result1 = result4;
+        } else {
+          var result3 = parse_RelativeScopedName();
+          if (result3 !== null) {
+            var result1 = result3;
+          } else {
+            var result1 = null;;
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(name) { return name; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_AbsoluteScopedName() {
+        var cacheKey = 'AbsoluteScopedName@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 2) === "::") {
+          var result3 = "::";
+          pos += 2;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"::\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_RelativeScopedName();
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(rel) { return "::" + rel; })(result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_RelativeScopedName() {
+        var cacheKey = 'RelativeScopedName@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_identifier();
+        if (result3 !== null) {
+          var result4 = [];
+          var result5 = parse_ScopedNameRest();
+          while (result5 !== null) {
+            result4.push(result5);
+            var result5 = parse_ScopedNameRest();
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(name, rest) { return name + rest.join(""); })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ScopedNameRest() {
+        var cacheKey = 'ScopedNameRest@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 2) === "::") {
+          var result3 = "::";
+          pos += 2;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"::\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_identifier();
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(name) { return name.join(""); })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_BooleanLiteral() {
+        var cacheKey = 'BooleanLiteral@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        if (input.substr(pos, 4) === "true") {
+          var result4 = "true";
+          pos += 4;
+        } else {
+          var result4 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"true\"");
+          }
+        }
+        if (result4 !== null) {
+          var result1 = result4;
+        } else {
+          if (input.substr(pos, 5) === "false") {
+            var result3 = "false";
+            pos += 5;
+          } else {
+            var result3 = null;
+            if (reportMatchFailures) {
+              matchFailed("\"false\"");
+            }
+          }
+          if (result3 !== null) {
+            var result1 = result3;
+          } else {
+            var result1 = null;;
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(value) { return value; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Nullable() {
+        var cacheKey = 'Nullable@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        if (input.substr(pos, 1) === "?") {
+          var result3 = "?";
+          pos += 1;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"?\"");
+          }
+        }
+        var result1 = result3 !== null ? result3 : '';
+        var result2 = result1 !== null
+          ? (function(nullable) { return nullable ? true : false; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ReturnType() {
+        var cacheKey = 'ReturnType@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        if (input.substr(pos, 4) === "void") {
+          var result4 = "void";
+          pos += 4;
+        } else {
+          var result4 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"void\"");
+          }
+        }
+        if (result4 !== null) {
+          var result1 = result4;
+        } else {
+          var result3 = parse_type();
+          if (result3 !== null) {
+            var result1 = result3;
+          } else {
+            var result1 = null;;
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(ret) { return ret; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_definitions() {
+        var cacheKey = 'definitions@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_w();
+        if (result3 !== null) {
+          var result4 = [];
+          var result5 = parse_definition();
+          while (result5 !== null) {
+            result4.push(result5);
+            var result5 = parse_definition();
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(defs) { return defs; })(result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_definition() {
+        var cacheKey = 'definition@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result9 = parse_partialinterface();
+        if (result9 !== null) {
+          var result1 = result9;
+        } else {
+          var result8 = parse_module();
+          if (result8 !== null) {
+            var result1 = result8;
+          } else {
+            var result7 = parse_interface();
+            if (result7 !== null) {
+              var result1 = result7;
+            } else {
+              var result6 = parse_dictionary();
+              if (result6 !== null) {
+                var result1 = result6;
+              } else {
+                var result5 = parse_typedef();
+                if (result5 !== null) {
+                  var result1 = result5;
+                } else {
+                  var result4 = parse_exception();
+                  if (result4 !== null) {
+                    var result1 = result4;
+                  } else {
+                    var result3 = parse_implements();
+                    if (result3 !== null) {
+                      var result1 = result3;
+                    } else {
+                      var result1 = null;;
+                    };
+                  };
+                };
+              };
+            };
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(def) { return def; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_partialinterface() {
+        var cacheKey = 'partialinterface@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result21 = parse_extendedAttributeList();
+        var result3 = result21 !== null ? result21 : '';
+        if (result3 !== null) {
+          var result20 = parse_s();
+          var result4 = result20 !== null ? result20 : '';
+          if (result4 !== null) {
+            if (input.substr(pos, 7) === "partial") {
+              var result5 = "partial";
+              pos += 7;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"partial\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                if (input.substr(pos, 9) === "interface") {
+                  var result7 = "interface";
+                  pos += 9;
+                } else {
+                  var result7 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"interface\"");
+                  }
+                }
+                if (result7 !== null) {
+                  var result8 = parse_s();
+                  if (result8 !== null) {
+                    var result9 = parse_identifier();
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        if (input.substr(pos, 1) === "{") {
+                          var result11 = "{";
+                          pos += 1;
+                        } else {
+                          var result11 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\"{\"");
+                          }
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            var result13 = [];
+                            var result19 = parse_ifMember();
+                            while (result19 !== null) {
+                              result13.push(result19);
+                              var result19 = parse_ifMember();
+                            }
+                            if (result13 !== null) {
+                              var result14 = parse_w();
+                              if (result14 !== null) {
+                                if (input.substr(pos, 1) === "}") {
+                                  var result15 = "}";
+                                  pos += 1;
+                                } else {
+                                  var result15 = null;
+                                  if (reportMatchFailures) {
+                                    matchFailed("\"}\"");
+                                  }
+                                }
+                                if (result15 !== null) {
+                                  var result16 = parse_w();
+                                  if (result16 !== null) {
+                                    if (input.substr(pos, 1) === ";") {
+                                      var result17 = ";";
+                                      pos += 1;
+                                    } else {
+                                      var result17 = null;
+                                      if (reportMatchFailures) {
+                                        matchFailed("\";\"");
+                                      }
+                                    }
+                                    if (result17 !== null) {
+                                      var result18 = parse_w();
+                                      if (result18 !== null) {
+                                        var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16, result17, result18];
+                                      } else {
+                                        var result1 = null;
+                                        pos = savedPos1;
+                                      }
+                                    } else {
+                                      var result1 = null;
+                                      pos = savedPos1;
+                                    }
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, name, mem) { return { type: "partialinterface", name: name, members: mem, extAttrs: extAttrs }; })(result1[0], result1[6], result1[10])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_module() {
+        var cacheKey = 'module@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result18 = parse_extendedAttributeList();
+        var result3 = result18 !== null ? result18 : '';
+        if (result3 !== null) {
+          var result17 = parse_s();
+          var result4 = result17 !== null ? result17 : '';
+          if (result4 !== null) {
+            if (input.substr(pos, 6) === "module") {
+              var result5 = "module";
+              pos += 6;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"module\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                var result7 = parse_identifier();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === "{") {
+                      var result9 = "{";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\"{\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        var result11 = parse_definitions();
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            if (input.substr(pos, 1) === "}") {
+                              var result13 = "}";
+                              pos += 1;
+                            } else {
+                              var result13 = null;
+                              if (reportMatchFailures) {
+                                matchFailed("\"}\"");
+                              }
+                            }
+                            if (result13 !== null) {
+                              var result14 = parse_w();
+                              if (result14 !== null) {
+                                if (input.substr(pos, 1) === ";") {
+                                  var result15 = ";";
+                                  pos += 1;
+                                } else {
+                                  var result15 = null;
+                                  if (reportMatchFailures) {
+                                    matchFailed("\";\"");
+                                  }
+                                }
+                                if (result15 !== null) {
+                                  var result16 = parse_w();
+                                  if (result16 !== null) {
+                                    var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16];
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, name, defs) { return { type: "module", name: name, definitions: defs, extAttrs: extAttrs }; })(result1[0], result1[4], result1[8])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_implements() {
+        var cacheKey = 'implements@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result14 = parse_extendedAttributeList();
+        var result3 = result14 !== null ? result14 : '';
+        if (result3 !== null) {
+          var result13 = parse_s();
+          var result4 = result13 !== null ? result13 : '';
+          if (result4 !== null) {
+            var result5 = parse_ScopedName();
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                if (input.substr(pos, 10) === "implements") {
+                  var result7 = "implements";
+                  pos += 10;
+                } else {
+                  var result7 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"implements\"");
+                  }
+                }
+                if (result7 !== null) {
+                  var result8 = parse_s();
+                  if (result8 !== null) {
+                    var result9 = parse_ScopedName();
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        if (input.substr(pos, 1) === ";") {
+                          var result11 = ";";
+                          pos += 1;
+                        } else {
+                          var result11 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\";\"");
+                          }
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, target, impl) { return { type: 'implements', target: target, 'implements': impl, extAttrs: extAttrs }; })(result1[0], result1[2], result1[6])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_interface() {
+        var cacheKey = 'interface@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result22 = parse_extendedAttributeList();
+        var result3 = result22 !== null ? result22 : '';
+        if (result3 !== null) {
+          var result21 = parse_s();
+          var result4 = result21 !== null ? result21 : '';
+          if (result4 !== null) {
+            if (input.substr(pos, 9) === "interface") {
+              var result5 = "interface";
+              pos += 9;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"interface\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                var result7 = parse_identifier();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    var result20 = parse_ifInheritance();
+                    var result9 = result20 !== null ? result20 : '';
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        if (input.substr(pos, 1) === "{") {
+                          var result11 = "{";
+                          pos += 1;
+                        } else {
+                          var result11 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\"{\"");
+                          }
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            var result13 = [];
+                            var result19 = parse_ifMember();
+                            while (result19 !== null) {
+                              result13.push(result19);
+                              var result19 = parse_ifMember();
+                            }
+                            if (result13 !== null) {
+                              var result14 = parse_w();
+                              if (result14 !== null) {
+                                if (input.substr(pos, 1) === "}") {
+                                  var result15 = "}";
+                                  pos += 1;
+                                } else {
+                                  var result15 = null;
+                                  if (reportMatchFailures) {
+                                    matchFailed("\"}\"");
+                                  }
+                                }
+                                if (result15 !== null) {
+                                  var result16 = parse_w();
+                                  if (result16 !== null) {
+                                    if (input.substr(pos, 1) === ";") {
+                                      var result17 = ";";
+                                      pos += 1;
+                                    } else {
+                                      var result17 = null;
+                                      if (reportMatchFailures) {
+                                        matchFailed("\";\"");
+                                      }
+                                    }
+                                    if (result17 !== null) {
+                                      var result18 = parse_w();
+                                      if (result18 !== null) {
+                                        var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16, result17, result18];
+                                      } else {
+                                        var result1 = null;
+                                        pos = savedPos1;
+                                      }
+                                    } else {
+                                      var result1 = null;
+                                      pos = savedPos1;
+                                    }
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, name, herit, mem) { return { type: "interface", name: name, inheritance: herit, members: mem, extAttrs: extAttrs }; })(result1[0], result1[4], result1[6], result1[10])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ifInheritance() {
+        var cacheKey = 'ifInheritance@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 1) === ":") {
+          var result3 = ":";
+          pos += 1;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\":\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            var result5 = parse_ScopedNameList();
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(herit) { return herit; })(result1[2])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ifMember() {
+        var cacheKey = 'ifMember@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result4 = parse_const();
+        if (result4 !== null) {
+          var result1 = result4;
+        } else {
+          var result3 = parse_attrOrOp();
+          if (result3 !== null) {
+            var result1 = result3;
+          } else {
+            var result1 = null;;
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(mem) { return mem; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_const() {
+        var cacheKey = 'const@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result18 = parse_extendedAttributeList();
+        var result3 = result18 !== null ? result18 : '';
+        if (result3 !== null) {
+          var result17 = parse_s();
+          var result4 = result17 !== null ? result17 : '';
+          if (result4 !== null) {
+            if (input.substr(pos, 5) === "const") {
+              var result5 = "const";
+              pos += 5;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"const\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                var result7 = parse_type();
+                if (result7 !== null) {
+                  var result8 = parse_s();
+                  if (result8 !== null) {
+                    var result9 = parse_identifier();
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        if (input.substr(pos, 1) === "=") {
+                          var result11 = "=";
+                          pos += 1;
+                        } else {
+                          var result11 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\"=\"");
+                          }
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            var result13 = parse_constExpr();
+                            if (result13 !== null) {
+                              var result14 = parse_w();
+                              if (result14 !== null) {
+                                if (input.substr(pos, 1) === ";") {
+                                  var result15 = ";";
+                                  pos += 1;
+                                } else {
+                                  var result15 = null;
+                                  if (reportMatchFailures) {
+                                    matchFailed("\";\"");
+                                  }
+                                }
+                                if (result15 !== null) {
+                                  var result16 = parse_w();
+                                  if (result16 !== null) {
+                                    var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16];
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, type, name, value) { return { type: "const", extAttrs: extAttrs, idlType: type, name: name, value: value }; })(result1[0], result1[4], result1[6], result1[10])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_constExpr() {
+        var cacheKey = 'constExpr@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result5 = parse_BooleanLiteral();
+        if (result5 !== null) {
+          var result1 = result5;
+        } else {
+          var result4 = parse_float();
+          if (result4 !== null) {
+            var result1 = result4;
+          } else {
+            var result3 = parse_integer();
+            if (result3 !== null) {
+              var result1 = result3;
+            } else {
+              var result1 = null;;
+            };
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(value) { return value; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_attrOrOp() {
+        var cacheKey = 'attrOrOp@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result5 = parse_Stringifier();
+        if (result5 !== null) {
+          var result1 = result5;
+        } else {
+          var result4 = parse_Attribute();
+          if (result4 !== null) {
+            var result1 = result4;
+          } else {
+            var result3 = parse_Operation();
+            if (result3 !== null) {
+              var result1 = result3;
+            } else {
+              var result1 = null;;
+            };
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(ao) { return ao; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Stringifier() {
+        var cacheKey = 'Stringifier@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 11) === "stringifier") {
+          var result3 = "stringifier";
+          pos += 11;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"stringifier\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            var result8 = parse_Attribute();
+            if (result8 !== null) {
+              var result5 = result8;
+            } else {
+              var result7 = parse_OperationRest();
+              if (result7 !== null) {
+                var result5 = result7;
+              } else {
+                if (input.substr(pos, 1) === ";") {
+                  var result6 = ";";
+                  pos += 1;
+                } else {
+                  var result6 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\";\"");
+                  }
+                }
+                if (result6 !== null) {
+                  var result5 = result6;
+                } else {
+                  var result5 = null;;
+                };
+              };
+            }
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(rest) {
+                      if (rest === ";") return { type: "stringifier" };
+                      else {
+                          rest.stringifier = true;
+                          return rest;
+                      }
+                  })(result1[2])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Attribute() {
+        var cacheKey = 'Attribute@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result23 = parse_extendedAttributeList();
+        var result3 = result23 !== null ? result23 : '';
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            var savedPos2 = pos;
+            if (input.substr(pos, 8) === "readonly") {
+              var result21 = "readonly";
+              pos += 8;
+            } else {
+              var result21 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"readonly\"");
+              }
+            }
+            if (result21 !== null) {
+              var result22 = parse_s();
+              if (result22 !== null) {
+                var result20 = [result21, result22];
+              } else {
+                var result20 = null;
+                pos = savedPos2;
+              }
+            } else {
+              var result20 = null;
+              pos = savedPos2;
+            }
+            var result5 = result20 !== null ? result20 : '';
+            if (result5 !== null) {
+              if (input.substr(pos, 9) === "attribute") {
+                var result6 = "attribute";
+                pos += 9;
+              } else {
+                var result6 = null;
+                if (reportMatchFailures) {
+                  matchFailed("\"attribute\"");
+                }
+              }
+              if (result6 !== null) {
+                var result7 = parse_s();
+                if (result7 !== null) {
+                  var result8 = parse_type();
+                  if (result8 !== null) {
+                    var result9 = parse_s();
+                    if (result9 !== null) {
+                      var result10 = parse_identifier();
+                      if (result10 !== null) {
+                        var result11 = parse_w();
+                        if (result11 !== null) {
+                          var result19 = parse_GetRaises();
+                          var result12 = result19 !== null ? result19 : '';
+                          if (result12 !== null) {
+                            var result13 = parse_w();
+                            if (result13 !== null) {
+                              var result18 = parse_SetRaises();
+                              var result14 = result18 !== null ? result18 : '';
+                              if (result14 !== null) {
+                                var result15 = parse_w();
+                                if (result15 !== null) {
+                                  if (input.substr(pos, 1) === ";") {
+                                    var result16 = ";";
+                                    pos += 1;
+                                  } else {
+                                    var result16 = null;
+                                    if (reportMatchFailures) {
+                                      matchFailed("\";\"");
+                                    }
+                                  }
+                                  if (result16 !== null) {
+                                    var result17 = parse_w();
+                                    if (result17 !== null) {
+                                      var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16, result17];
+                                    } else {
+                                      var result1 = null;
+                                      pos = savedPos1;
+                                    }
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, ro, type, name, gr, sr) { return { type: "attribute", extAttrs: extAttrs, idlType: type, name: name, readonly: (ro ? true : false), getraises: gr, setraises: sr }; })(result1[0], result1[2], result1[5], result1[7], result1[9], result1[11])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_GetRaises() {
+        var cacheKey = 'GetRaises@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 9) === "getraises") {
+          var result3 = "getraises";
+          pos += 9;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"getraises\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === "(") {
+              var result5 = "(";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"(\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_ScopedNameList();
+              if (result6 !== null) {
+                if (input.substr(pos, 1) === ")") {
+                  var result7 = ")";
+                  pos += 1;
+                } else {
+                  var result7 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\")\"");
+                  }
+                }
+                if (result7 !== null) {
+                  var result1 = [result3, result4, result5, result6, result7];
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(list) { return list; })(result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_SetRaises() {
+        var cacheKey = 'SetRaises@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 9) === "setraises") {
+          var result3 = "setraises";
+          pos += 9;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"setraises\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === "(") {
+              var result5 = "(";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"(\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_ScopedNameList();
+              if (result6 !== null) {
+                if (input.substr(pos, 1) === ")") {
+                  var result7 = ")";
+                  pos += 1;
+                } else {
+                  var result7 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\")\"");
+                  }
+                }
+                if (result7 !== null) {
+                  var result1 = [result3, result4, result5, result6, result7];
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(list) { return list; })(result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Operation() {
+        var cacheKey = 'Operation@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result8 = parse_extendedAttributeList();
+        var result3 = result8 !== null ? result8 : '';
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            var result5 = parse_Qualifiers();
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                var result7 = parse_OperationRest();
+                if (result7 !== null) {
+                  var result1 = [result3, result4, result5, result6, result7];
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, quals, rest) {
+                      for (var k in quals) rest[k] = quals[k];
+                      if (extAttrs) rest.extAttrs = extAttrs;
+                      return rest;
+                  })(result1[0], result1[2], result1[4])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Qualifiers() {
+        var cacheKey = 'Qualifiers@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_w();
+        if (result3 !== null) {
+          if (input.substr(pos, 6) === "static") {
+            var result7 = "static";
+            pos += 6;
+          } else {
+            var result7 = null;
+            if (reportMatchFailures) {
+              matchFailed("\"static\"");
+            }
+          }
+          if (result7 !== null) {
+            var result4 = result7;
+          } else {
+            var result5 = [];
+            var result6 = parse_Special();
+            while (result6 !== null) {
+              result5.push(result6);
+              var result6 = parse_Special();
+            }
+            if (result5 !== null) {
+              var result4 = result5;
+            } else {
+              var result4 = null;;
+            };
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(quals) {   if (typeof quals == "string") return [quals];
+          		    return quals; })(result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Special() {
+        var cacheKey = 'Special@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_w();
+        if (result3 !== null) {
+          if (input.substr(pos, 6) === "getter") {
+            var result10 = "getter";
+            pos += 6;
+          } else {
+            var result10 = null;
+            if (reportMatchFailures) {
+              matchFailed("\"getter\"");
+            }
+          }
+          if (result10 !== null) {
+            var result4 = result10;
+          } else {
+            if (input.substr(pos, 6) === "setter") {
+              var result9 = "setter";
+              pos += 6;
+            } else {
+              var result9 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"setter\"");
+              }
+            }
+            if (result9 !== null) {
+              var result4 = result9;
+            } else {
+              if (input.substr(pos, 7) === "creator") {
+                var result8 = "creator";
+                pos += 7;
+              } else {
+                var result8 = null;
+                if (reportMatchFailures) {
+                  matchFailed("\"creator\"");
+                }
+              }
+              if (result8 !== null) {
+                var result4 = result8;
+              } else {
+                if (input.substr(pos, 7) === "deleter") {
+                  var result7 = "deleter";
+                  pos += 7;
+                } else {
+                  var result7 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"deleter\"");
+                  }
+                }
+                if (result7 !== null) {
+                  var result4 = result7;
+                } else {
+                  if (input.substr(pos, 12) === "legacycaller") {
+                    var result6 = "legacycaller";
+                    pos += 12;
+                  } else {
+                    var result6 = null;
+                    if (reportMatchFailures) {
+                      matchFailed("\"legacycaller\"");
+                    }
+                  }
+                  if (result6 !== null) {
+                    var result4 = result6;
+                  } else {
+                    var result4 = null;;
+                  };
+                };
+              };
+            };
+          }
+          if (result4 !== null) {
+            var result5 = parse_w();
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(spe) { return spe; })(result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_OperationRest() {
+        var cacheKey = 'OperationRest@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_ReturnType();
+        if (result3 !== null) {
+          var result4 = parse_s();
+          if (result4 !== null) {
+            var result19 = parse_identifier();
+            var result5 = result19 !== null ? result19 : '';
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                if (input.substr(pos, 1) === "(") {
+                  var result7 = "(";
+                  pos += 1;
+                } else {
+                  var result7 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"(\"");
+                  }
+                }
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    var result18 = parse_Arguments();
+                    var result9 = result18 !== null ? result18 : '';
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        if (input.substr(pos, 1) === ")") {
+                          var result11 = ")";
+                          pos += 1;
+                        } else {
+                          var result11 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\")\"");
+                          }
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            var result17 = parse_Raises();
+                            var result13 = result17 !== null ? result17 : '';
+                            if (result13 !== null) {
+                              var result14 = parse_w();
+                              if (result14 !== null) {
+                                if (input.substr(pos, 1) === ";") {
+                                  var result15 = ";";
+                                  pos += 1;
+                                } else {
+                                  var result15 = null;
+                                  if (reportMatchFailures) {
+                                    matchFailed("\";\"");
+                                  }
+                                }
+                                if (result15 !== null) {
+                                  var result16 = parse_w();
+                                  if (result16 !== null) {
+                                    var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16];
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(ret, name, args, exc) { return { type: "operation", idlType: ret, name: name, arguments: (args ? args : []), raises: exc }; })(result1[0], result1[2], result1[6], result1[10])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Arguments() {
+        var cacheKey = 'Arguments@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_Argument();
+        if (result3 !== null) {
+          var result4 = [];
+          var result5 = parse_ArgumentsRest();
+          while (result5 !== null) {
+            result4.push(result5);
+            var result5 = parse_ArgumentsRest();
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(first, others) {   var ret = [first];
+                      for (var i = 0, n = others.length; i < n; i++) { ret.push(others[i]); }
+                      return ret; })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ArgumentsRest() {
+        var cacheKey = 'ArgumentsRest@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_w();
+        if (result3 !== null) {
+          if (input.substr(pos, 1) === ",") {
+            var result4 = ",";
+            pos += 1;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("\",\"");
+            }
+          }
+          if (result4 !== null) {
+            var result5 = parse_w();
+            if (result5 !== null) {
+              var result6 = parse_Argument();
+              if (result6 !== null) {
+                var result1 = [result3, result4, result5, result6];
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(rest) { return rest; })(result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Argument() {
+        var cacheKey = 'Argument@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result16 = parse_extendedAttributeList();
+        var result3 = result16 !== null ? result16 : '';
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            if (input.substr(pos, 2) === "in") {
+              var result15 = "in";
+              pos += 2;
+            } else {
+              var result15 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"in\"");
+              }
+            }
+            var result5 = result15 !== null ? result15 : '';
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                if (input.substr(pos, 8) === "optional") {
+                  var result14 = "optional";
+                  pos += 8;
+                } else {
+                  var result14 = null;
+                  if (reportMatchFailures) {
+                    matchFailed("\"optional\"");
+                  }
+                }
+                var result7 = result14 !== null ? result14 : '';
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    var result9 = parse_type();
+                    if (result9 !== null) {
+                      if (input.substr(pos, 3) === "...") {
+                        var result13 = "...";
+                        pos += 3;
+                      } else {
+                        var result13 = null;
+                        if (reportMatchFailures) {
+                          matchFailed("\"...\"");
+                        }
+                      }
+                      var result10 = result13 !== null ? result13 : '';
+                      if (result10 !== null) {
+                        var result11 = parse_s();
+                        if (result11 !== null) {
+                          var result12 = parse_identifier();
+                          if (result12 !== null) {
+                            var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, opt, type, ell, name) { return { name: name, type: type, variadic: (ell ? true : false), optional: (opt ? true : false), extAttrs: extAttrs }; })(result1[0], result1[4], result1[6], result1[7], result1[9])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_Raises() {
+        var cacheKey = 'Raises@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 6) === "raises") {
+          var result3 = "raises";
+          pos += 6;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"raises\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_s();
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === "(") {
+              var result5 = "(";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"(\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                var result7 = parse_ScopedNameList();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === ")") {
+                      var result9 = ")";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\")\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result1 = [result3, result4, result5, result6, result7, result8, result9];
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(list) { return list; })(result1[4])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_dictionary() {
+        var cacheKey = 'dictionary@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 10) === "dictionary") {
+          var result3 = "dictionary";
+          pos += 10;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"dictionary\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_s();
+          if (result4 !== null) {
+            var result5 = parse_identifier();
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                var result18 = parse_ifInheritance();
+                var result7 = result18 !== null ? result18 : '';
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === "{") {
+                      var result9 = "{";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\"{\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        var result11 = [];
+                        var result17 = parse_dictionaryMember();
+                        while (result17 !== null) {
+                          result11.push(result17);
+                          var result17 = parse_dictionaryMember();
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            if (input.substr(pos, 1) === "}") {
+                              var result13 = "}";
+                              pos += 1;
+                            } else {
+                              var result13 = null;
+                              if (reportMatchFailures) {
+                                matchFailed("\"}\"");
+                              }
+                            }
+                            if (result13 !== null) {
+                              var result14 = parse_w();
+                              if (result14 !== null) {
+                                if (input.substr(pos, 1) === ";") {
+                                  var result15 = ";";
+                                  pos += 1;
+                                } else {
+                                  var result15 = null;
+                                  if (reportMatchFailures) {
+                                    matchFailed("\";\"");
+                                  }
+                                }
+                                if (result15 !== null) {
+                                  var result16 = parse_w();
+                                  if (result16 !== null) {
+                                    var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16];
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(name, superclass, members) {
+                          return { 
+                              type: "dictionary",
+                              name: name,
+                              inheritance: superclass,
+                              members: members
+                          };
+                      })(result1[2], result1[4], result1[8])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_dictionaryMember() {
+        var cacheKey = 'dictionaryMember@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result14 = parse_extendedAttributeList();
+        var result3 = result14 !== null ? result14 : '';
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            var result5 = parse_type();
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                var result7 = parse_identifier();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    var result13 = parse_defaultValue();
+                    var result9 = result13 !== null ? result13 : '';
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        if (input.substr(pos, 1) === ";") {
+                          var result11 = ";";
+                          pos += 1;
+                        } else {
+                          var result11 = null;
+                          if (reportMatchFailures) {
+                            matchFailed("\";\"");
+                          }
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, type, name, defaultValue) {
+                       return {
+                           type: type,
+                           name: name,
+                           defaultValue: defaultValue
+                       };
+                   })(result1[0], result1[2], result1[4], result1[6])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_defaultValue() {
+        var cacheKey = 'defaultValue@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 1) === "=") {
+          var result3 = "=";
+          pos += 1;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"=\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            var result5 = parse_constExpr();
+            if (result5 !== null) {
+              var result1 = [result3, result4, result5];
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(value) { return value; })(result1[2])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_typedef() {
+        var cacheKey = 'typedef@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        if (input.substr(pos, 7) === "typedef") {
+          var result3 = "typedef";
+          pos += 7;
+        } else {
+          var result3 = null;
+          if (reportMatchFailures) {
+            matchFailed("\"typedef\"");
+          }
+        }
+        if (result3 !== null) {
+          var result4 = parse_s();
+          if (result4 !== null) {
+            var result5 = parse_type();
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                var result7 = parse_identifier();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === ";") {
+                      var result9 = ";";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\";\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        var result1 = [result3, result4, result5, result6, result7, result8, result9, result10];
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(type, name) { return { type: 'typedef', name: name, idlType: type }; })(result1[2], result1[4])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_exception() {
+        var cacheKey = 'exception@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result18 = parse_extendedAttributeList();
+        var result3 = result18 !== null ? result18 : '';
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            if (input.substr(pos, 9) === "exception") {
+              var result5 = "exception";
+              pos += 9;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"exception\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                var result7 = parse_identifier();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === "{") {
+                      var result9 = "{";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\"{\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        var result11 = [];
+                        var result17 = parse_exMember();
+                        while (result17 !== null) {
+                          result11.push(result17);
+                          var result17 = parse_exMember();
+                        }
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            if (input.substr(pos, 1) === "}") {
+                              var result13 = "}";
+                              pos += 1;
+                            } else {
+                              var result13 = null;
+                              if (reportMatchFailures) {
+                                matchFailed("\"}\"");
+                              }
+                            }
+                            if (result13 !== null) {
+                              var result14 = parse_w();
+                              if (result14 !== null) {
+                                if (input.substr(pos, 1) === ";") {
+                                  var result15 = ";";
+                                  pos += 1;
+                                } else {
+                                  var result15 = null;
+                                  if (reportMatchFailures) {
+                                    matchFailed("\";\"");
+                                  }
+                                }
+                                if (result15 !== null) {
+                                  var result16 = parse_w();
+                                  if (result16 !== null) {
+                                    var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13, result14, result15, result16];
+                                  } else {
+                                    var result1 = null;
+                                    pos = savedPos1;
+                                  }
+                                } else {
+                                  var result1 = null;
+                                  pos = savedPos1;
+                                }
+                              } else {
+                                var result1 = null;
+                                pos = savedPos1;
+                              }
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, name, mem) { return { type: 'exception', name: name, members: mem, extAttrs: extAttrs }; })(result1[0], result1[4], result1[8])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_exMember() {
+        var cacheKey = 'exMember@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result4 = parse_const();
+        if (result4 !== null) {
+          var result1 = result4;
+        } else {
+          var result3 = parse_field();
+          if (result3 !== null) {
+            var result1 = result3;
+          } else {
+            var result1 = null;;
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(mem) { return mem; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_field() {
+        var cacheKey = 'field@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result12 = parse_extendedAttributeList();
+        var result3 = result12 !== null ? result12 : '';
+        if (result3 !== null) {
+          var result11 = parse_s();
+          var result4 = result11 !== null ? result11 : '';
+          if (result4 !== null) {
+            var result5 = parse_type();
+            if (result5 !== null) {
+              var result6 = parse_s();
+              if (result6 !== null) {
+                var result7 = parse_identifier();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === ";") {
+                      var result9 = ";";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\";\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        var result1 = [result3, result4, result5, result6, result7, result8, result9, result10];
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(extAttrs, type, name) { return { type: "field", extAttrs: extAttrs, idlType: type, name: name }; })(result1[0], result1[2], result1[4])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_extendedAttributeList() {
+        var cacheKey = 'extendedAttributeList@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_w();
+        if (result3 !== null) {
+          if (input.substr(pos, 1) === "[") {
+            var result4 = "[";
+            pos += 1;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("\"[\"");
+            }
+          }
+          if (result4 !== null) {
+            var result5 = parse_w();
+            if (result5 !== null) {
+              var result6 = parse_ExtAttrs();
+              if (result6 !== null) {
+                var result7 = parse_w();
+                if (result7 !== null) {
+                  if (input.substr(pos, 1) === "]") {
+                    var result8 = "]";
+                    pos += 1;
+                  } else {
+                    var result8 = null;
+                    if (reportMatchFailures) {
+                      matchFailed("\"]\"");
+                    }
+                  }
+                  if (result8 !== null) {
+                    var result9 = parse_w();
+                    if (result9 !== null) {
+                      var result1 = [result3, result4, result5, result6, result7, result8, result9];
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(ea) { return ea; })(result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ExtAttrs() {
+        var cacheKey = 'ExtAttrs@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_ExtAttr();
+        if (result3 !== null) {
+          var result4 = [];
+          var result5 = parse_ExtAttrsRest();
+          while (result5 !== null) {
+            result4.push(result5);
+            var result5 = parse_ExtAttrsRest();
+          }
+          if (result4 !== null) {
+            var result1 = [result3, result4];
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(first, others) {   var ret = [first];
+                      for (var i = 0, n = others.length; i < n; i++) { ret.push(others[i]); }
+                      return ret; })(result1[0], result1[1])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ExtAttrsRest() {
+        var cacheKey = 'ExtAttrsRest@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_w();
+        if (result3 !== null) {
+          if (input.substr(pos, 1) === ",") {
+            var result4 = ",";
+            pos += 1;
+          } else {
+            var result4 = null;
+            if (reportMatchFailures) {
+              matchFailed("\",\"");
+            }
+          }
+          if (result4 !== null) {
+            var result5 = parse_w();
+            if (result5 !== null) {
+              var result6 = parse_ExtAttr();
+              if (result6 !== null) {
+                var result1 = [result3, result4, result5, result6];
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(rest) { return rest; })(result1[3])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ExtAttr() {
+        var cacheKey = 'ExtAttr@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result6 = parse_ExtAttrArgList();
+        if (result6 !== null) {
+          var result1 = result6;
+        } else {
+          var result5 = parse_ExtAttrNamedArgList();
+          if (result5 !== null) {
+            var result1 = result5;
+          } else {
+            var result4 = parse_ExtAttrNameValue();
+            if (result4 !== null) {
+              var result1 = result4;
+            } else {
+              var result3 = parse_ExtAttrNoArg();
+              if (result3 !== null) {
+                var result1 = result3;
+              } else {
+                var result1 = null;;
+              };
+            };
+          };
+        }
+        var result2 = result1 !== null
+          ? (function(ea) { return ea; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ExtAttrNoArg() {
+        var cacheKey = 'ExtAttrNoArg@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var result1 = parse_identifier();
+        var result2 = result1 !== null
+          ? (function(name) {return { name: name }; })(result1)
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ExtAttrNameValue() {
+        var cacheKey = 'ExtAttrNameValue@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_identifier();
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === "=") {
+              var result5 = "=";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"=\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                var result7 = parse_ScopedName();
+                if (result7 !== null) {
+                  var result1 = [result3, result4, result5, result6, result7];
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(name, value) {return { name: name, value: value }; })(result1[0], result1[4])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ExtAttrNamedArgList() {
+        var cacheKey = 'ExtAttrNamedArgList@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_identifier();
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === "=") {
+              var result5 = "=";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"=\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                var result7 = parse_identifier();
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === "(") {
+                      var result9 = "(";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\"(\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result10 = parse_w();
+                      if (result10 !== null) {
+                        var result14 = parse_Arguments();
+                        var result11 = result14 !== null ? result14 : '';
+                        if (result11 !== null) {
+                          var result12 = parse_w();
+                          if (result12 !== null) {
+                            if (input.substr(pos, 1) === ")") {
+                              var result13 = ")";
+                              pos += 1;
+                            } else {
+                              var result13 = null;
+                              if (reportMatchFailures) {
+                                matchFailed("\")\"");
+                              }
+                            }
+                            if (result13 !== null) {
+                              var result1 = [result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13];
+                            } else {
+                              var result1 = null;
+                              pos = savedPos1;
+                            }
+                          } else {
+                            var result1 = null;
+                            pos = savedPos1;
+                          }
+                        } else {
+                          var result1 = null;
+                          pos = savedPos1;
+                        }
+                      } else {
+                        var result1 = null;
+                        pos = savedPos1;
+                      }
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(name, value, args) {return { name: name, value: value, arguments: args }; })(result1[0], result1[4], result1[8])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_ExtAttrArgList() {
+        var cacheKey = 'ExtAttrArgList@' + pos;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = cachedResult.nextPos;
+          return cachedResult.result;
+        }
+        
+        
+        var savedPos0 = pos;
+        var savedPos1 = pos;
+        var result3 = parse_identifier();
+        if (result3 !== null) {
+          var result4 = parse_w();
+          if (result4 !== null) {
+            if (input.substr(pos, 1) === "(") {
+              var result5 = "(";
+              pos += 1;
+            } else {
+              var result5 = null;
+              if (reportMatchFailures) {
+                matchFailed("\"(\"");
+              }
+            }
+            if (result5 !== null) {
+              var result6 = parse_w();
+              if (result6 !== null) {
+                var result10 = parse_Arguments();
+                var result7 = result10 !== null ? result10 : '';
+                if (result7 !== null) {
+                  var result8 = parse_w();
+                  if (result8 !== null) {
+                    if (input.substr(pos, 1) === ")") {
+                      var result9 = ")";
+                      pos += 1;
+                    } else {
+                      var result9 = null;
+                      if (reportMatchFailures) {
+                        matchFailed("\")\"");
+                      }
+                    }
+                    if (result9 !== null) {
+                      var result1 = [result3, result4, result5, result6, result7, result8, result9];
+                    } else {
+                      var result1 = null;
+                      pos = savedPos1;
+                    }
+                  } else {
+                    var result1 = null;
+                    pos = savedPos1;
+                  }
+                } else {
+                  var result1 = null;
+                  pos = savedPos1;
+                }
+              } else {
+                var result1 = null;
+                pos = savedPos1;
+              }
+            } else {
+              var result1 = null;
+              pos = savedPos1;
+            }
+          } else {
+            var result1 = null;
+            pos = savedPos1;
+          }
+        } else {
+          var result1 = null;
+          pos = savedPos1;
+        }
+        var result2 = result1 !== null
+          ? (function(name, args) {return { name: name, arguments: args }; })(result1[0], result1[4])
+          : null;
+        if (result2 !== null) {
+          var result0 = result2;
+        } else {
+          var result0 = null;
+          pos = savedPos0;
+        }
+        
+        
+        
+        cache[cacheKey] = {
+          nextPos: pos,
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function buildErrorMessage() {
+        function buildExpected(failuresExpected) {
+          failuresExpected.sort();
+          
+          var lastFailure = null;
+          var failuresExpectedUnique = [];
+          for (var i = 0; i < failuresExpected.length; i++) {
+            if (failuresExpected[i] !== lastFailure) {
+              failuresExpectedUnique.push(failuresExpected[i]);
+              lastFailure = failuresExpected[i];
+            }
+          }
+          
+          switch (failuresExpectedUnique.length) {
+            case 0:
+              return 'end of input';
+            case 1:
+              return failuresExpectedUnique[0];
+            default:
+              return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ')
+                + ' or '
+                + failuresExpectedUnique[failuresExpectedUnique.length - 1];
+          }
+        }
+        
+        var expected = buildExpected(rightmostMatchFailuresExpected);
+        var actualPos = Math.max(pos, rightmostMatchFailuresPos);
+        var actual = actualPos < input.length
+          ? quote(input.charAt(actualPos))
+          : 'end of input';
+        
+        return 'Expected ' + expected + ' but ' + actual + ' found.';
+      }
+      
+      function computeErrorPosition() {
+        /*
+         * The first idea was to use |String.split| to break the input up to the
+         * error position along newlines and derive the line and column from
+         * there. However IE's |split| implementation is so broken that it was
+         * enough to prevent it.
+         */
+        
+        var line = 1;
+        var column = 1;
+        var seenCR = false;
+        
+        for (var i = 0; i <  rightmostMatchFailuresPos; i++) {
+          var ch = input.charAt(i);
+          if (ch === '\n') {
+            if (!seenCR) { line++; }
+            column = 1;
+            seenCR = false;
+          } else if (ch === '\r' | ch === '\u2028' || ch === '\u2029') {
+            line++;
+            column = 1;
+            seenCR = true;
+          } else {
+            column++;
+            seenCR = false;
+          }
+        }
+        
+        return { line: line, column: column };
+      }
+      
+      
+      
+      var result = parseFunctions[startRule]();
+      
+      /*
+       * The parser is now in one of the following three states:
+       *
+       * 1. The parser successfully parsed the whole input.
+       *
+       *    - |result !== null|
+       *    - |pos === input.length|
+       *    - |rightmostMatchFailuresExpected| may or may not contain something
+       *
+       * 2. The parser successfully parsed only a part of the input.
+       *
+       *    - |result !== null|
+       *    - |pos < input.length|
+       *    - |rightmostMatchFailuresExpected| may or may not contain something
+       *
+       * 3. The parser did not successfully parse any part of the input.
+       *
+       *   - |result === null|
+       *   - |pos === 0|
+       *   - |rightmostMatchFailuresExpected| contains at least one failure
+       *
+       * All code following this comment (including called functions) must
+       * handle these states.
+       */
+      if (result === null || pos !== input.length) {
+        var errorPosition = computeErrorPosition();
+        throw new this.SyntaxError(
+          buildErrorMessage(),
+          errorPosition.line,
+          errorPosition.column
+        );
+      }
+      
+      return result;
+    },
+    
+    /* Returns the parser source code. */
+    toSource: function() { return this._source; }
+  };
+  
+  /* Thrown when a parser encounters a syntax error. */
+  
+  result.SyntaxError = function(message, line, column) {
+    this.name = 'SyntaxError';
+    this.message = message;
+    this.line = line;
+    this.column = column;
+  };
+  
+  result.SyntaxError.prototype = Error.prototype;
+  
+  return result;
+})();
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/w3c/idlharness.js
@@ -0,0 +1,1487 @@
+/*
+Distributed under both the W3C Test Suite License [1] and the W3C
+3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
+policies and contribution forms [3].
+
+[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
+[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
+[3] http://www.w3.org/2004/10/27-testcases
+*/
+
+/*
+ * This file automatically generates browser tests for WebIDL interfaces, using
+ * the testharness.js framework.  To use, first include the following:
+ *
+ *   <script src=/resources/testharness.js></script>
+ *   <script src=/resources/testharnessreport.js></script>
+ *   <script src=/resources/WebIDLParser.js></script>
+ *   <script src=/resources/idlharness.js></script>
+ *
+ * Then you'll need some type of IDLs.  Here's some script that can be run on a
+ * spec written in HTML, which will grab all the elements with class="idl",
+ * concatenate them, and replace the body so you can copy-paste:
+ *
+     var s = "";
+     [].forEach.call(document.getElementsByClassName("idl"), function(idl) {
+       //https://www.w3.org/Bugs/Public/show_bug.cgi?id=14914
+       if (!idl.classList.contains("extract"))
+       {
+         s += idl.textContent + "\n\n";
+       }
+     });
+     document.body.innerHTML = '<pre></pre>';
+     document.body.firstChild.textContent = s;
+ *
+ * (TODO: write this in Python or something so that it can be done from the
+ * command line instead.)
+ *
+ * Once you have that, put it in your script somehow.  The easiest way is to
+ * embed it literally in an HTML file with <script type=text/plain> or similar,
+ * so that you don't have to do any escaping.  Another possibility is to put it
+ * in a separate .idl file that's fetched via XHR or similar.  Sample usage:
+ *
+ *   var idl_array = new IdlArray();
+ *   idl_array.add_untested_idls("interface Node { readonly attribute DOMString nodeName; };");
+ *   idl_array.add_idls("interface Document : Node { readonly attribute DOMString URL; };");
+ *   idl_array.add_objects({Document: ["document"]});
+ *   idl_array.test();
+ *
+ * This tests that window.Document exists and meets all the requirements of
+ * WebIDL.  It also tests that window.document (the result of evaluating the
+ * string "document") has URL and nodeName properties that behave as they
+ * should, and otherwise meets WebIDL's requirements for an object whose
+ * primary interface is Document.  It does not test that window.Node exists,
+ * which is what you want if the Node interface is already tested in some other
+ * specification's suite and your specification only extends or refers to it.
+ * Of course, each IDL string can define many different things, and calls to
+ * add_objects() can register many different objects for different interfaces:
+ * this is a very simple example.
+ *
+ * TODO: Write assert_writable, assert_enumerable, assert_configurable and
+ * their inverses, and use those instead of just checking
+ * getOwnPropertyDescriptor.
+ *
+ * == Public methods of IdlArray ==
+ *
+ * IdlArray objects can be obtained with new IdlArray().  Anything not
+ * documented in this section should be considered an implementation detail,
+ * and outside callers should not use it.
+ *
+ * add_idls(idl_string):
+ *   Parses idl_string (throwing on parse error) and adds the results to the
+ *   IdlArray.  All the definitions will be tested when you run test().  If
+ *   some of the definitions refer to other definitions, those must be present
+ *   too.  For instance, if idl_string says that Document inherits from Node,
+ *   the Node interface must also have been provided in some call to add_idls()
+ *   or add_untested_idls().
+ *
+ * add_untested_idls(idl_string):
+ *   Like add_idls(), but the definitions will not be tested.  If an untested
+ *   interface is added and then extended with a tested partial interface, the
+ *   members of the partial interface will still be tested.  Also, all the
+ *   members will still be tested for objects added with add_objects(), because
+ *   you probably want to test that (for instance) window.document has all the
+ *   properties from Node, not just Document, even if the Node interface itself
+ *   is tested in a different test suite.
+ *
+ * add_objects(dict):
+ *   dict should be an object whose keys are the names of interfaces or
+ *   exceptions, and whose values are arrays of strings.  When an interface or
+ *   exception is tested, every string registered for it with add_objects()
+ *   will be evaluated, and tests will be run on the result to verify that it
+ *   correctly implements that interface or exception.  This is the only way to
+ *   test anything about [NoInterfaceObject] interfaces, and there are many
+ *   tests that can't be run on any interface without an object to fiddle with.
+ *
+ *   The interface has to be the *primary* interface of all the objects
+ *   provided.  For example, don't pass {Node: ["document"]}, but rather
+ *   {Document: ["document"]}.  Assuming the Document interface was declared to
+ *   inherit from Node, this will automatically test that document implements
+ *   the Node interface too.
+ *
+ *   Warning: methods will be called on any provided objects, in a manner that
+ *   WebIDL requires be safe.  For instance, if a method has mandatory
+ *   arguments, the test suite will try calling it with too few arguments to
+ *   see if it throws an exception.  If an implementation incorrectly runs the
+ *   function instead of throwing, this might have side effects, possibly even
+ *   preventing the test suite from running correctly.
+ *
+ * prevent_multiple_testing(name):
+ *   This is a niche method for use in case you're testing many objects that
+ *   implement the same interfaces, and don't want to retest the same
+ *   interfaces every single time.  For instance, HTML defines many interfaces
+ *   that all inherit from HTMLElement, so the HTML test suite has something
+ *   like
+ *     .add_objects({
+ *         HTMLHtmlElement: ['document.documentElement'],
+ *         HTMLHeadElement: ['document.head'],
+ *         HTMLBodyElement: ['document.body'],
+ *         ...
+ *     })
+ *   and so on for dozens of element types.  This would mean that it would
+ *   retest that each and every one of those elements implements HTMLElement,
+ *   Element, and Node, which would be thousands of basically redundant tests.
+ *   The test suite therefore calls prevent_multiple_testing("HTMLElement").
+ *   This means that once one object has been tested to implement HTMLElement
+ *   and its ancestors, no other object will be.  Thus in the example code
+ *   above, the harness would test that document.documentElement correctly
+ *   implements HTMLHtmlElement, HTMLElement, Element, and Node; but
+ *   document.head would only be tested for HTMLHeadElement, and so on for
+ *   further objects.
+ *
+ * test():
+ *   Run all tests.  This should be called after you've called all other
+ *   methods to add IDLs and objects.
+ */
+"use strict";
+(function(){
+/// IdlArray ///
+//Entry point
+window.IdlArray = function()
+//@{
+{
+    this.members = {};
+    this.objects = {};
+    // When adding multiple collections of IDLs one at a time, an earlier one
+    // might contain a partial interface or implements statement that depends
+    // on a later one.  Save these up and handle them right before we run
+    // tests.
+    this.partials = [];
+    this.implements = {};
+}
+
+//@}
+IdlArray.prototype.add_idls = function(raw_idls)
+//@{
+{
+    this.internal_add_idls(WebIDLParser.parse(raw_idls));
+};
+
+//@}
+IdlArray.prototype.add_untested_idls = function(raw_idls)
+//@{
+{
+    var parsed_idls = WebIDLParser.parse(raw_idls);
+    for (var i = 0; i < parsed_idls.length; i++)
+    {
+        parsed_idls[i].untested = true;
+        if ("members" in parsed_idls[i])
+        {
+            for (var j = 0; j < parsed_idls[i].members.length; j++)
+            {
+                parsed_idls[i].members[j].untested = true;
+            }
+        }
+    }
+    this.internal_add_idls(parsed_idls);
+}
+
+//@}
+IdlArray.prototype.internal_add_idls = function(parsed_idls)
+//@{
+{
+    parsed_idls.forEach(function(parsed_idl)
+    {
+        if (parsed_idl.type == "partialinterface")
+        {
+            this.partials.push(parsed_idl);
+            return;
+        }
+
+        if (parsed_idl.type == "implements")
+        {
+            if (!(parsed_idl.target in this.implements))
+            {
+                this.implements[parsed_idl.target] = [];
+            }
+            this.implements[parsed_idl.target].push(parsed_idl.implements);
+            return;
+        }
+
+        parsed_idl.array = this;
+        if (parsed_idl.name in this.members)
+        {
+            throw "Duplicate identifier " + parsed_idl.name;
+        }
+        switch(parsed_idl.type)
+        {
+        case "interface":
+            this.members[parsed_idl.name] = new IdlInterface(parsed_idl);
+            break;
+
+        case "exception":
+            this.members[parsed_idl.name] = new IdlException(parsed_idl);
+            break;
+
+        case "dictionary":
+            //Nothing to test, but we need the dictionary info around for type
+            //checks
+            this.members[parsed_idl.name] = new IdlDictionary(parsed_idl);
+            break;
+
+        case "typedef":
+            //TODO
+            break;
+
+        default:
+            throw parsed_idl.name + ": " + parsed_idl.type + " not yet supported";
+        }
+    }.bind(this));
+}
+
+//@}
+IdlArray.prototype.add_objects = function(dict)
+//@{
+{
+    for (var k in dict)
+    {
+        if (k in this.objects)
+        {
+            this.objects[k] = this.objects[k].concat(dict[k]);
+        }
+        else
+        {
+            this.objects[k] = dict[k];
+        }
+    }
+}
+
+//@}
+IdlArray.prototype.prevent_multiple_testing = function(name)
+//@{
+{
+    this.members[name].prevent_multiple_testing = true;
+}
+
+//@}
+IdlArray.prototype.recursively_get_implements = function(interface_name)
+//@{
+{
+    var ret = this.implements[interface_name];
+    if (ret === undefined)
+    {
+        return [];
+    }
+    for (var i = 0; i < this.implements[interface_name].length; i++)
+    {
+        ret = ret.concat(this.recursively_get_implements(ret[i]));
+        if (ret.indexOf(ret[i]) != ret.lastIndexOf(ret[i]))
+        {
+            throw "Circular implements statements involving " + ret[i];
+        }
+    }
+    return ret;
+}
+
+//@}
+IdlArray.prototype.test = function()
+//@{
+{
+    this.partials.forEach(function(parsed_idl)
+    {
+        if (!(parsed_idl.name in this.members)
+        || !(this.members[parsed_idl.name] instanceof IdlInterface))
+        {
+            throw "Partial interface " + parsed_idl.name + " with no original interface";
+        }
+        if (parsed_idl.extAttrs)
+        {
+            parsed_idl.extAttrs.forEach(function(extAttr)
+            {
+                this.members[parsed_idl.name].extAttrs.push(extAttr);
+            }.bind(this));
+        }
+        parsed_idl.members.forEach(function(member)
+        {
+            this.members[parsed_idl.name].members.push(new IdlInterfaceMember(member));
+        }.bind(this));
+    }.bind(this));
+    this.partials = [];
+
+    for (var lhs in this.implements)
+    {
+        this.recursively_get_implements(lhs).forEach(function(rhs)
+        {
+            if (!(lhs in this.members)
+            || !(this.members[lhs] instanceof IdlInterface)
+            || !(rhs in this.members)
+            || !(this.members[rhs] instanceof IdlInterface))
+            {
+                throw lhs + " implements " + rhs + ", but one is undefined or not an interface";
+            }
+            this.members[rhs].members.forEach(function(member)
+            {
+                this.members[lhs].members.push(new IdlInterfaceMember(member));
+            }.bind(this));
+        }.bind(this));
+    }
+    this.implements = {};
+
+    for (var name in this.members)
+    {
+        this.members[name].test();
+        if (name in this.objects)
+        {
+            this.objects[name].forEach(function(str)
+            {
+                this.members[name].test_object(str);
+            }.bind(this));
+        }
+    }
+};
+
+//@}
+IdlArray.prototype.assert_type_is = function(value, type)
+//@{
+{
+    if (type.idlType == "any")
+    {
+        //No assertions to make
+        return;
+    }
+
+    if (type.nullable && value === null)
+    {
+        //This is fine
+        return;
+    }
+
+    if (type.array)
+    {
+        //TODO: not supported yet
+        return;
+    }
+
+    if (type.sequence)
+    {
+        assert_true(Array.isArray(value), "is not array");
+        if (!type.idlType.length)
+        {
+            return;
+        }
+        type = type.idlType[0];
+    }
+    else
+    {
+        type = type.idlType;
+    }
+
+    switch(type)
+    {
+        case "void":
+            assert_equals(value, undefined);
+            return;
+
+        case "boolean":
+            assert_equals(typeof value, "boolean");
+            return;
+
+        case "byte":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(-128 <= value && value <= 127, "byte " + value + " not in range [-128, 127]");
+            return;
+
+        case "octet":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(0 <= value && value <= 255, "octet " + value + " not in range [0, 255]");
+            return;
+
+        case "short":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(-32768 <= value && value <= 32767, "short " + value + " not in range [-32768, 32767]");
+            return;
+
+        case "unsigned short":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(0 <= value && value <= 65535, "unsigned short " + value + " not in range [0, 65535]");
+            return;
+
+        case "long":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(-2147483648 <= value && value <= 2147483647, "long " + value + " not in range [-2147483648, 2147483647]");
+            return;
+
+        case "unsigned long":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(0 <= value && value <= 4294967295, "unsigned long " + value + " not in range [0, 4294967295]");
+            return;
+
+        case "long long":
+            assert_equals(typeof value, "number");
+            return;
+
+        case "unsigned long long":
+            assert_equals(typeof value, "number");
+            assert_true(0 <= value, "unsigned long long is negative");
+            return;
+
+        case "float":
+        case "double":
+            //TODO: distinguish these cases
+            assert_equals(typeof value, "number");
+            return;
+
+        case "DOMString":
+            assert_equals(typeof value, "string");
+            return;
+
+        case "object":
+            assert_true(typeof value == "object" || typeof value == "function", "wrong type: not object or function");
+            return;
+    }
+
+    if (!(type in this.members))
+    {
+        throw "Unrecognized type " + type;
+    }
+
+    if (this.members[type] instanceof IdlInterface)
+    {
+        //We don't want to run the full
+        //IdlInterface.prototype.test_instance_of, because that could result in
+        //an infinite loop.  TODO: This means we don't have tests for
+        //NoInterfaceObject interfaces, and we also can't test objects that
+        //come from another window.
+        assert_true(typeof value == "object" || typeof value == "function", "wrong type: not object or function");
+        if (value instanceof Object
+        && !this.members[type].has_extended_attribute("NoInterfaceObject")
+        && type in window)
+        {
+            assert_true(value instanceof window[type], "not instanceof " + type);
+        }
+    }
+    else if (this.members[type] instanceof IdlDictionary)
+    {
+        //TODO: Test when we actually have something to test this on
+    }
+    else
+    {
+        throw "Type " + type + " isn't an interface or dictionary";
+    }
+};
+//@}
+
+/// IdlObject ///
+function IdlObject() {}
+IdlObject.prototype.has_extended_attribute = function(name)
+//@{
+{
+    return this.extAttrs.some(function(o)
+    {
+        return o.name == name;
+    });
+};
+
+//@}
+IdlObject.prototype.test = function() {};
+
+/// IdlDictionary ///
+//Used for IdlArray.prototype.assert_type_is
+function IdlDictionary(obj)
+//@{
+{
+    this.name = obj.name;
+    this.members = obj.members ? obj.members : [];
+    this.inheritance = obj.inheritance ? obj.inheritance: [];
+}
+
+//@}
+IdlDictionary.prototype = Object.create(IdlObject.prototype);
+
+/// IdlException ///
+function IdlException(obj)
+//@{
+{
+    this.name = obj.name;
+    this.array = obj.array;
+    this.untested = obj.untested;
+    this.extAttrs = obj.extAttrs ? obj.extAttrs : [];
+    this.members = obj.members ? obj.members.map(function(m){return new IdlInterfaceMember(m)}) : [];
+    this.inheritance = obj.inheritance ? obj.inheritance : [];
+}
+
+//@}
+IdlException.prototype = Object.create(IdlObject.prototype);
+IdlException.prototype.test = function()
+//@{
+{
+    // Note: largely copy-pasted from IdlInterface, but then, so is the spec
+    // text.
+    if (this.has_extended_attribute("NoInterfaceObject"))
+    {
+        //No tests to do without an instance
+        return;
+    }
+
+    if (!this.untested)
+    {
+        this.test_self();
+    }
+    this.test_members();
+}
+
+//@}
+IdlException.prototype.test_self = function()
+//@{
+{
+    test(function()
+    {
+        //"For every exception that is not declared with the
+        //[NoInterfaceObject] extended attribute, a corresponding property must
+        //exist on the exception’s relevant namespace object. The name of the
+        //property is the identifier of the exception, and its value is an
+        //object called the exception interface object, which provides access
+        //to any constants that have been associated with the exception. The
+        //property has the attributes { [[Writable]]: true, [[Enumerable]]:
+        //false, [[Configurable]]: true }."
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        var desc = Object.getOwnPropertyDescriptor(window, this.name);
+        assert_false("get" in desc, "window's property " + format_value(this.name) + " has getter");
+        assert_false("set" in desc, "window's property " + format_value(this.name) + " has setter");
+        assert_true(desc.writable, "window's property " + format_value(this.name) + " is not writable");
+        assert_false(desc.enumerable, "window's property " + format_value(this.name) + " is enumerable");
+        assert_true(desc.configurable, "window's property " + format_value(this.name) + " is not configurable");
+
+        //"The exception interface object for a given exception must be a
+        //function object."
+        //"If an object is defined to be a function object, then it has
+        //characteristics as follows:"
+        //"Its [[Prototype]] internal property is the Function prototype
+        //object."
+        //Note: This doesn't match browsers as of December 2011, see
+        //http://www.w3.org/Bugs/Public/show_bug.cgi?id=14813
+        assert_true(Function.prototype.isPrototypeOf(window[this.name]),
+                    "prototype of window's property " + format_value(this.name) + " is not Function.prototype");
+        //"Its [[Get]] internal property is set as described in ECMA-262
+        //section 15.3.5.4."
+        //Not much to test for this.
+        //"Its [[Construct]] internal property is set as described in ECMA-262
+        //section 13.2.2."
+        //Tested below.
+        //"Its [[HasInstance]] internal property is set as described in
+        //ECMA-262 section 15.3.5.3, unless otherwise specified."
+        //TODO
+        //"Its [[Class]] internal property is “Function”."
+        //String() and {}.toString.call() should be equivalent, since nothing
+        //defines a stringifier.
+        assert_equals({}.toString.call(window[this.name]), "[object Function]",
+                      "{}.toString.call(" + this.name + ")");
+        assert_equals(String(window[this.name]), "[object Function]",
+                      "String(" + this.name + ")");
+
+        //TODO: Test 4.9.1.1. Exception interface object [[Call]] method (which
+        //does not match browsers: //http://www.w3.org/Bugs/Public/show_bug.cgi?id=14885)
+    }.bind(this), this.name + " exception: existence and properties of exception interface object");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+
+        //"The exception interface object must also have a property named
+        //“prototype” with attributes { [[Writable]]: false, [[Enumerable]]:
+        //false, [[Configurable]]: false } whose value is an object called the
+        //exception interface prototype object. This object also provides
+        //access to the constants that are declared on the exception."
+        assert_own_property(window[this.name], "prototype",
+                            'exception "' + this.name + '" does not have own property "prototype"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name], "prototype");
+        assert_false("get" in desc, this.name + ".prototype has getter");
+        assert_false("set" in desc, this.name + ".prototype has setter");
+        assert_false(desc.writable, this.name + ".prototype is writable");
+        assert_false(desc.enumerable, this.name + ".prototype is enumerable");
+        assert_false(desc.configurable, this.name + ".prototype is configurable");
+
+        //"The exception interface prototype object for a given exception must
+        //have an internal [[Prototype]] property whose value is as follows:
+        //
+        //"If the exception is declared to inherit from another exception, then
+        //the value of the internal [[Prototype]] property is the exception
+        //interface prototype object for the inherited exception.
+        //"Otherwise, the exception is not declared to inherit from another
+        //exception. The value of the internal [[Prototype]] property is the
+        //Error prototype object ([ECMA-262], section 15.11.3.1)."
+        //Note: This doesn't match browsers as of December 2011, see
+        //https://www.w3.org/Bugs/Public/show_bug.cgi?id=14887.
+        var inherit_exception = this.inheritance.length ? this.inheritance[0] : "Error";
+        assert_own_property(window, inherit_exception,
+                            'should inherit from ' + inherit_exception + ', but window has no such property');
+        assert_own_property(window[inherit_exception], "prototype",
+                            'should inherit from ' + inherit_exception + ', but that object has no "prototype" property');
+        assert_true(window[inherit_exception].prototype.isPrototypeOf(window[this.name].prototype),
+                    'prototype of ' + this.name + '.prototype is not ' + inherit_exception + '.prototype');
+
+        //"The class string of an exception interface prototype object is the
+        //concatenation of the exception’s identifier and the string
+        //“Prototype”."
+        //String() and {}.toString.call() should be equivalent, since nothing
+        //defines a stringifier.
+        assert_equals({}.toString.call(window[this.name].prototype), "[object " + this.name + "Prototype]",
+                      "{}.toString.call(" + this.name + ")");
+        assert_equals(String(window[this.name].prototype), "[object " + this.name + "Prototype]",
+                      "String(" + this.name + ")");
+    }.bind(this), this.name + " exception: existence and properties of exception interface prototype object");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+
+        //"There must be a property named “name” on the exception interface
+        //prototype object with attributes { [[Writable]]: true,
+        //[[Enumerable]]: false, [[Configurable]]: true } and whose value is
+        //the identifier of the exception."
+        assert_own_property(window[this.name].prototype, "name",
+                'prototype object does not have own property "name"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, "name");
+        assert_false("get" in desc, this.name + ".prototype.name has getter");
+        assert_false("set" in desc, this.name + ".prototype.name has setter");
+        assert_true(desc.writable, this.name + ".prototype.name is not writable");
+        assert_false(desc.enumerable, this.name + ".prototype.name is enumerable");
+        assert_true(desc.configurable, this.name + ".prototype.name is not configurable");
+        assert_equals(desc.value, this.name, this.name + ".prototype.name has incorrect value");
+    }.bind(this), this.name + " exception: existence and properties of exception interface prototype object's \"name\" property");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+
+        //"If the [NoInterfaceObject] extended attribute was not specified on
+        //the exception, then there must also be a property named “constructor”
+        //on the exception interface prototype object with attributes {
+        //[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }
+        //and whose value is a reference to the exception interface object for
+        //the exception."
+        assert_own_property(window[this.name].prototype, "constructor",
+                            this.name + '.prototype does not have own property "constructor"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, "constructor");
+        assert_false("get" in desc, this.name + ".prototype.constructor has getter");
+        assert_false("set" in desc, this.name + ".prototype.constructor has setter");
+        assert_true(desc.writable, this.name + ".prototype.constructor is not writable");
+        assert_false(desc.enumerable, this.name + ".prototype.constructor is enumerable");
+        assert_true(desc.configurable, this.name + ".prototype.constructor in not configurable");
+        assert_equals(window[this.name].prototype.constructor, window[this.name],
+                      this.name + '.prototype.constructor is not the same object as ' + this.name);
+    }.bind(this), this.name + " exception: existence and properties of exception interface prototype object's \"constructor\" property");
+}
+
+//@}
+IdlException.prototype.test_members = function()
+//@{
+{
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        if (member.untested)
+        {
+            continue;
+        }
+        if (member.type == "const" && member.name != "prototype")
+        {
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+
+                //"For each constant defined on the exception, there must be a
+                //corresponding property on the exception interface object, if
+                //it exists, if the identifier of the constant is not
+                //“prototype”."
+                assert_own_property(window[this.name], member.name);
+                //"The value of the property is the ECMAScript value that is
+                //equivalent to the constant’s IDL value, according to the
+                //rules in section 4.2 above."
+                assert_equals(window[this.name][member.name], eval(member.value),
+                              "property has wrong value");
+                //"The property has attributes { [[Writable]]: false,
+                //[[Enumerable]]: true, [[Configurable]]: false }."
+                var desc = Object.getOwnPropertyDescriptor(window[this.name], member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " exception: constant " + member.name + " on exception interface object");
+            //"In addition, a property with the same characteristics must
+            //exist on the exception interface prototype object."
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'exception "' + this.name + '" does not have own property "prototype"');
+
+                assert_own_property(window[this.name].prototype, member.name);
+                assert_equals(window[this.name].prototype[member.name], eval(member.value),
+                              "property has wrong value");
+                var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " exception: constant " + member.name + " on exception interface prototype object");
+        }
+        else if (member.type == "field")
+        {
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'exception "' + this.name + '" does not have own property "prototype"');
+
+                //"For each exception field, there must be a corresponding
+                //property on the exception interface prototype object, whose
+                //characteristics are as follows:
+                //"The name of the property is the identifier of the exception
+                //field."
+                assert_own_property(window[this.name].prototype, member.name);
+                //"The property has attributes { [[Get]]: G, [[Enumerable]]:
+                //true, [[Configurable]]: true }, where G is the exception
+                //field getter, defined below."
+                var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, member.name);
+                assert_false("value" in desc, "property descriptor has value but is supposed to be accessor");
+                assert_false("writable" in desc, 'property descriptor has "writable" field but is supposed to be accessor');
+                //TODO: ES5 doesn't seem to say whether desc should have a .set
+                //property.
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_true(desc.configurable, "property is not configurable");
+                //"The exception field getter is a Function object whose
+                //behavior when invoked is as follows:"
+                assert_equals(typeof desc.get, "function", "typeof getter");
+                //"The value of the Function object’s “length” property is the
+                //Number value 0."
+                //This test is before the TypeError tests so that it's easiest
+                //to see that Firefox 11a1 only fails one assert in this test.
+                assert_equals(desc.get.length, 0, "getter length");
+                //"Let O be the result of calling ToObject on the this value.
+                //"If O is not a platform object representing an exception for
+                //the exception on which the exception field was declared, then
+                //throw a TypeError."
+                //TODO: Test on a platform object representing an exception.
+                assert_throws(new TypeError(), function()
+                {
+                    window[this.name].prototype[member.name];
+                }, "getting property on prototype object must throw TypeError");
+                assert_throws(new TypeError(), function()
+                {
+                    desc.get.call({});
+                }, "calling getter on wrong object type must throw TypeError");
+            }.bind(this), this.name + " exception: field " + member.name + " on exception interface prototype object");
+        }
+    }
+}
+
+//@}
+IdlException.prototype.test_object = function(desc)
+//@{
+{
+    var obj, exception = null;
+    try
+    {
+        obj = eval(desc);
+    }
+    catch(e)
+    {
+        exception = e;
+    }
+
+    test(function()
+    {
+        assert_equals(exception, null, "Unexpected exception when evaluating object");
+        assert_equals(typeof obj, "object", "wrong typeof object");
+
+        //We can't easily test that its prototype is correct if there's no
+        //interface object, or the object is from a different global environment
+        //(not instanceof Object).  TODO: test in this case that its prototype at
+        //least looks correct, even if we can't test that it's actually correct.
+        if (!this.has_extended_attribute("NoInterfaceObject")
+        && (typeof obj != "object" || obj instanceof Object))
+        {
+            assert_own_property(window, this.name,
+                                "window does not have own property " + format_value(this.name));
+            assert_own_property(window[this.name], "prototype",
+                                'exception "' + this.name + '" does not have own property "prototype"');
+
+            //"The value of the internal [[Prototype]] property of the
+            //exception object must be the exception interface prototype object
+            //from the global environment the exception object is associated
+            //with."
+            assert_true(window[this.name].prototype.isPrototypeOf(obj),
+                desc + "'s prototype is not " + this.name + ".prototype");
+        }
+
+        //"The class string of the exception object must be the identifier of
+        //the exception."
+        assert_equals({}.toString.call(obj), "[object " + this.name + "]", "{}.toString.call(" + desc + ")");
+        //Stringifier is not defined for DOMExceptions, because message isn't
+        //defined.
+    }.bind(this), this.name + " must be represented by " + desc);
+
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        test(function()
+        {
+            assert_equals(exception, null, "Unexpected exception when evaluating object");
+            assert_equals(typeof obj, "object", "wrong typeof object");
+            assert_inherits(obj, member.name);
+            if (member.type == "const")
+            {
+                assert_equals(obj[member.name], eval(member.value));
+            }
+            if (member.type == "field")
+            {
+                this.array.assert_type_is(obj[member.name], member.idlType);
+            }
+        }.bind(this), this.name + " exception: " + desc + ' must inherit property "' + member.name + '" with the proper type');
+    }
+}
+//@}
+
+/// IdlInterface ///
+function IdlInterface(obj)
+//@{
+{
+    this.name = obj.name;
+    this.array = obj.array;
+    this.untested = obj.untested;
+    this.extAttrs = obj.extAttrs ? obj.extAttrs : [];
+    this.members = obj.members ? obj.members.map(function(m){return new IdlInterfaceMember(m)}) : [];
+    this.inheritance = obj.inheritance ? obj.inheritance : [];
+}
+
+//@}
+IdlInterface.prototype = Object.create(IdlObject.prototype);
+IdlInterface.prototype.test = function()
+//@{
+{
+    if (this.has_extended_attribute("NoInterfaceObject"))
+    {
+        //No tests to do without an instance
+        return;
+    }
+
+    if (!this.untested)
+    {
+        this.test_self();
+    }
+    this.test_members();
+}
+
+//@}
+IdlInterface.prototype.test_self = function()
+//@{
+{
+    test(function()
+    {
+        //"For every interface that is not declared with the
+        //[NoInterfaceObject] extended attribute, a corresponding property
+        //must exist on the interface’s relevant namespace object. The name
+        //of the property is the identifier of the interface, and its value
+        //is an object called the interface object. The property has the
+        //attributes { [[Writable]]: true, [[Enumerable]]: false,
+        //[[Configurable]]: true }."
+        //TODO: Should we test here that the property is actually writable
+        //etc., or trust getOwnPropertyDescriptor?
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        var desc = Object.getOwnPropertyDescriptor(window, this.name);
+        assert_false("get" in desc, "window's property " + format_value(this.name) + " has getter");
+        assert_false("set" in desc, "window's property " + format_value(this.name) + " has setter");
+        assert_true(desc.writable, "window's property " + format_value(this.name) + " is not writable");
+        assert_false(desc.enumerable, "window's property " + format_value(this.name) + " is enumerable");
+        assert_true(desc.configurable, "window's property " + format_value(this.name) + " is not configurable");
+
+        //"Interface objects are always function objects."
+        //"If an object is defined to be a function object, then it has
+        //characteristics as follows:"
+        //"Its [[Prototype]] internal property is the Function prototype
+        //object."
+        //Note: This doesn't match browsers as of December 2011, see
+        //http://www.w3.org/Bugs/Public/show_bug.cgi?id=14813
+        assert_true(Function.prototype.isPrototypeOf(window[this.name]),
+                    "prototype of window's property " + format_value(this.name) + " is not Function.prototype");
+        //"Its [[Get]] internal property is set as described in ECMA-262
+        //section 15.3.5.4."
+        //Not much to test for this.
+        //"Its [[Construct]] internal property is set as described in ECMA-262
+        //section 13.2.2."
+        //Tested below if no constructor is defined.  TODO: test constructors
+        //if defined.
+        //"Its [[HasInstance]] internal property is set as described in
+        //ECMA-262 section 15.3.5.3, unless otherwise specified."
+        //TODO
+        //"Its [[Class]] internal property is “Function”."
+        //String() and {}.toString.call() should be equivalent, since nothing
+        //defines a stringifier.
+        assert_equals({}.toString.call(window[this.name]), "[object Function]",
+                      "{}.toString.call(" + this.name + ")");
+        assert_equals(String(window[this.name]), "[object Function]",
+                      "String(" + this.name + ")");
+
+        if (!this.has_extended_attribute("Constructor"))
+        {
+            //"The internal [[Call]] method of the interface object behaves as
+            //follows . . .
+            //
+            //"If I was not declared with a [Constructor] extended attribute,
+            //then throw a TypeError."
+            assert_throws(new TypeError(), function()
+            {
+                window[this.name]();
+            }, "interface object didn't throw TypeError when called as a function");
+            assert_throws(new TypeError(), function()
+            {
+                new window[this.name]();
+            }, "interface object didn't throw TypeError when called as a constructor");
+        }
+    }.bind(this), this.name + " interface: existence and properties of interface object");
+
+    if (this.has_extended_attribute("Constructor"))
+    {
+        test(function()
+        {
+            assert_own_property(window, this.name,
+                                "window does not have own property " + format_value(this.name));
+
+            //"Interface objects for interfaces declared with a [Constructor]
+            //extended attribute must have a property named “length” with
+            //attributes { [[Writable]]: false, [[Enumerable]]: false,
+            //[[Configurable]]: false } whose value is a Number determined as
+            //follows: . . .
+            //"Return the maximum argument list length of the constructors in
+            //the entries of S."
+            //TODO: Variadic constructors.  Should generalize this so that it
+            //works for testing operation length too (currently we just don't
+            //support multiple operations with the same identifier).
+            var expected_length = this.extAttrs
+                .filter(function(attr) { return attr.name == "Constructor" })
+                .map(function(attr) { return attr.arguments.length })
+                .reduce(function(m, n) { return Math.max(m, n) });
+            assert_own_property(window[this.name], "length");
+            assert_equals(window[this.name].length, expected_length, "wrong value for " + this.name + ".length");
+            var desc = Object.getOwnPropertyDescriptor(window[this.name], "length");
+            assert_false("get" in desc, this.name + ".length has getter");
+            assert_false("set" in desc, this.name + ".length has setter");
+            assert_false(desc.writable, this.name + ".length is writable");
+            assert_false(desc.enumerable, this.name + ".length is enumerable");
+            assert_false(desc.configurable, this.name + ".length is configurable");
+        }.bind(this), this.name + " interface constructor");
+    }
+
+    //TODO: Test named constructors if I find any interfaces that have them.
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+
+        //"The interface object must also have a property named “prototype”
+        //with attributes { [[Writable]]: false, [[Enumerable]]: false,
+        //[[Configurable]]: false } whose value is an object called the
+        //interface prototype object. This object has properties that
+        //correspond to the attributes and operations defined on the interface,
+        //and is described in more detail in section 4.5.3 below."
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name], "prototype");
+        assert_false("get" in desc, this.name + ".prototype has getter");
+        assert_false("set" in desc, this.name + ".prototype has setter");
+        assert_false(desc.writable, this.name + ".prototype is writable");
+        assert_false(desc.enumerable, this.name + ".prototype is enumerable");
+        assert_false(desc.configurable, this.name + ".prototype is configurable");
+
+        //"The interface prototype object for a given interface A must have
+        //an internal [[Prototype]] property whose value is as follows:
+        //"If A is not declared to inherit from another interface, then the
+        //value of the internal [[Prototype]] property of A is the Array
+        //prototype object ([ECMA-262], section 15.4.4) if the interface
+        //was declared with ArrayClass, or the Object prototype object
+        //otherwise ([ECMA-262], section 15.2.4).
+        //"Otherwise, A does inherit from another interface. The value of
+        //the internal [[Prototype]] property of A is the interface
+        //prototype object for the inherited interface."
+        var inherit_interface;
+        if (this.inheritance.length)
+        {
+            inherit_interface = this.inheritance[0];
+        }
+        else if (this.has_extended_attribute("ArrayClass"))
+        {
+            inherit_interface = "Array";
+        }
+        else
+        {
+            inherit_interface = "Object";
+        }
+        assert_own_property(window, inherit_interface,
+                            'should inherit from ' + inherit_interface + ', but window has no such property');
+        assert_own_property(window[inherit_interface], "prototype",
+                            'should inherit from ' + inherit_interface + ', but that object has no "prototype" property');
+        assert_true(window[inherit_interface].prototype.isPrototypeOf(window[this.name].prototype),
+                    'prototype of ' + this.name + '.prototype is not ' + inherit_interface + '.prototype');
+
+        //"The class string of an interface prototype object is the
+        //concatenation of the interface’s identifier and the string
+        //“Prototype”."
+        //String() and {}.toString.call() should be equivalent, since nothing
+        //defines a stringifier.
+        assert_equals({}.toString.call(window[this.name].prototype), "[object " + this.name + "Prototype]",
+                      "{}.toString.call(" + this.name + ")");
+        assert_equals(String(window[this.name].prototype), "[object " + this.name + "Prototype]",
+                      "String(" + this.name + ")");
+    }.bind(this), this.name + " interface: existence and properties of interface prototype object");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+
+        //"If the [NoInterfaceObject] extended attribute was not specified on
+        //the interface, then the interface prototype object must also have a
+        //property named “constructor” with attributes { [[Writable]]: true,
+        //[[Enumerable]]: false, [[Configurable]]: true } whose value is a
+        //reference to the interface object for the interface."
+        assert_own_property(window[this.name].prototype, "constructor",
+                            this.name + '.prototype does not have own property "constructor"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, "constructor");
+        assert_false("get" in desc, this.name + ".prototype.constructor has getter");
+        assert_false("set" in desc, this.name + ".prototype.constructor has setter");
+        assert_true(desc.writable, this.name + ".prototype.constructor is not writable");
+        assert_false(desc.enumerable, this.name + ".prototype.constructor is enumerable");
+        assert_true(desc.configurable, this.name + ".prototype.constructor in not configurable");
+        assert_equals(window[this.name].prototype.constructor, window[this.name],
+                      this.name + '.prototype.constructor is not the same object as ' + this.name);
+    }.bind(this), this.name + ' interface: existence and properties of interface prototype object\'s "constructor" property');
+}
+
+//@}
+IdlInterface.prototype.test_members = function()
+//@{
+{
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        if (member.untested)
+        {
+            continue;
+        }
+        if (member.type == "const")
+        {
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+
+                //"For each constant defined on an interface A, there must
+                //be a corresponding property on the interface object, if
+                //it exists."
+                assert_own_property(window[this.name], member.name);
+                //"The value of the property is that which is obtained by
+                //converting the constant’s IDL value to an ECMAScript
+                //value."
+                assert_equals(window[this.name][member.name], eval(member.value),
+                              "property has wrong value");
+                //"The property has attributes { [[Writable]]: false,
+                //[[Enumerable]]: true, [[Configurable]]: false }."
+                var desc = Object.getOwnPropertyDescriptor(window[this.name], member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " interface: constant " + member.name + " on interface object");
+            //"In addition, a property with the same characteristics must
+            //exist on the interface prototype object."
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'interface "' + this.name + '" does not have own property "prototype"');
+
+                assert_own_property(window[this.name].prototype, member.name);
+                assert_equals(window[this.name].prototype[member.name], eval(member.value),
+                              "property has wrong value");
+                var desc = Object.getOwnPropertyDescriptor(window[this.name], member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " interface: constant " + member.name + " on interface prototype object");
+        }
+        else if (member.type == "attribute")
+        {
+            if (member.has_extended_attribute("Unforgeable"))
+            {
+                //We do the checks in test_interface_of instead
+                continue;
+            }
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'interface "' + this.name + '" does not have own property "prototype"');
+
+                do_interface_attribute_asserts(window[this.name].prototype, member);
+            }.bind(this), this.name + " interface: attribute " + member.name);
+        }
+        else if (member.type == "operation")
+        {
+            //TODO: Need to correctly handle multiple operations with the
+            //same identifier.
+            if (!member.name)
+            {
+                //Unnamed getter or such
+                continue;
+            }
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'interface "' + this.name + '" does not have own property "prototype"');
+
+                //"For each unique identifier of an operation defined on
+                //the interface, there must be a corresponding property on
+                //the interface prototype object (if it is a regular
+                //operation) or the interface object (if it is a static
+                //operation), unless the effective overload set for that
+                //identifier and operation and with an argument count of 0
+                //(for the ECMAScript language binding) has no entries."
+                //TODO: The library doesn't seem to support static
+                //operations.
+                assert_own_property(window[this.name].prototype, member.name,
+                    "interface prototype object missing non-static operation");
+
+                var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, member.name);
+                //"The property has attributes { [[Writable]]: true,
+                //[[Enumerable]]: true, [[Configurable]]: true }."
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_true(desc.writable, "property is not writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_true(desc.configurable, "property is not configurable");
+                //"The value of the property is a Function object whose
+                //behavior is as follows . . ."
+                assert_equals(typeof window[this.name].prototype[member.name], "function",
+                              "property must be a function");
+                //"The value of the Function object’s “length” property is
+                //a Number determined as follows:
+                //". . .
+                //"Return the maximum argument list length of the functions
+                //in the entries of S."
+                assert_equals(window[this.name].prototype[member.name].length, member.arguments.length,
+                    "property has wrong .length");
+            }.bind(this), this.name + " interface: operation " + member.name);
+        }
+        //TODO: check more member types, like stringifier
+    }
+}
+
+//@}
+IdlInterface.prototype.test_object = function(desc)
+//@{
+{
+    var obj, exception = null;
+    try
+    {
+        obj = eval(desc);
+    }
+    catch(e)
+    {
+        exception = e;
+    }
+
+    //TODO: WebIDLParser doesn't currently support named legacycallers, so I'm
+    //not sure what those would look like in the AST
+    var expected_typeof = this.members.some(function(member)
+    {
+        return member.legacycaller
+            || ("idlType" in member && member.idlType.legacycaller)
+            || ("idlType" in member && typeof member.idlType == "object"
+            && "idlType" in member.idlType && member.idlType.idlType == "legacycaller");
+    }) ? "function" : "object";
+
+    this.test_primary_interface_of(desc, obj, exception, expected_typeof);
+    var current_interface = this;
+    while (current_interface)
+    {
+        if (!(current_interface.name in this.array.members))
+        {
+            throw "Interface " + current_interface.name + " not found (inherited by " + this.name + ")";
+        }
+        if (current_interface.prevent_multiple_testing && current_interface.already_tested)
+        {
+            return;
+        }
+        current_interface.test_interface_of(desc, obj, exception, expected_typeof);
+        current_interface = this.array.members[current_interface.inheritance[0]];
+    }
+}
+
+//@}
+IdlInterface.prototype.test_primary_interface_of = function(desc, obj, exception, expected_typeof)
+//@{
+{
+    //We can't easily test that its prototype is correct if there's no
+    //interface object, or the object is from a different global environment
+    //(not instanceof Object).  TODO: test in this case that its prototype at
+    //least looks correct, even if we can't test that it's actually correct.
+    if (!this.has_extended_attribute("NoInterfaceObject")
+    && (typeof obj != expected_typeof || obj instanceof Object))
+    {
+        test(function()
+        {
+            assert_equals(exception, null, "Unexpected exception when evaluating object");
+            assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+            assert_own_property(window, this.name,
+                                "window does not have own property " + format_value(this.name));
+            assert_own_property(window[this.name], "prototype",
+                                'interface "' + this.name + '" does not have own property "prototype"');
+
+            //"The value of the internal [[Prototype]] property of the platform
+            //object is the interface prototype object of the primary interface
+            //from the platform object’s associated global environment."
+            assert_true(window[this.name].prototype.isPrototypeOf(obj),
+                desc + "'s prototype is not " + this.name + ".prototype");
+        }.bind(this), this.name + " must be primary interface of " + desc);
+    }
+
+    //"The class string of a platform object that implements one or more
+    //interfaces must be the identifier of the primary interface of the
+    //platform object."
+    test(function()
+    {
+        assert_equals(exception, null, "Unexpected exception when evaluating object");
+        assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+        assert_equals({}.toString.call(obj), "[object " + this.name + "]", "{}.toString.call(" + desc + ")");
+        if (!this.members.some(function(member) { return member.stringifier || member.type == "stringifier"}))
+        {
+            assert_equals(String(obj), "[object " + this.name + "]", "String(" + desc + ")");
+        }
+    }.bind(this), "Stringification of " + desc);
+}
+
+//@}
+IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expected_typeof)
+//@{
+{
+    //TODO: Indexed and named properties, more checks on interface members
+    this.already_tested = true;
+
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        if (member.has_extended_attribute("Unforgeable"))
+        {
+            test(function()
+            {
+                assert_equals(exception, null, "Unexpected exception when evaluating object");
+                assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+                do_interface_attribute_asserts(obj, member);
+            }.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"');
+        }
+        else if ((member.type == "const"
+        || member.type == "attribute"
+        || member.type == "operation")
+        && member.name)
+        {
+            test(function()
+            {
+                assert_equals(exception, null, "Unexpected exception when evaluating object");
+                assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+                assert_inherits(obj, member.name);
+                if (member.type == "const")
+                {
+                    assert_equals(obj[member.name], eval(member.value));
+                }
+                if (member.type == "attribute")
+                {
+                    // Attributes are accessor properties, so they might
+                    // legitimately throw an exception rather than returning
+                    // anything.
+                    try
+                    {
+                        this.array.assert_type_is(obj[member.name], member.idlType);
+                    }
+                    catch (e)
+                    {
+                    }
+                }
+                if (member.type == "operation")
+                {
+                    assert_equals(typeof obj[member.name], "function");
+                }
+            }.bind(this), this.name + " interface: " + desc + ' must inherit property "' + member.name + '" with the proper type');
+        }
+        //TODO: This is wrong if there are multiple operations with the same
+        //identifier.
+        //TODO: Test passing arguments of the wrong type.
+        if (member.type == "operation" && member.name && member.arguments.length)
+        {
+            test(function()
+            {
+                assert_equals(exception, null, "Unexpected exception when evaluating object");
+                assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+                assert_inherits(obj, member.name);
+                var args = [];
+                for (var i = 0; i < member.arguments.length; i++)
+                {
+                    if (member.arguments[i].optional)
+                    {
+                        break;
+                    }
+                    assert_throws(new TypeError(), function()
+                    {
+                        obj[member.name].apply(obj, args);
+                    }, "Called with " + i + " arguments");
+
+                    args.push(create_suitable_object(member.arguments[i].type));
+                }
+            }.bind(this), this.name + " interface: calling " + member.name + "() on " + desc + " with too few arguments must throw TypeError");
+        }
+    }
+}
+
+//@}
+function do_interface_attribute_asserts(obj, member)
+//@{
+{
+    //"For each attribute defined on the interface, there must exist a
+    //corresponding property. If the attribute was declared with the
+    //[Unforgeable] extended attribute, then the property exists on every
+    //object that implements the interface.  Otherwise, it exists on the
+    //interface’s interface prototype object."
+    //This is called by test_self() with the prototype as obj, and by
+    //test_interface_of() with the object as obj.
+    assert_own_property(obj, member.name);
+
+    //"The property has attributes { [[Get]]: G, [[Set]]: S,
+    //[[Enumerable]]: true, [[Configurable]]: configurable },
+    //where:
+    //"configurable is false if the attribute was declared with
+    //the [Unforgeable] extended attribute and true otherwise;
+    //"G is the attribute getter, defined below; and
+    //"S is the attribute setter, also defined below."
+    var desc = Object.getOwnPropertyDescriptor(obj, member.name);
+    assert_false("value" in desc, 'property descriptor has value but is supposed to be accessor');
+    assert_false("writable" in desc, 'property descriptor has "writable" field but is supposed to be accessor');
+    assert_true(desc.enumerable, "property is not enumerable");
+    if (member.has_extended_attribute("Unforgeable"))
+    {
+        assert_false(desc.configurable, "[Unforgeable] property must not be configurable");
+    }
+    else
+    {
+        assert_true(desc.configurable, "property must be configurable");
+    }
+
+    //"The attribute getter is a Function object whose behavior
+    //when invoked is as follows:
+    //"...
+    //"The value of the Function object’s “length” property is
+    //the Number value 0."
+    assert_equals(typeof desc.get, "function", "getter must be Function");
+    assert_equals(desc.get.length, 0, "getter length must be 0");
+
+    //TODO: Test calling setter on the interface prototype (should throw
+    //TypeError in most cases).
+    //
+    //"The attribute setter is undefined if the attribute is
+    //declared readonly and has neither a [PutForwards] nor a
+    //[Replaceable] extended attribute declared on it.
+    //Otherwise, it is a Function object whose behavior when
+    //invoked is as follows:
+    //"...
+    //"The value of the Function object’s “length” property is
+    //the Number value 1."
+    if (member.readonly
+    && !member.has_extended_attribute("PutForwards")
+    && !member.has_extended_attribute("Replaceable"))
+    {
+        assert_equals(desc.set, undefined, "setter must be undefined for readonly attributes");
+    }
+    else
+    {
+        assert_equals(typeof desc.set, "function", "setter must be function for PutForwards, Replaceable, or non-readonly attributes");
+        assert_equals(desc.set.length, 1, "setter length must be 1");
+    }
+}
+//@}
+
+/// IdlInterfaceMember ///
+function IdlInterfaceMember(obj)
+//@{
+{
+    for (var k in obj)
+    {
+        if (k == "extAttrs")
+        {
+            this.extAttrs = obj.extAttrs ? obj.extAttrs : [];
+        }
+        else
+        {
+            this[k] = obj[k];
+        }
+    }
+    if (!("extAttrs" in this))
+    {
+        this.extAttrs = [];
+    }
+}
+
+//@}
+IdlInterfaceMember.prototype = Object.create(IdlObject.prototype);
+
+/// Internal helper functions ///
+function create_suitable_object(type)
+//@{
+{
+    if (type.nullable)
+    {
+        return null;
+    }
+    switch (type.idlType)
+    {
+        case "any":
+        case "boolean":
+            return true;
+
+        case "byte": case "octet": case "short": case "unsigned short":
+        case "long": case "unsigned long": case "long long":
+        case "unsigned long long": case "float": case "double":
+            return 7;
+
+        case "DOMString":
+            return "foo";
+
+        case "object":
+            return {a: "b"};
+
+        case "Node":
+            return document.createTextNode("abc");
+    }
+    return null;
+}
+//@}
+})();
+// vim: set expandtab shiftwidth=4 tabstop=4 foldmarker=@{,@} foldmethod=marker:
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/w3c/testharness.css
@@ -0,0 +1,70 @@
+html {
+    font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
+}
+
+section#summary {
+    margin-bottom:1em;
+}
+
+table#results {
+    border-collapse:collapse;
+    table-layout:fixed;
+    width:100%;
+}
+
+table#results th:first-child,
+table#results td:first-child {
+    width:4em;
+}
+
+table#results th:last-child,
+table#results td:last-child {
+    width:50%;
+}
+
+table#results th {
+    padding:0;
+    padding-bottom:0.5em;
+    border-bottom:medium solid black;
+}
+
+table#results td {
+    padding:1em;
+    padding-bottom:0.5em;
+    border-bottom:thin solid black;
+}
+
+tr.pass > td:first-child {
+    color:green;
+}
+
+tr.fail > td:first-child {
+    color:red;
+}
+
+tr.timeout > td:first-child {
+    color:red;
+}
+
+tr.notrun > td:first-child {
+    color:blue;
+}
+
+.pass .fail .timeout .notrun > td:first-child {
+    font-variant:small-caps;
+}
+
+table#results span {
+    display:block;
+}
+
+table#results span.expected {
+    font-family:DejaVu Sans Mono, Bitstream Vera Sans Mono, Monospace;
+    white-space:pre;
+}
+
+table#results span.actual {
+    font-family:DejaVu Sans Mono, Bitstream Vera Sans Mono, Monospace;
+    white-space:pre;
+}
+
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/w3c/testharness.js
@@ -0,0 +1,1758 @@
+/*
+Distributed under both the W3C Test Suite License [1] and the W3C
+3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
+policies and contribution forms [3].
+
+[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
+[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
+[3] http://www.w3.org/2004/10/27-testcases
+*/
+
+/*
+ * == Introduction ==
+ *
+ * This file provides a framework for writing testcases. It is intended to
+ * provide a convenient API for making common assertions, and to work both
+ * for testing synchronous and asynchronous DOM features in a way that
+ * promotes clear, robust, tests.
+ *
+ * == Basic Usage ==
+ *
+ * To use this file, import the script and the testharnessreport script into
+ * the test document:
+ * <script src="/resources/testharness.js"></script>
+ * <script src="/resources/testharnessreport.js"></script>
+ *
+ * Within each file one may define one or more tests. Each test is atomic
+ * in the sense that a single test has a single result (pass/fail/timeout).
+ * Within each test one may have a number of asserts. The test fails at the
+ * first failing assert, and the remainder of the test is (typically) not run.
+ *
+ * If the file containing the tests is a HTML file with an element of id "log"
+ * this will be populated with a table containing the test results after all
+ * the tests have run.
+ *
+ * NOTE: By default tests must be created before the load event fires. For ways
+ *       to create tests after the load event, see "Determining when all tests are
+ *       complete", below
+ *
+ * == Synchronous Tests ==
+ *
+ * To create a synchronous test use the test() function:
+ *
+ * test(test_function, name, properties)
+ *
+ * test_function is a function that contains the code to test. For example a
+ * trivial passing test would be:
+ *
+ * test(function() {assert_true(true)}, "assert_true with true")
+ *
+ * The function passed in is run in the test() call.
+ *
+ * properties is an object that overrides default test properties. The recognised properties
+ * are:
+ *    timeout - the test timeout in ms
+ *
+ * e.g.
+ * test(test_function, "Sample test", {timeout:1000})
+ *
+ * would run test_function with a timeout of 1s.
+ *
+ * == Asynchronous Tests ==
+ *
+ * Testing asynchronous features is somewhat more complex since the result of
+ * a test may depend on one or more events or other callbacks. The API provided
+ * for testing these features is indended to be rather low-level but hopefully
+ * applicable to many situations.
+ *
+ * To create a test, one starts by getting a Test object using async_test:
+ *
+ * async_test(name, properties)
+ *
+ * e.g.
+ * var t = async_test("Simple async test")
+ *
+ * Assertions can be added to the test by calling the step method of the test
+ * object with a function containing the test assertions:
+ *
+ * t.step(function() {assert_true(true)});
+ *
+ * When all the steps are complete, the done() method must be called:
+ *
+ * t.done();
+ *
+ * The properties argument is identical to that for test().
+ *
+ * In many cases it is convenient to run a step in response to an event or a
+ * callback. A convenient method of doing this is through the step_func method
+ * which returns a function that, when called runs a test step. For example
+ *
+ * object.some_event = t.step_func(function(e) {assert_true(e.a)});
+ *
+ * == Making assertions ==
+ *
+ * Functions for making assertions start assert_
+ * The best way to get a list is to look in this file for functions names
+ * matching that pattern. The general signature is
+ *
+ * assert_something(actual, expected, description)
+ *
+ * although not all assertions precisely match this pattern e.g. assert_true
+ * only takes actual and description as arguments.
+ *
+ * The description parameter is used to present more useful error messages when
+ * a test fails
+ *
+ * NOTE: All asserts must be located in a test() or a step of an async_test().
+ *       asserts outside these places won't be detected correctly by the harness
+ *       and may cause a file to stop testing.
+ *
+ * == Setup ==
+ *
+ * Sometimes tests require non-trivial setup that may fail. For this purpose
+ * there is a setup() function, that may be called with one or two arguments.
+ * The two argument version is:
+ *
+ * setup(func, properties)
+ *
+ * The one argument versions may omit either argument.
+ * func is a function to be run synchronously. setup() becomes a no-op once
+ * any tests have returned results. Properties are global properties of the test
+ * harness. Currently recognised properties are:
+ *
+ * timeout - The time in ms after which the harness should stop waiting for
+ *           tests to complete (this is different to the per-test timeout
+ *           because async tests do not start their timer until .step is called)
+ *
+ * explicit_done - Wait for an explicit call to done() before declaring all tests
+ *                 complete (see below)
+ *
+ * output_document - The document to which results should be logged. By default this is
+ *                   the current document but could be an ancestor document in some cases
+ *                   e.g. a SVG test loaded in an HTML wrapper
+ *
+ * == Determining when all tests are complete ==
+ *
+ * By default the test harness will assume there are no more results to come
+ * when:
+ * 1) There are no Test objects that have been created but not completed
+ * 2) The load event on the document has fired
+ *
+ * This behaviour can be overridden by setting the explicit_done property to true
+ * in a call to setup(). If explicit_done is true, the test harness will not assume
+ * it is done until the global done() function is called. Once done() is called, the
+ * two conditions above apply like normal.
+ *
+ * == Generating tests ==
+ *
+ * NOTE: this functionality may be removed
+ *
+ * There are scenarios in which is is desirable to create a large number of
+ * (synchronous) tests that are internally similar but vary in the parameters
+ * used. To make this easier, the generate_tests function allows a single
+ * function to be called with each set of parameters in a list:
+ *
+ * generate_tests(test_function, parameter_lists)
+ *
+ * For example:
+ *
+ * generate_tests(assert_equals, [
+ *     ["Sum one and one", 1+1, 2],
+ *     ["Sum one and zero", 1+0, 1]
+ *     ])
+ *
+ * Is equivalent to:
+ *
+ * test(function() {assert_equals(1+1, 2)}, "Sum one and one")
+ * test(function() {assert_equals(1+0, 1)}, "Sum one and zero")
+ *
+ * Note that the first item in each parameter list corresponds to the name of
+ * the test.
+ *
+ * == Callback API ==
+ *
+ * The framework provides callbacks corresponding to 3 events:
+ *
+ * start - happens when the first Test is created
+ * result - happens when a test result is recieved
+ * complete - happens when all results are recieved
+ *
+ * The page defining the tests may add callbacks for these events by calling
+ * the following methods:
+ *
+ *   add_start_callback(callback) - callback called with no arguments
+ *   add_result_callback(callback) - callback called with a test argument
+ *   add_completion_callback(callback) - callback called with an array of tests
+ *                                       and an status object
+ *
+ * tests have the following properties:
+ *   status: A status code. This can be compared to the PASS, FAIL, TIMEOUT and
+ *           NOTRUN properties on the test object
+ *   message: A message indicating the reason for failure. In the future this
+ *            will always be a string
+ *
+ *  The status object gives the overall status of the harness. It has the
+ *  following properties:
+ *    status: Can be compared to the OK, ERROR and TIMEOUT properties
+ *    message: An error message set when the status is ERROR
+ *
+ * == External API ==
+ *
+ * In order to collect the results of multiple pages containing tests, the test
+ * harness will, when loaded in a nested browsing context, attempt to call
+ * certain functions in each ancestor browsing context:
+ *
+ * start - start_callback
+ * result - result_callback
+ * complete - completion_callback
+ *
+ * These are given the same arguments as the corresponding internal callbacks
+ * described above.
+ *
+ * == List of assertions ==
+ *
+ * assert_true(actual, description)
+ *   asserts that /actual/ is strictly true
+ *
+ * assert_false(actual, description)
+ *   asserts that /actual/ is strictly false
+ *
+ * assert_equals(actual, expected, description)
+ *   asserts that /actual/ is the same value as /expected/
+ *
+ * assert_not_equals(actual, expected, description)
+ *   asserts that /actual/ is a different value to /expected/. Yes, this means
+ *   that "expected" is a misnomer
+ *
+ * assert_in_array(actual, expected, description)
+ *   asserts that /expected/ is an Array, and /actual/ is equal to one of the
+ *   members -- expected.indexOf(actual) != -1
+ *
+ * assert_array_equals(actual, expected, description)
+ *   asserts that /actual/ and /expected/ have the same length and the value of
+ *   each indexed property in /actual/ is the strictly equal to the corresponding
+ *   property value in /expected/
+ *
+ * assert_approx_equals(actual, expected, epsilon, description)
+ *   asserts that /actual/ is a number within +/- /epsilon/ of /expected/
+ *
+ * assert_regexp_match(actual, expected, description)
+ *   asserts that /actual/ matches the regexp /expected/
+ *
+ * assert_own_property(object, property_name, description)
+ *   assert that object has own property property_name
+ *
+ * assert_inherits(object, property_name, description)
+ *   assert that object does not have an own property named property_name
+ *   but that property_name is present in the prototype chain for object
+ *
+ * assert_idl_attribute(object, attribute_name, description)
+ *   assert that an object that is an instance of some interface has the
+ *   attribute attribute_name following the conditions specified by WebIDL
+ *
+ * assert_readonly(object, property_name, description)
+ *   assert that property property_name on object is readonly
+ *
+ * assert_throws(code, func, description)
+ *   code - a DOMException/RangeException code as a string, e.g. "HIERARCHY_REQUEST_ERR"
+ *   func - a function that should throw
+ *
+ *   assert that func throws a DOMException or RangeException (as appropriate)
+ *   with the given code.  If an object is passed for code instead of a string,
+ *   checks that the thrown exception has a property called "name" that matches
+ *   the property of code called "name".  Note, this function will probably be
+ *   rewritten sometime to make more sense.
+ *
+ * assert_unreached(description)
+ *   asserts if called. Used to ensure that some codepath is *not* taken e.g.
+ *   an event does not fire.
+ *
+ * assert_exists(object, property_name, description)
+ *   *** deprecated ***
+ *   asserts that object has an own property property_name
+ *
+ * assert_not_exists(object, property_name, description)
+ *   *** deprecated ***
+ *   assert that object does not have own property property_name
+ */
+
+(function ()
+{
+    var debug = false;
+    // default timeout is 5 seconds, test can override if needed
+    var settings = {
+      output:true,
+      timeout:5000,
+      test_timeout:2000
+    };
+
+    var xhtml_ns = "http://www.w3.org/1999/xhtml";
+
+    // script_prefix is used by Output.prototype.show_results() to figure out
+    // where to get testharness.css from.  It's enclosed in an extra closure to
+    // not pollute the library's namespace with variables like "src".
+    var script_prefix = null;
+    (function ()
+    {
+        var scripts = document.getElementsByTagName("script");
+        for (var i = 0; i < scripts.length; i++)
+        {
+            if (scripts[i].src)
+            {
+                var src = scripts[i].src;
+            }
+            else if (scripts[i].href)
+            {
+                //SVG case
+                var src = scripts[i].href.baseVal;
+            }
+            if (src && src.slice(src.length - "testharness.js".length) === "testharness.js")
+            {
+                script_prefix = src.slice(0, src.length - "testharness.js".length);
+                break;
+            }
+        }
+    })();
+
+    /*
+     * API functions
+     */
+
+    var name_counter = 0;
+    function next_default_name()
+    {
+        //Don't use document.title to work around an Opera bug in XHTML documents
+        var prefix = document.getElementsByTagName("title").length > 0 ?
+                         document.getElementsByTagName("title")[0].firstChild.data :
+                         "Untitled";
+        var suffix = name_counter > 0 ? " " + name_counter : "";
+        name_counter++;
+        return prefix + suffix;
+    }
+
+    function test(func, name, properties)
+    {
+        var test_name = name ? name : next_default_name();
+        properties = properties ? properties : {};
+        var test_obj = new Test(test_name, properties);
+        test_obj.step(func);
+        if (test_obj.status === test_obj.NOTRUN) {
+            test_obj.done();
+        }
+    }
+
+    function async_test(name, properties)
+    {
+        var test_name = name ? name : next_default_name();
+        properties = properties ? properties : {};
+        var test_obj = new Test(test_name, properties);
+        return test_obj;
+    }
+
+    function setup(func_or_properties, maybe_properties)
+    {
+        var func = null;
+        var properties = {};
+        if (arguments.length === 2) {
+            func = func_or_properties;
+            properties = maybe_properties;
+        } else if (func_or_properties instanceof Function){
+            func = func_or_properties;
+        } else {
+            properties = func_or_properties;
+        }
+        tests.setup(func, properties);
+        output.setup(properties);
+    }
+
+    function done() {
+        tests.end_wait();
+    }
+
+    function generate_tests(func, args) {
+        forEach(args, function(x)
+                {
+                    var name = x[0];
+                    test(function()
+                         {
+                             func.apply(this, x.slice(1));
+                         }, name);
+                });
+    }
+
+    function on_event(object, event, callback)
+    {
+      object.addEventListener(event, callback, false);
+    }
+
+    expose(test, 'test');
+    expose(async_test, 'async_test');
+    expose(generate_tests, 'generate_tests');
+    expose(setup, 'setup');
+    expose(done, 'done');
+    expose(on_event, 'on_event');
+
+    /*
+     * Return a string truncated to the given length, with ... added at the end
+     * if it was longer.
+     */
+    function truncate(s, len)
+    {
+        if (s.length > len) {
+            return s.substring(0, len - 3) + "...";
+        }
+        return s;
+    }
+
+    /*
+     * Convert a value to a nice, human-readable string
+     */
+    function format_value(val)
+    {
+        if (Array.isArray(val))
+        {
+            return "[" + val.map(format_value).join(", ") + "]";
+        }
+
+        switch (typeof val)
+        {
+        case "string":
+            for (var i = 0; i < 32; i++)
+            {
+                var replace = "\\";
+                switch (i) {
+                case 0: replace += "0"; break;
+                case 1: replace += "x01"; break;
+                case 2: replace += "x02"; break;
+                case 3: replace += "x03"; break;
+                case 4: replace += "x04"; break;
+                case 5: replace += "x05"; break;
+                case 6: replace += "x06"; break;
+                case 7: replace += "x07"; break;
+                case 8: replace += "b"; break;
+                case 9: replace += "t"; break;
+                case 10: replace += "n"; break;
+                case 11: replace += "v"; break;
+                case 12: replace += "f"; break;
+                case 13: replace += "r"; break;
+                case 14: replace += "x0e"; break;
+                case 15: replace += "x0f"; break;
+                case 16: replace += "x10"; break;
+                case 17: replace += "x11"; break;
+                case 18: replace += "x12"; break;
+                case 19: replace += "x13"; break;
+                case 20: replace += "x14"; break;
+                case 21: replace += "x15"; break;
+                case 22: replace += "x16"; break;
+                case 23: replace += "x17"; break;
+                case 24: replace += "x18"; break;
+                case 25: replace += "x19"; break;
+                case 26: replace += "x1a"; break;
+                case 27: replace += "x1b"; break;
+                case 28: replace += "x1c"; break;
+                case 29: replace += "x1d"; break;
+                case 30: replace += "x1e"; break;
+                case 31: replace += "x1f"; break;
+                }
+                val = val.replace(RegExp(String.fromCharCode(i), "g"), replace);
+            }
+            return '"' + val.replace(/"/g, '\\"') + '"';
+        case "boolean":
+        case "undefined":
+            return String(val);
+        case "number":
+            // In JavaScript, -0 === 0 and String(-0) == "0", so we have to
+            // special-case.
+            if (val === -0 && 1/val === -Infinity)
+            {
+                return "-0";
+            }
+            return String(val);
+        case "object":
+            if (val === null)
+            {
+                return "null";
+            }
+
+            // Special-case Node objects, since those come up a lot in my tests.  I
+            // ignore namespaces.  I use duck-typing instead of instanceof, because
+            // instanceof doesn't work if the node is from another window (like an
+            // iframe's contentWindow):
+            // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295
+            if ("nodeType" in val
+            && "nodeName" in val
+            && "nodeValue" in val
+            && "childNodes" in val)
+            {
+                switch (val.nodeType)
+                {
+                case Node.ELEMENT_NODE:
+                    var ret = "<" + val.tagName.toLowerCase();
+                    for (var i = 0; i < val.attributes.length; i++)
+                    {
+                        ret += " " + val.attributes[i].name + '="' + val.attributes[i].value + '"';
+                    }
+                    ret += ">" + val.innerHTML + "</" + val.tagName.toLowerCase() + ">";
+                    return "Element node " + truncate(ret, 60);
+                case Node.TEXT_NODE:
+                    return 'Text node "' + truncate(val.data, 60) + '"';
+                case Node.PROCESSING_INSTRUCTION_NODE:
+                    return "ProcessingInstruction node with target " + format_value(truncate(val.target, 60)) + " and data " + format_value(truncate(val.data, 60));
+                case Node.COMMENT_NODE:
+                    return "Comment node <!--" + truncate(val.data, 60) + "-->";
+                case Node.DOCUMENT_NODE:
+                    return "Document node with " + val.childNodes.length + (val.childNodes.length == 1 ? " child" : " children");
+                case Node.DOCUMENT_TYPE_NODE:
+                    return "DocumentType node";
+                case Node.DOCUMENT_FRAGMENT_NODE:
+                    return "DocumentFragment node with " + val.childNodes.length + (val.childNodes.length == 1 ? " child" : " children");
+                default:
+                    return "Node object of unknown type";
+                }
+            }
+
+            // Fall through to default
+        default:
+            return typeof val + ' "' + truncate(String(val), 60) + '"';
+        }
+    }
+    expose(format_value, "format_value");
+
+    /*
+     * Assertions
+     */
+
+    function assert_true(actual, description)
+    {
+        assert(actual === true, "assert_true", description,
+                                "expected true got ${actual}", {actual:actual});
+    };
+    expose(assert_true, "assert_true");
+
+    function assert_false(actual, description)
+    {
+        assert(actual === false, "assert_false", description,
+                                 "expected false got ${actual}", {actual:actual});
+    };
+    expose(assert_false, "assert_false");
+
+    function same_value(x, y) {
+        if (y !== y)
+        {
+            //NaN case
+            return x !== x;
+        }
+        else if (x === 0 && y === 0) {
+            //Distinguish +0 and -0
+            return 1/x === 1/y;
+        }
+        else
+        {
+            //typical case
+            return x === y;
+        }
+    }
+
+    function assert_equals(actual, expected, description)
+    {
+         /*
+          * Test if two primitives are equal or two objects
+          * are the same object
+          */
+        assert(same_value(actual, expected), "assert_equals", description,
+                                             "expected ${expected} but got ${actual}",
+                                             {expected:expected, actual:actual});
+    };
+    expose(assert_equals, "assert_equals");
+
+    function assert_not_equals(actual, expected, description)
+    {
+         /*
+          * Test if two primitives are unequal or two objects
+          * are different objects
+          */
+        assert(!same_value(actual, expected), "assert_not_equals", description,
+                                              "got disallowed value ${actual}",
+                                              {actual:actual});
+    };
+    expose(assert_not_equals, "assert_not_equals");
+
+    function assert_in_array(actual, expected, description)
+    {
+        assert(expected.indexOf(actual) != -1, "assert_in_array", description,
+                                               "value ${actual} not in array ${expected}",
+                                               {actual:actual, expected:expected});
+    }
+    expose(assert_in_array, "assert_in_array");
+
+    function assert_object_equals(actual, expected, description)
+    {
+         //This needs to be improved a great deal
+         function check_equal(expected, actual, stack)
+         {
+             stack.push(actual);
+
+             var p;
+             for (p in actual)
+             {
+                 assert(expected.hasOwnProperty(p), "assert_object_equals", description,
+                                                    "unexpected property ${p}", {p:p});
+
+                 if (typeof actual[p] === "object" && actual[p] !== null)
+                 {
+                     if (stack.indexOf(actual[p]) === -1)
+                     {
+                         check_equal(actual[p], expected[p], stack);
+                     }
+                 }
+                 else
+                 {
+                     assert(actual[p] === expected[p], "assert_object_equals", description,
+                                                       "property ${p} expected ${expected} got ${actual}",
+                                                       {p:p, expected:expected, actual:actual});
+                 }
+             }
+             for (p in expected)
+             {
+                 assert(actual.hasOwnProperty(p),
+                        "assert_object_equals", description,
+                        "expected property ${p} missing", {p:p});
+             }
+             stack.pop();
+         }
+         check_equal(actual, expected, []);
+    };
+    expose(assert_object_equals, "assert_object_equals");
+
+    function assert_array_equals(actual, expected, description)
+    {
+        assert(actual.length === expected.length,
+               "assert_array_equals", description,
+               "lengths differ, expected ${expected} got ${actual}",
+               {expected:expected.length, actual:actual.length});
+
+        for (var i=0; i < actual.length; i++)
+        {
+            assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),
+                   "assert_array_equals", description,
+                   "property ${i}, property expected to be $expected but was $actual",
+                   {i:i, expected:expected.hasOwnProperty(i) ? "present" : "missing",
+                   actual:actual.hasOwnProperty(i) ? "present" : "missing"});
+            assert(expected[i] === actual[i],
+                   "assert_array_equals", description,
+                   "property ${i}, expected ${expected} but got ${actual}",
+                   {i:i, expected:expected[i], actual:actual[i]});
+        }
+    }
+    expose(assert_array_equals, "assert_array_equals");
+
+    function assert_approx_equals(actual, expected, epsilon, description)
+    {
+        /*
+         * Test if two primitive numbers are equal withing +/- epsilon
+         */
+        assert(typeof actual === "number",
+               "assert_approx_equals", description,
+               "expected a number but got a ${type_actual}",
+               {type_actual:typeof actual});
+
+        assert(Math.abs(actual - expected) <= epsilon,
+               "assert_approx_equals", description,
+               "expected ${expected} +/- ${epsilon} but got ${actual}",
+               {expected:expected, actual:actual, epsilon:epsilon});
+    };
+    expose(assert_approx_equals, "assert_approx_equals");
+
+    function assert_regexp_match(actual, expected, description) {
+        /*
+         * Test if a string (actual) matches a regexp (expected)
+         */
+        assert(expected.test(actual),
+               "assert_regexp_match", description,
+               "expected ${expected} but got ${actual}",
+               {expected:expected, actual:actual});
+    }
+    expose(assert_regexp_match, "assert_regexp_match");
+
+
+    function _assert_own_property(name) {
+        return function(object, property_name, description)
+        {
+            assert(object.hasOwnProperty(property_name),
+                   name, description,
+                   "expected property ${p} missing", {p:property_name});
+        };
+    }
+    expose(_assert_own_property("assert_exists"), "assert_exists");
+    expose(_assert_own_property("assert_own_property"), "assert_own_property");
+
+    function assert_not_exists(object, property_name, description)
+    {
+        assert(!object.hasOwnProperty(property_name),
+               "assert_not_exists", description,
+               "unexpected property ${p} found", {p:property_name});
+    };
+    expose(assert_not_exists, "assert_not_exists");
+
+    function _assert_inherits(name) {
+        return function (object, property_name, description)
+        {
+            assert(typeof object === "object",
+                   name, description,
+                   "provided value is not an object");
+
+            assert("hasOwnProperty" in object,
+                   name, description,
+                   "provided value is an object but has no hasOwnProperty method");
+
+            assert(!object.hasOwnProperty(property_name),
+                   name, description,
+                   "property ${p} found on object expected in prototype chain",
+                   {p:property_name});
+
+            assert(property_name in object,
+                   name, description,
+                   "property ${p} not found in prototype chain",
+                   {p:property_name});
+        };
+    }
+    expose(_assert_inherits("assert_inherits"), "assert_inherits");
+    expose(_assert_inherits("assert_idl_attribute"), "assert_idl_attribute");
+
+    function assert_readonly(object, property_name, description)
+    {
+         var initial_value = object[property_name];
+         try {
+             //Note that this can have side effects in the case where
+             //the property has PutForwards
+             object[property_name] = initial_value + "a"; //XXX use some other value here?
+             assert(object[property_name] === initial_value,
+                    "assert_readonly", description,
+                    "changing property ${p} succeeded",
+                    {p:property_name});
+         }
+         finally
+         {
+             object[property_name] = initial_value;
+         }
+    };
+    expose(assert_readonly, "assert_readonly");
+
+    function assert_throws(code, func, description)
+    {
+        try
+        {
+            func.call(this);
+            assert(false, "assert_throws", description,
+                   "${func} did not throw", {func:func});
+        }
+        catch(e)
+        {
+            if (e instanceof AssertionError) {
+                throw(e);
+            }
+            if (typeof code === "object")
+            {
+                assert(typeof e == "object" && "name" in e && e.name == code.name,
+                       "assert_throws", description,
+                       "${func} threw ${actual} (${actual_name}) expected ${expected} (${expected_name})",
+                                    {func:func, actual:e, actual_name:e.name,
+                                     expected:code,
+                                     expected_name:code.name});
+                return;
+            }
+            var required_props = {};
+            required_props.code = {
+                INDEX_SIZE_ERR: 1,
+                HIERARCHY_REQUEST_ERR: 3,
+                WRONG_DOCUMENT_ERR: 4,
+                INVALID_CHARACTER_ERR: 5,
+                NO_MODIFICATION_ALLOWED_ERR: 7,
+                NOT_FOUND_ERR: 8,
+                NOT_SUPPORTED_ERR: 9,
+                INVALID_STATE_ERR: 11,
+                SYNTAX_ERR: 12,
+                INVALID_MODIFICATION_ERR: 13,
+                NAMESPACE_ERR: 14,
+                INVALID_ACCESS_ERR: 15,
+                TYPE_MISMATCH_ERR: 17,
+                SECURITY_ERR: 18,
+                NETWORK_ERR: 19,
+                ABORT_ERR: 20,
+                URL_MISMATCH_ERR: 21,
+                QUOTA_EXCEEDED_ERR: 22,
+                TIMEOUT_ERR: 23,
+                INVALID_NODE_TYPE_ERR: 24,
+                DATA_CLONE_ERR: 25,
+            }[code];
+            if (required_props.code === undefined)
+            {
+                throw new AssertionError('Test bug: unrecognized DOMException code "' + code + '" passed to assert_throws()');
+            }
+            required_props[code] = required_props.code;
+            //Uncomment this when the latest version of every browser
+            //actually implements the spec; otherwise it just creates
+            //zillions of failures.  Also do required_props.type.
+            //required_props.name = code;
+            //
+            //We'd like to test that e instanceof the appropriate interface,
+            //but we can't, because we don't know what window it was created
+            //in.  It might be an instanceof the appropriate interface on some
+            //unknown other window.  TODO: Work around this somehow?
+
+            assert(typeof e == "object",
+                   "assert_throws", description,
+                   "${func} threw ${e} with type ${type}, not an object",
+                   {func:func, e:e, type:typeof e});
+
+            for (var prop in required_props)
+            {
+                assert(typeof e == "object" && prop in e && e[prop] == required_props[prop],
+                       "assert_throws", description,
+                       "${func} threw ${e} that is not a DOMException " + code + ": property ${prop} is equal to ${actual}, expected ${expected}",
+                       {func:func, e:e, prop:prop, actual:e[prop], expected:required_props[prop]});
+            }
+        }
+    }
+    expose(assert_throws, "assert_throws");
+
+    function assert_unreached(description) {
+         assert(false, "assert_unreached", description,
+                "Reached unreachable code");
+    }
+    expose(assert_unreached, "assert_unreached");
+
+    function Test(name, properties)
+    {
+        this.name = name;
+        this.status = this.NOTRUN;
+        this.timeout_id = null;
+        this.is_done = false;
+
+        this.timeout_length = properties.timeout ? properties.timeout : settings.test_timeout;
+
+        this.message = null;
+
+        var this_obj = this;
+        this.steps = [];
+
+        tests.push(this);
+    }
+
+    Test.prototype = {
+        PASS:0,
+        FAIL:1,
+        TIMEOUT:2,
+        NOTRUN:3
+    };
+
+
+    Test.prototype.step = function(func, this_obj)
+    {
+        //In case the test has already failed
+        if (this.status !== this.NOTRUN)
+        {
+          return;
+        }
+
+        tests.started = true;
+
+        if (this.timeout_id === null) {
+            this.set_timeout();
+        }
+
+        this.steps.push(func);
+
+        if (arguments.length === 1)
+        {
+            this_obj = this;
+        }
+
+        try
+        {
+            func.apply(this_obj, Array.prototype.slice.call(arguments, 2));
+        }
+        catch(e)
+        {
+            //This can happen if something called synchronously invoked another
+            //step
+            if (this.status !== this.NOTRUN)
+            {
+                return;
+            }
+            this.status = this.FAIL;
+            this.message = e.message;
+            if (typeof e.stack != "undefined" && typeof e.message == "string") {
+                //Try to make it more informative for some exceptions, at least
+                //in Gecko and WebKit.  This results in a stack dump instead of
+                //just errors like "Cannot read property 'parentNode' of null"
+                //or "root is null".  Makes it a lot longer, of course.
+                this.message += "(stack: " + e.stack + ")";
+            }
+            this.done();
+            if (debug && e.constructor !== AssertionError) {
+                throw e;
+            }
+        }
+    };
+
+    Test.prototype.step_func = function(func, this_obj)
+    {
+        var test_this = this;
+
+        if (arguments.length === 1)
+        {
+            this_obj = test_this;
+        }
+
+        return function()
+        {
+            test_this.step.apply(test_this, [func, this_obj].concat(
+                Array.prototype.slice.call(arguments)));
+        };
+    };
+
+    Test.prototype.set_timeout = function()
+    {
+        var this_obj = this;
+        this.timeout_id = setTimeout(function()
+                                     {
+                                         this_obj.timeout();
+                                     }, this.timeout_length);
+    };
+
+    Test.prototype.timeout = function()
+    {
+        this.status = this.TIMEOUT;
+        this.timeout_id = null;
+        this.message = "Test timed out";
+        this.done();
+    };
+
+    Test.prototype.done = function()
+    {
+        if (this.is_done) {
+            return;
+        }
+        clearTimeout(this.timeout_id);
+        if (this.status === this.NOTRUN)
+        {
+            this.status = this.PASS;
+        }
+        this.is_done = true;
+        tests.result(this);
+    };
+
+
+    /*
+     * Harness
+     */
+
+    function TestsStatus()
+    {
+        this.status = null;
+        this.message = null;
+    }
+    TestsStatus.prototype = {
+        OK:0,
+        ERROR:1,
+        TIMEOUT:2
+    };
+
+    function Tests()
+    {
+        this.tests = [];
+        this.num_pending = 0;
+
+        this.phases = {
+            INITIAL:0,
+            SETUP:1,
+            HAVE_TESTS:2,
+            HAVE_RESULTS:3,
+            COMPLETE:4
+        };
+        this.phase = this.phases.INITIAL;
+
+        //All tests can't be done until the load event fires
+        this.all_loaded = false;
+        this.wait_for_finish = false;
+        this.processing_callbacks = false;
+
+        this.timeout_length = settings.timeout;
+        this.timeout_id = null;
+        this.set_timeout();
+
+        this.start_callbacks = [];
+        this.test_done_callbacks = [];
+        this.all_done_callbacks = [];
+
+        this.status = new TestsStatus();
+
+        var this_obj = this;
+
+        on_event(window, "load",
+                 function()
+                 {
+                     this_obj.all_loaded = true;
+                     if (this_obj.all_done())
+                     {
+                         this_obj.complete();
+                     }
+                 });
+        this.properties = {};
+    }
+
+    Tests.prototype.setup = function(func, properties)
+    {
+        if (this.phase >= this.phases.HAVE_RESULTS)
+        {
+            return;
+        }
+        if (this.phase < this.phases.SETUP)
+        {
+            this.phase = this.phases.SETUP;
+        }
+
+        for (var p in properties)
+        {
+            if (properties.hasOwnProperty(p))
+            {
+                this.properties[p] = properties[p];
+            }
+        }
+
+        if (properties.timeout)
+        {
+            this.timeout_length = properties.timeout;
+            this.set_timeout();
+        }
+        if (properties.explicit_done)
+        {
+            this.wait_for_finish = true;
+        }
+
+        if (func)
+        {
+            try
+            {
+                func();
+            } catch(e)
+            {
+                this.status.status = this.status.ERROR;
+                this.status.message = e;
+            };
+        }
+    };
+
+    Tests.prototype.set_timeout = function()
+    {
+        var this_obj = this;
+        clearTimeout(this.timeout_id);
+        this.timeout_id = setTimeout(function() {
+                                         this_obj.timeout();
+                                     }, this.timeout_length);
+    };
+
+    Tests.prototype.timeout = function() {
+        this.status.status = this.status.TIMEOUT;
+        this.complete();
+    };
+
+    Tests.prototype.end_wait = function()
+    {
+        this.wait_for_finish = false;
+        if (this.all_done()) {
+            this.complete();
+        }
+    };
+
+    Tests.prototype.push = function(test)
+    {
+        if (this.phase < this.phases.HAVE_TESTS) {
+            this.notify_start();
+        }
+        this.num_pending++;
+        this.tests.push(test);
+    };
+
+    Tests.prototype.all_done = function() {
+        return (this.all_loaded && this.num_pending === 0 &&
+                !this.wait_for_finish && !this.processing_callbacks);
+    };
+
+    Tests.prototype.start = function() {
+        this.phase = this.phases.HAVE_TESTS;
+        this.notify_start();
+    };
+
+    Tests.prototype.notify_start = function() {
+        var this_obj = this;
+        forEach (this.start_callbacks,
+                 function(callback)
+                 {
+                     callback(this_obj.properties);
+                 });
+        forEach(ancestor_windows(),
+                function(w)
+                {
+                    if(w.start_callback)
+                    {
+                        try
+                        {
+                            w.start_callback(this_obj.properties);
+                        }
+                        catch(e)
+                        {
+                            if (debug)
+                            {
+                                throw(e);
+                            }
+                        }
+                    }
+                });
+    };
+
+    Tests.prototype.result = function(test)
+    {
+        if (this.phase > this.phases.HAVE_RESULTS)
+        {
+            return;
+        }
+        this.phase = this.phases.HAVE_RESULTS;
+        this.num_pending--;
+        this.notify_result(test);
+    };
+
+    Tests.prototype.notify_result = function(test) {
+        var this_obj = this;
+        this.processing_callbacks = true;
+        forEach(this.test_done_callbacks,
+                function(callback)
+                {
+                    callback(test, this_obj);
+                });
+
+        forEach(ancestor_windows(),
+                function(w)
+                {
+                    if(w.result_callback)
+                    {
+                        try
+                        {
+                            w.result_callback(test);
+                        }
+                        catch(e)
+                        {
+                            if(debug) {
+                                throw e;
+                            }
+                        }
+                    }
+                });
+        this.processing_callbacks = false;
+        if (this_obj.all_done())
+        {
+            this_obj.complete();
+        }
+    };
+
+    Tests.prototype.complete = function() {
+        if (this.phase === this.phases.COMPLETE) {
+            return;
+        }
+        this.phase = this.phases.COMPLETE;
+        this.notify_complete();
+    };
+
+    Tests.prototype.notify_complete = function()
+    {
+        clearTimeout(this.timeout_id);
+        var this_obj = this;
+        if (this.status.status === null)
+        {
+            this.status.status = this.status.OK;
+        }
+
+        forEach (this.all_done_callbacks,
+                 function(callback)
+                 {
+                     callback(this_obj.tests, this_obj.status);
+                 });
+
+        forEach(ancestor_windows(),
+                function(w)
+                {
+                    if(w.completion_callback)
+                    {
+                        try
+                        {
+                            w.completion_callback(this_obj.tests, this_obj.status);
+                        }
+                        catch(e)
+                        {
+                            if (debug)
+                            {
+                                throw e;
+                            }
+                        }
+                    }
+                });
+    };
+
+    var tests = new Tests();
+
+    function add_start_callback(callback) {
+        tests.start_callbacks.push(callback);
+    }
+
+    function add_result_callback(callback)
+    {
+        tests.test_done_callbacks.push(callback);
+    }
+
+    function add_completion_callback(callback)
+    {
+       tests.all_done_callbacks.push(callback);
+    }
+
+    expose(add_start_callback, 'add_start_callback');
+    expose(add_result_callback, 'add_result_callback');
+    expose(add_completion_callback, 'add_completion_callback');
+
+    /*
+     * Output listener
+    */
+
+    function Output() {
+      this.output_document = null;
+      this.output_node = null;
+      this.done_count = 0;
+      this.enabled = settings.output;
+      this.phase = this.INITIAL;
+    }
+
+    Output.prototype.INITIAL = 0;
+    Output.prototype.STARTED = 1;
+    Output.prototype.HAVE_RESULTS = 2;
+    Output.prototype.COMPLETE = 3;
+
+    Output.prototype.setup = function(properties) {
+        if (this.phase > this.INITIAL) {
+            return;
+        }
+
+        //If output is disabled in testharnessreport.js the test shouldn't be
+        //able to override that
+        this.enabled = this.enabled && (properties.hasOwnProperty("output") ?
+                                        properties.output : settings.output);
+    };
+
+    Output.prototype.init = function(properties)
+    {
+        if (this.phase >= this.STARTED) {
+            return;
+        }
+        if (properties.output_document) {
+            this.output_document = properties.output_document;
+        } else {
+            this.output_document = document;
+        }
+        this.phase = this.STARTED;
+    };
+
+    Output.prototype.resolve_log = function()
+    {
+        if (!this.output_document) {
+            return;
+        }
+        var node = this.output_document.getElementById("log");
+        if (node) {
+            this.output_node = node;
+        }
+    };
+
+    Output.prototype.show_status = function(test)
+    {
+        if (this.phase < this.STARTED)
+        {
+            this.init();
+        }
+        if (!this.enabled)
+        {
+            return;
+        }
+        if (this.phase < this.HAVE_RESULTS)
+        {
+            this.resolve_log();
+            this.phase = this.HAVE_RESULTS;
+        }
+        this.done_count++;
+        if (this.output_node)
+        {
+            if (this.done_count < 100
+            || (this.done_count < 1000 && this.done_count % 100 == 0)
+            || this.done_count % 1000 == 0) {
+                this.output_node.textContent = "Running, "
+                    + this.done_count + " complete, "
+                    + tests.num_pending + " remain";
+            }
+        }
+    };
+
+    Output.prototype.show_results = function (tests, harness_status)
+    {
+        if (this.phase >= this.COMPLETE) {
+            return;
+        }
+        if (!this.enabled)
+        {
+            return;
+        }
+        if (!this.output_node) {
+            this.resolve_log();
+        }
+        this.phase = this.COMPLETE;
+
+        var log = this.output_node;
+        if (!log)
+        {
+            return;
+        }
+        var output_document = this.output_document;
+
+        while (log.lastChild)
+        {
+            log.removeChild(log.lastChild);
+        }
+
+        if (script_prefix != null) {
+            var stylesheet = output_document.createElementNS(xhtml_ns, "link");
+            stylesheet.setAttribute("rel", "stylesheet");
+            stylesheet.setAttribute("href", script_prefix + "testharness.css");
+            var heads = output_document.getElementsByTagName("head");
+            if (heads.length) {
+                heads[0].appendChild(stylesheet);
+            }
+        }
+
+        var status_text = {};
+        status_text[Test.prototype.PASS] = "Pass";
+        status_text[Test.prototype.FAIL] = "Fail";
+        status_text[Test.prototype.TIMEOUT] = "Timeout";
+        status_text[Test.prototype.NOTRUN] = "Not Run";
+
+        var status_number = {};
+        forEach(tests, function(test) {
+                    var status = status_text[test.status];
+                    if (status_number.hasOwnProperty(status))
+                    {
+                        status_number[status] += 1;
+                    } else {
+                        status_number[status] = 1;
+                    }
+                });
+
+        function status_class(status)
+        {
+            return status.replace(/\s/g, '').toLowerCase();
+        }
+
+        var summary_template = ["section", {"id":"summary"},
+                                ["h2", {}, "Summary"],
+                                ["p", {}, "Found ${num_tests} tests"],
+                                function(vars) {
+                                    var rv = [["div", {}]];
+                                    var i=0;
+                                    while (status_text.hasOwnProperty(i)) {
+                                        if (status_number.hasOwnProperty(status_text[i])) {
+                                            var status = status_text[i];
+                                            rv[0].push(["div", {"class":status_class(status)},
+                                                        ["label", {},
+                                                         ["input", {type:"checkbox", checked:"checked"}],
+                                                         status_number[status] + " " + status]]);
+                                        }
+                                        i++;
+                                    }
+                                    return rv;
+                                }];
+
+        log.appendChild(render(summary_template, {num_tests:tests.length}, output_document));
+
+        forEach(output_document.querySelectorAll("section#summary label"),
+                function(element)
+                {
+                    on_event(element, "click",
+                             function(e)
+                             {
+                                 if (output_document.getElementById("results") === null)
+                                 {
+                                     e.preventDefault();
+                                     return;
+                                 }
+                                 var result_class = element.parentNode.getAttribute("class");
+                                 var style_element = output_document.querySelector("style#hide-" + result_class);
+                                 var input_element = element.querySelector("input");
+                                 if (!style_element && !input_element.checked) {
+                                     style_element = output_document.createElementNS(xhtml_ns, "style");
+                                     style_element.id = "hide-" + result_class;
+                                     style_element.innerHTML = "table#results > tbody > tr."+result_class+"{display:none}";
+                                     output_document.body.appendChild(style_element);
+                                 } else if (style_element && input_element.checked) {
+                                     style_element.parentNode.removeChild(style_element);
+                                 }
+                             });
+                });
+
+        // This use of innerHTML plus manual escaping is not recommended in
+        // general, but is necessary here for performance.  Using textContent
+        // on each individual <td> adds tens of seconds of execution time for
+        // large test suites (tens of thousands of tests).
+        function escape_html(s)
+        {
+            return s.replace(/\&/g, "&amp;")
+                .replace(/</g, "&lt;")
+                .replace(/"/g, "&quot;")
+                .replace(/'/g, "&#39;");
+        }
+
+        log.appendChild(document.createElement("section"));
+        var html = "<h2>Details</h2><table id='results'>"
+            + "<thead><tr><th>Result</th><th>Test Name</th><th>Message</th></tr></thead>"
+            + "<tbody>";
+        for (var i = 0; i < tests.length; i++) {
+            html += '<tr class="'
+                + escape_html(status_class(status_text[tests[i].status]))
+                + '"><td>'
+                + escape_html(status_text[tests[i].status])
+                + "</td><td>"
+                + escape_html(tests[i].name)
+                + "</td><td>"
+                + escape_html(tests[i].message ? tests[i].message : " ")
+                + "</td></tr>";
+        }
+        log.lastChild.innerHTML = html + "</tbody></table>";
+    };
+
+    var output = new Output();
+    add_start_callback(function (properties) {output.init(properties);});
+    add_result_callback(function (test) {output.show_status(tests);});
+    add_completion_callback(function (tests, harness_status) {output.show_results(tests, harness_status);});
+
+    /*
+     * Template code
+     *
+     * A template is just a javascript structure. An element is represented as:
+     *
+     * [tag_name, {attr_name:attr_value}, child1, child2]
+     *
+     * the children can either be strings (which act like text nodes), other templates or
+     * functions (see below)
+     *
+     * A text node is represented as
+     *
+     * ["{text}", value]
+     *
+     * String values have a simple substitution syntax; ${foo} represents a variable foo.
+     *
+     * It is possible to embed logic in templates by using a function in a place where a
+     * node would usually go. The function must either return part of a template or null.
+     *
+     * In cases where a set of nodes are required as output rather than a single node
+     * with children it is possible to just use a list
+     * [node1, node2, node3]
+     *
+     * Usage:
+     *
+     * render(template, substitutions) - take a template and an object mapping
+     * variable names to parameters and return either a DOM node or a list of DOM nodes
+     *
+     * substitute(template, substitutions) - take a template and variable mapping object,
+     * make the variable substitutions and return the substituted template
+     *
+     */
+
+    function is_single_node(template)
+    {
+        return typeof template[0] === "string";
+    }
+
+    function substitute(template, substitutions)
+    {
+        if (typeof template === "function") {
+            var replacement = template(substitutions);
+            if (replacement)
+            {
+                var rv = substitute(replacement, substitutions);
+                return rv;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        else if (is_single_node(template))
+        {
+            return substitute_single(template, substitutions);
+        }
+        else
+        {
+            return filter(map(template, function(x) {
+                                  return substitute(x, substitutions);
+                              }), function(x) {return x !== null;});
+        }
+    }
+
+    function substitute_single(template, substitutions)
+    {
+        var substitution_re = /\${([^ }]*)}/g;
+
+        function do_substitution(input) {
+            var components = input.split(substitution_re);
+            var rv = [];
+            for (var i=0; i<components.length; i+=2)
+            {
+                rv.push(components[i]);
+                if (components[i+1])
+                {
+                    rv.push(String(substitutions[components[i+1]]));
+                }
+            }
+            return rv;
+        }
+
+        var rv = [];
+        rv.push(do_substitution(String(template[0])).join(""));
+
+        if (template[0] === "{text}") {
+            substitute_children(template.slice(1), rv);
+        } else {
+            substitute_attrs(template[1], rv);
+            substitute_children(template.slice(2), rv);
+        }
+
+        function substitute_attrs(attrs, rv)
+        {
+            rv[1] = {};
+            for (var name in template[1])
+            {
+                if (attrs.hasOwnProperty(name))
+                {
+                    var new_name = do_substitution(name).join("");
+                    var new_value = do_substitution(attrs[name]).join("");
+                    rv[1][new_name] = new_value;
+                };
+            }
+        }
+
+        function substitute_children(children, rv)
+        {
+            for (var i=0; i<children.length; i++)
+            {
+                if (children[i] instanceof Object) {
+                    var replacement = substitute(children[i], substitutions);
+                    if (replacement !== null)
+                    {
+                        if (is_single_node(replacement))
+                        {
+                            rv.push(replacement);
+                        }
+                        else
+                        {
+                            extend(rv, replacement);
+                        }
+                    }
+                }
+                else
+                {
+                    extend(rv, do_substitution(String(children[i])));
+                }
+            }
+            return rv;
+        }
+
+        return rv;
+    }
+
+ function make_dom_single(template, doc)
+ {
+     var output_document = doc || document;
+     if (template[0] === "{text}")
+     {
+         var element = output_document.createTextNode("");
+         for (var i=1; i<template.length; i++)
+         {
+             element.data += template[i];
+         }
+     }
+     else
+     {
+         var element = output_document.createElementNS(xhtml_ns, template[0]);
+         for (var name in template[1]) {
+             if (template[1].hasOwnProperty(name))
+             {
+                 element.setAttribute(name, template[1][name]);
+             }
+         }
+         for (var i=2; i<template.length; i++)
+         {
+             if (template[i] instanceof Object)
+             {
+                 var sub_element = make_dom(template[i]);
+                 element.appendChild(sub_element);
+             }
+             else
+             {
+                 var text_node = output_document.createTextNode(template[i]);
+                 element.appendChild(text_node);
+             }
+         }
+     }
+
+     return element;
+ }
+
+
+
+ function make_dom(template, substitutions, output_document)
+    {
+        if (is_single_node(template))
+        {
+            return make_dom_single(template, output_document);
+        }
+        else
+        {
+            return map(template, function(x) {
+                           return make_dom_single(x, output_document);
+                       });
+        }
+    }
+
+ function render(template, substitutions, output_document)
+    {
+        return make_dom(substitute(template, substitutions), output_document);
+    }
+
+    /*
+     * Utility funcions
+     */
+    function assert(expected_true, function_name, description, error, substitutions)
+    {
+        if (expected_true !== true)
+        {
+            throw new AssertionError(make_message(function_name, description,
+                                                  error, substitutions));
+        }
+    }
+
+    function AssertionError(message)
+    {
+        this.message = message;
+    }
+
+    function make_message(function_name, description, error, substitutions)
+    {
+        for (var p in substitutions) {
+            if (substitutions.hasOwnProperty(p)) {
+                substitutions[p] = format_value(substitutions[p]);
+            }
+        }
+        var node_form = substitute(["{text}", "${function_name}: ${description}" + error],
+                                   merge({function_name:function_name,
+                                          description:(description?description + " ":"")},
+                                          substitutions));
+        return node_form.slice(1).join("");
+    }
+
+    function filter(array, callable, thisObj) {
+        var rv = [];
+        for (var i=0; i<array.length; i++)
+        {
+            if (array.hasOwnProperty(i))
+            {
+                var pass = callable.call(thisObj, array[i], i, array);
+                if (pass) {
+                    rv.push(array[i]);
+                }
+            }
+        }
+        return rv;
+    }
+
+    function map(array, callable, thisObj)
+    {
+        var rv = [];
+        rv.length = array.length;
+        for (var i=0; i<array.length; i++)
+        {
+            if (array.hasOwnProperty(i))
+            {
+                rv[i] = callable.call(thisObj, array[i], i, array);
+            }
+        }
+        return rv;
+    }
+
+    function extend(array, items)
+    {
+        Array.prototype.push.apply(array, items);
+    }
+
+    function forEach (array, callback, thisObj)
+    {
+        for (var i=0; i<array.length; i++)
+        {
+            if (array.hasOwnProperty(i))
+            {
+                callback.call(thisObj, array[i], i, array);
+            }
+        }
+    }
+
+    function merge(a,b)
+    {
+        var rv = {};
+        var p;
+        for (p in a)
+        {
+            rv[p] = a[p];
+        }
+        for (p in b) {
+            rv[p] = b[p];
+        }
+        return rv;
+    }
+
+    function expose(object, name)
+    {
+        var components = name.split(".");
+        var target = window;
+        for (var i=0; i<components.length - 1; i++)
+        {
+            if (!(components[i] in target))
+            {
+                target[components[i]] = {};
+            }
+            target = target[components[i]];
+        }
+        target[components[components.length - 1]] = object;
+    }
+
+ function ancestor_windows() {
+     //Get the windows [self ... top] as an array
+     if ("result_cache" in ancestor_windows)
+     {
+         return ancestor_windows.result_cache;
+     }
+     var rv = [self];
+     var w = self;
+     while (w != w.parent)
+     {
+         w = w.parent;
+         rv.push(w);
+     }
+     ancestor_windows.result_cache = rv;
+     return rv;
+ }
+
+})();
+// vim: set expandtab shiftwidth=4 tabstop=4:
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/w3c/testharnessreport.js.in
@@ -0,0 +1,120 @@
+/* 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/. */
+
+var W3CTest = {
+  /**
+   * Dictionary mapping a test URL to either the string "all", which means that
+   * all tests in this file are expected to fail, or a dictionary mapping test
+   * names to either the boolean |true|, or the string "debug". The former
+   * means that this test is expected to fail in all builds, and the latter
+   * that it is only expected to fail in debug builds.
+   *
+   * This is filled in by the writeReporter.py script.
+   */
+  "expectedFailures": ${expectations},
+
+  /**
+   * List of test results, needed by TestRunner to update the UI.
+   */
+  "tests": [],
+
+  /**
+   * Reference to the TestRunner object in the parent frame.
+   */
+  "runner": parent === this ? null : parent.TestRunner || parent.wrappedJSObject.TestRunner,
+
+  /**
+   * Prefixes for the error logging. Indexed first by int(todo) and second by
+   * int(result).
+   */
+  "prefixes": [
+    ["TEST-UNEXPECTED-FAIL", "TEST-PASS"],
+    ["TEST-KNOWN-FAIL", "TEST-UNEXPECTED-PASS"]
+  ],
+
+  /**
+   * Returns the URL of the current test, relative to the root W3C tests
+   * directory. Used as a key into the expectedFailures dictionary.
+   */
+  "getURL": function() {
+    return this.runner.currentTestURL.substring("/tests/dom/tests/mochitest/w3c/".length);
+  },
+
+  /**
+   * Lets the test runner know about a test result.
+   */
+  "_log": function(test) {
+    var msg = this.prefixes[+test.todo][+test.result] + " | ";
+    if (this.runner.currentTestURL)
+      msg += this.runner.currentTestURL;
+    msg += " | " + test.message;
+    this.runner[(test.result === !test.todo) ? "log" : "error"](msg);
+  },
+
+  /**
+   * Reports a test result. The argument is an object with the following
+   * properties:
+   *
+   * o message (string): message to be reported
+   * o result (boolean): whether this test failed
+   * o todo (boolean): whether this test is expected to fail
+   */
+  "report": function(test) {
+    this.tests.push(test);
+    this._log(test);
+  },
+
+  /**
+   * Returns true if this test is expected to fail, and false otherwise.
+   */
+  "_todo": function(url, test) {
+    if (!(url in this.expectedFailures)) {
+      return false;
+    }
+    if (this.expectedFailures[url] === "all") {
+      return true;
+    }
+    var value = this.expectedFailures[url][test.name];
+    return value === true || (value === "debug" && !!SpecialPowers.isDebugBuild);
+  },
+
+  /**
+   * Callback function for testharness.js. Called when one test in a file
+   * finishes.
+   */
+  "result": function(test) {
+    var url = this.getURL();
+    this.report({
+      "message": test.message || test.name,
+      "result": test.status === test.PASS,
+      "todo": this._todo(url, test)
+    });
+  },
+
+  /**
+   * Callback function for testharness.js. Called when the entire test file
+   * finishes.
+   */
+  "finish": function(tests, status) {
+    var url = this.getURL();
+    this.report({
+      "message": "Finished test",
+      "result": status.status === status.OK,
+      "todo":
+        url in this.expectedFailures &&
+        this.expectedFailures[url] === "error"
+    });
+    this.runner.testFinished(this.tests);
+  }
+};
+(function() {
+  if (!W3CTest.runner) {
+    return;
+  }
+  add_result_callback(W3CTest.result.bind(W3CTest));
+  add_completion_callback(W3CTest.finish.bind(W3CTest));
+  setup({
+    "output": false
+  });
+})();
new file mode 100755
--- /dev/null
+++ b/dom/tests/mochitest/w3c/updateTestharness.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+# 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/.
+
+import subprocess
+
+repo = "https://dvcs.w3.org/hg/resources"
+dest = "resources-upstream"
+files = ["testharness.js", "testharness.css", "idlharness.js", "WebIDLParser.js"]
+
+subprocess.check_call(["hg", "clone", repo, dest])
+for f in files:
+  subprocess.check_call(["cp", "%s/%s" % (dest, f), f])
+  subprocess.check_call(["hg", "add", f])
+subprocess.check_call(["rm", "--recursive", "--force", dest])
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/w3c/writeReporter.py
@@ -0,0 +1,36 @@
+# 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/.
+
+import os
+import sys
+import string
+
+try:
+  import json
+except ImportError:
+  import simplejson as json
+
+def writeReporter(src):
+  src = src.replace("testharnessreport.js.in", "")
+  expectations = {}
+  fp = open(src + "failures.txt", "rb")
+  for line in fp:
+    gp = open(src + line.strip() + ".json")
+    expectations.update(json.load(gp))
+    gp.close()
+  fp.close()
+  fp = open(src + "testharnessreport.js.in", "rb")
+  template = fp.read()
+  fp.close()
+  fp = open("testharnessreport.js", "wb")
+  expjson = json.dumps(expectations,
+                       indent = 2,
+                       sort_keys = True,
+                       separators = (',', ': '))
+  result = string.Template(template).substitute({ 'expectations': expjson })
+  fp.write(result)
+  fp.close()
+
+if __name__ == "__main__":
+  writeReporter(sys.argv[1])
--- a/testing/mochitest/tests/SimpleTest/TestRunner.js
+++ b/testing/mochitest/tests/SimpleTest/TestRunner.js
@@ -84,35 +84,54 @@ TestRunner._expectingProcessCrash = fals
 /**
  * Make sure the tests don't hang indefinitely.
 **/
 TestRunner._numTimeouts = 0;
 TestRunner._currentTestStartTime = new Date().valueOf();
 TestRunner._timeoutFactor = 1;
 
 TestRunner._checkForHangs = function() {
+  function reportError(win, msg) {
+    if ("SimpleTest" in win) {
+      win.SimpleTest.ok(false, "Test timed out.");
+    } else if ("W3CTest" in win) {
+      win.W3CTest.report({
+        "message": msg,
+        "result": false,
+        "todo": false
+      });
+    }
+  }
+  function killTest(win) {
+    if ("SimpleTest" in win) {
+      win.SimpleTest.finish();
+    } else if ("W3CTest" in win) {
+      win.W3CTest.kill();
+    }
+  }
+
   if (TestRunner._currentTest < TestRunner._urls.length) {
     var runtime = new Date().valueOf() - TestRunner._currentTestStartTime;
     if (runtime >= TestRunner.timeout * TestRunner._timeoutFactor) {
       var frameWindow = $('testframe').contentWindow.wrappedJSObject ||
                           $('testframe').contentWindow;
-      frameWindow.SimpleTest.ok(false, "Test timed out.");
+      reportError(frameWindow, "Test timed out.");
 
       // If we have too many timeouts, give up. We don't want to wait hours
       // for results if some bug causes lots of tests to time out.
       if (++TestRunner._numTimeouts >= TestRunner.maxTimeouts) {
         TestRunner._haltTests = true;
 
         TestRunner.currentTestURL = "(SimpleTest/TestRunner.js)";
-        frameWindow.SimpleTest.ok(false, TestRunner.maxTimeouts + " test timeouts, giving up.");
+        reportError(frameWindow, TestRunner.maxTimeouts + " test timeouts, giving up.");
         var skippedTests = TestRunner._urls.length - TestRunner._currentTest;
-        frameWindow.SimpleTest.ok(false, "Skipping " + skippedTests + " remaining tests.");
+        reportError(frameWindow, "Skipping " + skippedTests + " remaining tests.");
       }
 
-      frameWindow.SimpleTest.finish();
+      killTest(frameWindow);
 
       if (TestRunner._haltTests)
         return;
     }
 
     setTimeout(TestRunner._checkForHangs, 30000);
   }
 }
--- a/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
+++ b/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
@@ -1065,9 +1065,15 @@ SpecialPowersAPI.prototype = {
     return ((typeof(id) == "string") ?
         aWindow.document.getElementById(id) : id); 
   },
   
   dispatchEvent: function(aWindow, target, event) {
     var el = this._getElement(aWindow, target);
     return el.dispatchEvent(event);
   },
+
+  get isDebugBuild() {
+    delete this.isDebugBuild;
+    var debug = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
+    return this.isDebugBuild = debug.isDebugBuild;
+  }
 };