diff --git a/core/engine/src/handler/function/script.rs b/core/engine/src/handler/function/script.rs index 6eb8acaf..25712a66 100644 --- a/core/engine/src/handler/function/script.rs +++ b/core/engine/src/handler/function/script.rs @@ -1,12 +1,13 @@ -use anyhow::{anyhow, Context}; use std::fmt::Debug; use std::thread; use std::time::Duration; -use crate::handler::function::vm::BASE_VM; +use anyhow::{anyhow, Context}; use serde::{Deserialize, Serialize}; use serde_json::Value; +use crate::handler::function::vm::BASE_VM; + #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct EvaluateResponse { @@ -90,6 +91,9 @@ impl Script { return Err(anyhow!(exception.to_rust_string_lossy(tc_scope))); }; - serde_v8::from_v8(tc_scope, result).context("Failed to parse function result") + let result_string: String = + serde_v8::from_v8(tc_scope, result).context("Failed to parse function result")?; + + serde_json::from_str(result_string.as_str()).context("Failed to parse function result") } } diff --git a/core/engine/src/handler/function/scripts/internals.js b/core/engine/src/handler/function/scripts/internals.js index 127334d0..dca79850 100644 --- a/core/engine/src/handler/function/scripts/internals.js +++ b/core/engine/src/handler/function/scripts/internals.js @@ -16,7 +16,7 @@ const console = { } }; -const main = (input) => ({ +const main = (input) => JSON.stringify({ output: handler(input, {moment: __GLOBAL__DAYJS, dayjs: __GLOBAL__DAYJS, Big: Big, env: __GLOBAL__ENV}), log, });