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 5872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5883 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5883 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
5884 128 * 1024); | 5884 128 * 1024); |
5885 | 5885 |
5886 static const char kSource[] = | 5886 static const char kSource[] = |
5887 "let x = 5;" | 5887 "let x = 5;" |
5888 "export { x as y };" | 5888 "export { x as y };" |
5889 "import { q as z } from 'm.js';" | 5889 "import { q as z } from 'm.js';" |
5890 "import n from 'n.js';" | 5890 "import n from 'n.js';" |
5891 "export { a as b } from 'm.js';" | 5891 "export { a as b } from 'm.js';" |
5892 "export * from 'p.js';" | 5892 "export * from 'p.js';" |
| 5893 "export var foo;" |
| 5894 "export function goo() {};" |
| 5895 "export let hoo;" |
| 5896 "export const joo = 42;" |
| 5897 "export default (function koo() {});" |
5893 "import 'q.js'"; | 5898 "import 'q.js'"; |
5894 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); | 5899 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); |
5895 i::Handle<i::Script> script = factory->NewScript(source); | 5900 i::Handle<i::Script> script = factory->NewScript(source); |
5896 i::Zone zone(CcTest::i_isolate()->allocator()); | 5901 i::Zone zone(CcTest::i_isolate()->allocator()); |
5897 i::ParseInfo info(&zone, script); | 5902 i::ParseInfo info(&zone, script); |
5898 i::Parser parser(&info); | 5903 i::Parser parser(&info); |
5899 info.set_module(); | 5904 info.set_module(); |
5900 CHECK(parser.Parse(&info)); | 5905 CHECK(parser.Parse(&info)); |
5901 CHECK(i::Compiler::Analyze(&info)); | 5906 CHECK(i::Compiler::Analyze(&info)); |
5902 i::FunctionLiteral* func = info.literal(); | 5907 i::FunctionLiteral* func = info.literal(); |
5903 i::Scope* module_scope = func->scope(); | 5908 i::Scope* module_scope = func->scope(); |
5904 i::Scope* outer_scope = module_scope->outer_scope(); | 5909 i::Scope* outer_scope = module_scope->outer_scope(); |
5905 CHECK(outer_scope->is_script_scope()); | 5910 CHECK(outer_scope->is_script_scope()); |
5906 CHECK_NULL(outer_scope->outer_scope()); | 5911 CHECK_NULL(outer_scope->outer_scope()); |
5907 CHECK(module_scope->is_module_scope()); | 5912 CHECK(module_scope->is_module_scope()); |
5908 i::ModuleDescriptor* descriptor = module_scope->module(); | 5913 i::ModuleDescriptor* descriptor = module_scope->module(); |
5909 CHECK_NOT_NULL(descriptor); | 5914 CHECK_NOT_NULL(descriptor); |
5910 CHECK_EQ(1, descriptor->Length()); | |
5911 const i::AstRawString* export_name = | |
5912 info.ast_value_factory()->GetOneByteString("y"); | |
5913 const i::AstRawString* local_name = | |
5914 descriptor->LookupLocalExport(export_name, &zone); | |
5915 CHECK_NOT_NULL(local_name); | |
5916 CHECK(local_name->IsOneByteEqualTo("x")); | |
5917 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); | 5915 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); |
5918 CHECK_EQ(3, declarations->length()); | 5916 CHECK_EQ(8, declarations->length()); |
5919 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); | 5917 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); |
5920 i::ImportDeclaration* import_decl = | 5918 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); |
5921 declarations->at(1)->AsImportDeclaration(); | 5919 CHECK(declarations->at(2)->proxy()->raw_name()->IsOneByteEqualTo("n")); |
5922 CHECK(import_decl->import_name()->IsOneByteEqualTo("q")); | 5920 CHECK(declarations->at(3)->proxy()->raw_name()->IsOneByteEqualTo("foo")); |
5923 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z")); | 5921 CHECK(declarations->at(4)->proxy()->raw_name()->IsOneByteEqualTo("goo")); |
5924 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js")); | 5922 CHECK(declarations->at(5)->proxy()->raw_name()->IsOneByteEqualTo("hoo")); |
5925 import_decl = declarations->at(2)->AsImportDeclaration(); | 5923 CHECK(declarations->at(6)->proxy()->raw_name()->IsOneByteEqualTo("joo")); |
5926 CHECK(import_decl->import_name()->IsOneByteEqualTo("default")); | 5924 CHECK( |
5927 CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("n")); | 5925 declarations->at(7)->proxy()->raw_name()->IsOneByteEqualTo("*default*")); |
5928 CHECK(import_decl->module_specifier()->IsOneByteEqualTo("n.js")); | 5926 // TODO(neis): Test more once we can inspect the imports/exports. |
5929 // TODO(adamk): Add test for indirect exports once they're fully implemented. | |
5930 // TODO(adamk): Add test for star exports once they're fully implemented. | |
5931 const i::ZoneList<const i::AstRawString*>& requested_modules = | |
5932 descriptor->requested_modules(); | |
5933 CHECK_EQ(4, requested_modules.length()); | |
5934 CHECK(requested_modules[0]->IsOneByteEqualTo("m.js")); | |
5935 CHECK(requested_modules[1]->IsOneByteEqualTo("n.js")); | |
5936 CHECK(requested_modules[2]->IsOneByteEqualTo("p.js")); | |
5937 CHECK(requested_modules[3]->IsOneByteEqualTo("q.js")); | |
5938 } | 5927 } |
5939 | 5928 |
5940 | 5929 |
5941 TEST(DuplicateProtoError) { | 5930 TEST(DuplicateProtoError) { |
5942 const char* context_data[][2] = { | 5931 const char* context_data[][2] = { |
5943 {"({", "});"}, | 5932 {"({", "});"}, |
5944 {"'use strict'; ({", "});"}, | 5933 {"'use strict'; ({", "});"}, |
5945 {NULL, NULL} | 5934 {NULL, NULL} |
5946 }; | 5935 }; |
5947 const char* error_data[] = { | 5936 const char* error_data[] = { |
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7964 "(a,);", | 7953 "(a,);", |
7965 "(a,b,c,);", | 7954 "(a,b,c,);", |
7966 NULL | 7955 NULL |
7967 }; | 7956 }; |
7968 // clang-format on | 7957 // clang-format on |
7969 | 7958 |
7970 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 7959 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; |
7971 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 7960 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
7972 arraysize(always_flags)); | 7961 arraysize(always_flags)); |
7973 } | 7962 } |
OLD | NEW |