From 56af1250fe993c6452a3fc504ed27f8067b7b124 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 7 Dec 2020 13:57:18 +0100 Subject: [PATCH] lib: make safe primordials safe to construct PR-URL: https://github.com/nodejs/node/pull/36428 Reviewed-By: Rich Trott --- lib/internal/per_context/primordials.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index ad5707954738ae..8bb7d41983262b 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -146,21 +146,31 @@ primordials.makeSafe = makeSafe; // Subclass the constructors because we need to use their prototype // methods later. +// Defining the `constructor` is necessary here to avoid the default +// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`. primordials.SafeMap = makeSafe( Map, - class SafeMap extends Map {} + class SafeMap extends Map { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } ); primordials.SafeWeakMap = makeSafe( WeakMap, - class SafeWeakMap extends WeakMap {} + class SafeWeakMap extends WeakMap { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } ); primordials.SafeSet = makeSafe( Set, - class SafeSet extends Set {} + class SafeSet extends Set { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } ); primordials.SafeWeakSet = makeSafe( WeakSet, - class SafeWeakSet extends WeakSet {} + class SafeWeakSet extends WeakSet { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } ); // Create copies of the namespace objects