Jacek Caban : jscript: Return 'unknown' in typeof operator for native object's values that can't be retrieved.

Alexandre Julliard julliard at winehq.org
Wed Dec 29 11:14:55 CST 2010


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Dec 29 16:02:25 2010 +0100

jscript: Return 'unknown' in typeof operator for native object's values that can't be retrieved.

---

 dlls/jscript/engine.c      |    8 +++++++-
 dlls/jscript/tests/lang.js |    7 +++++--
 dlls/jscript/tests/run.c   |   29 +++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 42d6762..9a5ecbc 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -2365,6 +2365,7 @@ static HRESULT typeof_exprval(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t
     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};
+    static const WCHAR unknownW[] = {'u','n','k','n','o','w','n',0};
 
     if(exprval->type == EXPRVAL_INVALID) {
         *ret = undefinedW;
@@ -2372,8 +2373,13 @@ static HRESULT typeof_exprval(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t
     }
 
     hres = exprval_to_value(ctx, exprval, ei, &val);
-    if(FAILED(hres))
+    if(FAILED(hres)) {
+        if(exprval->type == EXPRVAL_IDREF) {
+            *ret = unknownW;
+            return S_OK;
+        }
         return hres;
+    }
 
     switch(V_VT(&val)) {
     case VT_EMPTY:
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 5a361d7..bf74ed7 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -108,6 +108,11 @@ 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");
 ok(typeof(this) === "object", "typeof(this) is not object");
+ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
+tmp = typeof((new Object()).doesnotexist);
+ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
+tmp = typeof(testObj.onlyDispID);
+ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
 
 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
 
@@ -1057,8 +1062,6 @@ if(false) {
 
 ok(in_if_false(), "in_if_false failed");
 
-ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
-
 (function() { newValue = 1; })();
 ok(newValue === 1, "newValue = " + newValue);
 
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index 7b198df..f473c6c 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -68,6 +68,8 @@ DEFINE_EXPECT(testobj_delete);
 DEFINE_EXPECT(testobj_value);
 DEFINE_EXPECT(testobj_prop_d);
 DEFINE_EXPECT(testobj_noprop_d);
+DEFINE_EXPECT(testobj_onlydispid_d);
+DEFINE_EXPECT(testobj_onlydispid_i);
 DEFINE_EXPECT(GetItemInfo_testVal);
 DEFINE_EXPECT(ActiveScriptSite_OnScriptError);
 DEFINE_EXPECT(invoke_func);
@@ -90,6 +92,7 @@ DEFINE_EXPECT(invoke_func);
 #define DISPID_GLOBAL_ISWIN64       0x100f
 
 #define DISPID_TESTOBJ_PROP         0x2000
+#define DISPID_TESTOBJ_ONLYDISPID   0x2001
 
 static const WCHAR testW[] = {'t','e','s','t',0};
 static const CHAR testA[] = "test";
@@ -230,6 +233,13 @@ static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD
         test_grfdex(grfdex, fdexNameCaseSensitive);
         return DISP_E_UNKNOWNNAME;
     }
+    if(!strcmp_wa(bstrName, "onlyDispID")) {
+        if(strict_dispid_check)
+            CHECK_EXPECT(testobj_onlydispid_d);
+        test_grfdex(grfdex, fdexNameCaseSensitive);
+        *pid = DISPID_TESTOBJ_ONLYDISPID;
+        return S_OK;
+    }
 
     ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
     return E_NOTIMPL;
@@ -266,6 +276,19 @@ static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid,
         V_VT(pvarRes) = VT_I4;
         V_I4(pvarRes) = 1;
         return S_OK;
+    case DISPID_TESTOBJ_ONLYDISPID:
+        if(strict_dispid_check)
+            CHECK_EXPECT(testobj_onlydispid_i);
+        ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
+        ok(pdp != NULL, "pdp == NULL\n");
+        ok(!pdp->rgvarg, "rgvarg != NULL\n");
+        ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
+        ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
+        ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
+        ok(pvarRes != NULL, "pvarRes == NULL\n");
+        ok(V_VT(pvarRes) ==  VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
+        ok(pei != NULL, "pei == NULL\n");
+        return DISP_E_MEMBERNOTFOUND;
     }
 
     ok(0, "unexpected call %x\n", id);
@@ -1431,6 +1454,12 @@ static void run_tests(void)
     parse_script_a("testThis(this);");
     parse_script_a("(function () { testThis(this); })();");
 
+    SET_EXPECT(testobj_onlydispid_d);
+    SET_EXPECT(testobj_onlydispid_i);
+    parse_script_a("ok(typeof(testObj.onlyDispID) === 'unknown', 'unexpected typeof(testObj.onlyDispID)');");
+    CHECK_CALLED(testobj_onlydispid_d);
+    CHECK_CALLED(testobj_onlydispid_i);
+
     run_from_res("lang.js");
     run_from_res("api.js");
     run_from_res("regexp.js");




More information about the wine-cvs mailing list