[idlharness.js] Handle callbacks in very basic manner (#18085)

* Handle callbacks in very basic manner

* Drop todo, keep new Document()
diff --git a/html/dom/interfaces.https.html b/html/dom/interfaces.https.html
index 6ca7721..433d802 100644
--- a/html/dom/interfaces.https.html
+++ b/html/dom/interfaces.https.html
@@ -40,6 +40,14 @@
   ['html'],
   ['SVG', 'cssom', 'touch-events', 'uievents', 'dom', 'xhr'],
   async idlArray => {
+    self.documentWithHandlers = new Document();
+    const handler = function(e) {};
+    for (const callback of idlArray.members['GlobalEventHandlers'].members) {
+      if (callback.idlType && callback.idlType.idlType === 'EventHandler') {
+        documentWithHandlers[callback.name] = handler;
+      }
+    }
+
     idlArray.add_objects({
       NodeList: ['document.getElementsByName("name")'],
       HTMLAllCollection: ['document.all'],
@@ -48,7 +56,7 @@
       HTMLOptionsCollection: ['document.createElement("select").options'],
       DOMStringMap: ['document.head.dataset'],
       Transferable: [],
-      Document: ['iframe.contentDocument', 'new Document()'],
+      Document: ['iframe.contentDocument', 'new Document()', 'documentWithHandlers'],
       XMLDocument: ['document.implementation.createDocument(null, "", null)'],
       HTMLElement: ['document.createElement("noscript")'], // more tests in html/semantics/interfaces.js
       HTMLUnknownElement: ['document.createElement("bgsound")'], // more tests in html/semantics/interfaces.js
diff --git a/resources/idlharness.js b/resources/idlharness.js
index 9be554d..056540a 100644
--- a/resources/idlharness.js
+++ b/resources/idlharness.js
@@ -488,8 +488,7 @@
             break;
 
         case "callback":
-            // TODO
-            console.log("callback not yet supported");
+            this.members[parsed_idl.name] = new IdlCallback(parsed_idl);
             break;
 
         case "enum":
@@ -1163,9 +1162,13 @@
     {
         // TODO: Test when we actually have something to test this on
     }
+    else if (this.members[type] instanceof IdlCallback)
+    {
+        assert_equals(typeof value, "function");
+    }
     else
     {
-        throw new IdlHarnessError("Type " + type + " isn't an interface or dictionary");
+        throw new IdlHarnessError("Type " + type + " isn't an interface, callback or dictionary");
     }
 };
 
@@ -3096,6 +3099,24 @@
 
 IdlEnum.prototype = Object.create(IdlObject.prototype);
 
+/// IdlCallback ///
+// Used for IdlArray.prototype.assert_type_is
+function IdlCallback(obj)
+{
+    /**
+     * obj is an object produced by the WebIDLParser.js "callback"
+     * production.
+     */
+
+    /** Self-explanatory. */
+    this.name = obj.name;
+
+    /** Arguments for the callback. */
+    this.arguments = obj.arguments;
+}
+
+IdlCallback.prototype = Object.create(IdlObject.prototype);
+
 /// IdlTypedef ///
 // Used for IdlArray.prototype.assert_type_is
 function IdlTypedef(obj)