OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 load("test/mjsunit/wasm/wasm-constants.js"); | 9 load("test/mjsunit/wasm/wasm-constants.js"); |
10 load("test/mjsunit/wasm/wasm-module-builder.js"); | 10 load("test/mjsunit/wasm/wasm-module-builder.js"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 assertCompileError(builder().addFunction("f", kSig_i_v).end().toBuffer()); | 79 assertCompileError(builder().addFunction("f", kSig_i_v).end().toBuffer()); |
80 assertCompileError(builder().addFunction("f", kSig_i_v).addBody([ | 80 assertCompileError(builder().addFunction("f", kSig_i_v).addBody([ |
81 kExprReturn | 81 kExprReturn |
82 ]).end().toBuffer()); | 82 ]).end().toBuffer()); |
83 assertCompileError(builder().addFunction("f", kSig_v_v).addBody([ | 83 assertCompileError(builder().addFunction("f", kSig_v_v).addBody([ |
84 kExprGetLocal, 0 | 84 kExprGetLocal, 0 |
85 ]).end().toBuffer()); | 85 ]).end().toBuffer()); |
86 assertCompileError(builder().addStart(0).toBuffer()); | 86 assertCompileError(builder().addStart(0).toBuffer()); |
87 })(); | 87 })(); |
88 | 88 |
| 89 (function TestTypeError() { |
| 90 let b; |
| 91 b = builder(); |
| 92 b.addImport("foo", "bar", kSig_v_v); |
| 93 assertTypeError(b.toBuffer(), {}); |
| 94 |
| 95 b = builder(); |
| 96 b.addImportedGlobal("foo", "bar", kWasmI32); |
| 97 assertTypeError(b.toBuffer(), {}); |
| 98 |
| 99 b = builder(); |
| 100 b.addImportedMemory("foo", "bar"); |
| 101 assertTypeError(b.toBuffer(), {}); |
| 102 })(); |
| 103 |
89 (function TestLinkingError() { | 104 (function TestLinkingError() { |
90 let b; | 105 let b; |
91 | 106 |
92 b = builder(); | 107 b = builder(); |
93 b.addImport("foo", "bar", kSig_v_v); | 108 b.addImport("foo", "bar", kSig_v_v); |
94 assertLinkError(b.toBuffer(), {}); | |
95 b = builder(); | |
96 b.addImport("foo", "bar", kSig_v_v); | |
97 assertLinkError(b.toBuffer(), {foo: {}}); | 109 assertLinkError(b.toBuffer(), {foo: {}}); |
98 b = builder(); | 110 b = builder(); |
99 b.addImport("foo", "bar", kSig_v_v); | 111 b.addImport("foo", "bar", kSig_v_v); |
100 assertLinkError(b.toBuffer(), {foo: {bar: 9}}); | 112 assertLinkError(b.toBuffer(), {foo: {bar: 9}}); |
101 | 113 |
102 b = builder(); | 114 b = builder(); |
103 b.addImportedGlobal("foo", "bar", kWasmI32); | 115 b.addImportedGlobal("foo", "bar", kWasmI32); |
104 assertLinkError(b.toBuffer(), {}); | |
105 b = builder(); | |
106 b.addImportedGlobal("foo", "bar", kWasmI32); | |
107 assertLinkError(b.toBuffer(), {foo: {}}); | 116 assertLinkError(b.toBuffer(), {foo: {}}); |
108 b = builder(); | 117 b = builder(); |
109 b.addImportedGlobal("foo", "bar", kWasmI32); | 118 b.addImportedGlobal("foo", "bar", kWasmI32); |
110 assertLinkError(b.toBuffer(), {foo: {bar: ""}}); | 119 assertLinkError(b.toBuffer(), {foo: {bar: ""}}); |
111 b = builder(); | 120 b = builder(); |
112 b.addImportedGlobal("foo", "bar", kWasmI32); | 121 b.addImportedGlobal("foo", "bar", kWasmI32); |
113 assertLinkError(b.toBuffer(), {foo: {bar: () => 9}}); | 122 assertLinkError(b.toBuffer(), {foo: {bar: () => 9}}); |
114 | 123 |
115 b = builder(); | 124 b = builder(); |
116 b.addImportedMemory("foo", "bar"); | 125 b.addImportedMemory("foo", "bar"); |
117 assertLinkError(b.toBuffer(), {}); | |
118 b = builder(); | |
119 b.addImportedMemory("foo", "bar"); | |
120 assertLinkError(b.toBuffer(), {foo: {}}); | 126 assertLinkError(b.toBuffer(), {foo: {}}); |
121 b = builder(); | 127 b = builder(); |
122 b.addImportedMemory("foo", "bar", 1); | 128 b.addImportedMemory("foo", "bar", 1); |
123 assertLinkError(b.toBuffer(), | 129 assertLinkError(b.toBuffer(), |
124 {foo: {bar: () => new WebAssembly.Memory({initial: 0})}}); | 130 {foo: {bar: () => new WebAssembly.Memory({initial: 0})}}); |
125 | 131 |
126 b = builder(); | 132 b = builder(); |
127 b.addFunction("startup", kSig_v_v).addBody([ | 133 b.addFunction("startup", kSig_v_v).addBody([ |
128 kExprUnreachable, | 134 kExprUnreachable, |
129 ]).end().addStart(0); | 135 ]).end().addStart(0); |
(...skipping 24 matching lines...) Expand all Loading... |
154 b.addImport("foo", "bar", kSig_v_l); | 160 b.addImport("foo", "bar", kSig_v_l); |
155 assertConversionError(b.addFunction("run", kSig_v_v).addBody([ | 161 assertConversionError(b.addFunction("run", kSig_v_v).addBody([ |
156 kExprI64Const, 0, kExprCallFunction, 0 | 162 kExprI64Const, 0, kExprCallFunction, 0 |
157 ]).exportFunc().end().toBuffer(), {foo:{bar: (l)=>{}}}); | 163 ]).exportFunc().end().toBuffer(), {foo:{bar: (l)=>{}}}); |
158 | 164 |
159 b = builder() | 165 b = builder() |
160 assertConversionError(builder().addFunction("run", kSig_l_v).addBody([ | 166 assertConversionError(builder().addFunction("run", kSig_l_v).addBody([ |
161 kExprI64Const, 0 | 167 kExprI64Const, 0 |
162 ]).exportFunc().end().toBuffer()); | 168 ]).exportFunc().end().toBuffer()); |
163 })(); | 169 })(); |
OLD | NEW |