|
| 1 | +// Copyright JS Foundation and other contributors, http://js.foundation |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +var normal_typedarrays = [ |
| 16 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 17 | + new Uint16Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 18 | + new Uint32Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 19 | + new Float32Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 20 | + new Float64Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 21 | + new Int8Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 22 | + new Int16Array([1, 2, 3, 4, 5, 6, 7, 8]), |
| 23 | + new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]) |
| 24 | +]; |
| 25 | + |
| 26 | +normal_typedarrays.forEach (function(e){ |
| 27 | + try { |
| 28 | + e.prototype.values.call (undefined); |
| 29 | + assert (false); |
| 30 | + } |
| 31 | + catch (e) { |
| 32 | + assert (e instanceof TypeError) |
| 33 | + } |
| 34 | +}); |
| 35 | + |
| 36 | +normal_typedarrays.forEach(function (e){ |
| 37 | + var iterator = e.values (); |
| 38 | + var symbol_iterator = e[Symbol.iterator] (); |
| 39 | + |
| 40 | + var current_item = iterator.next (); |
| 41 | + var symbol_current_item = symbol_iterator.next (); |
| 42 | + |
| 43 | + for (var i = 0; i < e.length; i++) { |
| 44 | + assert (current_item.value === e[i]); |
| 45 | + assert (current_item.done === false); |
| 46 | + |
| 47 | + assert (current_item.value === symbol_current_item.value); |
| 48 | + assert (current_item.done === symbol_current_item.done); |
| 49 | + |
| 50 | + current_item = iterator.next (); |
| 51 | + symbol_current_item = symbol_iterator.next (); |
| 52 | + } |
| 53 | + |
| 54 | + assert (current_item.value === undefined); |
| 55 | + assert (current_item.done === true); |
| 56 | + assert (current_item.value === symbol_current_item.value); |
| 57 | + assert (current_item.done === symbol_current_item.done) |
| 58 | +}); |
| 59 | + |
| 60 | +var empty_typedarrays = [ |
| 61 | + new Uint8Array([]), |
| 62 | + new Uint16Array([]), |
| 63 | + new Uint32Array([]), |
| 64 | + new Float32Array([]), |
| 65 | + new Float64Array([]), |
| 66 | + new Int8Array([]), |
| 67 | + new Int16Array([]), |
| 68 | + new Int32Array([]) |
| 69 | +]; |
| 70 | + |
| 71 | +empty_typedarrays.forEach(function (e){ |
| 72 | + iterator = e.values (); |
| 73 | + current_item = iterator.next (); |
| 74 | + |
| 75 | + assert (current_item.value === undefined); |
| 76 | + assert (current_item.done === true); |
| 77 | +}); |
| 78 | + |
| 79 | +assert ([].values ().toString () === "[object Array Iterator]"); |
0 commit comments