#ifndef jsexn_h
#define jsexn_h
#include "jsapi.h"
#include "NamespaceImports.h"
#include "js/UniquePtr.h"
#include "vm/JSContext.h"
namespace js {
class ErrorObject;
UniquePtr<JSErrorNotes::Note> CopyErrorNote(JSContext* cx,
JSErrorNotes::Note* note);
UniquePtr<JSErrorReport> CopyErrorReport(JSContext* cx, JSErrorReport* report);
JSString* ComputeStackString(JSContext* cx);
extern void ErrorToException(JSContext* cx, JSErrorReport* reportp,
JSErrorCallback callback, void* userRef);
extern JSErrorReport* ErrorFromException(JSContext* cx, HandleObject obj);
extern JSObject* CopyErrorObject(JSContext* cx,
JS::Handle<ErrorObject*> errobj);
static_assert(
JSEXN_ERR == 0 &&
JSProto_Error + JSEXN_INTERNALERR == JSProto_InternalError &&
JSProto_Error + JSEXN_EVALERR == JSProto_EvalError &&
JSProto_Error + JSEXN_RANGEERR == JSProto_RangeError &&
JSProto_Error + JSEXN_REFERENCEERR == JSProto_ReferenceError &&
JSProto_Error + JSEXN_SYNTAXERR == JSProto_SyntaxError &&
JSProto_Error + JSEXN_TYPEERR == JSProto_TypeError &&
JSProto_Error + JSEXN_URIERR == JSProto_URIError &&
JSProto_Error + JSEXN_DEBUGGEEWOULDRUN == JSProto_DebuggeeWouldRun &&
JSProto_Error + JSEXN_WASMCOMPILEERROR == JSProto_CompileError &&
JSProto_Error + JSEXN_WASMLINKERROR == JSProto_LinkError &&
JSProto_Error + JSEXN_WASMRUNTIMEERROR == JSProto_RuntimeError &&
JSEXN_WASMRUNTIMEERROR + 1 == JSEXN_WARN &&
JSEXN_WARN + 1 == JSEXN_NOTE && JSEXN_NOTE + 1 == JSEXN_LIMIT,
"GetExceptionProtoKey and ExnTypeFromProtoKey require that "
"each corresponding JSExnType and JSProtoKey value be separated "
"by the same constant value");
static inline JSProtoKey GetExceptionProtoKey(JSExnType exn) {
MOZ_ASSERT(JSEXN_ERR <= exn);
MOZ_ASSERT(exn < JSEXN_WARN);
return JSProtoKey(JSProto_Error + int(exn));
}
static inline JSExnType ExnTypeFromProtoKey(JSProtoKey key) {
JSExnType type = static_cast<JSExnType>(key - JSProto_Error);
MOZ_ASSERT(type >= JSEXN_ERR);
MOZ_ASSERT(type < JSEXN_ERROR_LIMIT);
return type;
}
static inline bool IsErrorProtoKey(JSProtoKey key) {
int type = key - JSProto_Error;
return type >= JSEXN_ERR && type < JSEXN_ERROR_LIMIT;
}
class AutoClearPendingException {
JSContext* cx;
public:
explicit AutoClearPendingException(JSContext* cxArg) : cx(cxArg) {}
~AutoClearPendingException() { JS_ClearPendingException(cx); }
};
extern const char* ValueToSourceForError(JSContext* cx, HandleValue val,
JS::UniqueChars& bytes);
bool GetInternalError(JSContext* cx, unsigned errorNumber,
MutableHandleValue error);
bool GetTypeError(JSContext* cx, unsigned errorNumber,
MutableHandleValue error);
}
#endif