Skip to content

Move runtime_strings.js code into library_strings.js #19097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ See docs/process.md for more on how version tagging works.

3.1.35 (in development)
-----------------------
- The following JavaScript runtime functions were converted to JavaScript
library functions:
- UTF8ArrayToString
- UTF8ToString
- stringToUTF8Array
- stringToUTF8
- lengthBytesUTF8
If you use any of these functions in your JS code you will now need to include
them explictly in one of the following ways:
- Add them to a `__deps` entry in your JS library file (with leading $)
- Add them to `DEFAULT_LIBRARY_FUNCS_TO_INCLUDE` (with leading $)
- Add them to `EXPORTED_FUNCTIONS` (without leading $)
- Set `-sLEGACY_RUNTIME` to include all of them at once.
- `FS.loadFilesFromDB` and `FS.saveFilesToDB` were removed. We think it's
unlikly there were any users of these functions since there is now a separate
IDBFS filesystem for folks that want persistence. (#19049)
Expand Down
3 changes: 2 additions & 1 deletion src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ var LibraryEmbind = {
_embind_register_std_string__sig: 'vpp',
_embind_register_std_string__deps: [
'$readLatin1String', '$registerType',
'$simpleReadValueFromPointer', '$throwBindingError'],
'$simpleReadValueFromPointer', '$throwBindingError',
'$stringToUTF8', '$lengthBytesUTF8'],
_embind_register_std_string: function(rawType, name) {
name = readLatin1String(name);
var stdStringIsUTF8
Expand Down
7 changes: 5 additions & 2 deletions src/jsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,16 @@ function ${name}(${args}) {
function addImplicitDeps(snippet, deps) {
// There are some common dependencies that we inject automatically by
// conservatively scanning the input functions for their usage.
// Specifically, these are dependencies that are automatically generated by
// the {{{ makeDynCall }}}, and {{{ runtimeKeepalivePush/Pop }}} macros.
// Specifically, these are dependencies that are very common and would be
// burdensome to add manually to all functions.
// The first four are deps that are automatically/conditionally added
// by the {{{ makeDynCall }}}, and {{{ runtimeKeepalivePush/Pop }}} macros.
const autoDeps = [
'getDynCaller',
'getWasmTableEntry',
'runtimeKeepalivePush',
'runtimeKeepalivePop',
'UTF8ToString',
];
for (const dep of autoDeps) {
if (snippet.includes(dep + '(')) {
Expand Down
15 changes: 13 additions & 2 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ mergeInto(LibraryManager.library, {
return 0;
},

getnameinfo__deps: ['$Sockets', '$DNS', '$readSockaddr'],
getnameinfo__deps: ['$Sockets', '$DNS', '$readSockaddr', '$stringToUTF8'],
getnameinfo: function (sa, salen, node, nodelen, serv, servlen, flags) {
var info = readSockaddr(sa, salen);
if (info.errno) {
Expand Down Expand Up @@ -2305,6 +2305,7 @@ mergeInto(LibraryManager.library, {
// Mark as `noleakcheck` otherwise lsan will report the last returned string
// as a leak.
emscripten_run_script_string__noleakcheck: true,
emscripten_run_script_string__deps: ['$lengthBytesUTF8', '$stringToUTF8', 'malloc'],
emscripten_run_script_string: function(ptr) {
{{{ makeEval("var s = eval(UTF8ToString(ptr));") }}}
if (s == null) {
Expand Down Expand Up @@ -2565,7 +2566,7 @@ mergeInto(LibraryManager.library, {
return callstack;
},

emscripten_get_callstack__deps: ['$getCallstack'],
emscripten_get_callstack__deps: ['$getCallstack', '$lengthBytesUTF8', '$stringToUTF8'],
emscripten_get_callstack: function(flags, str, maxbytes) {
// Use explicit calls to from64 rather then using the __sig
// magic here. This is because the __sig wrapper uses arrow function
Expand Down Expand Up @@ -2647,6 +2648,7 @@ mergeInto(LibraryManager.library, {
debugger;
},

emscripten_print_double__deps: ['$stringToUTF8', '$lengthBytesUTF8'],
emscripten_print_double: function(x, to, max) {
var str = x + '';
if (to) return stringToUTF8(str, to, max);
Expand Down Expand Up @@ -2887,6 +2889,7 @@ mergeInto(LibraryManager.library, {
return result ? result.column || 0 : 0;
},

emscripten_get_module_name__deps: ['$stringToUTF8'],
emscripten_get_module_name: function(buf, length) {
#if MINIMAL_RUNTIME
return stringToUTF8('{{{ TARGET_BASENAME }}}.wasm', buf, length);
Expand Down Expand Up @@ -3363,6 +3366,9 @@ mergeInto(LibraryManager.library, {

// Use program_invocation_short_name and program_invocation_name in compiled
// programs. This function is for implementing them.
#if !MINIMAL_RUNTIME
_emscripten_get_progname__deps: ['$stringToUTF8'],
#endif
_emscripten_get_progname: function(str, len) {
#if !MINIMAL_RUNTIME
#if ASSERTIONS
Expand Down Expand Up @@ -3723,5 +3729,10 @@ DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push(
'$ccall',
'$cwrap',
'$ExitStatus',
'$UTF8ArrayToString',
'$UTF8ToString',
'$stringToUTF8Array',
'$stringToUTF8',
'$lengthBytesUTF8',
);
#endif
1 change: 1 addition & 0 deletions src/library_dylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ var LibraryDylink = {

// returns the side module metadata as an object
// { memorySize, memoryAlign, tableSize, tableAlign, neededDynlibs}
$getDylinkMetadata__deps: ['$UTF8ArrayToString'],
$getDylinkMetadata__internal: true,
$getDylinkMetadata: function(binary) {
var offset = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/library_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var LibraryFetch = {
$Fetch__postset: 'Fetch.staticInit();',
#endif
$Fetch: Fetch,
_emscripten_fetch_get_response_headers_length__deps: ['$lengthBytesUTF8'],
_emscripten_fetch_get_response_headers_length: fetchGetResponseHeadersLength,
_emscripten_fetch_get_response_headers__deps: ['$lengthBytesUTF8', '$stringToUTF8'],
_emscripten_fetch_get_response_headers: fetchGetResponseHeaders,
_emscripten_fetch_free: fetchFree,

Expand All @@ -30,6 +32,7 @@ var LibraryFetch = {
'$fetchXHR',
'$callUserCallback',
'$writeI53ToI64',
'$stringToUTF8',
#if FETCH_SUPPORT_INDEXEDDB
'$fetchCacheData',
'$fetchLoadCachedData',
Expand Down
5 changes: 4 additions & 1 deletion src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/

mergeInto(LibraryManager.library, {
$FS__deps: ['$randomFill', '$PATH', '$PATH_FS', '$TTY', '$MEMFS', '$asyncLoad', '$intArrayFromString',
$FS__deps: ['$randomFill', '$PATH', '$PATH_FS', '$TTY', '$MEMFS', '$asyncLoad',
'$intArrayFromString',
'$stringToUTF8Array',
'$lengthBytesUTF8',
#if LibraryManager.has('library_idbfs.js')
'$IDBFS',
#endif
Expand Down
9 changes: 5 additions & 4 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ var LibraryHTML5 = {
},
},

$registerKeyEventCallback__deps: ['$JSEvents', '$findEventTarget'],
$registerKeyEventCallback__deps: ['$JSEvents', '$findEventTarget', '$stringToUTF8'],
$registerKeyEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
#if PTHREADS
targetThread = JSEvents.getTargetThreadForEventCallback(targetThread);
Expand Down Expand Up @@ -768,7 +768,7 @@ var LibraryHTML5 = {
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},

$registerFocusEventCallback__deps: ['$JSEvents', '$findEventTarget'],
$registerFocusEventCallback__deps: ['$JSEvents', '$findEventTarget', '$stringToUTF8'],
$registerFocusEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
#if PTHREADS
targetThread = JSEvents.getTargetThreadForEventCallback(targetThread);
Expand Down Expand Up @@ -1073,7 +1073,7 @@ var LibraryHTML5 = {
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},

$fillFullscreenChangeEventData__deps: ['$JSEvents'],
$fillFullscreenChangeEventData__deps: ['$JSEvents', '$stringToUTF8'],
$fillFullscreenChangeEventData: function(eventStruct) {
var fullscreenElement = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement;
var isFullscreen = !!fullscreenElement;
Expand Down Expand Up @@ -1662,7 +1662,7 @@ var LibraryHTML5 = {
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},

$fillPointerlockChangeEventData__deps: ['$JSEvents'],
$fillPointerlockChangeEventData__deps: ['$JSEvents', '$stringToUTF8'],
$fillPointerlockChangeEventData: function(eventStruct) {
var pointerLockElement = document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement || document.msPointerLockElement;
var isPointerlocked = !!pointerLockElement;
Expand Down Expand Up @@ -2105,6 +2105,7 @@ var LibraryHTML5 = {
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},

$fillGamepadEventData__deps: ['$stringToUTF8'],
$fillGamepadEventData: function(eventStruct, e) {
{{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenGamepadEvent.timestamp, 'e.timestamp', 'double') }}};
for (var i = 0; i < e.axes.length; ++i) {
Expand Down
3 changes: 2 additions & 1 deletion src/library_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ mergeInto(LibraryManager.library, {
// in a maximum length that can be used to be secure from out of bounds
// writes.
$writeStringToMemory__docs: '/** @deprecated @param {boolean=} dontAddNull */',
$writeStringToMemory__deps: ['$lengthBytesUTF8', '$stringToUTF8'],
$writeStringToMemory: function(string, buffer, dontAddNull) {
warnOnce('writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!');

var /** @type {number} */ lastChar, /** @type {number} */ end;
if (dontAddNull) {
// stringToUTF8Array always appends null. If we don't want to do that, remember the
// stringToUTF8 always appends null. If we don't want to do that, remember the
// character that existed at the location where the null will be placed, and restore
// that after the write (below).
end = buffer + lengthBytesUTF8(string);
Expand Down
Loading