GeezerVison is showing github.com — tools: add `prefer-proto` rule · nodejs/node@ed69a3a
File treeExpand file treeCollapse file tree Open diff view settings js-native-api/test_object
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -314,6 +314,7 @@ module.exports = { | 314 | 314 | // Custom rules from eslint-plugin-node-core | 315 | 315 | 'node-core/no-unescaped-regexp-dot': 'error', | 316 | 316 | 'node-core/no-duplicate-requires': 'error', | | 317 | + 'node-core/prefer-proto': 'error', | 317 | 318 | }, | 318 | 319 | globals: { | 319 | 320 | ByteLengthQueuingStrategy: 'readable', | |
Collapse file Copy file name to clipboardExpand all lines: benchmark/es/map-bench.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,7 +25,7 @@ function runObject(n) { | 25 | 25 | } | 26 | 26 |
| 27 | 27 | function runNullProtoObject(n) { | 28 | | - const m = Object.create(null); | | 28 | + const m = { __proto__: null }; | 29 | 29 | bench.start(); | 30 | 30 | for (let i = 0; i < n; i++) { | 31 | 31 | m[`i${i}`] = i; | @@ -51,7 +51,7 @@ function runNullProtoLiteralObject(n) { | 51 | 51 | } | 52 | 52 |
| 53 | 53 | function StorageObject() {} | 54 | | -StorageObject.prototype = Object.create(null); | | 54 | +StorageObject.prototype = { __proto__: null }; | 55 | 55 |
| 56 | 56 | function runStorageObject(n) { | 57 | 57 | const m = new StorageObject(); | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/assert.md +4-4Lines changed: 4 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -664,7 +664,7 @@ const obj3 = { | 664 | 664 | b: 1, | 665 | 665 | }, | 666 | 666 | }; | 667 | | -const obj4 = Object.create(obj1); | | 667 | +const obj4 = { __proto__: obj1 }; | 668 | 668 |
| 669 | 669 | assert.deepEqual(obj1, obj1); | 670 | 670 | // OK | @@ -699,7 +699,7 @@ const obj3 = { | 699 | 699 | b: 1, | 700 | 700 | }, | 701 | 701 | }; | 702 | | -const obj4 = Object.create(obj1); | | 702 | +const obj4 = { __proto__: obj1 }; | 703 | 703 |
| 704 | 704 | assert.deepEqual(obj1, obj1); | 705 | 705 | // OK | @@ -1623,7 +1623,7 @@ const obj3 = { | 1623 | 1623 | b: 1, | 1624 | 1624 | }, | 1625 | 1625 | }; | 1626 | | -const obj4 = Object.create(obj1); | | 1626 | +const obj4 = { __proto__: obj1 }; | 1627 | 1627 |
| 1628 | 1628 | assert.notDeepEqual(obj1, obj1); | 1629 | 1629 | // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } | @@ -1656,7 +1656,7 @@ const obj3 = { | 1656 | 1656 | b: 1, | 1657 | 1657 | }, | 1658 | 1658 | }; | 1659 | | -const obj4 = Object.create(obj1); | | 1659 | +const obj4 = { __proto__: obj1 }; | 1660 | 1660 |
| 1661 | 1661 | assert.notDeepEqual(obj1, obj1); | 1662 | 1662 | // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_agent.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,7 +32,6 @@ const { | 32 | 32 | FunctionPrototypeCall, | 33 | 33 | NumberIsNaN, | 34 | 34 | NumberParseInt, | 35 | | - ObjectCreate, | 36 | 35 | ObjectKeys, | 37 | 36 | ObjectSetPrototypeOf, | 38 | 37 | ObjectValues, | @@ -111,9 +110,9 @@ function Agent(options) { | 111 | 110 |
| 112 | 111 | // Don't confuse net and make it think that we're connecting to a pipe | 113 | 112 | this.options.path = null; | 114 | | - this.requests = ObjectCreate(null); | 115 | | - this.sockets = ObjectCreate(null); | 116 | | - this.freeSockets = ObjectCreate(null); | | 113 | + this.requests = { __proto__: null }; | | 114 | + this.sockets = { __proto__: null }; | | 115 | + this.freeSockets = { __proto__: null }; | 117 | 116 | this.keepAliveMsecs = this.options.keepAliveMsecs || 1000; | 118 | 117 | this.keepAlive = this.options.keepAlive || false; | 119 | 118 | this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets; | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_outgoing.js +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,7 +28,6 @@ const { | 28 | 28 | MathAbs, | 29 | 29 | MathFloor, | 30 | 30 | NumberPrototypeToString, | 31 | | - ObjectCreate, | 32 | 31 | ObjectDefineProperty, | 33 | 32 | ObjectKeys, | 34 | 33 | ObjectValues, | @@ -217,7 +216,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headers', { | 217 | 216 | if (val == null) { | 218 | 217 | this[kOutHeaders] = null; | 219 | 218 | } else if (typeof val === 'object') { | 220 | | - const headers = this[kOutHeaders] = ObjectCreate(null); | | 219 | + const headers = this[kOutHeaders] = { __proto__: null }; | 221 | 220 | const keys = ObjectKeys(val); | 222 | 221 | // Retain for(;;) loop for performance reasons | 223 | 222 | // Refs: https://github.com/nodejs/node/pull/30958 | @@ -244,7 +243,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headerNames', { | 244 | 243 | get: internalUtil.deprecate(function() { | 245 | 244 | const headers = this[kOutHeaders]; | 246 | 245 | if (headers !== null) { | 247 | | - const out = ObjectCreate(null); | | 246 | + const out = { __proto__: null }; | 248 | 247 | const keys = ObjectKeys(headers); | 249 | 248 | // Retain for(;;) loop for performance reasons | 250 | 249 | // Refs: https://github.com/nodejs/node/pull/30958 | @@ -667,7 +666,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) { | 667 | 666 |
| 668 | 667 | let headers = this[kOutHeaders]; | 669 | 668 | if (headers === null) | 670 | | - this[kOutHeaders] = headers = ObjectCreate(null); | | 669 | + this[kOutHeaders] = headers = { __proto__: null }; | 671 | 670 |
| 672 | 671 | headers[StringPrototypeToLowerCase(name)] = [name, value]; | 673 | 672 | return this; | @@ -742,7 +741,7 @@ OutgoingMessage.prototype.getRawHeaderNames = function getRawHeaderNames() { | 742 | 741 | // Returns a shallow copy of the current outgoing headers. | 743 | 742 | OutgoingMessage.prototype.getHeaders = function getHeaders() { | 744 | 743 | const headers = this[kOutHeaders]; | 745 | | - const ret = ObjectCreate(null); | | 744 | + const ret = { __proto__: null }; | 746 | 745 | if (headers) { | 747 | 746 | const keys = ObjectKeys(headers); | 748 | 747 | // Retain for(;;) loop for performance reasons | |
Collapse file Copy file name to clipboardExpand all lines: lib/_tls_common.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,6 @@ const tls = require('tls'); | 26 | 26 | const { | 27 | 27 | ArrayPrototypePush, | 28 | 28 | JSONParse, | 29 | | - ObjectCreate, | 30 | 29 | RegExpPrototypeSymbolReplace, | 31 | 30 | } = primordials; | 32 | 31 |
| @@ -131,7 +130,7 @@ function translatePeerCertificate(c) { | 131 | 130 | } | 132 | 131 | if (c.infoAccess != null) { | 133 | 132 | const info = c.infoAccess; | 134 | | - c.infoAccess = ObjectCreate(null); | | 133 | + c.infoAccess = { __proto__: null }; | 135 | 134 |
| 136 | 135 | // XXX: More key validation? | 137 | 136 | RegExpPrototypeSymbolReplace(/([^\n:]*):([^\n]*)(?:\n|$)/g, info, | |
Collapse file Copy file name to clipboardExpand all lines: lib/buffer.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,7 +33,6 @@ const { | 33 | 33 | NumberIsNaN, | 34 | 34 | NumberMAX_SAFE_INTEGER, | 35 | 35 | NumberMIN_SAFE_INTEGER, | 36 | | - ObjectCreate, | 37 | 36 | ObjectDefineProperties, | 38 | 37 | ObjectDefineProperty, | 39 | 38 | ObjectSetPrototypeOf, | @@ -146,7 +145,7 @@ const constants = ObjectDefineProperties({}, { | 146 | 145 | Buffer.poolSize = 8 * 1024; | 147 | 146 | let poolSize, poolOffset, allocPool; | 148 | 147 |
| 149 | | -const encodingsMap = ObjectCreate(null); | | 148 | +const encodingsMap = { __proto__: null }; | 150 | 149 | for (let i = 0; i < encodings.length; ++i) | 151 | 150 | encodingsMap[encodings[i]] = i; | 152 | 151 |
| @@ -845,7 +844,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) { | 845 | 844 | if (ctx) { | 846 | 845 | let extras = false; | 847 | 846 | const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE; | 848 | | - const obj = ObjectCreate(null); | | 847 | + const obj = { __proto__: null }; | 849 | 848 | ArrayPrototypeForEach(getOwnNonIndexProperties(this, filter), | 850 | 849 | (key) => { | 851 | 850 | extras = true; | |
Collapse file Copy file name to clipboardExpand all lines: lib/diagnostics_channel.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | ArrayPrototypeIndexOf, | 5 | 5 | ArrayPrototypePush, | 6 | 6 | ArrayPrototypeSplice, | 7 | | - ObjectCreate, | 8 | 7 | ObjectGetPrototypeOf, | 9 | 8 | ObjectSetPrototypeOf, | 10 | 9 | SymbolHasInstance, | @@ -92,7 +91,7 @@ class Channel { | 92 | 91 | publish() {} | 93 | 92 | } | 94 | 93 |
| 95 | | -const channels = ObjectCreate(null); | | 94 | +const channels = { __proto__: null }; | 96 | 95 |
| 97 | 96 | function channel(name) { | 98 | 97 | let channel; | |
Collapse file Copy file name to clipboardExpand all lines: lib/events.js +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,7 +33,6 @@ const { | 33 | 33 | FunctionPrototypeBind, | 34 | 34 | FunctionPrototypeCall, | 35 | 35 | NumberIsNaN, | 36 | | - ObjectCreate, | 37 | 36 | ObjectDefineProperty, | 38 | 37 | ObjectDefineProperties, | 39 | 38 | ObjectGetPrototypeOf, | @@ -338,7 +337,7 @@ EventEmitter.init = function(opts) { | 338 | 337 |
| 339 | 338 | if (this._events === undefined || | 340 | 339 | this._events === ObjectGetPrototypeOf(this)._events) { | 341 | | - this._events = ObjectCreate(null); | | 340 | + this._events = { __proto__: null }; | 342 | 341 | this._eventsCount = 0; | 343 | 342 | } | 344 | 343 |
| @@ -547,7 +546,7 @@ function _addListener(target, type, listener, prepend) { | 547 | 546 |
| 548 | 547 | events = target._events; | 549 | 548 | if (events === undefined) { | 550 | | - events = target._events = ObjectCreate(null); | | 549 | + events = target._events = { __proto__: null }; | 551 | 550 | target._eventsCount = 0; | 552 | 551 | } else { | 553 | 552 | // To avoid recursion in the case that type === "newListener"! Before | @@ -685,7 +684,7 @@ EventEmitter.prototype.removeListener = | 685 | 684 |
| 686 | 685 | if (list === listener || list.listener === listener) { | 687 | 686 | if (--this._eventsCount === 0) | 688 | | - this._events = ObjectCreate(null); | | 687 | + this._events = { __proto__: null }; | 689 | 688 | else { | 690 | 689 | delete events[type]; | 691 | 690 | if (events.removeListener) | @@ -740,11 +739,11 @@ EventEmitter.prototype.removeAllListeners = | 740 | 739 | // Not listening for removeListener, no need to emit | 741 | 740 | if (events.removeListener === undefined) { | 742 | 741 | if (arguments.length === 0) { | 743 | | - this._events = ObjectCreate(null); | | 742 | + this._events = { __proto__: null }; | 744 | 743 | this._eventsCount = 0; | 745 | 744 | } else if (events[type] !== undefined) { | 746 | 745 | if (--this._eventsCount === 0) | 747 | | - this._events = ObjectCreate(null); | | 746 | + this._events = { __proto__: null }; | 748 | 747 | else | 749 | 748 | delete events[type]; | 750 | 749 | } | @@ -758,7 +757,7 @@ EventEmitter.prototype.removeAllListeners = | 758 | 757 | this.removeAllListeners(key); | 759 | 758 | } | 760 | 759 | this.removeAllListeners('removeListener'); | 761 | | - this._events = ObjectCreate(null); | | 760 | + this._events = { __proto__: null }; | 762 | 761 | this._eventsCount = 0; | 763 | 762 | return this; | 764 | 763 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/assert/assertion_error.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | Error, | 7 | 7 | ErrorCaptureStackTrace, | 8 | 8 | MathMax, | 9 | | - ObjectCreate, | 10 | 9 | ObjectDefineProperty, | 11 | 10 | ObjectGetPrototypeOf, | 12 | 11 | ObjectKeys, | @@ -48,7 +47,7 @@ const kMaxShortLength = 12; | 48 | 47 |
| 49 | 48 | function copyError(source) { | 50 | 49 | const keys = ObjectKeys(source); | 51 | | - const target = ObjectCreate(ObjectGetPrototypeOf(source)); | | 50 | + const target = { __proto__: ObjectGetPrototypeOf(source) }; | 52 | 51 | for (const key of keys) { | 53 | 52 | target[key] = source[key]; | 54 | 53 | } | |
|