JS_ReportErrorNumber 编辑

Report an error with an application-defined error code.

Syntax

void
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
                     void *userRef, const unsigned errorNumber, ...);

void
JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
                     void *userRef, const unsigned errorNumber, ...);

bool
JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags,
                             JSErrorCallback errorCallback, void *userRef,
                             const unsigned errorNumber, ...);

bool
JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags,
                               JSErrorCallback errorCallback, void *userRef,
                               const unsigned errorNumber, ...);

void
JS_ReportErrorNumberUCArray(JSContext *cx, JSErrorCallback errorCallback,
                            void *userRef, const unsigned errorNumber,
                            const char16_t **args); // Added in SpiderMonkey 19

NameTypeDescription
cxJSContext *The context in which to report the error. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
flagsunsignedError report flags.
errorCallbackJSErrorCallbackCallback to fetch the error message.
userRefvoid *A pointer to application data. The JavaScript engine passes this pointer to errorCallback. The meaning of the data is up to the application.
errorNumberconst unsignedAn error code. The JavaScript engine passes this number to errorCallback. The meaning of the error number is up to the application.
... / args... / const char16_t **

Additional arguments for the error message. These arguments must be of type char * for JS_ReportErrorNumber or JS_ReportErrorFlagsAndNumber, or char16_t * for JS_ReportErrorNumberUC or JS_ReportErrorFlagsAndNumberUC.

The number of additional arguments required depends on the error message, which is determined by the errorCallback.

Callback syntax

typedef const JSErrorFormatString *
(* JSErrorCallback)(void *userRef, const unsigned errorNumber);
NameTypeDescription
userRefvoid *The userRef pointer that was passed to the ReportErrorNumber API.
errorNumberconst unsignedThe errorNumber that was passed to the ReportErrorNumber API.

Description

These functions create a JSErrorReport, populate it with an error message obtained from the given JSErrorCallback, and either report it to the current error reporter callback or create an Error object and set it as the pending exception.

First errorCallback(userRef, errorNumber) is called. If errorCallback returns NULL, (??? what happens?).

Otherwise, if the JSErrorFormatString returned by the JSErrorCallback has .exnType == JSEXN_NONE, then the error reporter, if any, is called, and no Error object is created. (??? The source code seems to say we ignore the .exnType, actually, but surely I'm just missing something.)

Otherwise, if any JavaScript code is running in cx (for example, if the caller is a JSNative that was called from a script), then an Error object is created and becomes the pending exception. The error reporter is not called yet, because the script still has an opportunity to catch and handle the exception.

Otherwise, no JavaScript code is running in cx. If the JSOPTION_DONT_REPORT_UNCAUGHT option is set, (??? what happens?). Otherwise, (??? what happens?).

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:115 次

字数:7157

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文