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 <math.h>
|
2020-01-31 17:22:42 +01:00
|
|
|
#include <assert.h>
|
2020-01-31 17:22:48 +01:00
|
|
|
#include <wchar.h>
|
2009-07-20 18:17:51 +02:00
|
|
|
|
|
|
|
#include "jscript.h"
|
2020-01-30 15:50:15 +01:00
|
|
|
#include "engine.h"
|
2009-07-20 18:17:51 +02:00
|
|
|
|
|
|
|
#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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *jsthis;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *name = NULL, *msg = NULL, *ret = NULL;
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_t v;
|
2009-10-19 20:41:02 +02:00
|
|
|
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) {
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *str;
|
|
|
|
|
|
|
|
str = jsstr_alloc(object_errorW);
|
|
|
|
if(!str)
|
2009-10-19 20:41:02 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2012-10-11 12:16:01 +02:00
|
|
|
*r = jsval_string(str);
|
2009-10-19 20:41:02 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = jsdisp_propget_name(jsthis, nameW, &v);
|
2009-10-19 20:41:02 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
if(!is_undefined(v)) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_string(ctx, v, &name);
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_release(v);
|
2010-08-04 15:32:59 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
2009-10-19 20:41:02 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = jsdisp_propget_name(jsthis, messageW, &v);
|
2010-08-04 15:32:39 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2012-09-17 15:16:42 +02:00
|
|
|
if(!is_undefined(v)) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_string(ctx, v, &msg);
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_release(v);
|
2009-10-19 20:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
unsigned name_len = name ? jsstr_length(name) : 0;
|
|
|
|
unsigned msg_len = msg ? jsstr_length(msg) : 0;
|
2009-10-19 20:41:02 +02:00
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
if(name_len && msg_len) {
|
2013-03-25 12:28:38 +01:00
|
|
|
WCHAR *ptr;
|
|
|
|
|
2016-09-07 10:50:11 +02:00
|
|
|
ret = jsstr_alloc_buf(name_len + msg_len + 2, &ptr);
|
|
|
|
if(ret) {
|
2013-03-25 12:28:38 +01:00
|
|
|
jsstr_flush(name, ptr);
|
|
|
|
ptr[name_len] = ':';
|
|
|
|
ptr[name_len+1] = ' ';
|
|
|
|
jsstr_flush(msg, ptr+name_len+2);
|
|
|
|
}else {
|
|
|
|
hres = E_OUTOFMEMORY;
|
2009-10-19 20:41:02 +02:00
|
|
|
}
|
2012-10-11 12:16:01 +02:00
|
|
|
}else if(name_len) {
|
2009-10-19 20:41:02 +02:00
|
|
|
ret = name;
|
|
|
|
name = NULL;
|
2012-10-11 12:16:01 +02:00
|
|
|
}else if(msg_len) {
|
2010-08-04 15:32:59 +02:00
|
|
|
ret = msg;
|
|
|
|
msg = NULL;
|
|
|
|
}else {
|
2012-10-11 12:16:01 +02:00
|
|
|
ret = jsstr_alloc(object_errorW);
|
2009-10-19 20:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
if(msg)
|
|
|
|
jsstr_release(msg);
|
|
|
|
if(name)
|
|
|
|
jsstr_release(name);
|
2009-10-19 20:41:02 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(ret);
|
|
|
|
else
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_release(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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
2009-07-22 13:02:30 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case INVOKE_FUNC:
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_FUNCTION_EXPECTED;
|
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},
|
2018-07-09 20:59:12 +02:00
|
|
|
ARRAY_SIZE(Error_props),
|
2009-07-20 18:17:51 +02:00
|
|
|
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,
|
2013-03-08 11:37:30 +01:00
|
|
|
UINT number, jsstr_t *msg, 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;
|
|
|
|
|
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;
|
|
|
|
|
2018-05-14 13:33:24 +02:00
|
|
|
hres = jsdisp_define_data_property(err, numberW, PROPF_WRITABLE | PROPF_CONFIGURABLE,
|
|
|
|
jsval_number((INT)number));
|
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
|
|
|
}
|
|
|
|
|
2018-05-14 13:33:24 +02:00
|
|
|
hres = jsdisp_define_data_property(err, messageW,
|
|
|
|
PROPF_WRITABLE | PROPF_ENUMERABLE | PROPF_CONFIGURABLE,
|
|
|
|
jsval_string(msg));
|
2013-03-08 11:37:30 +01:00
|
|
|
if(SUCCEEDED(hres))
|
2018-05-14 13:33:24 +02:00
|
|
|
hres = jsdisp_define_data_property(err, descriptionW, PROPF_WRITABLE | PROPF_CONFIGURABLE,
|
|
|
|
jsval_string(msg));
|
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-09-17 15:16:42 +02:00
|
|
|
static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r, jsdisp_t *constr) {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *err;
|
2010-08-02 11:10:03 +02:00
|
|
|
UINT num = 0;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *msg = NULL;
|
2009-07-20 18:17:51 +02:00
|
|
|
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-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &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-09-18 19:01:49 +02:00
|
|
|
hres = to_string(ctx, argv[0], &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
|
|
|
}
|
|
|
|
|
2013-03-08 11:37:30 +01:00
|
|
|
if(!msg) {
|
|
|
|
if(argc > 1) {
|
|
|
|
hres = to_string(ctx, argv[1], &msg);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}else {
|
|
|
|
msg = jsstr_empty();
|
|
|
|
}
|
2009-07-20 18:17:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case INVOKE_FUNC:
|
|
|
|
case DISPATCH_CONSTRUCT:
|
2013-03-08 11:37:30 +01:00
|
|
|
hres = create_error(ctx, constr, num, msg, &err);
|
|
|
|
jsstr_release(msg);
|
2009-07-20 18:17:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_obj(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:
|
2012-10-11 12:16:01 +02:00
|
|
|
if(msg)
|
|
|
|
jsstr_release(msg);
|
2009-07-20 18:17:51 +02:00
|
|
|
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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-09-23 16:09:22 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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-09-18 19:01:49 +02:00
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-07-20 18:17:51 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return error_constr(ctx, flags, argc, argv, r, 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;
|
2013-02-09 23:32:02 +01:00
|
|
|
unsigned int i;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *str;
|
2009-07-20 18:17:51 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2018-07-09 20:59:12 +02:00
|
|
|
for(i=0; i < ARRAY_SIZE(names); 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;
|
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
str = jsstr_alloc(names[i]);
|
2012-09-17 15:16:42 +02:00
|
|
|
if(!str) {
|
2010-08-04 15:33:17 +02:00
|
|
|
jsdisp_release(err);
|
2009-07-20 18:17:51 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2018-05-14 13:33:24 +02:00
|
|
|
hres = jsdisp_define_data_property(err, nameW, PROPF_WRITABLE | PROPF_CONFIGURABLE,
|
|
|
|
jsval_string(str));
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_release(str);
|
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
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-07-20 18:18:00 +02:00
|
|
|
|
2020-01-31 17:22:48 +01:00
|
|
|
static jsstr_t *format_error_message(HRESULT error, const WCHAR *arg)
|
|
|
|
{
|
|
|
|
size_t len, arg_len = 0;
|
|
|
|
const WCHAR *res, *pos;
|
|
|
|
WCHAR *buf, *p;
|
|
|
|
jsstr_t *r;
|
|
|
|
|
|
|
|
if(!is_jscript_error(error))
|
|
|
|
return jsstr_empty();
|
|
|
|
|
|
|
|
len = LoadStringW(jscript_hinstance, HRESULT_CODE(error), (WCHAR*)&res, 0);
|
|
|
|
|
|
|
|
pos = wmemchr(res, '|', len);
|
|
|
|
if(pos && arg)
|
|
|
|
arg_len = lstrlenW(arg);
|
|
|
|
r = jsstr_alloc_buf(len + arg_len - (pos ? 1 : 0), &buf);
|
|
|
|
if(!r)
|
|
|
|
return jsstr_empty();
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
if(pos > res) {
|
|
|
|
memcpy(p, res, (pos - res) * sizeof(WCHAR));
|
|
|
|
p += pos - res;
|
|
|
|
}
|
|
|
|
pos = pos ? pos + 1 : res;
|
|
|
|
if(arg_len) {
|
|
|
|
memcpy(p, arg, arg_len * sizeof(WCHAR));
|
|
|
|
p += arg_len;
|
|
|
|
}
|
|
|
|
if(pos != res + len)
|
|
|
|
memcpy(p, pos, (res + len - pos) * sizeof(WCHAR));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-02-03 14:47:32 +01:00
|
|
|
HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
|
2009-07-20 18:18:00 +02:00
|
|
|
{
|
2020-02-03 14:47:32 +01:00
|
|
|
jsexcept_t *ei = ctx->ei;
|
|
|
|
TRACE("%08x\n", error);
|
|
|
|
reset_ei(ei);
|
|
|
|
ei->error = error;
|
|
|
|
if(str)
|
|
|
|
ei->message = format_error_message(error, str);
|
|
|
|
return DISP_E_EXCEPTION;
|
2009-07-20 18:18:00 +02:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:28:38 +01:00
|
|
|
void set_error_location(jsexcept_t *ei, bytecode_t *code, unsigned loc, unsigned source_id, jsstr_t *line)
|
2020-02-03 14:47:15 +01:00
|
|
|
{
|
|
|
|
if(is_jscript_error(ei->error)) {
|
|
|
|
if(!ei->source) {
|
|
|
|
const WCHAR *res;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = LoadStringW(jscript_hinstance, source_id, (WCHAR*)&res, 0);
|
|
|
|
ei->source = jsstr_alloc_len(res, len);
|
|
|
|
}
|
2020-02-03 14:47:25 +01:00
|
|
|
if(!ei->message)
|
|
|
|
ei->message = format_error_message(ei->error, NULL);
|
2020-02-03 14:47:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("source %s in %s\n", debugstr_w(code->source + loc), debugstr_w(code->source));
|
|
|
|
|
|
|
|
ei->code = bytecode_addref(code);
|
|
|
|
ei->loc = loc;
|
2020-02-04 20:28:38 +01:00
|
|
|
if(line)
|
|
|
|
ei->line = jsstr_addref(line);
|
2020-02-03 14:47:15 +01:00
|
|
|
}
|
|
|
|
|
2020-01-31 17:22:42 +01:00
|
|
|
jsdisp_t *create_builtin_error(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
jsdisp_t *constr = ctx->error_constr, *r;
|
|
|
|
jsexcept_t *ei = ctx->ei;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
assert(FAILED(ei->error) && ei->error != DISP_E_EXCEPTION);
|
|
|
|
|
|
|
|
if(is_jscript_error(ei->error)) {
|
|
|
|
switch(ei->error) {
|
|
|
|
case JS_E_SYNTAX:
|
|
|
|
case JS_E_MISSING_SEMICOLON:
|
|
|
|
case JS_E_MISSING_LBRACKET:
|
|
|
|
case JS_E_MISSING_RBRACKET:
|
|
|
|
case JS_E_EXPECTED_IDENTIFIER:
|
|
|
|
case JS_E_EXPECTED_ASSIGN:
|
|
|
|
case JS_E_INVALID_CHAR:
|
|
|
|
case JS_E_UNTERMINATED_STRING:
|
|
|
|
case JS_E_MISPLACED_RETURN:
|
|
|
|
case JS_E_INVALID_BREAK:
|
|
|
|
case JS_E_INVALID_CONTINUE:
|
|
|
|
case JS_E_LABEL_REDEFINED:
|
|
|
|
case JS_E_LABEL_NOT_FOUND:
|
|
|
|
case JS_E_EXPECTED_CCEND:
|
|
|
|
case JS_E_DISABLED_CC:
|
|
|
|
case JS_E_EXPECTED_AT:
|
|
|
|
constr = ctx->syntax_error_constr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JS_E_TO_PRIMITIVE:
|
|
|
|
case JS_E_INVALIDARG:
|
|
|
|
case JS_E_OBJECT_REQUIRED:
|
|
|
|
case JS_E_INVALID_PROPERTY:
|
|
|
|
case JS_E_INVALID_ACTION:
|
|
|
|
case JS_E_MISSING_ARG:
|
|
|
|
case JS_E_FUNCTION_EXPECTED:
|
|
|
|
case JS_E_DATE_EXPECTED:
|
|
|
|
case JS_E_NUMBER_EXPECTED:
|
|
|
|
case JS_E_OBJECT_EXPECTED:
|
|
|
|
case JS_E_UNDEFINED_VARIABLE:
|
|
|
|
case JS_E_BOOLEAN_EXPECTED:
|
|
|
|
case JS_E_VBARRAY_EXPECTED:
|
|
|
|
case JS_E_INVALID_DELETE:
|
|
|
|
case JS_E_JSCRIPT_EXPECTED:
|
|
|
|
case JS_E_ENUMERATOR_EXPECTED:
|
|
|
|
case JS_E_ARRAY_EXPECTED:
|
|
|
|
case JS_E_NONCONFIGURABLE_REDEFINED:
|
|
|
|
case JS_E_NONWRITABLE_MODIFIED:
|
|
|
|
case JS_E_PROP_DESC_MISMATCH:
|
|
|
|
case JS_E_INVALID_WRITABLE_PROP_DESC:
|
|
|
|
constr = ctx->type_error_constr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JS_E_SUBSCRIPT_OUT_OF_RANGE:
|
|
|
|
case JS_E_FRACTION_DIGITS_OUT_OF_RANGE:
|
|
|
|
case JS_E_PRECISION_OUT_OF_RANGE:
|
|
|
|
case JS_E_INVALID_LENGTH:
|
|
|
|
constr = ctx->range_error_constr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JS_E_ILLEGAL_ASSIGN:
|
|
|
|
constr = ctx->reference_error_constr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JS_E_REGEXP_SYNTAX:
|
|
|
|
constr = ctx->regexp_error_constr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JS_E_INVALID_URI_CODING:
|
|
|
|
case JS_E_INVALID_URI_CHAR:
|
|
|
|
constr = ctx->uri_error_constr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 14:47:25 +01:00
|
|
|
hres = create_error(ctx, constr, ei->error, ei->message ? ei->message : jsstr_empty(), &r);
|
2020-01-31 17:22:42 +01:00
|
|
|
return SUCCEEDED(hres) ? r : NULL;
|
|
|
|
}
|