2013-04-16 13:47:10 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* JS runtime exception classes.
|
|
|
|
*/
|
|
|
|
|
2013-06-19 17:59:46 -07:00
|
|
|
#ifndef jsexn_h
|
|
|
|
#define jsexn_h
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-12 22:20:27 -07:00
|
|
|
#include "jsapi.h"
|
2013-09-01 21:51:02 -07:00
|
|
|
#include "NamespaceImports.h"
|
2011-07-12 18:19:13 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Initialize the exception constructor/prototype hierarchy.
|
|
|
|
*/
|
|
|
|
extern JSObject *
|
2012-09-20 22:17:49 -07:00
|
|
|
js_InitExceptionClasses(JSContext *cx, js::HandleObject obj);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a JSErrorReport, check to see if there is an exception associated with
|
|
|
|
* the error number. If there is, then create an appropriate exception object,
|
|
|
|
* set it as the pending exception, and set the JSREPORT_EXCEPTION flag on the
|
|
|
|
* error report. Exception-aware host error reporters should probably ignore
|
2013-08-06 23:59:54 -07:00
|
|
|
* error reports so flagged. Returns true if an associated exception is
|
|
|
|
* found and set, false otherwise.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2013-08-08 15:53:04 -07:00
|
|
|
extern bool
|
2009-12-15 14:20:48 -08:00
|
|
|
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
|
|
|
|
JSErrorCallback callback, void *userRef);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called if a JS API call to js_Execute or js_InternalCall fails; calls the
|
|
|
|
* error reporter with the error report associated with any uncaught exception
|
|
|
|
* that has been raised. Returns true if there was an exception pending, and
|
|
|
|
* the error reporter was actually called.
|
|
|
|
*
|
|
|
|
* The JSErrorReport * that the error reporter is called with is currently
|
|
|
|
* associated with a JavaScript object, and is not guaranteed to persist after
|
|
|
|
* the object is collected. Any persistent uses of the JSErrorReport contents
|
|
|
|
* should make their own copy.
|
|
|
|
*
|
|
|
|
* The flags field of the JSErrorReport will have the JSREPORT_EXCEPTION flag
|
|
|
|
* set; embeddings that want to silently propagate JavaScript exceptions to
|
|
|
|
* other contexts may want to use an error reporter that ignores errors with
|
|
|
|
* this flag.
|
|
|
|
*/
|
2013-08-08 15:53:04 -07:00
|
|
|
extern bool
|
2007-03-22 10:30:00 -07:00
|
|
|
js_ReportUncaughtException(JSContext *cx);
|
|
|
|
|
|
|
|
extern JSErrorReport *
|
2012-10-04 16:21:36 -07:00
|
|
|
js_ErrorFromException(jsval exn);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern const JSErrorFormatString *
|
2013-08-29 08:56:05 -07:00
|
|
|
js_GetLocalizedErrorMessage(js::ExclusiveContext *cx, void *userRef, const char *locale,
|
2012-02-28 15:11:11 -08:00
|
|
|
const unsigned errorNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-12 18:19:13 -07:00
|
|
|
/*
|
|
|
|
* Make a copy of errobj parented to scope.
|
|
|
|
*
|
|
|
|
* cx must be in the same compartment as scope. errobj may be in a different
|
2011-08-18 10:30:19 -07:00
|
|
|
* compartment, but it must be an Error object (not a wrapper of one) and it
|
|
|
|
* must not be one of the prototype objects created by js_InitExceptionClasses
|
2013-10-07 09:43:20 -07:00
|
|
|
* (errobj->getPrivate() must not be nullptr).
|
2011-07-12 18:19:13 -07:00
|
|
|
*/
|
|
|
|
extern JSObject *
|
2012-04-30 17:10:30 -07:00
|
|
|
js_CopyErrorObject(JSContext *cx, js::HandleObject errobj, js::HandleObject scope);
|
2011-07-12 18:19:13 -07:00
|
|
|
|
2012-02-07 11:45:18 -08:00
|
|
|
static JS_INLINE JSProtoKey
|
2012-02-28 15:11:11 -08:00
|
|
|
GetExceptionProtoKey(int exn)
|
2012-02-07 11:45:18 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(JSEXN_ERR <= exn);
|
|
|
|
JS_ASSERT(exn < JSEXN_LIMIT);
|
|
|
|
return JSProtoKey(JSProto_Error + exn);
|
|
|
|
}
|
|
|
|
|
2013-06-19 17:59:46 -07:00
|
|
|
#endif /* jsexn_h */
|