| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,9 +91,52 @@ function copyPrototype(src, dest, prefix) { | |||
| 91 | 91 | } | |
| 92 | 92 | } | |
| 93 | 93 | ||
| 94 | + const createSafeIterator = (factory, next) => { | ||
| 95 | + class SafeIterator { | ||
| 96 | + constructor(iterable) { | ||
| 97 | + this._iterator = factory(iterable); | ||
| 98 | + } | ||
| 99 | + next() { | ||
| 100 | + return next(this._iterator); | ||
| 101 | + } | ||
| 102 | + [Symbol.iterator]() { | ||
| 103 | + return this; | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + Object.setPrototypeOf(SafeIterator.prototype, null); | ||
| 107 | + Object.freeze(SafeIterator.prototype); | ||
| 108 | + Object.freeze(SafeIterator); | ||
| 109 | + return SafeIterator; | ||
| 110 | + }; | ||
| 111 | + | ||
| 94 | 112 | function makeSafe(unsafe, safe) { | |
| 95 | - copyProps(unsafe.prototype, safe.prototype); | ||
| 113 | + if (Symbol.iterator in unsafe.prototype) { | ||
| 114 | + const dummy = new unsafe(); | ||
| 115 | + let next; // We can reuse the same `next` method. | ||
| 116 | + | ||
| 117 | + for (const key of Reflect.ownKeys(unsafe.prototype)) { | ||
| 118 | + if (!Reflect.getOwnPropertyDescriptor(safe.prototype, key)) { | ||
| 119 | + const desc = Reflect.getOwnPropertyDescriptor(unsafe.prototype, key); | ||
| 120 | + if ( | ||
| 121 | + typeof desc.value === 'function' && | ||
| 122 | + desc.value.length === 0 && | ||
| 123 | + Symbol.iterator in (desc.value.call(dummy) ?? {}) | ||
| 124 | + ) { | ||
| 125 | + const createIterator = uncurryThis(desc.value); | ||
| 126 | + next ??= uncurryThis(createIterator(dummy).next); | ||
| 127 | + const SafeIterator = createSafeIterator(createIterator, next); | ||
| 128 | + desc.value = function() { | ||
| 129 | + return new SafeIterator(this); | ||
| 130 | + }; | ||
| 131 | + } | ||
| 132 | + Reflect.defineProperty(safe.prototype, key, desc); | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + } else { | ||
| 136 | + copyProps(unsafe.prototype, safe.prototype); | ||
| 137 | + } | ||
| 96 | 138 | copyProps(unsafe, safe); | |
| 139 | + | ||
| 97 | 140 | Object.setPrototypeOf(safe.prototype, null); | |
| 98 | 141 | Object.freeze(safe.prototype); | |
| 99 | 142 | Object.freeze(safe); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,17 +7,12 @@ const { | |||
| 7 | 7 | ObjectKeys, | |
| 8 | 8 | ObjectGetOwnPropertyDescriptor, | |
| 9 | 9 | ObjectPrototypeHasOwnProperty, | |
| 10 | - Map, | ||
| 11 | - MapPrototypeEntries, | ||
| 12 | 10 | RegExpPrototypeTest, | |
| 13 | 11 | SafeMap, | |
| 14 | 12 | StringPrototypeMatch, | |
| 15 | 13 | StringPrototypeSplit, | |
| 16 | - uncurryThis, | ||
| 17 | 14 | } = primordials; | |
| 18 | 15 | ||
| 19 | - const MapIteratorNext = uncurryThis(MapPrototypeEntries(new Map()).next); | ||
| 20 | - | ||
| 21 | 16 | function ObjectGetValueSafe(obj, key) { | |
| 22 | 17 | const desc = ObjectGetOwnPropertyDescriptor(obj, key); | |
| 23 | 18 | return ObjectPrototypeHasOwnProperty(desc, 'value') ? desc.value : undefined; | |
@@ -195,11 +190,7 @@ function rekeySourceMap(cjsModuleInstance, newInstance) { | |||
| 195 | 190 | function sourceMapCacheToObject() { | |
| 196 | 191 | const obj = ObjectCreate(null); | |
| 197 | 192 | ||
| 198 | - const it = MapPrototypeEntries(esmSourceMapCache); | ||
| 199 | - let entry; | ||
| 200 | - while (!(entry = MapIteratorNext(it)).done) { | ||
| 201 | - const k = entry.value[0]; | ||
| 202 | - const v = entry.value[1]; | ||
| 193 | + for (const { 0: k, 1: v } of esmSourceMapCache) { | ||
| 203 | 194 | obj[k] = v; | |
| 204 | 195 | } | |
| 205 | 196 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayPrototypeForEach, | ||
| 4 | 5 | ArrayPrototypeMap, | |
| 5 | 6 | ArrayPrototypePush, | |
| 6 | 7 | FunctionPrototypeBind, | |
@@ -315,8 +316,7 @@ class WritableWorkerStdio extends Writable { | |||
| 315 | 316 | [kStdioWantsMoreDataCallback]() { | |
| 316 | 317 | const cbs = this[kWritableCallbacks]; | |
| 317 | 318 | this[kWritableCallbacks] = []; | |
| 318 | - for (const cb of cbs) | ||
| 319 | - cb(); | ||
| 319 | + ArrayPrototypeForEach(cbs, (cb) => cb()); | ||
| 320 | 320 | if ((this[kPort][kWaitingStreams] -= cbs.length) === 0) | |
| 321 | 321 | this[kPort].unref(); | |
| 322 | 322 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,16 +27,19 @@ const { callCount } = workerData; | |||
| 27 | 27 | function increaseCallCount() { callCount[0]++; } | |
| 28 | 28 | ||
| 29 | 29 | // Increase the call count when a forbidden method is called. | |
| 30 | - Object.getPrototypeOf((new Map()).entries()).next = increaseCallCount; | ||
| 31 | - Map.prototype.entries = increaseCallCount; | ||
| 32 | - Object.keys = increaseCallCount; | ||
| 33 | - Object.create = increaseCallCount; | ||
| 34 | - Object.hasOwnProperty = increaseCallCount; | ||
| 35 | 30 | for (const property of ['_cache', 'lineLengths', 'url']) { | |
| 36 | 31 | Object.defineProperty(Object.prototype, property, { | |
| 37 | 32 | get: increaseCallCount, | |
| 38 | 33 | set: increaseCallCount | |
| 39 | 34 | }); | |
| 40 | 35 | } | |
| 36 | + Object.getPrototypeOf([][Symbol.iterator]()).next = increaseCallCount; | ||
| 37 | + Object.getPrototypeOf((new Map()).entries()).next = increaseCallCount; | ||
| 38 | + Array.prototype[Symbol.iterator] = increaseCallCount; | ||
| 39 | + Map.prototype[Symbol.iterator] = increaseCallCount; | ||
| 40 | + Map.prototype.entries = increaseCallCount; | ||
| 41 | + Object.keys = increaseCallCount; | ||
| 42 | + Object.create = increaseCallCount; | ||
| 43 | + Object.hasOwnProperty = increaseCallCount; | ||
| 41 | 44 | ||
| 42 | 45 | parentPort.postMessage('done'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments