Jacek Caban : jscript: Properly handle function expressions with identifiers.

Alexandre Julliard julliard at wine.codeweavers.com
Fri May 6 11:08:16 CDT 2016


Module: wine
Branch: master
Commit: e1970c8547aa7fed5a097faf172eadc282b3394e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e1970c8547aa7fed5a097faf172eadc282b3394e

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri May  6 12:56:35 2016 +0200

jscript: Properly handle function expressions with identifiers.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/compile.c     | 15 ++++---------
 dlls/jscript/tests/lang.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 0c40d1f..77bbc89 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -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;
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 95655ab..a9f95f8 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -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");




More information about the wine-cvs mailing list