Piotr Caban : jscript: Improve Object_toString implementation.

Alexandre Julliard julliard at winehq.org
Thu Jul 16 11:58:18 CDT 2009


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

Author: Piotr Caban <piotr.caban at gmail.com>
Date:   Thu Jul 16 01:16:15 2009 +0200

jscript: Improve Object_toString implementation.

---

 dlls/jscript/jscript.h    |    1 +
 dlls/jscript/object.c     |   26 +++++++++++++++++++++++++-
 dlls/jscript/tests/api.js |   16 ++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index a6c34ba..370b3bd 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -68,6 +68,7 @@ typedef enum {
     JSCLASS_ARRAY,
     JSCLASS_BOOLEAN,
     JSCLASS_DATE,
+    JSCLASS_ERROR,
     JSCLASS_FUNCTION,
     JSCLASS_GLOBAL,
     JSCLASS_MATH,
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index 0dca008..8e0aad6 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -35,13 +35,37 @@ static const WCHAR default_valueW[] = {'[','o','b','j','e','c','t',' ','O','b','
 static HRESULT Object_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 {
+    static const WCHAR formatW[] = {'[','o','b','j','e','c','t',' ','%','s',']',0};
+
+    static const WCHAR arrayW[] = {'A','r','r','a','y',0};
+    static const WCHAR booleanW[] = {'B','o','o','l','e','a','n',0};
+    static const WCHAR dateW[] = {'D','a','t','e',0};
+    static const WCHAR errorW[] = {'E','r','r','o','r',0};
+    static const WCHAR functionW[] = {'F','u','n','c','t','i','o','n',0};
+    static const WCHAR mathW[] = {'M','a','t','h',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 regexpW[] = {'R','e','g','E','x','p',0};
+    static const WCHAR stringW[] = {'S','t','r','i','n','g',0};
+    /* Keep in sync with jsclass_t enum */
+    static const WCHAR *names[] = {NULL, arrayW, booleanW, dateW, errorW,
+        functionW, NULL, mathW, numberW, objectW, regexpW, stringW};
+
     TRACE("\n");
 
+    if(names[dispex->builtin_info->class] == NULL) {
+        ERR("dispex->builtin_info->class = %d\n",
+                dispex->builtin_info->class);
+        return E_FAIL;
+    }
+
     if(retv) {
         V_VT(retv) = VT_BSTR;
-        V_BSTR(retv) = SysAllocString(default_valueW);
+        V_BSTR(retv) = SysAllocStringLen(NULL, 9+strlenW(names[dispex->builtin_info->class]));
         if(!V_BSTR(retv))
             return E_OUTOFMEMORY;
+
+        sprintfW(V_BSTR(retv), formatW, names[dispex->builtin_info->class]);
     }
 
     return S_OK;
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index b347846..6af9bb8 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -60,6 +60,22 @@ ok(tmp === "abc", "encodeURI('abc') = " + tmp);
 
 tmp = "" + new Object();
 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
+(tmp = new Array).f = Object.prototype.toString;
+ok(tmp.f() === "[object Array]", "tmp.f() = " + tmp.f());
+(tmp = new Boolean).f = Object.prototype.toString;
+ok(tmp.f() === "[object Boolean]", "tmp.f() = " + tmp.f());
+(tmp = new Date).f = Object.prototype.toString;
+ok(tmp.f() === "[object Date]", "tmp.f() = " + tmp.f());
+(tmp = function() {}).f = Object.prototype.toString;
+ok(tmp.f() === "[object Function]", "tmp.f() = " + tmp.f());
+Math.f = Object.prototype.toString;
+ok(Math.f() === "[object Math]", "tmp.f() = " + tmp.f());
+(tmp = new Number).f = Object.prototype.toString;
+ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f());
+(tmp = new RegExp("")).f = Object.prototype.toString;
+ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f());
+(tmp = new String).f = Object.prototype.toString;
+ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f());
 
 ok("".length === 0, "\"\".length = " + "".length);
 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);




More information about the wine-cvs mailing list