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

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

Issue 1500543002: [es6] Unify ArrayBuffer and SharedArrayBuffer constructors. (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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 22 matching lines...) Expand all
33 function TestByteLength(param, expectedByteLength) { 33 function TestByteLength(param, expectedByteLength) {
34 var sab = new SharedArrayBuffer(param); 34 var sab = new SharedArrayBuffer(param);
35 assertSame(expectedByteLength, sab.byteLength); 35 assertSame(expectedByteLength, sab.byteLength);
36 } 36 }
37 37
38 function TestArrayBufferCreation() { 38 function TestArrayBufferCreation() {
39 TestByteLength(1, 1); 39 TestByteLength(1, 1);
40 TestByteLength(256, 256); 40 TestByteLength(256, 256);
41 TestByteLength(2.567, 2); 41 TestByteLength(2.567, 2);
42 42
43 TestByteLength("abc", 0); 43 TestByteLength("0", 0);
44 44
45 TestByteLength(0, 0); 45 TestByteLength(0, 0);
46 46
47 assertThrows(function() { new SharedArrayBuffer(-10); }, RangeError); 47 assertThrows(function() { new SharedArrayBuffer(-10); }, RangeError);
48 assertThrows(function() { new SharedArrayBuffer(-2.567); }, RangeError); 48 assertThrows(function() { new SharedArrayBuffer(-2.567); }, RangeError);
49 49
50 /* TODO[dslomov]: Reenable the test 50 /* TODO[dslomov]: Reenable the test
51 assertThrows(function() { 51 assertThrows(function() {
52 var ab1 = new SharedArrayBuffer(0xFFFFFFFFFFFF) 52 var ab1 = new SharedArrayBuffer(0xFFFFFFFFFFFF)
53 }, RangeError); 53 }, RangeError);
54 */ 54 */
55 55
56 var sab = new SharedArrayBuffer(); 56 var sab = new SharedArrayBuffer(0);
57 assertSame(0, sab.byteLength); 57 assertSame(0, sab.byteLength);
58 assertEquals("[object SharedArrayBuffer]", 58 assertEquals("[object SharedArrayBuffer]",
59 Object.prototype.toString.call(sab)); 59 Object.prototype.toString.call(sab));
60 } 60 }
61 61
62 TestArrayBufferCreation(); 62 TestArrayBufferCreation();
63 63
64 function TestByteLengthNotWritable() { 64 function TestByteLengthNotWritable() {
65 var sab = new SharedArrayBuffer(1024); 65 var sab = new SharedArrayBuffer(1024);
66 assertSame(1024, sab.byteLength); 66 assertSame(1024, sab.byteLength);
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 function props(x) { 541 function props(x) {
542 var array = []; 542 var array = [];
543 for (var p in x) array.push(p); 543 for (var p in x) array.push(p);
544 return array.sort(); 544 return array.sort();
545 } 545 }
546 assertArrayEquals([], props(func)); 546 assertArrayEquals([], props(func));
547 assertArrayEquals([], props(func.prototype)); 547 assertArrayEquals([], props(func.prototype));
548 if (obj) 548 if (obj)
549 assertArrayEquals([], props(obj)); 549 assertArrayEquals([], props(obj));
550 } 550 }
551 TestEnumerable(ArrayBuffer, new SharedArrayBuffer()); 551 TestEnumerable(ArrayBuffer, new SharedArrayBuffer(0));
552 for(i = 0; i < typedArrayConstructors.length; i++) { 552 for(i = 0; i < typedArrayConstructors.length; i++) {
553 TestEnumerable(typedArrayConstructors[i]); 553 TestEnumerable(typedArrayConstructors[i]);
554 } 554 }
555 555
556 // Test arbitrary properties on ArrayBuffer 556 // Test arbitrary properties on ArrayBuffer
557 function TestArbitrary(m) { 557 function TestArbitrary(m) {
558 function TestProperty(map, property, value) { 558 function TestProperty(map, property, value) {
559 map[property] = value; 559 map[property] = value;
560 assertEquals(value, map[property]); 560 assertEquals(value, map[property]);
561 } 561 }
562 for (var i = 0; i < 20; i++) { 562 for (var i = 0; i < 20; i++) {
563 TestProperty(m, 'key' + i, 'val' + i); 563 TestProperty(m, 'key' + i, 'val' + i);
564 TestProperty(m, 'foo' + i, 'bar' + i); 564 TestProperty(m, 'foo' + i, 'bar' + i);
565 } 565 }
566 } 566 }
567 TestArbitrary(new SharedArrayBuffer(256)); 567 TestArbitrary(new SharedArrayBuffer(256));
568 for(i = 0; i < typedArrayConstructors.length; i++) { 568 for(i = 0; i < typedArrayConstructors.length; i++) {
569 TestArbitrary(MakeSharedTypedArray(typedArrayConstructors[i], 10)); 569 TestArbitrary(MakeSharedTypedArray(typedArrayConstructors[i], 10));
570 } 570 }
571 571
572 // Test direct constructor call 572 // Test direct constructor call
573 assertThrows(function() { SharedArrayBuffer(); }, TypeError); 573 assertThrows(function() { SharedArrayBuffer(); }, TypeError);
574 for(i = 0; i < typedArrayConstructors.length; i++) { 574 for(i = 0; i < typedArrayConstructors.length; i++) {
575 assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i), 575 assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i),
576 TypeError); 576 TypeError);
577 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698