Skip to content

Commit

Permalink
fix merge / crate seperation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed Feb 26, 2024
1 parent e664d70 commit 5a7bdd6
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 48 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/gosub_webexecutor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ derive_more = "0.99"
lazy_static = "1.4"
thiserror = "1.0.57"
v8 = "0.83.2"
anyhow = "1.0.80"
anyhow = "1.0.80"
serde_json = "1.0.114"
7 changes: 2 additions & 5 deletions crates/gosub_webexecutor/src/js/v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ mod tests {
}

#[test]
#[should_panic = "called `Result::unwrap()` on an `Err` value: js: compile error: SyntaxError: missing ) after argument list\n\nCaused by:\n compile error: SyntaxError: missing ) after argument list"]
fn v8_run_invalid_syntax() {
let mut engine = crate::js::v8::V8Engine::new();

Expand All @@ -160,11 +161,7 @@ mod tests {
);

assert!(result.is_err());
// This assertion fails because the error type is not correct
// assert!(matches!(
// result,
// Err(anyhow::Error::new(JSError::Compile(_)))
// ));
result.unwrap();
}

#[test]
Expand Down
14 changes: 4 additions & 10 deletions crates/gosub_webexecutor/src/js/v8/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ impl<'a> JSArray for V8Array<'a> {
type RT = V8Engine<'a>;

fn get(&self, index: u32) -> Result<<Self::RT as JSRuntime>::Value> {
let Some(value) = self
.value
.get_index(self.ctx.borrow_mut().scope(), index)
else {
let Some(value) = self.value.get_index(self.ctx.borrow_mut().scope(), index) else {
return Err(Error::JS(JSError::Generic(
"failed to get a value from an array".to_owned(),
))
Expand Down Expand Up @@ -111,8 +108,8 @@ impl<'a> JSArray for V8Array<'a> {

#[cfg(test)]
mod tests {
use crate::web_executor::js::v8::{V8Array, V8Engine};
use crate::web_executor::js::{JSArray, JSRuntime, JSValue, ValueConversion};
use crate::js::v8::{V8Array, V8Engine};
use crate::js::{JSArray, JSRuntime, JSValue, ValueConversion};

#[test]
fn set() {
Expand Down Expand Up @@ -145,10 +142,7 @@ mod tests {
.unwrap();

assert_eq!(array.get(0).unwrap().as_number().unwrap(), 1234.0);
assert_eq!(
array.get(1).unwrap().as_string().unwrap(),
"Hello World!"
);
assert_eq!(array.get(1).unwrap().as_string().unwrap(), "Hello World!");
}

#[test]
Expand Down
16 changes: 6 additions & 10 deletions crates/gosub_webexecutor/src/js/v8/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ impl<'a> V8FunctionCallBack<'a> {
Ok(Self {
ctx,
args,
ret: Err(Error::JS(JSError::Execution(
"function was not called".to_owned(),
))),
ret: Err(Error::JS(JSError::Execution("function was not called".to_owned())).into()),
})
}
}
Expand Down Expand Up @@ -283,8 +281,7 @@ impl<'a> JSFunction for V8Function<'a> {
value,
})
} else {
Err(Error::JS(JSError::Execution(
"failed to call a function".to_owned())).into())
Err(Error::JS(JSError::Execution("failed to call a function".to_owned())).into())
}
}
}
Expand Down Expand Up @@ -566,17 +563,16 @@ impl<'a> JSFunctionVariadic for V8FunctionVariadic<'a> {
value,
})
} else {
Err(Error::JS(JSError::Execution(
"failed to call a function".to_owned())).into())
Err(Error::JS(JSError::Execution("failed to call a function".to_owned())).into())
}
}
}

#[cfg(test)]
mod tests {
use crate::web_executor::js::v8::{V8Engine, V8Function, V8FunctionVariadic, V8Value};
use crate::web_executor::js::{
Args, JSContext, JSFunction, JSFunctionCallBack, JSFunctionVariadic, JSRuntime, JSValue,
use crate::js::v8::{V8Engine, V8Function, V8FunctionVariadic};
use crate::js::{
Args, JSFunction, JSFunctionCallBack, JSFunctionVariadic, JSRuntime, JSValue,
ValueConversion,
};

Expand Down
10 changes: 5 additions & 5 deletions crates/gosub_webexecutor/src/js/v8/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a> JSObject for V8Object<'a> {
let Some(name) = v8::String::new(self.ctx.borrow_mut().scope(), name) else {
return Err(Error::JS(JSError::Generic("failed to create a string".to_owned())).into());
};

let scope = self.ctx.borrow_mut().scope();

self.value
Expand Down Expand Up @@ -253,7 +253,7 @@ impl<'a> JSObject for V8Object<'a> {
};

let gs = unsafe { &*(external.value() as *const GetterSetter) };

let isolate = gs.ctx.borrow().isolate;

let ctx = match ctx_from(scope, isolate) {
Expand Down Expand Up @@ -351,13 +351,13 @@ impl<'a> FromContext<'a, Local<'a, Object>> for V8Object<'a> {

#[cfg(test)]
mod tests {
use alloc::rc::Rc;
use std::cell::RefCell;
use std::rc::Rc;

use serde_json::to_string;

use crate::web_executor::js::v8::V8FunctionCallBackVariadic;
use crate::web_executor::js::{
use crate::js::v8::V8FunctionCallBackVariadic;
use crate::js::{
JSFunction, JSFunctionCallBack, JSFunctionCallBackVariadic, JSFunctionVariadic,
ValueConversion, VariadicArgsInternal,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_webexecutor/src/js/v8/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'a> JSValue for V8Value<'a> {

#[cfg(test)]
mod tests {
use crate::web_executor::js::JSContext;
use crate::js::JSContext;

use super::*;

Expand Down
21 changes: 7 additions & 14 deletions crates/gosub_webexecutor/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#![allow(dead_code)]
#![allow(unused_variables)]

use std::cell::RefCell;
use std::collections::HashMap;
use std::ops::Add;
use std::rc::Rc;

//use webinterop::{web_fns, web_interop};
use crate::js::v8::{
GetterCallback, SetterCallback, V8Context, V8Engine, V8Function, V8FunctionVariadic, V8Value,
};
use gosub_shared::types::Result;

use crate::js::{
Args, JSContext, JSFunction, JSFunctionCallBack, JSFunctionCallBackVariadic,
JSFunctionVariadic, JSGetterCallback, JSInterop, JSObject, JSRuntime, JSSetterCallback,
JSValue, ValueConversion, VariadicArgs, VariadicArgsInternal,
};
use gosub_shared::types::Result;
//use webinterop::{web_fns, web_interop};
use crate::js::v8::{V8Engine, V8Value};

//#[web_interop]
struct TestStruct {
Expand Down Expand Up @@ -147,7 +148,6 @@ impl JSInterop for Test2 {
let setter = {
let s = Rc::clone(&s);
Box::new(move |cb: &mut RT::SetterCB| {
let ctx = cb.context();
let value = cb.value();
let value = match value.as_number() {
Ok(value) => value,
Expand Down Expand Up @@ -188,7 +188,6 @@ impl JSInterop for Test2 {
let setter = {
let s = Rc::clone(&s);
Box::new(move |cb: &mut RT::SetterCB| {
let ctx = cb.context();
let value = cb.value();
let value = match value.as_string() {
Ok(value) => value,
Expand Down Expand Up @@ -243,8 +242,6 @@ impl JSInterop for Test2 {

let ctx = cb.context();

let args = cb.args();

let Some(arg0) = cb.args().get(0, ctx.clone()) else {
cb.error("failed to get argument");
return;
Expand Down Expand Up @@ -278,8 +275,6 @@ impl JSInterop for Test2 {

let ctx = cb.context();

let args = cb.args();

let Some(arg0) = cb.args().get(0, ctx.clone()) else {
cb.error("failed to get argument");
return;
Expand Down Expand Up @@ -308,8 +303,6 @@ impl JSInterop for Test2 {

let ctx = cb.context();

let args = cb.args();

let Some(arg0) = cb.args().get(0, ctx.clone()) else {
cb.error("failed to get argument");
return;
Expand Down

0 comments on commit 5a7bdd6

Please sign in to comment.