Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1169)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 999893003: Modules: simplify logic around allocation of module internal variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/scopes.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 5202 matching lines...) Expand 10 before | Expand all | Expand 10 after
5213 parser.set_allow_harmony_classes(true); 5213 parser.set_allow_harmony_classes(true);
5214 parser.set_allow_harmony_modules(true); 5214 parser.set_allow_harmony_modules(true);
5215 parser.set_allow_harmony_scoping(true); 5215 parser.set_allow_harmony_scoping(true);
5216 info.set_module(); 5216 info.set_module();
5217 CHECK(!parser.Parse(&info)); 5217 CHECK(!parser.Parse(&info));
5218 } 5218 }
5219 } 5219 }
5220 5220
5221 5221
5222 TEST(ModuleParsingInternals) { 5222 TEST(ModuleParsingInternals) {
5223 i::FLAG_harmony_modules = true;
5224
5223 i::Isolate* isolate = CcTest::i_isolate(); 5225 i::Isolate* isolate = CcTest::i_isolate();
5224 i::Factory* factory = isolate->factory(); 5226 i::Factory* factory = isolate->factory();
5225 v8::HandleScope handles(CcTest::isolate()); 5227 v8::HandleScope handles(CcTest::isolate());
5226 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 5228 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5227 v8::Context::Scope context_scope(context); 5229 v8::Context::Scope context_scope(context);
5228 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5230 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5229 128 * 1024); 5231 128 * 1024);
5230 5232
5231 static const char kSource[] = 5233 static const char kSource[] =
5232 "let x = 5;" 5234 "let x = 5;"
5233 "export { x as y };" 5235 "export { x as y };"
5234 "import { q as z } from 'm.js';" 5236 "import { q as z } from 'm.js';"
5235 "import n from 'n.js'"; 5237 "import n from 'n.js'";
5236 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5238 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5237 i::Handle<i::Script> script = factory->NewScript(source); 5239 i::Handle<i::Script> script = factory->NewScript(source);
5238 i::Zone zone; 5240 i::Zone zone;
5239 i::ParseInfo info(&zone); 5241 i::ParseInfo info(&zone);
5240 info.InitializeFromScript(script); 5242 info.InitializeFromScript(script);
5241 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); 5243 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
5242 i::Parser parser(&info); 5244 i::Parser parser(&info);
5243 parser.set_allow_harmony_modules(true); 5245 parser.set_allow_harmony_modules(true);
5244 parser.set_allow_harmony_scoping(true); 5246 parser.set_allow_harmony_scoping(true);
5245 info.set_module(); 5247 info.set_module();
5246 CHECK(parser.Parse(&info)); 5248 CHECK(parser.Parse(&info));
5249 CHECK(i::Compiler::Analyze(&info));
5250
5247 i::FunctionLiteral* func = info.function(); 5251 i::FunctionLiteral* func = info.function();
5248 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type()); 5252 i::Scope* module_scope = func->scope();
5249 i::ModuleDescriptor* descriptor = func->scope()->module(); 5253 i::Scope* outer_scope = module_scope->outer_scope();
5254 CHECK(outer_scope->is_script_scope());
5255 CHECK_NULL(outer_scope->outer_scope());
5256 CHECK_EQ(1, outer_scope->num_modules());
5257 CHECK(module_scope->is_module_scope());
5258 CHECK_NOT_NULL(module_scope->module_var());
5259 CHECK_EQ(i::INTERNAL, module_scope->module_var()->mode());
5260
5261 i::ModuleDescriptor* descriptor = module_scope->module();
5250 CHECK_NOT_NULL(descriptor); 5262 CHECK_NOT_NULL(descriptor);
5251 CHECK_EQ(1, descriptor->Length()); 5263 CHECK_EQ(1, descriptor->Length());
5252 const i::AstRawString* export_name = avf.GetOneByteString("y"); 5264 const i::AstRawString* export_name = avf.GetOneByteString("y");
5253 const i::AstRawString* local_name = 5265 const i::AstRawString* local_name =
5254 descriptor->LookupLocalExport(export_name, &zone); 5266 descriptor->LookupLocalExport(export_name, &zone);
5255 CHECK_NOT_NULL(local_name); 5267 CHECK_NOT_NULL(local_name);
5256 CHECK(local_name->IsOneByteEqualTo("x")); 5268 CHECK(local_name->IsOneByteEqualTo("x"));
5257 i::ZoneList<i::Declaration*>* declarations = func->scope()->declarations(); 5269 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
5258 CHECK_EQ(3, declarations->length()); 5270 CHECK_EQ(3, declarations->length());
5259 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); 5271 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5260 i::ImportDeclaration* import_decl = 5272 i::ImportDeclaration* import_decl =
5261 declarations->at(1)->AsImportDeclaration(); 5273 declarations->at(1)->AsImportDeclaration();
5262 CHECK(import_decl->import_name()->IsOneByteEqualTo("q")); 5274 CHECK(import_decl->import_name()->IsOneByteEqualTo("q"));
5263 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z")); 5275 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z"));
5264 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js")); 5276 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js"));
5265 import_decl = declarations->at(2)->AsImportDeclaration(); 5277 import_decl = declarations->at(2)->AsImportDeclaration();
5266 CHECK(import_decl->import_name()->IsOneByteEqualTo("default")); 5278 CHECK(import_decl->import_name()->IsOneByteEqualTo("default"));
5267 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("n")); 5279 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("n"));
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
5575 "(a/*\n*/=> a)(1)", 5587 "(a/*\n*/=> a)(1)",
5576 "((a)\n=> a)(1)", 5588 "((a)\n=> a)(1)",
5577 "((a)/*\n*/=> a)(1)", 5589 "((a)/*\n*/=> a)(1)",
5578 "((a, b)\n=> a + b)(1, 2)", 5590 "((a, b)\n=> a + b)(1, 2)",
5579 "((a, b)/*\n*/=> a + b)(1, 2)", 5591 "((a, b)/*\n*/=> a + b)(1, 2)",
5580 NULL}; 5592 NULL};
5581 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 5593 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
5582 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 5594 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
5583 arraysize(always_flags)); 5595 arraysize(always_flags));
5584 } 5596 }
OLDNEW
« no previous file with comments | « src/scopes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698