-
-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move stack switching logic into a new stack switching folder. (#3987)
This is a minor rearrangment. I renamed "continuations" stuff to "stack_switching" and made a new folder for stack switching logic. I also added logic in esbuild.config.mjs to calculate which functions exported from stack_switching.mjs and automatically copy them to Module and into the Emscripten namespace. This makes unit testing a little neater since there is no modification of the Module object.
- Loading branch information
Showing
11 changed files
with
82 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Bundle the stack switching folder as iife and then export names exported from | ||
* stack_switching.mjs onto Module and into the Emscripten namespace. | ||
*/ | ||
|
||
import { build } from "esbuild"; | ||
import { dirname, join } from "node:path"; | ||
|
||
const __dirname = dirname(new URL(import.meta.url).pathname); | ||
|
||
const outfile = join(__dirname, "stack_switching.out.js"); | ||
const globalName = "StackSwitching"; | ||
|
||
const config = { | ||
entryPoints: [join(__dirname, "stack_switching.mjs")], | ||
outfile, | ||
format: "iife", | ||
bundle: true, | ||
globalName, | ||
metafile: true, | ||
}; | ||
|
||
// First build as "esm" to get the list of exports. The metafile doesn't list | ||
// exports except when we set `format: "esm"`. Setting bundle: false saves a | ||
// tiny amount of time on this pass. | ||
const { metafile } = await build( | ||
Object.assign({}, config, { format: "esm", bundle: false }), | ||
); | ||
|
||
// The file name is the metafile.outputs key. It is relative to the current | ||
// working directory, so it's annoying to work it out. There will only be one | ||
// key in any case, so we just extract it with Object.values(). | ||
const exports = Object.values(metafile.outputs)[0].exports; | ||
|
||
// Add a footer that destructures the exports into the Emscripten namespace. | ||
// Also Object.assign them onto Module. | ||
const footer = ` | ||
const {${exports}} = ${globalName}; | ||
Object.assign(Module, ${globalName}); | ||
`.replaceAll(/\s/g, ""); | ||
config.footer = { js: footer }; | ||
|
||
// Build again, this time as an iife bundle with our extra footer. | ||
await build(config); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Files exported from here are copied into the Emscripten namespace. | ||
* See esbuild.config.mjs. | ||
*/ | ||
|
||
import { | ||
jsWrapperTag, | ||
wrapException, | ||
adjustWasmImports, | ||
} from "./create_invokes.mjs"; | ||
|
||
export { jsWrapperTag }; | ||
|
||
if (jsWrapperTag) { | ||
Module.adjustWasmImports = adjustWasmImports; | ||
Module.wrapException = wrapException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.