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

tests and warnings fix for v8 engine integration #55

Merged
merged 3 commits into from
Sep 12, 2020
Merged
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
11 changes: 11 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test

- name: Run cargo test v8 engine
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features=rusty_v8

lints:
name: Lints
bayne marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -71,3 +77,8 @@ jobs:
with:
command: clippy
args: -- -D warnings
- name: Run cargo clippy v8 engine
uses: actions-rs/cargo@v1
with:
command: clippy
args: --no-default-features --features=rusty_v8 -- -D warnings
2 changes: 1 addition & 1 deletion src/script_engine/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn test_syntax_error() {
);
if let Err(error) = result {
assert!(
error.to_string().contains("Expecting Token"),
error.to_string().to_lowercase().contains("token"),
"Should've been a lexer error, but instead got:\n {:#?}",
error
);
Expand Down
17 changes: 13 additions & 4 deletions src/script_engine/v8.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::http_client;
use crate::script_engine::{handle, Script, ScriptEngine};
use crate::Result;
use rusty_v8::{
Expand Down Expand Up @@ -70,6 +69,14 @@ impl V8ScriptEngine {
Ok(engine)
}
}
fn catch(
tc: &mut TryCatch,
scope: &mut Entered<ContextScope, Entered<HandleScope, OwnedIsolate>>,
) -> anyhow::Error {
let exception = tc.exception(scope).unwrap();
let msg = Exception::create_message(scope, exception);
anyhow!("{}", msg.get(scope).to_rust_string_lossy(scope))
}

impl ScriptEngine for V8ScriptEngine {
fn execute_script(&mut self, script: &Script) -> Result<String> {
Expand All @@ -91,9 +98,11 @@ impl ScriptEngine for V8ScriptEngine {
let mut try_catch = TryCatch::new(scope);
let try_catch = try_catch.enter();
let source = V8String::new(scope, script.src).unwrap();

let mut compiled = V8Script::compile(scope, context, source, None).unwrap();
let result = compiled.run(scope, context).unwrap();
let mut compiled = V8Script::compile(scope, context, source, None)
.ok_or_else(|| catch(try_catch, scope))?;
let result = compiled
.run(scope, context)
.ok_or_else(|| catch(try_catch, scope))?;

let result = result.to_string(scope).unwrap();

Expand Down