2017-04-26 17:36:32 +00:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
|
|
|
// Flags: --allow-natives-syntax
|
|
|
|
|
|
|
|
// Test Array call with known Boolean.
|
|
|
|
(() => {
|
|
|
|
function foo(x) { return Array(!!x); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals([true], foo(true));
|
|
|
|
assertEquals([false], foo(false));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([true], foo(true));
|
|
|
|
assertEquals([false], foo(false));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Array construct with known Boolean.
|
|
|
|
(() => {
|
|
|
|
function foo(x) { return new Array(!!x); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals([true], foo(true));
|
|
|
|
assertEquals([false], foo(false));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([true], foo(true));
|
|
|
|
assertEquals([false], foo(false));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Array call with known String.
|
|
|
|
(() => {
|
|
|
|
function foo(x) { return Array("" + x); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals(["a"], foo("a"));
|
|
|
|
assertEquals(["b"], foo("b"));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals(["a"], foo("a"));
|
|
|
|
assertEquals(["b"], foo("b"));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Array construct with known String.
|
|
|
|
(() => {
|
|
|
|
function foo(x) { return new Array("" + x); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals(["a"], foo("a"));
|
|
|
|
assertEquals(["b"], foo("b"));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals(["a"], foo("a"));
|
|
|
|
assertEquals(["b"], foo("b"));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Array call with known fixed small integer.
|
|
|
|
(() => {
|
|
|
|
function foo() { return Array(2); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals(2, foo().length);
|
|
|
|
assertEquals(2, foo().length);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals(2, foo().length);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Array construct with known fixed small integer.
|
|
|
|
(() => {
|
|
|
|
function foo() { return new Array(2); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals(2, foo().length);
|
|
|
|
assertEquals(2, foo().length);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals(2, foo().length);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Array call with multiple parameters.
|
|
|
|
(() => {
|
|
|
|
function foo(x, y, z) { return Array(x, y, z); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Array construct with multiple parameters.
|
|
|
|
(() => {
|
|
|
|
function foo(x, y, z) { return new Array(x, y, z); }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-04-26 17:36:32 +00:00
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
|
|
})();
|
2017-06-29 08:35:30 +00:00
|
|
|
|
|
|
|
// Test Array construct inside try-catch block.
|
|
|
|
(() => {
|
|
|
|
function foo(x) { try { return new Array(x) } catch (e) { return e } }
|
|
|
|
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-06-29 08:35:30 +00:00
|
|
|
assertEquals([], foo(0));
|
|
|
|
assertEquals([], foo(0));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([], foo(0));
|
|
|
|
assertInstanceof(foo(-1), RangeError);
|
|
|
|
})();
|
2019-03-20 21:44:01 +00:00
|
|
|
|
2019-04-25 17:49:48 +00:00
|
|
|
// Packed
|
2019-03-20 21:44:01 +00:00
|
|
|
// Test non-extensible Array call with multiple parameters.
|
|
|
|
(() => {
|
2019-04-25 17:49:48 +00:00
|
|
|
function foo(x, y, z, t) { return Object.preventExtensions(new Array(x, y, z, t)); }
|
2019-03-20 21:44:01 +00:00
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2019-04-25 17:49:48 +00:00
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
|
2019-04-19 18:05:11 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
2019-04-25 17:49:48 +00:00
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
|
2019-04-19 18:05:11 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
// Test sealed Array call with multiple parameters.
|
|
|
|
(() => {
|
2019-04-25 17:49:48 +00:00
|
|
|
function foo(x, y, z, t) { return Object.seal(new Array(x, y, z, t)); }
|
2019-04-19 18:05:11 +00:00
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2019-04-25 17:49:48 +00:00
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
|
2019-04-19 18:05:11 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
2019-04-25 17:49:48 +00:00
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
|
2019-04-19 18:05:11 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
// Test frozen Array call with multiple parameters.
|
|
|
|
(() => {
|
2019-04-25 17:49:48 +00:00
|
|
|
function foo(x, y, z, t) { return Object.freeze(new Array(x, y, z, t)); }
|
2019-04-19 18:05:11 +00:00
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2019-04-25 17:49:48 +00:00
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
|
2019-04-19 18:05:11 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
2019-04-25 17:49:48 +00:00
|
|
|
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Holey
|
|
|
|
// Test non-extensible Array call with multiple parameters.
|
|
|
|
(() => {
|
|
|
|
function foo(x, y, z, t) { return Object.preventExtensions([, x, y, z, t]); }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test sealed Array call with multiple parameters.
|
|
|
|
(() => {
|
|
|
|
function foo(x, y, z, t) { return Object.seal([, x, y, z, t]); }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test frozen Array call with multiple parameters.
|
|
|
|
(() => {
|
|
|
|
function foo(x, y, z, t) { return Object.freeze([, x, y, z, t]); }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
|
|
|
|
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
|
2019-03-20 21:44:01 +00:00
|
|
|
})();
|