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

Function executeJSLibraryFile

src/modules.mjs:305–356  ·  view source on GitHub ↗
(filename, contents)

Source from the content-addressed store, hash-verified

303 },
304
305 executeJSLibraryFile(filename, contents) {
306 const userLibraryProxy = new Proxy(this.library, {
307 set(target, prop, value) {
308 target[prop] = value;
309 if (!isDecorator(prop)) {
310 target[prop + '__user'] = true;
311 }
312 return true;
313 },
314 });
315
316 const isUserLibrary = !isBeneath(filename, systemLibdir);
317 if (isUserLibrary) {
318 debugLog(`executing user JS library: ${filename}`);
319 } else {
320 debugLog(`exectuing system JS library: ${filename}`);
321 }
322
323 let origLibrary;
324 // When we parse user libraries also set `__user` attribute
325 // on each element so that we can distinguish them later.
326 if (isUserLibrary) {
327 origLibrary = this.library;
328 this.library = userLibraryProxy;
329 }
330 pushCurrentFile(filename);
331 let preprocessedName = filename.replace(/\.\w+$/, '.preprocessed$&')
332 if (VERBOSE) {
333 preprocessedName = path.join(getTempDir(), path.basename(filename));
334 }
335
336 try {
337 runInMacroContext(contents, {filename: preprocessedName})
338 } catch (e) {
339 error(`failure to execute JS library "${filename}":`);
340 if (VERBOSE) {
341 fs.writeFileSync(preprocessedName, contents);
342 error(`preprocessed JS saved to ${preprocessedName}`)
343 } else {
344 error('use -sVERBOSE to save preprocessed JS');
345 }
346 throw e;
347 } finally {
348 popCurrentFile();
349 if (origLibrary) {
350 this.library = origLibrary;
351 }
352 }
353 if (VERBOSE) {
354 fs.rmSync(getTempDir(), { recursive: true, force: true });
355 }
356 }
357};
358
359// options is optional input object containing mergeInto params

Callers

nothing calls this directly

Calls 8

debugLogFunction · 0.90
pushCurrentFileFunction · 0.90
runInMacroContextFunction · 0.90
errorFunction · 0.90
popCurrentFileFunction · 0.90
isBeneathFunction · 0.85
getTempDirFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected