Skip to content

Commit fd1a6e7

Browse files
committed
!foo: use jco/pull/254
1 parent cfef3a7 commit fd1a6e7

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

crates/matrix-sdk-extensions/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
build-all-guests: build-timeline-guest
22

3-
build-timeline-guest:
3+
build-timeline-guest: transpile-timeline-guest-to-js
44
cd guests/timeline && \
55
cargo build --target wasm32-unknown-unknown --release && \
66
wasm-tools component new target/wasm32-unknown-unknown/release/timeline.wasm -o ../../timeline.wasm
77

88
transpile-timeline-guest-to-js:
9-
jco transpile --instantiation --optimize --no-typescript --out-dir guests/timeline/js/ timeline.wasm
9+
jco transpile --instantiation sync --optimize --no-typescript --out-dir guests/timeline/js/ timeline.wasm

crates/matrix-sdk-extensions/guests/timeline/js/timeline.d.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MatrixUiTimelineStd } from './interfaces/matrix-ui-timeline-std';
1+
import { MatrixUiTimelineStd } from './interfaces/matrix-ui-timeline-std.js';
22
export interface ImportObject {
33
'matrix:ui-timeline/std': typeof MatrixUiTimelineStd,
44
}
@@ -11,7 +11,7 @@ export interface Root {
1111
* returns a map of all the exports of the component.
1212
*
1313
* This function is intended to be similar to the
14-
* `WebAssembly.instantiate` function. The second `imports`
14+
* `WebAssembly.Instantiate` constructor. The second `imports`
1515
* argument is the "import object" for wasm, except here it
1616
* uses component-model-layer types instead of core wasm
1717
* integers/numbers/etc.
@@ -22,12 +22,12 @@ export interface Root {
2222
* will be invoked per core wasm module. The caller of this
2323
* function is responsible for reading the core wasm module
2424
* identified by `path` and returning its compiled
25-
* WebAssembly.Module object. This would use `compileStreaming`
26-
* on the web, for example.
25+
* `WebAssembly.Module` object. This would use the
26+
* `WebAssembly.Module` constructor on the web, for example.
2727
*/
2828
export function instantiate(
29-
compileCore: (path: string, imports: Record<string, any>) => Promise<WebAssembly.Module>,
29+
compileCore: (path: string, imports: Record<string, any>) => WebAssembly.Module,
3030
imports: ImportObject,
31-
instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => Promise<WebAssembly.Instance>
32-
): Promise<Root>;
31+
instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance
32+
): Root;
3333

crates/matrix-sdk-extensions/guests/timeline/js/timeline.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const instantiateCore = WebAssembly.Instance;
2+
13
const utf8Decoder = new TextDecoder();
24

35
const utf8Encoder = new TextEncoder();
@@ -28,14 +30,15 @@ function utf8Encode(s, realloc, memory) {
2830
return ptr;
2931
}
3032

31-
function instantiate(compileCore, imports, instantiateCore = WebAssembly.instantiate) {
33+
export function instantiate(compileCore, imports, instantiateCore = WebAssembly.Instance) {
3234
const module0 = compileCore('timeline.core.wasm');
3335
const module1 = compileCore('timeline.core2.wasm');
3436
const module2 = compileCore('timeline.core3.wasm');
37+
3538
const { print } = imports['matrix:ui-timeline/std'];
3639
let exports0;
3740
let exports1;
38-
41+
3942
function trampoline0(arg0, arg1) {
4043
const ptr0 = arg0;
4144
const len0 = arg1;
@@ -46,10 +49,7 @@ function instantiate(compileCore, imports, instantiateCore = WebAssembly.instant
4649
let exports2;
4750
let realloc0;
4851
const instanceFlags0 = new WebAssembly.Global({ value: "i32", mutable: true }, 3);
49-
// Promise.all([module0, module1, module2]).catch(() => {});
50-
51-
const m = module1;
52-
({ exports: exports0 } = instantiateCore(m /* module1 */));
52+
({ exports: exports0 } = instantiateCore(module1));
5353
({ exports: exports1 } = instantiateCore(module0, {
5454
'matrix:ui-timeline/std': {
5555
print: exports0['0'],

crates/matrix-sdk-extensions/src/javascriptcore.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ where
8686

8787
// Run the script.
8888
{
89-
let timeline_script = fs::read_to_string(js_file)
90-
.unwrap()
91-
.replace("export async function", "function")
92-
.replace(" await ", " ")
93-
.replace("(await ", "(");
89+
let timeline_script = fs::read_to_string(js_file).unwrap().replace("export ", "");
9490

9591
let _result = evaluate_script(
9692
&context,

0 commit comments

Comments
 (0)