domexception
Advanced tools
Comparing version 2.0.1 to 3.0.0
@@ -5,4 +5,4 @@ "use strict"; | ||
const sharedGlobalObject = { Error }; | ||
DOMException.install(sharedGlobalObject); | ||
DOMException.install(sharedGlobalObject, ["Window"]); | ||
module.exports = sharedGlobalObject.DOMException; |
@@ -6,201 +6,207 @@ "use strict"; | ||
const impl = utils.implSymbol; | ||
const ctorRegistry = utils.ctorRegistrySymbol; | ||
const implSymbol = utils.implSymbol; | ||
const ctorRegistrySymbol = utils.ctorRegistrySymbol; | ||
const iface = { | ||
// When an interface-module that implements this interface as a mixin is loaded, it will append its own `.is()` | ||
// method into this array. It allows objects that directly implements *those* interfaces to be recognized as | ||
// implementing this mixin interface. | ||
_mixedIntoPredicates: [], | ||
is(obj) { | ||
if (obj) { | ||
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { | ||
return true; | ||
} | ||
for (const isMixedInto of module.exports._mixedIntoPredicates) { | ||
if (isMixedInto(obj)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}, | ||
isImpl(obj) { | ||
if (obj) { | ||
if (obj instanceof Impl.implementation) { | ||
return true; | ||
} | ||
const interfaceName = "DOMException"; | ||
const wrapper = utils.wrapperForImpl(obj); | ||
for (const isMixedInto of module.exports._mixedIntoPredicates) { | ||
if (isMixedInto(wrapper)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}, | ||
convert(obj, { context = "The provided value" } = {}) { | ||
if (module.exports.is(obj)) { | ||
return utils.implForWrapper(obj); | ||
} | ||
throw new TypeError(`${context} is not of type 'DOMException'.`); | ||
}, | ||
exports.is = value => { | ||
return utils.isObject(value) && utils.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation; | ||
}; | ||
exports.isImpl = value => { | ||
return utils.isObject(value) && value instanceof Impl.implementation; | ||
}; | ||
exports.convert = (value, { context = "The provided value" } = {}) => { | ||
if (exports.is(value)) { | ||
return utils.implForWrapper(value); | ||
} | ||
throw new TypeError(`${context} is not of type 'DOMException'.`); | ||
}; | ||
create(globalObject, constructorArgs, privateData) { | ||
if (globalObject[ctorRegistry] === undefined) { | ||
throw new Error("Internal error: invalid global object"); | ||
} | ||
function makeWrapper(globalObject) { | ||
if (globalObject[ctorRegistrySymbol] === undefined) { | ||
throw new Error("Internal error: invalid global object"); | ||
} | ||
const ctor = globalObject[ctorRegistry]["DOMException"]; | ||
if (ctor === undefined) { | ||
throw new Error("Internal error: constructor DOMException is not installed on the passed global object"); | ||
} | ||
const ctor = globalObject[ctorRegistrySymbol]["DOMException"]; | ||
if (ctor === undefined) { | ||
throw new Error("Internal error: constructor DOMException is not installed on the passed global object"); | ||
} | ||
let obj = Object.create(ctor.prototype); | ||
obj = iface.setup(obj, globalObject, constructorArgs, privateData); | ||
return obj; | ||
}, | ||
createImpl(globalObject, constructorArgs, privateData) { | ||
const obj = iface.create(globalObject, constructorArgs, privateData); | ||
return utils.implForWrapper(obj); | ||
}, | ||
_internalSetup(obj) {}, | ||
setup(obj, globalObject, constructorArgs = [], privateData = {}) { | ||
privateData.wrapper = obj; | ||
return Object.create(ctor.prototype); | ||
} | ||
iface._internalSetup(obj); | ||
Object.defineProperty(obj, impl, { | ||
value: new Impl.implementation(globalObject, constructorArgs, privateData), | ||
configurable: true | ||
}); | ||
exports.create = (globalObject, constructorArgs, privateData) => { | ||
const wrapper = makeWrapper(globalObject); | ||
return exports.setup(wrapper, globalObject, constructorArgs, privateData); | ||
}; | ||
obj[impl][utils.wrapperSymbol] = obj; | ||
if (Impl.init) { | ||
Impl.init(obj[impl], privateData); | ||
} | ||
return obj; | ||
}, | ||
exports.createImpl = (globalObject, constructorArgs, privateData) => { | ||
const wrapper = exports.create(globalObject, constructorArgs, privateData); | ||
return utils.implForWrapper(wrapper); | ||
}; | ||
install(globalObject) { | ||
class DOMException { | ||
constructor() { | ||
const args = []; | ||
{ | ||
let curArg = arguments[0]; | ||
if (curArg !== undefined) { | ||
curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 1" }); | ||
} else { | ||
curArg = ""; | ||
} | ||
args.push(curArg); | ||
exports._internalSetup = (wrapper, globalObject) => {}; | ||
exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => { | ||
privateData.wrapper = wrapper; | ||
exports._internalSetup(wrapper, globalObject); | ||
Object.defineProperty(wrapper, implSymbol, { | ||
value: new Impl.implementation(globalObject, constructorArgs, privateData), | ||
configurable: true | ||
}); | ||
wrapper[implSymbol][utils.wrapperSymbol] = wrapper; | ||
if (Impl.init) { | ||
Impl.init(wrapper[implSymbol]); | ||
} | ||
return wrapper; | ||
}; | ||
exports.new = globalObject => { | ||
const wrapper = makeWrapper(globalObject); | ||
exports._internalSetup(wrapper, globalObject); | ||
Object.defineProperty(wrapper, implSymbol, { | ||
value: Object.create(Impl.implementation.prototype), | ||
configurable: true | ||
}); | ||
wrapper[implSymbol][utils.wrapperSymbol] = wrapper; | ||
if (Impl.init) { | ||
Impl.init(wrapper[implSymbol]); | ||
} | ||
return wrapper[implSymbol]; | ||
}; | ||
const exposed = new Set(["Window", "Worker"]); | ||
exports.install = (globalObject, globalNames) => { | ||
if (!globalNames.some(globalName => exposed.has(globalName))) { | ||
return; | ||
} | ||
class DOMException { | ||
constructor() { | ||
const args = []; | ||
{ | ||
let curArg = arguments[0]; | ||
if (curArg !== undefined) { | ||
curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 1" }); | ||
} else { | ||
curArg = ""; | ||
} | ||
{ | ||
let curArg = arguments[1]; | ||
if (curArg !== undefined) { | ||
curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 2" }); | ||
} else { | ||
curArg = "Error"; | ||
} | ||
args.push(curArg); | ||
args.push(curArg); | ||
} | ||
{ | ||
let curArg = arguments[1]; | ||
if (curArg !== undefined) { | ||
curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 2" }); | ||
} else { | ||
curArg = "Error"; | ||
} | ||
return iface.setup(Object.create(new.target.prototype), globalObject, args); | ||
args.push(curArg); | ||
} | ||
return exports.setup(Object.create(new.target.prototype), globalObject, args); | ||
} | ||
get name() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
get name() { | ||
const esValue = this !== null && this !== undefined ? this : globalObject; | ||
return this[impl]["name"]; | ||
if (!exports.is(esValue)) { | ||
throw new TypeError("'get name' called on an object that is not a valid instance of DOMException."); | ||
} | ||
get message() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return esValue[implSymbol]["name"]; | ||
} | ||
return this[impl]["message"]; | ||
get message() { | ||
const esValue = this !== null && this !== undefined ? this : globalObject; | ||
if (!exports.is(esValue)) { | ||
throw new TypeError("'get message' called on an object that is not a valid instance of DOMException."); | ||
} | ||
get code() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
return esValue[implSymbol]["message"]; | ||
} | ||
return this[impl]["code"]; | ||
get code() { | ||
const esValue = this !== null && this !== undefined ? this : globalObject; | ||
if (!exports.is(esValue)) { | ||
throw new TypeError("'get code' called on an object that is not a valid instance of DOMException."); | ||
} | ||
return esValue[implSymbol]["code"]; | ||
} | ||
Object.defineProperties(DOMException.prototype, { | ||
name: { enumerable: true }, | ||
message: { enumerable: true }, | ||
code: { enumerable: true }, | ||
[Symbol.toStringTag]: { value: "DOMException", configurable: true }, | ||
INDEX_SIZE_ERR: { value: 1, enumerable: true }, | ||
DOMSTRING_SIZE_ERR: { value: 2, enumerable: true }, | ||
HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true }, | ||
WRONG_DOCUMENT_ERR: { value: 4, enumerable: true }, | ||
INVALID_CHARACTER_ERR: { value: 5, enumerable: true }, | ||
NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true }, | ||
NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true }, | ||
NOT_FOUND_ERR: { value: 8, enumerable: true }, | ||
NOT_SUPPORTED_ERR: { value: 9, enumerable: true }, | ||
INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true }, | ||
INVALID_STATE_ERR: { value: 11, enumerable: true }, | ||
SYNTAX_ERR: { value: 12, enumerable: true }, | ||
INVALID_MODIFICATION_ERR: { value: 13, enumerable: true }, | ||
NAMESPACE_ERR: { value: 14, enumerable: true }, | ||
INVALID_ACCESS_ERR: { value: 15, enumerable: true }, | ||
VALIDATION_ERR: { value: 16, enumerable: true }, | ||
TYPE_MISMATCH_ERR: { value: 17, enumerable: true }, | ||
SECURITY_ERR: { value: 18, enumerable: true }, | ||
NETWORK_ERR: { value: 19, enumerable: true }, | ||
ABORT_ERR: { value: 20, enumerable: true }, | ||
URL_MISMATCH_ERR: { value: 21, enumerable: true }, | ||
QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true }, | ||
TIMEOUT_ERR: { value: 23, enumerable: true }, | ||
INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true }, | ||
DATA_CLONE_ERR: { value: 25, enumerable: true } | ||
}); | ||
Object.defineProperties(DOMException, { | ||
INDEX_SIZE_ERR: { value: 1, enumerable: true }, | ||
DOMSTRING_SIZE_ERR: { value: 2, enumerable: true }, | ||
HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true }, | ||
WRONG_DOCUMENT_ERR: { value: 4, enumerable: true }, | ||
INVALID_CHARACTER_ERR: { value: 5, enumerable: true }, | ||
NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true }, | ||
NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true }, | ||
NOT_FOUND_ERR: { value: 8, enumerable: true }, | ||
NOT_SUPPORTED_ERR: { value: 9, enumerable: true }, | ||
INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true }, | ||
INVALID_STATE_ERR: { value: 11, enumerable: true }, | ||
SYNTAX_ERR: { value: 12, enumerable: true }, | ||
INVALID_MODIFICATION_ERR: { value: 13, enumerable: true }, | ||
NAMESPACE_ERR: { value: 14, enumerable: true }, | ||
INVALID_ACCESS_ERR: { value: 15, enumerable: true }, | ||
VALIDATION_ERR: { value: 16, enumerable: true }, | ||
TYPE_MISMATCH_ERR: { value: 17, enumerable: true }, | ||
SECURITY_ERR: { value: 18, enumerable: true }, | ||
NETWORK_ERR: { value: 19, enumerable: true }, | ||
ABORT_ERR: { value: 20, enumerable: true }, | ||
URL_MISMATCH_ERR: { value: 21, enumerable: true }, | ||
QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true }, | ||
TIMEOUT_ERR: { value: 23, enumerable: true }, | ||
INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true }, | ||
DATA_CLONE_ERR: { value: 25, enumerable: true } | ||
}); | ||
if (globalObject[ctorRegistry] === undefined) { | ||
globalObject[ctorRegistry] = Object.create(null); | ||
} | ||
globalObject[ctorRegistry]["DOMException"] = DOMException; | ||
Object.defineProperty(globalObject, "DOMException", { | ||
configurable: true, | ||
writable: true, | ||
value: DOMException | ||
}); | ||
} | ||
}; // iface | ||
module.exports = iface; | ||
Object.defineProperties(DOMException.prototype, { | ||
name: { enumerable: true }, | ||
message: { enumerable: true }, | ||
code: { enumerable: true }, | ||
[Symbol.toStringTag]: { value: "DOMException", configurable: true }, | ||
INDEX_SIZE_ERR: { value: 1, enumerable: true }, | ||
DOMSTRING_SIZE_ERR: { value: 2, enumerable: true }, | ||
HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true }, | ||
WRONG_DOCUMENT_ERR: { value: 4, enumerable: true }, | ||
INVALID_CHARACTER_ERR: { value: 5, enumerable: true }, | ||
NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true }, | ||
NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true }, | ||
NOT_FOUND_ERR: { value: 8, enumerable: true }, | ||
NOT_SUPPORTED_ERR: { value: 9, enumerable: true }, | ||
INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true }, | ||
INVALID_STATE_ERR: { value: 11, enumerable: true }, | ||
SYNTAX_ERR: { value: 12, enumerable: true }, | ||
INVALID_MODIFICATION_ERR: { value: 13, enumerable: true }, | ||
NAMESPACE_ERR: { value: 14, enumerable: true }, | ||
INVALID_ACCESS_ERR: { value: 15, enumerable: true }, | ||
VALIDATION_ERR: { value: 16, enumerable: true }, | ||
TYPE_MISMATCH_ERR: { value: 17, enumerable: true }, | ||
SECURITY_ERR: { value: 18, enumerable: true }, | ||
NETWORK_ERR: { value: 19, enumerable: true }, | ||
ABORT_ERR: { value: 20, enumerable: true }, | ||
URL_MISMATCH_ERR: { value: 21, enumerable: true }, | ||
QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true }, | ||
TIMEOUT_ERR: { value: 23, enumerable: true }, | ||
INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true }, | ||
DATA_CLONE_ERR: { value: 25, enumerable: true } | ||
}); | ||
Object.defineProperties(DOMException, { | ||
INDEX_SIZE_ERR: { value: 1, enumerable: true }, | ||
DOMSTRING_SIZE_ERR: { value: 2, enumerable: true }, | ||
HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true }, | ||
WRONG_DOCUMENT_ERR: { value: 4, enumerable: true }, | ||
INVALID_CHARACTER_ERR: { value: 5, enumerable: true }, | ||
NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true }, | ||
NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true }, | ||
NOT_FOUND_ERR: { value: 8, enumerable: true }, | ||
NOT_SUPPORTED_ERR: { value: 9, enumerable: true }, | ||
INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true }, | ||
INVALID_STATE_ERR: { value: 11, enumerable: true }, | ||
SYNTAX_ERR: { value: 12, enumerable: true }, | ||
INVALID_MODIFICATION_ERR: { value: 13, enumerable: true }, | ||
NAMESPACE_ERR: { value: 14, enumerable: true }, | ||
INVALID_ACCESS_ERR: { value: 15, enumerable: true }, | ||
VALIDATION_ERR: { value: 16, enumerable: true }, | ||
TYPE_MISMATCH_ERR: { value: 17, enumerable: true }, | ||
SECURITY_ERR: { value: 18, enumerable: true }, | ||
NETWORK_ERR: { value: 19, enumerable: true }, | ||
ABORT_ERR: { value: 20, enumerable: true }, | ||
URL_MISMATCH_ERR: { value: 21, enumerable: true }, | ||
QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true }, | ||
TIMEOUT_ERR: { value: 23, enumerable: true }, | ||
INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true }, | ||
DATA_CLONE_ERR: { value: 25, enumerable: true } | ||
}); | ||
if (globalObject[ctorRegistrySymbol] === undefined) { | ||
globalObject[ctorRegistrySymbol] = Object.create(null); | ||
} | ||
globalObject[ctorRegistrySymbol][interfaceName] = DOMException; | ||
Object.defineProperty(globalObject, interfaceName, { | ||
configurable: true, | ||
writable: true, | ||
value: DOMException | ||
}); | ||
}; | ||
const Impl = require("./DOMException-impl.js"); |
{ | ||
"IndexSizeError": 1, | ||
"DOMStringSizeError": 2, | ||
"HierarchyRequestError": 3, | ||
"WrongDocumentError": 4, | ||
"InvalidCharacterError": 5, | ||
"NoDataAllowedError": 6, | ||
"NoModificationAllowedError": 7, | ||
@@ -17,3 +15,2 @@ "NotFoundError": 8, | ||
"InvalidAccessError": 15, | ||
"ValidationError": 16, | ||
"TypeMismatchError": 17, | ||
@@ -20,0 +17,0 @@ "SecurityError": 18, |
@@ -8,5 +8,3 @@ "use strict"; | ||
function hasOwn(obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
} | ||
const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty); | ||
@@ -51,2 +49,3 @@ const wrapperSymbol = Symbol("wrapper"); | ||
const IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())); | ||
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype); | ||
@@ -79,2 +78,18 @@ function isArrayIndexPropName(P) { | ||
function iteratorResult([key, value], kind) { | ||
let result; | ||
switch (kind) { | ||
case "key": | ||
result = key; | ||
break; | ||
case "value": | ||
result = value; | ||
break; | ||
case "key+value": | ||
result = [key, value]; | ||
break; | ||
} | ||
return { value: result, done: false }; | ||
} | ||
const supportsPropertyIndex = Symbol("supports property index"); | ||
@@ -92,2 +107,7 @@ const supportedPropertyIndices = Symbol("supported property indices"); | ||
const asyncIteratorNext = Symbol("async iterator get the next iteration result"); | ||
const asyncIteratorReturn = Symbol("async iterator return steps"); | ||
const asyncIteratorInit = Symbol("async iterator initialization steps"); | ||
const asyncIteratorEOI = Symbol("async iterator end of iteration"); | ||
module.exports = exports = { | ||
@@ -106,2 +126,3 @@ isObject, | ||
IteratorPrototype, | ||
AsyncIteratorPrototype, | ||
isArrayBuffer, | ||
@@ -119,3 +140,8 @@ isArrayIndexPropName, | ||
namedSetExisting, | ||
namedDelete | ||
namedDelete, | ||
asyncIteratorNext, | ||
asyncIteratorReturn, | ||
asyncIteratorInit, | ||
asyncIteratorEOI, | ||
iteratorResult | ||
}; |
MIT License | ||
Copyright © 2017 Domenic Denicola | ||
Copyright © Domenic Denicola | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)", | ||
@@ -28,17 +28,17 @@ "license": "MIT", | ||
"test": "mocha", | ||
"lint": "eslint lib" | ||
"lint": "eslint ." | ||
}, | ||
"dependencies": { | ||
"webidl-conversions": "^5.0.0" | ||
"webidl-conversions": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.7.2", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^6.2.2", | ||
"request": "^2.88.0", | ||
"webidl2js": "^12.0.0" | ||
"@domenic/eslint-config": "^1.4.0", | ||
"eslint": "^7.32.0", | ||
"minipass-fetch": "^1.4.1", | ||
"mocha": "^9.1.2", | ||
"webidl2js": "^16.2.0" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
} | ||
} |
# DOMException | ||
This package implements the [`DOMException`](https://heycam.github.io/webidl/#idl-DOMException) class, from web browsers. It exists in service of [jsdom](https://github.com/tmpvar/jsdom) and related packages. | ||
This package implements the [`DOMException`](https://heycam.github.io/webidl/#idl-DOMException) class, from web browsers. It exists in service of [jsdom](https://github.com/jsdom/jsdom) and related packages. | ||
@@ -5,0 +5,0 @@ Example usage: |
@@ -6,3 +6,3 @@ "use strict"; | ||
// https://heycam.github.io/webidl/#es-DOMException-specialness | ||
function installOverride(globalObject) { | ||
function installOverride(globalObject, globalNames) { | ||
if (typeof globalObject.Error !== "function") { | ||
@@ -12,6 +12,6 @@ throw new Error("Internal error: Error constructor is not present on the given global object."); | ||
DOMException.install(globalObject); | ||
DOMException.install(globalObject, globalNames); | ||
Object.setPrototypeOf(globalObject.DOMException.prototype, globalObject.Error.prototype); | ||
} | ||
module.exports = {...DOMException, install: installOverride }; | ||
module.exports = { ...DOMException, install: installOverride }; |
18658
11
420
+ Addedwebidl-conversions@7.0.0(transitive)
- Removedwebidl-conversions@5.0.0(transitive)
Updatedwebidl-conversions@^7.0.0