Home | History | Annotate | Download | only in regress
      1 // Copyright 2014 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Test that Array builtins can be called on primitive values.
      6 var values = [ 23, 4.2, true, false, 0/0 ];
      7 for (var i = 0; i < values.length; ++i) {
      8   var v = values[i];
      9   Array.prototype.join.call(v);
     10   Array.prototype.pop.call(v);
     11   Array.prototype.push.call(v);
     12   Array.prototype.reverse.call(v);
     13   Array.prototype.shift.call(v);
     14   Array.prototype.slice.call(v);
     15   Array.prototype.splice.call(v);
     16   Array.prototype.unshift.call(v);
     17 }
     18 
     19 // Test that ToObject on primitive values is only called once.
     20 var length_receiver, element_receiver;
     21 function length() { length_receiver = this; return 2; }
     22 function element() { element_receiver = this; return "x"; }
     23 Object.defineProperty(Number.prototype, "length", { get:length, set:length });
     24 Object.defineProperty(Number.prototype, "0", { get:element, set:element });
     25 Object.defineProperty(Number.prototype, "1", { get:element, set:element });
     26 Object.defineProperty(Number.prototype, "2", { get:element, set:element });
     27 function test_receiver(expected, call_string) {
     28   assertDoesNotThrow(call_string);
     29   assertEquals(new Number(expected), length_receiver);
     30   assertSame(length_receiver, element_receiver);
     31 }
     32 
     33 test_receiver(11, "Array.prototype.join.call(11)")
     34 test_receiver(23, "Array.prototype.pop.call(23)");
     35 test_receiver(42, "Array.prototype.push.call(42, 'y')");
     36 test_receiver(49, "Array.prototype.reverse.call(49)");
     37 test_receiver(65, "Array.prototype.shift.call(65)");
     38 test_receiver(77, "Array.prototype.slice.call(77, 1)");
     39 test_receiver(88, "Array.prototype.splice.call(88, 1, 1)");
     40 test_receiver(99, "Array.prototype.unshift.call(99, 'z')");
     41