Skip to content

Commit db151e1

Browse files
RaisinTenjuanarbol
authored andcommittedOct 11, 2022
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 08a9c4a. Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: #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>
1 parent acff743 commit db151e1

File tree

1 file changed

+37
-60
lines changed

1 file changed

+37
-60
lines changed
 

‎lib/internal/per_context/domexception.js

+37-60
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,18 @@ function throwInvalidThisError(Base, type) {
3838
throw err;
3939
}
4040

41-
let disusedNamesSet;
42-
let internalsMap;
43-
let nameToCodeMap;
44-
let isInitialized = false;
41+
const internalsMap = new SafeWeakMap();
42+
const nameToCodeMap = new SafeMap();
4543

46-
// We need to instantiate the maps lazily because they render
47-
// the snapshot non-rehashable.
48-
// https://bugs.chromium.org/p/v8/issues/detail?id=6593
49-
function ensureInitialized() {
50-
if (isInitialized) {
51-
return;
52-
}
53-
internalsMap = new SafeWeakMap();
54-
nameToCodeMap = new SafeMap();
55-
forEachCode((name, codeName, value) => {
56-
nameToCodeMap.set(name, value);
57-
});
58-
59-
// These were removed from the error names table.
60-
// See https://github.com/heycam/webidl/pull/946.
61-
disusedNamesSet = new SafeSet()
62-
.add('DOMStringSizeError')
63-
.add('NoDataAllowedError')
64-
.add('ValidationError');
65-
66-
isInitialized = true;
67-
}
44+
// These were removed from the error names table.
45+
// See https://github.com/heycam/webidl/pull/946.
46+
const disusedNamesSet = new SafeSet()
47+
.add('DOMStringSizeError')
48+
.add('NoDataAllowedError')
49+
.add('ValidationError');
6850

6951
class DOMException {
7052
constructor(message = '', name = 'Error') {
71-
ensureInitialized();
7253
ErrorCaptureStackTrace(this);
7354
internalsMap.set(this, {
7455
message: `${message}`,
@@ -77,7 +58,6 @@ class DOMException {
7758
}
7859

7960
get name() {
80-
ensureInitialized();
8161
const internals = internalsMap.get(this);
8262
if (internals === undefined) {
8363
throwInvalidThisError(TypeError, 'DOMException');
@@ -86,7 +66,6 @@ class DOMException {
8666
}
8767

8868
get message() {
89-
ensureInitialized();
9069
const internals = internalsMap.get(this);
9170
if (internals === undefined) {
9271
throwInvalidThisError(TypeError, 'DOMException');
@@ -95,7 +74,6 @@ class DOMException {
9574
}
9675

9776
get code() {
98-
ensureInitialized();
9977
const internals = internalsMap.get(this);
10078
if (internals === undefined) {
10179
throwInvalidThisError(TypeError, 'DOMException');
@@ -118,40 +96,39 @@ ObjectDefineProperties(DOMException.prototype, {
11896
code: { __proto__: null, enumerable: true, configurable: true }
11997
});
12098

121-
function forEachCode(fn) {
122-
fn('IndexSizeError', 'INDEX_SIZE_ERR', 1);
123-
fn('DOMStringSizeError', 'DOMSTRING_SIZE_ERR', 2);
124-
fn('HierarchyRequestError', 'HIERARCHY_REQUEST_ERR', 3);
125-
fn('WrongDocumentError', 'WRONG_DOCUMENT_ERR', 4);
126-
fn('InvalidCharacterError', 'INVALID_CHARACTER_ERR', 5);
127-
fn('NoDataAllowedError', 'NO_DATA_ALLOWED_ERR', 6);
128-
fn('NoModificationAllowedError', 'NO_MODIFICATION_ALLOWED_ERR', 7);
129-
fn('NotFoundError', 'NOT_FOUND_ERR', 8);
130-
fn('NotSupportedError', 'NOT_SUPPORTED_ERR', 9);
131-
fn('InUseAttributeError', 'INUSE_ATTRIBUTE_ERR', 10);
132-
fn('InvalidStateError', 'INVALID_STATE_ERR', 11);
133-
fn('SyntaxError', 'SYNTAX_ERR', 12);
134-
fn('InvalidModificationError', 'INVALID_MODIFICATION_ERR', 13);
135-
fn('NamespaceError', 'NAMESPACE_ERR', 14);
136-
fn('InvalidAccessError', 'INVALID_ACCESS_ERR', 15);
137-
fn('ValidationError', 'VALIDATION_ERR', 16);
138-
fn('TypeMismatchError', 'TYPE_MISMATCH_ERR', 17);
139-
fn('SecurityError', 'SECURITY_ERR', 18);
140-
fn('NetworkError', 'NETWORK_ERR', 19);
141-
fn('AbortError', 'ABORT_ERR', 20);
142-
fn('URLMismatchError', 'URL_MISMATCH_ERR', 21);
143-
fn('QuotaExceededError', 'QUOTA_EXCEEDED_ERR', 22);
144-
fn('TimeoutError', 'TIMEOUT_ERR', 23);
145-
fn('InvalidNodeTypeError', 'INVALID_NODE_TYPE_ERR', 24);
146-
fn('DataCloneError', 'DATA_CLONE_ERR', 25);
99+
for (const { 0: name, 1: codeName, 2: value } of [
100+
['IndexSizeError', 'INDEX_SIZE_ERR', 1],
101+
['DOMStringSizeError', 'DOMSTRING_SIZE_ERR', 2],
102+
['HierarchyRequestError', 'HIERARCHY_REQUEST_ERR', 3],
103+
['WrongDocumentError', 'WRONG_DOCUMENT_ERR', 4],
104+
['InvalidCharacterError', 'INVALID_CHARACTER_ERR', 5],
105+
['NoDataAllowedError', 'NO_DATA_ALLOWED_ERR', 6],
106+
['NoModificationAllowedError', 'NO_MODIFICATION_ALLOWED_ERR', 7],
107+
['NotFoundError', 'NOT_FOUND_ERR', 8],
108+
['NotSupportedError', 'NOT_SUPPORTED_ERR', 9],
109+
['InUseAttributeError', 'INUSE_ATTRIBUTE_ERR', 10],
110+
['InvalidStateError', 'INVALID_STATE_ERR', 11],
111+
['SyntaxError', 'SYNTAX_ERR', 12],
112+
['InvalidModificationError', 'INVALID_MODIFICATION_ERR', 13],
113+
['NamespaceError', 'NAMESPACE_ERR', 14],
114+
['InvalidAccessError', 'INVALID_ACCESS_ERR', 15],
115+
['ValidationError', 'VALIDATION_ERR', 16],
116+
['TypeMismatchError', 'TYPE_MISMATCH_ERR', 17],
117+
['SecurityError', 'SECURITY_ERR', 18],
118+
['NetworkError', 'NETWORK_ERR', 19],
119+
['AbortError', 'ABORT_ERR', 20],
120+
['URLMismatchError', 'URL_MISMATCH_ERR', 21],
121+
['QuotaExceededError', 'QUOTA_EXCEEDED_ERR', 22],
122+
['TimeoutError', 'TIMEOUT_ERR', 23],
123+
['InvalidNodeTypeError', 'INVALID_NODE_TYPE_ERR', 24],
124+
['DataCloneError', 'DATA_CLONE_ERR', 25],
147125
// There are some more error names, but since they don't have codes assigned,
148126
// we don't need to care about them.
149-
}
150-
151-
forEachCode((name, codeName, value) => {
127+
]) {
152128
const desc = { enumerable: true, value };
153129
ObjectDefineProperty(DOMException, codeName, desc);
154130
ObjectDefineProperty(DOMException.prototype, codeName, desc);
155-
});
131+
nameToCodeMap.set(name, value);
132+
}
156133

157134
exports.DOMException = DOMException;

0 commit comments

Comments
 (0)
Please sign in to comment.