Skip to content

Commit e8b023c

Browse files
authored
Fixed deno support. (#3990)
1 parent ee01548 commit e8b023c

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090

9191
* Fix MDN links to static interface methods.
9292
[#4010](https://github.com/rustwasm/wasm-bindgen/pull/4010)
93+
94+
* Fixed Deno support.
95+
[#3990](https://github.com/rustwasm/wasm-bindgen/pull/3990)
9396

9497
--------------------------------------------------------------------------------
9598

crates/cli-support/src/js/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ impl<'a> Context<'a> {
345345
}}
346346
347347
const wasmInstance = (await WebAssembly.instantiate(wasmCode, imports)).instance;
348-
const wasm = wasmInstance.exports;",
348+
const wasm = wasmInstance.exports;
349+
export const __wasm = wasm;",
349350
module_name = module_name
350351
)
351352
}

crates/cli/src/bin/wasm-bindgen-test-runner/deno.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ pub fn execute(
1818
1919
{console_override}
2020
21-
// global.__wbg_test_invoke = f => f();
21+
window.__wbg_test_invoke = f => f();
2222
2323
// Forward runtime arguments. These arguments are also arguments to the
2424
// `wasm-bindgen-test-runner` which forwards them to deno which we
2525
// forward to the test harness. this is basically only used for test
2626
// filters for now.
27-
cx.args(Deno.args.slice(1));
28-
29-
const ok = await cx.run(tests.map(n => wasm.__wasm[n]));
30-
if (!ok) Deno.exit(1);
27+
cx.args(Deno.args);
3128
3229
const tests = [];
3330
"#,
@@ -39,6 +36,11 @@ pub fn execute(
3936
js_to_execute.push_str(&format!("tests.push('{}')\n", test));
4037
}
4138

39+
js_to_execute.push_str(
40+
r#"const ok = await cx.run(tests.map(n => wasm.__wasm[n]));
41+
if (!ok) Deno.exit(1);"#,
42+
);
43+
4244
let js_path = tmpdir.join("run.js");
4345
fs::write(&js_path, js_to_execute).context("failed to write JS file")?;
4446

crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use anyhow::{bail, format_err, Context, Error};
33
use log::{debug, warn};
44
use rouille::url::Url;
55
use serde::{Deserialize, Serialize};
6-
use serde_json::{self, json, Map, Value as Json};
6+
use serde_json::{json, Map, Value as Json};
77
use std::env;
88
use std::fs::File;
99
use std::io::{self, Read};

crates/cli/src/bin/wasm-bindgen-test-runner/node.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ wrap("info");
3030
wrap("warn");
3131
wrap("error");
3232
33-
cx = new wasm.WasmBindgenTestContext();
33+
const cx = new wasm.WasmBindgenTestContext();
3434
handlers.on_console_debug = wasm.__wbgtest_console_debug;
3535
handlers.on_console_log = wasm.__wbgtest_console_log;
3636
handlers.on_console_info = wasm.__wbgtest_console_info;
@@ -117,7 +117,10 @@ pub fn execute(
117117
#[cfg(unix)]
118118
pub fn exec(cmd: &mut Command) -> Result<(), Error> {
119119
use std::os::unix::prelude::*;
120-
Err(Error::from(cmd.exec()).context("failed to execute `node`"))
120+
Err(Error::from(cmd.exec()).context(format!(
121+
"failed to execute `{}`",
122+
cmd.get_program().to_string_lossy()
123+
)))
121124
}
122125

123126
#[cfg(windows)]

crates/test/src/rt/detect.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ extern "C" {
1212
#[wasm_bindgen(method, getter, structural)]
1313
fn constructor(me: &Scope) -> Constructor;
1414

15+
#[wasm_bindgen(method, getter, structural, js_name = Deno)]
16+
fn deno(me: &Scope) -> Option<Deno>;
17+
18+
type Deno;
19+
1520
type Constructor;
1621
#[wasm_bindgen(method, getter, structural)]
1722
fn name(me: &Constructor) -> String;
@@ -27,7 +32,10 @@ pub fn detect() -> Runtime {
2732
"DedicatedWorkerGlobalScope"
2833
| "SharedWorkerGlobalScope"
2934
| "ServiceWorkerGlobalScope" => Runtime::Worker,
30-
_ => Runtime::Browser,
35+
_ => match scope.deno() {
36+
Some(_) => Runtime::Node,
37+
_ => Runtime::Browser,
38+
},
3139
},
3240
None => Runtime::Node,
3341
}

0 commit comments

Comments
 (0)