diff --git a/implementation.js b/implementation.js index cbb35d4..4a12d2c 100644 --- a/implementation.js +++ b/implementation.js @@ -14,18 +14,32 @@ var $toString = callBound('Object.prototype.toString'); var stackDesc = gOPD($Error.prototype, 'stack'); var stackGetter = stackDesc && stackDesc.get && callBind(stackDesc.get); +var domExceptionClonable = !!( + $structuredClone + && typeof DOMException === 'function' + && $structuredClone(new DOMException()) instanceof $Error +); + module.exports = function isError(arg) { if (!arg || (typeof arg !== 'object' && typeof arg !== 'function')) { return false; // step 1 } + if (typeof DOMException === 'function' && arg instanceof DOMException) { + return true; + } + if (isNativeError) { // node 10+ return isNativeError(arg); } if ($structuredClone) { try { - return $structuredClone(arg) instanceof $Error; + if ($structuredClone(arg) instanceof $Error) { + return true; + } else if (domExceptionClonable) { + return false; + } } catch (e) { return false; } diff --git a/test/tests.js b/test/tests.js index 72509a8..9f77413 100644 --- a/test/tests.js +++ b/test/tests.js @@ -60,7 +60,8 @@ module.exports = function (isError, t) { new URIError(), new EvalError(), typeof AggregateError === 'function' ? new AggregateError([]) : [], - typeof SuppressedError === 'function' ? new SuppressedError() : [] + typeof SuppressedError === 'function' ? new SuppressedError() : [], + typeof DOMException === 'function' ? new DOMException() : [] ), function (error) { st.equal(isError(error), true, inspect(error) + ' is an Error object'); });