theduke / quickjs-rs

Rust wrapper for the quickjs Javascript engine.
MIT License
570 stars 48 forks source link

works locally fine, but fails with "SyntaxError: stack overflow" on github ci/cd #130

Closed rv-nath closed 4 months ago

rv-nath commented 6 months ago

I have created a stack overflow question here. https://stackoverflow.com/questions/78360585/rust-crate-quickjs-fails-execution-of-simple-script-with-syntaxerror-stack-ove

This is my code that constructs a JS runtime and adds an object to it.

impl TestCtx {
    pub fn new() -> Self {
        let runtime = Context::new().unwrap();
        let client = reqwest::blocking::Client::new();

        // Initialize SAT as an empty object
        runtime.eval("var SAT = {}").unwrap();

        // define the 'SAT.test' function
        runtime
            .eval(
                r#"
                SAT.test = function (name, fn) {
                    SAT.testName = name;
                    let result = false;
                    try {
                        result = fn();
                        if (typeof result !== 'boolean') {
                            result = false;
                        }
                    } catch (e) {
                        // Handle error
                       result = false;
                    }
                    return result;
                }
            "#,
            )
            .unwrap();

        TestCtx {
            client,
            jwt_token: None,
            runtime,
            exec_duration: std::time::Duration::new(0, 0),
        }
    }

I am writing test code to ensure that I have initialized the JS runtime properly and that it has a SAT object in it.

#[cfg(test)]
mod tests {
    use crate::test_context::TestCtx;

    #[test]
    fn test_new() {
        let ts_ctx = TestCtx::new();
        // Test if the runtime has the SAT object
        let sat = ts_ctx.runtime.eval("typeof SAT.test").unwrap();
        let expected = quick_js::JsValue::String("function".to_string());
        assert_eq!(sat, expected);
    }

This works absolutely fine in my local PC environments. Tested on Windows WSL Ubuntu 22.04 as well as native Ubuntu 22.04. Always fails on Github server, which is also an Ubuntu.

Details are given in the link shared at the top of this question. Thanks for helping me in finding the cause of lthis behavior and how to avoid it.

rv-nath commented 4 months ago

It seems that quickjs has some issues in some aspects, or I do not understand it fully. Now I switched to v8 engine. Thanks.