jscript: Add error throwing functions.

This commit is contained in:
Piotr Caban 2009-07-20 18:18:00 +02:00 committed by Alexandre Julliard
parent 2d71dac412
commit 469b597212
8 changed files with 136 additions and 7 deletions

View file

@ -3,9 +3,11 @@ TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = jscript.dll
IMPORTS = oleaut32 advapi32 kernel32
IMPORTS = oleaut32 user32 advapi32 kernel32
RC_SRCS = rsrc.rc
RC_SRCS = \
jscript_En.rc \
rsrc.rc
C_SRCS = \
array.c \

View file

@ -590,10 +590,8 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
TRACE("\n");
if(!is_class(dispex, JSCLASS_DATE)) {
FIXME("throw TypeError\n");
return E_FAIL;
}
if(!is_class(dispex, JSCLASS_DATE))
return throw_type_error(dispex->ctx, ei, IDS_NOT_DATE, NULL);
date = (DateInstance*)dispex;
time = local_time(date->time, date);

View file

@ -330,3 +330,63 @@ HRESULT init_error_constr(script_ctx_t *ctx)
return S_OK;
}
static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str, DispatchEx *constr)
{
WCHAR buf[1024], *pos = NULL;
DispatchEx *err;
HRESULT hres;
TRACE("\n");
LoadStringW(jscript_hinstance, id, buf, sizeof(buf)/sizeof(WCHAR));
if(str) pos = strchrW(buf, '|');
if(pos) {
int len = strlenW(str);
memmove(pos+len, pos+1, strlenW(pos+1)*sizeof(WCHAR));
memcpy(pos, str, len*sizeof(WCHAR));
}
hres = create_error(ctx, constr, buf, &err);
if(FAILED(hres))
return hres;
if(!ei)
return id;
V_VT(&ei->var) = VT_DISPATCH;
V_DISPATCH(&ei->var) = (IDispatch*)_IDispatchEx_(err);
return 0x800A0000+id;
}
HRESULT throw_eval_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
{
return throw_error(ctx, ei, id, str, ctx->eval_error_constr);
}
HRESULT throw_range_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
{
return throw_error(ctx, ei, id, str, ctx->range_error_constr);
}
HRESULT throw_reference_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
{
return throw_error(ctx, ei, id, str, ctx->reference_error_constr);
}
HRESULT throw_syntax_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
{
return throw_error(ctx, ei, id, str, ctx->syntax_error_constr);
}
HRESULT throw_type_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
{
return throw_error(ctx, ei, id, str, ctx->type_error_constr);
}
HRESULT throw_uri_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
{
return throw_error(ctx, ei, id, str, ctx->uri_error_constr);
}

View file

@ -28,6 +28,8 @@
#include "dispex.h"
#include "activscp.h"
#include "resource.h"
#include "wine/unicode.h"
#include "wine/list.h"
@ -58,6 +60,8 @@ jsheap_t *jsheap_mark(jsheap_t*);
typedef struct DispatchEx DispatchEx;
extern HINSTANCE jscript_hinstance;
#define PROPF_ARGMASK 0x00ff
#define PROPF_METHOD 0x0100
#define PROPF_ENUM 0x0200
@ -139,6 +143,13 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_inf
DispatchEx*,DispatchEx**);
HRESULT Function_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT throw_reference_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT throw_syntax_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT throw_type_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
HRESULT create_math(script_ctx_t*,DispatchEx**);

View file

@ -0,0 +1,26 @@
/*
* Copyright 2009 Piotr Caban
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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 "resource.h"
LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
STRINGTABLE DISCARDABLE
{
IDS_NOT_DATE "'[object]' is not a date object"
}

View file

@ -40,7 +40,7 @@ static const CLSID CLSID_JScriptEncode =
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
static HINSTANCE jscript_hinstance;
HINSTANCE jscript_hinstance;
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{

21
dlls/jscript/resource.h Normal file
View file

@ -0,0 +1,21 @@
/*
* Copyright 2009 Piotr Caban
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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 <windef.h>
#define IDS_NOT_DATE 0x138E

View file

@ -1288,4 +1288,15 @@ err = new Error("message");
ok(err.message === "message", "err.message !== 'message'");
ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
function exception_test(func, type) {
ret = "";
try {
func();
} catch(e) {
ret = e.name;
}
ok(ret === type, "Exception test, ret = " + ret + ", expected " + type +". Executed function: " + func.toString());
}
exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError");
reportSuccess();