Test IDLs defined in WebIDL using idlharness (#6875)
diff --git a/WebIDL/interfaces.html b/WebIDL/interfaces.html
new file mode 100644
index 0000000..c3e6695
--- /dev/null
+++ b/WebIDL/interfaces.html
@@ -0,0 +1,28 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>WebIDL IDL tests</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=/resources/WebIDLParser.js></script>
+<script src=/resources/idlharness.js></script>
+
+<div id=log></div>
+<script>
+"use strict";
+var idlArray = new IdlArray();
+
+function doTest(idl) {
+ idlArray.add_idls(idl);
+ idlArray.add_objects({
+ DOMException: ['new DOMException()',
+ 'new DOMException("my message")',
+ 'new DOMException("my message", "myName")'],
+ });
+ idlArray.test();
+}
+
+promise_test(function() {
+ return fetch("/interfaces/webidl.idl").then(response => response.text())
+ .then(doTest);
+}, "Test driver");
+</script>
diff --git a/interfaces/webidl.idl b/interfaces/webidl.idl
new file mode 100644
index 0000000..8eb1d06
--- /dev/null
+++ b/interfaces/webidl.idl
@@ -0,0 +1,44 @@
+typedef (Int8Array or Int16Array or Int32Array or
+ Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or
+ Float32Array or Float64Array or DataView) ArrayBufferView;
+
+typedef (ArrayBufferView or ArrayBuffer) BufferSource;
+
+[
+ Exposed=(Window,Worker),
+ Constructor(optional DOMString message = "", optional DOMString name = "Error")]
+interface DOMException { // but see below note about ECMAScript binding
+ readonly attribute DOMString name;
+ readonly attribute DOMString message;
+ readonly attribute unsigned short code;
+
+ const unsigned short INDEX_SIZE_ERR = 1;
+ const unsigned short DOMSTRING_SIZE_ERR = 2;
+ const unsigned short HIERARCHY_REQUEST_ERR = 3;
+ const unsigned short WRONG_DOCUMENT_ERR = 4;
+ const unsigned short INVALID_CHARACTER_ERR = 5;
+ const unsigned short NO_DATA_ALLOWED_ERR = 6;
+ const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7;
+ const unsigned short NOT_FOUND_ERR = 8;
+ const unsigned short NOT_SUPPORTED_ERR = 9;
+ const unsigned short INUSE_ATTRIBUTE_ERR = 10;
+ const unsigned short INVALID_STATE_ERR = 11;
+ const unsigned short SYNTAX_ERR = 12;
+ const unsigned short INVALID_MODIFICATION_ERR = 13;
+ const unsigned short NAMESPACE_ERR = 14;
+ const unsigned short INVALID_ACCESS_ERR = 15;
+ const unsigned short VALIDATION_ERR = 16;
+ const unsigned short TYPE_MISMATCH_ERR = 17;
+ const unsigned short SECURITY_ERR = 18;
+ const unsigned short NETWORK_ERR = 19;
+ const unsigned short ABORT_ERR = 20;
+ const unsigned short URL_MISMATCH_ERR = 21;
+ const unsigned short QUOTA_EXCEEDED_ERR = 22;
+ const unsigned short TIMEOUT_ERR = 23;
+ const unsigned short INVALID_NODE_TYPE_ERR = 24;
+ const unsigned short DATA_CLONE_ERR = 25;
+};
+
+typedef unsigned long long DOMTimeStamp;
+callback Function = any (any... arguments);
+callback VoidFunction = void ();
diff --git a/resources/idlharness.js b/resources/idlharness.js
index dc3302f..5ba6989 100644
--- a/resources/idlharness.js
+++ b/resources/idlharness.js
@@ -1324,6 +1324,14 @@
// "Otherwise, if A is declared with the [LegacyArrayClass] extended
// attribute, then return %ArrayPrototype%.
// "Otherwise, return %ObjectPrototype%.
+ //
+ // "In the ECMAScript binding, the DOMException type has some additional
+ // requirements:
+ //
+ // "Unlike normal interface types, the interface prototype object
+ // for DOMException must have as its [[Prototype]] the intrinsic
+ // object %ErrorPrototype%."
+ //
if (this.name === "Window") {
assert_class_string(Object.getPrototypeOf(self[this.name].prototype),
'WindowProperties',
@@ -1340,6 +1348,9 @@
} else if (this.has_extended_attribute('LegacyArrayClass')) {
inherit_interface = 'Array';
inherit_interface_has_interface_object = true;
+ } else if (this.name === "DOMException") {
+ inherit_interface = 'Error';
+ inherit_interface_has_interface_object = true;
} else {
inherit_interface = 'Object';
inherit_interface_has_interface_object = true;
@@ -2277,6 +2288,11 @@
IdlInterface.prototype.has_stringifier = function()
//@{
{
+ if (this.name === "DOMException") {
+ // toString is inherited from Error, so don't assume we have the
+ // default stringifer
+ return true;
+ }
if (this.members.some(function(member) { return member.stringifier; })) {
return true;
}