Skip to content
Prev Previous commit
Next Next commit
fixup! lib: make safe primordials safe to iterate
  • Loading branch information
aduh95 committed Dec 7, 2020
commit cf5374855af25ca9da5e8446f40f949ebb7e0826
9 changes: 5 additions & 4 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ const createSafeIterator = (factory, next) => {
Object.setPrototypeOf(SafeIterator.prototype, null);
Object.freeze(SafeIterator.prototype);
Object.freeze(SafeIterator);
return function() {
return new SafeIterator(this);
};
return SafeIterator;
};

function makeSafe(unsafe, safe) {
Expand All @@ -95,7 +93,10 @@ function makeSafe(unsafe, safe) {
if (Symbol.iterator in unsafe.prototype) {
const createIterator = uncurryThis(unsafe.prototype[Symbol.iterator]);
const next = uncurryThis(createIterator(new unsafe()).next);
safe.prototype[Symbol.iterator] = createSafeIterator(createIterator, next);
const SafeIterator = createSafeIterator(createIterator, next);
safe.prototype[Symbol.iterator] = function() {
return new SafeIterator(this);
};
}
Object.setPrototypeOf(safe.prototype, null);
Object.freeze(safe.prototype);
Expand Down