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

jscript: Properly handle function expressions with identifiers.

parent 64124815
......@@ -872,17 +872,11 @@ static HRESULT compile_object_literal(compiler_ctx_t *ctx, property_value_expres
return S_OK;
}
static HRESULT compile_function_expression(compiler_ctx_t *ctx, function_expression_t *expr)
static HRESULT compile_function_expression(compiler_ctx_t *ctx, function_expression_t *expr, BOOL emit_ret)
{
unsigned func_id = ctx->func->func_cnt++;
ctx->func_tail = ctx->func_tail ? (ctx->func_tail->next = expr) : (ctx->func_head = expr);
/* FIXME: not exactly right */
if(expr->identifier && !expr->event_target) {
ctx->func->func_cnt++;
return push_instr_bstr(ctx, OP_ident, expr->identifier);
}
return push_instr_uint(ctx, OP_func, ctx->func->func_cnt++);
return emit_ret ? push_instr_uint(ctx, OP_func, func_id) : S_OK;
}
static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr, BOOL emit_ret)
......@@ -967,8 +961,7 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr, BOOL
hres = compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq2);
break;
case EXPR_FUNC:
hres = compile_function_expression(ctx, (function_expression_t*)expr);
break;
return compile_function_expression(ctx, (function_expression_t*)expr, emit_ret);
case EXPR_GREATER:
hres = compile_binary_expression(ctx, (binary_expression_t*)expr, OP_gt);
break;
......
......@@ -232,6 +232,58 @@ testNoRes(), testNoRes();
tmp = (function(){ return testNoRes(), testRes();})();
var f1, f2;
ok(funcexpr() == 2, "funcexpr() = " + funcexpr());
f1 = function funcexpr() { return 1; }
ok(f1 != funcexpr, "f1 == funcexpr");
ok(f1() === 1, "f1() = " + f1());
f2 = function funcexpr() { return 2; }
ok(f2 != funcexpr, "f2 != funcexpr");
ok(f2() === 2, "f2() = " + f2());
f1 = null;
for(i = 0; i < 3; i++) {
f2 = function funcexpr2() {};
ok(f1 != f2, "f1 == f2");
f1 = f2;
}
f1 = null;
for(i = 0; i < 3; i++) {
f2 = function() {};
ok(f1 != f2, "f1 == f2");
f1 = f2;
}
(function() {
ok(infuncexpr() == 2, "infuncexpr() = " + infuncexpr());
f1 = function infuncexpr() { return 1; }
ok(f1 != funcexpr, "f1 == funcexpr");
ok(f1() === 1, "f1() = " + f1());
f2 = function infuncexpr() { return 2; }
ok(f2 != funcexpr, "f2 != funcexpr");
ok(f2() === 2, "f2() = " + f2());
f1 = null;
for(i = 0; i < 3; i++) {
f2 = function infuncexpr2() {};
ok(f1 != f2, "f1 == f2");
f1 = f2;
}
f1 = null;
for(i = 0; i < 3; i++) {
f2 = function() {};
ok(f1 != f2, "f1 == f2");
f1 = f2;
}
})();
var obj1 = new Object();
ok(typeof(obj1) === "object", "typeof(obj1) is not object");
ok(obj1.constructor === Object, "unexpected obj1.constructor");
......
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