Skip to content

Commit 6870ed4

Browse files
authored
Move arrayUtils into libstrings.js (#23490)
Prior to #23297 it needed to be in its own file, but that is no longer that case.
1 parent cad8aea commit 6870ed4

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default [{
5454
'src/settings_internal.js',
5555
'src/growableHeap.js',
5656
'src/emrun_prejs.js',
57-
'src/arrayUtils.js',
5857
'src/deterministic.js',
5958
'src/base64Decode.js',
6059
'src/proxyWorker.js',

src/arrayUtils.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/lib/libstrings.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
#include "arrayUtils.js"
8-
97
addToLibrary({
108
// TextDecoder constructor defaults to UTF-8
119
#if TEXTDECODER == 2
@@ -256,8 +254,28 @@ addToLibrary({
256254
257255
$intArrayFromString__docs: '/** @type {function(string, boolean=, number=)} */',
258256
$intArrayFromString__deps: ['$lengthBytesUTF8', '$stringToUTF8Array'],
259-
$intArrayFromString: intArrayFromString,
260-
$intArrayToString: intArrayToString,
257+
$intArrayFromString: (stringy, dontAddNull, length) => {
258+
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
259+
var u8array = new Array(len);
260+
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
261+
if (dontAddNull) u8array.length = numBytesWritten;
262+
return u8array;
263+
},
264+
265+
$intArrayToString: (array) => {
266+
var ret = [];
267+
for (var i = 0; i < array.length; i++) {
268+
var chr = array[i];
269+
if (chr > 0xFF) {
270+
#if ASSERTIONS
271+
assert(false, `Character code ${chr} (${String.fromCharCode(chr)}) at offset ${i} not in 0x00-0xFF.`);
272+
#endif
273+
chr &= 0xFF;
274+
}
275+
ret.push(String.fromCharCode(chr));
276+
}
277+
return ret.join('');
278+
},
261279

262280
// Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the
263281
// emscripten HEAP, returns a copy of that string as a Javascript String

test/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4924,7 +4924,7 @@ def test_jslib_include(self):
49244924
''')
49254925
create_file('foo.js', '''
49264926
// Include a file from system directory
4927-
#include "arrayUtils.js"
4927+
#include "IDBStore.js"
49284928
// Include a local file.
49294929
#include "inc.js"
49304930
''')

0 commit comments

Comments
 (0)