Commit 469b5972 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

jscript: Add error throwing functions.

parent 2d71dac4
...@@ -3,9 +3,11 @@ TOPOBJDIR = ../.. ...@@ -3,9 +3,11 @@ TOPOBJDIR = ../..
SRCDIR = @srcdir@ SRCDIR = @srcdir@
VPATH = @srcdir@ VPATH = @srcdir@
MODULE = jscript.dll 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 = \ C_SRCS = \
array.c \ array.c \
......
...@@ -590,10 +590,8 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA ...@@ -590,10 +590,8 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
TRACE("\n"); TRACE("\n");
if(!is_class(dispex, JSCLASS_DATE)) { if(!is_class(dispex, JSCLASS_DATE))
FIXME("throw TypeError\n"); return throw_type_error(dispex->ctx, ei, IDS_NOT_DATE, NULL);
return E_FAIL;
}
date = (DateInstance*)dispex; date = (DateInstance*)dispex;
time = local_time(date->time, date); time = local_time(date->time, date);
......
...@@ -330,3 +330,63 @@ HRESULT init_error_constr(script_ctx_t *ctx) ...@@ -330,3 +330,63 @@ HRESULT init_error_constr(script_ctx_t *ctx)
return S_OK; 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);
}
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "dispex.h" #include "dispex.h"
#include "activscp.h" #include "activscp.h"
#include "resource.h"
#include "wine/unicode.h" #include "wine/unicode.h"
#include "wine/list.h" #include "wine/list.h"
...@@ -58,6 +60,8 @@ jsheap_t *jsheap_mark(jsheap_t*); ...@@ -58,6 +60,8 @@ jsheap_t *jsheap_mark(jsheap_t*);
typedef struct DispatchEx DispatchEx; typedef struct DispatchEx DispatchEx;
extern HINSTANCE jscript_hinstance;
#define PROPF_ARGMASK 0x00ff #define PROPF_ARGMASK 0x00ff
#define PROPF_METHOD 0x0100 #define PROPF_METHOD 0x0100
#define PROPF_ENUM 0x0200 #define PROPF_ENUM 0x0200
...@@ -139,6 +143,13 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_inf ...@@ -139,6 +143,13 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_inf
DispatchEx*,DispatchEx**); DispatchEx*,DispatchEx**);
HRESULT Function_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*); 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_object(script_ctx_t*,DispatchEx*,DispatchEx**);
HRESULT create_math(script_ctx_t*,DispatchEx**); HRESULT create_math(script_ctx_t*,DispatchEx**);
......
/*
* 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"
}
...@@ -40,7 +40,7 @@ static const CLSID CLSID_JScriptEncode = ...@@ -40,7 +40,7 @@ static const CLSID CLSID_JScriptEncode =
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); 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) static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{ {
......
/*
* 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
...@@ -1288,4 +1288,15 @@ err = new Error("message"); ...@@ -1288,4 +1288,15 @@ err = new Error("message");
ok(err.message === "message", "err.message !== 'message'"); ok(err.message === "message", "err.message !== 'message'");
ok(err.toString() === "[object Error]", "err.toString() = " + err.toString()); 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(); reportSuccess();
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