on master help sign in
Temporarily bundle the JS in the wasm binary and eval it

This is a temporary stop gap until we have local js snippets: https://github.com/rustwasm/rfcs/pull/6

commit08b0abf923f9d2fef0f5befc836eb0ccfc1eb8e8 authorNick Fitzgerald <fitzgen@gmail.com> dateTue 15 Jan 2019, 15:21 (8 years ago) parent92298cf
2 files changed+18−4
js/change-list.js+3−1 src/change_list.rs+15−3
js/change-list.js+3−1
@@ -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+15−3
@@ -1,10 +1,11 @@
11use bumpalo::{Bump, BumpAllocSafe};
2+use std::sync::Once;
23use wasm_bindgen::prelude::*;
34
45pub 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;
@@ -12,10 +13,10 @@ pub mod js {
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
2829impl 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 }