mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 05:04:48 +00:00
fix(op_crates/web): Use "deno:" URLs for internal script specifiers (#7383)
This commit is contained in:
parent
c14436a424
commit
b17a5fbcfa
10 changed files with 73 additions and 29 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
[package]
|
||||
name = "deno_web"
|
||||
version = "0.7.0"
|
||||
version = "0.7.1"
|
||||
edition = "2018"
|
||||
description = "Collection of Web APIs"
|
||||
authors = ["the Deno authors"]
|
||||
|
|
|
@ -2,30 +2,32 @@
|
|||
|
||||
use deno_core::js_check;
|
||||
use deno_core::JsRuntime;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn init(isolate: &mut JsRuntime) {
|
||||
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let files = vec![
|
||||
get_path("00_dom_exception.js"),
|
||||
get_path("01_event.js"),
|
||||
get_path("02_abort_signal.js"),
|
||||
get_path("08_text_encoding.js"),
|
||||
manifest_dir.join("00_dom_exception.js"),
|
||||
manifest_dir.join("01_event.js"),
|
||||
manifest_dir.join("02_abort_signal.js"),
|
||||
manifest_dir.join("08_text_encoding.js"),
|
||||
];
|
||||
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
|
||||
// workspace root.
|
||||
let display_root = manifest_dir.parent().unwrap().parent().unwrap();
|
||||
for file in files {
|
||||
println!("cargo:rerun-if-changed={}", file.display());
|
||||
let display_path = file.strip_prefix(display_root).unwrap();
|
||||
let display_path_str = display_path.display().to_string();
|
||||
js_check(isolate.execute(
|
||||
&file.to_string_lossy(),
|
||||
&("deno:".to_string() + &display_path_str.replace('\\', "/")),
|
||||
&std::fs::read_to_string(&file).unwrap(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_declaration() -> PathBuf {
|
||||
get_path("lib.deno_web.d.ts")
|
||||
}
|
||||
|
||||
fn get_path(file_name: &str) -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(file_name)
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_web.d.ts")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -78,6 +80,25 @@ mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_event_error() {
|
||||
run_in_task(|mut cx| {
|
||||
let mut isolate = setup();
|
||||
let result = isolate.execute("foo.js", "new Event()");
|
||||
if let Err(error) = result {
|
||||
let error_string = error.to_string();
|
||||
// Test that the script specifier is a URL: `deno:<repo-relative path>`.
|
||||
assert!(error_string.starts_with("deno:op_crates/web/01_event.js"));
|
||||
assert!(error_string.contains("Uncaught TypeError"));
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
if let Poll::Ready(Err(_)) = isolate.poll_unpin(&mut cx) {
|
||||
unreachable!();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_event_target() {
|
||||
run_in_task(|mut cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue