mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
remove std::fmt::debug
This commit is contained in:
parent
9b15201b25
commit
dfa91d5bb4
3 changed files with 25 additions and 14 deletions
|
@ -22,7 +22,7 @@ else
|
|||
: "${FEATURES:=}"
|
||||
fi
|
||||
|
||||
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+simd128 -Zlocation-detail=none' cargo build --lib --target wasm32-unknown-unknown -Z build-std=panic_abort,std -Z build-std-features=panic_immediate_abort --no-default-features --features "$FEATURES" --release
|
||||
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+simd128 -Zlocation-detail=none -Zfmt-debug=none' cargo build --lib --target wasm32-unknown-unknown -Z build-std=panic_abort,std -Z build-std-features=panic_immediate_abort --no-default-features --features "$FEATURES" --release
|
||||
wasm-bindgen --target web --out-dir out/ target/wasm32-unknown-unknown/release/rewriter.wasm
|
||||
|
||||
sed -i 's/import.meta.url/""/g' out/rewriter.js
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use js_sys::Error;
|
||||
use thiserror::Error;
|
||||
use wasm_bindgen::{JsError, JsValue};
|
||||
|
||||
|
@ -20,7 +21,7 @@ pub enum RewriterError {
|
|||
|
||||
impl From<JsValue> for RewriterError {
|
||||
fn from(value: JsValue) -> Self {
|
||||
Self::Js(format!("{:?}", value))
|
||||
Self::Js(Error::from(value).to_string().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,16 +32,16 @@ impl From<RewriterError> for JsValue {
|
|||
}
|
||||
|
||||
impl RewriterError {
|
||||
pub fn not_str(x: &str, obj: &JsValue) -> Self {
|
||||
Self::Not(format!("{:?} in {:?}", x, obj), "string")
|
||||
pub fn not_str(x: &str) -> Self {
|
||||
Self::Not(x.to_string(), "string")
|
||||
}
|
||||
|
||||
pub fn not_fn(obj: JsValue) -> Self {
|
||||
Self::Not(format!("{:?}", obj), "function")
|
||||
pub fn not_fn(x: &str) -> Self {
|
||||
Self::Not(x.to_string(), "function")
|
||||
}
|
||||
|
||||
pub fn not_bool(obj: &JsValue) -> Self {
|
||||
Self::Not(format!("{:?}", obj), "bool")
|
||||
pub fn not_bool(x: &str) -> Self {
|
||||
Self::Not(x.to_string(), "bool")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ fn get_obj(obj: &JsValue, k: &str) -> Result<JsValue> {
|
|||
fn get_str(obj: &JsValue, k: &str) -> Result<String> {
|
||||
Reflect::get(obj, &k.into())?
|
||||
.as_string()
|
||||
.ok_or_else(|| RewriterError::not_str(k, obj))
|
||||
.ok_or_else(|| RewriterError::not_str(k))
|
||||
}
|
||||
|
||||
fn set_obj(obj: &Object, k: &str, v: &JsValue) -> Result<()> {
|
||||
|
@ -74,14 +74,14 @@ fn set_obj(obj: &Object, k: &str, v: &JsValue) -> Result<()> {
|
|||
fn get_flag(scramjet: &Object, url: &str, flag: &str) -> Result<bool> {
|
||||
let fenabled = get_obj(scramjet, "flagEnabled")?
|
||||
.dyn_into::<Function>()
|
||||
.map_err(RewriterError::not_fn)?;
|
||||
.map_err(|_| RewriterError::not_fn("scramjet.flagEnabled"))?;
|
||||
let ret = fenabled.call2(
|
||||
&JsValue::NULL,
|
||||
&flag.into(),
|
||||
&web_sys::Url::new(url)?.into(),
|
||||
)?;
|
||||
|
||||
ret.as_bool().ok_or_else(|| RewriterError::not_bool(&ret))
|
||||
ret.as_bool().ok_or_else(|| RewriterError::not_bool("scramjet.flagEnabled return value"))
|
||||
}
|
||||
|
||||
fn get_config(scramjet: &Object, url: &str) -> Result<Config> {
|
||||
|
@ -123,7 +123,7 @@ fn create_rewriter_output(
|
|||
let errs: Vec<_> = out
|
||||
.1
|
||||
.into_iter()
|
||||
.map(|x| format!("{:?}", x.with_source_code(src.clone())))
|
||||
.map(|x| format!("{}", x.with_source_code(src.clone())))
|
||||
.collect();
|
||||
|
||||
let obj = Object::new();
|
||||
|
@ -145,7 +145,12 @@ pub fn rewrite_js(
|
|||
scramjet: &Object,
|
||||
) -> Result<RewriterOutput> {
|
||||
let before = Instant::now();
|
||||
let out = rewrite(&js, Url::from_str(url)?, scramtag(), get_config(scramjet, url)?)?;
|
||||
let out = rewrite(
|
||||
&js,
|
||||
Url::from_str(url)?,
|
||||
scramtag(),
|
||||
get_config(scramjet, url)?,
|
||||
)?;
|
||||
let after = Instant::now();
|
||||
|
||||
create_rewriter_output(out, script_url, js, after - before)
|
||||
|
@ -162,7 +167,12 @@ pub fn rewrite_js_from_arraybuffer(
|
|||
let js = unsafe { String::from_utf8_unchecked(js) };
|
||||
|
||||
let before = Instant::now();
|
||||
let out = rewrite(&js, Url::from_str(url)?, scramtag(), get_config(scramjet, url)?)?;
|
||||
let out = rewrite(
|
||||
&js,
|
||||
Url::from_str(url)?,
|
||||
scramtag(),
|
||||
get_config(scramjet, url)?,
|
||||
)?;
|
||||
let after = Instant::now();
|
||||
|
||||
create_rewriter_output(out, script_url, js, after - before)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue