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

jscript: Fixed Error.toString implementation for non-Error this.

parent 04819e90
...@@ -47,39 +47,45 @@ static inline ErrorInstance *error_this(vdisp_t *jsthis) ...@@ -47,39 +47,45 @@ static inline ErrorInstance *error_this(vdisp_t *jsthis)
} }
/* ECMA-262 3rd Edition 15.11.4.4 */ /* ECMA-262 3rd Edition 15.11.4.4 */
static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{ {
ErrorInstance *error; DispatchEx *jsthis;
BSTR name, msg = NULL, ret = NULL; BSTR name = NULL, msg = NULL, ret = NULL;
VARIANT v; VARIANT v;
HRESULT hres; HRESULT hres;
static const WCHAR str[] = {'[','o','b','j','e','c','t',' ','E','r','r','o','r',']',0}; static const WCHAR object_errorW[] = {'[','o','b','j','e','c','t',' ','E','r','r','o','r',']',0};
TRACE("\n"); TRACE("\n");
error = error_this(jsthis); jsthis = get_jsdisp(vthis);
if(ctx->version < 2 || !error) { if(!jsthis || ctx->version < 2) {
if(retv) { if(retv) {
V_VT(retv) = VT_BSTR; V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(str); V_BSTR(retv) = SysAllocString(object_errorW);
if(!V_BSTR(retv)) if(!V_BSTR(retv))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
return S_OK; return S_OK;
} }
hres = jsdisp_propget_name(&error->dispex, nameW, &v, ei, caller); hres = jsdisp_propget_name(jsthis, nameW, &v, ei, caller);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = to_string(ctx, &v, ei, &name); if(V_VT(&v) != VT_EMPTY) {
VariantClear(&v); hres = to_string(ctx, &v, ei, &name);
if(FAILED(hres)) VariantClear(&v);
return hres; if(FAILED(hres))
return hres;
if(!*name) {
SysFreeString(name);
name = NULL;
}
}
hres = jsdisp_propget_name(&error->dispex, messageW, &v, ei, caller); hres = jsdisp_propget_name(jsthis, messageW, &v, ei, caller);
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
if(V_VT(&v) != VT_EMPTY) { if(V_VT(&v) != VT_EMPTY) {
hres = to_string(ctx, &v, ei, &msg); hres = to_string(ctx, &v, ei, &msg);
...@@ -92,7 +98,7 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -92,7 +98,7 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
} }
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
if(msg) { if(name && msg) {
DWORD name_len, msg_len; DWORD name_len, msg_len;
name_len = SysStringLen(name); name_len = SysStringLen(name);
...@@ -105,9 +111,16 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -105,9 +111,16 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
ret[name_len+1] = ' '; ret[name_len+1] = ' ';
memcpy(ret+name_len+2, msg, msg_len*sizeof(WCHAR)); memcpy(ret+name_len+2, msg, msg_len*sizeof(WCHAR));
} }
}else { }else if(name) {
ret = name; ret = name;
name = NULL; name = NULL;
}else if(msg) {
ret = msg;
msg = NULL;
}else {
ret = SysAllocString(object_errorW);
if(!V_BSTR(retv))
hres = E_OUTOFMEMORY;
} }
} }
......
...@@ -1780,6 +1780,12 @@ ok(err.message === "message", "err.message = " + err.message); ...@@ -1780,6 +1780,12 @@ ok(err.message === "message", "err.message = " + err.message);
ok(err.description === "message", "err.description = " + err.description); ok(err.description === "message", "err.description = " + err.description);
err = new Error(); err = new Error();
ok(err.number === 0, "err.number = " + err.number); ok(err.number === 0, "err.number = " + err.number);
ok(err.description === "", "err.description = " + err.description);
err.description = 5;
ok(err.description === 5, "err.description = " + err.description);
ok(err.message === "", "err.message = " + err.message);
err.message = 4;
ok(err.message === 4, "err.message = " + err.message);
ok(!("number" in Error), "number is in Error"); ok(!("number" in Error), "number is in Error");
...@@ -1789,6 +1795,33 @@ tmp.toString = function() { return "test"; }; ...@@ -1789,6 +1795,33 @@ tmp.toString = function() { return "test"; };
tmp = Error.prototype.toString.call(tmp); tmp = Error.prototype.toString.call(tmp);
ok(tmp === "[object Error]", "Error.prototype.toString.call(tmp) = " + tmp); ok(tmp === "[object Error]", "Error.prototype.toString.call(tmp) = " + tmp);
if(invokeVersion >= 2) {
obj = new Object();
obj.name = "test";
tmp = Error.prototype.toString.call(obj);
ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
obj = new Object();
obj.name = 6;
obj.message = false;
tmp = Error.prototype.toString.call(obj);
ok(tmp === "6: false", "Error.prototype.toString.call(obj) = " + tmp);
obj = new Object();
obj.message = "test";
tmp = Error.prototype.toString.call(obj);
ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
obj = new Object();
obj.name = "";
obj.message = "test";
tmp = Error.prototype.toString.call(obj);
ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
}
tmp = Error.prototype.toString.call(testObj);
ok(tmp === "[object Error]", "Error.prototype.toString.call(testObj) = " + tmp);
err = new Error(); err = new Error();
err.name = null; err.name = null;
ok(err.name === null, "err.name = " + err.name + " expected null"); ok(err.name === null, "err.name = " + err.name + " expected null");
......
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