Skip to content

Commit

Permalink
[idlharness.js] Handle callbacks in very basic manner (#18085)
Browse files Browse the repository at this point in the history
* Handle callbacks in very basic manner

* Drop todo, keep new Document()
  • Loading branch information
lukebjerring authored Jul 25, 2019
1 parent f1e6032 commit 53f176d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 9 additions & 1 deletion html/dom/interfaces.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ <h1>HTML IDL tests</h1>
['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'],
Expand All @@ -48,7 +56,7 @@ <h1>HTML IDL tests</h1>
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
Expand Down
27 changes: 24 additions & 3 deletions resources/idlharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ IdlArray.prototype.internal_add_idls = function(parsed_idls, options)
break;

case "callback":
// TODO
console.log("callback not yet supported");
this.members[parsed_idl.name] = new IdlCallback(parsed_idl);
break;

case "enum":
Expand Down Expand Up @@ -1163,9 +1162,13 @@ IdlArray.prototype.assert_type_is = function(value, type)
{
// 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");
}
};

Expand Down Expand Up @@ -3096,6 +3099,24 @@ function IdlEnum(obj)

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)
Expand Down

0 comments on commit 53f176d

Please sign in to comment.