Skip to content

Commit 3b27120

Browse files
authored
Remove use of deprecated String.substr from the JS compiler. NFC (#23512)
1 parent 2f6d608 commit 3b27120

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/jsifier.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function mangleCSymbolName(f) {
5151
if (f === '__main_argc_argv') {
5252
f = 'main';
5353
}
54-
return f[0] == '$' ? f.substr(1) : '_' + f;
54+
return f[0] == '$' ? f.slice(1) : '_' + f;
5555
}
5656

5757
// Splits out items that pass filter. Returns also the original sans the filtered
@@ -284,7 +284,7 @@ ${argConversions}
284284

285285
// apply LIBRARY_DEBUG if relevant
286286
if (LIBRARY_DEBUG && !isJsOnlySymbol(symbol)) {
287-
snippet = modifyJSFunction(snippet, (args, body, async, oneliner) => {
287+
snippet = modifyJSFunction(snippet, (args, body, _async, oneliner) => {
288288
var run_func;
289289
if (oneliner) {
290290
run_func = `var ret = ${body}`;
@@ -637,7 +637,7 @@ function(${args}) {
637637
// emits
638638
// 'var foo = [value];'
639639
if (typeof snippet == 'string' && snippet[0] == '=') {
640-
snippet = snippet.substr(1);
640+
snippet = snippet.slice(1);
641641
}
642642
contentText = `var ${mangled} = ${snippet};`;
643643
}

src/modules.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function getUnusedLibrarySymbols() {
374374
for (const [ident, value] of Object.entries(LibraryManager.library)) {
375375
if (typeof value === 'function' || typeof value === 'number') {
376376
if (isJsOnlySymbol(ident) && !isDecorator(ident) && !isInternalSymbol(ident)) {
377-
const name = ident.substr(1);
377+
const name = ident.slice(1);
378378
if (!librarySymbolSet.has(name)) {
379379
missingSyms.add(name);
380380
}
@@ -492,7 +492,7 @@ function exportRuntime() {
492492
let runtimeElementsSet = new Set(runtimeElements);
493493
for (const ident of Object.keys(LibraryManager.library)) {
494494
if (isJsOnlySymbol(ident) && !isDecorator(ident) && !isInternalSymbol(ident)) {
495-
const jsname = ident.substr(1);
495+
const jsname = ident.slice(1);
496496
// Note that this assertion may be hit when a function is moved into the
497497
// JS library. In that case the function should be removed from the list
498498
// of runtime elements above.

src/parseTools.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ export function preprocess(filename) {
141141
showStack.push(truthy ? SHOW : IGNORE);
142142
} else if (first === '#include') {
143143
if (showCurrentLine()) {
144-
let includeFile = line.substr(line.indexOf(' ') + 1);
144+
let includeFile = line.slice(line.indexOf(' ') + 1);
145145
if (includeFile.startsWith('"')) {
146-
includeFile = includeFile.substr(1, includeFile.length - 2);
146+
includeFile = includeFile.slice(1, -1);
147147
}
148148
const absPath = findIncludeFile(includeFile, path.dirname(filename));
149149
if (!absPath) {
@@ -328,7 +328,7 @@ function getNativeTypeSize(type) {
328328
return POINTER_SIZE;
329329
}
330330
if (type[0] === 'i') {
331-
const bits = Number(type.substr(1));
331+
const bits = Number(type.slice(1));
332332
assert(bits % 8 === 0, `getNativeTypeSize invalid bits ${bits}, ${type} type`);
333333
return bits / 8;
334334
}
@@ -360,7 +360,7 @@ function ensureDot(value) {
360360
if (value.includes('.') || /[IN]/.test(value)) return value;
361361
const e = value.indexOf('e');
362362
if (e < 0) return value + '.0';
363-
return value.substr(0, e) + '.0' + value.substr(e);
363+
return value.slice(0, e) + '.0' + value.slice(e);
364364
}
365365

366366
export function isNumber(x) {
@@ -406,7 +406,7 @@ function asmFloatToInt(x) {
406406
}
407407

408408
// See makeSetValue
409-
function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align) {
409+
function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, _ignore, align) {
410410
assert(typeof align === 'undefined', 'makeGetValue no longer supports align parameter');
411411
assert(
412412
typeof noNeedFirst === 'undefined',
@@ -551,7 +551,7 @@ function getFastValue(a, op, b) {
551551

552552
if (b[0] === '-') {
553553
op = '-';
554-
b = b.substr(1);
554+
b = b.slice(1);
555555
}
556556

557557
return `(${a})${op}(${b})`;
@@ -785,14 +785,14 @@ export function modifyJSFunction(text, func) {
785785
if (match) {
786786
async_ = match[1] || '';
787787
args = match[3];
788-
rest = text.substr(match[0].length);
788+
rest = text.slice(match[0].length);
789789
} else {
790790
// Match an arrow function
791791
let match = text.match(/^\s*(var (\w+) = )?(async\s+)?\(([^)]*)\)\s+=>\s+/);
792792
if (match) {
793793
async_ = match[3] || '';
794794
args = match[4];
795-
rest = text.substr(match[0].length);
795+
rest = text.slice(match[0].length);
796796
rest = rest.trim();
797797
oneliner = rest[0] != '{';
798798
} else {
@@ -802,7 +802,7 @@ export function modifyJSFunction(text, func) {
802802
assert(match, `could not match function:\n${text}\n`);
803803
async_ = match[1] || '';
804804
args = match[2];
805-
rest = text.substr(match[0].length);
805+
rest = text.slice(match[0].length);
806806
}
807807
}
808808
let body = rest;

tools/acorn-optimizer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ const input = read(infile);
20232023
const extraInfoStart = input.lastIndexOf('// EXTRA_INFO:');
20242024
let extraInfo = null;
20252025
if (extraInfoStart > 0) {
2026-
extraInfo = JSON.parse(input.substr(extraInfoStart + 14));
2026+
extraInfo = JSON.parse(input.slice(extraInfoStart + 14));
20272027
}
20282028
// Collect all JS code comments to this map so that we can retain them in the
20292029
// outputted code if --closureFriendly was requested.

0 commit comments

Comments
 (0)