Chromium Code Reviews| Index: test/mjsunit/regress/wasm/regression-727560.js |
| diff --git a/test/mjsunit/regress/wasm/regression-727560.js b/test/mjsunit/regress/wasm/regression-727560.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b44c210e05b28b4959d4a77c4e823de0aa72c0a3 |
| --- /dev/null |
| +++ b/test/mjsunit/regress/wasm/regression-727560.js |
| @@ -0,0 +1,143 @@ |
| +// Copyright 2017 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +class Binary extends Array { |
|
Clemens Hammacher
2017/05/31 07:56:37
Please reduce this test case to also use wasm-modu
gdeepti
2017/06/01 07:01:37
Done.
|
| + emit_u8(val) { |
| + this.push(val); |
| + } |
| + emit_u32v(val) { |
| + while (true) { |
| + let v = val & 0xff; |
| + this.push(v); |
| + break; |
| + } |
| + } |
| + emit_bytes() { |
| + } |
| + emit_string(string) { |
| + let string_utf8 = unescape(string); |
| + this.emit_u32v(string_utf8.length); |
| + for (let i = 0; i < string_utf8.length; i++) { |
| + this.emit_u8(string_utf8.charCodeAt(i)); |
| + } |
| + } |
| + emit_header() { |
| + this.push(kWasmH0, kWasmH1, kWasmH2, kWasmH3, |
| + kWasmV0, kWasmV1, kWasmV2, kWasmV3); |
| + } |
| + emit_section(section_code, content_generator) { |
| + this.emit_u8(section_code); |
| + let section = new Binary; |
| + content_generator(section); |
| + this.emit_u32v(section.length); |
| + this.push(...section); |
| + } |
| +} |
| +class WasmFunctionBuilder { |
| + constructor() { |
| + } |
| +} |
| +class WasmModuleBuilder { |
| + constructor() { |
| + this.imports = []; |
| + this.exports = []; |
| + } |
| + addMemory(min, max, exp) { |
| + this.memory = {}; |
| + } |
| + addFunction() { |
| + } |
| + addImportedGlobal() { |
| + let o = { |
| + mutable: false} |
| + } |
| + addImportedMemory(module = "", name, maximum) { |
| + let o = {module: module, name: name, kind: kExternalMemory, |
| + maximum: maximum}; |
| + this.imports.push(o); |
| + } |
| + exportMemoryAs(name) { |
| + this.exports.push({name: name, kind: kExternalMemory}); |
| + } |
| + toArray() { |
| + let binary = new Binary; |
| + let wasm = this; |
| + binary.emit_header(); |
| + section => { |
| + }; |
| + binary.emit_section(kImportSectionCode, section => { |
| + section.emit_u32v(wasm.imports.length); |
| + for (let imp of wasm.imports) { |
| + section.emit_string(imp.module); |
| + section.emit_string(imp.name || ''); |
| + section.emit_u8(imp.kind); |
| + section.emit_u8(); // flags |
| + section.emit_u32v(); // initial |
| + } |
| + }); |
| + if (wasm.memory !== undefined) { |
| + binary.emit_section(kMemorySectionCode, section => { |
| + section.emit_u32v(kResizableMaximumFlag); |
| + section.emit_u32v(); |
| + section.emit_u32v(); |
| + }); |
| + section => { |
| + switch (global.type) { |
| + } |
| + }; |
| + } |
| + var mem_export = (wasm.memory !== undefined && wasm.memory.exp); |
| + var exports_count = wasm.exports.length + (mem_export ? 1 : 0); |
| + binary.emit_section(kExportSectionCode, section => { |
| + section.emit_u32v(exports_count); |
| + for (let exp of wasm.exports) { |
| + section.emit_string(exp.name); |
| + section.emit_u8(exp.kind); |
| + section.emit_u32v(); |
| + } |
| + }); |
| + return binary; |
| + } |
| + toBuffer() { |
| + let bytes = this.toArray(); |
| + let buffer = new ArrayBuffer(bytes.length); |
| + let view = new Uint8Array(buffer); |
| + for (let i = 0; i < bytes.length; i++) { |
| + let val = bytes[i]; |
| + view[i] = val | 0; |
| + } |
| + return buffer; |
| + } |
| + instantiate(ffi) { |
| + let module = new WebAssembly.Module(this.toBuffer()); |
| + let instance = new WebAssembly.Instance(module, ffi); |
| + return instance; |
| + } |
| +} |
| +var kWasmH0 = 0; |
| +var kWasmH1 = 0x61; |
| +var kWasmH2 = 0x73; |
| +var kWasmH3 = 0x6d; |
| +var kWasmV0 = 0x1; |
| +var kWasmV1 = 0; |
| +var kWasmV2 = 0; |
| +var kWasmV3 = 0; |
| +let kImportSectionCode = 2; // Import declarations |
| +let kMemorySectionCode = 5; // Memory attributes |
| +let kExportSectionCode = 7; // Exports |
| +let kResizableMaximumFlag = 1; |
| +let kExternalMemory = 2; |
| +function makeSig(params, results) { |
| +} |
| + { |
| + let builder = new WasmModuleBuilder(); |
| + builder.addMemory(); |
| + builder.exportMemoryAs("exported_mem"); |
| + i1 = builder.instantiate(); |
| + } |
| + { |
| + let builder = new WasmModuleBuilder(); |
| + builder.addImportedMemory("fil", "imported_mem"); |
| + i2 = builder.instantiate({fil: {imported_mem: i1.exports.exported_mem}}); |
| + } |