--- quickjs-master/quickjs.c	2026-03-23 13:45:52
+++ quickjs/quickjs.c	2026-03-23 17:19:56
@@ -31462,10 +31462,24 @@
     if (s->token.val == TOK_FUNCTION ||
         (token_is_pseudo_keyword(s, JS_ATOM_async) &&
          peek_token(s, TRUE) == TOK_FUNCTION)) {
+
+        if (peek_token(s, TRUE) == '(') {
+           /* Spidermonkey 1.8.5 mode: accept top function statements as expressions */
+           if (js_parse_expr(s))
+               return -1;
+           if (s->cur_func->eval_ret_idx >= 0) {
+               /* store the expression value so that it can be returned by eval() */
+               emit_op(s, OP_put_loc);
+               emit_u16(s, s->cur_func->eval_ret_idx);
+           } else {
+               emit_op(s, OP_drop); /* drop the result */
+           }
+        } else {
         if (js_parse_function_decl(s, JS_PARSE_FUNC_STATEMENT,
                                    JS_FUNC_NORMAL, JS_ATOM_NULL,
                                    s->token.ptr))
             return -1;
+        }
     } else if (s->token.val == TOK_EXPORT && fd->module) {
         if (js_parse_export(s))
             return -1;
