Simplify code for conversion between Boa and SurrealDB
This commit is contained in:
parent
d0c37f4d66
commit
663848172e
1 changed files with 14 additions and 7 deletions
|
@ -106,6 +106,7 @@ impl Class for JsRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(ctx: &Context, src: &str, arg: Vec<Value>, doc: Option<&Value>) -> Result<Value, Error> {
|
pub fn run(ctx: &Context, src: &str, arg: Vec<Value>, doc: Option<&Value>) -> Result<Value, Error> {
|
||||||
|
// Check the context
|
||||||
let _ = ctx.check()?;
|
let _ = ctx.check()?;
|
||||||
// Create an execution context
|
// Create an execution context
|
||||||
let mut ctx = Boa::default();
|
let mut ctx = Boa::default();
|
||||||
|
@ -126,7 +127,7 @@ pub fn run(ctx: &Context, src: &str, arg: Vec<Value>, doc: Option<&Value>) -> Re
|
||||||
// Attempt to execute the script
|
// Attempt to execute the script
|
||||||
match ctx.eval(src.as_bytes()) {
|
match ctx.eval(src.as_bytes()) {
|
||||||
// The script executed successfully
|
// The script executed successfully
|
||||||
Ok(ref v) => Ok(v.into()),
|
Ok(v) => Ok(v.into()),
|
||||||
// There was an error running the script
|
// There was an error running the script
|
||||||
Err(e) => Err(Error::InvalidScript {
|
Err(e) => Err(Error::InvalidScript {
|
||||||
message: e.display().to_string(),
|
message: e.display().to_string(),
|
||||||
|
@ -134,12 +135,6 @@ pub fn run(ctx: &Context, src: &str, arg: Vec<Value>, doc: Option<&Value>) -> Re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Value> for JsValue {
|
|
||||||
fn from(v: Value) -> Self {
|
|
||||||
JsValue::from(&v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&Datetime> for Date {
|
impl From<&Datetime> for Date {
|
||||||
fn from(v: &Datetime) -> Self {
|
fn from(v: &Datetime) -> Self {
|
||||||
let mut obj = Self::default();
|
let mut obj = Self::default();
|
||||||
|
@ -157,6 +152,12 @@ impl From<&Datetime> for Date {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Value> for JsValue {
|
||||||
|
fn from(v: Value) -> Self {
|
||||||
|
JsValue::from(&v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&Value> for JsValue {
|
impl From<&Value> for JsValue {
|
||||||
fn from(v: &Value) -> Self {
|
fn from(v: &Value) -> Self {
|
||||||
match v {
|
match v {
|
||||||
|
@ -212,6 +213,12 @@ impl From<&Value> for JsValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<JsValue> for Value {
|
||||||
|
fn from(v: JsValue) -> Self {
|
||||||
|
Value::from(&v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&JsValue> for Value {
|
impl From<&JsValue> for Value {
|
||||||
fn from(v: &JsValue) -> Self {
|
fn from(v: &JsValue) -> Self {
|
||||||
match v {
|
match v {
|
||||||
|
|
Loading…
Reference in a new issue