js/src/jsexn.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /*
michael@0 8 * JS runtime exception classes.
michael@0 9 */
michael@0 10
michael@0 11 #ifndef jsexn_h
michael@0 12 #define jsexn_h
michael@0 13
michael@0 14 #include "jsapi.h"
michael@0 15 #include "NamespaceImports.h"
michael@0 16
michael@0 17 namespace js {
michael@0 18 class ErrorObject;
michael@0 19
michael@0 20 JSErrorReport *
michael@0 21 CopyErrorReport(JSContext *cx, JSErrorReport *report);
michael@0 22
michael@0 23 JSString *
michael@0 24 ComputeStackString(JSContext *cx);
michael@0 25 }
michael@0 26
michael@0 27 /*
michael@0 28 * Given a JSErrorReport, check to see if there is an exception associated with
michael@0 29 * the error number. If there is, then create an appropriate exception object,
michael@0 30 * set it as the pending exception, and set the JSREPORT_EXCEPTION flag on the
michael@0 31 * error report. Exception-aware host error reporters should probably ignore
michael@0 32 * error reports so flagged.
michael@0 33 *
michael@0 34 * Return true if cx->throwing and cx->exception were set.
michael@0 35 *
michael@0 36 * This means that:
michael@0 37 *
michael@0 38 * - If the error is successfully converted to an exception and stored in
michael@0 39 * cx->exception, the return value is true. This is the "normal", happiest
michael@0 40 * case for the caller.
michael@0 41 *
michael@0 42 * - If we try to convert, but fail with OOM or some other error that ends up
michael@0 43 * setting cx->throwing to true and setting cx->exception, then we also
michael@0 44 * return true (because callers want to treat that case the same way).
michael@0 45 * The original error described by *reportp typically won't be reported
michael@0 46 * anywhere; instead OOM is reported.
michael@0 47 *
michael@0 48 * - If *reportp is just a warning, or the error code is unrecognized, or if
michael@0 49 * we decided to do nothing in order to avoid recursion, then return
michael@0 50 * false. In those cases, this error is just being swept under the rug
michael@0 51 * unless the caller decides to call CallErrorReporter explicitly.
michael@0 52 */
michael@0 53 extern bool
michael@0 54 js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
michael@0 55 JSErrorCallback callback, void *userRef);
michael@0 56
michael@0 57 /*
michael@0 58 * Called if a JS API call to js_Execute or js_InternalCall fails; calls the
michael@0 59 * error reporter with the error report associated with any uncaught exception
michael@0 60 * that has been raised. Returns true if there was an exception pending, and
michael@0 61 * the error reporter was actually called.
michael@0 62 *
michael@0 63 * The JSErrorReport * that the error reporter is called with is currently
michael@0 64 * associated with a JavaScript object, and is not guaranteed to persist after
michael@0 65 * the object is collected. Any persistent uses of the JSErrorReport contents
michael@0 66 * should make their own copy.
michael@0 67 *
michael@0 68 * The flags field of the JSErrorReport will have the JSREPORT_EXCEPTION flag
michael@0 69 * set; embeddings that want to silently propagate JavaScript exceptions to
michael@0 70 * other contexts may want to use an error reporter that ignores errors with
michael@0 71 * this flag.
michael@0 72 */
michael@0 73 extern bool
michael@0 74 js_ReportUncaughtException(JSContext *cx);
michael@0 75
michael@0 76 extern JSErrorReport *
michael@0 77 js_ErrorFromException(JSContext *cx, js::HandleObject obj);
michael@0 78
michael@0 79 extern const JSErrorFormatString *
michael@0 80 js_GetLocalizedErrorMessage(js::ExclusiveContext *cx, void *userRef, const char *locale,
michael@0 81 const unsigned errorNumber);
michael@0 82
michael@0 83 /*
michael@0 84 * Make a copy of errobj parented to scope.
michael@0 85 *
michael@0 86 * cx must be in the same compartment as scope. errobj may be in a different
michael@0 87 * compartment, but it must be an Error object (not a wrapper of one) and it
michael@0 88 * must not be one of the prototype objects created by js_InitExceptionClasses
michael@0 89 * (errobj->getPrivate() must not be nullptr).
michael@0 90 */
michael@0 91 extern JSObject *
michael@0 92 js_CopyErrorObject(JSContext *cx, JS::Handle<js::ErrorObject*> errobj, js::HandleObject scope);
michael@0 93
michael@0 94 static inline JSProtoKey
michael@0 95 GetExceptionProtoKey(JSExnType exn)
michael@0 96 {
michael@0 97 JS_ASSERT(JSEXN_ERR <= exn);
michael@0 98 JS_ASSERT(exn < JSEXN_LIMIT);
michael@0 99 return JSProtoKey(JSProto_Error + int(exn));
michael@0 100 }
michael@0 101
michael@0 102 #endif /* jsexn_h */

mercurial