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 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 i::Handle<i::Script> script = factory->NewScript(source); | 1113 i::Handle<i::Script> script = factory->NewScript(source); |
1114 i::Zone zone(CcTest::i_isolate()->allocator()); | 1114 i::Zone zone(CcTest::i_isolate()->allocator()); |
1115 i::ParseInfo info(&zone, script); | 1115 i::ParseInfo info(&zone, script); |
1116 i::Parser parser(&info); | 1116 i::Parser parser(&info); |
1117 info.set_global(); | 1117 info.set_global(); |
1118 CHECK(parser.Parse(&info)); | 1118 CHECK(parser.Parse(&info)); |
1119 CHECK(i::Rewriter::Rewrite(&info)); | 1119 CHECK(i::Rewriter::Rewrite(&info)); |
1120 CHECK(i::Scope::Analyze(&info)); | 1120 CHECK(i::Scope::Analyze(&info)); |
1121 CHECK(info.literal() != NULL); | 1121 CHECK(info.literal() != NULL); |
1122 | 1122 |
1123 i::Scope* script_scope = info.literal()->scope(); | 1123 i::DeclarationScope* script_scope = info.literal()->scope(); |
1124 CHECK(script_scope->is_script_scope()); | 1124 CHECK(script_scope->is_script_scope()); |
1125 | 1125 |
1126 i::Scope* scope = script_scope->inner_scope(); | 1126 i::Scope* scope = script_scope->inner_scope(); |
1127 DCHECK_NOT_NULL(scope); | 1127 DCHECK_NOT_NULL(scope); |
1128 DCHECK_NULL(scope->sibling()); | 1128 DCHECK_NULL(scope->sibling()); |
1129 // Adjust for constructor scope. | 1129 // Adjust for constructor scope. |
1130 if (j == 2) { | 1130 if (j == 2) { |
1131 scope = scope->inner_scope(); | 1131 scope = scope->inner_scope(); |
1132 DCHECK_NOT_NULL(scope); | 1132 DCHECK_NOT_NULL(scope); |
1133 DCHECK_NULL(scope->sibling()); | 1133 DCHECK_NULL(scope->sibling()); |
1134 } | 1134 } |
1135 // Arrows themselves never get an arguments object. | 1135 // Arrows themselves never get an arguments object. |
1136 if ((source_data[i].expected & ARGUMENTS) != 0 && | 1136 if ((source_data[i].expected & ARGUMENTS) != 0 && |
1137 !scope->is_arrow_scope()) { | 1137 !scope->AsDeclarationScope()->is_arrow_scope()) { |
1138 CHECK_NOT_NULL(scope->arguments()); | 1138 CHECK_NOT_NULL(scope->AsDeclarationScope()->arguments()); |
1139 } | 1139 } |
1140 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, | 1140 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, |
1141 scope->uses_super_property()); | 1141 scope->uses_super_property()); |
1142 if ((source_data[i].expected & THIS) != 0) { | 1142 if ((source_data[i].expected & THIS) != 0) { |
1143 // Currently the is_used() flag is conservative; all variables in a | 1143 // Currently the is_used() flag is conservative; all variables in a |
1144 // script scope are marked as used. | 1144 // script scope are marked as used. |
1145 CHECK( | 1145 CHECK( |
1146 scope->Lookup(info.ast_value_factory()->this_string())->is_used()); | 1146 scope->Lookup(info.ast_value_factory()->this_string())->is_used()); |
1147 } | 1147 } |
1148 CHECK_EQ((source_data[i].expected & EVAL) != 0, scope->calls_eval()); | 1148 CHECK_EQ((source_data[i].expected & EVAL) != 0, scope->calls_eval()); |
(...skipping 2236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3385 i::Zone zone(CcTest::i_isolate()->allocator()); | 3385 i::Zone zone(CcTest::i_isolate()->allocator()); |
3386 v8::Local<v8::Value> v = CompileRun(src); | 3386 v8::Local<v8::Value> v = CompileRun(src); |
3387 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3387 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
3388 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3388 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
3389 i::Context* context = f->context(); | 3389 i::Context* context = f->context(); |
3390 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); | 3390 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); |
3391 avf.Internalize(isolate); | 3391 avf.Internalize(isolate); |
3392 const i::AstRawString* name = avf.GetOneByteString("result"); | 3392 const i::AstRawString* name = avf.GetOneByteString("result"); |
3393 i::Handle<i::String> str = name->string(); | 3393 i::Handle<i::String> str = name->string(); |
3394 CHECK(str->IsInternalizedString()); | 3394 CHECK(str->IsInternalizedString()); |
3395 i::Scope* script_scope = | 3395 i::DeclarationScope* script_scope = |
3396 new (&zone) i::Scope(&zone, nullptr, i::SCRIPT_SCOPE); | 3396 new (&zone) i::DeclarationScope(&zone, nullptr, i::SCRIPT_SCOPE); |
3397 i::Scope* s = i::Scope::DeserializeScopeChain( | 3397 i::Scope* s = i::Scope::DeserializeScopeChain( |
3398 isolate, &zone, context, script_scope, &avf, | 3398 isolate, &zone, context, script_scope, &avf, |
3399 i::Scope::DeserializationMode::kKeepScopeInfo); | 3399 i::Scope::DeserializationMode::kKeepScopeInfo); |
3400 CHECK(s != script_scope); | 3400 CHECK(s != script_scope); |
3401 CHECK(name != NULL); | 3401 CHECK(name != NULL); |
3402 | 3402 |
3403 // Get result from h's function context (that is f's context) | 3403 // Get result from h's function context (that is f's context) |
3404 i::Variable* var = s->Lookup(name); | 3404 i::Variable* var = s->Lookup(name); |
3405 | 3405 |
3406 CHECK(var != NULL); | 3406 CHECK(var != NULL); |
(...skipping 26 matching lines...) Expand all Loading... |
3433 source->PrintOn(stdout); | 3433 source->PrintOn(stdout); |
3434 printf("\n"); | 3434 printf("\n"); |
3435 i::Zone zone(CcTest::i_isolate()->allocator()); | 3435 i::Zone zone(CcTest::i_isolate()->allocator()); |
3436 v8::Local<v8::Value> v = CompileRun(src); | 3436 v8::Local<v8::Value> v = CompileRun(src); |
3437 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); | 3437 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); |
3438 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); | 3438 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); |
3439 i::Context* context = f->context(); | 3439 i::Context* context = f->context(); |
3440 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); | 3440 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); |
3441 avf.Internalize(isolate); | 3441 avf.Internalize(isolate); |
3442 | 3442 |
3443 i::Scope* script_scope = | 3443 i::DeclarationScope* script_scope = |
3444 new (&zone) i::Scope(&zone, nullptr, i::SCRIPT_SCOPE); | 3444 new (&zone) i::DeclarationScope(&zone, nullptr, i::SCRIPT_SCOPE); |
3445 i::Scope* s = i::Scope::DeserializeScopeChain( | 3445 i::Scope* s = i::Scope::DeserializeScopeChain( |
3446 isolate, &zone, context, script_scope, &avf, | 3446 isolate, &zone, context, script_scope, &avf, |
3447 i::Scope::DeserializationMode::kKeepScopeInfo); | 3447 i::Scope::DeserializationMode::kKeepScopeInfo); |
3448 CHECK(s != script_scope); | 3448 CHECK(s != script_scope); |
3449 const i::AstRawString* name_x = avf.GetOneByteString("x"); | 3449 const i::AstRawString* name_x = avf.GetOneByteString("x"); |
3450 | 3450 |
3451 // Get result from f's function context (that is g's outer context) | 3451 // Get result from f's function context (that is g's outer context) |
3452 i::Variable* var_x = s->Lookup(name_x); | 3452 i::Variable* var_x = s->Lookup(name_x); |
3453 CHECK(var_x != NULL); | 3453 CHECK(var_x != NULL); |
3454 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned); | 3454 CHECK(var_x->maybe_assigned() == i::kMaybeAssigned); |
(...skipping 2480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5935 "import 'q.js'"; | 5935 "import 'q.js'"; |
5936 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); | 5936 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); |
5937 i::Handle<i::Script> script = factory->NewScript(source); | 5937 i::Handle<i::Script> script = factory->NewScript(source); |
5938 i::Zone zone(CcTest::i_isolate()->allocator()); | 5938 i::Zone zone(CcTest::i_isolate()->allocator()); |
5939 i::ParseInfo info(&zone, script); | 5939 i::ParseInfo info(&zone, script); |
5940 i::Parser parser(&info); | 5940 i::Parser parser(&info); |
5941 info.set_module(); | 5941 info.set_module(); |
5942 CHECK(parser.Parse(&info)); | 5942 CHECK(parser.Parse(&info)); |
5943 CHECK(i::Compiler::Analyze(&info)); | 5943 CHECK(i::Compiler::Analyze(&info)); |
5944 i::FunctionLiteral* func = info.literal(); | 5944 i::FunctionLiteral* func = info.literal(); |
5945 i::Scope* module_scope = func->scope(); | 5945 i::DeclarationScope* module_scope = func->scope(); |
5946 i::Scope* outer_scope = module_scope->outer_scope(); | 5946 i::Scope* outer_scope = module_scope->outer_scope(); |
5947 CHECK(outer_scope->is_script_scope()); | 5947 CHECK(outer_scope->is_script_scope()); |
5948 CHECK_NULL(outer_scope->outer_scope()); | 5948 CHECK_NULL(outer_scope->outer_scope()); |
5949 CHECK(module_scope->is_module_scope()); | 5949 CHECK(module_scope->is_module_scope()); |
5950 i::ModuleDescriptor* descriptor = module_scope->module(); | 5950 i::ModuleDescriptor* descriptor = module_scope->module(); |
5951 CHECK_NOT_NULL(descriptor); | 5951 CHECK_NOT_NULL(descriptor); |
5952 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); | 5952 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); |
5953 CHECK_EQ(8, declarations->length()); | 5953 CHECK_EQ(8, declarations->length()); |
5954 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); | 5954 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); |
5955 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); | 5955 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); |
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7984 "(a,);", | 7984 "(a,);", |
7985 "(a,b,c,);", | 7985 "(a,b,c,);", |
7986 NULL | 7986 NULL |
7987 }; | 7987 }; |
7988 // clang-format on | 7988 // clang-format on |
7989 | 7989 |
7990 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 7990 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; |
7991 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 7991 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
7992 arraysize(always_flags)); | 7992 arraysize(always_flags)); |
7993 } | 7993 } |
OLD | NEW |