on master help sign in
Temporarily bundle the JS in the wasm binary and eval it
08b0abfNick Fitzgerald
js/change-list.js+3−1
@@ -135,7 +135,8 @@ const OP_TABLE = [
135 }
135 }
136];
136];
137
137
138+// export
138−export class ChangeList {
139+class ChangeList {
139 constructor(container) {
140 constructor(container) {
140 this.container = container;
141 this.container = container;
141 this.ranges = [];
142 this.ranges = [];
@@ -178,3 +179,4 @@ export class ChangeList {
178 }
179 }
179 }
180 }
180}
181}
182+window.ChangeList = ChangeList;
src/change_list.rs+15−3
@@ -1,10 +1,11 @@
1use bumpalo::{Bump, BumpAllocSafe};
1use bumpalo::{Bump, BumpAllocSafe};
2+use std::sync::Once;
2use wasm_bindgen::prelude::*;
3use wasm_bindgen::prelude::*;
3
4
4pub mod js {
5pub mod js {
5 use wasm_bindgen::prelude::*;
6 use wasm_bindgen::prelude::*;
6
7
7− #[wasm_bindgen(module = "dodrio/change-list")]
8+ #[wasm_bindgen]
8 extern "C" {
9 extern "C" {
9 #[derive(Clone, Debug)]
10 #[derive(Clone, Debug)]
10 pub type ChangeList;
11 pub type ChangeList;
@@ -12,10 +13,10 @@ pub mod js {
12 #[wasm_bindgen(constructor)]
13 #[wasm_bindgen(constructor)]
13 pub fn new(container: &web_sys::Node) -> ChangeList;
14 pub fn new(container: &web_sys::Node) -> ChangeList;
14
15
15− #[wasm_bindgen(method, js_name = addChangeListRange)]
16+ #[wasm_bindgen(structural, method, js_name = addChangeListRange)]
16 pub fn add_change_list_range(this: &ChangeList, start: usize, len: usize);
17 pub fn add_change_list_range(this: &ChangeList, start: usize, len: usize);
17
18
18− #[wasm_bindgen(method, js_name = applyChanges)]
19+ #[wasm_bindgen(structural, method, js_name = applyChanges)]
19 pub fn apply_changes(this: &ChangeList, memory: JsValue);
20 pub fn apply_changes(this: &ChangeList, memory: JsValue);
20 }
21 }
21}
22}
@@ -27,6 +28,17 @@ pub(crate) struct ChangeList {
27
28
28impl ChangeList {
29impl ChangeList {
29 pub(crate) fn new(container: &web_sys::Node) -> ChangeList {
30 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+
30 let bump = Bump::new();
42 let bump = Bump::new();
31 let js = js::ChangeList::new(container);
43 let js = js::ChangeList::new(container);
32 ChangeList { bump, js }
44 ChangeList { bump, js }