Skip to content

Commit

Permalink
use deno core (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
urbas authored Jul 20, 2024
1 parent 70617d1 commit 721f02a
Show file tree
Hide file tree
Showing 10 changed files with 1,321 additions and 376 deletions.
1,102 changes: 1,019 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ clap = "4.0.18"
colored = "2.0.0"
rowan = "0"
rnix = "0"
v8 = "0.92.0"
deno_core = "0"
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

555 changes: 285 additions & 270 deletions nixjs-rt/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nixjs-rt/pkg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ in
buildNpmPackage rec {
name = "nixjs-rt";
src = self;
npmDepsHash = "sha256-bzi3/pHxDYgKKZsV3zVIwZ6cwGjAz0lolzeCotao+9I=";
npmDepsHash = "sha256-ev5i6sL2mQgxu7kuLVaMIJfUVEXcP27n8u2RiGE0Cd8=";
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.78.0"
channel = "1.79.0"
components = [ "clippy", "rust-analyzer", "rustfmt" ]
profile = "minimal"
2 changes: 2 additions & 0 deletions src/eval/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use deno_core::v8;

use super::{
helpers::{call_js_function, get_js_value_key, is_nixrt_type},
types::NixTypeKind,
Expand Down
22 changes: 5 additions & 17 deletions src/eval/execution.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;
use std::sync::Once;

use v8::{HandleScope, Local, ModuleStatus, Object};
use deno_core::v8;
use deno_core::v8::{HandleScope, Local, ModuleStatus, Object};

use crate::eval::types::EvalResult;

Expand All @@ -10,10 +10,8 @@ use super::error::NixError;
use super::helpers::{call_js_function, get_nixrt_type, try_get_js_object_key};
use super::types::js_value_to_nix;

static INIT_V8: Once = Once::new();

pub fn evaluate(nix_expr: &str, workdir: &Path) -> EvalResult {
initialize_v8();
deno_core::JsRuntime::init_platform(None);
// Declare the V8 execution context
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
Expand All @@ -34,10 +32,8 @@ pub fn evaluate(nix_expr: &str, workdir: &Path) -> EvalResult {
];

for (name, value) in globals {
let import_module_attr = v8::String::new(scope, name).unwrap();
global
.set(scope, import_module_attr.into(), *value)
.unwrap();
let global_var_name = v8::String::new(scope, name).unwrap();
global.set(scope, global_var_name.into(), *value).unwrap();
}

// Execute the Nix runtime JS module, get its exports
Expand Down Expand Up @@ -159,14 +155,6 @@ fn exec_module<'a>(
Ok(obj)
}

fn initialize_v8() {
INIT_V8.call_once(|| {
let platform = v8::new_default_platform(0, false).make_shared();
v8::V8::initialize_platform(platform);
v8::V8::initialize();
});
}

fn nix_value_from_module(
scope: &mut v8::ContextScope<v8::HandleScope>,
nix_module_fn: v8::Local<v8::Function>,
Expand Down
2 changes: 2 additions & 0 deletions src/eval/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use deno_core::v8;

use super::error::{js_error_to_rust, NixError};

pub fn is_nixrt_type<'s, T>(
Expand Down
2 changes: 2 additions & 0 deletions src/eval/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::HashMap;

use deno_core::v8;

use super::{
error::NixError,
helpers::{call_js_instance_mehod, is_nixrt_type, try_get_js_object_key},
Expand Down

0 comments on commit 721f02a

Please sign in to comment.