2015-05-11 17:20:43 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2015-09-30 19:49:46 +00:00
|
|
|
// Flags: --strong-mode --harmony-reflect
|
2015-10-28 15:57:01 +00:00
|
|
|
// Flags: --harmony-rest-parameters --allow-natives-syntax
|
2015-05-11 17:20:43 +00:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
function generateArguments(n, prefix) {
|
|
|
|
let a = [];
|
|
|
|
if (prefix) {
|
|
|
|
a.push(prefix);
|
|
|
|
}
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
a.push(String(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.join(', ');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-26 14:59:05 +00:00
|
|
|
function generateParams(n, directive_in_body) {
|
2015-05-11 17:20:43 +00:00
|
|
|
let a = [];
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
a[i] = `p${i}`;
|
|
|
|
}
|
|
|
|
return a.join(', ');
|
|
|
|
}
|
|
|
|
|
2015-08-26 14:59:05 +00:00
|
|
|
function generateParamsWithRest(n, directive_in_body) {
|
2015-05-19 18:44:18 +00:00
|
|
|
let a = [];
|
|
|
|
let i = 0;
|
|
|
|
for (; i < n; i++) {
|
|
|
|
a[i] = `p${i}`;
|
|
|
|
}
|
2015-08-26 14:59:05 +00:00
|
|
|
if (!directive_in_body) {
|
|
|
|
// If language mode directive occurs in body, rest parameters will trigger
|
|
|
|
// an early error regardless of language mode.
|
|
|
|
a.push(`...p${i}`);
|
|
|
|
}
|
2015-05-19 18:44:18 +00:00
|
|
|
return a.join(', ');
|
|
|
|
}
|
|
|
|
|
2015-05-11 17:20:43 +00:00
|
|
|
|
|
|
|
function generateSpread(n) {
|
|
|
|
return `...[${generateArguments(n)}]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(function FunctionCall() {
|
2015-05-18 14:18:51 +00:00
|
|
|
for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
|
2015-05-11 17:20:43 +00:00
|
|
|
let defs = [
|
2015-05-18 14:18:51 +00:00
|
|
|
`'use strong'; function f(${generateParams(parameterCount)}) {}`,
|
2015-05-19 18:44:18 +00:00
|
|
|
`'use strong'; function f(${generateParamsWithRest(parameterCount)}) {}`,
|
2015-05-18 14:18:51 +00:00
|
|
|
`'use strong'; function* f(${generateParams(parameterCount)}) {}`,
|
2015-05-19 18:44:18 +00:00
|
|
|
`'use strong'; function* f(${generateParamsWithRest(parameterCount)}) {}`,
|
2015-05-18 14:18:51 +00:00
|
|
|
`'use strong'; let f = (${generateParams(parameterCount)}) => {}`,
|
|
|
|
`function f(${generateParams(parameterCount)}) { 'use strong'; }`,
|
|
|
|
`function* f(${generateParams(parameterCount)}) { 'use strong'; }`,
|
|
|
|
`let f = (${generateParams(parameterCount)}) => { 'use strong'; }`,
|
2015-05-11 17:20:43 +00:00
|
|
|
];
|
|
|
|
for (let def of defs) {
|
2015-05-18 14:18:51 +00:00
|
|
|
for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
|
2015-05-11 17:20:43 +00:00
|
|
|
let calls = [
|
2015-05-18 14:18:51 +00:00
|
|
|
`f(${generateArguments(argumentCount)})`,
|
|
|
|
`f(${generateSpread(argumentCount)})`,
|
|
|
|
`f.call(${generateArguments(argumentCount, 'undefined')})`,
|
|
|
|
`f.call(undefined, ${generateSpread(argumentCount)})`,
|
|
|
|
`f.apply(undefined, [${generateArguments(argumentCount)}])`,
|
|
|
|
`f.bind(undefined)(${generateArguments(argumentCount)})`,
|
|
|
|
`%_CallFunction(${generateArguments(argumentCount, 'undefined')},
|
2015-05-11 17:20:43 +00:00
|
|
|
f)`,
|
2015-09-08 13:35:20 +00:00
|
|
|
`%Call(f, ${generateArguments(argumentCount, 'undefined')})`,
|
2015-05-18 14:18:51 +00:00
|
|
|
`%Apply(f, undefined, [${generateArguments(argumentCount)}], 0,
|
|
|
|
${argumentCount})`,
|
2015-05-11 17:20:43 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let call of calls) {
|
|
|
|
let code = `'use strict'; ${def}; ${call};`;
|
2015-05-18 14:18:51 +00:00
|
|
|
if (argumentCount < parameterCount) {
|
2015-08-26 14:59:05 +00:00
|
|
|
print(code);
|
2015-05-11 17:20:43 +00:00
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let calls = [
|
|
|
|
`f.call()`,
|
|
|
|
`f.apply()`,
|
|
|
|
`f.apply(undefined)`,
|
|
|
|
];
|
|
|
|
for (let call of calls) {
|
|
|
|
let code = `'use strict'; ${def}; ${call};`;
|
2015-05-18 14:18:51 +00:00
|
|
|
if (parameterCount > 0) {
|
2015-05-11 17:20:43 +00:00
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
(function MethodCall() {
|
2015-05-19 18:44:18 +00:00
|
|
|
for (let genParams of [generateParams, generateParamsWithRest]) {
|
|
|
|
for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
|
|
|
|
let defs = [
|
|
|
|
`let o = new class {
|
2015-08-26 14:59:05 +00:00
|
|
|
m(${genParams(parameterCount, true)}) { 'use strong'; }
|
2015-05-19 18:44:18 +00:00
|
|
|
}`,
|
|
|
|
`let o = new class {
|
2015-08-26 14:59:05 +00:00
|
|
|
*m(${genParams(parameterCount, true)}) { 'use strong'; }
|
2015-05-19 18:44:18 +00:00
|
|
|
}`,
|
2015-08-26 14:59:05 +00:00
|
|
|
`let o = { m(${genParams(parameterCount, true)}) { 'use strong'; } }`,
|
|
|
|
`let o = { *m(${genParams(parameterCount, true)}) { 'use strong'; } }`,
|
2015-05-19 18:44:18 +00:00
|
|
|
`'use strong';
|
|
|
|
let o = new class { m(${genParams(parameterCount)}) {} }`,
|
|
|
|
`'use strong';
|
|
|
|
let o = new class { *m(${genParams(parameterCount)}) {} }`,
|
|
|
|
`'use strong'; let o = { m(${genParams(parameterCount)}) {} }`,
|
|
|
|
`'use strong'; let o = { *m(${genParams(parameterCount)}) {} }`,
|
|
|
|
];
|
|
|
|
for (let def of defs) {
|
|
|
|
for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
|
|
|
|
let calls = [
|
|
|
|
`o.m(${generateArguments(argumentCount)})`,
|
|
|
|
`o.m(${generateSpread(argumentCount)})`,
|
|
|
|
`o.m.call(${generateArguments(argumentCount, 'o')})`,
|
|
|
|
`o.m.call(o, ${generateSpread(argumentCount)})`,
|
|
|
|
`o.m.apply(o, [${generateArguments(argumentCount)}])`,
|
|
|
|
`o.m.bind(o)(${generateArguments(argumentCount)})`,
|
|
|
|
`%_CallFunction(${generateArguments(argumentCount, 'o')}, o.m)`,
|
2015-09-08 13:35:20 +00:00
|
|
|
`%Call(o.m, ${generateArguments(argumentCount, 'o')})`,
|
2015-05-19 18:44:18 +00:00
|
|
|
`%Apply(o.m, o, [${generateArguments(argumentCount)}], 0,
|
|
|
|
${argumentCount})`,
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let call of calls) {
|
|
|
|
let code = `'use strict'; ${def}; ${call};`;
|
|
|
|
if (argumentCount < parameterCount) {
|
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-11 17:20:43 +00:00
|
|
|
let calls = [
|
2015-05-19 18:44:18 +00:00
|
|
|
`o.m.call()`,
|
|
|
|
`o.m.apply()`,
|
|
|
|
`o.m.apply(o)`,
|
2015-05-11 17:20:43 +00:00
|
|
|
];
|
|
|
|
for (let call of calls) {
|
|
|
|
let code = `'use strict'; ${def}; ${call};`;
|
2015-05-19 18:44:18 +00:00
|
|
|
if (parameterCount > 0) {
|
2015-05-11 17:20:43 +00:00
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
(function Constructor() {
|
2015-05-19 18:44:18 +00:00
|
|
|
for (let genParams of [generateParams, generateParamsWithRest]) {
|
|
|
|
for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
|
|
|
|
for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
|
|
|
|
let defs = [
|
|
|
|
`'use strong';
|
|
|
|
class C { constructor(${genParams(parameterCount)}) {} }`,
|
2015-05-11 17:20:43 +00:00
|
|
|
];
|
2015-05-19 18:44:18 +00:00
|
|
|
for (let def of defs) {
|
|
|
|
let calls = [
|
|
|
|
`new C(${generateArguments(argumentCount)})`,
|
|
|
|
`new C(${generateSpread(argumentCount)})`,
|
|
|
|
`Reflect.construct(C, [${generateArguments(argumentCount)}])`,
|
|
|
|
];
|
|
|
|
for (let call of calls) {
|
|
|
|
let code = `${def}; ${call};`;
|
|
|
|
if (argumentCount < parameterCount) {
|
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
}
|
2015-05-11 17:20:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
(function DerivedConstructor() {
|
2015-05-19 18:44:18 +00:00
|
|
|
for (let genParams of [generateParams, generateParamsWithRest]) {
|
|
|
|
for (let genArgs of [generateArguments, generateSpread]) {
|
|
|
|
for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
|
|
|
|
for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
|
|
|
|
let defs = [
|
|
|
|
`'use strong';
|
|
|
|
class B {
|
|
|
|
constructor(${genParams(parameterCount)}) {}
|
2015-05-11 17:20:43 +00:00
|
|
|
}
|
2015-05-19 18:44:18 +00:00
|
|
|
class C extends B {
|
|
|
|
constructor() {
|
|
|
|
super(${genArgs(argumentCount)});
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
];
|
|
|
|
for (let def of defs) {
|
|
|
|
let code = `${def}; new C();`;
|
|
|
|
if (argumentCount < parameterCount) {
|
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
2015-05-11 17:20:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
(function DerivedConstructorDefaultConstructorInDerivedClass() {
|
2015-05-19 18:44:18 +00:00
|
|
|
for (let genParams of [generateParams, generateParamsWithRest]) {
|
|
|
|
for (let genArgs of [generateArguments, generateSpread]) {
|
|
|
|
for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
|
|
|
|
for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
|
|
|
|
let defs = [
|
|
|
|
`'use strong';
|
|
|
|
class B {
|
|
|
|
constructor(${genParams(parameterCount)}) {}
|
|
|
|
}
|
|
|
|
class C extends B {}`,
|
|
|
|
];
|
|
|
|
for (let def of defs) {
|
|
|
|
let code = `${def}; new C(${genArgs(argumentCount)})`;
|
|
|
|
if (argumentCount < parameterCount) {
|
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
}
|
2015-05-11 17:20:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
(function TestOptimized() {
|
|
|
|
function f(x, y) { 'use strong'; }
|
|
|
|
|
|
|
|
assertThrows(f, TypeError);
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertThrows(f, TypeError);
|
|
|
|
|
|
|
|
function g() {
|
|
|
|
f(1);
|
|
|
|
}
|
|
|
|
assertThrows(g, TypeError);
|
|
|
|
%OptimizeFunctionOnNextCall(g);
|
|
|
|
assertThrows(g, TypeError);
|
|
|
|
|
|
|
|
f(1, 2);
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
f(1, 2);
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
(function TestOptimized2() {
|
|
|
|
'use strong';
|
|
|
|
function f(x, y) {}
|
|
|
|
|
|
|
|
assertThrows(f, TypeError);
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertThrows(f, TypeError);
|
|
|
|
|
|
|
|
function g() {
|
|
|
|
f(1);
|
|
|
|
}
|
|
|
|
assertThrows(g, TypeError);
|
|
|
|
%OptimizeFunctionOnNextCall(g);
|
|
|
|
assertThrows(g, TypeError);
|
|
|
|
|
|
|
|
f(1, 2);
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
f(1, 2);
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
2015-05-12 17:37:34 +00:00
|
|
|
(function TestOptimized3() {
|
|
|
|
function f(x, y) {}
|
|
|
|
function g() {
|
|
|
|
'use strong';
|
|
|
|
f(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g();
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
g();
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
2015-05-18 14:18:51 +00:00
|
|
|
(function ParametersSuper() {
|
|
|
|
for (let genArgs of [generateArguments, generateSpread]) {
|
|
|
|
for (let argumentCount = 0; argumentCount < 3; argumentCount++) {
|
|
|
|
for (let parameterCount = 0; parameterCount < 3; parameterCount++) {
|
|
|
|
let defs = [
|
|
|
|
`'use strict';
|
|
|
|
class B {
|
|
|
|
m(${generateParams(parameterCount)} ){ 'use strong' }
|
|
|
|
}`,
|
|
|
|
`'use strong'; class B { m(${generateParams(parameterCount)}) {} }`,
|
|
|
|
];
|
|
|
|
for (let def of defs) {
|
|
|
|
let code = `${def};
|
|
|
|
class D extends B {
|
|
|
|
m() {
|
|
|
|
super.m(${genArgs(argumentCount)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new D().m()`;
|
|
|
|
print('\n\n' + code);
|
|
|
|
if (argumentCount < parameterCount) {
|
|
|
|
assertThrows(code, TypeError);
|
|
|
|
} else {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|