Skip to content

Commit

Permalink
lib: the REPL should survive deletion of Array.prototype methods
Browse files Browse the repository at this point in the history
Specifically, `delete Array.prototype.lastIndexOf` immediately crashes
the REPL, as does deletion of a few other Array prototype methods.
  • Loading branch information
ljharb committed Sep 6, 2024
1 parent 342b501 commit 79c345d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {
ReflectApply,
SafeMap,
SafeWeakMap,
StringPrototypeRepeat,
Symbol,
} = primordials;

Expand Down Expand Up @@ -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;
};

Expand Down
6 changes: 4 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const {
ArrayPrototypePop,
ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeReduce,

Check failure on line 56 in lib/repl.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'ArrayPrototypeReduce' is assigned a value but never used
ArrayPrototypeReverse,

Check failure on line 57 in lib/repl.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'ArrayPrototypeReverse' is assigned a value but never used
ArrayPrototypeShift,
ArrayPrototypeSlice,
ArrayPrototypeSome,
Expand Down Expand Up @@ -1526,15 +1528,15 @@ 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;
}
// 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 {
Expand Down

0 comments on commit 79c345d

Please sign in to comment.