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

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

Issue 2199283002: [modules] Introduce new VariableLocation for module imports/exports. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. Created 4 years, 4 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/parsing/parser.cc ('k') | test/mjsunit/harmony/modules.js » ('j') | 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 5914 matching lines...) Expand 10 before | Expand all | Expand 10 after
5925 "export { x as y };" 5925 "export { x as y };"
5926 "import { q as z } from 'm.js';" 5926 "import { q as z } from 'm.js';"
5927 "import n from 'n.js';" 5927 "import n from 'n.js';"
5928 "export { a as b } from 'm.js';" 5928 "export { a as b } from 'm.js';"
5929 "export * from 'p.js';" 5929 "export * from 'p.js';"
5930 "export var foo;" 5930 "export var foo;"
5931 "export function goo() {};" 5931 "export function goo() {};"
5932 "export let hoo;" 5932 "export let hoo;"
5933 "export const joo = 42;" 5933 "export const joo = 42;"
5934 "export default (function koo() {});" 5934 "export default (function koo() {});"
5935 "import 'q.js'"; 5935 "import 'q.js';"
5936 "let nonexport = 42;"
5937 "import {m as mm} from 'm.js';"
5938 "import {aa} from 'm.js';"
5939 "export {aa as bb, x};"
5940 "import * as loo from 'bar.js';"
5941 "import * as foob from 'bar.js';"
5942 "export {foob};";
5936 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5943 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5937 i::Handle<i::Script> script = factory->NewScript(source); 5944 i::Handle<i::Script> script = factory->NewScript(source);
5938 i::Zone zone(CcTest::i_isolate()->allocator()); 5945 i::Zone zone(CcTest::i_isolate()->allocator());
5939 i::ParseInfo info(&zone, script); 5946 i::ParseInfo info(&zone, script);
5940 i::Parser parser(&info); 5947 i::Parser parser(&info);
5941 info.set_module(); 5948 info.set_module();
5942 CHECK(parser.Parse(&info)); 5949 CHECK(parser.Parse(&info));
5943 CHECK(i::Compiler::Analyze(&info)); 5950 CHECK(i::Compiler::Analyze(&info));
5944 i::FunctionLiteral* func = info.literal(); 5951 i::FunctionLiteral* func = info.literal();
5945 i::DeclarationScope* module_scope = func->scope(); 5952 i::DeclarationScope* module_scope = func->scope();
5946 i::Scope* outer_scope = module_scope->outer_scope(); 5953 i::Scope* outer_scope = module_scope->outer_scope();
5947 CHECK(outer_scope->is_script_scope()); 5954 CHECK(outer_scope->is_script_scope());
5948 CHECK_NULL(outer_scope->outer_scope()); 5955 CHECK_NULL(outer_scope->outer_scope());
5949 CHECK(module_scope->is_module_scope()); 5956 CHECK(module_scope->is_module_scope());
5957 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
5958
5959 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5960 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET);
5961 CHECK(declarations->at(0)->proxy()->var()->location() ==
5962 i::VariableLocation::MODULE);
5963
5964 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z"));
5965 CHECK(declarations->at(1)->proxy()->var()->mode() == i::CONST);
5966 CHECK(declarations->at(1)->proxy()->var()->location() ==
5967 i::VariableLocation::MODULE);
5968
5969 CHECK(declarations->at(2)->proxy()->raw_name()->IsOneByteEqualTo("n"));
5970 CHECK(declarations->at(2)->proxy()->var()->mode() == i::CONST);
5971 CHECK(declarations->at(2)->proxy()->var()->location() ==
5972 i::VariableLocation::MODULE);
5973
5974 CHECK(declarations->at(3)->proxy()->raw_name()->IsOneByteEqualTo("foo"));
5975 CHECK(declarations->at(3)->proxy()->var()->mode() == i::VAR);
5976 CHECK(declarations->at(3)->proxy()->var()->location() ==
5977 i::VariableLocation::MODULE);
5978
5979 CHECK(declarations->at(4)->proxy()->raw_name()->IsOneByteEqualTo("goo"));
5980 CHECK(declarations->at(4)->proxy()->var()->mode() == i::LET);
5981 CHECK(declarations->at(4)->proxy()->var()->location() ==
5982 i::VariableLocation::MODULE);
5983
5984 CHECK(declarations->at(5)->proxy()->raw_name()->IsOneByteEqualTo("hoo"));
5985 CHECK(declarations->at(5)->proxy()->var()->mode() == i::LET);
5986 CHECK(declarations->at(5)->proxy()->var()->location() ==
5987 i::VariableLocation::MODULE);
5988
5989 CHECK(declarations->at(6)->proxy()->raw_name()->IsOneByteEqualTo("joo"));
5990 CHECK(declarations->at(6)->proxy()->var()->mode() == i::CONST);
5991 CHECK(declarations->at(6)->proxy()->var()->location() ==
5992 i::VariableLocation::MODULE);
5993
5994 CHECK(
5995 declarations->at(7)->proxy()->raw_name()->IsOneByteEqualTo("*default*"));
5996 CHECK(declarations->at(7)->proxy()->var()->mode() == i::CONST);
5997 CHECK(declarations->at(7)->proxy()->var()->location() ==
5998 i::VariableLocation::MODULE);
5999
6000 CHECK(
6001 declarations->at(8)->proxy()->raw_name()->IsOneByteEqualTo("nonexport"));
6002 CHECK(declarations->at(8)->proxy()->var()->location() !=
6003 i::VariableLocation::MODULE);
6004
6005 CHECK(declarations->at(9)->proxy()->raw_name()->IsOneByteEqualTo("mm"));
6006 CHECK(declarations->at(9)->proxy()->var()->mode() == i::CONST);
6007 CHECK(declarations->at(9)->proxy()->var()->location() ==
6008 i::VariableLocation::MODULE);
6009
6010 CHECK(declarations->at(10)->proxy()->raw_name()->IsOneByteEqualTo("aa"));
6011 CHECK(declarations->at(10)->proxy()->var()->mode() == i::CONST);
6012 CHECK(declarations->at(10)->proxy()->var()->location() ==
6013 i::VariableLocation::MODULE);
6014
6015 CHECK(declarations->at(11)->proxy()->raw_name()->IsOneByteEqualTo("loo"));
6016 CHECK(declarations->at(11)->proxy()->var()->mode() == i::CONST);
6017 CHECK(declarations->at(11)->proxy()->var()->location() !=
6018 i::VariableLocation::MODULE);
6019
6020 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob"));
6021 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST);
6022 CHECK(declarations->at(12)->proxy()->var()->location() ==
6023 i::VariableLocation::MODULE);
6024
6025 CHECK_EQ(13, declarations->length());
6026
5950 i::ModuleDescriptor* descriptor = module_scope->module(); 6027 i::ModuleDescriptor* descriptor = module_scope->module();
5951 CHECK_NOT_NULL(descriptor); 6028 CHECK_NOT_NULL(descriptor);
5952 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
5953 CHECK_EQ(8, declarations->length());
5954 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5955 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z"));
5956 CHECK(declarations->at(2)->proxy()->raw_name()->IsOneByteEqualTo("n"));
5957 CHECK(declarations->at(3)->proxy()->raw_name()->IsOneByteEqualTo("foo"));
5958 CHECK(declarations->at(4)->proxy()->raw_name()->IsOneByteEqualTo("goo"));
5959 CHECK(declarations->at(5)->proxy()->raw_name()->IsOneByteEqualTo("hoo"));
5960 CHECK(declarations->at(6)->proxy()->raw_name()->IsOneByteEqualTo("joo"));
5961 CHECK(
5962 declarations->at(7)->proxy()->raw_name()->IsOneByteEqualTo("*default*"));
5963 // TODO(neis): Test more once we can inspect the imports/exports. 6029 // TODO(neis): Test more once we can inspect the imports/exports.
5964 } 6030 }
5965 6031
5966 6032
5967 TEST(DuplicateProtoError) { 6033 TEST(DuplicateProtoError) {
5968 const char* context_data[][2] = { 6034 const char* context_data[][2] = {
5969 {"({", "});"}, 6035 {"({", "});"},
5970 {"'use strict'; ({", "});"}, 6036 {"'use strict'; ({", "});"},
5971 {NULL, NULL} 6037 {NULL, NULL}
5972 }; 6038 };
(...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after
7984 "(a,);", 8050 "(a,);",
7985 "(a,b,c,);", 8051 "(a,b,c,);",
7986 NULL 8052 NULL
7987 }; 8053 };
7988 // clang-format on 8054 // clang-format on
7989 8055
7990 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 8056 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
7991 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 8057 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7992 arraysize(always_flags)); 8058 arraysize(always_flags));
7993 } 8059 }
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | test/mjsunit/harmony/modules.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698