File tree Expand file tree Collapse file tree 13 files changed +24
-55
lines changed
Plugins/PackageToJS/Templates
Sources/JavaScriptKit/Documentation.docc/Tutorials/Hello-World/Resources Expand file tree Collapse file tree 13 files changed +24
-55
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,4 @@ xcuserdata/
9
9
.vscode
10
10
Examples /* /Bundle
11
11
Examples /* /package-lock.json
12
- / Package.resolved
12
+ Package.resolved
Original file line number Diff line number Diff line change 8
8
< body >
9
9
< script type ="module ">
10
10
import { init } from "./Bundle/index.js"
11
- init ( fetch ( new URL ( "./Bundle/main.wasm" , import . meta . url ) ) ) ;
11
+ init ( ) ;
12
12
</ script >
13
13
< h1 > Full-text Search with Actor on Web Worker</ h1 >
14
14
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 8
8
< body >
9
9
< script type ="module ">
10
10
import { init } from "./.build/plugins/PackageToJS/outputs/Package/index.js" ;
11
- await init ( fetch ( "./.build/plugins/PackageToJS/outputs/Package/main.wasm" ) ) ;
11
+ init ( ) ;
12
12
</ script >
13
13
</ body >
14
14
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 8
8
< body >
9
9
< script type ="module ">
10
10
import { init } from "./.build/plugins/PackageToJS/outputs/Package/index.js" ;
11
- await init ( fetch ( "./.build/plugins/PackageToJS/outputs/Package/main.wasm" ) ) ;
11
+ init ( ) ;
12
12
</ script >
13
13
</ body >
14
14
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 29
29
< body >
30
30
< script type ="module ">
31
31
import { init } from "./Bundle/index.js"
32
- init ( fetch ( new URL ( "./Bundle/main.wasm" , import . meta . url ) ) ) ;
32
+ init ( ) ;
33
33
</ script >
34
34
< h1 > Threading Example</ h1 >
35
35
< p >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 70
70
< body >
71
71
< script type ="module ">
72
72
import { init } from "./Bundle/index.js"
73
- init ( fetch ( new URL ( "./Bundle/main.wasm" , import . meta . url ) ) ) ;
73
+ init ( ) ;
74
74
</ script >
75
75
< h1 > OffscreenCanvas Example</ h1 >
76
76
< p >
Original file line number Diff line number Diff line change 1
- import type { Import , Export } from './instantiate.js'
1
+ import type { Export , ModuleSource } from './instantiate.js'
2
2
3
3
export type Options = {
4
4
/**
5
- * The CLI arguments to pass to the WebAssembly module
5
+ * The WebAssembly module to instantiate
6
+ *
7
+ * If not provided, the module will be fetched from the default path.
6
8
*/
7
- args ?: string [ ]
8
- /* #if USE_SHARED_MEMORY */
9
- /**
10
- * The WebAssembly memory to use (must be 'shared')
11
- */
12
- memory : WebAssembly . Memory
13
- /* #endif */
9
+ module ?: ModuleSource
14
10
}
15
11
16
12
/**
17
- * Initialize the given WebAssembly module
13
+ * Instantiate and initialize the module
18
14
*
19
- * This is a convenience function that creates an instantiator and instantiates the module.
20
- * @param moduleSource - The WebAssembly module to instantiate
21
- * @param imports - The imports to add
22
- * @param options - The options
15
+ * This is a convenience function for browser environments.
16
+ * If you need a more flexible API, see `instantiate`.
23
17
*/
24
- export declare function init (
25
- moduleSource : WebAssembly . Module | ArrayBufferView | ArrayBuffer | Response | PromiseLike < Response >
26
- ) : Promise < {
18
+ export declare function init ( options ?: Options ) : Promise < {
27
19
instance : WebAssembly . Instance ,
28
20
exports : Export
29
21
} >
Original file line number Diff line number Diff line change @@ -3,12 +3,16 @@ import { instantiate } from './instantiate.js';
3
3
import { defaultBrowserSetup /* #if USE_SHARED_MEMORY */ , createDefaultWorkerFactory /* #endif */ } from './platforms/browser.js' ;
4
4
5
5
/** @type {import('./index.d').init } */
6
- export async function init ( moduleSource ) {
7
- const options = await defaultBrowserSetup ( {
8
- module : moduleSource ,
6
+ export async function init ( options = { } ) {
7
+ let module = options . module ;
8
+ if ( ! module ) {
9
+ module = fetch ( new URL ( "@PACKAGE_TO_JS_MODULE_PATH@" , import . meta. url ) )
10
+ }
11
+ const instantiateOptions = await defaultBrowserSetup ( {
12
+ module,
9
13
/* #if USE_SHARED_MEMORY */
10
14
spawnWorker : createDefaultWorkerFactory ( )
11
15
/* #endif */
12
16
} )
13
- return await instantiate ( options ) ;
17
+ return await instantiate ( instantiateOptions ) ;
14
18
}
Original file line number Diff line number Diff line change 5
5
< title > Swift Web App</ title >
6
6
< script type ="module ">
7
7
import { init } from "./.build/plugins/PackageToJS/outputs/Package/index.js" ;
8
- await init ( fetch ( "./.build/plugins/PackageToJS/outputs/Package/main.wasm" ) ) ;
8
+ init ( ) ;
9
9
</ script >
10
10
</ head >
11
11
< body >
You can’t perform that action at this time.
0 commit comments