Commit 46118045 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added Object.toString for host objects implementation.

parent 37c2d43e
...@@ -36,6 +36,7 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D ...@@ -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) VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{ {
DispatchEx *jsdisp; DispatchEx *jsdisp;
const WCHAR *str;
static const WCHAR formatW[] = {'[','o','b','j','e','c','t',' ','%','s',']',0}; 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 ...@@ -56,18 +57,22 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, D
TRACE("\n"); TRACE("\n");
jsdisp = get_jsdisp(jsthis); 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); FIXME("jdisp->builtin_info->class = %d\n", jsdisp->builtin_info->class);
return E_FAIL; return E_FAIL;
} }
if(retv) { if(retv) {
V_VT(retv) = VT_BSTR; 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)) if(!V_BSTR(retv))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
sprintfW(V_BSTR(retv), formatW, names[jsdisp->builtin_info->class]); sprintfW(V_BSTR(retv), formatW, str);
} }
return S_OK; return S_OK;
......
...@@ -87,6 +87,8 @@ ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f()); ...@@ -87,6 +87,8 @@ ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f());
ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f()); ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f());
(tmp = new String).f = Object.prototype.toString; (tmp = new String).f = Object.prototype.toString;
ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f()); 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(1) instanceof Number, "Object(1) is not instance of Number");
ok(Object("") instanceof String, "Object('') is not instance of String"); ok(Object("") instanceof String, "Object('') is not instance of String");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment