feat: add dependency
This commit is contained in:
1
javascript-engine/external/boa/boa_wasm/.gitignore
vendored
Normal file
1
javascript-engine/external/boa/boa_wasm/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkg
|
||||
22
javascript-engine/external/boa/boa_wasm/Cargo.toml
vendored
Normal file
22
javascript-engine/external/boa/boa_wasm/Cargo.toml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "boa_wasm"
|
||||
description = "WASM compatibility layer for the Boa JavaScript engine."
|
||||
keywords = ["javascript", "compiler", "lexer", "parser", "js"]
|
||||
categories = ["parser-implementations", "wasm", "compilers"]
|
||||
publish = false
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
boa_engine = { workspace = true, features = ["console"] }
|
||||
wasm-bindgen = "0.2.83"
|
||||
getrandom = { version = "0.2.8", features = ["js"] }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
name = "boa_wasm"
|
||||
bench = false
|
||||
72
javascript-engine/external/boa/boa_wasm/src/lib.rs
vendored
Normal file
72
javascript-engine/external/boa/boa_wasm/src/lib.rs
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
//! A ECMAScript WASM implementation based on boa_engine.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg",
|
||||
html_favicon_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg"
|
||||
)]
|
||||
#![cfg_attr(not(test), forbid(clippy::unwrap_used))]
|
||||
#![warn(missing_docs, clippy::dbg_macro)]
|
||||
#![deny(
|
||||
// rustc lint groups https://doc.rust-lang.org/rustc/lints/groups.html
|
||||
warnings,
|
||||
future_incompatible,
|
||||
let_underscore,
|
||||
nonstandard_style,
|
||||
rust_2018_compatibility,
|
||||
rust_2018_idioms,
|
||||
rust_2021_compatibility,
|
||||
unused,
|
||||
|
||||
// rustc allowed-by-default lints https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html
|
||||
macro_use_extern_crate,
|
||||
meta_variable_misuse,
|
||||
missing_abi,
|
||||
missing_copy_implementations,
|
||||
missing_debug_implementations,
|
||||
non_ascii_idents,
|
||||
noop_method_call,
|
||||
single_use_lifetimes,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unreachable_pub,
|
||||
unsafe_op_in_unsafe_fn,
|
||||
unused_crate_dependencies,
|
||||
unused_import_braces,
|
||||
unused_lifetimes,
|
||||
unused_qualifications,
|
||||
unused_tuple_struct_fields,
|
||||
variant_size_differences,
|
||||
|
||||
// rustdoc lints https://doc.rust-lang.org/rustdoc/lints.html
|
||||
rustdoc::broken_intra_doc_links,
|
||||
rustdoc::private_intra_doc_links,
|
||||
rustdoc::missing_crate_level_docs,
|
||||
rustdoc::private_doc_tests,
|
||||
rustdoc::invalid_codeblock_attributes,
|
||||
rustdoc::invalid_rust_codeblocks,
|
||||
rustdoc::bare_urls,
|
||||
|
||||
// clippy categories https://doc.rust-lang.org/clippy/
|
||||
clippy::all,
|
||||
clippy::correctness,
|
||||
clippy::suspicious,
|
||||
clippy::style,
|
||||
clippy::complexity,
|
||||
clippy::perf,
|
||||
clippy::pedantic,
|
||||
clippy::nursery,
|
||||
)]
|
||||
|
||||
use boa_engine::Context;
|
||||
use getrandom as _;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Evaluate the given ECMAScript code.
|
||||
#[wasm_bindgen]
|
||||
pub fn evaluate(src: &str) -> Result<String, JsValue> {
|
||||
// Setup executor
|
||||
Context::default()
|
||||
.eval(src)
|
||||
.map_err(|e| JsValue::from(format!("Uncaught {e}")))
|
||||
.map(|v| v.display().to_string())
|
||||
}
|
||||
Reference in New Issue
Block a user