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

Side by Side Diff: test/mjsunit/harmony/atomics.js

Issue 2814753003: [SAB] Validate index before value conversion (Closed)
Patch Set: feedback Created 3 years, 8 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/compiler/ia32/instruction-selector-ia32.cc ('k') | test/test262/test262.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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: --harmony-sharedarraybuffer 5 // Flags: --harmony-sharedarraybuffer
6 // 6 //
7 7
8 function toRangeWrapped(value) { 8 function toRangeWrapped(value) {
9 var range = this.max - this.min + 1; 9 var range = this.max - this.min + 1;
10 while (value < this.min) { 10 while (value < this.min) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 assertThrows(function() { Atomics.xor(o, 0, 0); }, TypeError); 55 assertThrows(function() { Atomics.xor(o, 0, 0); }, TypeError);
56 assertThrows(function() { Atomics.exchange(o, 0, 0); }, TypeError); 56 assertThrows(function() { Atomics.exchange(o, 0, 0); }, TypeError);
57 }); 57 });
58 })(); 58 })();
59 59
60 (function TestBadIndex() { 60 (function TestBadIndex() {
61 var sab = new SharedArrayBuffer(8); 61 var sab = new SharedArrayBuffer(8);
62 var si32a = new Int32Array(sab); 62 var si32a = new Int32Array(sab);
63 var si32a2 = new Int32Array(sab, 4); 63 var si32a2 = new Int32Array(sab, 4);
64 64
65 // Non-integer indexes should throw RangeError. 65 // Indexes that are out of bounds when coerced via ToIndex should throw
66 var nonInteger = [1.4, '1.4', NaN, -Infinity, Infinity, undefined, 'hi', {}]; 66 // RangeError.
67 nonInteger.forEach(function(i) { 67 [-Infinity, Infinity].forEach(function(i) {
68 assertThrows(function() { Atomics.compareExchange(si32a, i, 0); }, 68 assertThrows(function() { Atomics.compareExchange(si32a, i, 0); },
69 RangeError); 69 RangeError);
70 assertThrows(function() { Atomics.load(si32a, i, 0); }, RangeError); 70 assertThrows(function() { Atomics.load(si32a, i, 0); }, RangeError);
71 assertThrows(function() { Atomics.store(si32a, i, 0); }, RangeError); 71 assertThrows(function() { Atomics.store(si32a, i, 0); }, RangeError);
72 assertThrows(function() { Atomics.add(si32a, i, 0); }, RangeError); 72 assertThrows(function() { Atomics.add(si32a, i, 0); }, RangeError);
73 assertThrows(function() { Atomics.sub(si32a, i, 0); }, RangeError); 73 assertThrows(function() { Atomics.sub(si32a, i, 0); }, RangeError);
74 assertThrows(function() { Atomics.and(si32a, i, 0); }, RangeError); 74 assertThrows(function() { Atomics.and(si32a, i, 0); }, RangeError);
75 assertThrows(function() { Atomics.or(si32a, i, 0); }, RangeError); 75 assertThrows(function() { Atomics.or(si32a, i, 0); }, RangeError);
76 assertThrows(function() { Atomics.xor(si32a, i, 0); }, RangeError); 76 assertThrows(function() { Atomics.xor(si32a, i, 0); }, RangeError);
77 assertThrows(function() { Atomics.exchange(si32a, i, 0); }, RangeError); 77 assertThrows(function() { Atomics.exchange(si32a, i, 0); }, RangeError);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 assertEquals(0, result, name); 133 assertEquals(0, result, name);
134 assertEquals(0, ia[expectedIndex], name); 134 assertEquals(0, ia[expectedIndex], name);
135 135
136 for (var i = 0; i < ia.length; ++i) { 136 for (var i = 0; i < ia.length; ++i) {
137 if (i == expectedIndex) continue; 137 if (i == expectedIndex) continue;
138 assertEquals(i * 2, ia[i], name); 138 assertEquals(i * 2, ia[i], name);
139 } 139 }
140 }; 140 };
141 141
142 // These values all map to index 0 142 // These values all map to index 0
143 [-0, 0, 0.0, null, false].forEach(function(i) { 143 [-0, 0, 0.0, null, false, NaN, {}, '0.2', 'hi', undefined].forEach(
144 function(i) {
144 var name = String(i); 145 var name = String(i);
145 [si32a, si32a2].forEach(function(array) { 146 [si32a, si32a2].forEach(function(array) {
146 testOp(Atomics.compareExchange, array, i, 0, name); 147 testOp(Atomics.compareExchange, array, i, 0, name);
147 testOp(Atomics.load, array, i, 0, name); 148 testOp(Atomics.load, array, i, 0, name);
148 testOp(Atomics.store, array, i, 0, name); 149 testOp(Atomics.store, array, i, 0, name);
149 testOp(Atomics.add, array, i, 0, name); 150 testOp(Atomics.add, array, i, 0, name);
150 testOp(Atomics.sub, array, i, 0, name); 151 testOp(Atomics.sub, array, i, 0, name);
151 testOp(Atomics.and, array, i, 0, name); 152 testOp(Atomics.and, array, i, 0, name);
152 testOp(Atomics.or, array, i, 0, name); 153 testOp(Atomics.or, array, i, 0, name);
153 testOp(Atomics.xor, array, i, 0, name); 154 testOp(Atomics.xor, array, i, 0, name);
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // Exchange 558 // Exchange
558 sta[0] = val = 0x12; 559 sta[0] = val = 0x12;
559 operand = 0x22 + offset; 560 operand = 0x22 + offset;
560 valWrapped = t.toRange(operand); 561 valWrapped = t.toRange(operand);
561 assertEquals(val, Atomics.exchange(sta, 0, operand), name); 562 assertEquals(val, Atomics.exchange(sta, 0, operand), name);
562 assertEquals(valWrapped, sta[0], name); 563 assertEquals(valWrapped, sta[0], name);
563 } 564 }
564 565
565 }); 566 });
566 })(); 567 })();
568
569 (function TestValidateIndexBeforeValue() {
570 var testOp = function(op, sta, name) {
571 var valueof_has_been_called = 0;
572 var value = {valueOf: function() { valueof_has_been_called = 1; return 0;}};
573 var index = -1;
574
575 // The index should be checked before calling ToInteger on the value, so
576 // valueof_has_been_called should not be modified.
577 sta[0] = 0;
578 assertThrows(function() { op(sta, index, value, value); }, RangeError);
579 assertEquals(0, valueof_has_been_called);
580 };
581
582 IntegerTypedArrayConstructors.forEach(function(t) {
583 var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT);
584 var sta = new t.constr(sab);
585 var name = Object.prototype.toString.call(sta);
586
587 testOp(Atomics.compareExchange, sta, name);
588 testOp(Atomics.load, sta, name);
589 testOp(Atomics.store, sta, name);
590 testOp(Atomics.add, sta, name);
591 testOp(Atomics.sub, sta, name);
592 testOp(Atomics.and, sta, name);
593 testOp(Atomics.or, sta, name);
594 testOp(Atomics.xor, sta, name);
595 testOp(Atomics.exchange, sta, name);
596 });
597 })();
OLDNEW
« no previous file with comments | « src/compiler/ia32/instruction-selector-ia32.cc ('k') | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698