| 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 5570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5581 "import { a, b as d, c, } from 'm.js';", | 5581 "import { a, b as d, c, } from 'm.js';", |
| 5582 "import * as thing from 'm.js';", | 5582 "import * as thing from 'm.js';", |
| 5583 "import thing from 'm.js';", | 5583 "import thing from 'm.js';", |
| 5584 "import thing, * as rest from 'm.js';", | 5584 "import thing, * as rest from 'm.js';", |
| 5585 "import thing, { a, b, c } from 'm.js';", | 5585 "import thing, { a, b, c } from 'm.js';", |
| 5586 "import { arguments as a } from 'm.js';", | 5586 "import { arguments as a } from 'm.js';", |
| 5587 "import { for as f } from 'm.js';", | 5587 "import { for as f } from 'm.js';", |
| 5588 "import { yield as y } from 'm.js';", | 5588 "import { yield as y } from 'm.js';", |
| 5589 "import { static as s } from 'm.js';", | 5589 "import { static as s } from 'm.js';", |
| 5590 "import { let as l } from 'm.js';", | 5590 "import { let as l } from 'm.js';", |
| 5591 |
| 5592 "import thing from 'a.js'; export {thing};", |
| 5593 "export {thing}; import thing from 'a.js';", |
| 5594 "import {thing} from 'a.js'; export {thing};", |
| 5595 "export {thing}; import {thing} from 'a.js';", |
| 5596 "import * as thing from 'a.js'; export {thing};", |
| 5597 "export {thing}; import * as thing from 'a.js';", |
| 5591 }; | 5598 }; |
| 5592 // clang-format on | 5599 // clang-format on |
| 5593 | 5600 |
| 5594 i::Isolate* isolate = CcTest::i_isolate(); | 5601 i::Isolate* isolate = CcTest::i_isolate(); |
| 5595 i::Factory* factory = isolate->factory(); | 5602 i::Factory* factory = isolate->factory(); |
| 5596 | 5603 |
| 5597 v8::HandleScope handles(CcTest::isolate()); | 5604 v8::HandleScope handles(CcTest::isolate()); |
| 5598 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5605 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5599 v8::Context::Scope context_scope(context); | 5606 v8::Context::Scope context_scope(context); |
| 5600 | 5607 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5904 "try {} catch (enum) {}", | 5911 "try {} catch (enum) {}", |
| 5905 "try {} catch (enum) {} finally {}", | 5912 "try {} catch (enum) {} finally {}", |
| 5906 NULL | 5913 NULL |
| 5907 }; | 5914 }; |
| 5908 // clang-format on | 5915 // clang-format on |
| 5909 const char* context_data[][2] = {{"", ""}, {NULL, NULL}}; | 5916 const char* context_data[][2] = {{"", ""}, {NULL, NULL}}; |
| 5910 | 5917 |
| 5911 RunModuleParserSyncTest(context_data, kErrorSources, kError); | 5918 RunModuleParserSyncTest(context_data, kErrorSources, kError); |
| 5912 } | 5919 } |
| 5913 | 5920 |
| 5921 static void CheckModuleEntry(const i::ModuleDescriptor::ModuleEntry* entry, |
| 5922 const char* export_name, const char* local_name, const char* import_name, |
| 5923 const char* module_request) { |
| 5924 CHECK_NOT_NULL(entry); |
| 5925 if (export_name == nullptr) { |
| 5926 CHECK_NULL(entry->export_name); |
| 5927 } else { |
| 5928 entry->export_name->IsOneByteEqualTo(export_name); |
| 5929 } |
| 5930 if (local_name == nullptr) { |
| 5931 CHECK_NULL(entry->local_name); |
| 5932 } else { |
| 5933 entry->local_name->IsOneByteEqualTo(local_name); |
| 5934 } |
| 5935 if (import_name == nullptr) { |
| 5936 CHECK_NULL(entry->import_name); |
| 5937 } else { |
| 5938 entry->import_name->IsOneByteEqualTo(import_name); |
| 5939 } |
| 5940 if (module_request == nullptr) { |
| 5941 CHECK_NULL(entry->module_request); |
| 5942 } else { |
| 5943 entry->module_request->IsOneByteEqualTo(module_request); |
| 5944 } |
| 5945 } |
| 5946 |
| 5914 TEST(ModuleParsingInternals) { | 5947 TEST(ModuleParsingInternals) { |
| 5915 i::Isolate* isolate = CcTest::i_isolate(); | 5948 i::Isolate* isolate = CcTest::i_isolate(); |
| 5916 i::Factory* factory = isolate->factory(); | 5949 i::Factory* factory = isolate->factory(); |
| 5917 v8::HandleScope handles(CcTest::isolate()); | 5950 v8::HandleScope handles(CcTest::isolate()); |
| 5918 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5951 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5919 v8::Context::Scope context_scope(context); | 5952 v8::Context::Scope context_scope(context); |
| 5920 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5953 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5921 128 * 1024); | 5954 128 * 1024); |
| 5922 | 5955 |
| 5923 static const char kSource[] = | 5956 static const char kSource[] = |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6033 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); | 6066 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); |
| 6034 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); | 6067 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); |
| 6035 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); | 6068 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); |
| 6036 CHECK(declarations->at(12)->proxy()->var()->location() == | 6069 CHECK(declarations->at(12)->proxy()->var()->location() == |
| 6037 i::VariableLocation::MODULE); | 6070 i::VariableLocation::MODULE); |
| 6038 | 6071 |
| 6039 i::ModuleDescriptor* descriptor = module_scope->module(); | 6072 i::ModuleDescriptor* descriptor = module_scope->module(); |
| 6040 CHECK_NOT_NULL(descriptor); | 6073 CHECK_NOT_NULL(descriptor); |
| 6041 | 6074 |
| 6042 CHECK_EQ(11, descriptor->exports().length()); | 6075 CHECK_EQ(11, descriptor->exports().length()); |
| 6043 | 6076 CheckModuleEntry( |
| 6044 CHECK(descriptor->exports().at(0)->export_name->IsOneByteEqualTo("y")); | 6077 descriptor->exports().at(0), "y", "x", nullptr, nullptr); |
| 6045 CHECK(descriptor->exports().at(0)->local_name->IsOneByteEqualTo("x")); | 6078 CheckModuleEntry( |
| 6046 CHECK_NULL(descriptor->exports().at(0)->module_request); | 6079 descriptor->exports().at(1), "b", nullptr, "a", "m.js"); |
| 6047 CHECK_NULL(descriptor->exports().at(0)->import_name); | 6080 CheckModuleEntry( |
| 6048 | 6081 descriptor->exports().at(2), nullptr, nullptr, nullptr, "p.js"); |
| 6049 CHECK(descriptor->exports().at(1)->export_name->IsOneByteEqualTo("b")); | 6082 CheckModuleEntry( |
| 6050 CHECK(descriptor->exports().at(1)->import_name->IsOneByteEqualTo("a")); | 6083 descriptor->exports().at(3), "foo", "foo", nullptr, nullptr); |
| 6051 CHECK(descriptor->exports().at(1)->module_request->IsOneByteEqualTo("m.js")); | 6084 CheckModuleEntry( |
| 6052 CHECK_NULL(descriptor->exports().at(1)->local_name); | 6085 descriptor->exports().at(4), "goo", "goo", nullptr, nullptr); |
| 6053 | 6086 CheckModuleEntry( |
| 6054 CHECK(descriptor->exports().at(2)->module_request->IsOneByteEqualTo("p.js")); | 6087 descriptor->exports().at(5), "hoo", "hoo", nullptr, nullptr); |
| 6055 CHECK_NULL(descriptor->exports().at(2)->local_name); | 6088 CheckModuleEntry( |
| 6056 CHECK_NULL(descriptor->exports().at(2)->import_name); | 6089 descriptor->exports().at(6), "joo", "joo", nullptr, nullptr); |
| 6057 CHECK_NULL(descriptor->exports().at(2)->export_name); | 6090 CheckModuleEntry( |
| 6058 | 6091 descriptor->exports().at(7), "default", "*default*", nullptr, nullptr); |
| 6059 CHECK(descriptor->exports().at(3)->export_name->IsOneByteEqualTo("foo")); | 6092 CheckModuleEntry( |
| 6060 CHECK(descriptor->exports().at(3)->local_name->IsOneByteEqualTo("foo")); | 6093 descriptor->exports().at(8), "bb", nullptr, "aa", "m.js"); // !!! |
| 6061 CHECK_NULL(descriptor->exports().at(3)->module_request); | 6094 CheckModuleEntry( |
| 6062 CHECK_NULL(descriptor->exports().at(3)->import_name); | 6095 descriptor->exports().at(9), "x", "x", nullptr, nullptr); |
| 6063 | 6096 CheckModuleEntry( |
| 6064 CHECK(descriptor->exports().at(4)->export_name->IsOneByteEqualTo("goo")); | 6097 descriptor->exports().at(10), "foob", "foob", nullptr, nullptr); |
| 6065 CHECK(descriptor->exports().at(4)->local_name->IsOneByteEqualTo("goo")); | |
| 6066 CHECK_NULL(descriptor->exports().at(4)->module_request); | |
| 6067 CHECK_NULL(descriptor->exports().at(4)->import_name); | |
| 6068 | |
| 6069 CHECK(descriptor->exports().at(5)->export_name->IsOneByteEqualTo("hoo")); | |
| 6070 CHECK(descriptor->exports().at(5)->local_name->IsOneByteEqualTo("hoo")); | |
| 6071 CHECK_NULL(descriptor->exports().at(5)->module_request); | |
| 6072 CHECK_NULL(descriptor->exports().at(5)->import_name); | |
| 6073 | |
| 6074 CHECK(descriptor->exports().at(6)->export_name->IsOneByteEqualTo("joo")); | |
| 6075 CHECK(descriptor->exports().at(6)->local_name->IsOneByteEqualTo("joo")); | |
| 6076 CHECK_NULL(descriptor->exports().at(6)->module_request); | |
| 6077 CHECK_NULL(descriptor->exports().at(6)->import_name); | |
| 6078 | |
| 6079 CHECK(descriptor->exports().at(7)->export_name->IsOneByteEqualTo("default")); | |
| 6080 CHECK(descriptor->exports().at(7)->local_name->IsOneByteEqualTo("*default*")); | |
| 6081 CHECK_NULL(descriptor->exports().at(7)->module_request); | |
| 6082 CHECK_NULL(descriptor->exports().at(7)->import_name); | |
| 6083 | |
| 6084 CHECK(descriptor->exports().at(8)->export_name->IsOneByteEqualTo("bb")); | |
| 6085 CHECK(descriptor->exports().at(8)->local_name->IsOneByteEqualTo("aa")); | |
| 6086 CHECK_NULL(descriptor->exports().at(8)->module_request); | |
| 6087 CHECK_NULL(descriptor->exports().at(8)->import_name); | |
| 6088 | |
| 6089 CHECK(descriptor->exports().at(9)->export_name->IsOneByteEqualTo("x")); | |
| 6090 CHECK(descriptor->exports().at(9)->local_name->IsOneByteEqualTo("x")); | |
| 6091 CHECK_NULL(descriptor->exports().at(9)->module_request); | |
| 6092 CHECK_NULL(descriptor->exports().at(9)->import_name); | |
| 6093 | |
| 6094 CHECK(descriptor->exports().at(10)->export_name->IsOneByteEqualTo("foob")); | |
| 6095 CHECK(descriptor->exports().at(10)->local_name->IsOneByteEqualTo("foob")); | |
| 6096 CHECK_NULL(descriptor->exports().at(10)->module_request); | |
| 6097 CHECK_NULL(descriptor->exports().at(10)->import_name); | |
| 6098 | 6098 |
| 6099 CHECK_EQ(3, descriptor->special_imports().length()); | 6099 CHECK_EQ(3, descriptor->special_imports().length()); |
| 6100 | 6100 CheckModuleEntry( |
| 6101 CHECK_NULL(descriptor->special_imports().at(0)->local_name); | 6101 descriptor->special_imports().at(0), nullptr, nullptr, nullptr, "q.js"); |
| 6102 CHECK_NULL(descriptor->special_imports().at(0)->export_name); | 6102 CheckModuleEntry( |
| 6103 CHECK_NULL(descriptor->special_imports().at(0)->import_name); | 6103 descriptor->special_imports().at(1), nullptr, "loo", nullptr, "bar.js"); |
| 6104 CHECK(descriptor->special_imports().at(0)->module_request->IsOneByteEqualTo( | 6104 CheckModuleEntry( |
| 6105 "q.js")); | 6105 descriptor->special_imports().at(2), nullptr, "foob", nullptr, "bar.js"); |
| 6106 | |
| 6107 CHECK( | |
| 6108 descriptor->special_imports().at(1)->local_name->IsOneByteEqualTo("loo")); | |
| 6109 CHECK_NULL(descriptor->special_imports().at(1)->export_name); | |
| 6110 CHECK_NULL(descriptor->special_imports().at(1)->import_name); | |
| 6111 CHECK(descriptor->special_imports().at(1)->module_request->IsOneByteEqualTo( | |
| 6112 "bar.js")); | |
| 6113 | |
| 6114 CHECK(descriptor->special_imports().at(2)->local_name->IsOneByteEqualTo( | |
| 6115 "foob")); | |
| 6116 CHECK_NULL(descriptor->special_imports().at(2)->export_name); | |
| 6117 CHECK_NULL(descriptor->special_imports().at(2)->import_name); | |
| 6118 CHECK(descriptor->special_imports().at(2)->module_request->IsOneByteEqualTo( | |
| 6119 "bar.js")); | |
| 6120 | 6106 |
| 6121 CHECK_EQ(4, descriptor->regular_imports().size()); | 6107 CHECK_EQ(4, descriptor->regular_imports().size()); |
| 6122 | 6108 const i::ModuleDescriptor::ModuleEntry* entry; |
| 6123 CHECK_NULL(descriptor->regular_imports() | 6109 entry = descriptor->regular_imports().find( |
| 6124 .find(declarations->at(1)->proxy()->raw_name()) | 6110 declarations->at(1)->proxy()->raw_name())->second; |
| 6125 ->second->export_name); | 6111 CheckModuleEntry(entry, nullptr, "z", "q", "m.js"); |
| 6126 CHECK(descriptor->regular_imports() | 6112 entry = descriptor->regular_imports().find( |
| 6127 .find(declarations->at(1)->proxy()->raw_name()) | 6113 declarations->at(2)->proxy()->raw_name())->second; |
| 6128 ->second->import_name->IsOneByteEqualTo("q")); | 6114 CheckModuleEntry(entry, nullptr, "n", "default", "n.js"); |
| 6129 CHECK(descriptor->regular_imports() | 6115 entry = descriptor->regular_imports().find( |
| 6130 .find(declarations->at(1)->proxy()->raw_name()) | 6116 declarations->at(9)->proxy()->raw_name())->second; |
| 6131 ->second->module_request->IsOneByteEqualTo("m.js")); | 6117 CheckModuleEntry(entry, nullptr, "mm", "m", "m.js"); |
| 6132 | 6118 entry = descriptor->regular_imports().find( |
| 6133 CHECK_NULL(descriptor->regular_imports() | 6119 declarations->at(10)->proxy()->raw_name())->second; |
| 6134 .find(declarations->at(2)->proxy()->raw_name()) | 6120 CheckModuleEntry(entry, nullptr, "aa", "aa", "m.js"); |
| 6135 ->second->export_name); | |
| 6136 CHECK(descriptor->regular_imports() | |
| 6137 .find(declarations->at(2)->proxy()->raw_name()) | |
| 6138 ->second->import_name->IsOneByteEqualTo("default")); | |
| 6139 CHECK(descriptor->regular_imports() | |
| 6140 .find(declarations->at(2)->proxy()->raw_name()) | |
| 6141 ->second->module_request->IsOneByteEqualTo("n.js")); | |
| 6142 | |
| 6143 CHECK_NULL(descriptor->regular_imports() | |
| 6144 .find(declarations->at(9)->proxy()->raw_name()) | |
| 6145 ->second->export_name); | |
| 6146 CHECK(descriptor->regular_imports() | |
| 6147 .find(declarations->at(9)->proxy()->raw_name()) | |
| 6148 ->second->import_name->IsOneByteEqualTo("m")); | |
| 6149 CHECK(descriptor->regular_imports() | |
| 6150 .find(declarations->at(9)->proxy()->raw_name()) | |
| 6151 ->second->module_request->IsOneByteEqualTo("m.js")); | |
| 6152 | |
| 6153 CHECK_NULL(descriptor->regular_imports() | |
| 6154 .find(declarations->at(10)->proxy()->raw_name()) | |
| 6155 ->second->export_name); | |
| 6156 CHECK(descriptor->regular_imports() | |
| 6157 .find(declarations->at(10)->proxy()->raw_name()) | |
| 6158 ->second->import_name->IsOneByteEqualTo("aa")); | |
| 6159 CHECK(descriptor->regular_imports() | |
| 6160 .find(declarations->at(10)->proxy()->raw_name()) | |
| 6161 ->second->module_request->IsOneByteEqualTo("m.js")); | |
| 6162 } | 6121 } |
| 6163 | 6122 |
| 6164 | 6123 |
| 6165 TEST(DuplicateProtoError) { | 6124 TEST(DuplicateProtoError) { |
| 6166 const char* context_data[][2] = { | 6125 const char* context_data[][2] = { |
| 6167 {"({", "});"}, | 6126 {"({", "});"}, |
| 6168 {"'use strict'; ({", "});"}, | 6127 {"'use strict'; ({", "});"}, |
| 6169 {NULL, NULL} | 6128 {NULL, NULL} |
| 6170 }; | 6129 }; |
| 6171 const char* error_data[] = { | 6130 const char* error_data[] = { |
| (...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8182 "(a,);", | 8141 "(a,);", |
| 8183 "(a,b,c,);", | 8142 "(a,b,c,);", |
| 8184 NULL | 8143 NULL |
| 8185 }; | 8144 }; |
| 8186 // clang-format on | 8145 // clang-format on |
| 8187 | 8146 |
| 8188 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 8147 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; |
| 8189 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 8148 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 8190 arraysize(always_flags)); | 8149 arraysize(always_flags)); |
| 8191 } | 8150 } |
| OLD | NEW |