2014-04-23 12:48:32 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Test that Array builtins can be called on primitive values.
|
|
|
|
var values = [ 23, 4.2, true, false, 0/0 ];
|
|
|
|
for (var i = 0; i < values.length; ++i) {
|
|
|
|
var v = values[i];
|
2014-04-30 08:52:00 +00:00
|
|
|
Array.prototype.join.call(v);
|
2014-04-23 12:48:32 +00:00
|
|
|
Array.prototype.pop.call(v);
|
|
|
|
Array.prototype.push.call(v);
|
2014-04-30 08:52:00 +00:00
|
|
|
Array.prototype.reverse.call(v);
|
2014-04-23 12:48:32 +00:00
|
|
|
Array.prototype.shift.call(v);
|
2014-04-30 08:52:00 +00:00
|
|
|
Array.prototype.slice.call(v);
|
|
|
|
Array.prototype.splice.call(v);
|
2014-04-23 12:48:32 +00:00
|
|
|
Array.prototype.unshift.call(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that ToObject on primitive values is only called once.
|
|
|
|
var length_receiver, element_receiver;
|
2014-04-30 08:52:00 +00:00
|
|
|
function length() { length_receiver = this; return 2; }
|
2014-04-23 12:48:32 +00:00
|
|
|
function element() { element_receiver = this; return "x"; }
|
|
|
|
Object.defineProperty(Number.prototype, "length", { get:length, set:length });
|
|
|
|
Object.defineProperty(Number.prototype, "0", { get:element, set:element });
|
|
|
|
Object.defineProperty(Number.prototype, "1", { get:element, set:element });
|
2014-04-30 08:52:00 +00:00
|
|
|
Object.defineProperty(Number.prototype, "2", { get:element, set:element });
|
|
|
|
function test_receiver(expected, call_string) {
|
|
|
|
assertDoesNotThrow(call_string);
|
|
|
|
assertEquals(new Number(expected), length_receiver);
|
|
|
|
assertSame(length_receiver, element_receiver);
|
|
|
|
}
|
2014-04-23 12:48:32 +00:00
|
|
|
|
2014-04-30 08:52:00 +00:00
|
|
|
test_receiver(11, "Array.prototype.join.call(11)")
|
|
|
|
test_receiver(23, "Array.prototype.pop.call(23)");
|
|
|
|
test_receiver(42, "Array.prototype.push.call(42, 'y')");
|
|
|
|
test_receiver(49, "Array.prototype.reverse.call(49)");
|
|
|
|
test_receiver(65, "Array.prototype.shift.call(65)");
|
|
|
|
test_receiver(77, "Array.prototype.slice.call(77, 1)");
|
|
|
|
test_receiver(88, "Array.prototype.splice.call(88, 1, 1)");
|
|
|
|
test_receiver(99, "Array.prototype.unshift.call(99, 'z')");
|