Skip to content

Commit

Permalink
Move arrayUtils into libstrings.js (emscripten-core#23490)
Browse files Browse the repository at this point in the history
Prior to emscripten-core#23297 it needed to be in its own file, but that is no longer
that case.
  • Loading branch information
sbc100 authored Jan 24, 2025
1 parent cad8aea commit 6870ed4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 35 deletions.
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default [{
'src/settings_internal.js',
'src/growableHeap.js',
'src/emrun_prejs.js',
'src/arrayUtils.js',
'src/deterministic.js',
'src/base64Decode.js',
'src/proxyWorker.js',
Expand Down
29 changes: 0 additions & 29 deletions src/arrayUtils.js

This file was deleted.

26 changes: 22 additions & 4 deletions src/lib/libstrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* SPDX-License-Identifier: MIT
*/

#include "arrayUtils.js"

addToLibrary({
// TextDecoder constructor defaults to UTF-8
#if TEXTDECODER == 2
Expand Down Expand Up @@ -256,8 +254,28 @@ addToLibrary({
$intArrayFromString__docs: '/** @type {function(string, boolean=, number=)} */',
$intArrayFromString__deps: ['$lengthBytesUTF8', '$stringToUTF8Array'],
$intArrayFromString: intArrayFromString,
$intArrayToString: intArrayToString,
$intArrayFromString: (stringy, dontAddNull, length) => {
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
var u8array = new Array(len);
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
if (dontAddNull) u8array.length = numBytesWritten;
return u8array;
},
$intArrayToString: (array) => {
var ret = [];
for (var i = 0; i < array.length; i++) {
var chr = array[i];
if (chr > 0xFF) {
#if ASSERTIONS
assert(false, `Character code ${chr} (${String.fromCharCode(chr)}) at offset ${i} not in 0x00-0xFF.`);
#endif
chr &= 0xFF;
}
ret.push(String.fromCharCode(chr));
}
return ret.join('');
},

// Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the
// emscripten HEAP, returns a copy of that string as a Javascript String
Expand Down
2 changes: 1 addition & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -4924,7 +4924,7 @@ def test_jslib_include(self):
''')
create_file('foo.js', '''
// Include a file from system directory
#include "arrayUtils.js"
#include "IDBStore.js"
// Include a local file.
#include "inc.js"
''')
Expand Down

0 comments on commit 6870ed4

Please sign in to comment.