Jacek Caban : jscript: Added function expression implementation.

Alexandre Julliard julliard at winehq.org
Thu Sep 11 08:00:54 CDT 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 10 21:08:46 2008 +0200

jscript: Added function expression implementation.

---

 dlls/jscript/engine.c      |   30 +++++++++++++++++++++++++++---
 dlls/jscript/tests/lang.js |   11 +++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index d1dc0a7..e594c69 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -703,10 +703,34 @@ static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr
     return S_OK;
 }
 
-HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
+/* ECMA-262 3rd Edition    13 */
+HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    function_expression_t *expr = (function_expression_t*)_expr;
+    DispatchEx *dispex;
+    VARIANT var;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain, &dispex);
+    if(FAILED(hres))
+        return hres;
+
+    V_VT(&var) = VT_DISPATCH;
+    V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
+
+    if(expr->identifier) {
+        hres = jsdisp_propput_name(ctx->var_disp, expr->identifier, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
+        if(FAILED(hres)) {
+            jsdisp_release(dispex);
+            return hres;
+        }
+    }
+
+    ret->type = EXPRVAL_VARIANT;
+    ret->u.var = var;
+    return S_OK;
 }
 
 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 4e76b21..1914a05 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -81,5 +81,16 @@ ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
 
 var obj1 = new Object();
 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
+obj1.test = true;
+obj1.func = function () {
+    ok(this === obj1, "this is not obj1");
+    ok(this.test === true, "this.test is not true");
+    ok(arguments.length === 1, "arguments.length is not 1");
+    ok(arguments["0"] === true, "arguments[0] is not true");
+
+    return "test";
+};
+
+ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
 
 reportSuccess();




More information about the wine-cvs mailing list