Skip to content

Commit 86eef90

Browse files
authored
Add warning when legacy parseTools functions are used. NFC (#19707)
1 parent 3dbf777 commit 86eef90

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

src/library_wasmfs_jsimpl.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ mergeInto(LibraryManager.library, {
2424
return wasmFS$backends[backend].freeFile(file);
2525
},
2626

27+
_wasmfs_jsimpl_write__deps: i53ConversionDeps,
2728
_wasmfs_jsimpl_write: function(backend, file, buffer, length, {{{ defineI64Param('offset') }}}) {
28-
{{{ receiveI64ParamAsDouble('offset') }}}
29+
{{{ receiveI64ParamAsI53('offset') }}}
2930
#if ASSERTIONS
3031
assert(wasmFS$backends[backend]);
3132
#endif
3233
return wasmFS$backends[backend].write(file, buffer, length, offset);
3334
},
3435

36+
_wasmfs_jsimpl_read__deps: i53ConversionDeps,
3537
_wasmfs_jsimpl_read: function(backend, file, buffer, length, {{{ defineI64Param('offset') }}}) {
36-
{{{ receiveI64ParamAsDouble('offset') }}}
38+
{{{ receiveI64ParamAsI53('offset') }}}
3739
#if ASSERTIONS
3840
assert(wasmFS$backends[backend]);
3941
#endif
@@ -70,9 +72,9 @@ mergeInto(LibraryManager.library, {
7072
_emscripten_proxy_finish(ctx);
7173
},
7274

73-
_wasmfs_jsimpl_async_write__deps: ['emscripten_proxy_finish'],
75+
_wasmfs_jsimpl_async_write__deps: ['emscripten_proxy_finish'].concat(i53ConversionDeps),
7476
_wasmfs_jsimpl_async_write: async function(ctx, backend, file, buffer, length, {{{ defineI64Param('offset') }}}, result_p) {
75-
{{{ receiveI64ParamAsDouble('offset') }}}
77+
{{{ receiveI64ParamAsI53('offset') }}}
7678
#if ASSERTIONS
7779
assert(wasmFS$backends[backend]);
7880
#endif
@@ -81,9 +83,9 @@ mergeInto(LibraryManager.library, {
8183
_emscripten_proxy_finish(ctx);
8284
},
8385

84-
_wasmfs_jsimpl_async_read__deps: ['emscripten_proxy_finish'],
86+
_wasmfs_jsimpl_async_read__deps: ['emscripten_proxy_finish'].concat(i53ConversionDeps),
8587
_wasmfs_jsimpl_async_read: async function(ctx, backend, file, buffer, length, {{{ defineI64Param('offset') }}}, result_p) {
86-
{{{ receiveI64ParamAsDouble('offset') }}}
88+
{{{ receiveI64ParamAsI53('offset') }}}
8789
#if ASSERTIONS
8890
assert(wasmFS$backends[backend]);
8991
#endif

src/library_wasmfs_opfs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,11 @@ mergeInto(LibraryManager.library, {
410410
wasmfsOPFSProxyFinish(ctx);
411411
},
412412

413-
_wasmfs_opfs_set_size_access__deps: ['$wasmfsOPFSAccessHandles', '$wasmfsOPFSProxyFinish'],
413+
_wasmfs_opfs_set_size_access__deps: ['$wasmfsOPFSAccessHandles', '$wasmfsOPFSProxyFinish'].concat(i53ConversionDeps),
414414
_wasmfs_opfs_set_size_access: async function(ctx, accessID,
415415
{{{ defineI64Param('size') }}},
416416
errPtr) {
417-
{{{ receiveI64ParamAsDouble('size') }}};
417+
{{{ receiveI64ParamAsI53('size') }}};
418418
let accessHandle = wasmfsOPFSAccessHandles.get(accessID);
419419
try {
420420
await accessHandle.truncate(size);
@@ -425,11 +425,11 @@ mergeInto(LibraryManager.library, {
425425
wasmfsOPFSProxyFinish(ctx);
426426
},
427427

428-
_wasmfs_opfs_set_size_file__deps: ['$wasmfsOPFSFileHandles', '$wasmfsOPFSProxyFinish'],
428+
_wasmfs_opfs_set_size_file__deps: ['$wasmfsOPFSFileHandles', '$wasmfsOPFSProxyFinish'].concat(i53ConversionDeps),
429429
_wasmfs_opfs_set_size_file: async function(ctx, fileID,
430430
{{{ defineI64Param('size') }}},
431431
errPtr) {
432-
{{{ receiveI64ParamAsDouble('size') }}};
432+
{{{ receiveI64ParamAsI53('size') }}};
433433
let fileHandle = wasmfsOPFSFileHandles.get(fileID);
434434
try {
435435
let writable = await fileHandle.createWritable({keepExistingData: true});

src/parseTools_legacy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
// Should probably be renamed to `makeReturn64` but keeping this old name in
99
// case external JS library code uses this name.
1010
function makeStructuralReturn(values) {
11+
warn('use of legacy parseTools function: makeStructuralReturn');
1112
assert(values.length == 2);
1213
return 'setTempRet0(' + values[1] + '); return ' + asmCoercion(values[0], 'i32');
1314
}
1415

1516
// Replaced (at least internally) with receiveI64ParamAsI53 that does
1617
// bounds checking.
1718
function receiveI64ParamAsDouble(name) {
19+
warn('use of legacy parseTools function: receiveI64ParamAsDouble');
1820
if (WASM_BIGINT) {
1921
// Just convert the bigint into a double.
2022
return `${name} = Number(${name});`;
@@ -25,13 +27,15 @@ function receiveI64ParamAsDouble(name) {
2527
}
2628

2729
function receiveI64ParamAsI32s(name) {
30+
warn('use of legacy parseTools function: receiveI64ParamAsI32s');
2831
if (WASM_BIGINT) {
2932
return `var ${name}_low = Number(${name} & 0xffffffffn) | 0, ${name}_high = Number(${name} >> 32n) | 0;`;
3033
}
3134
return '';
3235
}
3336

3437
function stripCorrections(param) {
38+
warn('use of legacy parseTools function: stripCorrections');
3539
let m;
3640
while (true) {
3741
if (m = /^\((.*)\)$/.exec(param)) {
@@ -62,6 +66,7 @@ function stripCorrections(param) {
6266
const UNROLL_LOOP_MAX = 8;
6367

6468
function makeCopyValues(dest, src, num, type, modifier, align, sep = ';') {
69+
warn('use of legacy parseTools function: makeCopyValues');
6570
assert(typeof align === 'undefined');
6671
function unroll(type, num, jump = 1) {
6772
const setValues = range(num).map((i) => makeSetValue(dest, i * jump, makeGetValue(src, i * jump, type), type));
@@ -93,10 +98,12 @@ function makeCopyValues(dest, src, num, type, modifier, align, sep = ';') {
9398
}
9499

95100
function makeMalloc(source, param) {
101+
warn('use of legacy parseTools function: makeMalloc');
96102
return `_malloc(${param})`;
97103
}
98104

99105
function getNativeFieldSize(type) {
106+
warn('use of legacy parseTools function: getNativeFieldSize');
100107
return Math.max(getNativeTypeSize(type), POINTER_SIZE);
101108
}
102109

@@ -110,6 +117,7 @@ global.Runtime = {
110117
global.ATMAINS = [];
111118

112119
function addAtMain(code) {
120+
warn('use of legacy parseTools function: addAtMain');
113121
assert(HAS_MAIN, 'addAtMain called but program has no main function');
114122
ATMAINS.push(code);
115123
}

test/test_other.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12947,7 +12947,8 @@ def test_no_cfi(self):
1294712947

1294812948
@also_with_wasm_bigint
1294912949
def test_parseTools(self):
12950-
self.emcc_args += ['--js-library', test_file('other/test_parseTools.js')]
12950+
# Suppress js compiler warnings because we deliberately use legacy parseTools functions
12951+
self.emcc_args += ['-Wno-js-compiler', '--js-library', test_file('other/test_parseTools.js')]
1295112952
self.do_other_test('test_parseTools.c')
1295212953

1295312954
# If we run ths same test with -sASSERTIONS=2 we expect it to fail because it

0 commit comments

Comments
 (0)