mirror of
https://github.com/radareorg/quickjs.git
synced 2026-11-07 06:25:57 -10:00
Implemented separately from the other errors because it is defined in terms of WebIDL, where members of an interface are getters on their prototype. See the difference between `JSON.stringify(Object.getOwnPropertyDescriptors(new TypeError()))` vs `JSON.stringify(Object.getOwnPropertyDescriptors(new DOMException()))`. Note: the standard doesn't specify where to put "stack". We follow existing practice which imitates node instead of browsers.
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import { assert, assertThrows } from "./assert.js";
|
|
|
|
function test_code() {
|
|
let ex = new DOMException();
|
|
assert(ex.code, 0);
|
|
ex = new DOMException("", "HierarchyRequestError\0test");
|
|
assert(ex.code, 0);
|
|
ex = new DOMException("test", "HierarchyRequestError");
|
|
assert(ex.code, 3);
|
|
assert(ex.code, ex.HIERARCHY_REQUEST_ERR);
|
|
assert(ex.code, DOMException.HIERARCHY_REQUEST_ERR);
|
|
ex = new DOMException("", "DataCloneError");
|
|
assert(ex.code, ex.DATA_CLONE_ERR);
|
|
assert(ex.code, 25);
|
|
ex = new DOMException("", "IndexSizeError");
|
|
assert(ex.code, ex.INDEX_SIZE_ERR);
|
|
assert(ex.code, 1);
|
|
}
|
|
|
|
function test_properties() {
|
|
let ex = new DOMException("test");
|
|
assert(ex.message, "test");
|
|
assert(ex.name, "Error");
|
|
ex = new DOMException("test", "InvalidCharacterError");
|
|
assert(ex.name, "InvalidCharacterError");
|
|
assertThrows(TypeError, () => ex.message = "");
|
|
assertThrows(TypeError, () => ex.name = "test");
|
|
assert(ex.__proto__, DOMException.prototype);
|
|
/* Note: browsers set "stack" on the prototype, not the object.
|
|
* This follows node. */
|
|
assert(Object.getOwnPropertyNames(ex), ["stack"]);
|
|
}
|
|
|
|
test_code();
|
|
test_properties();
|