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

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

Issue 2108193003: [modules] AST and parser rework. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@anonymous-declarations
Patch Set: . Created 4 years, 5 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
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 5872 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {});"
adamk 2016/07/13 18:38:22 Can you also add an anonymous case? That'll be cov
neis 2016/07/14 10:28:24 Not sure what you mean. This module already has a
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 // CHECK_EQ(1, descriptor->Length());
adamk 2016/07/13 18:38:22 Is this stuff dead now?
neis 2016/07/14 10:28:24 Yes, removed. Will most likely re-add such tests l
5927 // const i::AstRawString* export_name =
5928 // info.ast_value_factory()->GetOneByteString("y");
5929 // const i::AstRawString* local_name =
5930 // descriptor->LookupExport(export_name, &zone);
5931 // CHECK_NOT_NULL(local_name);
5932 // CHECK(local_name->IsOneByteEqualTo("x"));
5933 // i::ImportDeclaration* import_decl =
5934 // declarations->at(1)->AsImportDeclaration();
5935 // CHECK(import_decl->import_name()->IsOneByteEqualTo("q"));
5936 // CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z"));
5937 // CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js"));
5938 // import_decl = declarations->at(2)->AsImportDeclaration();
5939 // CHECK(import_decl->import_name()->IsOneByteEqualTo("default"));
5940 // CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("n"));
5941 // CHECK(import_decl->module_specifier()->IsOneByteEqualTo("n.js"));
5929 // TODO(adamk): Add test for indirect exports once they're fully implemented. 5942 // 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. 5943 // TODO(adamk): Add test for star exports once they're fully implemented.
5931 const i::ZoneList<const i::AstRawString*>& requested_modules = 5944 // const i::ZoneList<const i::AstRawString*>& requested_modules =
5932 descriptor->requested_modules(); 5945 // descriptor->requested_modules();
5933 CHECK_EQ(4, requested_modules.length()); 5946 // CHECK_EQ(4, requested_modules.length());
5934 CHECK(requested_modules[0]->IsOneByteEqualTo("m.js")); 5947 // CHECK(requested_modules[0]->IsOneByteEqualTo("m.js"));
5935 CHECK(requested_modules[1]->IsOneByteEqualTo("n.js")); 5948 // CHECK(requested_modules[1]->IsOneByteEqualTo("n.js"));
5936 CHECK(requested_modules[2]->IsOneByteEqualTo("p.js")); 5949 // CHECK(requested_modules[2]->IsOneByteEqualTo("p.js"));
5937 CHECK(requested_modules[3]->IsOneByteEqualTo("q.js")); 5950 // CHECK(requested_modules[3]->IsOneByteEqualTo("q.js"));
5938 } 5951 }
5939 5952
5940 5953
5941 TEST(DuplicateProtoError) { 5954 TEST(DuplicateProtoError) {
5942 const char* context_data[][2] = { 5955 const char* context_data[][2] = {
5943 {"({", "});"}, 5956 {"({", "});"},
5944 {"'use strict'; ({", "});"}, 5957 {"'use strict'; ({", "});"},
5945 {NULL, NULL} 5958 {NULL, NULL}
5946 }; 5959 };
5947 const char* error_data[] = { 5960 const char* error_data[] = {
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after
7964 "(a,);", 7977 "(a,);",
7965 "(a,b,c,);", 7978 "(a,b,c,);",
7966 NULL 7979 NULL
7967 }; 7980 };
7968 // clang-format on 7981 // clang-format on
7969 7982
7970 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 7983 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
7971 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 7984 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7972 arraysize(always_flags)); 7985 arraysize(always_flags));
7973 } 7986 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698