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 5200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); |
| 5246 i::ImportDeclaration* import_decl = |
| 5247 declarations->at(1)->AsImportDeclaration(); |
| 5248 CHECK(import_decl->import_name()->IsOneByteEqualTo("q")); |
| 5249 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z")); |
| 5250 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js")); |
5245 } | 5251 } |
5246 | 5252 |
5247 | 5253 |
5248 TEST(DuplicateProtoError) { | 5254 TEST(DuplicateProtoError) { |
5249 const char* context_data[][2] = { | 5255 const char* context_data[][2] = { |
5250 {"({", "});"}, | 5256 {"({", "});"}, |
5251 {"'use strict'; ({", "});"}, | 5257 {"'use strict'; ({", "});"}, |
5252 {NULL, NULL} | 5258 {NULL, NULL} |
5253 }; | 5259 }; |
5254 const char* error_data[] = { | 5260 const char* error_data[] = { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5532 static const ParserFlag always_flags[] = { | 5538 static const ParserFlag always_flags[] = { |
5533 kAllowStrongMode, kAllowHarmonyScoping | 5539 kAllowStrongMode, kAllowHarmonyScoping |
5534 }; | 5540 }; |
5535 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, | 5541 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, |
5536 arraysize(always_flags)); | 5542 arraysize(always_flags)); |
5537 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5543 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, |
5538 arraysize(always_flags)); | 5544 arraysize(always_flags)); |
5539 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5545 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, |
5540 arraysize(always_flags)); | 5546 arraysize(always_flags)); |
5541 } | 5547 } |
OLD | NEW |