bootstrap: stop delaying instantiation of maps in per-context scripts

The linked issue, https://bugs.chromium.org/p/v8/issues/detail?id=6593,
is marked as "Fixed", so I think we can revert this now.

This reverts commit 08a9c4a996964aca909cd75fa8ecafd652c54885.

Signed-off-by: Darshan Sen <raisinten@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/42934
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=9187
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Darshan Sen 2022-05-05 17:26:12 +05:30 committed by GitHub
parent edcc542996
commit 30388fc796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,37 +36,18 @@ function throwInvalidThisError(Base, type) {
throw err; throw err;
} }
let disusedNamesSet; const internalsMap = new SafeWeakMap();
let internalsMap; const nameToCodeMap = new SafeMap();
let nameToCodeMap;
let isInitialized = false;
// We need to instantiate the maps lazily because they render // These were removed from the error names table.
// the snapshot non-rehashable. // See https://github.com/heycam/webidl/pull/946.
// https://bugs.chromium.org/p/v8/issues/detail?id=6593 const disusedNamesSet = new SafeSet()
function ensureInitialized() { .add('DOMStringSizeError')
if (isInitialized) { .add('NoDataAllowedError')
return; .add('ValidationError');
}
internalsMap = new SafeWeakMap();
nameToCodeMap = new SafeMap();
forEachCode((name, codeName, value) => {
nameToCodeMap.set(name, value);
});
// These were removed from the error names table.
// See https://github.com/heycam/webidl/pull/946.
disusedNamesSet = new SafeSet()
.add('DOMStringSizeError')
.add('NoDataAllowedError')
.add('ValidationError');
isInitialized = true;
}
class DOMException { class DOMException {
constructor(message = '', name = 'Error') { constructor(message = '', name = 'Error') {
ensureInitialized();
ErrorCaptureStackTrace(this); ErrorCaptureStackTrace(this);
internalsMap.set(this, { internalsMap.set(this, {
message: `${message}`, message: `${message}`,
@ -75,7 +56,6 @@ class DOMException {
} }
get name() { get name() {
ensureInitialized();
const internals = internalsMap.get(this); const internals = internalsMap.get(this);
if (internals === undefined) { if (internals === undefined) {
throwInvalidThisError(TypeError, 'DOMException'); throwInvalidThisError(TypeError, 'DOMException');
@ -84,7 +64,6 @@ class DOMException {
} }
get message() { get message() {
ensureInitialized();
const internals = internalsMap.get(this); const internals = internalsMap.get(this);
if (internals === undefined) { if (internals === undefined) {
throwInvalidThisError(TypeError, 'DOMException'); throwInvalidThisError(TypeError, 'DOMException');
@ -93,7 +72,6 @@ class DOMException {
} }
get code() { get code() {
ensureInitialized();
const internals = internalsMap.get(this); const internals = internalsMap.get(this);
if (internals === undefined) { if (internals === undefined) {
throwInvalidThisError(TypeError, 'DOMException'); throwInvalidThisError(TypeError, 'DOMException');
@ -116,40 +94,39 @@ ObjectDefineProperties(DOMException.prototype, {
code: { enumerable: true, configurable: true } code: { enumerable: true, configurable: true }
}); });
function forEachCode(fn) { for (const { 0: name, 1: codeName, 2: value } of [
fn('IndexSizeError', 'INDEX_SIZE_ERR', 1); ['IndexSizeError', 'INDEX_SIZE_ERR', 1],
fn('DOMStringSizeError', 'DOMSTRING_SIZE_ERR', 2); ['DOMStringSizeError', 'DOMSTRING_SIZE_ERR', 2],
fn('HierarchyRequestError', 'HIERARCHY_REQUEST_ERR', 3); ['HierarchyRequestError', 'HIERARCHY_REQUEST_ERR', 3],
fn('WrongDocumentError', 'WRONG_DOCUMENT_ERR', 4); ['WrongDocumentError', 'WRONG_DOCUMENT_ERR', 4],
fn('InvalidCharacterError', 'INVALID_CHARACTER_ERR', 5); ['InvalidCharacterError', 'INVALID_CHARACTER_ERR', 5],
fn('NoDataAllowedError', 'NO_DATA_ALLOWED_ERR', 6); ['NoDataAllowedError', 'NO_DATA_ALLOWED_ERR', 6],
fn('NoModificationAllowedError', 'NO_MODIFICATION_ALLOWED_ERR', 7); ['NoModificationAllowedError', 'NO_MODIFICATION_ALLOWED_ERR', 7],
fn('NotFoundError', 'NOT_FOUND_ERR', 8); ['NotFoundError', 'NOT_FOUND_ERR', 8],
fn('NotSupportedError', 'NOT_SUPPORTED_ERR', 9); ['NotSupportedError', 'NOT_SUPPORTED_ERR', 9],
fn('InUseAttributeError', 'INUSE_ATTRIBUTE_ERR', 10); ['InUseAttributeError', 'INUSE_ATTRIBUTE_ERR', 10],
fn('InvalidStateError', 'INVALID_STATE_ERR', 11); ['InvalidStateError', 'INVALID_STATE_ERR', 11],
fn('SyntaxError', 'SYNTAX_ERR', 12); ['SyntaxError', 'SYNTAX_ERR', 12],
fn('InvalidModificationError', 'INVALID_MODIFICATION_ERR', 13); ['InvalidModificationError', 'INVALID_MODIFICATION_ERR', 13],
fn('NamespaceError', 'NAMESPACE_ERR', 14); ['NamespaceError', 'NAMESPACE_ERR', 14],
fn('InvalidAccessError', 'INVALID_ACCESS_ERR', 15); ['InvalidAccessError', 'INVALID_ACCESS_ERR', 15],
fn('ValidationError', 'VALIDATION_ERR', 16); ['ValidationError', 'VALIDATION_ERR', 16],
fn('TypeMismatchError', 'TYPE_MISMATCH_ERR', 17); ['TypeMismatchError', 'TYPE_MISMATCH_ERR', 17],
fn('SecurityError', 'SECURITY_ERR', 18); ['SecurityError', 'SECURITY_ERR', 18],
fn('NetworkError', 'NETWORK_ERR', 19); ['NetworkError', 'NETWORK_ERR', 19],
fn('AbortError', 'ABORT_ERR', 20); ['AbortError', 'ABORT_ERR', 20],
fn('URLMismatchError', 'URL_MISMATCH_ERR', 21); ['URLMismatchError', 'URL_MISMATCH_ERR', 21],
fn('QuotaExceededError', 'QUOTA_EXCEEDED_ERR', 22); ['QuotaExceededError', 'QUOTA_EXCEEDED_ERR', 22],
fn('TimeoutError', 'TIMEOUT_ERR', 23); ['TimeoutError', 'TIMEOUT_ERR', 23],
fn('InvalidNodeTypeError', 'INVALID_NODE_TYPE_ERR', 24); ['InvalidNodeTypeError', 'INVALID_NODE_TYPE_ERR', 24],
fn('DataCloneError', 'DATA_CLONE_ERR', 25); ['DataCloneError', 'DATA_CLONE_ERR', 25],
// There are some more error names, but since they don't have codes assigned, // There are some more error names, but since they don't have codes assigned,
// we don't need to care about them. // we don't need to care about them.
} ]) {
forEachCode((name, codeName, value) => {
const desc = { enumerable: true, value }; const desc = { enumerable: true, value };
ObjectDefineProperty(DOMException, codeName, desc); ObjectDefineProperty(DOMException, codeName, desc);
ObjectDefineProperty(DOMException.prototype, codeName, desc); ObjectDefineProperty(DOMException.prototype, codeName, desc);
}); nameToCodeMap.set(name, value);
}
exports.DOMException = DOMException; exports.DOMException = DOMException;