jscript: Added Object.toString for host objects implementation.

This commit is contained in:
Jacek Caban 2009-09-23 16:19:58 +02:00 committed by Alexandre Julliard
parent 37c2d43e28
commit 461180459b
2 changed files with 10 additions and 3 deletions

View File

@ -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;

View File

@ -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");