Commit b268e41d authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Use bytecode for function expression implementation.

parent f999f4ae
......@@ -646,6 +646,21 @@ static HRESULT compile_array_literal(compiler_ctx_t *ctx, array_literal_expressi
return push_instr_uint(ctx, OP_carray, elem_cnt);
}
static HRESULT compile_function_expression(compiler_ctx_t *ctx, function_expression_t *expr)
{
unsigned instr;
/* FIXME: not exactly right */
if(expr->identifier)
return push_instr_bstr(ctx, OP_ident, expr->identifier);
instr = push_instr(ctx, OP_func);
if(instr == -1)
return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.func = expr;
return S_OK;
}
static HRESULT compile_expression_noret(compiler_ctx_t *ctx, expression_t *expr, BOOL *no_ret)
{
......@@ -702,6 +717,8 @@ static HRESULT compile_expression_noret(compiler_ctx_t *ctx, expression_t *expr,
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq);
case EXPR_EQEQ:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq2);
case EXPR_FUNC:
return compile_function_expression(ctx, (function_expression_t*)expr);
case EXPR_GREATER:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_gt);
case EXPR_GREATEREQ:
......
......@@ -1420,32 +1420,22 @@ HRESULT try_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t
}
/* ECMA-262 3rd Edition 13 */
HRESULT function_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
static HRESULT interp_func(exec_ctx_t *ctx)
{
function_expression_t *expr = (function_expression_t*)_expr;
VARIANT var;
function_expression_t *expr = ctx->parser->code->instrs[ctx->ip].arg1.func;
jsdisp_t *dispex;
VARIANT v;
HRESULT hres;
TRACE("\n");
if(expr->identifier) {
hres = jsdisp_propget_name(ctx->exec_ctx->var_disp, expr->identifier, &var, ei, NULL/*FIXME*/);
if(FAILED(hres))
return hres;
}else {
jsdisp_t *dispex;
hres = create_source_function(ctx->exec_ctx->parser, expr->parameter_list, expr->source_elements, ctx->exec_ctx->scope_chain,
expr->src_str, expr->src_len, &dispex);
if(FAILED(hres))
return hres;
var_set_jsdisp(&var, dispex);
}
hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
expr->src_str, expr->src_len, &dispex);
if(FAILED(hres))
return hres;
ret->type = EXPRVAL_VARIANT;
ret->u.var = var;
return S_OK;
var_set_jsdisp(&v, dispex);
return stack_push(ctx, &v);
}
/* ECMA-262 3rd Edition 11.2.1 */
......
......@@ -57,6 +57,7 @@ typedef struct _func_stack {
X(double, 1, ARG_SBL, 0) \
X(eq, 1, 0,0) \
X(eq2, 1, 0,0) \
X(func, 1, ARG_FUNC, 0) \
X(gt, 1, 0,0) \
X(gteq, 1, 0,0) \
X(ident, 1, ARG_BSTR, 0) \
......@@ -117,6 +118,7 @@ typedef union {
LONG lng;
WCHAR *str;
unsigned uint;
function_expression_t *func; /* FIXME */
} instr_arg_t;
typedef enum {
......@@ -124,6 +126,7 @@ typedef enum {
ARG_ADDR,
ARG_BSTR,
ARG_EXPR,
ARG_FUNC,
ARG_INT,
ARG_STR
} instr_arg_type_t;
......@@ -565,7 +568,6 @@ typedef struct {
prop_val_t *property_list;
} property_value_expression_t;
HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT property_value_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT compiled_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
......
......@@ -1357,7 +1357,7 @@ static const expression_eval_t expression_eval_table[] = {
compiled_expression_eval,
compiled_expression_eval,
compiled_expression_eval,
function_expression_eval,
compiled_expression_eval,
compiled_expression_eval,
compiled_expression_eval,
property_value_expression_eval,
......
......@@ -1110,6 +1110,12 @@ ok(newValue === 1, "newValue = " + newValue);
obj = {undefined: 3};
ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
name_override_func = 3;
ok(name_override_func === 3, "name_override_func = " + name_override_func);
function name_override_func() {};
ok(name_override_func === 3, "name_override_func = " + name_override_func);
/* Keep this test in the end of file */
undefined = 6;
ok(undefined === 6, "undefined = " + undefined);
......
......@@ -1487,6 +1487,8 @@ static void run_tests(void)
CHECK_CALLED(global_propdelete_d);
CHECK_CALLED(DeleteMemberByDispID);
parse_script_a("(function reportSuccess() {})()");
parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
parse_script_a("function reportSuccess() {}; reportSuccess();");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment