MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / runJSify

Function runJSify

src/jsifier.mjs:386–975  ·  view source on GitHub ↗
(outputFile, symbolsOnly)

Source from the content-addressed store, hash-verified

384const PROXY_SYNC_ASYNC = 2;
385
386export async function runJSify(outputFile, symbolsOnly) {
387 const libraryItems = [];
388 const symbolDeps = {};
389 const asyncFuncs = [];
390 let postSets = [];
391
392 LibraryManager.load();
393
394 let outputHandle = process.stdout;
395 if (outputFile) {
396 outputHandle = await fs.open(outputFile, 'w');
397 }
398
399 async function writeOutput(str) {
400 // Unmangle previously mangled `import.meta` references.
401 // See also: `mangleUnsupportedSyntax` in parseTools.mjs.
402 if (EXPORT_ES6) {
403 str = str.replaceAll('EMSCRIPTEN$IMPORT$META', 'import.meta');
404 }
405
406 await outputHandle.write(str + '\n');
407 }
408
409 const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE;
410 symbolsNeeded.push(...extraLibraryFuncs);
411 for (const sym of EXPORTED_RUNTIME_METHODS) {
412 if ('$' + sym in LibraryManager.library) {
413 symbolsNeeded.push('$' + sym);
414 }
415 }
416
417 for (const key of Object.keys(LibraryManager.library)) {
418 if (!isDecorator(key)) {
419 if (INCLUDE_FULL_LIBRARY || EXPORTED_FUNCTIONS.has(mangleCSymbolName(key))) {
420 symbolsNeeded.push(key);
421 }
422 }
423 }
424
425 function processLibraryFunction(snippet, symbol, mangled, deps, isStub) {
426 // It is possible that when printing the function as a string on Windows,
427 // the js interpreter we are in returns the string with Windows line endings
428 // \r\n. This is undesirable, since line endings are managed in the form \n
429 // in the output for binary file writes, so make sure the endings are
430 // uniform.
431 snippet = snippet.toString().replace(/\r\n/gm, '\n');
432
433 // Is this a shorthand `foo() {}` method syntax?
434 // If so, prepend a function keyword so that it's valid syntax when extracted.
435 if (snippet.startsWith(symbol)) {
436 snippet = 'function ' + snippet;
437 }
438
439 if (isStub) {
440 return snippet;
441 }
442
443 // apply LIBRARY_DEBUG if relevant

Callers

nothing calls this directly

Calls 15

isDecoratorFunction · 0.90
errorOccuredFunction · 0.90
mangleCSymbolNameFunction · 0.85
symbolHandlerFunction · 0.85
writeOutputFunction · 0.85
finalCombinerFunction · 0.85
hasMethod · 0.80
keysMethod · 0.65
ErrorEnum · 0.50
loadMethod · 0.45
openMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected