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

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

Issue 21924007: Make new Harmony constructors subclassing-friendly (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/harmony/collections.js ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // Flags: --allow-natives-syntax
27 29
28 // ArrayBuffer 30 // ArrayBuffer
29 31
30 function TestByteLength(param, expectedByteLength) { 32 function TestByteLength(param, expectedByteLength) {
31 var ab = new ArrayBuffer(param); 33 var ab = new ArrayBuffer(param);
32 assertSame(expectedByteLength, ab.byteLength); 34 assertSame(expectedByteLength, ab.byteLength);
33 } 35 }
34 36
35 function TestArrayBufferCreation() { 37 function TestArrayBufferCreation() {
36 TestByteLength(1, 1); 38 TestByteLength(1, 1);
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 assertArrayEquals([], props(func.prototype)); 554 assertArrayEquals([], props(func.prototype));
553 if (obj) 555 if (obj)
554 assertArrayEquals([], props(obj)); 556 assertArrayEquals([], props(obj));
555 } 557 }
556 TestEnumerable(ArrayBuffer, new ArrayBuffer()); 558 TestEnumerable(ArrayBuffer, new ArrayBuffer());
557 for(i = 0; i < typedArrayConstructors.lenght; i++) { 559 for(i = 0; i < typedArrayConstructors.lenght; i++) {
558 TestEnumerable(typedArrayConstructors[i]); 560 TestEnumerable(typedArrayConstructors[i]);
559 } 561 }
560 TestEnumerable(DataView, new DataView(new ArrayBuffer())); 562 TestEnumerable(DataView, new DataView(new ArrayBuffer()));
561 563
562 // Test arbitrary properties on ArrayBuffer 564 // Test arbitrary properties on ArrayBuffer and DataView
563 function TestArbitrary(m) { 565 function TestArbitrary(m) {
564 function TestProperty(map, property, value) { 566 function TestProperty(map, property, value) {
565 map[property] = value; 567 map[property] = value;
566 assertEquals(value, map[property]); 568 assertEquals(value, map[property]);
567 } 569 }
568 for (var i = 0; i < 20; i++) { 570 for (var i = 0; i < 20; i++) {
569 TestProperty(m, i, 'val' + i); 571 TestProperty(m, i, 'val' + i);
570 TestProperty(m, 'foo' + i, 'bar' + i); 572 TestProperty(m, 'foo' + i, 'bar' + i);
571 } 573 }
572 } 574 }
573 TestArbitrary(new ArrayBuffer(256)); 575 TestArbitrary(new ArrayBuffer(256));
574 for(i = 0; i < typedArrayConstructors.lenght; i++) { 576 TestArbitrary(new DataView(new ArrayBuffer(256)));
575 TestArbitary(new typedArrayConstructors[i](10)); 577
578 // Test arbitrary properties on TypedArrays
579 function TestArbitraryNonIndexed(m) {
580 function TestProperty(map, property, value) {
581 map[property] = value;
582 assertEquals(value, map[property]);
583 }
584 for (var i = 0; i < 20; i++) {
585 TestProperty(m, 'foo' + i, 'bar' + i);
586 }
576 } 587 }
577 TestArbitrary(new DataView(new ArrayBuffer(256))); 588 for(i = 0; i < typedArrayConstructors.length; i++) {
589 TestArbitraryNonIndexed(new typedArrayConstructors[i](10));
590 }
578 591
579 592
580 // Test direct constructor call 593 // Test direct constructor call
581 assertThrows(function() { ArrayBuffer(); }, TypeError); 594 assertThrows(function() { ArrayBuffer(); }, TypeError);
582 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); 595 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError);
596
597 // Test that constructor can be called only on appropriate objects only once.
598 function TestConstructorBehavior(C) {
599 var obj = new C();
600 assertThrows(function() { C.call(obj); }, TypeError);
601 assertThrows(function() { C.call({}); }, TypeError);
602 var uninitObj = %NewObject(C);
603 C.call(uninitObj); // shouldn't throw
604 }
605
606 TestConstructorBehavior(ArrayBuffer);
607 for(i = 0; i < typedArrayConstructors.length; i++) {
608 TestConstructorBehavior(typedArrayConstructors[i]);
609 }
610
611
612 // Test that DataView constructor can be called only on appropriate objects
613 // only once.
614 function TestDataViewConstructorBehavior() {
615 var ab = new ArrayBuffer(100);
616 var obj = new DataView(ab);
617 assertThrows(function() { DataView.call(obj, ab); }, TypeError);
618 assertThrows(function() { DataView.call({}, ab); }, TypeError);
619 var uninitObj = %NewObject(DataView);
620 DataView.call(uninitObj, ab); // shouldn't throw
621 }
622 TestDataViewConstructorBehavior();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/collections.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698