From 8d9dd1434ea6ea6e787c2428735277e32b940243 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 c9482c39cf3a5e..25152c7be9c3a3 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