Home | History | Annotate | Download | only in js
      1 # Copyright 2013 the V8 project authors. All rights reserved.
      2 # Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      3 #
      4 # Redistribution and use in source and binary forms, with or without
      5 # modification, are permitted provided that the following conditions
      6 # are met:
      7 # 1.  Redistributions of source code must retain the above copyright
      8 #     notice, this list of conditions and the following disclaimer.
      9 # 2.  Redistributions in binary form must reproduce the above copyright
     10 #     notice, this list of conditions and the following disclaimer in the
     11 #     documentation and/or other materials provided with the distribution.
     12 #
     13 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
     14 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     15 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     16 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     17 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     18 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     19 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     20 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     22 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 
     24 Test some array functions on non-array objects.
     25 
     26 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     27 
     28 
     29 PASS properties(['b', 'a']) is '0:b, 1:a, length:2(DontDelete, DontEnum)'
     30 PASS properties({ length:2, 0:'b', 1:'a' }) is '0:b, 1:a, length:2'
     31 PASS properties(new OneItemConstructor) is '0:a(FromPrototype), length:1(FromPrototype)'
     32 PASS properties(new TwoItemConstructor) is '0:b(FromPrototype), 1:a(FromPrototype), length:2(FromPrototype)'
     33 PASS Array.prototype.toString.call({}) is "[object Object]"
     34 PASS Array.prototype.toString.call(new Date) is "[object Date]"
     35 PASS Array.prototype.toString.call({sort: function() { return 'sort' }}) is "[object Object]"
     36 PASS Array.prototype.toString.call({join: function() { return 'join' }}) is "join"
     37 PASS Array.prototype.toString.call({__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', length: 3}) is "a,b,c"
     38 PASS ({__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', length: 3}).toString() is "a,b,c"
     39 PASS Array.prototype.toString.call({__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', length: 3, join: function() { return 'join' }}) is "join"
     40 PASS ({__proto__: Array.prototype, 0: 'a', 1: 'b', 2: 'c', length: 3, join: function() { return 'join' }}).toString() is "join"
     41 PASS Array.prototype.toString.call(42) is "Number.prototype.join:42"
     42 PASS [0, 1, 2].toString() is "array-join"
     43 FAIL Array.prototype.toLocaleString.call({}) should throw an exception. Was .
     44 PASS Array.prototype.concat.call(x = { length:2, 0:'b', 1:'a' }) is [x]
     45 PASS Array.prototype.join.call({}) is ''
     46 PASS Array.prototype.join.call(['b', 'a']) is 'b,a'
     47 PASS Array.prototype.join.call({ length:2, 0:'b', 1:'a' }) is 'b,a'
     48 PASS Array.prototype.join.call(new TwoItemConstructor) is 'b,a'
     49 PASS Array.prototype.pop.call({}) is undefined
     50 PASS Array.prototype.pop.call({ length:2, 0:'b', 1:'a' }) is 'a'
     51 PASS Array.prototype.pop.call({ length:2, 0:'b', 1:'a' }) is 'a'
     52 PASS Array.prototype.pop.call(new TwoItemConstructor) is 'a'
     53 PASS Array.prototype.pop.call(x = {}); properties(x) is 'length:0'
     54 PASS Array.prototype.pop.call(x = ['b', 'a']); properties(x) is '0:b, length:1(DontDelete, DontEnum)'
     55 PASS Array.prototype.pop.call(x = { length:2, 0:'b', 1:'a' }); properties(x) is '0:b, length:1'
     56 PASS Array.prototype.pop.call(x = new TwoItemConstructor); properties(x) is '0:b(FromPrototype), 1:a(FromPrototype), length:1'
     57 PASS Array.prototype.push.call({}) is 0
     58 PASS Array.prototype.push.call(['b', 'a']) is 2
     59 PASS Array.prototype.push.call({ length:2, 0:'b', 1:'a' }) is 2
     60 PASS Array.prototype.push.call(new TwoItemConstructor) is 2
     61 PASS Array.prototype.push.call(x = {}); properties(x) is 'length:0'
     62 PASS Array.prototype.push.call(x = ['b', 'a']); properties(x) is '0:b, 1:a, length:2(DontDelete, DontEnum)'
     63 PASS Array.prototype.push.call(x = { length:2, 0:'b', 1:'a' }); properties(x) is '0:b, 1:a, length:2'
     64 PASS Array.prototype.push.call(x = new TwoItemConstructor); properties(x) is '0:b(FromPrototype), 1:a(FromPrototype), length:2'
     65 PASS Array.prototype.push.call({}, 'c') is 1
     66 PASS Array.prototype.push.call(['b', 'a'], 'c') is 3
     67 PASS Array.prototype.push.call({ length:2, 0:'b', 1:'a' }, 'c') is 3
     68 PASS Array.prototype.push.call(new TwoItemConstructor, 'c') is 3
     69 PASS Array.prototype.push.call(x = {}, 'c'); properties(x) is '0:c, length:1'
     70 PASS Array.prototype.push.call(x = ['b', 'a'], 'c'); properties(x) is '0:b, 1:a, 2:c, length:3(DontDelete, DontEnum)'
     71 PASS Array.prototype.push.call(x = { length:2, 0:'b', 1:'a' }, 'c'); properties(x) is '0:b, 1:a, 2:c, length:3'
     72 PASS Array.prototype.push.call(x = new TwoItemConstructor, 'c'); properties(x) is '0:b(FromPrototype), 1:a(FromPrototype), 2:c, length:3'
     73 PASS properties(Array.prototype.reverse.call({})) is ''
     74 PASS properties(Array.prototype.reverse.call(['b', 'a'])) is '0:a, 1:b, length:2(DontDelete, DontEnum)'
     75 PASS properties(Array.prototype.reverse.call({ length:2, 0:'b', 1:'a' })) is '0:a, 1:b, length:2'
     76 PASS properties(Array.prototype.reverse.call(new OneItemConstructor)) is '0:a(FromPrototype), length:1(FromPrototype)'
     77 PASS properties(Array.prototype.reverse.call(new TwoItemConstructor)) is '0:a, 1:b, length:2(FromPrototype)'
     78 PASS Array.prototype.shift.call({}) is undefined
     79 PASS Array.prototype.shift.call(['b', 'a']) is 'b'
     80 PASS Array.prototype.shift.call({ length:2, 0:'b', 1:'a' }) is 'b'
     81 PASS Array.prototype.shift.call(new TwoItemConstructor) is 'b'
     82 PASS Array.prototype.shift.call(x = {}); properties(x) is 'length:0'
     83 PASS Array.prototype.shift.call(x = ['b', 'a']); properties(x) is '0:a, length:1(DontDelete, DontEnum)'
     84 PASS Array.prototype.shift.call(x = { length:2, 0:'b', 1:'a' }); properties(x) is '0:a, length:1'
     85 PASS Array.prototype.shift.call(x = new TwoItemConstructor); properties(x) is '0:a, 1:a(FromPrototype), length:1'
     86 PASS Array.prototype.slice.call({}, 0, 1) is []
     87 PASS Array.prototype.slice.call(['b', 'a'], 0, 1) is ['b']
     88 PASS Array.prototype.slice.call({ length:2, 0:'b', 1:'a' }, 0, 1) is ['b']
     89 PASS Array.prototype.slice.call(new TwoItemConstructor, 0, 1) is ['b']
     90 PASS properties(Array.prototype.sort.call({})) is ''
     91 PASS properties(Array.prototype.sort.call(['b', 'a'])) is '0:a, 1:b, length:2(DontDelete, DontEnum)'
     92 PASS properties(Array.prototype.sort.call({ length:2, 0:'b', 1:'a' })) is '0:a, 1:b, length:2'
     93 PASS properties(Array.prototype.sort.call(new OneItemConstructor)) is '0:a(FromPrototype), length:1(FromPrototype)'
     94 PASS properties(Array.prototype.sort.call(new TwoItemConstructor)) is '0:a, 1:b, length:2(FromPrototype)'
     95 PASS Array.prototype.splice.call({}, 0, 1) is []
     96 PASS Array.prototype.splice.call(['b', 'a'], 0, 1) is ['b']
     97 PASS Array.prototype.splice.call({ length:2, 0:'b', 1:'a' }, 0, 1) is ['b']
     98 PASS Array.prototype.splice.call(new TwoItemConstructor, 0, 1) is ['b']
     99 PASS Array.prototype.splice.call(x = {}, 0, 1); properties(x) is 'length:0'
    100 PASS Array.prototype.splice.call(x = ['b', 'a'], 0, 1); properties(x) is '0:a, length:1(DontDelete, DontEnum)'
    101 PASS Array.prototype.splice.call(x = { length:2, 0:'b', 1:'a' }, 0, 1); properties(x) is '0:a, length:1'
    102 PASS Array.prototype.splice.call(x = new TwoItemConstructor, 0, 1); properties(x) is '0:a, 1:a(FromPrototype), length:1'
    103 PASS Array.prototype.unshift.call({}) is 0
    104 PASS Array.prototype.unshift.call(['b', 'a']) is 2
    105 PASS Array.prototype.unshift.call({ length:2, 0:'b', 1:'a' }) is 2
    106 PASS Array.prototype.unshift.call(new TwoItemConstructor) is 2
    107 PASS Array.prototype.unshift.call(x = {}); properties(x) is 'length:0'
    108 PASS Array.prototype.unshift.call(x = ['b', 'a']); properties(x) is '0:b, 1:a, length:2(DontDelete, DontEnum)'
    109 PASS Array.prototype.unshift.call(x = { length:2, 0:'b', 1:'a' }); properties(x) is '0:b, 1:a, length:2'
    110 PASS Array.prototype.unshift.call(x = new TwoItemConstructor); properties(x) is '0:b(FromPrototype), 1:a(FromPrototype), length:2'
    111 PASS Array.prototype.unshift.call({}, 'c') is 1
    112 PASS Array.prototype.unshift.call(['b', 'a'], 'c') is 3
    113 PASS Array.prototype.unshift.call({ length:2, 0:'b', 1:'a' }, 'c') is 3
    114 PASS Array.prototype.unshift.call(new TwoItemConstructor, 'c') is 3
    115 PASS Array.prototype.unshift.call(x = {}, 'c'); properties(x) is '0:c, length:1'
    116 PASS Array.prototype.unshift.call(x = ['b', 'a'], 'c'); properties(x) is '0:c, 1:b, 2:a, length:3(DontDelete, DontEnum)'
    117 PASS Array.prototype.unshift.call(x = { length:2, 0:'b', 1:'a' }, 'c'); properties(x) is '0:c, 1:b, 2:a, length:3'
    118 PASS Array.prototype.unshift.call(x = new TwoItemConstructor, 'c'); properties(x) is '0:c, 1:b, 2:a, length:3'
    119 PASS successfullyParsed is true
    120 
    121 TEST COMPLETE
    122 
    123