mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-14 17:16:18 +00:00
jscript: Add Error_number handling to constructor and error throwing functions.
This commit is contained in:
parent
f3eef0d4c8
commit
a77e369cfe
|
@ -15,6 +15,10 @@
|
|||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "wine/port.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "jscript.h"
|
||||
|
||||
|
@ -213,7 +217,7 @@ static HRESULT alloc_error(script_ctx_t *ctx, BOOL error_prototype,
|
|||
}
|
||||
|
||||
static HRESULT create_error(script_ctx_t *ctx, DispatchEx *constr,
|
||||
const WCHAR *msg, DispatchEx **ret)
|
||||
const UINT *number, const WCHAR *msg, DispatchEx **ret)
|
||||
{
|
||||
ErrorInstance *err;
|
||||
HRESULT hres;
|
||||
|
@ -222,10 +226,17 @@ static HRESULT create_error(script_ctx_t *ctx, DispatchEx *constr,
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
if(number) {
|
||||
V_VT(&err->number) = VT_I4;
|
||||
V_I4(&err->number) = *number;
|
||||
}
|
||||
|
||||
V_VT(&err->message) = VT_BSTR;
|
||||
if(msg) V_BSTR(&err->message) = SysAllocString(msg);
|
||||
else V_BSTR(&err->message) = SysAllocStringLen(NULL, 0);
|
||||
|
||||
VariantCopy(&err->description, &err->message);
|
||||
|
||||
if(!V_BSTR(&err->message)) {
|
||||
heap_free(err);
|
||||
return E_OUTOFMEMORY;
|
||||
|
@ -238,11 +249,28 @@ static HRESULT create_error(script_ctx_t *ctx, DispatchEx *constr,
|
|||
static HRESULT error_constr(DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, DispatchEx *constr) {
|
||||
DispatchEx *err;
|
||||
VARIANT numv;
|
||||
UINT num;
|
||||
BSTR msg = NULL;
|
||||
HRESULT hres;
|
||||
|
||||
V_VT(&numv) = VT_NULL;
|
||||
|
||||
if(arg_cnt(dp)) {
|
||||
hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &msg);
|
||||
hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &numv);
|
||||
if(FAILED(hres) || (V_VT(&numv)==VT_R8 && isnan(V_R8(&numv))))
|
||||
hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &msg);
|
||||
else if(V_VT(&numv) == VT_I4)
|
||||
num = V_I4(&numv);
|
||||
else
|
||||
num = V_R8(&numv);
|
||||
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
}
|
||||
|
||||
if(arg_cnt(dp)>1 && !msg) {
|
||||
hres = to_string(dispex->ctx, get_arg(dp, 1), ei, &msg);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
}
|
||||
|
@ -250,7 +278,11 @@ static HRESULT error_constr(DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
|
|||
switch(flags) {
|
||||
case INVOKE_FUNC:
|
||||
case DISPATCH_CONSTRUCT:
|
||||
hres = create_error(dispex->ctx, constr, msg, &err);
|
||||
if(V_VT(&numv) == VT_NULL)
|
||||
hres = create_error(dispex->ctx, constr, NULL, msg, &err);
|
||||
else
|
||||
hres = create_error(dispex->ctx, constr, &num, msg, &err);
|
||||
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
@ -394,7 +426,8 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH
|
|||
memcpy(pos, str, len*sizeof(WCHAR));
|
||||
}
|
||||
|
||||
hres = create_error(ctx, constr, buf, &err);
|
||||
id |= 0x800A0000;
|
||||
hres = create_error(ctx, constr, &id, buf, &err);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
@ -404,7 +437,7 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH
|
|||
V_VT(&ei->var) = VT_DISPATCH;
|
||||
V_DISPATCH(&ei->var) = (IDispatch*)_IDispatchEx_(err);
|
||||
|
||||
return 0x800A0000+id;
|
||||
return id;
|
||||
}
|
||||
|
||||
HRESULT throw_eval_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
|
||||
|
|
|
@ -1287,22 +1287,31 @@ ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
|
|||
err = new Error("message");
|
||||
ok(err.message === "message", "err.message !== 'message'");
|
||||
ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
|
||||
err = new Error(123);
|
||||
ok(err.number === 123, "err.number = " + err.number);
|
||||
err = new Error(0, "message");
|
||||
ok(err.number === 0, "err.number = " + err.number);
|
||||
ok(err.message === "message", "err.message = " + err.message);
|
||||
ok(err.description === "message", "err.description = " + err.description);
|
||||
|
||||
function exception_test(func, type) {
|
||||
function exception_test(func, type, number) {
|
||||
ret = "";
|
||||
num = "";
|
||||
try {
|
||||
func();
|
||||
} catch(e) {
|
||||
ret = e.name;
|
||||
num = e.number;
|
||||
}
|
||||
ok(ret === type, "Exception test, ret = " + ret + ", expected " + type +". Executed function: " + func.toString());
|
||||
ok(num === number, "Exception test, num = " + num + ", expected " + number + ". Executed function: " + func.toString());
|
||||
}
|
||||
exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError");
|
||||
exception_test(function() {Array(-3);}, "RangeError");
|
||||
exception_test(function() {arr.toString = Boolean.prototype.toString; arr.toString();}, "TypeError");
|
||||
exception_test(function() {date.setTime();}, "TypeError");
|
||||
exception_test(function() {arr.test();}, "TypeError");
|
||||
exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError");
|
||||
exception_test(function() {(new Number(3)).toString(1);}, "TypeError");
|
||||
exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError", -2146823282);
|
||||
exception_test(function() {Array(-3);}, "RangeError", -2146823259);
|
||||
exception_test(function() {arr.toString = Boolean.prototype.toString; arr.toString();}, "TypeError", -2146823278);
|
||||
exception_test(function() {date.setTime();}, "TypeError", -2146827839);
|
||||
exception_test(function() {arr.test();}, "TypeError", -2146827850);
|
||||
exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError", -2146823287);
|
||||
exception_test(function() {(new Number(3)).toString(1);}, "TypeError", -2146828283);
|
||||
|
||||
reportSuccess();
|
||||
|
|
Loading…
Reference in a new issue