mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 23:50:02 -04:00
cargo fmt
This commit is contained in:
parent
3d1b5b4c09
commit
9ad3faa331
4 changed files with 478 additions and 472 deletions
|
@ -9,52 +9,52 @@ use wasm_bindgen::prelude::*;
|
|||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
fn log(s: &str);
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
fn log(s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn init() {
|
||||
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
}
|
||||
|
||||
fn create_encode_function(encode: Function) -> EncodeFn {
|
||||
Box::new(move |str| {
|
||||
encode
|
||||
.call1(&JsValue::NULL, &str.into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
})
|
||||
Box::new(move |str| {
|
||||
encode
|
||||
.call1(&JsValue::NULL, &str.into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
})
|
||||
}
|
||||
|
||||
fn get_str(config: &Object, k: &str) -> String {
|
||||
Reflect::get(config, &k.into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap()
|
||||
Reflect::get(config, &k.into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn get_config(config: Object) -> Config {
|
||||
Config {
|
||||
prefix: get_str(&config, "prefix"),
|
||||
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap().into()),
|
||||
wrapfn: get_str(&config, "wrapfn"),
|
||||
importfn: get_str(&config, "importfn"),
|
||||
rewritefn: get_str(&config, "rewritefn"),
|
||||
}
|
||||
Config {
|
||||
prefix: get_str(&config, "prefix"),
|
||||
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap().into()),
|
||||
wrapfn: get_str(&config, "wrapfn"),
|
||||
importfn: get_str(&config, "importfn"),
|
||||
rewritefn: get_str(&config, "rewritefn"),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn rewrite_js(js: &str, url: &str, config: Object) -> Vec<u8> {
|
||||
rewrite(js, Url::from_str(url).unwrap(), get_config(config))
|
||||
rewrite(js, Url::from_str(url).unwrap(), get_config(config))
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn rewrite_js_from_arraybuffer(js: &[u8], url: &str, config: Object) -> Vec<u8> {
|
||||
// we know that this is a valid utf-8 string
|
||||
let js = unsafe { std::str::from_utf8_unchecked(js) };
|
||||
// we know that this is a valid utf-8 string
|
||||
let js = unsafe { std::str::from_utf8_unchecked(js) };
|
||||
|
||||
rewrite(js, Url::from_str(url).unwrap(), get_config(config))
|
||||
rewrite(js, Url::from_str(url).unwrap(), get_config(config))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue