blob: e30bb74be56ab6b3f393bf54850dc9aeb096821e [file] [log] [blame]
--- quickjs-master/quickjs.c 2024-05-05 13:54:47
+++ quickjs/quickjs.c 2024-05-06 16:56:22
@@ -29430,10 +29430,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, s->token.line_num))
return -1;
+ }
} else if (s->token.val == TOK_EXPORT && fd->module) {
if (js_parse_export(s))
return -1;