Jacek Caban : jscript: Added typeof expression implementation.

Alexandre Julliard julliard at winehq.org
Wed Sep 10 06:01:42 CDT 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 10 02:36:03 2008 +0200

jscript: Added typeof expression implementation.

---

 dlls/jscript/engine.c      |   70 ++++++++++++++++++++++++++++++++++++++++++--
 dlls/jscript/tests/lang.js |   13 ++++++++
 2 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 42db70a..c15b05b 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -959,10 +959,74 @@ HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, j
     return E_NOTIMPL;
 }
 
-HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
+HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    unary_expression_t *expr = (unary_expression_t*)_expr;
+    const WCHAR *str;
+    exprval_t exprval;
+    VARIANT val;
+    HRESULT hres;
+
+    static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
+    static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
+    static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
+    static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
+    static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
+    static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
+
+    TRACE("\n");
+
+    hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
+    if(FAILED(hres))
+        return hres;
+
+    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
+    exprval_release(&exprval);
+    if(FAILED(hres))
+        return hres;
+
+    switch(V_VT(&val)) {
+    case VT_EMPTY:
+        str = undefinedW;
+        break;
+    case VT_NULL:
+        str = objectW;
+        break;
+    case VT_BOOL:
+        str = booleanW;
+        break;
+    case VT_I4:
+    case VT_R8:
+        str = numberW;
+        break;
+    case VT_BSTR:
+        str = stringW;
+        break;
+    case VT_DISPATCH: {
+        DispatchEx *dispex;
+
+        dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val));
+        if(dispex) {
+            str = dispex->builtin_info->class == JSCLASS_FUNCTION ? functionW : objectW;
+            IDispatchEx_Release(_IDispatchEx_(dispex));
+        }else {
+            str = objectW;
+        }
+        break;
+    }
+    default:
+        FIXME("unhandled vt %d\n", V_VT(&val));
+        hres = E_NOTIMPL;
+    }
+
+    VariantClear(&val);
+    if(FAILED(hres))
+        return hres;
+
+    ret->type = EXPRVAL_VARIANT;
+    V_VT(&ret->u.var) = VT_BSTR;
+    V_BSTR(&ret->u.var) = SysAllocString(str);
+    return S_OK;
 }
 
 HRESULT minus_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 96ecdb4..088468a 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -56,4 +56,17 @@ ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
 ok(Math !== undefined, "Math is undefined");
 ok(Math.prototype === undefined, "Math.prototype is not undefined");
 
+ok(typeof(0) === "number", "typeof(0) is not number");
+ok(typeof(1.5) === "number", "typeof(1.5) is not number");
+ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
+ok(typeof("") === "string", "typeof(\"\") is not string");
+ok(typeof(true) === "boolean", "typeof(true) is not boolean");
+ok(typeof(null) === "object", "typeof(null) is not object");
+ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
+ok(typeof(Math) === "object", "typeof(Math) is not object");
+ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
+ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
+ok(typeof(String) === "function", "typeof(String) is not function");
+ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
+
 reportSuccess();




More information about the wine-cvs mailing list