aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html
blob: 99d92ca48daa644e3ab9c3ecfcfa1a3446e3d291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
title: WebAssembly.CompileError()
slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError
translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError
---
<div>{{JSRef}}</div>

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

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><code>new WebAssembly.CompileError(<var>message</var>, <var>fileName</var>, <var>lineNumber</var>)</code></pre>

<h3 id="参数">参数</h3>

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

<h2 id="属性">属性</h2>

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

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

<h2 id="方法">方法</h2>

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

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

<h2 id="示例">示例</h2>

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

<pre class="brush: js">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);                   // 返回代码运行的位置
}</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('WebAssembly JS', '#constructor-properties-of-the-webassembly-object', 'WebAssembly constructors')}}</td>
   <td>{{Spec2('WebAssembly JS')}}</td>
   <td>Initial WebAssembly draft definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard', 'NativeError')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>Definition of standard NativeError types.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">浏览器兼容性</h2>

<div>


<p>{{Compat("javascript.builtins.WebAssembly.CompileError")}}</p>
</div>

<h2 id="参见">参见</h2>

<ul>
 <li><a href="/en-US/docs/WebAssembly">WebAssembly</a> overview page</li>
 <li><a href="/en-US/docs/WebAssembly/Concepts">WebAssembly concepts</a></li>
 <li><a href="/en-US/docs/WebAssembly/Using_the_JavaScript_API">Using the WebAssembly JavaScript API</a></li>
</ul>

<dl>
</dl>