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

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

Issue 948303004: Re-introduce ImportDeclaration to the parser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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
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 5200 matching lines...) Expand 10 before | Expand all | Expand 10 after
5211 5211
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[] = "let x = 5; export { x as y };"; 5221 static const char kSource[] =
5222 "let x = 5; export { x as y }; import { q as z } from 'm.js';";
5222 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5223 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5223 i::Handle<i::Script> script = factory->NewScript(source); 5224 i::Handle<i::Script> script = factory->NewScript(source);
5224 i::CompilationInfoWithZone info(script); 5225 i::CompilationInfoWithZone info(script);
5225 i::AstValueFactory avf(info.zone(), isolate->heap()->HashSeed());
5226 i::Parser parser(&info, isolate->stack_guard()->real_climit(), 5226 i::Parser parser(&info, isolate->stack_guard()->real_climit(),
5227 isolate->heap()->HashSeed(), isolate->unicode_cache()); 5227 isolate->heap()->HashSeed(), isolate->unicode_cache());
5228 parser.set_allow_harmony_modules(true); 5228 parser.set_allow_harmony_modules(true);
5229 parser.set_allow_harmony_scoping(true); 5229 parser.set_allow_harmony_scoping(true);
5230 info.MarkAsModule(); 5230 info.MarkAsModule();
5231 CHECK(parser.Parse(&info)); 5231 CHECK(parser.Parse(&info));
5232 i::FunctionLiteral* func = info.function(); 5232 i::FunctionLiteral* func = info.function();
5233 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type()); 5233 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type());
5234 i::ModuleDescriptor* descriptor = func->scope()->module(); 5234 i::ModuleDescriptor* descriptor = func->scope()->module();
5235 CHECK_NOT_NULL(descriptor); 5235 CHECK_NOT_NULL(descriptor);
5236 const i::AstRawString* name_x = avf.GetOneByteString("x");
5237 const i::AstRawString* name_y = avf.GetOneByteString("y");
5238 int num_exports = 0; 5236 int num_exports = 0;
5239 for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { 5237 for (auto it = descriptor->iterator(); !it.done(); it.Advance()) {
5240 ++num_exports; 5238 ++num_exports;
5241 CHECK(*name_x == *it.local_name()); 5239 CHECK(it.local_name()->IsOneByteEqualTo("x"));
5242 CHECK(*name_y == *it.export_name()); 5240 CHECK(it.export_name()->IsOneByteEqualTo("y"));
5243 } 5241 }
5244 CHECK_EQ(1, num_exports); 5242 CHECK_EQ(1, num_exports);
5243 i::ZoneList<i::Declaration*>* declarations = func->scope()->declarations();
5244 CHECK_EQ(2, declarations->length());
5245 for (int i = 0; i < declarations->length(); ++i) {
5246 i::ImportDeclaration* decl = declarations->at(i)->AsImportDeclaration();
arv (Not doing code reviews) 2015/02/25 16:07:25 Maybe remove the loop and check x and z separately
adamk 2015/02/25 21:43:12 Done.
5247 if (decl != NULL) {
5248 CHECK(decl->import_name()->IsOneByteEqualTo("q"));
5249 CHECK(decl->proxy()->raw_name()->IsOneByteEqualTo("z"));
5250 CHECK(decl->module_specifier()->IsOneByteEqualTo("m.js"));
5251 }
5252 }
5245 } 5253 }
5246 5254
5247 5255
5248 TEST(DuplicateProtoError) { 5256 TEST(DuplicateProtoError) {
5249 const char* context_data[][2] = { 5257 const char* context_data[][2] = {
5250 {"({", "});"}, 5258 {"({", "});"},
5251 {"'use strict'; ({", "});"}, 5259 {"'use strict'; ({", "});"},
5252 {NULL, NULL} 5260 {NULL, NULL}
5253 }; 5261 };
5254 const char* error_data[] = { 5262 const char* error_data[] = {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
5532 static const ParserFlag always_flags[] = { 5540 static const ParserFlag always_flags[] = {
5533 kAllowStrongMode, kAllowHarmonyScoping 5541 kAllowStrongMode, kAllowHarmonyScoping
5534 }; 5542 };
5535 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, 5543 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
5536 arraysize(always_flags)); 5544 arraysize(always_flags));
5537 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5545 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5538 arraysize(always_flags)); 5546 arraysize(always_flags));
5539 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5547 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5540 arraysize(always_flags)); 5548 arraysize(always_flags));
5541 } 5549 }
OLDNEW
« src/parser.h ('K') | « src/variables.cc ('k') | test/message/import-as-redeclaration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698