1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsexn.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* 1.11 + * JS runtime exception classes. 1.12 + */ 1.13 + 1.14 +#ifndef jsexn_h 1.15 +#define jsexn_h 1.16 + 1.17 +#include "jsapi.h" 1.18 +#include "NamespaceImports.h" 1.19 + 1.20 +namespace js { 1.21 +class ErrorObject; 1.22 + 1.23 +JSErrorReport * 1.24 +CopyErrorReport(JSContext *cx, JSErrorReport *report); 1.25 + 1.26 +JSString * 1.27 +ComputeStackString(JSContext *cx); 1.28 +} 1.29 + 1.30 +/* 1.31 + * Given a JSErrorReport, check to see if there is an exception associated with 1.32 + * the error number. If there is, then create an appropriate exception object, 1.33 + * set it as the pending exception, and set the JSREPORT_EXCEPTION flag on the 1.34 + * error report. Exception-aware host error reporters should probably ignore 1.35 + * error reports so flagged. 1.36 + * 1.37 + * Return true if cx->throwing and cx->exception were set. 1.38 + * 1.39 + * This means that: 1.40 + * 1.41 + * - If the error is successfully converted to an exception and stored in 1.42 + * cx->exception, the return value is true. This is the "normal", happiest 1.43 + * case for the caller. 1.44 + * 1.45 + * - If we try to convert, but fail with OOM or some other error that ends up 1.46 + * setting cx->throwing to true and setting cx->exception, then we also 1.47 + * return true (because callers want to treat that case the same way). 1.48 + * The original error described by *reportp typically won't be reported 1.49 + * anywhere; instead OOM is reported. 1.50 + * 1.51 + * - If *reportp is just a warning, or the error code is unrecognized, or if 1.52 + * we decided to do nothing in order to avoid recursion, then return 1.53 + * false. In those cases, this error is just being swept under the rug 1.54 + * unless the caller decides to call CallErrorReporter explicitly. 1.55 + */ 1.56 +extern bool 1.57 +js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp, 1.58 + JSErrorCallback callback, void *userRef); 1.59 + 1.60 +/* 1.61 + * Called if a JS API call to js_Execute or js_InternalCall fails; calls the 1.62 + * error reporter with the error report associated with any uncaught exception 1.63 + * that has been raised. Returns true if there was an exception pending, and 1.64 + * the error reporter was actually called. 1.65 + * 1.66 + * The JSErrorReport * that the error reporter is called with is currently 1.67 + * associated with a JavaScript object, and is not guaranteed to persist after 1.68 + * the object is collected. Any persistent uses of the JSErrorReport contents 1.69 + * should make their own copy. 1.70 + * 1.71 + * The flags field of the JSErrorReport will have the JSREPORT_EXCEPTION flag 1.72 + * set; embeddings that want to silently propagate JavaScript exceptions to 1.73 + * other contexts may want to use an error reporter that ignores errors with 1.74 + * this flag. 1.75 + */ 1.76 +extern bool 1.77 +js_ReportUncaughtException(JSContext *cx); 1.78 + 1.79 +extern JSErrorReport * 1.80 +js_ErrorFromException(JSContext *cx, js::HandleObject obj); 1.81 + 1.82 +extern const JSErrorFormatString * 1.83 +js_GetLocalizedErrorMessage(js::ExclusiveContext *cx, void *userRef, const char *locale, 1.84 + const unsigned errorNumber); 1.85 + 1.86 +/* 1.87 + * Make a copy of errobj parented to scope. 1.88 + * 1.89 + * cx must be in the same compartment as scope. errobj may be in a different 1.90 + * compartment, but it must be an Error object (not a wrapper of one) and it 1.91 + * must not be one of the prototype objects created by js_InitExceptionClasses 1.92 + * (errobj->getPrivate() must not be nullptr). 1.93 + */ 1.94 +extern JSObject * 1.95 +js_CopyErrorObject(JSContext *cx, JS::Handle<js::ErrorObject*> errobj, js::HandleObject scope); 1.96 + 1.97 +static inline JSProtoKey 1.98 +GetExceptionProtoKey(JSExnType exn) 1.99 +{ 1.100 + JS_ASSERT(JSEXN_ERR <= exn); 1.101 + JS_ASSERT(exn < JSEXN_LIMIT); 1.102 + return JSProtoKey(JSProto_Error + int(exn)); 1.103 +} 1.104 + 1.105 +#endif /* jsexn_h */