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

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

Issue 953983002: Fix up ParseProgram and ParseModule to do something sane with module scopes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Stop using CHECK_EQ for AstRawStrings, clang does not like it 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
« src/parser.h ('K') | « 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 5054 matching lines...) Expand 10 before | Expand all | Expand 10 after
5065 i::Factory* factory = isolate->factory(); 5065 i::Factory* factory = isolate->factory();
5066 5066
5067 v8::HandleScope handles(CcTest::isolate()); 5067 v8::HandleScope handles(CcTest::isolate());
5068 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 5068 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5069 v8::Context::Scope context_scope(context); 5069 v8::Context::Scope context_scope(context);
5070 5070
5071 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5071 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5072 128 * 1024); 5072 128 * 1024);
5073 5073
5074 for (unsigned i = 0; i < arraysize(kSources); ++i) { 5074 for (unsigned i = 0; i < arraysize(kSources); ++i) {
5075 int kProgramByteSize = i::StrLength(kSources[i]);
5076 i::ScopedVector<char> program(kProgramByteSize + 1);
5077 i::SNPrintF(program, "%s", kSources[i]);
5078 i::Handle<i::String> source = 5075 i::Handle<i::String> source =
5079 factory->NewStringFromUtf8(i::CStrVector(program.start())) 5076 factory->NewStringFromAsciiChecked(kSources[i]);
5080 .ToHandleChecked();
5081 5077
5082 // Show that parsing as a module works 5078 // Show that parsing as a module works
5083 { 5079 {
5084 i::Handle<i::Script> script = factory->NewScript(source); 5080 i::Handle<i::Script> script = factory->NewScript(source);
5085 i::CompilationInfoWithZone info(script); 5081 i::CompilationInfoWithZone info(script);
5086 i::Parser parser(&info, isolate->stack_guard()->real_climit(), 5082 i::Parser parser(&info, isolate->stack_guard()->real_climit(),
5087 isolate->heap()->HashSeed(), isolate->unicode_cache()); 5083 isolate->heap()->HashSeed(), isolate->unicode_cache());
5088 parser.set_allow_harmony_classes(true); 5084 parser.set_allow_harmony_classes(true);
5089 parser.set_allow_harmony_modules(true); 5085 parser.set_allow_harmony_modules(true);
5090 parser.set_allow_harmony_scoping(true); 5086 parser.set_allow_harmony_scoping(true);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5190 i::Factory* factory = isolate->factory(); 5186 i::Factory* factory = isolate->factory();
5191 5187
5192 v8::HandleScope handles(CcTest::isolate()); 5188 v8::HandleScope handles(CcTest::isolate());
5193 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 5189 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5194 v8::Context::Scope context_scope(context); 5190 v8::Context::Scope context_scope(context);
5195 5191
5196 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5192 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5197 128 * 1024); 5193 128 * 1024);
5198 5194
5199 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 5195 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5200 int kProgramByteSize = i::StrLength(kErrorSources[i]);
5201 i::ScopedVector<char> program(kProgramByteSize + 1);
5202 i::SNPrintF(program, "%s", kErrorSources[i]);
5203 i::Handle<i::String> source = 5196 i::Handle<i::String> source =
5204 factory->NewStringFromUtf8(i::CStrVector(program.start())) 5197 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5205 .ToHandleChecked();
5206 5198
5207 i::Handle<i::Script> script = factory->NewScript(source); 5199 i::Handle<i::Script> script = factory->NewScript(source);
5208 i::CompilationInfoWithZone info(script); 5200 i::CompilationInfoWithZone info(script);
5209 i::Parser parser(&info, isolate->stack_guard()->real_climit(), 5201 i::Parser parser(&info, isolate->stack_guard()->real_climit(),
5210 isolate->heap()->HashSeed(), isolate->unicode_cache()); 5202 isolate->heap()->HashSeed(), isolate->unicode_cache());
5211 parser.set_allow_harmony_classes(true); 5203 parser.set_allow_harmony_classes(true);
5212 parser.set_allow_harmony_modules(true); 5204 parser.set_allow_harmony_modules(true);
5213 parser.set_allow_harmony_scoping(true); 5205 parser.set_allow_harmony_scoping(true);
5214 info.MarkAsModule(); 5206 info.MarkAsModule();
5215 CHECK(!parser.Parse(&info)); 5207 CHECK(!parser.Parse(&info));
5216 } 5208 }
5217 } 5209 }
5218 5210
5219 5211
5212 TEST(ModuleParsingInternals) {
5213 i::Isolate* isolate = CcTest::i_isolate();
5214 i::Factory* factory = isolate->factory();
5215 v8::HandleScope handles(CcTest::isolate());
5216 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5217 v8::Context::Scope context_scope(context);
5218 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5219 128 * 1024);
5220
5221 static const char kSource[] = "let x = 5; export { x as y };";
5222 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5223 i::Handle<i::Script> script = factory->NewScript(source);
5224 i::CompilationInfoWithZone info(script);
5225 i::AstValueFactory avf(info.zone(), isolate->heap()->HashSeed());
5226 i::Parser parser(&info, isolate->stack_guard()->real_climit(),
5227 isolate->heap()->HashSeed(), isolate->unicode_cache());
5228 parser.set_allow_harmony_modules(true);
5229 parser.set_allow_harmony_scoping(true);
5230 info.MarkAsModule();
5231 CHECK(parser.Parse(&info));
5232 i::FunctionLiteral* func = info.function();
5233 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type());
5234 i::ModuleDescriptor* descriptor = func->scope()->module();
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;
5239 for (auto it = descriptor->iterator(); !it.done(); it.Advance()) {
5240 ++num_exports;
5241 CHECK(*name_x == *it.local_name());
5242 CHECK(*name_y == *it.export_name());
5243 }
5244 CHECK_EQ(1, num_exports);
5245 }
5246
5247
5220 TEST(DuplicateProtoError) { 5248 TEST(DuplicateProtoError) {
5221 const char* context_data[][2] = { 5249 const char* context_data[][2] = {
5222 {"({", "});"}, 5250 {"({", "});"},
5223 {"'use strict'; ({", "});"}, 5251 {"'use strict'; ({", "});"},
5224 {NULL, NULL} 5252 {NULL, NULL}
5225 }; 5253 };
5226 const char* error_data[] = { 5254 const char* error_data[] = {
5227 "__proto__: {}, __proto__: {}", 5255 "__proto__: {}, __proto__: {}",
5228 "__proto__: {}, \"__proto__\": {}", 5256 "__proto__: {}, \"__proto__\": {}",
5229 "__proto__: {}, \"__\x70roto__\": {}", 5257 "__proto__: {}, \"__\x70roto__\": {}",
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
5504 static const ParserFlag always_flags[] = { 5532 static const ParserFlag always_flags[] = {
5505 kAllowStrongMode, kAllowHarmonyScoping 5533 kAllowStrongMode, kAllowHarmonyScoping
5506 }; 5534 };
5507 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, 5535 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
5508 arraysize(always_flags)); 5536 arraysize(always_flags));
5509 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5537 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5510 arraysize(always_flags)); 5538 arraysize(always_flags));
5511 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5539 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5512 arraysize(always_flags)); 5540 arraysize(always_flags));
5513 } 5541 }
OLDNEW
« src/parser.h ('K') | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698