From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../webassembly/compileerror/index.html | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror') diff --git a/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html b/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html new file mode 100644 index 0000000000..179b8589a2 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html @@ -0,0 +1,114 @@ +--- +title: WebAssembly.CompileError() +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError +--- +
{{JSRef}}
+ +

WebAssembly.CompileError()构造函数创建一个新的WebAssembly CompileError对象,该对象表示WebAssembly解码或验证期间的错误。

+ +

语法

+ +
new WebAssembly.CompileError(message, fileName, lineNumber)
+ +

参数

+ +
+
message {{optional_inline}}
+
有可读性的错误描述。
+
fileName {{optional_inline}}{{non-standard_inline}}
+
包含导致异常的代码的文件名。
+
lineNumber {{optional_inline}}{{non-standard_inline}}
+
导致异常的代码的行号。
+
+ +

属性

+ +

CompileError构造函数没有一些它特有的属性,但是,它确实通过原型链继承了某些属性。

+ +
+
WebAssembly.CompileError.prototype.constructor
+
创建示例原型的特定函数。
+
{{jsxref("Error.prototype.message", "WebAssembly.CompileError.prototype.message")}}
+
错误信息。 尽管ECMA-262指定{{jsxref("URIError")}}应提供自己的message属性,但在SpiderMonkey中,它继承了 {{jsxref("Error.prototype.message")}}。
+
{{jsxref("Error.prototype.name", "WebAssembly.CompileError.prototype.name")}}
+
错误名称。继承自 {{jsxref("Error")}}。
+
{{jsxref("Error.prototype.fileName", "WebAssembly.CompileError.prototype.fileName")}}
+
报出错误的文件名。继承自 {{jsxref("Error")}}。
+
{{jsxref("Error.prototype.lineNumber", "WebAssembly.CompileError.prototype.lineNumber")}}
+
报出错误的代码所在文件中的行数。继承自 {{jsxref("Error")}}。
+
{{jsxref("Error.prototype.columnNumber", "WebAssembly.CompileError.prototype.columnNumber")}}
+
报出错误的代码所在文件中的列数。继承自 {{jsxref("Error")}}。
+
{{jsxref("Error.prototype.stack", "WebAssembly.CompileError.prototype.stack")}}
+
堆栈跟踪。 继承自{{jsxref("Error")}}。
+
+ +

方法

+ +

CompileError构造函数不包含自己的方法,但是,它确实通过原型链继承了一些方法。

+ +
+
{{jsxref("Error.prototype.toSource", "WebAssembly.CompileError.prototype.toSource()")}}
+
返回可能导致相同错误的代码。 继承自{{jsxref("Error")}}。
+
{{jsxref("Error.prototype.toString", "WebAssembly.CompileError.prototype.toString()")}}
+
返回表示代表指定的Error对象的字符串。从 {{jsxref("Error")}}继承。
+
+ +

示例

+ +

以下代码段创建一个新的CompileError实例,并将其详细信息记录到控制台:

+ +
try {
+  throw new WebAssembly.CompileError('Hello', 'someFile', 10);
+} catch (e) {
+  console.log(e instanceof CompileError); // true
+  console.log(e.message);                 // "Hello"
+  console.log(e.name);                    // "CompileError"
+  console.log(e.fileName);                // "someFile"
+  console.log(e.lineNumber);              // 10
+  console.log(e.columnNumber);            // 0
+  console.log(e.stack);                   // 返回代码运行的位置
+}
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('WebAssembly JS', '#constructor-properties-of-the-webassembly-object', 'WebAssembly constructors')}}{{Spec2('WebAssembly JS')}}Initial WebAssembly draft definition.
{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard', 'NativeError')}}{{Spec2('ESDraft')}}Definition of standard NativeError types.
+ +

浏览器兼容性

+ +
+ + +

{{Compat("javascript.builtins.WebAssembly.CompileError")}}

+
+ +

参见

+ + + +
+
-- cgit v1.2.3-54-g00ecf