Debian Codegraph @

rhino/testsrc/jstests/harmony/typed-array-slice.js

raw symbols SCIP
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 // Flags: --allow-natives-syntax
29
30 // This is a regression test for overlapping key and value registers.
31
32 load("testsrc/assert.js");
33
34 function assertSame(expected, found, name_opt) {
35 if (found === expected) {
36 if (expected !== 0 || (1 / expected) == (1 / found)) return;
37 } else if ((expected !== expected) && (found !== found)) {
38 return;
39 }
40 var msg = 'expected ' + expected + ' != ' + found;
41 if (name_opt) {
42 msg += ' ' + name_opt;
43 }
44 throw new Error(msg);
45 }
46
47 function assertEquals(expected, found, name_opt) {
48 assertSame(expected, found, name_opt);
49 }
50
51 var types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array,
52 Int32Array, Uint32Array, Uint8ClampedArray, Float32Array,
53 Float64Array];
54
55 var results1 = [-2, -2, 254, -2, 65534, -2, 4294967294, 0, -2, -2];
56 var results2 = [undefined, -1, 255, -1, 65535, -1, 4294967295, 0, -1, -1];
57 var results3 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
58 var results4 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
59
60 const kElementCount = 40;
61
62 function do_slice(a) {
63 return Array.prototype.slice.call(a, 4, 8);
64 }
65
66 for (var t = 0; t < types.length; t++) {
67 var type = types[t];
68 var a = new type(kElementCount);
69 for (var i = 0; i < kElementCount; ++i ) {
70 a[i] = i-6;
71 }
72 delete a[5];
73 var sliced = do_slice(a);
74
75 //%ClearFunctionTypeFeedback(do_slice);
76 assertEquals(results1[t], sliced[0]);
77 assertEquals(results2[t], sliced[1]);
78 assertEquals(results3[t], sliced[2]);
79 assertEquals(results4[t], sliced[3]);
80 }
81
82 "success";