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

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

Issue 958213006: Create ImportDeclarations for default imports. (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/parser.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 5201 matching lines...) Expand 10 before | Expand all | Expand 10 after
5212 TEST(ModuleParsingInternals) { 5212 TEST(ModuleParsingInternals) {
5213 i::Isolate* isolate = CcTest::i_isolate(); 5213 i::Isolate* isolate = CcTest::i_isolate();
5214 i::Factory* factory = isolate->factory(); 5214 i::Factory* factory = isolate->factory();
5215 v8::HandleScope handles(CcTest::isolate()); 5215 v8::HandleScope handles(CcTest::isolate());
5216 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 5216 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5217 v8::Context::Scope context_scope(context); 5217 v8::Context::Scope context_scope(context);
5218 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5218 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5219 128 * 1024); 5219 128 * 1024);
5220 5220
5221 static const char kSource[] = 5221 static const char kSource[] =
5222 "let x = 5; export { x as y }; import { q as z } from 'm.js';"; 5222 "let x = 5;"
5223 "export { x as y };"
5224 "import { q as z } from 'm.js';"
5225 "import n from 'n.js'";
5223 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5226 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5224 i::Handle<i::Script> script = factory->NewScript(source); 5227 i::Handle<i::Script> script = factory->NewScript(source);
5225 i::CompilationInfoWithZone info(script); 5228 i::CompilationInfoWithZone info(script);
5226 i::Parser parser(&info, isolate->stack_guard()->real_climit(), 5229 i::Parser parser(&info, isolate->stack_guard()->real_climit(),
5227 isolate->heap()->HashSeed(), isolate->unicode_cache()); 5230 isolate->heap()->HashSeed(), isolate->unicode_cache());
5228 parser.set_allow_harmony_modules(true); 5231 parser.set_allow_harmony_modules(true);
5229 parser.set_allow_harmony_scoping(true); 5232 parser.set_allow_harmony_scoping(true);
5230 info.MarkAsModule(); 5233 info.MarkAsModule();
5231 CHECK(parser.Parse(&info)); 5234 CHECK(parser.Parse(&info));
5232 i::FunctionLiteral* func = info.function(); 5235 i::FunctionLiteral* func = info.function();
5233 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type()); 5236 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type());
5234 i::ModuleDescriptor* descriptor = func->scope()->module(); 5237 i::ModuleDescriptor* descriptor = func->scope()->module();
5235 CHECK_NOT_NULL(descriptor); 5238 CHECK_NOT_NULL(descriptor);
5236 int num_exports = 0; 5239 int num_exports = 0;
5237 for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { 5240 for (auto it = descriptor->iterator(); !it.done(); it.Advance()) {
5238 ++num_exports; 5241 ++num_exports;
5239 CHECK(it.local_name()->IsOneByteEqualTo("x")); 5242 CHECK(it.local_name()->IsOneByteEqualTo("x"));
5240 CHECK(it.export_name()->IsOneByteEqualTo("y")); 5243 CHECK(it.export_name()->IsOneByteEqualTo("y"));
5241 } 5244 }
5242 CHECK_EQ(1, num_exports); 5245 CHECK_EQ(1, num_exports);
5243 i::ZoneList<i::Declaration*>* declarations = func->scope()->declarations(); 5246 i::ZoneList<i::Declaration*>* declarations = func->scope()->declarations();
5244 CHECK_EQ(2, declarations->length()); 5247 CHECK_EQ(3, declarations->length());
5245 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); 5248 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5246 i::ImportDeclaration* import_decl = 5249 i::ImportDeclaration* import_decl =
5247 declarations->at(1)->AsImportDeclaration(); 5250 declarations->at(1)->AsImportDeclaration();
5248 CHECK(import_decl->import_name()->IsOneByteEqualTo("q")); 5251 CHECK(import_decl->import_name()->IsOneByteEqualTo("q"));
5249 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z")); 5252 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z"));
5250 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js")); 5253 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js"));
5254 import_decl = declarations->at(2)->AsImportDeclaration();
5255 CHECK(import_decl->import_name()->IsOneByteEqualTo("default"));
5256 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("n"));
5257 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("n.js"));
5251 } 5258 }
5252 5259
5253 5260
5254 TEST(DuplicateProtoError) { 5261 TEST(DuplicateProtoError) {
5255 const char* context_data[][2] = { 5262 const char* context_data[][2] = {
5256 {"({", "});"}, 5263 {"({", "});"},
5257 {"'use strict'; ({", "});"}, 5264 {"'use strict'; ({", "});"},
5258 {NULL, NULL} 5265 {NULL, NULL}
5259 }; 5266 };
5260 const char* error_data[] = { 5267 const char* error_data[] = {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
5538 static const ParserFlag always_flags[] = { 5545 static const ParserFlag always_flags[] = {
5539 kAllowStrongMode, kAllowHarmonyScoping 5546 kAllowStrongMode, kAllowHarmonyScoping
5540 }; 5547 };
5541 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, 5548 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
5542 arraysize(always_flags)); 5549 arraysize(always_flags));
5543 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5550 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5544 arraysize(always_flags)); 5551 arraysize(always_flags));
5545 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5552 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5546 arraysize(always_flags)); 5553 arraysize(always_flags));
5547 } 5554 }
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698