feat(quickjs): add quickjs sample
This commit is contained in:
77
quickjs/Cargo.lock
generated
Normal file
77
quickjs/Cargo.lock
generated
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.58"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "copy_dir"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e4281031634644843bd2f5aa9c48cf98fc48d6b083bd90bb11becf10deaf8b0"
|
||||||
|
dependencies = [
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kernel32-sys"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
"winapi-build",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libquickjs-sys"
|
||||||
|
version = "0.7.0"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"copy_dir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-js"
|
||||||
|
version = "0.3.5-alpha.0"
|
||||||
|
dependencies = [
|
||||||
|
"libquickjs-sys",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quickjs"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"quick-js",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "walkdir"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780"
|
||||||
|
dependencies = [
|
||||||
|
"kernel32-sys",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-build"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
||||||
10
quickjs/Cargo.toml
Normal file
10
quickjs/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "quickjs"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
quick-js = { path= "external/quickjs-rs" }
|
||||||
@@ -1571,9 +1571,12 @@ static inline uint8_t *js_get_stack_pointer(void)
|
|||||||
|
|
||||||
static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
|
static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
|
||||||
{
|
{
|
||||||
size_t size;
|
// stackoverflow patch
|
||||||
|
// size_t size;
|
||||||
|
ptrdiff_t size;
|
||||||
size = rt->stack_top - js_get_stack_pointer();
|
size = rt->stack_top - js_get_stack_pointer();
|
||||||
return unlikely((size + alloca_size) > rt->stack_size);
|
// return unlikely((size + alloca_size) > rt->stack_size);
|
||||||
|
return unlikely((size + (ptrdiff_t)alloca_size) > (ptrdiff_t)rt->stack_size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
14
quickjs/src/main.rs
Normal file
14
quickjs/src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use quick_js::Context;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let context = Context::new().unwrap();
|
||||||
|
|
||||||
|
let value = context.eval("1 + 2").unwrap();
|
||||||
|
println!("js: 1 + 2 = {:?}", value);
|
||||||
|
|
||||||
|
context.add_callback("myCallback", |a: i32, b: i32| a + b * b).unwrap();
|
||||||
|
let script = r#" var x = myCallback(10, 20); x; "#;
|
||||||
|
|
||||||
|
let value = context.eval(script).unwrap();
|
||||||
|
println!("js: callback = {:?}", value);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user