mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-12 22:10:01 -04:00
pass in full scramjet config
This commit is contained in:
parent
c60645d478
commit
f0e8aed666
2 changed files with 10 additions and 12 deletions
|
@ -33,7 +33,11 @@ fn create_encode_function(encode: JsValue) -> EncodeFn {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_str(config: &Object, k: &str) -> String {
|
||||
fn get_obj(config: &JsValue, k: &str) -> JsValue {
|
||||
Reflect::get(config, &k.into()).unwrap()
|
||||
}
|
||||
|
||||
fn get_str(config: &JsValue, k: &str) -> String {
|
||||
Reflect::get(config, &k.into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
|
@ -43,7 +47,7 @@ fn get_str(config: &Object, k: &str) -> String {
|
|||
fn get_config(config: Object) -> Config {
|
||||
Config {
|
||||
prefix: get_str(&config, "prefix"),
|
||||
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap()),
|
||||
encode: create_encode_function(get_obj(&get_obj(&config, "codec"), "encode")),
|
||||
wrapfn: get_str(&config, "wrapfn"),
|
||||
importfn: get_str(&config, "importfn"),
|
||||
rewritefn: get_str(&config, "rewritefn"),
|
||||
|
|
|
@ -24,21 +24,15 @@ export function rewriteJs(js: string | ArrayBuffer, origin?: URL) {
|
|||
if ("window" in globalThis) origin ??= new URL(decodeUrl(location.href));
|
||||
|
||||
const before = performance.now();
|
||||
const cfg = {
|
||||
prefix: self.$scramjet.config.prefix,
|
||||
codec: self.$scramjet.config.codec.encode,
|
||||
wrapfn: self.$scramjet.config.wrapfn,
|
||||
trysetfn: self.$scramjet.config.trysetfn,
|
||||
importfn: self.$scramjet.config.importfn,
|
||||
rewritefn: self.$scramjet.config.rewritefn,
|
||||
};
|
||||
if (typeof js === "string") {
|
||||
js = new TextDecoder().decode(rewrite_js(js, origin.toString(), cfg));
|
||||
js = new TextDecoder().decode(
|
||||
rewrite_js(js, origin.toString(), self.$scramjet.config)
|
||||
);
|
||||
} else {
|
||||
js = rewrite_js_from_arraybuffer(
|
||||
new Uint8Array(js),
|
||||
origin.toString(),
|
||||
cfg
|
||||
self.$scramjet.config
|
||||
);
|
||||
}
|
||||
const after = performance.now();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue