2017-02-07 10:11:01 +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.
|
|
|
|
|
2017-10-24 11:15:47 +00:00
|
|
|
#include "src/api.h"
|
2017-02-07 10:11:01 +00:00
|
|
|
#include "src/ast/ast.h"
|
|
|
|
#include "src/compiler.h"
|
|
|
|
#include "src/objects-inl.h"
|
|
|
|
#include "src/parsing/parse-info.h"
|
|
|
|
#include "src/parsing/parsing.h"
|
2017-06-30 10:38:38 +00:00
|
|
|
#include "src/parsing/preparsed-scope-data.h"
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/scope-test-helper.h"
|
|
|
|
#include "test/cctest/unicode-helpers.h"
|
|
|
|
|
2017-02-23 12:27:30 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-03-01 15:26:42 +00:00
|
|
|
enum SkipTests {
|
2017-02-23 12:27:30 +00:00
|
|
|
DONT_SKIP = 0,
|
|
|
|
// Skip if the test function declares itself strict, otherwise don't skip.
|
|
|
|
SKIP_STRICT_FUNCTION = 1,
|
|
|
|
// Skip if there's a "use strict" directive above the test.
|
|
|
|
SKIP_STRICT_OUTER = 1 << 1,
|
2017-03-01 15:26:42 +00:00
|
|
|
SKIP_ARROW = 1 << 2,
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT = SKIP_STRICT_FUNCTION | SKIP_STRICT_OUTER
|
|
|
|
};
|
|
|
|
|
2017-08-04 09:19:41 +00:00
|
|
|
enum class PreciseMaybeAssigned { YES, NO };
|
|
|
|
|
|
|
|
enum class Bailout { BAILOUT_IF_OUTER_SLOPPY, NO };
|
|
|
|
|
2017-02-23 12:27:30 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-02-07 10:11:01 +00:00
|
|
|
TEST(PreParserScopeAnalysis) {
|
|
|
|
i::FLAG_lazy_inner_functions = true;
|
2017-08-16 08:19:06 +00:00
|
|
|
i::FLAG_preparser_scope_analysis = true;
|
2017-06-22 13:09:01 +00:00
|
|
|
i::FLAG_aggressive_lazy_inner_functions = true;
|
2017-02-07 10:11:01 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
i::Factory* factory = isolate->factory();
|
2017-10-23 12:41:57 +00:00
|
|
|
LocalContext env;
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-02-13 12:09:06 +00:00
|
|
|
struct {
|
2017-06-21 14:13:35 +00:00
|
|
|
const char* code;
|
2017-02-23 12:27:30 +00:00
|
|
|
bool strict_outer;
|
|
|
|
bool strict_test_function;
|
2017-03-01 15:26:42 +00:00
|
|
|
bool arrow;
|
2017-02-13 12:09:06 +00:00
|
|
|
} outers[] = {
|
2017-03-03 13:53:05 +00:00
|
|
|
// Normal case (test function at the laziness boundary):
|
2017-10-24 11:15:47 +00:00
|
|
|
{"function test(%s) { %s function skippable() { } } test;", false, false,
|
|
|
|
false},
|
|
|
|
|
|
|
|
{"var test2 = function test(%s) { %s function skippable() { } }; test2",
|
|
|
|
false, false, false},
|
2017-06-22 13:09:01 +00:00
|
|
|
|
2017-03-03 13:53:05 +00:00
|
|
|
// Arrow functions (they can never be at the laziness boundary):
|
2017-10-24 11:15:47 +00:00
|
|
|
{"function test() { (%s) => { %s }; function skippable() { } } test;",
|
|
|
|
false, false, true},
|
|
|
|
|
|
|
|
// Repeat the above mentioned cases with global 'use strict'
|
|
|
|
{"'use strict'; function test(%s) { %s function skippable() { } } test;",
|
|
|
|
true, false, false},
|
|
|
|
|
|
|
|
{"'use strict'; var test2 = function test(%s) { %s \n"
|
|
|
|
"function skippable() { } }; test2",
|
|
|
|
true, false, false},
|
|
|
|
|
|
|
|
{"'use strict'; function test() { (%s) => { %s };\n"
|
|
|
|
"function skippable() { } } test;",
|
|
|
|
true, false, true},
|
2017-03-03 13:53:05 +00:00
|
|
|
|
|
|
|
// ... and with the test function declaring itself strict:
|
2017-10-24 11:15:47 +00:00
|
|
|
{"function test(%s) { 'use strict'; %s function skippable() { } } test;",
|
|
|
|
false, true, false},
|
|
|
|
|
|
|
|
{"var test2 = function test(%s) { 'use strict'; %s \n"
|
|
|
|
"function skippable() { } }; test2",
|
|
|
|
false, true, false},
|
|
|
|
|
|
|
|
{"function test() { 'use strict'; (%s) => { %s };\n"
|
|
|
|
"function skippable() { } } test;",
|
|
|
|
false, true, true},
|
2017-05-16 08:44:40 +00:00
|
|
|
|
2017-06-30 10:38:38 +00:00
|
|
|
// Methods containing skippable functions.
|
2017-10-24 11:15:47 +00:00
|
|
|
{"function get_method() {\n"
|
|
|
|
" class MyClass { test_method(%s) { %s function skippable() { } } }\n"
|
|
|
|
" var o = new MyClass(); return o.test_method;\n"
|
|
|
|
"}\n"
|
|
|
|
"get_method();",
|
|
|
|
true, true, false},
|
2017-03-03 13:53:05 +00:00
|
|
|
|
|
|
|
// FIXME(marja): Generators and async functions
|
2017-02-13 12:09:06 +00:00
|
|
|
};
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-02-07 20:43:48 +00:00
|
|
|
struct Inner {
|
|
|
|
Inner(const char* s) : source(s) {} // NOLINT
|
2017-03-01 15:26:42 +00:00
|
|
|
Inner(const char* s, SkipTests skip) : source(s), skip(skip) {}
|
2017-08-04 09:19:41 +00:00
|
|
|
Inner(const char* s, SkipTests skip, PreciseMaybeAssigned precise)
|
2017-03-01 15:26:42 +00:00
|
|
|
: source(s), skip(skip), precise_maybe_assigned(precise) {}
|
2017-02-07 20:43:48 +00:00
|
|
|
|
|
|
|
Inner(const char* p, const char* s) : params(p), source(s) {}
|
2017-03-01 15:26:42 +00:00
|
|
|
Inner(const char* p, const char* s, SkipTests skip)
|
|
|
|
: params(p), source(s), skip(skip) {}
|
2017-08-04 09:19:41 +00:00
|
|
|
Inner(const char* p, const char* s, SkipTests skip,
|
|
|
|
PreciseMaybeAssigned precise)
|
2017-03-01 15:26:42 +00:00
|
|
|
: params(p), source(s), skip(skip), precise_maybe_assigned(precise) {}
|
2017-08-04 09:19:41 +00:00
|
|
|
Inner(const char* p, const char* s, SkipTests skip, Bailout bailout)
|
|
|
|
: params(p), source(s), skip(skip), bailout(bailout) {}
|
2017-02-07 20:43:48 +00:00
|
|
|
|
|
|
|
const char* params = "";
|
2017-02-07 10:11:01 +00:00
|
|
|
const char* source;
|
2017-03-01 15:26:42 +00:00
|
|
|
SkipTests skip = DONT_SKIP;
|
2017-08-04 09:19:41 +00:00
|
|
|
PreciseMaybeAssigned precise_maybe_assigned = PreciseMaybeAssigned::YES;
|
|
|
|
Bailout bailout = Bailout::NO;
|
2017-02-07 10:11:01 +00:00
|
|
|
} inners[] = {
|
|
|
|
// Simple cases
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var1;"},
|
|
|
|
{"var1 = 5;"},
|
|
|
|
{"if (true) {}"},
|
|
|
|
{"function f1() {}"},
|
2017-06-22 13:09:01 +00:00
|
|
|
{"test;"},
|
|
|
|
{"test2;"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Var declarations and assignments.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var var1;"},
|
|
|
|
{"var var1; var1 = 5;"},
|
2017-08-04 09:19:41 +00:00
|
|
|
{"if (true) { var var1; }", DONT_SKIP, PreciseMaybeAssigned::NO},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { var var1; var1 = 5; }"},
|
|
|
|
{"var var1; function f() { var1; }"},
|
|
|
|
{"var var1; var1 = 5; function f() { var1; }"},
|
|
|
|
{"var var1; function f() { var1 = 5; }"},
|
2017-03-03 13:53:05 +00:00
|
|
|
{"function f1() { f2(); } function f2() {}"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Let declarations and assignments.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"let var1;"},
|
|
|
|
{"let var1; var1 = 5;"},
|
|
|
|
{"if (true) { let var1; }"},
|
|
|
|
{"if (true) { let var1; var1 = 5; }"},
|
|
|
|
{"let var1; function f() { var1; }"},
|
|
|
|
{"let var1; var1 = 5; function f() { var1; }"},
|
|
|
|
{"let var1; function f() { var1 = 5; }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Const declarations.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"const var1 = 5;"},
|
|
|
|
{"if (true) { const var1 = 5; }"},
|
|
|
|
{"const var1 = 5; function f() { var1; }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-05-16 08:44:40 +00:00
|
|
|
// Functions.
|
|
|
|
{"function f1() { let var2; }"},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var var1 = function f1() { let var2; };"},
|
|
|
|
{"let var1 = function f1() { let var2; };"},
|
|
|
|
{"const var1 = function f1() { let var2; };"},
|
|
|
|
{"var var1 = function() { let var2; };"},
|
|
|
|
{"let var1 = function() { let var2; };"},
|
|
|
|
{"const var1 = function() { let var2; };"},
|
2017-05-16 08:44:40 +00:00
|
|
|
|
2017-08-30 08:57:23 +00:00
|
|
|
{"function *f1() { let var2; }"},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"let var1 = function *f1() { let var2; };"},
|
|
|
|
{"let var1 = function*() { let var2; };"},
|
2017-08-30 08:57:23 +00:00
|
|
|
|
|
|
|
{"async function f1() { let var2; }"},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"let var1 = async function f1() { let var2; };"},
|
|
|
|
{"let var1 = async function() { let var2; };"},
|
2017-08-30 08:57:23 +00:00
|
|
|
|
2017-02-07 10:11:01 +00:00
|
|
|
// Redeclarations.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var var1; var var1;"},
|
|
|
|
{"var var1; var var1; var1 = 5;"},
|
|
|
|
{"var var1; if (true) { var var1; }"},
|
|
|
|
{"if (true) { var var1; var var1; }"},
|
|
|
|
{"var var1; if (true) { var var1; var1 = 5; }"},
|
|
|
|
{"if (true) { var var1; var var1; var1 = 5; }"},
|
|
|
|
{"var var1; var var1; function f() { var1; }"},
|
|
|
|
{"var var1; var var1; function f() { var1 = 5; }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Shadowing declarations.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var var1; if (true) { var var1; }"},
|
|
|
|
{"var var1; if (true) { let var1; }"},
|
|
|
|
{"let var1; if (true) { let var1; }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var var1; if (true) { const var1 = 0; }"},
|
|
|
|
{"const var1 = 0; if (true) { const var1 = 0; }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-02-24 10:44:03 +00:00
|
|
|
// Variables deeper in the subscopes (scopes without variables inbetween).
|
|
|
|
{"if (true) { if (true) { function f() { var var1 = 5; } } }"},
|
|
|
|
|
2017-02-07 10:11:01 +00:00
|
|
|
// Arguments and this.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"arguments;"},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"arguments = 5;", SKIP_STRICT},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { arguments; }"},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"if (true) { arguments = 5; }", SKIP_STRICT},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"() => { arguments; };"},
|
2017-03-03 13:53:05 +00:00
|
|
|
{"var1, var2, var3", "arguments;"},
|
|
|
|
{"var1, var2, var3", "arguments = 5;", SKIP_STRICT},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var1, var2, var3", "() => { arguments; };"},
|
|
|
|
{"var1, var2, var3", "() => { arguments = 5; };", SKIP_STRICT},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-02-07 20:43:48 +00:00
|
|
|
{"this;"},
|
|
|
|
{"if (true) { this; }"},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"() => { this; };"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Variable called "arguments"
|
2017-02-23 12:27:30 +00:00
|
|
|
{"var arguments;", SKIP_STRICT},
|
|
|
|
{"var arguments; arguments = 5;", SKIP_STRICT},
|
2017-08-04 09:19:41 +00:00
|
|
|
{"if (true) { var arguments; }", SKIP_STRICT, PreciseMaybeAssigned::NO},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"if (true) { var arguments; arguments = 5; }", SKIP_STRICT},
|
|
|
|
{"var arguments; function f() { arguments; }", SKIP_STRICT},
|
|
|
|
{"var arguments; arguments = 5; function f() { arguments; }",
|
|
|
|
SKIP_STRICT},
|
|
|
|
{"var arguments; function f() { arguments = 5; }", SKIP_STRICT},
|
|
|
|
|
|
|
|
{"let arguments;", SKIP_STRICT},
|
|
|
|
{"let arguments; arguments = 5;", SKIP_STRICT},
|
|
|
|
{"if (true) { let arguments; }", SKIP_STRICT},
|
|
|
|
{"if (true) { let arguments; arguments = 5; }", SKIP_STRICT},
|
|
|
|
{"let arguments; function f() { arguments; }", SKIP_STRICT},
|
|
|
|
{"let arguments; arguments = 5; function f() { arguments; }",
|
|
|
|
SKIP_STRICT},
|
|
|
|
{"let arguments; function f() { arguments = 5; }", SKIP_STRICT},
|
|
|
|
|
|
|
|
{"const arguments = 5;", SKIP_STRICT},
|
|
|
|
{"if (true) { const arguments = 5; }", SKIP_STRICT},
|
|
|
|
{"const arguments = 5; function f() { arguments; }", SKIP_STRICT},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Destructuring declarations.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var [var1, var2] = [1, 2];"},
|
|
|
|
{"var [var1, var2, [var3, var4]] = [1, 2, [3, 4]];"},
|
|
|
|
{"var [{var1: var2}, {var3: var4}] = [{var1: 1}, {var3: 2}];"},
|
|
|
|
{"var [var1, ...var2] = [1, 2, 3];"},
|
|
|
|
|
|
|
|
{"var {var1: var2, var3: var4} = {var1: 1, var3: 2};"},
|
|
|
|
{"var {var1: var2, var3: {var4: var5}} = {var1: 1, var3: {var4: 2}};"},
|
|
|
|
{"var {var1: var2, var3: [var4, var5]} = {var1: 1, var3: [2, 3]};"},
|
|
|
|
|
|
|
|
{"let [var1, var2] = [1, 2];"},
|
|
|
|
{"let [var1, var2, [var3, var4]] = [1, 2, [3, 4]];"},
|
|
|
|
{"let [{var1: var2}, {var3: var4}] = [{var1: 1}, {var3: 2}];"},
|
|
|
|
{"let [var1, ...var2] = [1, 2, 3];"},
|
|
|
|
|
|
|
|
{"let {var1: var2, var3: var4} = {var1: 1, var3: 2};"},
|
|
|
|
{"let {var1: var2, var3: {var4: var5}} = {var1: 1, var3: {var4: 2}};"},
|
|
|
|
{"let {var1: var2, var3: [var4, var5]} = {var1: 1, var3: [2, 3]};"},
|
|
|
|
|
|
|
|
{"const [var1, var2] = [1, 2];"},
|
|
|
|
{"const [var1, var2, [var3, var4]] = [1, 2, [3, 4]];"},
|
|
|
|
{"const [{var1: var2}, {var3: var4}] = [{var1: 1}, {var3: 2}];"},
|
|
|
|
{"const [var1, ...var2] = [1, 2, 3];"},
|
|
|
|
|
|
|
|
{"const {var1: var2, var3: var4} = {var1: 1, var3: 2};"},
|
|
|
|
{"const {var1: var2, var3: {var4: var5}} = {var1: 1, var3: {var4: 2}};"},
|
|
|
|
{"const {var1: var2, var3: [var4, var5]} = {var1: 1, var3: [2, 3]};"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Referencing the function variable.
|
2017-02-13 12:09:06 +00:00
|
|
|
{"test;"},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"function f1() { f1; }"},
|
|
|
|
{"function f1() { function f2() { f1; } }"},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"function arguments() {}", SKIP_STRICT},
|
|
|
|
{"function f1() {} function f1() {}", SKIP_STRICT},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var f1; function f1() {}"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Assigning to the function variable.
|
2017-02-13 12:09:06 +00:00
|
|
|
{"test = 3;"},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"function f1() { f1 = 3; }"},
|
|
|
|
{"function f1() { f1; } f1 = 3;"},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"function arguments() {} arguments = 8;", SKIP_STRICT},
|
|
|
|
{"function f1() {} f1 = 3; function f1() {}", SKIP_STRICT},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Evals.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var var1; eval('');"},
|
|
|
|
{"var var1; function f1() { eval(''); }"},
|
|
|
|
{"let var1; eval('');"},
|
|
|
|
{"let var1; function f1() { eval(''); }"},
|
|
|
|
{"const var1 = 10; eval('');"},
|
|
|
|
{"const var1 = 10; function f1() { eval(''); }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// Standard for loops.
|
2017-02-07 20:43:48 +00:00
|
|
|
{"for (var var1 = 0; var1 < 10; ++var1) { }"},
|
|
|
|
{"for (let var1 = 0; var1 < 10; ++var1) { }"},
|
|
|
|
{"for (const var1 = 0; var1 < 10; ++var1) { }"},
|
|
|
|
|
|
|
|
{"for (var var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"},
|
|
|
|
{"for (let var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"},
|
|
|
|
{"for (const var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// For of loops
|
2017-02-07 20:43:48 +00:00
|
|
|
{"for (var1 of [1, 2]) { }"},
|
|
|
|
{"for (var var1 of [1, 2]) { }"},
|
|
|
|
{"for (let var1 of [1, 2]) { }"},
|
|
|
|
{"for (const var1 of [1, 2]) { }"},
|
|
|
|
|
|
|
|
{"for (var1 of [1, 2]) { var1; }"},
|
|
|
|
{"for (var var1 of [1, 2]) { var1; }"},
|
|
|
|
{"for (let var1 of [1, 2]) { var1; }"},
|
|
|
|
{"for (const var1 of [1, 2]) { var1; }"},
|
|
|
|
|
|
|
|
{"for (var1 of [1, 2]) { var1 = 0; }"},
|
|
|
|
{"for (var var1 of [1, 2]) { var1 = 0; }"},
|
|
|
|
{"for (let var1 of [1, 2]) { var1 = 0; }"},
|
|
|
|
{"for (const var1 of [1, 2]) { var1 = 0; }"},
|
|
|
|
|
|
|
|
{"for (var1 of [1, 2]) { function foo() { var1; } }"},
|
|
|
|
{"for (var var1 of [1, 2]) { function foo() { var1; } }"},
|
|
|
|
{"for (let var1 of [1, 2]) { function foo() { var1; } }"},
|
|
|
|
{"for (const var1 of [1, 2]) { function foo() { var1; } }"},
|
|
|
|
|
|
|
|
{"for (var1 of [1, 2]) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (var var1 of [1, 2]) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (let var1 of [1, 2]) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (const var1 of [1, 2]) { function foo() { var1 = 0; } }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
|
|
|
// For in loops
|
2017-02-07 20:43:48 +00:00
|
|
|
{"for (var1 in {a: 6}) { }"},
|
|
|
|
{"for (var var1 in {a: 6}) { }"},
|
|
|
|
{"for (let var1 in {a: 6}) { }"},
|
|
|
|
{"for (const var1 in {a: 6}) { }"},
|
|
|
|
|
|
|
|
{"for (var1 in {a: 6}) { var1; }"},
|
|
|
|
{"for (var var1 in {a: 6}) { var1; }"},
|
|
|
|
{"for (let var1 in {a: 6}) { var1; }"},
|
|
|
|
{"for (const var1 in {a: 6}) { var1; }"},
|
|
|
|
|
|
|
|
{"for (var1 in {a: 6}) { var1 = 0; }"},
|
|
|
|
{"for (var var1 in {a: 6}) { var1 = 0; }"},
|
|
|
|
{"for (let var1 in {a: 6}) { var1 = 0; }"},
|
|
|
|
{"for (const var1 in {a: 6}) { var1 = 0; }"},
|
|
|
|
|
|
|
|
{"for (var1 in {a: 6}) { function foo() { var1; } }"},
|
|
|
|
{"for (var var1 in {a: 6}) { function foo() { var1; } }"},
|
|
|
|
{"for (let var1 in {a: 6}) { function foo() { var1; } }"},
|
|
|
|
{"for (const var1 in {a: 6}) { function foo() { var1; } }"},
|
|
|
|
|
|
|
|
{"for (var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (var var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (let var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (const var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
|
|
|
|
|
|
|
{"for (var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (var var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (let var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
|
|
|
{"for (const var1 in {a: 6}) { function foo() { var1 = 0; } }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-03-03 13:53:05 +00:00
|
|
|
// Destructuring loop variable
|
|
|
|
{"for ([var1, var2] of [[1, 1], [2, 2]]) { }"},
|
|
|
|
{"for (var [var1, var2] of [[1, 1], [2, 2]]) { }"},
|
|
|
|
{"for (let [var1, var2] of [[1, 1], [2, 2]]) { }"},
|
|
|
|
{"for (const [var1, var2] of [[1, 1], [2, 2]]) { }"},
|
|
|
|
|
|
|
|
{"for ([var1, var2] of [[1, 1], [2, 2]]) { var2 = 3; }"},
|
|
|
|
{"for (var [var1, var2] of [[1, 1], [2, 2]]) { var2 = 3; }"},
|
|
|
|
{"for (let [var1, var2] of [[1, 1], [2, 2]]) { var2 = 3; }"},
|
|
|
|
{"for (const [var1, var2] of [[1, 1], [2, 2]]) { var2 = 3; }"},
|
|
|
|
|
|
|
|
{"for ([var1, var2] of [[1, 1], [2, 2]]) { () => { var2 = 3; } }"},
|
|
|
|
{"for (var [var1, var2] of [[1, 1], [2, 2]]) { () => { var2 = 3; } }"},
|
|
|
|
{"for (let [var1, var2] of [[1, 1], [2, 2]]) { () => { var2 = 3; } }"},
|
|
|
|
{"for (const [var1, var2] of [[1, 1], [2, 2]]) { () => { var2 = 3; } }"},
|
|
|
|
|
2017-08-11 08:13:05 +00:00
|
|
|
// Skippable function in loop header
|
|
|
|
{"for (let [var1, var2 = function() { }] of [[1]]) { }"},
|
|
|
|
{"for (let [var1, var2 = function() { var1; }] of [[1]]) { }"},
|
|
|
|
{"for (let [var1, var2 = function() { var2; }] of [[1]]) { }"},
|
|
|
|
{"for (let [var1, var2 = function() { var1; var2; }] of [[1]]) { }"},
|
|
|
|
{"for (let [var1, var2 = function() { var1 = 0; }] of [[1]]) { }"},
|
|
|
|
{"for (let [var1, var2 = function() { var2 = 0; }] of [[1]]) { }"},
|
|
|
|
{"for (let [var1, var2 = function() { var1 = 0; var2 = 0; }] of [[1]]) { "
|
|
|
|
"}"},
|
|
|
|
|
|
|
|
{"for (let [var1, var2 = function() { }] of [[1]]) { function f() { "
|
|
|
|
"var1; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { }] of [[1]]) { function f() { "
|
|
|
|
"var2; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { }] of [[1]]) { function f() { "
|
|
|
|
"var1; var2; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { }] of [[1]]) { function f() { "
|
|
|
|
"var1 = 0; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { }] of [[1]]) { function f() { "
|
|
|
|
"var2 = 0; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { }] of [[1]]) { function f() { "
|
|
|
|
"var1 = 0; var2 = 0; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { var1; }] of [[1]]) { "
|
|
|
|
"function f() { var1; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { var1; }] of [[1]]) { "
|
|
|
|
"function f() { var2; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { var1; }] of [[1]]) { "
|
|
|
|
"function f() { var1; var2; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { var2; }] of [[1]]) { "
|
|
|
|
"function f() { var1; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { var2; }] of [[1]]) { "
|
|
|
|
"function f() { var2; } }"},
|
|
|
|
{"for (let [var1, var2 = function() { var2; }] of [[1]]) { "
|
|
|
|
"function f() { var1; var2; } }"},
|
|
|
|
|
2017-02-07 10:11:01 +00:00
|
|
|
// Loops without declarations
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var var1 = 0; for ( ; var1 < 2; ++var1) { }"},
|
|
|
|
{"var var1 = 0; for ( ; var1 < 2; ++var1) { function foo() { var1; } }"},
|
|
|
|
{"var var1 = 0; for ( ; var1 > 2; ) { }"},
|
|
|
|
{"var var1 = 0; for ( ; var1 > 2; ) { function foo() { var1; } }"},
|
|
|
|
{"var var1 = 0; for ( ; var1 > 2; ) { function foo() { var1 = 6; } }"},
|
|
|
|
|
|
|
|
{"var var1 = 0; for(var1; var1 < 2; ++var1) { }"},
|
|
|
|
{"var var1 = 0; for (var1; var1 < 2; ++var1) { function foo() { var1; } "
|
2017-02-07 10:11:01 +00:00
|
|
|
"}"},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var var1 = 0; for (var1; var1 > 2; ) { }"},
|
|
|
|
{"var var1 = 0; for (var1; var1 > 2; ) { function foo() { var1; } }"},
|
|
|
|
{"var var1 = 0; for (var1; var1 > 2; ) { function foo() { var1 = 6; } }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-02-17 13:05:51 +00:00
|
|
|
// Block functions (potentially sloppy).
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { function f1() {} }"},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"if (true) { function f1() {} function f1() {} }", SKIP_STRICT},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { if (true) { function f1() {} } }"},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"if (true) { if (true) { function f1() {} function f1() {} } }",
|
|
|
|
SKIP_STRICT},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { function f1() {} f1 = 3; }"},
|
|
|
|
|
|
|
|
{"if (true) { function f1() {} function foo() { f1; } }"},
|
|
|
|
{"if (true) { function f1() {} } function foo() { f1; }"},
|
|
|
|
{"if (true) { function f1() {} function f1() {} function foo() { f1; } "
|
2017-02-17 13:05:51 +00:00
|
|
|
"}",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { function f1() {} function f1() {} } function foo() { f1; "
|
2017-02-17 13:05:51 +00:00
|
|
|
"}",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { if (true) { function f1() {} } function foo() { f1; } }"},
|
|
|
|
{"if (true) { if (true) { function f1() {} function f1() {} } function "
|
2017-02-17 13:05:51 +00:00
|
|
|
"foo() { f1; } }",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT},
|
2017-02-07 20:43:48 +00:00
|
|
|
{"if (true) { function f1() {} f1 = 3; function foo() { f1; } }"},
|
|
|
|
{"if (true) { function f1() {} f1 = 3; } function foo() { f1; }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
|
2017-02-07 20:43:48 +00:00
|
|
|
{"var f1 = 1; if (true) { function f1() {} }"},
|
|
|
|
{"var f1 = 1; if (true) { function f1() {} } function foo() { f1; }"},
|
2017-02-09 17:31:21 +00:00
|
|
|
|
2017-03-03 13:53:05 +00:00
|
|
|
{"if (true) { function f1() {} function f2() { f1(); } }"},
|
|
|
|
|
2017-08-30 08:57:23 +00:00
|
|
|
{"if (true) { function *f1() {} }"},
|
|
|
|
{"if (true) { async function f1() {} }"},
|
|
|
|
|
2017-10-05 09:31:30 +00:00
|
|
|
// (Potentially sloppy) block function shadowing a catch variable.
|
|
|
|
{"try { } catch(var1) { if (true) { function var1() {} } }"},
|
|
|
|
|
2017-02-09 17:31:21 +00:00
|
|
|
// Simple parameters.
|
|
|
|
{"var1", ""},
|
|
|
|
{"var1", "var1;"},
|
|
|
|
{"var1", "var1 = 9;"},
|
|
|
|
{"var1", "function f1() { var1; }"},
|
|
|
|
{"var1", "function f1() { var1 = 9; }"},
|
|
|
|
|
2017-02-16 09:16:32 +00:00
|
|
|
{"var1, var2", ""},
|
|
|
|
{"var1, var2", "var2;"},
|
|
|
|
{"var1, var2", "var2 = 9;"},
|
|
|
|
{"var1, var2", "function f1() { var2; }"},
|
|
|
|
{"var1, var2", "function f1() { var2 = 9; }"},
|
|
|
|
{"var1, var2", "var1;"},
|
|
|
|
{"var1, var2", "var1 = 9;"},
|
|
|
|
{"var1, var2", "function f1() { var1; }"},
|
|
|
|
{"var1, var2", "function f1() { var1 = 9; }"},
|
|
|
|
|
2017-02-09 17:31:21 +00:00
|
|
|
// Duplicate parameters.
|
2017-03-01 15:26:42 +00:00
|
|
|
{"var1, var1", "", SkipTests(SKIP_STRICT | SKIP_ARROW)},
|
|
|
|
{"var1, var1", "var1;", SkipTests(SKIP_STRICT | SKIP_ARROW)},
|
|
|
|
{"var1, var1", "var1 = 9;", SkipTests(SKIP_STRICT | SKIP_ARROW)},
|
|
|
|
{"var1, var1", "function f1() { var1; }",
|
|
|
|
SkipTests(SKIP_STRICT | SKIP_ARROW)},
|
|
|
|
{"var1, var1", "function f1() { var1 = 9; }",
|
|
|
|
SkipTests(SKIP_STRICT | SKIP_ARROW)},
|
2017-02-23 12:27:30 +00:00
|
|
|
|
|
|
|
// If the function declares itself strict, non-simple parameters aren't
|
|
|
|
// allowed.
|
2017-02-09 17:31:21 +00:00
|
|
|
|
2017-02-10 13:37:03 +00:00
|
|
|
// Rest parameter.
|
2017-02-23 12:27:30 +00:00
|
|
|
{"...var2", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"...var2", "var2;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"...var2", "var2 = 9;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"...var2", "function f1() { var2; }", SKIP_STRICT_FUNCTION},
|
|
|
|
{"...var2", "function f1() { var2 = 9; }", SKIP_STRICT_FUNCTION},
|
|
|
|
|
|
|
|
{"var1, ...var2", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"var1, ...var2", "var2;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"var1, ...var2", "var2 = 9;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"var1, ...var2", "function f1() { var2; }", SKIP_STRICT_FUNCTION},
|
|
|
|
{"var1, ...var2", "function f1() { var2 = 9; }", SKIP_STRICT_FUNCTION},
|
2017-02-16 09:16:32 +00:00
|
|
|
|
2017-02-17 11:48:36 +00:00
|
|
|
// Default parameters.
|
2017-08-04 09:19:41 +00:00
|
|
|
{"var1 = 3", "", SKIP_STRICT_FUNCTION, PreciseMaybeAssigned::NO},
|
|
|
|
{"var1, var2 = var1", "", SKIP_STRICT_FUNCTION, PreciseMaybeAssigned::NO},
|
|
|
|
{"var1, var2 = 4, ...var3", "", SKIP_STRICT_FUNCTION,
|
|
|
|
PreciseMaybeAssigned::NO},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
|
|
|
// Destructuring parameters. Because of the search space explosion, we
|
|
|
|
// cannot test all interesting cases. Let's try to test a relevant subset.
|
2017-02-23 12:27:30 +00:00
|
|
|
{"[]", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{}", "", SKIP_STRICT_FUNCTION},
|
|
|
|
|
|
|
|
{"[var1]", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1}", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{var1}", "", SKIP_STRICT_FUNCTION},
|
|
|
|
|
|
|
|
{"[var1]", "var1;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1}", "var1;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1}", "name1;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{var1}", "var1;", SKIP_STRICT_FUNCTION},
|
|
|
|
|
|
|
|
{"[var1]", "var1 = 16;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1}", "var1 = 16;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1}", "name1 = 16;", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{var1}", "var1 = 16;", SKIP_STRICT_FUNCTION},
|
|
|
|
|
2017-10-24 11:15:47 +00:00
|
|
|
{"[var1]", "() => { var1; };", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1}", "() => { var1; };", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1}", "() => { name1; };", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{var1}", "() => { var1; };", SKIP_STRICT_FUNCTION},
|
2017-02-23 12:27:30 +00:00
|
|
|
|
|
|
|
{"[var1, var2, var3]", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1, name2: var2, name3: var3}", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{var1, var2, var3}", "", SKIP_STRICT_FUNCTION},
|
|
|
|
|
2017-10-24 11:15:47 +00:00
|
|
|
{"[var1, var2, var3]", "() => { var2 = 16;};", SKIP_STRICT_FUNCTION},
|
|
|
|
{"{name1: var1, name2: var2, name3: var3}", "() => { var2 = 16;};",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT_FUNCTION},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"{name1: var1, name2: var2, name3: var3}", "() => { name2 = 16;};",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT_FUNCTION},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"{var1, var2, var3}", "() => { var2 = 16;};", SKIP_STRICT_FUNCTION},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
|
|
|
// Nesting destructuring.
|
2017-02-23 12:27:30 +00:00
|
|
|
{"[var1, [var2, var3], {var4, name5: [var5, var6]}]", "",
|
|
|
|
SKIP_STRICT_FUNCTION},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
|
|
|
// Complicated params.
|
2017-03-01 15:26:42 +00:00
|
|
|
{"var1, [var2], var3 = 24, [var4, var5] = [2, 4], var6, {var7}, var8, "
|
|
|
|
"{name9: var9, name10: var10}, ...var11",
|
2017-08-04 09:19:41 +00:00
|
|
|
"", SKIP_STRICT_FUNCTION, PreciseMaybeAssigned::NO},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
2017-05-16 08:44:40 +00:00
|
|
|
// Complicated cases from bugs.
|
2017-08-04 09:19:41 +00:00
|
|
|
{"var1 = {} = {}", "", SKIP_STRICT_FUNCTION, PreciseMaybeAssigned::NO},
|
2017-05-16 08:44:40 +00:00
|
|
|
|
2017-02-17 11:48:36 +00:00
|
|
|
// Destructuring rest. Because we can.
|
2017-03-01 15:26:42 +00:00
|
|
|
{"var1, ...[var2]", "", SKIP_STRICT_FUNCTION},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var1, ...[var2]", "() => { var2; };", SKIP_STRICT_FUNCTION},
|
2017-03-01 15:26:42 +00:00
|
|
|
{"var1, ...{0: var2}", "", SKIP_STRICT_FUNCTION},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var1, ...{0: var2}", "() => { var2; };", SKIP_STRICT_FUNCTION},
|
2017-03-01 15:26:42 +00:00
|
|
|
{"var1, ...[]", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"var1, ...{}", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"var1, ...[var2, var3]", "", SKIP_STRICT_FUNCTION},
|
|
|
|
{"var1, ...{0: var2, 1: var3}", "", SKIP_STRICT_FUNCTION},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
|
|
|
// Default parameters for destruring parameters.
|
2017-08-04 09:19:41 +00:00
|
|
|
{"[var1, var2] = [2, 4]", "", SKIP_STRICT_FUNCTION,
|
|
|
|
PreciseMaybeAssigned::NO},
|
|
|
|
{"{var1, var2} = {var1: 3, var2: 3}", "", SKIP_STRICT_FUNCTION,
|
|
|
|
PreciseMaybeAssigned::NO},
|
2017-03-01 15:26:42 +00:00
|
|
|
|
|
|
|
// Default parameters inside destruring parameters.
|
2017-08-04 09:19:41 +00:00
|
|
|
{"[var1 = 4, var2 = var1]", "", SKIP_STRICT_FUNCTION,
|
|
|
|
PreciseMaybeAssigned::NO},
|
|
|
|
{"{var1 = 4, var2 = var1}", "", SKIP_STRICT_FUNCTION,
|
|
|
|
PreciseMaybeAssigned::NO},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
|
|
|
// Locals shadowing parameters.
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var1, var2", "var var1 = 16; () => { var1 = 17; };"},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
|
|
|
// Locals shadowing destructuring parameters and the rest parameter.
|
2017-10-24 11:15:47 +00:00
|
|
|
{"[var1, var2]", "var var1 = 16; () => { var1 = 17; };",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT_FUNCTION},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"{var1, var2}", "var var1 = 16; () => { var1 = 17; };",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT_FUNCTION},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var1, var2, ...var3", "var var3 = 16; () => { var3 = 17; };",
|
2017-02-23 12:27:30 +00:00
|
|
|
SKIP_STRICT_FUNCTION},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var1, var2 = var1", "var var1 = 16; () => { var1 = 17; };",
|
2017-08-04 09:19:41 +00:00
|
|
|
SKIP_STRICT_FUNCTION, PreciseMaybeAssigned::NO},
|
2017-02-17 11:48:36 +00:00
|
|
|
|
|
|
|
// Hoisted sloppy block function shadowing a parameter.
|
2017-03-01 15:26:42 +00:00
|
|
|
// FIXME(marja): why is maybe_assigned inaccurate?
|
2017-08-04 09:19:41 +00:00
|
|
|
{"var1, var2", "for (;;) { function var1() { } }", DONT_SKIP,
|
|
|
|
PreciseMaybeAssigned::NO},
|
2017-02-20 16:01:12 +00:00
|
|
|
|
2017-08-04 09:19:41 +00:00
|
|
|
// Sloppy eval in default parameter.
|
2017-03-01 15:26:42 +00:00
|
|
|
{"var1, var2 = eval(''), var3", "let var4 = 0;", SKIP_STRICT_FUNCTION,
|
2017-08-04 09:19:41 +00:00
|
|
|
Bailout::BAILOUT_IF_OUTER_SLOPPY},
|
2017-02-23 12:27:30 +00:00
|
|
|
{"var1, var2 = eval(''), var3 = eval('')", "let var4 = 0;",
|
2017-08-04 09:19:41 +00:00
|
|
|
SKIP_STRICT_FUNCTION, Bailout::BAILOUT_IF_OUTER_SLOPPY},
|
2017-02-20 16:01:12 +00:00
|
|
|
|
2017-08-04 09:19:41 +00:00
|
|
|
// Sloppy eval in arrow function parameter list which is inside another
|
|
|
|
// arrow function parameter list.
|
2017-03-03 13:53:05 +00:00
|
|
|
{"var1, var2 = (var3, var4 = eval(''), var5) => { let var6; }, var7",
|
2017-08-04 09:19:41 +00:00
|
|
|
"let var8 = 0;", SKIP_STRICT_FUNCTION, Bailout::BAILOUT_IF_OUTER_SLOPPY},
|
|
|
|
|
|
|
|
// Sloppy eval in a function body with non-simple parameters.
|
|
|
|
{"var1 = 1, var2 = 2", "eval('');", SKIP_STRICT_FUNCTION},
|
2017-03-03 13:53:05 +00:00
|
|
|
|
|
|
|
// Catch variable
|
|
|
|
{"try { } catch(var1) { }"},
|
|
|
|
{"try { } catch(var1) { var1; }"},
|
|
|
|
{"try { } catch(var1) { var1 = 3; }"},
|
|
|
|
{"try { } catch(var1) { function f() { var1; } }"},
|
|
|
|
{"try { } catch(var1) { function f() { var1 = 3; } }"},
|
2017-06-23 07:41:10 +00:00
|
|
|
|
|
|
|
{"try { } catch({var1, var2}) { function f() { var1 = 3; } }"},
|
|
|
|
{"try { } catch([var1, var2]) { function f() { var1 = 3; } }"},
|
|
|
|
{"try { } catch({}) { }"},
|
|
|
|
{"try { } catch([]) { }"},
|
2017-03-03 13:53:05 +00:00
|
|
|
|
|
|
|
// Shadowing the catch variable
|
|
|
|
{"try { } catch(var1) { var var1 = 3; }"},
|
|
|
|
{"try { } catch(var1) { var var1 = 3; function f() { var1 = 3; } }"},
|
2017-05-15 13:41:09 +00:00
|
|
|
|
|
|
|
// Classes
|
|
|
|
{"class MyClass {}"},
|
2017-10-24 11:15:47 +00:00
|
|
|
{"var1 = class MyClass {};"},
|
|
|
|
{"var var1 = class MyClass {};"},
|
|
|
|
{"let var1 = class MyClass {};"},
|
|
|
|
{"const var1 = class MyClass {};"},
|
|
|
|
{"var var1 = class {};"},
|
|
|
|
{"let var1 = class {};"},
|
|
|
|
{"const var1 = class {};"},
|
2017-05-16 08:44:40 +00:00
|
|
|
|
2017-05-17 12:46:27 +00:00
|
|
|
{"class MyClass { constructor() {} }"},
|
|
|
|
{"class MyClass { constructor() { var var1; } }"},
|
|
|
|
{"class MyClass { constructor() { var var1 = 11; } }"},
|
|
|
|
{"class MyClass { constructor() { var var1; function foo() { var1 = 11; "
|
|
|
|
"} } }"},
|
|
|
|
|
2017-05-16 08:44:40 +00:00
|
|
|
{"class MyClass { m() {} }"},
|
|
|
|
{"class MyClass { m() { var var1; } }"},
|
|
|
|
{"class MyClass { m() { var var1 = 11; } }"},
|
|
|
|
{"class MyClass { m() { var var1; function foo() { var1 = 11; } } }"},
|
|
|
|
|
|
|
|
{"class MyClass { static m() {} }"},
|
|
|
|
{"class MyClass { static m() { var var1; } }"},
|
|
|
|
{"class MyClass { static m() { var var1 = 11; } }"},
|
|
|
|
{"class MyClass { static m() { var var1; function foo() { var1 = 11; } } "
|
|
|
|
"}"},
|
2017-05-17 12:46:27 +00:00
|
|
|
|
|
|
|
{"class MyBase {} class MyClass extends MyBase {}"},
|
|
|
|
{"class MyClass extends MyBase { constructor() {} }"},
|
|
|
|
{"class MyClass extends MyBase { constructor() { super(); } }"},
|
|
|
|
{"class MyClass extends MyBase { constructor() { var var1; } }"},
|
|
|
|
{"class MyClass extends MyBase { constructor() { var var1 = 11; } }"},
|
|
|
|
{"class MyClass extends MyBase { constructor() { var var1; function "
|
|
|
|
"foo() { var1 = 11; } } }"},
|
|
|
|
|
|
|
|
{"class MyClass extends MyBase { m() {} }"},
|
|
|
|
{"class MyClass extends MyBase { m() { super.foo; } }"},
|
|
|
|
{"class MyClass extends MyBase { m() { var var1; } }"},
|
|
|
|
{"class MyClass extends MyBase { m() { var var1 = 11; } }"},
|
|
|
|
{"class MyClass extends MyBase { m() { var var1; function foo() { var1 = "
|
|
|
|
"11; } } }"},
|
|
|
|
|
|
|
|
{"class MyClass extends MyBase { static m() {} }"},
|
|
|
|
{"class MyClass extends MyBase { static m() { super.foo; } }"},
|
|
|
|
{"class MyClass extends MyBase { static m() { var var1; } }"},
|
|
|
|
{"class MyClass extends MyBase { static m() { var var1 = 11; } }"},
|
|
|
|
{"class MyClass extends MyBase { static m() { var var1; function foo() { "
|
|
|
|
"var1 = 11; } } }"},
|
2017-02-07 10:11:01 +00:00
|
|
|
};
|
|
|
|
|
2017-02-13 12:09:06 +00:00
|
|
|
for (unsigned outer_ix = 0; outer_ix < arraysize(outers); ++outer_ix) {
|
|
|
|
for (unsigned inner_ix = 0; inner_ix < arraysize(inners); ++inner_ix) {
|
2017-02-23 12:27:30 +00:00
|
|
|
if (outers[outer_ix].strict_outer &&
|
2017-03-01 15:26:42 +00:00
|
|
|
(inners[inner_ix].skip & SKIP_STRICT_OUTER)) {
|
2017-02-23 12:27:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (outers[outer_ix].strict_test_function &&
|
2017-03-01 15:26:42 +00:00
|
|
|
(inners[inner_ix].skip & SKIP_STRICT_FUNCTION)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (outers[outer_ix].arrow && (inners[inner_ix].skip & SKIP_ARROW)) {
|
2017-02-17 13:05:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-21 14:13:35 +00:00
|
|
|
const char* code = outers[outer_ix].code;
|
|
|
|
int code_len = Utf8LengthHelper(code);
|
2017-02-13 12:09:06 +00:00
|
|
|
|
|
|
|
int params_len = Utf8LengthHelper(inners[inner_ix].params);
|
|
|
|
int source_len = Utf8LengthHelper(inners[inner_ix].source);
|
2017-06-21 14:13:35 +00:00
|
|
|
int len = code_len + params_len + source_len;
|
2017-02-13 12:09:06 +00:00
|
|
|
|
2017-06-21 14:13:35 +00:00
|
|
|
i::ScopedVector<char> program(len + 1);
|
|
|
|
i::SNPrintF(program, code, inners[inner_ix].params,
|
|
|
|
inners[inner_ix].source);
|
2017-02-13 12:09:06 +00:00
|
|
|
|
2017-10-24 11:15:47 +00:00
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
|
2017-02-13 12:09:06 +00:00
|
|
|
i::Handle<i::String> source =
|
2017-06-21 14:13:35 +00:00
|
|
|
factory->InternalizeUtf8String(program.start());
|
2017-02-13 12:09:06 +00:00
|
|
|
source->PrintOn(stdout);
|
|
|
|
printf("\n");
|
|
|
|
|
2017-10-24 11:15:47 +00:00
|
|
|
// Compile and run the script to get a pointer to the lazy function.
|
|
|
|
v8::Local<v8::Value> v = CompileRun(program.start());
|
|
|
|
i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
|
|
|
|
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
|
|
|
|
i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared());
|
|
|
|
|
2017-08-04 09:19:41 +00:00
|
|
|
if (inners[inner_ix].bailout == Bailout::BAILOUT_IF_OUTER_SLOPPY &&
|
|
|
|
!outers[outer_ix].strict_outer) {
|
2017-10-24 11:15:47 +00:00
|
|
|
CHECK(!shared->HasPreParsedScopeData());
|
2017-08-04 09:19:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-03-07 13:55:05 +00:00
|
|
|
|
2017-10-24 11:15:47 +00:00
|
|
|
CHECK(shared->HasPreParsedScopeData());
|
|
|
|
i::Handle<i::PreParsedScopeData> produced_data_on_heap(
|
|
|
|
i::PreParsedScopeData::cast(shared->preparsed_scope_data()));
|
|
|
|
|
|
|
|
// Parse the lazy function using the scope data.
|
|
|
|
i::ParseInfo using_scope_data(shared);
|
|
|
|
using_scope_data.set_lazy_compile();
|
|
|
|
using_scope_data.consumed_preparsed_scope_data()->SetData(
|
|
|
|
produced_data_on_heap);
|
|
|
|
CHECK(i::parsing::ParseFunction(&using_scope_data, shared, isolate));
|
|
|
|
|
|
|
|
// Verify that we skipped at least one function inside that scope.
|
|
|
|
i::DeclarationScope* scope_with_skipped_functions =
|
|
|
|
using_scope_data.literal()->scope();
|
|
|
|
CHECK(i::ScopeTestHelper::HasSkippedFunctionInside(
|
|
|
|
scope_with_skipped_functions));
|
|
|
|
|
|
|
|
// Do scope allocation (based on the preparsed scope data).
|
|
|
|
i::DeclarationScope::Analyze(&using_scope_data);
|
|
|
|
|
|
|
|
// Parse the lazy function again eagerly to produce baseline data.
|
|
|
|
i::ParseInfo not_using_scope_data(shared);
|
|
|
|
not_using_scope_data.set_lazy_compile();
|
|
|
|
CHECK(i::parsing::ParseFunction(¬_using_scope_data, shared, isolate));
|
|
|
|
|
|
|
|
// Verify that we didn't skip anything (there's no preparsed scope data,
|
|
|
|
// so we cannot skip).
|
|
|
|
i::DeclarationScope* scope_without_skipped_functions =
|
|
|
|
not_using_scope_data.literal()->scope();
|
|
|
|
CHECK(!i::ScopeTestHelper::HasSkippedFunctionInside(
|
|
|
|
scope_without_skipped_functions));
|
|
|
|
|
|
|
|
// Do normal scope allocation.
|
|
|
|
i::DeclarationScope::Analyze(¬_using_scope_data);
|
|
|
|
|
|
|
|
// Verify that scope allocation gave the same results when parsing w/ the
|
|
|
|
// scope data (and skipping functions), and when parsing without.
|
2017-03-07 13:55:05 +00:00
|
|
|
i::ScopeTestHelper::CompareScopes(
|
2017-10-24 11:15:47 +00:00
|
|
|
scope_without_skipped_functions, scope_with_skipped_functions,
|
2017-08-04 09:19:41 +00:00
|
|
|
inners[inner_ix].precise_maybe_assigned == PreciseMaybeAssigned::YES);
|
2017-02-13 12:09:06 +00:00
|
|
|
}
|
2017-02-07 10:11:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-11 07:55:01 +00:00
|
|
|
|
|
|
|
// Regression test for
|
|
|
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=753896. Should not
|
|
|
|
// crash.
|
|
|
|
TEST(Regress753896) {
|
2017-08-16 08:19:06 +00:00
|
|
|
i::FLAG_preparser_scope_analysis = true;
|
2017-08-11 07:55:01 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
i::Factory* factory = isolate->factory();
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
LocalContext env;
|
|
|
|
|
|
|
|
i::Handle<i::String> source = factory->InternalizeUtf8String(
|
|
|
|
"function lazy() { let v = 0; if (true) { var v = 0; } }");
|
|
|
|
i::Handle<i::Script> script = factory->NewScript(source);
|
|
|
|
i::ParseInfo info(script);
|
|
|
|
|
|
|
|
// We don't assert that parsing succeeded or that it failed; currently the
|
|
|
|
// error is not detected inside lazy functions, but it might be in the future.
|
|
|
|
i::parsing::ParseProgram(&info, isolate);
|
|
|
|
}
|
2017-09-29 12:58:14 +00:00
|
|
|
|
|
|
|
TEST(ProducingAndConsumingByteData) {
|
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
LocalContext env;
|
|
|
|
|
|
|
|
i::Zone zone(isolate->allocator(), ZONE_NAME);
|
|
|
|
i::ProducedPreParsedScopeData::ByteData bytes(&zone);
|
|
|
|
// Write some data.
|
|
|
|
bytes.WriteUint32(1983); // This will be overwritten.
|
|
|
|
bytes.WriteUint32(2147483647);
|
|
|
|
bytes.WriteUint8(4);
|
|
|
|
bytes.WriteUint8(255);
|
|
|
|
bytes.WriteUint32(0);
|
|
|
|
bytes.WriteUint8(0);
|
|
|
|
bytes.OverwriteFirstUint32(2017);
|
|
|
|
bytes.WriteUint8(100);
|
2017-10-24 11:15:47 +00:00
|
|
|
// Write quarter bytes between uint8s and uint32s to verify they're stored
|
|
|
|
// correctly.
|
|
|
|
bytes.WriteQuarter(3);
|
|
|
|
bytes.WriteQuarter(0);
|
|
|
|
bytes.WriteQuarter(2);
|
|
|
|
bytes.WriteQuarter(1);
|
|
|
|
bytes.WriteQuarter(0);
|
|
|
|
bytes.WriteUint8(50);
|
|
|
|
bytes.WriteQuarter(0);
|
|
|
|
bytes.WriteQuarter(1);
|
|
|
|
bytes.WriteQuarter(2);
|
|
|
|
bytes.WriteUint32(50);
|
|
|
|
// End with a lonely quarter.
|
|
|
|
bytes.WriteQuarter(2);
|
2017-09-29 12:58:14 +00:00
|
|
|
|
|
|
|
i::Handle<i::PodArray<uint8_t>> data_on_heap = bytes.Serialize(isolate);
|
|
|
|
i::ConsumedPreParsedScopeData::ByteData bytes_for_reading;
|
|
|
|
i::ConsumedPreParsedScopeData::ByteData::ReadingScope reading_scope(
|
|
|
|
&bytes_for_reading, *data_on_heap);
|
|
|
|
|
|
|
|
// Read the data back.
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint32(), 2017);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint32(), 2147483647);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint8(), 4);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint8(), 255);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint32(), 0);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint8(), 0);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint8(), 100);
|
2017-10-24 11:15:47 +00:00
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 3);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 1);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint8(), 50);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 0);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 1);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadUint32(), 50);
|
|
|
|
CHECK_EQ(bytes_for_reading.ReadQuarter(), 2);
|
2017-09-29 12:58:14 +00:00
|
|
|
}
|