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 5054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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_classes(true); | |
arv (Not doing code reviews)
2015/02/24 22:13:34
no need for classes here
adamk
2015/02/24 22:17:54
Removed.
| |
5229 parser.set_allow_harmony_modules(true); | |
5230 parser.set_allow_harmony_scoping(true); | |
5231 info.MarkAsModule(); | |
5232 CHECK(parser.Parse(&info)); | |
5233 i::FunctionLiteral* func = info.function(); | |
5234 CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type()); | |
5235 i::ModuleDescriptor* descriptor = func->scope()->module(); | |
5236 CHECK_NOT_NULL(descriptor); | |
5237 const i::AstRawString* name_x = avf.GetOneByteString("x"); | |
5238 const i::AstRawString* name_y = avf.GetOneByteString("y"); | |
5239 int num_exports = 0; | |
5240 for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { | |
5241 ++num_exports; | |
5242 CHECK_EQ(*name_x, *it.local_name()); | |
5243 CHECK_EQ(*name_y, *it.export_name()); | |
5244 } | |
5245 CHECK_EQ(1, num_exports); | |
5246 } | |
5247 | |
5248 | |
5220 TEST(DuplicateProtoError) { | 5249 TEST(DuplicateProtoError) { |
5221 const char* context_data[][2] = { | 5250 const char* context_data[][2] = { |
5222 {"({", "});"}, | 5251 {"({", "});"}, |
5223 {"'use strict'; ({", "});"}, | 5252 {"'use strict'; ({", "});"}, |
5224 {NULL, NULL} | 5253 {NULL, NULL} |
5225 }; | 5254 }; |
5226 const char* error_data[] = { | 5255 const char* error_data[] = { |
5227 "__proto__: {}, __proto__: {}", | 5256 "__proto__: {}, __proto__: {}", |
5228 "__proto__: {}, \"__proto__\": {}", | 5257 "__proto__: {}, \"__proto__\": {}", |
5229 "__proto__: {}, \"__\x70roto__\": {}", | 5258 "__proto__: {}, \"__\x70roto__\": {}", |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5504 static const ParserFlag always_flags[] = { | 5533 static const ParserFlag always_flags[] = { |
5505 kAllowStrongMode, kAllowHarmonyScoping | 5534 kAllowStrongMode, kAllowHarmonyScoping |
5506 }; | 5535 }; |
5507 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, | 5536 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, |
5508 arraysize(always_flags)); | 5537 arraysize(always_flags)); |
5509 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5538 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, |
5510 arraysize(always_flags)); | 5539 arraysize(always_flags)); |
5511 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5540 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, |
5512 arraysize(always_flags)); | 5541 arraysize(always_flags)); |
5513 } | 5542 } |
OLD | NEW |