2009-07-20 18:17:51 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2012-05-29 12:53:55 +02:00
|
|
|
|
2009-07-20 18:18:22 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
2009-07-20 18:17:51 +02:00
|
|
|
|
|
|
|
#include "jscript.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2009-07-20 18:18:17 +02:00
|
|
|
static const WCHAR descriptionW[] = {'d','e','s','c','r','i','p','t','i','o','n',0};
|
2009-07-20 18:17:51 +02:00
|
|
|
static const WCHAR messageW[] = {'m','e','s','s','a','g','e',0};
|
2009-10-19 20:41:02 +02:00
|
|
|
static const WCHAR nameW[] = {'n','a','m','e',0};
|
2009-07-20 18:18:17 +02:00
|
|
|
static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
|
2009-07-20 18:17:51 +02:00
|
|
|
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
|
|
|
|
|
2009-07-20 18:17:57 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.11.4.4 */
|
2010-08-04 15:32:59 +02:00
|
|
|
static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *jsthis;
|
2010-08-04 15:32:59 +02:00
|
|
|
BSTR name = NULL, msg = NULL, ret = NULL;
|
2009-10-19 20:41:02 +02:00
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-08-04 15:32:59 +02:00
|
|
|
static const WCHAR object_errorW[] = {'[','o','b','j','e','c','t',' ','E','r','r','o','r',']',0};
|
2009-07-20 18:17:57 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2010-08-04 15:32:59 +02:00
|
|
|
jsthis = get_jsdisp(vthis);
|
|
|
|
if(!jsthis || ctx->version < 2) {
|
2009-10-19 20:41:02 +02:00
|
|
|
if(retv) {
|
|
|
|
V_VT(retv) = VT_BSTR;
|
2010-08-04 15:32:59 +02:00
|
|
|
V_BSTR(retv) = SysAllocString(object_errorW);
|
2009-10-19 20:41:02 +02:00
|
|
|
if(!V_BSTR(retv))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-12 12:14:38 +01:00
|
|
|
hres = jsdisp_propget_name(jsthis, nameW, &v, ei);
|
2009-10-19 20:41:02 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-08-04 15:32:59 +02:00
|
|
|
if(V_VT(&v) != VT_EMPTY) {
|
|
|
|
hres = to_string(ctx, &v, ei, &name);
|
|
|
|
VariantClear(&v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(!*name) {
|
|
|
|
SysFreeString(name);
|
|
|
|
name = NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-10-19 20:41:02 +02:00
|
|
|
|
2012-03-12 12:14:38 +01:00
|
|
|
hres = jsdisp_propget_name(jsthis, messageW, &v, ei);
|
2010-08-04 15:32:39 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
if(V_VT(&v) != VT_EMPTY) {
|
|
|
|
hres = to_string(ctx, &v, ei, &msg);
|
|
|
|
VariantClear(&v);
|
|
|
|
if(SUCCEEDED(hres) && !*msg) {
|
|
|
|
SysFreeString(msg);
|
|
|
|
msg = NULL;
|
|
|
|
}
|
2009-10-19 20:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2010-08-04 15:32:59 +02:00
|
|
|
if(name && msg) {
|
2009-10-19 20:41:02 +02:00
|
|
|
DWORD name_len, msg_len;
|
|
|
|
|
|
|
|
name_len = SysStringLen(name);
|
|
|
|
msg_len = SysStringLen(msg);
|
|
|
|
|
|
|
|
ret = SysAllocStringLen(NULL, name_len + msg_len + 2);
|
|
|
|
if(ret) {
|
|
|
|
memcpy(ret, name, name_len*sizeof(WCHAR));
|
|
|
|
ret[name_len] = ':';
|
|
|
|
ret[name_len+1] = ' ';
|
|
|
|
memcpy(ret+name_len+2, msg, msg_len*sizeof(WCHAR));
|
|
|
|
}
|
2010-08-04 15:32:59 +02:00
|
|
|
}else if(name) {
|
2009-10-19 20:41:02 +02:00
|
|
|
ret = name;
|
|
|
|
name = NULL;
|
2010-08-04 15:32:59 +02:00
|
|
|
}else if(msg) {
|
|
|
|
ret = msg;
|
|
|
|
msg = NULL;
|
|
|
|
}else {
|
|
|
|
ret = SysAllocString(object_errorW);
|
2009-10-19 20:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SysFreeString(msg);
|
|
|
|
SysFreeString(name);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-07-20 18:17:57 +02:00
|
|
|
if(retv) {
|
|
|
|
V_VT(retv) = VT_BSTR;
|
2009-10-19 20:41:02 +02:00
|
|
|
V_BSTR(retv) = ret;
|
|
|
|
}else {
|
|
|
|
SysFreeString(ret);
|
2009-07-20 18:17:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT Error_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
2009-07-22 13:02:30 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case INVOKE_FUNC:
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
|
2009-07-22 13:02:30 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const builtin_prop_t Error_props[] = {
|
|
|
|
{toStringW, Error_toString, PROPF_METHOD}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t Error_info = {
|
|
|
|
JSCLASS_ERROR,
|
|
|
|
{NULL, Error_value, 0},
|
|
|
|
sizeof(Error_props)/sizeof(*Error_props),
|
|
|
|
Error_props,
|
2010-08-04 15:33:17 +02:00
|
|
|
NULL,
|
2009-07-20 18:17:51 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t ErrorInst_info = {
|
|
|
|
JSCLASS_ERROR,
|
|
|
|
{NULL, Error_value, 0},
|
2010-08-04 15:32:39 +02:00
|
|
|
0,
|
|
|
|
NULL,
|
2010-08-04 15:33:17 +02:00
|
|
|
NULL,
|
2009-07-20 18:17:51 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT alloc_error(script_ctx_t *ctx, jsdisp_t *prototype,
|
|
|
|
jsdisp_t *constr, jsdisp_t **ret)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *err;
|
2009-07-20 18:17:51 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2010-08-04 15:33:17 +02:00
|
|
|
err = heap_alloc_zero(sizeof(*err));
|
2009-07-20 18:17:51 +02:00
|
|
|
if(!err)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-08-14 11:58:10 +02:00
|
|
|
if(prototype)
|
2010-08-04 15:33:17 +02:00
|
|
|
hres = init_dispex(err, ctx, &Error_info, prototype);
|
2009-08-14 11:58:10 +02:00
|
|
|
else
|
2010-08-04 15:33:17 +02:00
|
|
|
hres = init_dispex_from_constr(err, ctx, &ErrorInst_info,
|
2009-08-14 11:58:10 +02:00
|
|
|
constr ? constr : ctx->error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(err);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = err;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT create_error(script_ctx_t *ctx, jsdisp_t *constr,
|
|
|
|
UINT number, const WCHAR *msg, jsdisp_t **ret)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *err;
|
2010-08-02 11:10:03 +02:00
|
|
|
VARIANT v;
|
2009-07-20 18:17:51 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2009-08-14 11:58:10 +02:00
|
|
|
hres = alloc_error(ctx, NULL, constr, &err);
|
2009-07-20 18:17:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-20 11:18:59 +02:00
|
|
|
num_set_int(&v, number);
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propput_name(err, numberW, &v, NULL/*FIXME*/);
|
2010-08-02 11:10:03 +02:00
|
|
|
if(FAILED(hres)) {
|
2010-08-04 15:33:17 +02:00
|
|
|
jsdisp_release(err);
|
2010-08-02 11:10:03 +02:00
|
|
|
return hres;
|
2009-07-20 18:18:22 +02:00
|
|
|
}
|
|
|
|
|
2010-08-04 15:32:39 +02:00
|
|
|
V_VT(&v) = VT_BSTR;
|
|
|
|
if(msg) V_BSTR(&v) = SysAllocString(msg);
|
|
|
|
else V_BSTR(&v) = SysAllocStringLen(NULL, 0);
|
|
|
|
if(V_BSTR(&v)) {
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propput_name(err, messageW, &v, NULL/*FIXME*/);
|
2010-08-04 15:32:39 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propput_name(err, descriptionW, &v, NULL/*FIXME*/);
|
2010-08-04 15:32:39 +02:00
|
|
|
SysFreeString(V_BSTR(&v));
|
|
|
|
}else {
|
|
|
|
hres = E_OUTOFMEMORY;
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
2010-08-04 15:32:11 +02:00
|
|
|
if(FAILED(hres)) {
|
2010-08-04 15:33:17 +02:00
|
|
|
jsdisp_release(err);
|
2010-08-04 15:32:11 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2010-08-04 15:33:17 +02:00
|
|
|
*ret = err;
|
2009-07-20 18:17:51 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, VARIANT *argv,
|
2010-09-06 16:11:49 +02:00
|
|
|
VARIANT *retv, jsexcept_t *ei, jsdisp_t *constr) {
|
|
|
|
jsdisp_t *err;
|
2010-08-02 11:10:03 +02:00
|
|
|
UINT num = 0;
|
2009-07-20 18:17:51 +02:00
|
|
|
BSTR msg = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc) {
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2010-08-02 11:10:03 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
hres = to_number(ctx, argv, ei, &n);
|
2012-03-27 11:28:51 +02:00
|
|
|
if(FAILED(hres)) /* FIXME: really? */
|
2012-05-29 12:53:55 +02:00
|
|
|
n = NAN;
|
2012-03-27 11:28:51 +02:00
|
|
|
if(isnan(n))
|
2012-06-25 14:08:38 +02:00
|
|
|
hres = to_string(ctx, argv, ei, &msg);
|
2009-07-20 18:18:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
num = n;
|
2009-07-20 18:18:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc>1 && !msg) {
|
|
|
|
hres = to_string(ctx, argv+1, ei, &msg);
|
2009-07-20 18:17:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case INVOKE_FUNC:
|
|
|
|
case DISPATCH_CONSTRUCT:
|
2010-08-02 11:10:03 +02:00
|
|
|
hres = create_error(ctx, constr, num, msg, &err);
|
2009-12-31 13:03:01 +01:00
|
|
|
SysFreeString(msg);
|
2009-07-20 18:18:22 +02:00
|
|
|
|
2009-07-20 18:17:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-09-07 15:41:40 +02:00
|
|
|
if(retv)
|
|
|
|
var_set_jsdisp(retv, err);
|
2009-07-20 18:17:51 +02:00
|
|
|
else
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(err);
|
2009-07-20 18:17:51 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT ErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT EvalErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->eval_error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT RangeErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->range_error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT ReferenceErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->reference_error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT RegExpErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-09-23 16:09:22 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->regexp_error_constr);
|
2009-09-23 16:09:22 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT SyntaxErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->syntax_error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT TypeErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->type_error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static HRESULT URIErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc, VARIANT *argv, VARIANT *retv, jsexcept_t *ei)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-06-25 14:08:38 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, retv, ei, ctx->uri_error_constr);
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT init_error_constr(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
static const WCHAR ErrorW[] = {'E','r','r','o','r',0};
|
|
|
|
static const WCHAR EvalErrorW[] = {'E','v','a','l','E','r','r','o','r',0};
|
|
|
|
static const WCHAR RangeErrorW[] = {'R','a','n','g','e','E','r','r','o','r',0};
|
|
|
|
static const WCHAR ReferenceErrorW[] = {'R','e','f','e','r','e','n','c','e','E','r','r','o','r',0};
|
2009-09-23 16:09:22 +02:00
|
|
|
static const WCHAR RegExpErrorW[] = {'R','e','g','E','x','p','E','r','r','o','r',0};
|
2009-07-20 18:17:51 +02:00
|
|
|
static const WCHAR SyntaxErrorW[] = {'S','y','n','t','a','x','E','r','r','o','r',0};
|
|
|
|
static const WCHAR TypeErrorW[] = {'T','y','p','e','E','r','r','o','r',0};
|
|
|
|
static const WCHAR URIErrorW[] = {'U','R','I','E','r','r','o','r',0};
|
|
|
|
static const WCHAR *names[] = {ErrorW, EvalErrorW, RangeErrorW,
|
2009-09-23 16:09:22 +02:00
|
|
|
ReferenceErrorW, RegExpErrorW, SyntaxErrorW, TypeErrorW, URIErrorW};
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t **constr_addr[] = {&ctx->error_constr, &ctx->eval_error_constr,
|
2009-09-23 16:09:22 +02:00
|
|
|
&ctx->range_error_constr, &ctx->reference_error_constr, &ctx->regexp_error_constr,
|
2009-07-20 18:17:51 +02:00
|
|
|
&ctx->syntax_error_constr, &ctx->type_error_constr,
|
|
|
|
&ctx->uri_error_constr};
|
|
|
|
static builtin_invoke_t constr_val[] = {ErrorConstr_value, EvalErrorConstr_value,
|
2009-09-23 16:09:22 +02:00
|
|
|
RangeErrorConstr_value, ReferenceErrorConstr_value, RegExpErrorConstr_value,
|
|
|
|
SyntaxErrorConstr_value, TypeErrorConstr_value, URIErrorConstr_value};
|
2009-07-20 18:17:51 +02:00
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *err;
|
2009-07-20 18:17:51 +02:00
|
|
|
INT i;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-09-23 16:09:22 +02:00
|
|
|
for(i=0; i < sizeof(names)/sizeof(names[0]); i++) {
|
2009-08-14 11:58:10 +02:00
|
|
|
hres = alloc_error(ctx, i==0 ? object_prototype : NULL, NULL, &err);
|
2009-07-20 18:17:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_BSTR;
|
|
|
|
V_BSTR(&v) = SysAllocString(names[i]);
|
|
|
|
if(!V_BSTR(&v)) {
|
2010-08-04 15:33:17 +02:00
|
|
|
jsdisp_release(err);
|
2009-07-20 18:17:51 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propput_name(err, nameW, &v, NULL/*FIXME*/);
|
2009-07-20 18:17:51 +02:00
|
|
|
|
|
|
|
if(SUCCEEDED(hres))
|
2012-07-16 15:31:37 +02:00
|
|
|
hres = create_builtin_constructor(ctx, constr_val[i], names[i], NULL,
|
2010-08-04 15:33:17 +02:00
|
|
|
PROPF_CONSTR|1, err, constr_addr[i]);
|
2009-07-20 18:17:51 +02:00
|
|
|
|
2010-08-04 15:33:17 +02:00
|
|
|
jsdisp_release(err);
|
2009-07-20 18:17:51 +02:00
|
|
|
VariantClear(&v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-07-20 18:18:00 +02:00
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str, jsdisp_t *constr)
|
2009-07-20 18:18:00 +02:00
|
|
|
{
|
|
|
|
WCHAR buf[1024], *pos = NULL;
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *err;
|
2009-07-20 18:18:00 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
if(!is_jscript_error(error))
|
|
|
|
return error;
|
|
|
|
|
2009-07-24 09:35:56 +02:00
|
|
|
buf[0] = '\0';
|
2010-12-28 15:04:59 +01:00
|
|
|
LoadStringW(jscript_hinstance, HRESULT_CODE(error), buf, sizeof(buf)/sizeof(WCHAR));
|
2009-07-20 18:18:00 +02:00
|
|
|
|
|
|
|
if(str) pos = strchrW(buf, '|');
|
|
|
|
if(pos) {
|
|
|
|
int len = strlenW(str);
|
2009-07-22 13:01:59 +02:00
|
|
|
memmove(pos+len, pos+1, (strlenW(pos+1)+1)*sizeof(WCHAR));
|
2009-07-20 18:18:00 +02:00
|
|
|
memcpy(pos, str, len*sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
|
2009-07-22 13:01:59 +02:00
|
|
|
WARN("%s\n", debugstr_w(buf));
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
hres = create_error(ctx, constr, error, buf, &err);
|
2009-07-20 18:18:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-09-07 15:41:40 +02:00
|
|
|
if(ei)
|
|
|
|
var_set_jsdisp(&ei->var, err);
|
2010-12-28 15:04:59 +01:00
|
|
|
return error;
|
2009-07-20 18:18:00 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
HRESULT throw_generic_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
|
2009-09-30 14:34:47 +02:00
|
|
|
{
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_error(ctx, ei, error, str, ctx->error_constr);
|
2009-09-30 14:34:47 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
HRESULT throw_range_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
|
2009-07-20 18:18:00 +02:00
|
|
|
{
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_error(ctx, ei, error, str, ctx->range_error_constr);
|
2009-07-20 18:18:00 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
HRESULT throw_reference_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
|
2009-07-20 18:18:00 +02:00
|
|
|
{
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_error(ctx, ei, error, str, ctx->reference_error_constr);
|
2009-07-20 18:18:00 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
HRESULT throw_regexp_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
|
2009-09-23 16:09:22 +02:00
|
|
|
{
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_error(ctx, ei, error, str, ctx->regexp_error_constr);
|
2009-09-23 16:09:22 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
HRESULT throw_syntax_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
|
2009-07-20 18:18:00 +02:00
|
|
|
{
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_error(ctx, ei, error, str, ctx->syntax_error_constr);
|
2009-07-20 18:18:00 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
HRESULT throw_type_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
|
2009-07-20 18:18:00 +02:00
|
|
|
{
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_error(ctx, ei, error, str, ctx->type_error_constr);
|
2009-07-20 18:18:00 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 15:04:59 +01:00
|
|
|
HRESULT throw_uri_error(script_ctx_t *ctx, jsexcept_t *ei, HRESULT error, const WCHAR *str)
|
2009-07-20 18:18:00 +02:00
|
|
|
{
|
2010-12-28 15:04:59 +01:00
|
|
|
return throw_error(ctx, ei, error, str, ctx->uri_error_constr);
|
2009-07-20 18:18:00 +02:00
|
|
|
}
|