Skip to content

Commit 1f51b7f

Browse files
authored
Merge pull request #15 from rivet-dev/ralph/v8-runtime
chore: standalone v8 process
2 parents 96137b6 + f289c03 commit 1f51b7f

75 files changed

Lines changed: 4665 additions & 5648 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/rust.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,39 @@ on:
1515
- ".github/workflows/rust.yml"
1616

1717
jobs:
18+
lint:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Rust toolchain
25+
uses: dtolnay/rust-toolchain@stable
26+
with:
27+
toolchain: "1.85.0"
28+
components: clippy, rustfmt
29+
30+
- name: Cache Rust build artifacts
31+
uses: actions/cache@v4
32+
with:
33+
path: |
34+
~/.cargo/registry
35+
~/.cargo/git
36+
crates/v8-runtime/target
37+
key: rust-lint-${{ hashFiles('crates/v8-runtime/Cargo.lock') }}
38+
restore-keys: |
39+
rust-lint-
40+
41+
- name: Check formatting
42+
working-directory: crates/v8-runtime
43+
run: cargo fmt --all -- --check
44+
45+
- name: Run clippy
46+
working-directory: crates/v8-runtime
47+
run: cargo clippy --all-targets -- -D warnings
48+
1849
build:
50+
needs: lint
1951
strategy:
2052
fail-fast: false
2153
matrix:

crates/v8-runtime/npm/darwin-arm64/package.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
{
22
"name": "@secure-exec/v8-darwin-arm64",
3-
"version": "0.1.1-rc.3",
3+
"version": "0.1.0",
44
"license": "Apache-2.0",
5-
"os": [
6-
"darwin"
7-
],
8-
"cpu": [
9-
"arm64"
10-
],
11-
"main": "install.js",
12-
"files": [
13-
"install.js"
14-
],
15-
"scripts": {
16-
"postinstall": "node install.js"
17-
},
5+
"os": ["darwin"],
6+
"cpu": ["arm64"],
7+
"main": "secure-exec-v8",
8+
"files": ["secure-exec-v8"],
189
"repository": {
1910
"type": "git",
2011
"url": "https://github.com/rivet-dev/secure-exec.git",

crates/v8-runtime/npm/darwin-x64/package.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
{
22
"name": "@secure-exec/v8-darwin-x64",
3-
"version": "0.1.1-rc.3",
3+
"version": "0.1.0",
44
"license": "Apache-2.0",
5-
"os": [
6-
"darwin"
7-
],
8-
"cpu": [
9-
"x64"
10-
],
11-
"main": "install.js",
12-
"files": [
13-
"install.js"
14-
],
15-
"scripts": {
16-
"postinstall": "node install.js"
17-
},
5+
"os": ["darwin"],
6+
"cpu": ["x64"],
7+
"main": "secure-exec-v8",
8+
"files": ["secure-exec-v8"],
189
"repository": {
1910
"type": "git",
2011
"url": "https://github.com/rivet-dev/secure-exec.git",

crates/v8-runtime/npm/linux-arm64-gnu/package.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
{
22
"name": "@secure-exec/v8-linux-arm64-gnu",
3-
"version": "0.1.1-rc.3",
3+
"version": "0.1.0",
44
"license": "Apache-2.0",
5-
"os": [
6-
"linux"
7-
],
8-
"cpu": [
9-
"arm64"
10-
],
11-
"main": "install.js",
12-
"files": [
13-
"install.js"
14-
],
15-
"scripts": {
16-
"postinstall": "node install.js"
17-
},
5+
"os": ["linux"],
6+
"cpu": ["arm64"],
7+
"main": "secure-exec-v8",
8+
"files": ["secure-exec-v8"],
189
"repository": {
1910
"type": "git",
2011
"url": "https://github.com/rivet-dev/secure-exec.git",

crates/v8-runtime/npm/linux-x64-gnu/package.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
{
22
"name": "@secure-exec/v8-linux-x64-gnu",
3-
"version": "0.1.1-rc.3",
3+
"version": "0.1.0",
44
"license": "Apache-2.0",
5-
"os": [
6-
"linux"
7-
],
8-
"cpu": [
9-
"x64"
10-
],
5+
"os": ["linux"],
6+
"cpu": ["x64"],
117
"main": "secure-exec-v8",
12-
"files": [
13-
"secure-exec-v8"
14-
],
8+
"files": ["secure-exec-v8"],
159
"repository": {
1610
"type": "git",
1711
"url": "https://github.com/rivet-dev/secure-exec.git",

crates/v8-runtime/npm/win32-x64/package.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
{
22
"name": "@secure-exec/v8-win32-x64",
3-
"version": "0.1.1-rc.3",
3+
"version": "0.1.0",
44
"license": "Apache-2.0",
5-
"os": [
6-
"win32"
7-
],
8-
"cpu": [
9-
"x64"
10-
],
11-
"main": "install.js",
12-
"files": [
13-
"install.js"
14-
],
15-
"scripts": {
16-
"postinstall": "node install.js"
17-
},
5+
"os": ["win32"],
6+
"cpu": ["x64"],
7+
"main": "secure-exec-v8.exe",
8+
"files": ["secure-exec-v8.exe"],
189
"repository": {
1910
"type": "git",
2011
"url": "https://github.com/rivet-dev/secure-exec.git",

crates/v8-runtime/src/bridge.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ pub fn serialize_v8_value(
5555
value: v8::Local<v8::Value>,
5656
) -> Result<Vec<u8>, String> {
5757
let context = scope.get_current_context();
58-
let serializer = v8::ValueSerializer::new(
59-
scope,
60-
Box::new(DefaultSerializerDelegate),
61-
);
58+
let serializer = v8::ValueSerializer::new(scope, Box::new(DefaultSerializerDelegate));
6259
serializer.write_header();
6360
serializer
6461
.write_value(context, value)
@@ -89,11 +86,8 @@ pub fn deserialize_v8_value<'s>(
8986
data: &[u8],
9087
) -> Result<v8::Local<'s, v8::Value>, String> {
9188
let context = scope.get_current_context();
92-
let deserializer = v8::ValueDeserializer::new(
93-
scope,
94-
Box::new(DefaultDeserializerDelegate),
95-
data,
96-
);
89+
let deserializer =
90+
v8::ValueDeserializer::new(scope, Box::new(DefaultDeserializerDelegate), data);
9791
deserializer
9892
.read_header(context)
9993
.ok_or_else(|| "V8 ValueDeserializer: invalid header".to_string())?;
@@ -128,6 +122,8 @@ struct SyncBridgeFnData {
128122
/// Opaque store that keeps bridge function data alive.
129123
/// Must be held for the lifetime of the V8 context.
130124
pub struct BridgeFnStore {
125+
// Box ensures stable pointer address for v8::External data when Vec grows
126+
#[allow(clippy::vec_box)]
131127
_data: Vec<Box<SyncBridgeFnData>>,
132128
}
133129

@@ -142,6 +138,8 @@ struct AsyncBridgeFnData {
142138
/// Opaque store that keeps async bridge function data alive.
143139
/// Must be held for the lifetime of the V8 context.
144140
pub struct AsyncBridgeFnStore {
141+
// Box ensures stable pointer address for v8::External data when Vec grows
142+
#[allow(clippy::vec_box)]
145143
_data: Vec<Box<AsyncBridgeFnData>>,
146144
}
147145

@@ -245,7 +243,8 @@ fn sync_bridge_callback(
245243
match serialize_v8_args_into(scope, &args, &mut bufs.ser_buf) {
246244
Ok(()) => bufs.ser_buf.clone(),
247245
Err(err) => {
248-
let msg = v8::String::new(scope, &format!("bridge serialization error: {}", err)).unwrap();
246+
let msg = v8::String::new(scope, &format!("bridge serialization error: {}", err))
247+
.unwrap();
249248
let exc = v8::Exception::error(scope, msg);
250249
scope.throw_exception(exc);
251250
return;
@@ -349,9 +348,8 @@ fn async_bridge_callback(
349348
let external = match v8::Local::<v8::External>::try_from(args.data()) {
350349
Ok(ext) => ext,
351350
Err(_) => {
352-
let msg =
353-
v8::String::new(scope, "internal error: missing async bridge function data")
354-
.unwrap();
351+
let msg = v8::String::new(scope, "internal error: missing async bridge function data")
352+
.unwrap();
355353
let exc = v8::Exception::error(scope, msg);
356354
scope.throw_exception(exc);
357355
return;
@@ -383,7 +381,8 @@ fn async_bridge_callback(
383381
match serialize_v8_args_into(scope, &args, &mut bufs.ser_buf) {
384382
Ok(()) => bufs.ser_buf.clone(),
385383
Err(err) => {
386-
let msg = v8::String::new(scope, &format!("bridge serialization error: {}", err)).unwrap();
384+
let msg = v8::String::new(scope, &format!("bridge serialization error: {}", err))
385+
.unwrap();
387386
let exc = v8::Exception::error(scope, msg);
388387
scope.throw_exception(exc);
389388
return;
@@ -449,17 +448,15 @@ pub fn register_stub_bridge_fns(
449448

450449
// Register sync bridge functions as stubs (no External data)
451450
for &method_name in sync_fns {
452-
let template = v8::FunctionTemplate::builder(sync_bridge_callback)
453-
.build(scope);
451+
let template = v8::FunctionTemplate::builder(sync_bridge_callback).build(scope);
454452
let func = template.get_function(scope).unwrap();
455453
let key = v8::String::new(scope, method_name).unwrap();
456454
global.set(scope, key.into(), func.into());
457455
}
458456

459457
// Register async bridge functions as stubs (no External data)
460458
for &method_name in async_fns {
461-
let template = v8::FunctionTemplate::builder(async_bridge_callback)
462-
.build(scope);
459+
let template = v8::FunctionTemplate::builder(async_bridge_callback).build(scope);
463460
let func = template.get_function(scope).unwrap();
464461
let key = v8::String::new(scope, method_name).unwrap();
465462
global.set(scope, key.into(), func.into());
@@ -468,7 +465,11 @@ pub fn register_stub_bridge_fns(
468465

469466
/// Serialize V8 function arguments into a pre-allocated buffer.
470467
/// The buffer is cleared and reused across calls (grows to high-water mark).
471-
fn serialize_v8_args_into(scope: &mut v8::HandleScope, args: &v8::FunctionCallbackArguments, buf: &mut Vec<u8>) -> Result<(), String> {
468+
fn serialize_v8_args_into(
469+
scope: &mut v8::HandleScope,
470+
args: &v8::FunctionCallbackArguments,
471+
buf: &mut Vec<u8>,
472+
) -> Result<(), String> {
472473
let count = args.length();
473474
let array = v8::Array::new(scope, count);
474475
for i in 0..count {

0 commit comments

Comments
 (0)