blob: 32045cfd55d6a07fa85da8c45bcfe9a9746ada79 [file] [log] [blame]
/**
* @license
* Copyright 2015 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
// When bootstrapping struct info, we can't use the full library because
// it itself depends on the struct info information.
#if !BOOTSTRAPPING_STRUCT_INFO
assert(false, "libbootstrap.js only designed for use with BOOTSTRAPPING_STRUCT_INFO")
#endif
assert(Object.keys(LibraryManager.library).length === 0);
addToLibrary({
$callRuntimeCallbacks: () => {},
$ExitStatus: class {
name = 'ExitStatus';
constructor(status) {
this.message = `Program terminated with exit(${status})`;
this.status = status;
}
},
$exitJS__deps: ['$ExitStatus'],
$exitJS: (code) => quit_(code, new ExitStatus(code)),
$handleException: (e) => {
if (e instanceof ExitStatus || e == 'unwind') {
return EXITSTATUS;
}
quit_(1, e);
},
// printf/puts implementations for when musl is not pulled in - very
// partial, but enough for bootstrapping structInfo
printf__deps: ['$formatString', '$intArrayToString'],
printf__sig: 'ipp',
printf: (format, varargs) => {
// int printf(const char *restrict format, ...);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
// extra effort to support printf, even without a filesystem. very partial, very hackish
var result = formatString(format, varargs);
var string = intArrayToString(result);
if (string.endsWith('\n')) string = string.slice(0, -1); // remove a final \n, as Module.print will do that
out(string);
return result.length;
},
puts__sig: 'ip',
puts: (s) => {
// extra effort to support puts, even without a filesystem. very partial, very hackish
var result = UTF8ToString(s);
var string = result;
if (string.endsWith('\n')) string = string.slice(0, -1); // remove a final \n, as Module.print will do that
out(string);
return result.length;
},
});