2001-09-20 04:02:59 +04:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1998-10-14 14:22:38 +04:00
|
|
|
*
|
2003-11-15 03:11:16 +03:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-10-14 14:22:38 +04:00
|
|
|
*
|
2003-11-15 03:11:16 +03:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-10-14 14:22:38 +04:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
1999-09-29 03:12:09 +04:00
|
|
|
*
|
2003-11-15 03:11:16 +03:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-09-29 03:12:09 +04:00
|
|
|
*
|
2001-09-03 23:36:24 +04:00
|
|
|
* Contributor(s):
|
1999-09-29 03:12:09 +04:00
|
|
|
*
|
2003-11-15 03:11:16 +03:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-10-14 14:22:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* JS standard exception implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jsstddef.h"
|
2002-03-03 03:59:16 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-10-14 14:22:38 +04:00
|
|
|
#include "jstypes.h"
|
2002-03-03 03:59:16 +03:00
|
|
|
#include "jsbit.h"
|
1998-10-14 14:22:38 +04:00
|
|
|
#include "jsutil.h" /* Added by JSIFY */
|
|
|
|
#include "jsprf.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jscntxt.h"
|
|
|
|
#include "jsconfig.h"
|
2004-12-09 05:19:53 +03:00
|
|
|
#include "jsdbgapi.h"
|
1998-10-14 14:22:38 +04:00
|
|
|
#include "jsexn.h"
|
1998-11-05 03:08:43 +03:00
|
|
|
#include "jsfun.h"
|
2002-02-09 09:28:58 +03:00
|
|
|
#include "jsinterp.h"
|
2000-09-09 04:41:15 +04:00
|
|
|
#include "jsnum.h"
|
2004-12-09 05:19:53 +03:00
|
|
|
#include "jsopcode.h"
|
2002-02-09 09:28:58 +03:00
|
|
|
#include "jsscript.h"
|
1998-10-14 14:22:38 +04:00
|
|
|
|
|
|
|
#if JS_HAS_ERROR_EXCEPTIONS
|
|
|
|
#if !JS_HAS_EXCEPTIONS
|
|
|
|
# error "JS_HAS_EXCEPTIONS must be defined to use JS_HAS_ERROR_EXCEPTIONS"
|
|
|
|
#endif
|
|
|
|
|
2000-04-05 10:39:11 +04:00
|
|
|
/* XXX consider adding rt->atomState.messageAtom */
|
2000-09-09 04:41:15 +04:00
|
|
|
static char js_message_str[] = "message";
|
|
|
|
static char js_filename_str[] = "fileName";
|
|
|
|
static char js_lineno_str[] = "lineNumber";
|
2002-02-09 09:28:58 +03:00
|
|
|
static char js_stack_str[] = "stack";
|
2000-04-05 10:39:11 +04:00
|
|
|
|
|
|
|
/* Forward declarations for ExceptionClass's initializer. */
|
1998-11-05 03:08:43 +03:00
|
|
|
static JSBool
|
|
|
|
Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
|
|
|
|
|
|
|
|
static void
|
|
|
|
exn_finalize(JSContext *cx, JSObject *obj);
|
|
|
|
|
2000-04-05 10:39:11 +04:00
|
|
|
static JSClass ExceptionClass = {
|
2001-03-10 03:16:32 +03:00
|
|
|
"Error",
|
1998-11-05 03:08:43 +03:00
|
|
|
JSCLASS_HAS_PRIVATE,
|
|
|
|
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize,
|
1999-11-12 00:52:35 +03:00
|
|
|
NULL, NULL, NULL, Exception,
|
2000-08-26 06:30:22 +04:00
|
|
|
NULL, NULL, NULL, 0
|
1998-11-05 03:08:43 +03:00
|
|
|
};
|
1998-10-14 14:22:38 +04:00
|
|
|
|
|
|
|
/*
|
1998-11-05 03:08:43 +03:00
|
|
|
* A copy of the JSErrorReport originally generated.
|
1998-10-14 14:22:38 +04:00
|
|
|
*/
|
|
|
|
typedef struct JSExnPrivate {
|
|
|
|
JSErrorReport *errorReport;
|
|
|
|
} JSExnPrivate;
|
|
|
|
|
2000-10-14 02:11:52 +04:00
|
|
|
/*
|
|
|
|
* Undo all the damage done by exn_newPrivate.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
exn_destroyPrivate(JSContext *cx, JSExnPrivate *privateData)
|
|
|
|
{
|
|
|
|
JSErrorReport *report;
|
|
|
|
const jschar **args;
|
|
|
|
|
2001-09-03 23:36:24 +04:00
|
|
|
if (!privateData)
|
2000-10-14 02:11:52 +04:00
|
|
|
return;
|
|
|
|
report = privateData->errorReport;
|
|
|
|
if (report) {
|
|
|
|
if (report->uclinebuf)
|
2002-03-14 03:14:48 +03:00
|
|
|
JS_free(cx, (void *)report->uclinebuf);
|
2000-10-14 02:11:52 +04:00
|
|
|
if (report->filename)
|
2002-03-14 03:14:48 +03:00
|
|
|
JS_free(cx, (void *)report->filename);
|
2000-10-14 02:11:52 +04:00
|
|
|
if (report->ucmessage)
|
2002-03-14 03:14:48 +03:00
|
|
|
JS_free(cx, (void *)report->ucmessage);
|
2000-10-14 02:11:52 +04:00
|
|
|
if (report->messageArgs) {
|
|
|
|
args = report->messageArgs;
|
2004-12-12 01:00:34 +03:00
|
|
|
while (*args)
|
2000-10-14 02:11:52 +04:00
|
|
|
JS_free(cx, (void *)*args++);
|
|
|
|
JS_free(cx, (void *)report->messageArgs);
|
|
|
|
}
|
|
|
|
JS_free(cx, report);
|
|
|
|
}
|
|
|
|
JS_free(cx, privateData);
|
|
|
|
}
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
/*
|
|
|
|
* Copy everything interesting about an error into allocated memory.
|
|
|
|
*/
|
|
|
|
static JSExnPrivate *
|
2000-10-14 02:11:52 +04:00
|
|
|
exn_newPrivate(JSContext *cx, JSErrorReport *report)
|
1998-10-14 14:22:38 +04:00
|
|
|
{
|
2000-10-14 02:11:52 +04:00
|
|
|
intN i;
|
1998-10-14 14:22:38 +04:00
|
|
|
JSExnPrivate *newPrivate;
|
1998-11-05 03:08:43 +03:00
|
|
|
JSErrorReport *newReport;
|
2000-10-14 02:11:52 +04:00
|
|
|
size_t capacity;
|
1998-10-14 14:22:38 +04:00
|
|
|
|
|
|
|
newPrivate = (JSExnPrivate *)JS_malloc(cx, sizeof (JSExnPrivate));
|
2000-10-14 02:11:52 +04:00
|
|
|
if (!newPrivate)
|
|
|
|
return NULL;
|
|
|
|
memset(newPrivate, 0, sizeof (JSExnPrivate));
|
1998-10-14 14:22:38 +04:00
|
|
|
|
|
|
|
/* Copy the error report */
|
|
|
|
newReport = (JSErrorReport *)JS_malloc(cx, sizeof (JSErrorReport));
|
2000-10-14 02:11:52 +04:00
|
|
|
if (!newReport)
|
|
|
|
goto error;
|
|
|
|
memset(newReport, 0, sizeof (JSErrorReport));
|
|
|
|
newPrivate->errorReport = newReport;
|
2001-09-03 23:36:24 +04:00
|
|
|
|
2004-12-12 01:00:34 +03:00
|
|
|
if (report->filename) {
|
2000-10-14 02:11:52 +04:00
|
|
|
newReport->filename = JS_strdup(cx, report->filename);
|
|
|
|
if (!newReport->filename)
|
|
|
|
goto error;
|
1998-10-14 14:22:38 +04:00
|
|
|
} else {
|
2000-10-14 02:11:52 +04:00
|
|
|
newReport->filename = NULL;
|
1998-10-14 14:22:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
newReport->lineno = report->lineno;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't need to copy linebuf and tokenptr, because they
|
|
|
|
* point into the deflated string cache. (currently?)
|
|
|
|
*/
|
|
|
|
newReport->linebuf = report->linebuf;
|
|
|
|
newReport->tokenptr = report->tokenptr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* But we do need to copy uclinebuf, uctokenptr, because they're
|
|
|
|
* pointers into internal tokenstream structs, and may go away.
|
|
|
|
*/
|
2004-12-12 01:00:34 +03:00
|
|
|
if (report->uclinebuf) {
|
2002-03-14 03:14:48 +03:00
|
|
|
capacity = js_strlen(report->uclinebuf) + 1;
|
2000-10-14 02:11:52 +04:00
|
|
|
newReport->uclinebuf =
|
|
|
|
(const jschar *)JS_malloc(cx, capacity * sizeof(jschar));
|
|
|
|
if (!newReport->uclinebuf)
|
|
|
|
goto error;
|
2002-03-14 03:14:48 +03:00
|
|
|
js_strncpy((jschar *)newReport->uclinebuf, report->uclinebuf, capacity);
|
|
|
|
newReport->uctokenptr = newReport->uclinebuf + (report->uctokenptr -
|
|
|
|
report->uclinebuf);
|
2000-04-05 10:39:11 +04:00
|
|
|
} else {
|
2002-03-14 03:14:48 +03:00
|
|
|
newReport->uclinebuf = newReport->uctokenptr = NULL;
|
2000-04-05 10:39:11 +04:00
|
|
|
}
|
|
|
|
|
2004-12-12 01:00:34 +03:00
|
|
|
if (report->ucmessage) {
|
2000-10-14 02:11:52 +04:00
|
|
|
capacity = js_strlen(report->ucmessage) + 1;
|
2002-09-18 22:44:47 +04:00
|
|
|
newReport->ucmessage = (const jschar *)
|
|
|
|
JS_malloc(cx, capacity * sizeof(jschar));
|
2000-10-14 02:11:52 +04:00
|
|
|
if (!newReport->ucmessage)
|
|
|
|
goto error;
|
|
|
|
js_strncpy((jschar *)newReport->ucmessage, report->ucmessage, capacity);
|
2000-04-05 10:39:11 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
if (report->messageArgs) {
|
2004-12-12 01:00:34 +03:00
|
|
|
for (i = 0; report->messageArgs[i]; i++)
|
2002-03-14 03:14:48 +03:00
|
|
|
continue;
|
1998-11-05 03:08:43 +03:00
|
|
|
JS_ASSERT(i);
|
|
|
|
newReport->messageArgs =
|
|
|
|
(const jschar **)JS_malloc(cx, (i + 1) * sizeof(jschar *));
|
2000-10-14 02:11:52 +04:00
|
|
|
if (!newReport->messageArgs)
|
|
|
|
goto error;
|
2004-12-12 01:00:34 +03:00
|
|
|
for (i = 0; report->messageArgs[i]; i++) {
|
2000-10-14 02:11:52 +04:00
|
|
|
capacity = js_strlen(report->messageArgs[i]) + 1;
|
1998-11-05 03:08:43 +03:00
|
|
|
newReport->messageArgs[i] =
|
2000-10-14 02:11:52 +04:00
|
|
|
(const jschar *)JS_malloc(cx, capacity * sizeof(jschar));
|
|
|
|
if (!newReport->messageArgs[i])
|
|
|
|
goto error;
|
1998-11-05 03:08:43 +03:00
|
|
|
js_strncpy((jschar *)(newReport->messageArgs[i]),
|
2000-10-14 02:11:52 +04:00
|
|
|
report->messageArgs[i], capacity);
|
1998-11-05 03:08:43 +03:00
|
|
|
}
|
1999-07-16 03:37:05 +04:00
|
|
|
newReport->messageArgs[i] = NULL;
|
1998-11-05 03:08:43 +03:00
|
|
|
} else {
|
1999-07-16 03:37:05 +04:00
|
|
|
newReport->messageArgs = NULL;
|
1998-11-05 03:08:43 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newReport->ucmessage = NULL;
|
|
|
|
newReport->messageArgs = NULL;
|
|
|
|
}
|
1999-04-27 19:18:57 +04:00
|
|
|
newReport->errorNumber = report->errorNumber;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
/* Note that this is before it gets flagged with JSREPORT_EXCEPTION */
|
|
|
|
newReport->flags = report->flags;
|
|
|
|
|
|
|
|
return newPrivate;
|
2000-10-14 02:11:52 +04:00
|
|
|
error:
|
|
|
|
exn_destroyPrivate(cx, newPrivate);
|
|
|
|
return NULL;
|
1998-10-14 14:22:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
exn_finalize(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
JSExnPrivate *privateData;
|
2000-02-02 04:10:31 +03:00
|
|
|
jsval privateValue;
|
1998-10-14 14:22:38 +04:00
|
|
|
|
2000-02-02 04:10:31 +03:00
|
|
|
privateValue = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
1998-10-14 14:22:38 +04:00
|
|
|
|
2002-02-09 09:28:58 +03:00
|
|
|
if (!JSVAL_IS_VOID(privateValue)) {
|
2000-02-02 04:10:31 +03:00
|
|
|
privateData = (JSExnPrivate*) JSVAL_TO_PRIVATE(privateValue);
|
1998-11-05 03:08:43 +03:00
|
|
|
if (privateData)
|
|
|
|
exn_destroyPrivate(cx, privateData);
|
1998-10-14 14:22:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-06 01:07:23 +04:00
|
|
|
JSErrorReport *
|
1998-11-05 03:08:43 +03:00
|
|
|
js_ErrorFromException(JSContext *cx, jsval exn)
|
|
|
|
{
|
|
|
|
JSObject *obj;
|
|
|
|
JSExnPrivate *privateData;
|
2000-02-02 04:10:31 +03:00
|
|
|
jsval privateValue;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
1999-12-23 00:58:53 +03:00
|
|
|
if (JSVAL_IS_PRIMITIVE(exn))
|
1998-11-05 03:08:43 +03:00
|
|
|
return NULL;
|
|
|
|
obj = JSVAL_TO_OBJECT(exn);
|
2000-04-05 10:39:11 +04:00
|
|
|
if (OBJ_GET_CLASS(cx, obj) != &ExceptionClass)
|
1998-11-05 03:08:43 +03:00
|
|
|
return NULL;
|
2000-02-02 04:10:31 +03:00
|
|
|
privateValue = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
2002-02-09 09:28:58 +03:00
|
|
|
if (JSVAL_IS_VOID(privateValue))
|
1999-10-06 01:07:23 +04:00
|
|
|
return NULL;
|
2000-02-02 04:10:31 +03:00
|
|
|
privateData = (JSExnPrivate*) JSVAL_TO_PRIVATE(privateValue);
|
1998-11-05 03:08:43 +03:00
|
|
|
if (!privateData)
|
|
|
|
return NULL;
|
2000-04-05 10:39:11 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
JS_ASSERT(privateData->errorReport);
|
|
|
|
return privateData->errorReport;
|
|
|
|
}
|
|
|
|
|
2000-04-05 10:39:11 +04:00
|
|
|
/*
|
|
|
|
* This must be kept in synch with the exceptions array below.
|
|
|
|
* XXX use a jsexn.tbl file a la jsopcode.tbl
|
|
|
|
*/
|
1998-10-14 14:22:38 +04:00
|
|
|
typedef enum JSExnType {
|
|
|
|
JSEXN_NONE = -1,
|
|
|
|
JSEXN_ERR,
|
2002-03-14 03:14:48 +03:00
|
|
|
JSEXN_INTERNALERR,
|
|
|
|
JSEXN_EVALERR,
|
|
|
|
JSEXN_RANGEERR,
|
|
|
|
JSEXN_REFERENCEERR,
|
|
|
|
JSEXN_SYNTAXERR,
|
|
|
|
JSEXN_TYPEERR,
|
|
|
|
JSEXN_URIERR,
|
|
|
|
JSEXN_LIMIT
|
1998-10-14 14:22:38 +04:00
|
|
|
} JSExnType;
|
|
|
|
|
|
|
|
struct JSExnSpec {
|
|
|
|
int protoIndex;
|
1998-11-05 03:08:43 +03:00
|
|
|
const char *name;
|
2000-04-05 10:39:11 +04:00
|
|
|
JSNative native;
|
1998-10-14 14:22:38 +04:00
|
|
|
};
|
|
|
|
|
2000-04-05 10:39:11 +04:00
|
|
|
/*
|
|
|
|
* All *Error constructors share the same JSClass, ExceptionClass. But each
|
|
|
|
* constructor function for an *Error class must have a distinct native 'call'
|
|
|
|
* function pointer, in order for instanceof to work properly across multiple
|
|
|
|
* standard class sets. See jsfun.c:fun_hasInstance.
|
|
|
|
*/
|
|
|
|
#define MAKE_EXCEPTION_CTOR(name) \
|
2000-08-19 12:37:07 +04:00
|
|
|
const char js_##name##_str[] = #name; \
|
2000-04-05 10:39:11 +04:00
|
|
|
static JSBool \
|
|
|
|
name(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) \
|
|
|
|
{ \
|
|
|
|
return Exception(cx, obj, argc, argv, rval); \
|
|
|
|
}
|
|
|
|
|
|
|
|
MAKE_EXCEPTION_CTOR(Error)
|
|
|
|
MAKE_EXCEPTION_CTOR(InternalError)
|
|
|
|
MAKE_EXCEPTION_CTOR(EvalError)
|
|
|
|
MAKE_EXCEPTION_CTOR(RangeError)
|
|
|
|
MAKE_EXCEPTION_CTOR(ReferenceError)
|
|
|
|
MAKE_EXCEPTION_CTOR(SyntaxError)
|
|
|
|
MAKE_EXCEPTION_CTOR(TypeError)
|
|
|
|
MAKE_EXCEPTION_CTOR(URIError)
|
|
|
|
|
|
|
|
#undef MAKE_EXCEPTION_CTOR
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
static struct JSExnSpec exceptions[] = {
|
2000-08-19 12:37:07 +04:00
|
|
|
{ JSEXN_NONE, js_Error_str, Error },
|
|
|
|
{ JSEXN_ERR, js_InternalError_str, InternalError },
|
|
|
|
{ JSEXN_ERR, js_EvalError_str, EvalError },
|
|
|
|
{ JSEXN_ERR, js_RangeError_str, RangeError },
|
|
|
|
{ JSEXN_ERR, js_ReferenceError_str, ReferenceError },
|
|
|
|
{ JSEXN_ERR, js_SyntaxError_str, SyntaxError },
|
|
|
|
{ JSEXN_ERR, js_TypeError_str, TypeError },
|
|
|
|
{ JSEXN_ERR, js_URIError_str, URIError },
|
2002-09-18 22:44:47 +04:00
|
|
|
{0,NULL,NULL}
|
1998-10-14 14:22:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static JSBool
|
2002-03-03 03:59:16 +03:00
|
|
|
InitExceptionObject(JSContext *cx, JSObject *obj, JSString *message,
|
|
|
|
JSString *filename, uintN lineno)
|
1998-10-14 14:22:38 +04:00
|
|
|
{
|
2002-02-09 09:28:58 +03:00
|
|
|
JSCheckAccessOp checkAccess;
|
|
|
|
JSErrorReporter older;
|
|
|
|
JSExceptionState *state;
|
2002-03-03 03:59:16 +03:00
|
|
|
jschar *stackbuf;
|
|
|
|
size_t stacklen, stackmax;
|
|
|
|
JSStackFrame *fp;
|
2002-02-09 09:28:58 +03:00
|
|
|
jsval callerid, v;
|
2002-03-03 03:59:16 +03:00
|
|
|
JSBool ok;
|
|
|
|
JSString *argsrc, *stack;
|
|
|
|
uintN i, ulineno;
|
|
|
|
const char *cp;
|
|
|
|
char ulnbuf[11];
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
if (!JS_DefineProperty(cx, obj, js_message_str, STRING_TO_JSVAL(message),
|
|
|
|
NULL, NULL, JSPROP_ENUMERATE)) {
|
2000-09-09 04:41:15 +04:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
|
|
|
|
if (!JS_DefineProperty(cx, obj, js_filename_str,
|
2000-09-09 04:41:15 +04:00
|
|
|
STRING_TO_JSVAL(filename),
|
2002-03-03 03:59:16 +03:00
|
|
|
NULL, NULL, JSPROP_ENUMERATE)) {
|
2000-09-09 04:41:15 +04:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
|
|
|
|
if (!JS_DefineProperty(cx, obj, js_lineno_str,
|
2002-02-09 09:28:58 +03:00
|
|
|
INT_TO_JSVAL(lineno),
|
2002-03-03 03:59:16 +03:00
|
|
|
NULL, NULL, JSPROP_ENUMERATE)) {
|
2002-02-09 09:28:58 +03:00
|
|
|
return JS_FALSE;
|
2002-03-03 03:59:16 +03:00
|
|
|
}
|
2001-09-03 23:36:24 +04:00
|
|
|
|
2002-02-09 09:28:58 +03:00
|
|
|
/*
|
2002-03-03 03:59:16 +03:00
|
|
|
* Set the 'stack' property.
|
|
|
|
*
|
|
|
|
* First, set aside any error reporter for cx and save its exception state
|
|
|
|
* so we can suppress any checkAccess failures. Such failures should stop
|
|
|
|
* the backtrace procedure, not result in a failure of this constructor.
|
2002-02-09 09:28:58 +03:00
|
|
|
*/
|
|
|
|
checkAccess = cx->runtime->checkObjectAccess;
|
|
|
|
if (checkAccess) {
|
|
|
|
older = JS_SetErrorReporter(cx, NULL);
|
|
|
|
state = JS_SaveExceptionState(cx);
|
|
|
|
}
|
2002-02-14 10:25:34 +03:00
|
|
|
#ifdef __GNUC__ /* suppress bogus gcc warnings */
|
|
|
|
else {
|
|
|
|
older = NULL;
|
|
|
|
state = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2002-02-09 09:28:58 +03:00
|
|
|
callerid = ATOM_KEY(cx->runtime->atomState.callerAtom);
|
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
/*
|
|
|
|
* Prepare to allocate a jschar buffer at stackbuf, where stacklen indexes
|
|
|
|
* the next free jschar slot, and with room for at most stackmax non-null
|
|
|
|
* jschars. If stackbuf is non-null, it always contains an extra slot for
|
|
|
|
* the null terminator we'll store at the end, as a backstop.
|
|
|
|
*
|
|
|
|
* All early returns must goto done after this point, till the after-loop
|
|
|
|
* cleanup code has run!
|
|
|
|
*/
|
|
|
|
stackbuf = NULL;
|
|
|
|
stacklen = stackmax = 0;
|
|
|
|
ok = JS_TRUE;
|
|
|
|
|
|
|
|
#define APPEND_CHAR_TO_STACK(c) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
if (stacklen == stackmax) { \
|
|
|
|
void *ptr_; \
|
|
|
|
stackmax = stackmax ? 2 * stackmax : 64; \
|
|
|
|
ptr_ = JS_realloc(cx, stackbuf, (stackmax+1) * sizeof(jschar)); \
|
|
|
|
if (!ptr_) { \
|
|
|
|
ok = JS_FALSE; \
|
|
|
|
goto done; \
|
|
|
|
} \
|
|
|
|
stackbuf = ptr_; \
|
|
|
|
} \
|
|
|
|
stackbuf[stacklen++] = (c); \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
#define APPEND_STRING_TO_STACK(str) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
JSString *str_ = str; \
|
|
|
|
size_t length_ = JSSTRING_LENGTH(str_); \
|
|
|
|
if (stacklen + length_ > stackmax) { \
|
|
|
|
void *ptr_; \
|
|
|
|
stackmax = JS_BIT(JS_CeilingLog2(stacklen + length_)); \
|
|
|
|
ptr_ = JS_realloc(cx, stackbuf, (stackmax+1) * sizeof(jschar)); \
|
|
|
|
if (!ptr_) { \
|
|
|
|
ok = JS_FALSE; \
|
|
|
|
goto done; \
|
|
|
|
} \
|
|
|
|
stackbuf = ptr_; \
|
|
|
|
} \
|
|
|
|
js_strncpy(stackbuf + stacklen, JSSTRING_CHARS(str_), length_); \
|
|
|
|
stacklen += length_; \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
for (fp = cx->fp; fp; fp = fp->down) {
|
2002-02-09 09:28:58 +03:00
|
|
|
if (checkAccess) {
|
|
|
|
v = (fp->fun && fp->argv) ? fp->argv[-2] : JSVAL_NULL;
|
|
|
|
if (!JSVAL_IS_PRIMITIVE(v)) {
|
|
|
|
ok = checkAccess(cx, fp->fun->object, callerid, JSACC_READ, &v);
|
|
|
|
if (!ok) {
|
|
|
|
ok = JS_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
if (fp->fun) {
|
|
|
|
if (fp->fun->atom)
|
|
|
|
APPEND_STRING_TO_STACK(ATOM_TO_STRING(fp->fun->atom));
|
|
|
|
|
|
|
|
APPEND_CHAR_TO_STACK('(');
|
|
|
|
for (i = 0; i < fp->argc; i++) {
|
2002-09-06 02:25:48 +04:00
|
|
|
/* Avoid toSource bloat and fallibility for object types. */
|
2002-05-07 12:34:51 +04:00
|
|
|
v = fp->argv[i];
|
2002-09-06 02:25:48 +04:00
|
|
|
if (JSVAL_IS_PRIMITIVE(v)) {
|
|
|
|
argsrc = js_ValueToSource(cx, v);
|
|
|
|
} else if (JSVAL_IS_FUNCTION(cx, v)) {
|
|
|
|
/* XXX Avoid function decompilation bloat for now. */
|
2002-05-07 12:34:51 +04:00
|
|
|
argsrc = JS_GetFunctionId(JS_ValueToFunction(cx, v));
|
|
|
|
if (!argsrc)
|
|
|
|
argsrc = js_ValueToSource(cx, v);
|
|
|
|
} else {
|
2002-09-06 02:25:48 +04:00
|
|
|
/* XXX Avoid toString on objects, it takes too long and
|
|
|
|
uses too much memory, for too many classes (see
|
|
|
|
Mozilla bug 166743). */
|
|
|
|
char buf[100];
|
|
|
|
JS_snprintf(buf, sizeof buf, "[object %s]",
|
|
|
|
OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v))->name);
|
|
|
|
argsrc = JS_NewStringCopyZ(cx, buf);
|
2002-05-07 12:34:51 +04:00
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
if (!argsrc) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (i > 0)
|
|
|
|
APPEND_CHAR_TO_STACK(',');
|
|
|
|
APPEND_STRING_TO_STACK(argsrc);
|
2002-02-09 09:28:58 +03:00
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
APPEND_CHAR_TO_STACK(')');
|
2002-02-09 09:28:58 +03:00
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
|
|
|
|
APPEND_CHAR_TO_STACK('@');
|
|
|
|
if (fp->script && fp->script->filename) {
|
|
|
|
for (cp = fp->script->filename; *cp; cp++)
|
|
|
|
APPEND_CHAR_TO_STACK(*cp);
|
|
|
|
}
|
|
|
|
APPEND_CHAR_TO_STACK(':');
|
|
|
|
if (fp->script && fp->pc) {
|
2003-07-27 02:37:11 +04:00
|
|
|
ulineno = js_PCToLineNumber(cx, fp->script, fp->pc);
|
2002-03-03 03:59:16 +03:00
|
|
|
JS_snprintf(ulnbuf, sizeof ulnbuf, "%u", ulineno);
|
|
|
|
for (cp = ulnbuf; *cp; cp++)
|
|
|
|
APPEND_CHAR_TO_STACK(*cp);
|
|
|
|
} else {
|
|
|
|
APPEND_CHAR_TO_STACK('0');
|
2002-02-09 09:28:58 +03:00
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
APPEND_CHAR_TO_STACK('\n');
|
2002-02-09 09:28:58 +03:00
|
|
|
}
|
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
#undef APPEND_CHAR_TO_STACK
|
|
|
|
#undef APPEND_STRING_TO_STACK
|
|
|
|
|
2002-02-09 09:28:58 +03:00
|
|
|
done:
|
|
|
|
if (checkAccess) {
|
|
|
|
if (ok)
|
|
|
|
JS_RestoreExceptionState(cx, state);
|
|
|
|
else
|
|
|
|
JS_DropExceptionState(cx, state);
|
|
|
|
JS_SetErrorReporter(cx, older);
|
|
|
|
}
|
|
|
|
if (!ok) {
|
2002-03-03 03:59:16 +03:00
|
|
|
JS_free(cx, stackbuf);
|
2002-02-09 09:28:58 +03:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
if (!stackbuf) {
|
2002-02-09 09:28:58 +03:00
|
|
|
stack = cx->runtime->emptyString;
|
|
|
|
} else {
|
2002-03-03 03:59:16 +03:00
|
|
|
/* NB: if stackbuf was allocated, it has room for the terminator. */
|
|
|
|
JS_ASSERT(stacklen <= stackmax);
|
|
|
|
if (stacklen < stackmax) {
|
|
|
|
/*
|
|
|
|
* Realloc can fail when shrinking on some FreeBSD versions, so
|
|
|
|
* don't use JS_realloc here; simply let the oversized allocation
|
|
|
|
* be owned by the string in that rare case.
|
|
|
|
*/
|
|
|
|
void *shrunk = realloc(stackbuf, (stacklen+1) * sizeof(jschar));
|
|
|
|
if (shrunk)
|
|
|
|
stackbuf = shrunk;
|
|
|
|
}
|
|
|
|
stackbuf[stacklen] = 0;
|
|
|
|
stack = js_NewString(cx, stackbuf, stacklen, 0);
|
2002-02-09 09:28:58 +03:00
|
|
|
if (!stack) {
|
2002-03-03 03:59:16 +03:00
|
|
|
JS_free(cx, stackbuf);
|
2002-02-09 09:28:58 +03:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
return JS_DefineProperty(cx, obj, js_stack_str,
|
|
|
|
STRING_TO_JSVAL(stack),
|
|
|
|
NULL, NULL, JSPROP_ENUMERATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
JSBool ok;
|
|
|
|
jsval pval;
|
|
|
|
int32 lineno;
|
|
|
|
JSString *message, *filename;
|
2004-12-09 05:19:53 +03:00
|
|
|
JSStackFrame *fp;
|
2002-03-03 03:59:16 +03:00
|
|
|
|
|
|
|
if (cx->creatingException)
|
|
|
|
return JS_FALSE;
|
|
|
|
cx->creatingException = JS_TRUE;
|
|
|
|
|
|
|
|
if (!(cx->fp->flags & JSFRAME_CONSTRUCTING)) {
|
|
|
|
/*
|
|
|
|
* ECMA ed. 3, 15.11.1 requires Error, etc., to construct even when
|
|
|
|
* called as functions, without operator new. But as we do not give
|
|
|
|
* each constructor a distinct JSClass, whose .name member is used by
|
|
|
|
* js_NewObject to find the class prototype, we must get the class
|
|
|
|
* prototype ourselves.
|
|
|
|
*/
|
|
|
|
ok = OBJ_GET_PROPERTY(cx, JSVAL_TO_OBJECT(argv[-2]),
|
2004-10-05 14:19:07 +04:00
|
|
|
ATOM_TO_JSID(cx->runtime->atomState
|
|
|
|
.classPrototypeAtom),
|
2002-03-03 03:59:16 +03:00
|
|
|
&pval);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
|
|
|
obj = js_NewObject(cx, &ExceptionClass, JSVAL_TO_OBJECT(pval), NULL);
|
|
|
|
if (!obj) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*rval = OBJECT_TO_JSVAL(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it's a new object of class Exception, then null out the private
|
|
|
|
* data so that the finalizer doesn't attempt to free it.
|
|
|
|
*/
|
|
|
|
if (OBJ_GET_CLASS(cx, obj) == &ExceptionClass)
|
|
|
|
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, JSVAL_VOID);
|
|
|
|
|
|
|
|
/* Set the 'message' property. */
|
|
|
|
if (argc != 0) {
|
|
|
|
message = js_ValueToString(cx, argv[0]);
|
|
|
|
if (!message) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2004-09-21 05:18:00 +04:00
|
|
|
argv[0] = STRING_TO_JSVAL(message);
|
2002-03-03 03:59:16 +03:00
|
|
|
} else {
|
|
|
|
message = cx->runtime->emptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the 'fileName' property. */
|
|
|
|
if (argc > 1) {
|
|
|
|
filename = js_ValueToString(cx, argv[1]);
|
|
|
|
if (!filename) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2004-09-21 05:18:00 +04:00
|
|
|
argv[1] = STRING_TO_JSVAL(filename);
|
2004-12-09 05:19:53 +03:00
|
|
|
fp = NULL;
|
2002-03-03 03:59:16 +03:00
|
|
|
} else {
|
2004-12-09 05:19:53 +03:00
|
|
|
fp = JS_GetScriptedCaller(cx, NULL);
|
|
|
|
if (fp) {
|
|
|
|
filename = JS_NewStringCopyZ(cx, fp->script->filename);
|
|
|
|
if (!filename) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
filename = cx->runtime->emptyString;
|
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the 'lineNumber' property. */
|
|
|
|
if (argc > 2) {
|
|
|
|
ok = js_ValueToInt32(cx, argv[2], &lineno);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
|
|
|
} else {
|
2004-12-09 05:19:53 +03:00
|
|
|
if (!fp)
|
|
|
|
fp = JS_GetScriptedCaller(cx, NULL);
|
|
|
|
lineno = (fp && fp->pc) ? js_PCToLineNumber(cx, fp->script, fp->pc) : 0;
|
2002-03-03 03:59:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ok = InitExceptionObject(cx, obj, message, filename, lineno);
|
|
|
|
|
|
|
|
out:
|
|
|
|
cx->creatingException = JS_FALSE;
|
2002-02-09 09:28:58 +03:00
|
|
|
return ok;
|
1999-09-21 22:58:51 +04:00
|
|
|
}
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
/*
|
1998-11-05 03:08:43 +03:00
|
|
|
* Convert to string.
|
1998-10-14 14:22:38 +04:00
|
|
|
*
|
2000-04-05 10:39:11 +04:00
|
|
|
* This method only uses JavaScript-modifiable properties name, message. It
|
|
|
|
* is left to the host to check for private data and report filename and line
|
1998-11-05 03:08:43 +03:00
|
|
|
* number information along with this message.
|
1998-10-14 14:22:38 +04:00
|
|
|
*/
|
|
|
|
static JSBool
|
|
|
|
exn_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
jsval v;
|
1998-11-05 03:08:43 +03:00
|
|
|
JSString *name, *message, *result;
|
|
|
|
jschar *chars, *cp;
|
2001-10-25 04:26:38 +04:00
|
|
|
size_t name_length, message_length, length;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2004-10-05 14:19:07 +04:00
|
|
|
if (!OBJ_GET_PROPERTY(cx, obj,
|
|
|
|
ATOM_TO_JSID(cx->runtime->atomState.nameAtom),
|
|
|
|
&v)) {
|
2000-04-05 10:39:11 +04:00
|
|
|
return JS_FALSE;
|
2004-10-05 14:19:07 +04:00
|
|
|
}
|
2004-09-21 05:18:00 +04:00
|
|
|
name = JSVAL_IS_STRING(v) ? JSVAL_TO_STRING(v) : cx->runtime->emptyString;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2004-09-21 05:18:00 +04:00
|
|
|
if (!JS_GetProperty(cx, obj, js_message_str, &v))
|
1998-11-05 03:08:43 +03:00
|
|
|
return JS_FALSE;
|
2004-09-21 05:18:00 +04:00
|
|
|
message = JSVAL_IS_STRING(v) ? JSVAL_TO_STRING(v)
|
|
|
|
: cx->runtime->emptyString;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2001-10-25 04:26:38 +04:00
|
|
|
if (JSSTRING_LENGTH(message) != 0) {
|
|
|
|
name_length = JSSTRING_LENGTH(name);
|
|
|
|
message_length = JSSTRING_LENGTH(message);
|
2004-09-21 05:18:00 +04:00
|
|
|
length = (name_length ? name_length + 2 : 0) + message_length;
|
2000-02-02 04:10:31 +03:00
|
|
|
cp = chars = (jschar*) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
1998-11-05 03:08:43 +03:00
|
|
|
if (!chars)
|
|
|
|
return JS_FALSE;
|
2000-04-05 10:39:11 +04:00
|
|
|
|
2004-09-21 05:18:00 +04:00
|
|
|
if (name_length) {
|
|
|
|
js_strncpy(cp, JSSTRING_CHARS(name), name_length);
|
|
|
|
cp += name_length;
|
|
|
|
*cp++ = ':'; *cp++ = ' ';
|
|
|
|
}
|
2001-10-25 04:26:38 +04:00
|
|
|
js_strncpy(cp, JSSTRING_CHARS(message), message_length);
|
|
|
|
cp += message_length;
|
1998-11-05 03:08:43 +03:00
|
|
|
*cp = 0;
|
2000-04-05 10:39:11 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
result = js_NewString(cx, chars, length, 0);
|
|
|
|
if (!result) {
|
|
|
|
JS_free(cx, chars);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
1998-10-14 14:22:38 +04:00
|
|
|
} else {
|
1998-11-05 03:08:43 +03:00
|
|
|
result = name;
|
1998-10-14 14:22:38 +04:00
|
|
|
}
|
1998-11-05 03:08:43 +03:00
|
|
|
|
|
|
|
*rval = STRING_TO_JSVAL(result);
|
1998-10-14 14:22:38 +04:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
#if JS_HAS_TOSOURCE
|
|
|
|
/*
|
|
|
|
* Return a string that may eval to something similar to the original object.
|
|
|
|
*/
|
|
|
|
static JSBool
|
|
|
|
exn_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
2000-04-05 10:39:11 +04:00
|
|
|
jsval v;
|
2000-09-09 04:41:15 +04:00
|
|
|
JSString *name, *message, *filename, *lineno_as_str, *result;
|
2001-10-25 04:26:38 +04:00
|
|
|
int32 lineno;
|
|
|
|
size_t lineno_length, name_length, message_length, filename_length, length;
|
1998-11-05 03:08:43 +03:00
|
|
|
jschar *chars, *cp;
|
|
|
|
|
2004-10-05 14:19:07 +04:00
|
|
|
if (!OBJ_GET_PROPERTY(cx, obj,
|
|
|
|
ATOM_TO_JSID(cx->runtime->atomState.nameAtom),
|
|
|
|
&v)) {
|
2000-04-05 10:39:11 +04:00
|
|
|
return JS_FALSE;
|
2004-10-05 14:19:07 +04:00
|
|
|
}
|
2000-04-05 10:39:11 +04:00
|
|
|
name = js_ValueToString(cx, v);
|
|
|
|
if (!name)
|
1998-11-05 03:08:43 +03:00
|
|
|
return JS_FALSE;
|
|
|
|
|
2000-04-05 10:39:11 +04:00
|
|
|
if (!JS_GetProperty(cx, obj, js_message_str, &v) ||
|
2001-09-03 23:36:24 +04:00
|
|
|
!(message = js_ValueToSource(cx, v))) {
|
1998-11-05 03:08:43 +03:00
|
|
|
return JS_FALSE;
|
2000-04-05 10:39:11 +04:00
|
|
|
}
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2000-09-09 04:41:15 +04:00
|
|
|
if (!JS_GetProperty(cx, obj, js_filename_str, &v) ||
|
2001-09-03 23:36:24 +04:00
|
|
|
!(filename = js_ValueToSource(cx, v))) {
|
2000-09-09 04:41:15 +04:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_GetProperty(cx, obj, js_lineno_str, &v) ||
|
|
|
|
!js_ValueToInt32 (cx, v, &lineno)) {
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lineno != 0) {
|
|
|
|
if (!(lineno_as_str = js_ValueToString(cx, v))) {
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
2001-10-25 04:26:38 +04:00
|
|
|
lineno_length = JSSTRING_LENGTH(lineno_as_str);
|
2000-09-09 04:41:15 +04:00
|
|
|
} else {
|
|
|
|
lineno_as_str = NULL;
|
2001-10-25 04:26:38 +04:00
|
|
|
lineno_length = 0;
|
2001-09-03 23:36:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Magic 8, for the characters in ``(new ())''. */
|
2001-10-25 04:26:38 +04:00
|
|
|
name_length = JSSTRING_LENGTH(name);
|
|
|
|
message_length = JSSTRING_LENGTH(message);
|
|
|
|
length = 8 + name_length + message_length;
|
2001-09-03 23:36:24 +04:00
|
|
|
|
2001-10-25 04:26:38 +04:00
|
|
|
filename_length = JSSTRING_LENGTH(filename);
|
|
|
|
if (filename_length != 0) {
|
2001-09-03 23:36:24 +04:00
|
|
|
/* append filename as ``, {filename}'' */
|
2001-10-25 04:26:38 +04:00
|
|
|
length += 2 + filename_length;
|
2000-09-09 04:41:15 +04:00
|
|
|
if (lineno_as_str) {
|
|
|
|
/* append lineno as ``, {lineno_as_str}'' */
|
2001-10-25 04:26:38 +04:00
|
|
|
length += 2 + lineno_length;
|
2000-09-09 04:41:15 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (lineno_as_str) {
|
|
|
|
/*
|
|
|
|
* no filename, but have line number,
|
|
|
|
* need to append ``, "", {lineno_as_str}''
|
|
|
|
*/
|
2001-10-25 04:26:38 +04:00
|
|
|
length += 6 + lineno_length;
|
2000-09-09 04:41:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-02 04:10:31 +03:00
|
|
|
cp = chars = (jschar*) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
1998-11-05 03:08:43 +03:00
|
|
|
if (!chars)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
*cp++ = '('; *cp++ = 'n'; *cp++ = 'e'; *cp++ = 'w'; *cp++ = ' ';
|
2001-10-25 04:26:38 +04:00
|
|
|
js_strncpy(cp, JSSTRING_CHARS(name), name_length);
|
|
|
|
cp += name_length;
|
1998-11-05 03:08:43 +03:00
|
|
|
*cp++ = '(';
|
2001-10-25 04:26:38 +04:00
|
|
|
if (message_length != 0) {
|
|
|
|
js_strncpy(cp, JSSTRING_CHARS(message), message_length);
|
|
|
|
cp += message_length;
|
1998-11-05 03:08:43 +03:00
|
|
|
}
|
2000-09-09 04:41:15 +04:00
|
|
|
|
2001-10-25 04:26:38 +04:00
|
|
|
if (filename_length != 0) {
|
2001-09-03 23:36:24 +04:00
|
|
|
/* append filename as ``, {filename}'' */
|
|
|
|
*cp++ = ','; *cp++ = ' ';
|
2001-10-25 04:26:38 +04:00
|
|
|
js_strncpy(cp, JSSTRING_CHARS(filename), filename_length);
|
|
|
|
cp += filename_length;
|
2000-09-09 04:41:15 +04:00
|
|
|
} else {
|
|
|
|
if (lineno_as_str) {
|
|
|
|
/*
|
|
|
|
* no filename, but have line number,
|
|
|
|
* need to append ``, "", {lineno_as_str}''
|
|
|
|
*/
|
|
|
|
*cp++ = ','; *cp++ = ' '; *cp++ = '"'; *cp++ = '"';
|
|
|
|
}
|
|
|
|
}
|
2001-10-25 04:26:38 +04:00
|
|
|
if (lineno_as_str) {
|
|
|
|
/* append lineno as ``, {lineno_as_str}'' */
|
|
|
|
*cp++ = ','; *cp++ = ' ';
|
|
|
|
js_strncpy(cp, JSSTRING_CHARS(lineno_as_str), lineno_length);
|
|
|
|
cp += lineno_length;
|
|
|
|
}
|
2000-09-09 04:41:15 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
*cp++ = ')'; *cp++ = ')'; *cp = 0;
|
|
|
|
|
|
|
|
result = js_NewString(cx, chars, length, 0);
|
|
|
|
if (!result) {
|
|
|
|
JS_free(cx, chars);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
*rval = STRING_TO_JSVAL(result);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
static JSFunctionSpec exception_methods[] = {
|
1998-11-05 03:08:43 +03:00
|
|
|
#if JS_HAS_TOSOURCE
|
1999-11-12 00:52:35 +03:00
|
|
|
{js_toSource_str, exn_toSource, 0,0,0},
|
1998-11-05 03:08:43 +03:00
|
|
|
#endif
|
1999-11-12 00:52:35 +03:00
|
|
|
{js_toString_str, exn_toString, 0,0,0},
|
|
|
|
{0,0,0,0,0}
|
1998-10-14 14:22:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
JSObject *
|
|
|
|
js_InitExceptionClasses(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
int i;
|
1998-11-05 03:08:43 +03:00
|
|
|
JSObject *protos[JSEXN_LIMIT];
|
1998-10-14 14:22:38 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
/* Initialize the prototypes first. */
|
|
|
|
for (i = 0; exceptions[i].name != 0; i++) {
|
|
|
|
JSAtom *atom;
|
|
|
|
JSFunction *fun;
|
|
|
|
JSString *nameString;
|
2000-04-05 10:39:11 +04:00
|
|
|
int protoIndex = exceptions[i].protoIndex;
|
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
/* Make the prototype for the current constructor name. */
|
2000-04-05 10:39:11 +04:00
|
|
|
protos[i] = js_NewObject(cx, &ExceptionClass,
|
|
|
|
(protoIndex != JSEXN_NONE)
|
|
|
|
? protos[protoIndex]
|
|
|
|
: NULL,
|
1998-11-05 03:08:43 +03:00
|
|
|
obj);
|
|
|
|
if (!protos[i])
|
|
|
|
return NULL;
|
|
|
|
|
2000-04-05 10:39:11 +04:00
|
|
|
/* So exn_finalize knows whether to destroy private data. */
|
2002-02-09 09:28:58 +03:00
|
|
|
OBJ_SET_SLOT(cx, protos[i], JSSLOT_PRIVATE, JSVAL_VOID);
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2000-04-05 10:39:11 +04:00
|
|
|
atom = js_Atomize(cx, exceptions[i].name, strlen(exceptions[i].name), 0);
|
|
|
|
if (!atom)
|
1999-09-21 22:58:51 +04:00
|
|
|
return NULL;
|
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
/* Make a constructor function for the current name. */
|
2002-02-09 09:28:58 +03:00
|
|
|
fun = js_DefineFunction(cx, obj, atom, exceptions[i].native, 3, 0);
|
1998-11-05 03:08:43 +03:00
|
|
|
if (!fun)
|
2000-04-05 10:39:11 +04:00
|
|
|
return NULL;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
|
|
|
/* Make this constructor make objects of class Exception. */
|
2000-04-05 10:39:11 +04:00
|
|
|
fun->clasp = &ExceptionClass;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
|
|
|
/* Make the prototype and constructor links. */
|
2000-04-05 10:39:11 +04:00
|
|
|
if (!js_SetClassPrototype(cx, fun->object, protos[i],
|
|
|
|
JSPROP_READONLY | JSPROP_PERMANENT)) {
|
1998-11-05 03:08:43 +03:00
|
|
|
return NULL;
|
2000-04-05 10:39:11 +04:00
|
|
|
}
|
1998-11-05 03:08:43 +03:00
|
|
|
|
|
|
|
/* proto bootstrap bit from JS_InitClass omitted. */
|
|
|
|
nameString = JS_NewStringCopyZ(cx, exceptions[i].name);
|
2000-12-30 01:19:09 +03:00
|
|
|
if (!nameString)
|
1998-11-05 03:08:43 +03:00
|
|
|
return NULL;
|
2000-04-05 10:39:11 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
/* Add the name property to the prototype. */
|
|
|
|
if (!JS_DefineProperty(cx, protos[i], js_name_str,
|
|
|
|
STRING_TO_JSVAL(nameString),
|
|
|
|
NULL, NULL,
|
|
|
|
JSPROP_ENUMERATE)) {
|
|
|
|
return NULL;
|
2000-04-05 10:39:11 +04:00
|
|
|
}
|
1998-10-14 14:22:38 +04:00
|
|
|
}
|
2000-04-05 10:39:11 +04:00
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
/*
|
1998-11-05 03:08:43 +03:00
|
|
|
* Add an empty message property. (To Exception.prototype only,
|
|
|
|
* because this property will be the same for all the exception
|
|
|
|
* protos.)
|
1998-10-14 14:22:38 +04:00
|
|
|
*/
|
2000-04-05 10:39:11 +04:00
|
|
|
if (!JS_DefineProperty(cx, protos[0], js_message_str,
|
1998-11-05 03:08:43 +03:00
|
|
|
STRING_TO_JSVAL(cx->runtime->emptyString),
|
2000-04-05 10:39:11 +04:00
|
|
|
NULL, NULL, JSPROP_ENUMERATE)) {
|
1998-11-05 03:08:43 +03:00
|
|
|
return NULL;
|
2000-04-05 10:39:11 +04:00
|
|
|
}
|
2000-09-09 04:41:15 +04:00
|
|
|
if (!JS_DefineProperty(cx, protos[0], js_filename_str,
|
|
|
|
STRING_TO_JSVAL(cx->runtime->emptyString),
|
|
|
|
NULL, NULL, JSPROP_ENUMERATE)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!JS_DefineProperty(cx, protos[0], js_lineno_str,
|
|
|
|
INT_TO_JSVAL(0),
|
|
|
|
NULL, NULL, JSPROP_ENUMERATE)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-04-05 10:39:11 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
/*
|
|
|
|
* Add methods only to Exception.prototype, because ostensibly all
|
|
|
|
* exception types delegate to that.
|
|
|
|
*/
|
|
|
|
if (!JS_DefineFunctions(cx, protos[0], exception_methods))
|
|
|
|
return NULL;
|
1998-10-14 14:22:38 +04:00
|
|
|
|
|
|
|
return protos[0];
|
|
|
|
}
|
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
static JSExnType errorToExceptionNum[] = {
|
1998-10-14 14:22:38 +04:00
|
|
|
#define MSG_DEF(name, number, count, exception, format) \
|
|
|
|
exception,
|
|
|
|
#include "js.msg"
|
|
|
|
#undef MSG_DEF
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined ( DEBUG_mccabe ) && defined ( PRINTNAMES )
|
|
|
|
/* For use below... get character strings for error name and exception name */
|
|
|
|
static struct exnname { char *name; char *exception; } errortoexnname[] = {
|
|
|
|
#define MSG_DEF(name, number, count, exception, format) \
|
|
|
|
{#name, #exception},
|
|
|
|
#include "js.msg"
|
|
|
|
#undef MSG_DEF
|
|
|
|
};
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
JSBool
|
1998-11-05 03:08:43 +03:00
|
|
|
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp)
|
1998-10-14 14:22:38 +04:00
|
|
|
{
|
|
|
|
JSErrNum errorNumber;
|
|
|
|
JSExnType exn;
|
2002-03-03 03:59:16 +03:00
|
|
|
JSBool ok;
|
|
|
|
JSObject *errProto, *errObject;
|
|
|
|
JSString *messageStr, *filenameStr;
|
|
|
|
uintN lineno;
|
1998-10-14 14:22:38 +04:00
|
|
|
JSExnPrivate *privateData;
|
|
|
|
|
2002-09-06 02:25:48 +04:00
|
|
|
/*
|
|
|
|
* Tell our caller to report immediately if cx has no active frames, or if
|
|
|
|
* this report is just a warning.
|
|
|
|
*/
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_ASSERT(reportp);
|
2002-09-06 02:25:48 +04:00
|
|
|
if (!cx->fp || JSREPORT_IS_WARNING(reportp->flags))
|
2000-01-18 14:06:05 +03:00
|
|
|
return JS_FALSE;
|
2002-09-06 02:25:48 +04:00
|
|
|
|
|
|
|
/* Find the exception index associated with this error. */
|
2000-02-02 04:10:31 +03:00
|
|
|
errorNumber = (JSErrNum) reportp->errorNumber;
|
1998-11-05 03:08:43 +03:00
|
|
|
exn = errorToExceptionNum[errorNumber];
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_ASSERT(exn < JSEXN_LIMIT);
|
|
|
|
|
|
|
|
#if defined( DEBUG_mccabe ) && defined ( PRINTNAMES )
|
|
|
|
/* Print the error name and the associated exception name to stderr */
|
|
|
|
fprintf(stderr, "%s\t%s\n",
|
2002-03-14 03:14:48 +03:00
|
|
|
errortoexnname[errorNumber].name,
|
|
|
|
errortoexnname[errorNumber].exception);
|
1998-10-14 14:22:38 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return false (no exception raised) if no exception is associated
|
|
|
|
* with the given error number.
|
|
|
|
*/
|
|
|
|
if (exn == JSEXN_NONE)
|
2002-03-14 03:14:48 +03:00
|
|
|
return JS_FALSE;
|
1998-10-14 14:22:38 +04:00
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
/*
|
|
|
|
* Prevent runaway recursion, just as the Exception native constructor
|
|
|
|
* must do, via cx->creatingException. If an out-of-memory error occurs,
|
|
|
|
* no exception object will be created, but we don't assume that OOM is
|
|
|
|
* the only kind of error that subroutines of this function called below
|
|
|
|
* might raise.
|
|
|
|
*/
|
|
|
|
if (cx->creatingException)
|
|
|
|
return JS_FALSE;
|
|
|
|
cx->creatingException = JS_TRUE;
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
/*
|
1998-11-05 03:08:43 +03:00
|
|
|
* Try to get an appropriate prototype by looking up the corresponding
|
2001-08-22 08:59:28 +04:00
|
|
|
* exception constructor name in the scope chain of the current context's
|
|
|
|
* top stack frame, or in the global object if no frame is active.
|
1998-10-14 14:22:38 +04:00
|
|
|
*/
|
2004-11-17 10:43:01 +03:00
|
|
|
ok = js_GetClassPrototype(cx, exceptions[exn].name, &errProto);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
2002-03-03 03:59:16 +03:00
|
|
|
|
|
|
|
errObject = js_NewObject(cx, &ExceptionClass, errProto, NULL);
|
|
|
|
if (!errObject) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2002-05-07 12:34:51 +04:00
|
|
|
/*
|
|
|
|
* Set the generated Exception object early, so it won't be GC'd by a last
|
|
|
|
* ditch attempt to collect garbage, or a GC that otherwise nests or races
|
|
|
|
* under any of the following calls. If one of the following calls fails,
|
|
|
|
* it will overwrite this exception object with one of its own (except in
|
|
|
|
* case of OOM errors, of course).
|
|
|
|
*/
|
|
|
|
JS_SetPendingException(cx, OBJECT_TO_JSVAL(errObject));
|
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
messageStr = JS_NewStringCopyZ(cx, message);
|
|
|
|
if (!messageStr) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
2001-08-22 08:59:28 +04:00
|
|
|
}
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2000-09-09 04:41:15 +04:00
|
|
|
if (reportp) {
|
2002-03-03 03:59:16 +03:00
|
|
|
filenameStr = JS_NewStringCopyZ(cx, reportp->filename);
|
|
|
|
if (!filenameStr) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
lineno = reportp->lineno;
|
2002-02-14 10:25:34 +03:00
|
|
|
} else {
|
2002-03-03 03:59:16 +03:00
|
|
|
filenameStr = cx->runtime->emptyString;
|
|
|
|
lineno = 0;
|
2000-09-09 04:41:15 +04:00
|
|
|
}
|
2002-03-03 03:59:16 +03:00
|
|
|
ok = InitExceptionObject(cx, errObject, messageStr, filenameStr, lineno);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
2001-09-03 23:36:24 +04:00
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
/*
|
2002-03-03 03:59:16 +03:00
|
|
|
* Construct a new copy of the error report struct, and store it in the
|
|
|
|
* exception object's private data. We can't use the error report struct
|
|
|
|
* that was passed in, because it's stack-allocated, and also because it
|
|
|
|
* may point to transient data in the JSTokenStream.
|
1998-10-14 14:22:38 +04:00
|
|
|
*/
|
2000-10-14 02:11:52 +04:00
|
|
|
privateData = exn_newPrivate(cx, reportp);
|
2002-03-03 03:59:16 +03:00
|
|
|
if (!privateData) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
1998-11-05 03:08:43 +03:00
|
|
|
OBJ_SET_SLOT(cx, errObject, JSSLOT_PRIVATE, PRIVATE_TO_JSVAL(privateData));
|
1998-10-14 14:22:38 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
/* Flag the error report passed in to indicate an exception was raised. */
|
1998-10-14 14:22:38 +04:00
|
|
|
reportp->flags |= JSREPORT_EXCEPTION;
|
1998-11-05 03:08:43 +03:00
|
|
|
|
2002-03-03 03:59:16 +03:00
|
|
|
out:
|
|
|
|
cx->creatingException = JS_FALSE;
|
|
|
|
return ok;
|
1998-10-14 14:22:38 +04:00
|
|
|
}
|
|
|
|
#endif /* JS_HAS_ERROR_EXCEPTIONS */
|
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
#if JS_HAS_EXCEPTIONS
|
|
|
|
|
2002-03-14 03:14:48 +03:00
|
|
|
JSBool
|
1998-11-05 03:08:43 +03:00
|
|
|
js_ReportUncaughtException(JSContext *cx)
|
|
|
|
{
|
|
|
|
JSObject *exnObject;
|
|
|
|
JSString *str;
|
|
|
|
jsval exn;
|
2004-12-09 05:19:53 +03:00
|
|
|
JSErrorReport *reportp, report;
|
1999-10-07 01:31:34 +04:00
|
|
|
const char *bytes;
|
2004-12-12 01:00:34 +03:00
|
|
|
JSBool ok;
|
1999-10-07 01:31:34 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
if (!JS_IsExceptionPending(cx))
|
2004-07-17 06:39:55 +04:00
|
|
|
return JS_TRUE;
|
2000-04-05 10:39:11 +04:00
|
|
|
|
1998-11-05 03:08:43 +03:00
|
|
|
if (!JS_GetPendingException(cx, &exn))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because js_ValueToString below could error and an exception object
|
2004-07-17 06:39:55 +04:00
|
|
|
* could become unrooted, we must root exnObject.
|
1998-11-05 03:08:43 +03:00
|
|
|
*/
|
2004-07-17 06:39:55 +04:00
|
|
|
if (JSVAL_IS_PRIMITIVE(exn)) {
|
|
|
|
exnObject = NULL;
|
|
|
|
} else {
|
1998-11-05 03:08:43 +03:00
|
|
|
exnObject = JSVAL_TO_OBJECT(exn);
|
1999-04-27 19:18:57 +04:00
|
|
|
if (!js_AddRoot(cx, &exnObject, "exn.report.root"))
|
1998-11-05 03:08:43 +03:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if JS_HAS_ERROR_EXCEPTIONS
|
|
|
|
reportp = js_ErrorFromException(cx, exn);
|
|
|
|
#else
|
|
|
|
reportp = NULL;
|
|
|
|
#endif
|
|
|
|
|
2002-03-14 03:14:48 +03:00
|
|
|
str = js_ValueToString(cx, exn);
|
|
|
|
bytes = str ? js_GetStringBytes(str) : "null";
|
2004-12-12 01:00:34 +03:00
|
|
|
ok = JS_TRUE;
|
1999-10-07 01:31:34 +04:00
|
|
|
|
2004-12-09 05:19:53 +03:00
|
|
|
if (!reportp && exnObject) {
|
|
|
|
jsval v;
|
|
|
|
const char *filename;
|
|
|
|
int32 lineno;
|
|
|
|
|
2004-12-12 01:00:34 +03:00
|
|
|
ok = JS_GetProperty(cx, exnObject, js_message_str, &v);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
2004-12-09 05:19:53 +03:00
|
|
|
bytes = JSVAL_IS_STRING(v) ? JS_GetStringBytes(JSVAL_TO_STRING(v)) : "";
|
|
|
|
|
2004-12-12 01:00:34 +03:00
|
|
|
ok = JS_GetProperty(cx, exnObject, js_filename_str, &v);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
2004-12-09 05:19:53 +03:00
|
|
|
filename = JSVAL_IS_STRING(v) ? JS_GetStringBytes(JSVAL_TO_STRING(v))
|
|
|
|
: "";
|
|
|
|
|
2004-12-12 01:00:34 +03:00
|
|
|
ok = JS_GetProperty(cx, exnObject, js_lineno_str, &v);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
|
|
|
ok = js_ValueToInt32 (cx, v, &lineno);
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
2004-12-09 05:19:53 +03:00
|
|
|
|
|
|
|
reportp = &report;
|
|
|
|
memset(&report, 0, sizeof report);
|
|
|
|
report.filename = filename;
|
|
|
|
report.lineno = (lineno >= 0) ? (uintN) lineno : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reportp) {
|
1998-11-05 03:08:43 +03:00
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
1999-10-07 01:31:34 +04:00
|
|
|
JSMSG_UNCAUGHT_EXCEPTION, bytes);
|
1998-11-05 03:08:43 +03:00
|
|
|
} else {
|
|
|
|
/* Flag the error as an exception. */
|
|
|
|
reportp->flags |= JSREPORT_EXCEPTION;
|
1999-10-07 01:31:34 +04:00
|
|
|
js_ReportErrorAgain(cx, bytes, reportp);
|
1998-11-05 03:08:43 +03:00
|
|
|
}
|
|
|
|
|
2004-07-17 06:39:55 +04:00
|
|
|
JS_ClearPendingException(cx);
|
2004-12-12 01:00:34 +03:00
|
|
|
out:
|
|
|
|
if (exnObject)
|
|
|
|
js_RemoveRoot(cx->runtime, &exnObject);
|
|
|
|
return ok;
|
1998-11-05 03:08:43 +03:00
|
|
|
}
|
|
|
|
|
2002-03-14 03:14:48 +03:00
|
|
|
#endif /* JS_HAS_EXCEPTIONS */
|