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

Side by Side Diff: test/mjsunit/wasm/asm-wasm.js

Issue 1677373002: Adding support for asm.js foreign globals. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 4 years, 10 months 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 | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 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 function EmptyTest() { 7 function EmptyTest() {
8 "use asm"; 8 "use asm";
9 function caller() { 9 function caller() {
10 empty(); 10 empty();
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 var foreign = new ffi(); 1073 var foreign = new ffi();
1074 1074
1075 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), 1075 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(),
1076 foreign, null); 1076 foreign, null);
1077 1077
1078 module.__init__(); 1078 module.__init__();
1079 assertEquals(89, module.caller(83, 83.25)); 1079 assertEquals(89, module.caller(83, 83.25));
1080 } 1080 }
1081 1081
1082 TestForeignFunctionMultipleUse(); 1082 TestForeignFunctionMultipleUse();
1083
1084
1085 function TestForeignVariables() {
1086 function AsmModule(stdlib, foreign, buffer) {
1087 "use asm";
1088
1089 var i1 = foreign.foo | 0;
1090 var f1 = +foreign.bar;
1091 var i2 = foreign.baz | 0;
1092 var f2 = +foreign.baz;
1093
1094 function geti1() {
1095 return i1|0;
1096 }
1097
1098 function getf1() {
1099 return +f1;
1100 }
1101
1102 function geti2() {
1103 return i2|0;
1104 }
1105
1106 function getf2() {
1107 return +f2;
1108 }
1109
1110 return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2};
1111 }
1112
1113 function TestCase(env, i1, f1, i2, f2) {
1114 var module = _WASMEXP_.instantiateModuleFromAsm(
1115 AsmModule.toString(), env);
1116 module.__init__();
1117 assertEquals(i1, module.geti1());
1118 assertEquals(f1, module.getf1());
1119 assertEquals(i2, module.geti2());
1120 assertEquals(f2, module.getf2());
1121 }
1122
1123 // Check normal operation.
1124 TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7);
1125 // Check partial operation.
1126 TestCase({baz: 345.7}, 0, NaN, 345, 345.7);
1127 // Check that undefined values are converted to proper defaults.
1128 TestCase({qux: 999}, 0, NaN, 0, NaN);
1129 // Check that an undefined ffi is ok.
1130 TestCase(undefined, 0, NaN, 0, NaN);
1131 // Check that true values are converted properly.
1132 TestCase({foo: true, bar: true, baz: true}, 1, 1.0, 1, 1.0);
1133 // Check that false values are converted properly.
1134 TestCase({foo: false, bar: false, baz: false}, 0, 0, 0, 0);
1135 // Check that null values are converted properly.
1136 TestCase({foo: null, bar: null, baz: null}, 0, 0, 0, 0);
1137 // Check that string values are converted properly.
1138 TestCase({foo: 'hi', bar: 'there', baz: 'dude'}, 0, NaN, 0, NaN);
1139 TestCase({foo: '0xff', bar: '234', baz: '456.1'}, 255, 234, 456, 456.1, 456);
1140 // Check that Date values are converted properly.
1141 TestCase({foo: new Date(123), bar: new Date(456),
1142 baz: new Date(789)}, 123, 456, 789, 789);
1143 // Check that list values are converted properly.
1144 TestCase({foo: [], bar: [], baz: []}, 0, 0, 0, 0);
1145 // Check that object values are converted properly.
1146 TestCase({foo: {}, bar: {}, baz: {}}, 0, NaN, 0, NaN);
1147 // Check that getter object values are converted properly.
1148 var o = {
1149 get foo() {
1150 return 123.4;
1151 }
1152 };
1153 TestCase({foo: o.foo, bar: o.foo, baz: o.foo}, 123, 123.4, 123, 123.4);
1154 // Check that getter object values are converted properly.
1155 var o = {
1156 get baz() {
1157 return 123.4;
1158 }
1159 };
1160 TestCase(o, 0, NaN, 123, 123.4);
1161 // Check that objects with valueOf are converted properly.
1162 var o = {
1163 valueOf: function() { return 99; }
1164 };
1165 TestCase({foo: o, bar: o, baz: o}, 99, 99, 99, 99);
1166 // Check that function values are converted properly.
1167 TestCase({foo: TestCase, bar: TestCase, qux: TestCase}, 0, NaN, 0, NaN);
1168 // Check that a missing ffi object is safe.
1169 TestCase(undefined, 0, NaN, 0, NaN);
1170 }
1171
1172 TestForeignVariables();
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698