Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the V8 Inspector api #49

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Cargo.lock
.vscode/*
*.o
*.a

# Debugging history.
.gdb_history

# Developer tools
.clangd*
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ license = "Redis Source Available License 2.0 (RSALv2) or the Server Side Public
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tungstenite = { version = "0.20", optional = true }
log = "0.4"
serde = { version = "=1.0.171", features = ["derive"] }
serde_derive = "=1.0.171"
serde_json = "1"
serde-aux = "4"

[build-dependencies]
bindgen = "0.59.2"
bindgen = "0.65"
vergen = { version = "8", features = ["git", "gitcl"] }
lazy_static = "1"

Expand All @@ -21,3 +27,7 @@ lazy_static = "1"
name = "v8_rs"
path = "src/lib.rs"
crate-type = ["cdylib", "rlib"]

[features]
default = ["debug-server"]
debug-server = ["tungstenite"]
50 changes: 24 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
# v8-rs
Rust wrapper for v8
Rust wrapper for the [Google V8 JavaScript Engine](https://chromium.googlesource.com/v8/v8).

Example:
## Example:

```rust
use crate::v8::*;
use v8_rs::v8::*;

// initialized v8
// Initialise the V8 engine:
v8_init_platform(1, Some("--expose-gc")).unwrap();
v8_init();

// Create a new isolate
// Create a new isolate:
let isolate = isolate::V8Isolate::new();

// Create a new isolate scope
let _h_scope = isolate.new_handlers_scope();

// Enter the isolate
// Enter the isolate created:
let i_scope = isolate.enter();

// Create the code string object
let code_str = isolate.new_string("1+1");
// Create the code string object:
let code_str = i_scope.new_string("1+1");

// Create a JS context for code invocation.
// Create a JS execution context for code invocation:""
let ctx = i_scope.new_context(None);

// Enter the created context
let ctx_scope = ctx.enter();
// Enter the created execution context:
let ctx_scope = ctx.enter(&i_scope);

// Compile the code
// Compile the code:
let script = ctx_scope.compile(&code_str).unwrap();

// Run the code
// Run the compiled code:
let res = script.run(&ctx_scope).unwrap();

// Get the result
let res_utf8 = res.to_utf8(&isolate).unwrap();
// Get the result:
let res_utf8 = res.to_utf8().unwrap();
assert_eq!(res_utf8.as_str(), "2");
```

## Build Options

Usually, just adding the crate as a dependency in your project will be enough. That said it is possible to change the following build option using evironment variables.

* V8_VERSION - will change the default V8 version to use.
* V8_UPDATE_HEADERS - will update the V8 headers according to the set version, allow to also set the following options:
* V8_HEADERS_PATH - control where to download the headers zip file, default `v8_c_api/libv8.include.zip`.
* V8_FORCE_DOWNLOAD_V8_HEADERS - download the V8 headers zip file even if it is already exists.
* V8_HEADERS_URL - url from where to download the V8 headers zip file.
* V8_MONOLITH_PATH - control where to download the V8 monolith, default `v8_c_api/libv8_monolith.a`
* V8_FORCE_DOWNLOAD_V8_MONOLITH - download the V8 monolith even if it is already exists.
* V8_MONOLITH_URL - url from where to download the V8 monolith file.
* `V8_VERSION` - will change the default V8 version to use.
* `V8_UPDATE_HEADERS` - will update the V8 headers according to the set version, allow to also set the following options:
* `V8_HEADERS_PATH` - control where to download the headers zip file, default `v8_c_api/libv8.include.zip`.
* `V8_FORCE_DOWNLOAD_V8_HEADERS` - download the V8 headers zip file even if it is already exists.
* `V8_HEADERS_URL` - url from where to download the V8 headers zip file.
* `V8_MONOLITH_PATH` - control where to download the V8 monolith, default `v8_c_api/libv8_monolith.a`
* `V8_FORCE_DOWNLOAD_V8_MONOLITH` - download the V8 monolith even if it is already exists.
* `V8_MONOLITH_URL` - url from where to download the V8 monolith file.
Loading