mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
check for valid encode function
This commit is contained in:
parent
9ad3faa331
commit
f8fb713328
1 changed files with 8 additions and 3 deletions
|
@ -3,9 +3,10 @@ pub mod rewrite;
|
||||||
use std::{panic, str::FromStr};
|
use std::{panic, str::FromStr};
|
||||||
|
|
||||||
use js_sys::{Function, Object, Reflect};
|
use js_sys::{Function, Object, Reflect};
|
||||||
|
use oxc_ast::ast::Function;
|
||||||
use rewrite::{rewrite, Config, EncodeFn};
|
use rewrite::{rewrite, Config, EncodeFn};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::{prelude::*, throw_str};
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -18,7 +19,11 @@ 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 {
|
fn create_encode_function(encode: JsValue) -> EncodeFn {
|
||||||
|
let Ok(encode) = encode.dyn_into::<Function>() else {
|
||||||
|
throw_str("invalid encode function");
|
||||||
|
};
|
||||||
|
|
||||||
Box::new(move |str| {
|
Box::new(move |str| {
|
||||||
encode
|
encode
|
||||||
.call1(&JsValue::NULL, &str.into())
|
.call1(&JsValue::NULL, &str.into())
|
||||||
|
@ -39,7 +44,7 @@ fn get_str(config: &Object, k: &str) -> String {
|
||||||
fn get_config(config: Object) -> Config {
|
fn get_config(config: Object) -> Config {
|
||||||
Config {
|
Config {
|
||||||
prefix: get_str(&config, "prefix"),
|
prefix: get_str(&config, "prefix"),
|
||||||
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap().into()),
|
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap()),
|
||||||
wrapfn: get_str(&config, "wrapfn"),
|
wrapfn: get_str(&config, "wrapfn"),
|
||||||
importfn: get_str(&config, "importfn"),
|
importfn: get_str(&config, "importfn"),
|
||||||
rewritefn: get_str(&config, "rewritefn"),
|
rewritefn: get_str(&config, "rewritefn"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue