From ca568bcb4ca6bf6020e663a110ba12c8dbdf58a4 Mon Sep 17 00:00:00 2001 From: stefan-gorules <127550877+stefan-gorules@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:39:09 +0200 Subject: [PATCH] fix: function data pass; (#80) --- core/engine/src/handler/function/script.rs | 10 +++++++--- core/engine/src/handler/function/scripts/internals.js | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) 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, });