feat(quickjs): add quickjs

from: https://crates.io/crates/quick-js
This commit is contained in:
2020-07-12 12:53:57 +08:00
parent 2ff135faaa
commit ae0b65aef3
55 changed files with 91533 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
//! FFI Bindings for [quickjs](https://bellard.org/quickjs/),
//! a Javascript engine.
//! See the [quickjs](https://crates.io/crates/quickjs) crate for a high-level
//! wrapper.
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
#[cfg(test)]
mod tests {
use std::ffi::CStr;
use super::*;
// Small sanity test that starts the runtime and evaluates code.
#[test]
fn test_eval() {
unsafe {
let rt = JS_NewRuntime();
let ctx = JS_NewContext(rt);
let code_str = "1 + 1\0";
let code = CStr::from_bytes_with_nul(code_str.as_bytes()).unwrap();
let script = CStr::from_bytes_with_nul("script\0".as_bytes()).unwrap();
let value = JS_Eval(
ctx,
code.as_ptr(),
code_str.len() - 1,
script.as_ptr(),
JS_EVAL_TYPE_GLOBAL as i32,
);
assert_eq!(value.tag, 0);
assert_eq!(value.u.int32, 2);
}
}
}