diff --git a/lib/internal/repl/completion.js b/lib/internal/repl/completion.js index a16b7af0d1732c..59718ce57a5565 100644 --- a/lib/internal/repl/completion.js +++ b/lib/internal/repl/completion.js @@ -540,14 +540,14 @@ function findExpressionCompleteTarget(code) { // such code can't generate a valid AST so we need to strip // the suffix, run this function's logic and add back the // optional chaining operator to the result if present - const result = findExpressionCompleteTarget(code.slice(0, -2)); + const result = findExpressionCompleteTarget(StringPrototypeSlice(code, 0, -2)); return !result ? result : `${result}?.`; } // The code ends with a dot, such code can't generate a valid AST // so we need to strip the suffix, run this function's logic and // add back the dot to the result if present - const result = findExpressionCompleteTarget(code.slice(0, -1)); + const result = findExpressionCompleteTarget(StringPrototypeSlice(code, 0, -1)); return !result ? result : `${result}.`; } @@ -587,7 +587,7 @@ function findExpressionCompleteTarget(code) { // want to potentially complete on, so let's re-run the function's logic on that if (lastBodyStatement.type === 'ExpressionStatement' && lastBodyStatement.expression.right) { const exprRight = lastBodyStatement.expression.right; - const exprRightCode = code.slice(exprRight.start, exprRight.end); + const exprRightCode = StringPrototypeSlice(code, exprRight.start, exprRight.end); return findExpressionCompleteTarget(exprRightCode); } @@ -599,7 +599,7 @@ function findExpressionCompleteTarget(code) { // If there is no initialization we can simply return return null; } - const lastDeclarationInitCode = code.slice(lastDeclarationInit.start, lastDeclarationInit.end); + const lastDeclarationInitCode = StringPrototypeSlice(code, lastDeclarationInit.start, lastDeclarationInit.end); return findExpressionCompleteTarget(lastDeclarationInitCode); } @@ -609,7 +609,7 @@ function findExpressionCompleteTarget(code) { lastBodyStatement.expression.type === 'UnaryExpression' && lastBodyStatement.expression.argument) { const argument = lastBodyStatement.expression.argument; - const argumentCode = code.slice(argument.start, argument.end); + const argumentCode = StringPrototypeSlice(code, argument.start, argument.end); return findExpressionCompleteTarget(argumentCode); } @@ -619,7 +619,7 @@ function findExpressionCompleteTarget(code) { lastBodyStatement.expression.type === 'NewExpression' && lastBodyStatement.expression.callee) { const callee = lastBodyStatement.expression.callee; - const calleeCode = code.slice(callee.start, callee.end); + const calleeCode = StringPrototypeSlice(code, callee.start, callee.end); return findExpressionCompleteTarget(calleeCode); } @@ -641,7 +641,7 @@ function findExpressionCompleteTarget(code) { // If any of the above early returns haven't activated then it means that // the potential complete target is the full code (e.g. the code represents // a simple partial identifier, a member expression, etc...) - return code.slice(lastBodyStatement.start, lastBodyStatement.end); + return StringPrototypeSlice(code, lastBodyStatement.start, lastBodyStatement.end); } /** @@ -667,7 +667,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) { // The object itself is a member expression, so we need to recurse (e.g. the expression is `obj.foo.bar`) return includesProxiesOrGetters( expr.object, - exprStr.slice(0, expr.object.end), + StringPrototypeSlice(exprStr, 0, expr.object.end), evalFn, ctx, (includes, lastEvaledObj) => { @@ -748,7 +748,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) { // Arguably this behavior should not be too surprising, but if it turns out that it is, // then we can revisit this behavior and add logic to analyze the property expression // and eval it only if we can confidently say that it can't have any side effects - `try { ${exprStr.slice(astProp.start, astProp.end)} } catch {} `, + `try { ${StringPrototypeSlice(exprStr, astProp.start, astProp.end)} } catch {} `, ctx, getREPLResourceName(), (err, evaledProp) => {