Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: test/mjsunit/wasm/calls.js

Issue 1504713014: Initial import of v8-native WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/asm-wasm.js ('k') | test/mjsunit/wasm/compile-run-basic.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 load("test/mjsunit/wasm/wasm-constants.js");
6
7 var module = (function () {
8 var kBodySize = 5;
9 var kNameOffset = 21 + kBodySize + 1;
10
11 return WASM.instantiateModule(bytes(
12 // -- memory
13 kDeclMemory,
14 12, 12, 1,
15 // -- signatures
16 kDeclSignatures, 1,
17 2, kAstI32, kAstI32, kAstI32, // int, int -> int
18 // -- functions
19 kDeclFunctions, 1,
20 kDeclFunctionName | kDeclFunctionExport,
21 0, 0,
22 kNameOffset, 0, 0, 0, // name offset
23 kBodySize, 0,
24 // -- body
25 kExprI32Sub, // --
26 kExprGetLocal, 0, // --
27 kExprGetLocal, 1, // --
28 kDeclEnd,
29 's', 'u', 'b', 0 // name
30 ));
31 })();
32
33 // Check the module exists.
34 assertFalse(module === undefined);
35 assertFalse(module === null);
36 assertFalse(module === 0);
37 assertEquals("object", typeof module);
38
39 // Check the memory is an ArrayBuffer.
40 var mem = module.memory;
41 assertFalse(mem === undefined);
42 assertFalse(mem === null);
43 assertFalse(mem === 0);
44 assertEquals("object", typeof mem);
45 assertTrue(mem instanceof ArrayBuffer);
46 for (var i = 0; i < 4; i++) {
47 module.memory = 0; // should be ignored
48 assertEquals(mem, module.memory);
49 }
50
51 assertEquals(4096, module.memory.byteLength);
52
53 // Check the properties of the sub function.
54 assertEquals("function", typeof module.sub);
55
56 assertEquals(-55, module.sub(33, 88));
57 assertEquals(-55555, module.sub(33333, 88888));
58 assertEquals(-5555555, module.sub(3333333, 8888888));
59
60
61 var module = (function() {
62 var kBodySize = 1;
63 var kNameOffset2 = 19 + kBodySize + 1;
64
65 return WASM.instantiateModule(bytes(
66 // -- memory
67 kDeclMemory,
68 12, 12, 1,
69 // -- signatures
70 kDeclSignatures, 1,
71 0, kAstStmt, // signature: void -> void
72 // -- functions
73 kDeclFunctions, 1,
74 kDeclFunctionName | kDeclFunctionExport,
75 0, 0, // signature index
76 kNameOffset2, 0, 0, 0, // name offset
77 kBodySize, 0,
78 kExprNop, // body
79 kDeclEnd,
80 'n', 'o', 'p', 0 // name
81 ));
82 })();
83
84 // Check the module exists.
85 assertFalse(module === undefined);
86 assertFalse(module === null);
87 assertFalse(module === 0);
88 assertEquals("object", typeof module);
89
90 // Check the memory is an ArrayBuffer.
91 var mem = module.memory;
92 assertFalse(mem === undefined);
93 assertFalse(mem === null);
94 assertFalse(mem === 0);
95 assertEquals("object", typeof mem);
96 assertTrue(mem instanceof ArrayBuffer);
97 for (var i = 0; i < 4; i++) {
98 module.memory = 0; // should be ignored
99 assertEquals(mem, module.memory);
100 }
101
102 assertEquals(4096, module.memory.byteLength);
103
104 // Check the properties of the sub function.
105 assertFalse(module.nop === undefined);
106 assertFalse(module.nop === null);
107 assertFalse(module.nop === 0);
108 assertEquals("function", typeof module.nop);
109
110 assertEquals(undefined, module.nop());
111
112 (function testLt() {
113 var kBodySize = 5;
114 var kNameOffset = 21 + kBodySize + 1;
115
116 var data = bytes(
117 // -- memory
118 kDeclMemory,
119 12, 12, 1,
120 // -- signatures
121 kDeclSignatures, 1,
122 2, kAstI32, kAstF64, kAstF64, // (f64,f64)->int
123 // -- functions
124 kDeclFunctions, 1,
125 kDeclFunctionName | kDeclFunctionExport,
126 0, 0, // signature index
127 kNameOffset, 0, 0, 0, // name offset
128 kBodySize, 0,
129 // -- body
130 kExprF64Lt, // --
131 kExprGetLocal, 0, // --
132 kExprGetLocal, 1, // --
133 kDeclEnd,
134 'f', 'l', 't', 0 // name
135 );
136
137 var module = WASM.instantiateModule(data);
138
139 assertEquals("function", typeof module.flt);
140 assertEquals(1, module.flt(-2, -1));
141 assertEquals(0, module.flt(7.3, 7.1));
142 assertEquals(1, module.flt(7.1, 7.3));
143 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/asm-wasm.js ('k') | test/mjsunit/wasm/compile-run-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698