Skip to content
This repository was archived by the owner on Mar 2, 2021. It is now read-only.

Commit 08b0abf

Browse files
committed
Temporarily bundle the JS in the wasm binary and eval it
This is a temporary stop gap until we have local js snippets: rustwasm/rfcs#6
1 parent 92298cf commit 08b0abf

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

js/change-list.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ const OP_TABLE = [
135135
}
136136
];
137137

138-
export class ChangeList {
138+
// export
139+
class ChangeList {
139140
constructor(container) {
140141
this.container = container;
141142
this.ranges = [];
@@ -178,3 +179,4 @@ export class ChangeList {
178179
}
179180
}
180181
}
182+
window.ChangeList = ChangeList;

src/change_list.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
use bumpalo::{Bump, BumpAllocSafe};
2+
use std::sync::Once;
23
use wasm_bindgen::prelude::*;
34

45
pub mod js {
56
use wasm_bindgen::prelude::*;
67

7-
#[wasm_bindgen(module = "dodrio/change-list")]
8+
#[wasm_bindgen]
89
extern "C" {
910
#[derive(Clone, Debug)]
1011
pub type ChangeList;
1112

1213
#[wasm_bindgen(constructor)]
1314
pub fn new(container: &web_sys::Node) -> ChangeList;
1415

15-
#[wasm_bindgen(method, js_name = addChangeListRange)]
16+
#[wasm_bindgen(structural, method, js_name = addChangeListRange)]
1617
pub fn add_change_list_range(this: &ChangeList, start: usize, len: usize);
1718

18-
#[wasm_bindgen(method, js_name = applyChanges)]
19+
#[wasm_bindgen(structural, method, js_name = applyChanges)]
1920
pub fn apply_changes(this: &ChangeList, memory: JsValue);
2021
}
2122
}
@@ -27,6 +28,17 @@ pub(crate) struct ChangeList {
2728

2829
impl ChangeList {
2930
pub(crate) fn new(container: &web_sys::Node) -> ChangeList {
31+
// XXX: Because wasm-bindgen-test doesn't support third party JS
32+
// dependencies, we can't use `wasm_bindgen(module = "...")` for our
33+
// `ChangeList` JS import. Instead, this *should* be a local JS snippet,
34+
// but that isn't implemented yet:
35+
// https://github.com/rustwasm/rfcs/pull/6
36+
static EVAL: Once = Once::new();
37+
EVAL.call_once(|| {
38+
js_sys::eval(include_str!("../js/change-list.js"))
39+
.expect("should eval change-list.js OK");
40+
});
41+
3042
let bump = Bump::new();
3143
let js = js::ChangeList::new(container);
3244
ChangeList { bump, js }

0 commit comments

Comments
 (0)