JSErrorReport 编辑

Describes the format of a JS error that is used either by the internal error reporting mechanism or by a user-defined error-reporting mechanism.

Syntax

JSErrorReport();

Properties

NameTypeDescription
filenameconst char *Indicates the source file or URL that produced the error condition. If NULL, the error is local to the script in the current HTML page.
linenounsignedLine number in the source that caused the error.
columnunsignedzero-based column index in line in the source that caused the error.
isMutedbool

The Web Platform allows scripts to be loaded from arbitrary cross-origin sources. This allows an attack by which a malicious website loads a sensitive file (say, a bank statement) cross-origin (using the user's cookies), and sniffs the generated syntax errors (via a window.onerror handler) for juicy morsels of its contents.

To counter this attack, HTML5 specifies that script errors should be sanitized ("muted") when the script is not same-origin with the global for which it is loaded. Callers should set this flag for cross-origin scripts, and it will be propagated appropriately to child scripts and passed back in JSErrorReports.

linebufconst char *Text of the line that caused the error, minus the trailing newline character.
tokenptrconst char *Pointer to the error token in *linebuf.
uclinebufconst char16_t *Unicode line buffer. This is the buffer that contains the original data.
uctokenptrconst char16_t *Pointer to the error token in *uclinebuf.
flagsunsigned

The logical OR of zero or more of the following flags:

JSREPORT_WARNING
This "error" is really only a warning. It will not cause the current operation to fail.
JSREPORT_EXCEPTION
An exception is being raised. A JSErrorReporter might choose to ignore a JSErrorReport that has this flag set, since the exception may be caught and handled by JavaScript code.
JSREPORT_STRICT
This error is only being reported because the engine is in strict mode.
JSREPORT_STRICT_MODE_ERROR
This condition is an error in strict mode code, a warning if JS_HAS_STRICT_OPTION(cx), and otherwise should not be reported at all. We check the strictness of the context's top frame's script; where that isn't appropriate, the caller should do the right checks itself instead of using this flag.

The constant JSREPORT_ERROR is 0 and can be used to indicate an error report without any of the above flags.

errorNumberunsignedThe error number.
ucmessageconst char16_t *The default unicode error message.
messageArgsconst char16_t **Arguments for the error message.
exnTypeint16_tOne of the JSExnType constants.

Description

JSErrorReport describes a single error that occurs in the execution of script.

In the event of an error, filename will either contain the name of the external source file or URL containing the script (SCRIPT SRC=) or NULL, indicating that a script embedded in the current HTML page caused the error.

lineno indicates the line number of the script containing the error. In the case of an error in a script embedded in the HTML page, lineno indicates the HTML lineno where the script error is located.

linebuf is a pointer to a user-defined buffer into which JS copies the offending line of the script.

tokenptr is a pointer into linebuf that identifies the precise location line of the problem within the offending line.

uclinebuf is a pointer to a user-defined buffer into which JS copies the Unicode (original) version of the offending line of script.

uctokenptr is a pointer into uclinebuf that identifies the precise location line of the problem within the offending Unicode (original) version of the offending line.

To use JSErrorReport, your application must define a variable of type JSErrorReport and allocate a buffer to hold the text that generated the error condition. Set linebuf to point at the buffer before your application executes a script. For Unicode scripts, define a second buffer that holds the Unicode version of the text the generated the error. For application that do not use Unicode, set uclinebuf and uctokenptr to NULL.

Macros

NameDescription
JSREPORT_IS_WARNING(flags)Returns true if flags has JSREPORT_WARNING.
JSREPORT_IS_EXCEPTION(flags)Returns true if flags has JSREPORT_EXCEPTION.
JSREPORT_IS_STRICT(flags)Returns true if flags has JSREPORT_STRICT.
JSREPORT_IS_STRICT_MODE_ERROR(flags)Returns true if flags has JSREPORT_STRICT_MODE_ERROR.

See Also

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

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

发布评论

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

词条统计

浏览:60 次

字数:8604

最后编辑:8年前

编辑次数:0 次

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