Skip to content

Commit

Permalink
use ArrayPrototypeForEach instead of SafeArrayIterator
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine du Hamel <[email protected]>
  • Loading branch information
ExE-Boss and aduh95 committed Jan 11, 2021
1 parent 932e4bf commit d4373f8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function copyPrototype(src, dest, prefix) {
/* eslint-enable node-core/prefer-primordials */

const {
ArrayPrototypeForEach,
FunctionPrototypeCall,
Map,
ObjectFreeze,
Expand Down Expand Up @@ -212,24 +213,23 @@ primordials.SafeStringIterator = createSafeIterator(
primordials.StringIteratorPrototypeNext
);

const { SafeArrayIterator } = primordials;
const copyProps = (src, dest) => {
for (const key of new SafeArrayIterator(ReflectOwnKeys(src))) {
ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
ReflectDefineProperty(
dest,
key,
ReflectGetOwnPropertyDescriptor(src, key));
}
}
});
};

const makeSafe = (unsafe, safe) => {
if (SymbolIterator in unsafe.prototype) {
const dummy = new unsafe();
let next; // We can reuse the same `next` method.

for (const key of new SafeArrayIterator(ReflectOwnKeys(unsafe.prototype))) {
ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {
if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {
const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key);
if (
Expand All @@ -246,7 +246,7 @@ const makeSafe = (unsafe, safe) => {
}
ReflectDefineProperty(safe.prototype, key, desc);
}
}
});
} else {
copyProps(unsafe.prototype, safe.prototype);
}
Expand Down

0 comments on commit d4373f8

Please sign in to comment.