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 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 // 'module' Identifier Module | 1153 // 'module' Identifier Module |
1154 | 1154 |
1155 Handle<String> name = ParseIdentifier(CHECK_OK); | 1155 Handle<String> name = ParseIdentifier(CHECK_OK); |
1156 | 1156 |
1157 #ifdef DEBUG | 1157 #ifdef DEBUG |
1158 if (FLAG_print_interface_details) | 1158 if (FLAG_print_interface_details) |
1159 PrintF("# Module %s...\n", name->ToAsciiArray()); | 1159 PrintF("# Module %s...\n", name->ToAsciiArray()); |
1160 #endif | 1160 #endif |
1161 | 1161 |
1162 Module* module = ParseModule(CHECK_OK); | 1162 Module* module = ParseModule(CHECK_OK); |
1163 VariableProxy* proxy = NewUnresolved(name, LET, module->interface()); | 1163 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface()); |
1164 Declaration* declaration = | 1164 Declaration* declaration = |
1165 factory()->NewModuleDeclaration(proxy, module, top_scope_); | 1165 factory()->NewModuleDeclaration(proxy, module, top_scope_); |
1166 Declare(declaration, true, CHECK_OK); | 1166 Declare(declaration, true, CHECK_OK); |
1167 | 1167 |
1168 #ifdef DEBUG | 1168 #ifdef DEBUG |
1169 if (FLAG_print_interface_details) | 1169 if (FLAG_print_interface_details) |
1170 PrintF("# Module %s.\n", name->ToAsciiArray()); | 1170 PrintF("# Module %s.\n", name->ToAsciiArray()); |
1171 | 1171 |
1172 if (FLAG_print_interfaces) { | 1172 if (FLAG_print_interfaces) { |
1173 PrintF("module %s : ", name->ToAsciiArray()); | 1173 PrintF("module %s : ", name->ToAsciiArray()); |
1174 module->interface()->Print(); | 1174 module->interface()->Print(); |
1175 } | 1175 } |
1176 #endif | 1176 #endif |
1177 | 1177 |
1178 if (names) names->Add(name, zone()); | 1178 if (names) names->Add(name, zone()); |
1179 if (module->body() == NULL) | 1179 if (module->body() == NULL) |
1180 return factory()->NewEmptyStatement(); | 1180 return factory()->NewEmptyStatement(); |
1181 else | 1181 else |
1182 return module->body(); | 1182 return factory()->NewModuleStatement(proxy, module->body()); |
1183 } | 1183 } |
1184 | 1184 |
1185 | 1185 |
1186 Module* Parser::ParseModule(bool* ok) { | 1186 Module* Parser::ParseModule(bool* ok) { |
1187 // Module: | 1187 // Module: |
1188 // '{' ModuleElement '}' | 1188 // '{' ModuleElement '}' |
1189 // '=' ModulePath ';' | 1189 // '=' ModulePath ';' |
1190 // 'at' String ';' | 1190 // 'at' String ';' |
1191 | 1191 |
1192 switch (peek()) { | 1192 switch (peek()) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 | 1321 |
1322 Expect(Token::STRING, CHECK_OK); | 1322 Expect(Token::STRING, CHECK_OK); |
1323 Handle<String> symbol = GetSymbol(CHECK_OK); | 1323 Handle<String> symbol = GetSymbol(CHECK_OK); |
1324 | 1324 |
1325 // TODO(ES6): Request JS resource from environment... | 1325 // TODO(ES6): Request JS resource from environment... |
1326 | 1326 |
1327 #ifdef DEBUG | 1327 #ifdef DEBUG |
1328 if (FLAG_print_interface_details) PrintF("# Url "); | 1328 if (FLAG_print_interface_details) PrintF("# Url "); |
1329 #endif | 1329 #endif |
1330 | 1330 |
1331 Module* result = factory()->NewModuleUrl(symbol); | 1331 // Create an empty literal as long as the feature isn't finished. |
1332 Interface* interface = result->interface(); | 1332 USE(symbol); |
| 1333 Scope* scope = NewScope(top_scope_, MODULE_SCOPE); |
| 1334 Block* body = factory()->NewBlock(NULL, 1, false); |
| 1335 body->set_scope(scope); |
| 1336 Interface* interface = scope->interface(); |
| 1337 Module* result = factory()->NewModuleLiteral(body, interface); |
1333 interface->Freeze(ok); | 1338 interface->Freeze(ok); |
1334 ASSERT(*ok); | 1339 ASSERT(*ok); |
1335 // Create dummy scope to avoid errors as long as the feature isn't finished. | |
1336 Scope* scope = NewScope(top_scope_, MODULE_SCOPE); | |
1337 interface->Unify(scope->interface(), zone(), ok); | 1340 interface->Unify(scope->interface(), zone(), ok); |
1338 ASSERT(*ok); | 1341 ASSERT(*ok); |
1339 return result; | 1342 return result; |
1340 } | 1343 } |
1341 | 1344 |
1342 | 1345 |
1343 Module* Parser::ParseModuleSpecifier(bool* ok) { | 1346 Module* Parser::ParseModuleSpecifier(bool* ok) { |
1344 // ModuleSpecifier: | 1347 // ModuleSpecifier: |
1345 // String | 1348 // String |
1346 // ModulePath | 1349 // ModulePath |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 if (is_extended_mode()) { | 1698 if (is_extended_mode()) { |
1696 // In harmony mode we treat re-declarations as early errors. See | 1699 // In harmony mode we treat re-declarations as early errors. See |
1697 // ES5 16 for a definition of early errors. | 1700 // ES5 16 for a definition of early errors. |
1698 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); | 1701 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); |
1699 const char* elms[2] = { "Variable", *c_string }; | 1702 const char* elms[2] = { "Variable", *c_string }; |
1700 Vector<const char*> args(elms, 2); | 1703 Vector<const char*> args(elms, 2); |
1701 ReportMessage("redeclaration", args); | 1704 ReportMessage("redeclaration", args); |
1702 *ok = false; | 1705 *ok = false; |
1703 return; | 1706 return; |
1704 } | 1707 } |
1705 const char* type = | |
1706 (var->mode() == VAR) ? "var" : var->is_const_mode() ? "const" : "let"; | |
1707 Handle<String> type_string = | 1708 Handle<String> type_string = |
1708 isolate()->factory()->NewStringFromUtf8(CStrVector(type), TENURED); | 1709 isolate()->factory()->NewStringFromUtf8(CStrVector("Variable"), |
| 1710 TENURED); |
1709 Expression* expression = | 1711 Expression* expression = |
1710 NewThrowTypeError(isolate()->factory()->redeclaration_symbol(), | 1712 NewThrowTypeError(isolate()->factory()->redeclaration_symbol(), |
1711 type_string, name); | 1713 type_string, name); |
1712 declaration_scope->SetIllegalRedeclaration(expression); | 1714 declaration_scope->SetIllegalRedeclaration(expression); |
1713 } | 1715 } |
1714 } | 1716 } |
1715 | 1717 |
1716 // We add a declaration node for every declaration. The compiler | 1718 // We add a declaration node for every declaration. The compiler |
1717 // will only generate code if necessary. In particular, declarations | 1719 // will only generate code if necessary. In particular, declarations |
1718 // for inner local variables that do not represent functions won't | 1720 // for inner local variables that do not represent functions won't |
(...skipping 4261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5980 ASSERT(info->isolate()->has_pending_exception()); | 5982 ASSERT(info->isolate()->has_pending_exception()); |
5981 } else { | 5983 } else { |
5982 result = parser.ParseProgram(); | 5984 result = parser.ParseProgram(); |
5983 } | 5985 } |
5984 } | 5986 } |
5985 info->SetFunction(result); | 5987 info->SetFunction(result); |
5986 return (result != NULL); | 5988 return (result != NULL); |
5987 } | 5989 } |
5988 | 5990 |
5989 } } // namespace v8::internal | 5991 } } // namespace v8::internal |
OLD | NEW |