Module: wine Branch: master Commit: 461180459b7a077fbdd617b51b3d0641863e5921 URL: http://source.winehq.org/git/wine.git/?a=commit;h=461180459b7a077fbdd617b51b...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Sep 23 16:19:58 2009 +0200
jscript: Added Object.toString for host objects implementation.
---
dlls/jscript/object.c | 11 ++++++++--- dlls/jscript/tests/api.js | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c index 7dffff7..f5bc455 100644 --- a/dlls/jscript/object.c +++ b/dlls/jscript/object.c @@ -36,6 +36,7 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { DispatchEx *jsdisp; + const WCHAR *str;
static const WCHAR formatW[] = {'[','o','b','j','e','c','t',' ','%','s',']',0};
@@ -56,18 +57,22 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D TRACE("\n");
jsdisp = get_jsdisp(jsthis); - if(!jsdisp || names[jsdisp->builtin_info->class] == NULL) { + if(!jsdisp) { + str = objectW; + }else if(names[jsdisp->builtin_info->class]) { + str = names[jsdisp->builtin_info->class]; + }else { FIXME("jdisp->builtin_info->class = %d\n", jsdisp->builtin_info->class); return E_FAIL; }
if(retv) { V_VT(retv) = VT_BSTR; - V_BSTR(retv) = SysAllocStringLen(NULL, 9+strlenW(names[jsdisp->builtin_info->class])); + V_BSTR(retv) = SysAllocStringLen(NULL, 9+strlenW(str)); if(!V_BSTR(retv)) return E_OUTOFMEMORY;
- sprintfW(V_BSTR(retv), formatW, names[jsdisp->builtin_info->class]); + sprintfW(V_BSTR(retv), formatW, str); }
return S_OK; diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 7b22212..ee3a058 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -87,6 +87,8 @@ ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f()); 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()); +tmp = Object.prototype.toString.call(testObj); +ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
ok(Object(1) instanceof Number, "Object(1) is not instance of Number"); ok(Object("") instanceof String, "Object('') is not instance of String");