[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var globalThis = require('../internals/global-this');
|
---|
| 4 | var getBuiltIn = require('../internals/get-built-in');
|
---|
| 5 | var createPropertyDescriptor = require('../internals/create-property-descriptor');
|
---|
| 6 | var defineProperty = require('../internals/object-define-property').f;
|
---|
| 7 | var hasOwn = require('../internals/has-own-property');
|
---|
| 8 | var anInstance = require('../internals/an-instance');
|
---|
| 9 | var inheritIfRequired = require('../internals/inherit-if-required');
|
---|
| 10 | var normalizeStringArgument = require('../internals/normalize-string-argument');
|
---|
| 11 | var DOMExceptionConstants = require('../internals/dom-exception-constants');
|
---|
| 12 | var clearErrorStack = require('../internals/error-stack-clear');
|
---|
| 13 | var DESCRIPTORS = require('../internals/descriptors');
|
---|
| 14 | var IS_PURE = require('../internals/is-pure');
|
---|
| 15 |
|
---|
| 16 | var DOM_EXCEPTION = 'DOMException';
|
---|
| 17 | var Error = getBuiltIn('Error');
|
---|
| 18 | var NativeDOMException = getBuiltIn(DOM_EXCEPTION);
|
---|
| 19 |
|
---|
| 20 | var $DOMException = function DOMException() {
|
---|
| 21 | anInstance(this, DOMExceptionPrototype);
|
---|
| 22 | var argumentsLength = arguments.length;
|
---|
| 23 | var message = normalizeStringArgument(argumentsLength < 1 ? undefined : arguments[0]);
|
---|
| 24 | var name = normalizeStringArgument(argumentsLength < 2 ? undefined : arguments[1], 'Error');
|
---|
| 25 | var that = new NativeDOMException(message, name);
|
---|
| 26 | var error = new Error(message);
|
---|
| 27 | error.name = DOM_EXCEPTION;
|
---|
| 28 | defineProperty(that, 'stack', createPropertyDescriptor(1, clearErrorStack(error.stack, 1)));
|
---|
| 29 | inheritIfRequired(that, this, $DOMException);
|
---|
| 30 | return that;
|
---|
| 31 | };
|
---|
| 32 |
|
---|
| 33 | var DOMExceptionPrototype = $DOMException.prototype = NativeDOMException.prototype;
|
---|
| 34 |
|
---|
| 35 | var ERROR_HAS_STACK = 'stack' in new Error(DOM_EXCEPTION);
|
---|
| 36 | var DOM_EXCEPTION_HAS_STACK = 'stack' in new NativeDOMException(1, 2);
|
---|
| 37 |
|
---|
| 38 | // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
|
---|
| 39 | var descriptor = NativeDOMException && DESCRIPTORS && Object.getOwnPropertyDescriptor(globalThis, DOM_EXCEPTION);
|
---|
| 40 |
|
---|
| 41 | // Bun ~ 0.1.1 DOMException have incorrect descriptor and we can't redefine it
|
---|
| 42 | // https://github.com/Jarred-Sumner/bun/issues/399
|
---|
| 43 | var BUGGY_DESCRIPTOR = !!descriptor && !(descriptor.writable && descriptor.configurable);
|
---|
| 44 |
|
---|
| 45 | var FORCED_CONSTRUCTOR = ERROR_HAS_STACK && !BUGGY_DESCRIPTOR && !DOM_EXCEPTION_HAS_STACK;
|
---|
| 46 |
|
---|
| 47 | // `DOMException` constructor patch for `.stack` where it's required
|
---|
| 48 | // https://webidl.spec.whatwg.org/#es-DOMException-specialness
|
---|
| 49 | $({ global: true, constructor: true, forced: IS_PURE || FORCED_CONSTRUCTOR }, { // TODO: fix export logic
|
---|
| 50 | DOMException: FORCED_CONSTRUCTOR ? $DOMException : NativeDOMException
|
---|
| 51 | });
|
---|
| 52 |
|
---|
| 53 | var PolyfilledDOMException = getBuiltIn(DOM_EXCEPTION);
|
---|
| 54 | var PolyfilledDOMExceptionPrototype = PolyfilledDOMException.prototype;
|
---|
| 55 |
|
---|
| 56 | if (PolyfilledDOMExceptionPrototype.constructor !== PolyfilledDOMException) {
|
---|
| 57 | if (!IS_PURE) {
|
---|
| 58 | defineProperty(PolyfilledDOMExceptionPrototype, 'constructor', createPropertyDescriptor(1, PolyfilledDOMException));
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | for (var key in DOMExceptionConstants) if (hasOwn(DOMExceptionConstants, key)) {
|
---|
| 62 | var constant = DOMExceptionConstants[key];
|
---|
| 63 | var constantName = constant.s;
|
---|
| 64 | if (!hasOwn(PolyfilledDOMException, constantName)) {
|
---|
| 65 | defineProperty(PolyfilledDOMException, constantName, createPropertyDescriptor(6, constant.c));
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|