Skip to content

Commit

Permalink
move @@toStringTag to a separate module, improve compat tests, fix …
Browse files Browse the repository at this point in the history
…entries
  • Loading branch information
zloirock committed Oct 9, 2021
1 parent e956d47 commit 6e04c89
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 18 deletions.
6 changes: 6 additions & 0 deletions packages/core-js-compat/src/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,12 @@ export const data = {
deno: '1.7',
firefox: '37',
},
'web.dom-exception.to-string-tag': {
chrome: '49',
deno: '1.7',
firefox: '51',
safari: '11.1',
},
'web.immediate': {
ie: '10',
node: '0.9.1',
Expand Down
1 change: 1 addition & 0 deletions packages/core-js-compat/src/modules-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ export default {
'es.error.to-string',
'web.dom-exception.constructor',
'web.dom-exception.stack',
'web.dom-exception.to-string-tag',
],
};
3 changes: 0 additions & 3 deletions packages/core-js/features/dom-exception.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/core-js/features/dom-exception/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../stable/dom-exception/constructor');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/dom-exception/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../stable/dom-exception');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/dom-exception/to-string-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../stable/dom-exception/to-string-tag');

module.exports = parent;
7 changes: 4 additions & 3 deletions packages/core-js/internals/set-to-string-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ var wellKnownSymbol = require('../internals/well-known-symbol');

var TO_STRING_TAG = wellKnownSymbol('toStringTag');

module.exports = function (it, TAG, STATIC) {
if (it && !hasOwn(it = STATIC ? it : it.prototype, TO_STRING_TAG)) {
defineProperty(it, TO_STRING_TAG, { configurable: true, value: TAG });
module.exports = function (target, TAG, STATIC) {
if (target && !STATIC) target = target.prototype;
if (target && !hasOwn(target, TO_STRING_TAG)) {
defineProperty(target, TO_STRING_TAG, { configurable: true, value: TAG });
}
};
7 changes: 2 additions & 5 deletions packages/core-js/modules/web.dom-exception.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var anInstance = require('../internals/an-instance');
var anObject = require('../internals/an-object');
var errorToString = require('../internals/error-to-string');
var normalizeStringArgument = require('../internals/normalize-string-argument');
var setToStringTag = require('../internals/set-to-string-tag');
var DOMExceptionConstants = require('../internals/dom-exception-constants');
var InternalStateModule = require('../internals/internal-state');
var DESCRIPTORS = require('../internals/descriptors');
Expand Down Expand Up @@ -92,8 +91,8 @@ var INCORRECT_CODE = INCORRECT_CONSTRUCTOR || fails(function () {

// Deno 1.6.3- DOMException constants just missed
var MISSED_CONSTANTS = INCORRECT_CONSTRUCTOR
|| !NativeDOMException[DATA_CLONE_ERR]
|| !NativeDOMExceptionPrototype[DATA_CLONE_ERR];
|| NativeDOMException[DATA_CLONE_ERR] !== 25
|| NativeDOMExceptionPrototype[DATA_CLONE_ERR] !== 25;

var FORCED_CONSTRUCTOR = IS_PURE ? INCORRECT_TO_STRING || INCORRECT_CODE || MISSED_CONSTANTS : INCORRECT_CONSTRUCTOR;

Expand Down Expand Up @@ -129,5 +128,3 @@ for (var key in DOMExceptionConstants) if (hasOwn(DOMExceptionConstants, key)) {
defineProperty(PolyfilledDOMExceptionPrototype, constantName, descriptor);
}
}

setToStringTag(PolyfilledDOMException, DOM_EXCEPTION);
6 changes: 6 additions & 0 deletions packages/core-js/modules/web.dom-exception.to-string-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var getBuiltIn = require('../internals/get-built-in');
var setToStringTag = require('../internals/set-to-string-tag');

var DOM_EXCEPTION = 'DOMException';

setToStringTag(getBuiltIn(DOM_EXCEPTION), DOM_EXCEPTION);
6 changes: 0 additions & 6 deletions packages/core-js/stable/dom-exception.js

This file was deleted.

6 changes: 6 additions & 0 deletions packages/core-js/stable/dom-exception/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require('../../modules/es.error.to-string');
require('../../modules/web.dom-exception.constructor');
require('../../modules/web.dom-exception.stack');
var path = require('../../internals/path');

module.exports = path.DOMException;
7 changes: 7 additions & 0 deletions packages/core-js/stable/dom-exception/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require('../../modules/es.error.to-string');
require('../../modules/web.dom-exception.constructor');
require('../../modules/web.dom-exception.stack');
require('../../modules/web.dom-exception.to-string-tag');
var path = require('../../internals/path');

module.exports = path.DOMException;
3 changes: 3 additions & 0 deletions packages/core-js/stable/dom-exception/to-string-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require('../../modules/web.dom-exception.to-string-tag');

module.exports = 'DOMException';
1 change: 1 addition & 0 deletions packages/core-js/web/dom-exception.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('../modules/es.error.to-string');
require('../modules/web.dom-exception.constructor');
require('../modules/web.dom-exception.stack');
require('../modules/web.dom-exception.to-string-tag');
var path = require('../internals/path');

module.exports = path.DOMException;
1 change: 1 addition & 0 deletions packages/core-js/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require('../modules/web.dom-collections.for-each');
require('../modules/web.dom-collections.iterator');
require('../modules/web.dom-exception.constructor');
require('../modules/web.dom-exception.stack');
require('../modules/web.dom-exception.to-string-tag');
require('../modules/web.immediate');
require('../modules/web.queue-microtask');
require('../modules/web.timers');
Expand Down
2 changes: 2 additions & 0 deletions tests/commonjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ for (PATH of ['core-js-pure', 'core-js']) {
}

for (const NS of ['stable', 'features']) {
ok(typeof load(NS, 'dom-exception/constructor') === 'function');
ok(load(NS, 'dom-exception/to-string-tag') === 'DOMException');
ok(typeof load(NS, 'dom-exception') === 'function');
ok(typeof load(NS, 'dom-collections').iterator === 'function');
ok(typeof load(NS, 'dom-collections/for-each') === 'function');
Expand Down
10 changes: 9 additions & 1 deletion tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1585,11 +1585,19 @@ GLOBAL.tests = {
return true;
},
'web.dom-exception.constructor': function () {
return typeof DOMException === 'function';
return new DOMException() instanceof Error
&& new DOMException(1, 'DataCloneError').code === 25
&& String(new DOMException(1, 2)) === '2: 1'
&& DOMException.DATA_CLONE_ERR === 25
&& DOMException.prototype.DATA_CLONE_ERR === 25;
},
'web.dom-exception.stack': function () {
return !('stack' in Error('1')) || 'stack' in new DOMException();
},
'web.dom-exception.to-string-tag': function () {
return typeof DOMException === 'function'
&& DOMException.prototype[Symbol.toStringTag] === 'DOMException';
},
'web.immediate': function () {
return setImmediate && clearImmediate;
},
Expand Down

0 comments on commit 6e04c89

Please sign in to comment.