From 7014e50ca32d39b94d04e04a5e6498e5c2f4346f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 17 Sep 2024 10:08:43 -0500 Subject: [PATCH] lib: the REPL should survive deletion of Array.prototype methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Specifically, `delete Array.prototype.lastIndexOf` immediately crashes the REPL, as does deletion of a few other Array prototype methods. PR-URL: https://github.com/nodejs/node/pull/31457 Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Michaƫl Zasso --- lib/domain.js | 3 ++- lib/repl.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/domain.js b/lib/domain.js index 7da672a3691..03d240e98d4 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -40,6 +40,7 @@ const { ReflectApply, SafeMap, SafeWeakMap, + StringPrototypeRepeat, Symbol, } = primordials; @@ -131,7 +132,7 @@ const domainRequireStack = new Error('require(`domain`) at this point').stack; const { setUncaughtExceptionCaptureCallback } = process; process.setUncaughtExceptionCaptureCallback = function(fn) { const err = new ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE(); - err.stack = err.stack + '\n' + '-'.repeat(40) + '\n' + domainRequireStack; + err.stack += `\n${StringPrototypeRepeat('-', 40)}\n${domainRequireStack}`; throw err; }; diff --git a/lib/repl.js b/lib/repl.js index a7aa4c71783..88e2dc37d6f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1528,7 +1528,7 @@ function complete(line, callback) { let p; if ((typeof obj === 'object' && obj !== null) || typeof obj === 'function') { - memberGroups.push(filteredOwnPropertyNames(obj)); + ArrayPrototypePush(memberGroups, filteredOwnPropertyNames(obj)); p = ObjectGetPrototypeOf(obj); } else { p = obj.constructor ? obj.constructor.prototype : null; @@ -1536,7 +1536,7 @@ function complete(line, callback) { // Circular refs possible? Let's guard against that. let sentinel = 5; while (p !== null && sentinel-- !== 0) { - memberGroups.push(filteredOwnPropertyNames(p)); + ArrayPrototypePush(memberGroups, filteredOwnPropertyNames(p)); p = ObjectGetPrototypeOf(p); } } catch {