OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3843 TestMaybeAssigned(input, "foo", false, allow_lazy_parsing); | 3843 TestMaybeAssigned(input, "foo", false, allow_lazy_parsing); |
3844 } | 3844 } |
3845 TestMaybeAssigned(wrap(input), "foo", false, false); | 3845 TestMaybeAssigned(wrap(input), "foo", false, false); |
3846 } | 3846 } |
3847 } | 3847 } |
3848 | 3848 |
3849 TEST(MaybeAssignedTopLevel) { | 3849 TEST(MaybeAssignedTopLevel) { |
3850 i::Isolate* isolate = CcTest::i_isolate(); | 3850 i::Isolate* isolate = CcTest::i_isolate(); |
3851 i::HandleScope scope(isolate); | 3851 i::HandleScope scope(isolate); |
3852 LocalContext env; | 3852 LocalContext env; |
3853 i::Factory* factory = isolate->factory(); | |
3854 | 3853 |
3855 const char* prefixes[] = { | 3854 const char* prefixes[] = { |
3856 "let foo; ", | 3855 "let foo; ", |
3857 "let foo = 0; ", | 3856 "let foo = 0; ", |
3858 "let [foo] = [1]; ", | 3857 "let [foo] = [1]; ", |
3859 "let {foo} = {foo: 2}; ", | 3858 "let {foo} = {foo: 2}; ", |
3860 "let {foo=3} = {}; ", | 3859 "let {foo=3} = {}; ", |
3861 "var foo; ", | 3860 "var foo; ", |
3862 "var foo = 0; ", | 3861 "var foo = 0; ", |
3863 "var [foo] = [1]; ", | 3862 "var [foo] = [1]; ", |
3864 "var {foo} = {foo: 2}; ", | 3863 "var {foo} = {foo: 2}; ", |
3865 "var {foo=3} = {}; ", | 3864 "var {foo=3} = {}; ", |
| 3865 "{ var foo; }; ", |
| 3866 "{ var foo = 0; }; ", |
| 3867 "{ var [foo] = [1]; }; ", |
| 3868 "{ var {foo} = {foo: 2}; }; ", |
| 3869 "{ var {foo=3} = {}; }; ", |
3866 "function foo() {}; ", | 3870 "function foo() {}; ", |
3867 "function* foo() {}; ", | 3871 "function* foo() {}; ", |
3868 "async function foo() {}; ", | 3872 "async function foo() {}; ", |
3869 "class foo {}; ", | 3873 "class foo {}; ", |
3870 "class foo extends null {}; ", | 3874 "class foo extends null {}; ", |
3871 }; | 3875 }; |
3872 const char* sources[] = { | 3876 |
| 3877 const char* module_and_script_tests[] = { |
3873 "function bar() {foo = 42}; ext(bar); ext(foo)", | 3878 "function bar() {foo = 42}; ext(bar); ext(foo)", |
3874 "ext(function() {foo++}); ext(foo)", | 3879 "ext(function() {foo++}); ext(foo)", |
3875 "bar = () => --foo; ext(bar); ext(foo)", | 3880 "bar = () => --foo; ext(bar); ext(foo)", |
3876 "function* bar() {eval(ext)}; ext(bar); ext(foo)", | 3881 "function* bar() {eval(ext)}; ext(bar); ext(foo)", |
3877 }; | 3882 }; |
3878 | 3883 |
| 3884 const char* script_only_tests[] = { |
| 3885 "", |
| 3886 "{ function foo() {}; }; ", |
| 3887 "{ function* foo() {}; }; ", |
| 3888 "{ async function foo() {}; }; ", |
| 3889 }; |
| 3890 |
3879 for (unsigned i = 0; i < arraysize(prefixes); ++i) { | 3891 for (unsigned i = 0; i < arraysize(prefixes); ++i) { |
3880 const char* prefix = prefixes[i]; | 3892 for (unsigned j = 0; j < arraysize(module_and_script_tests); ++j) { |
3881 for (unsigned j = 0; j < arraysize(sources); ++j) { | 3893 std::string source(prefixes[i]); |
3882 const char* source = sources[j]; | 3894 source += module_and_script_tests[j]; |
3883 i::ScopedVector<char> program(Utf8LengthHelper(prefix) + | 3895 std::vector<unsigned> top; |
3884 Utf8LengthHelper(source) + 1); | 3896 Input input({true, source, top}); |
3885 i::SNPrintF(program, "%s%s", prefix, source); | 3897 for (unsigned module = 0; module <= 1; ++module) { |
| 3898 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; |
| 3899 ++allow_lazy_parsing) { |
| 3900 TestMaybeAssigned(input, "foo", module, allow_lazy_parsing); |
| 3901 } |
| 3902 } |
| 3903 } |
| 3904 } |
3886 | 3905 |
3887 i::Handle<i::String> string = | 3906 for (unsigned i = 0; i < arraysize(prefixes); ++i) { |
3888 factory->InternalizeUtf8String(program.start()); | 3907 for (unsigned j = 0; j < arraysize(script_only_tests); ++j) { |
3889 string->PrintOn(stdout); | 3908 std::string source(prefixes[i]); |
3890 printf("\n"); | 3909 source += script_only_tests[j]; |
3891 i::Handle<i::Script> script = factory->NewScript(string); | 3910 std::vector<unsigned> top; |
3892 | 3911 Input input({true, source, top}); |
3893 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { | 3912 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; |
3894 for (unsigned module = 0; module < 2; ++module) { | 3913 ++allow_lazy_parsing) { |
3895 std::unique_ptr<i::ParseInfo> info; | 3914 TestMaybeAssigned(input, "foo", false, allow_lazy_parsing); |
3896 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); | |
3897 info->set_module(module); | |
3898 info->set_allow_lazy_parsing(allow_lazy); | |
3899 | |
3900 CHECK(i::parsing::ParseProgram(info.get())); | |
3901 CHECK(i::Compiler::Analyze(info.get())); | |
3902 | |
3903 CHECK_NOT_NULL(info->literal()); | |
3904 i::Scope* scope = info->literal()->scope(); | |
3905 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | |
3906 CHECK_NULL(scope->sibling()); | |
3907 CHECK(module ? scope->is_module_scope() : scope->is_script_scope()); | |
3908 | |
3909 const i::AstRawString* var_name = | |
3910 info->ast_value_factory()->GetOneByteString("foo"); | |
3911 i::Variable* var = scope->Lookup(var_name); | |
3912 CHECK(var->is_used()); | |
3913 CHECK(var->maybe_assigned() == i::kMaybeAssigned); | |
3914 } | |
3915 } | 3915 } |
3916 } | 3916 } |
3917 } | 3917 } |
3918 } | 3918 } |
3919 | 3919 |
3920 namespace { | 3920 namespace { |
3921 | 3921 |
3922 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, | 3922 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, |
3923 i::Handle<i::JSObject> m, const char* name) { | 3923 i::Handle<i::JSObject> m, const char* name) { |
3924 i::AstValueFactory avf(zone, isolate->ast_string_constants(), | 3924 i::AstValueFactory avf(zone, isolate->ast_string_constants(), |
(...skipping 5517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9442 DCHECK_NULL(scope->sibling()); | 9442 DCHECK_NULL(scope->sibling()); |
9443 DCHECK(scope->is_function_scope()); | 9443 DCHECK(scope->is_function_scope()); |
9444 const i::AstRawString* var_name = | 9444 const i::AstRawString* var_name = |
9445 info.ast_value_factory()->GetOneByteString("my_var"); | 9445 info.ast_value_factory()->GetOneByteString("my_var"); |
9446 i::Variable* var = scope->Lookup(var_name); | 9446 i::Variable* var = scope->Lookup(var_name); |
9447 CHECK_EQ(inners[i].ctxt_allocate, | 9447 CHECK_EQ(inners[i].ctxt_allocate, |
9448 i::ScopeTestHelper::MustAllocateInContext(var)); | 9448 i::ScopeTestHelper::MustAllocateInContext(var)); |
9449 } | 9449 } |
9450 } | 9450 } |
9451 } | 9451 } |
OLD | NEW |