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

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

Issue 960793003: Allow lookup of module exports by export name. (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/modules.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 5205 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; export { x as y }; import { q as z } from 'm.js';";
5223 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5223 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5224 i::Handle<i::Script> script = factory->NewScript(source); 5224 i::Handle<i::Script> script = factory->NewScript(source);
5225 i::CompilationInfoWithZone info(script); 5225 i::CompilationInfoWithZone info(script);
5226 i::Zone* zone = info.zone();
5227 i::AstValueFactory avf(zone, isolate->heap()->HashSeed());
5226 i::Parser parser(&info, isolate->stack_guard()->real_climit(), 5228 i::Parser parser(&info, isolate->stack_guard()->real_climit(),
5227 isolate->heap()->HashSeed(), isolate->unicode_cache()); 5229 isolate->heap()->HashSeed(), isolate->unicode_cache());
5228 parser.set_allow_harmony_modules(true); 5230 parser.set_allow_harmony_modules(true);
5229 parser.set_allow_harmony_scoping(true); 5231 parser.set_allow_harmony_scoping(true);
5230 info.MarkAsModule(); 5232 info.MarkAsModule();
5231 CHECK(parser.Parse(&info)); 5233 CHECK(parser.Parse(&info));
5232 i::FunctionLiteral* func = info.function(); 5234 i::FunctionLiteral* func = info.function();
5233 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type()); 5235 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type());
5234 i::ModuleDescriptor* descriptor = func->scope()->module(); 5236 i::ModuleDescriptor* descriptor = func->scope()->module();
5235 CHECK_NOT_NULL(descriptor); 5237 CHECK_NOT_NULL(descriptor);
5236 int num_exports = 0; 5238 CHECK_EQ(1, descriptor->Length());
5237 for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { 5239 const i::AstRawString* export_name = avf.GetOneByteString("y");
5238 ++num_exports; 5240 const i::AstRawString* local_name =
5239 CHECK(it.local_name()->IsOneByteEqualTo("x")); 5241 descriptor->LookupLocalExport(export_name, zone);
5240 CHECK(it.export_name()->IsOneByteEqualTo("y")); 5242 CHECK_NOT_NULL(local_name);
5241 } 5243 CHECK(local_name->IsOneByteEqualTo("x"));
5242 CHECK_EQ(1, num_exports);
5243 i::ZoneList<i::Declaration*>* declarations = func->scope()->declarations(); 5244 i::ZoneList<i::Declaration*>* declarations = func->scope()->declarations();
5244 CHECK_EQ(2, declarations->length()); 5245 CHECK_EQ(2, declarations->length());
5245 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); 5246 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5246 i::ImportDeclaration* import_decl = 5247 i::ImportDeclaration* import_decl =
5247 declarations->at(1)->AsImportDeclaration(); 5248 declarations->at(1)->AsImportDeclaration();
5248 CHECK(import_decl->import_name()->IsOneByteEqualTo("q")); 5249 CHECK(import_decl->import_name()->IsOneByteEqualTo("q"));
5249 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z")); 5250 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z"));
5250 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js")); 5251 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js"));
5251 } 5252 }
5252 5253
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
5538 static const ParserFlag always_flags[] = { 5539 static const ParserFlag always_flags[] = {
5539 kAllowStrongMode, kAllowHarmonyScoping 5540 kAllowStrongMode, kAllowHarmonyScoping
5540 }; 5541 };
5541 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, 5542 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
5542 arraysize(always_flags)); 5543 arraysize(always_flags));
5543 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5544 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5544 arraysize(always_flags)); 5545 arraysize(always_flags));
5545 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5546 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5546 arraysize(always_flags)); 5547 arraysize(always_flags));
5547 } 5548 }
OLDNEW
« no previous file with comments | « src/modules.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698