Skip to content

Commit bc882da

Browse files
committed
fixup: add support for Object.create(null)
1 parent 0c92b54 commit bc882da

33 files changed

Lines changed: 70 additions & 53 deletions

benchmark/es/map-bench.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function runObject(n) {
2525
}
2626

2727
function runNullProtoObject(n) {
28-
const m = Object.create(null);
28+
const m = { __proto__: null };
2929
bench.start();
3030
for (let i = 0; i < n; i++) {
3131
m[`i${i}`] = i;
@@ -51,7 +51,7 @@ function runNullProtoLiteralObject(n) {
5151
}
5252

5353
function StorageObject() {}
54-
StorageObject.prototype = Object.create(null);
54+
StorageObject.prototype = { __proto__: null };
5555

5656
function runStorageObject(n) {
5757
const m = new StorageObject();

test/async-hooks/verify-graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = function verifyGraph(hooks, graph) {
100100
assert.strictEqual(errors.length, 0);
101101

102102
// Verify that all expected types are present (but more/others are allowed)
103-
const expTypes = Object.create(null);
103+
const expTypes = { __proto__: null };
104104
for (let i = 0; i < graph.length; i++) {
105105
if (expTypes[graph[i].type] == null) expTypes[graph[i].type] = 0;
106106
expTypes[graph[i].type]++;

test/parallel/test-assert-deep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ assert.throws(
11901190
});
11911191
assertNotDeepOrStrict(a, b);
11921192

1193-
a = Object.create(null);
1193+
a = { __proto__: null };
11941194
b = new RangeError('abc');
11951195
Object.defineProperty(a, Symbol.toStringTag, {
11961196
value: 'Error'

test/parallel/test-blob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ assert.throws(() => new Blob({}), {
290290

291291
{
292292
// Testing the defaults
293-
[undefined, null, Object.create(null), { type: undefined }, {
293+
[undefined, null, { __proto__: null }, { type: undefined }, {
294294
get type() {}, // eslint-disable-line getter-return
295295
}].forEach((options) => {
296296
assert.strictEqual(

test/parallel/test-buffer-from.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ deepStrictEqual(
4040
{ valueOf() { return null; } },
4141
{ valueOf() { return undefined; } },
4242
{ valueOf: null },
43-
Object.create(null),
43+
{ __proto__: null },
4444
new Number(true),
4545
new MyBadPrimitive(),
4646
Symbol(),

test/parallel/test-common-must-not-mutate-object-deep.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function setPrototypeOfQuux(root) {
192192
// Test various supported types, directly and nested:
193193
[
194194
undefined, null, false, true, 42, 42n, Symbol('42'), NaN, Infinity, {}, [],
195-
() => {}, async () => {}, Promise.resolve(), Math, Object.create(null),
195+
() => {}, async () => {}, Promise.resolve(), Math, { __proto__: null },
196196
].forEach((target) => {
197197
assert.deepStrictEqual(mustNotMutateObjectDeep(target), target);
198198
assert.deepStrictEqual(mustNotMutateObjectDeep({ target }), { target });

test/parallel/test-crypto-x509.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const der = Buffer.from(
211211

212212
// Verify that legacy encoding works
213213
const legacyObjectCheck = {
214-
subject: Object.assign(Object.create(null), {
214+
subject: Object.assign({ __proto__: null }, {
215215
C: 'US',
216216
ST: 'CA',
217217
L: 'SF',
@@ -220,7 +220,7 @@ const der = Buffer.from(
220220
CN: 'agent1',
221221
emailAddress: 'ry@tinyclouds.org',
222222
}),
223-
issuer: Object.assign(Object.create(null), {
223+
issuer: Object.assign({ __proto__: null }, {
224224
C: 'US',
225225
ST: 'CA',
226226
L: 'SF',
@@ -229,7 +229,7 @@ const der = Buffer.from(
229229
CN: 'ca1',
230230
emailAddress: 'ry@tinyclouds.org',
231231
}),
232-
infoAccess: Object.assign(Object.create(null), {
232+
infoAccess: Object.assign({ __proto__: null }, {
233233
'OCSP - URI': ['http://ocsp.nodejs.org/'],
234234
'CA Issuers - URI': ['http://ca.nodejs.org/ca.cert']
235235
}),

test/parallel/test-error-value-type-detection.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ strictEqual(
3333
);
3434

3535
strictEqual(
36-
determineSpecificType(Object.create(null)),
36+
determineSpecificType({ __proto__: null }),
3737
'[Object: null prototype] {}',
3838
);
3939

test/parallel/test-event-emitter-emit-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const EE = new EventEmitter();
88

99
// Works as expected if the context has no `constructor.name`
1010
{
11-
const ctx = Object.create(null);
11+
const ctx = { __proto__: null };
1212
assert.throws(
1313
() => EE.emit.call(ctx, 'error', new Error('foo')),
1414
common.expectsError({ name: 'Error', message: 'foo' })

test/parallel/test-fs-opendir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ doAsyncIterBreakTest().then(common.mustCall());
166166
async function doAsyncIterReturnTest() {
167167
const dir = await fs.promises.opendir(testDir);
168168
await (async function() {
169-
for await (const dirent of dir) {
169+
for await (const dirent of dir) { // eslint-disable-line no-unused-vars
170170
return;
171171
}
172172
})();

0 commit comments

Comments
 (0)