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 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1034 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
1035 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); | 1035 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); |
1036 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 1036 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
1037 // The end position of a token is one position after the last | 1037 // The end position of a token is one position after the last |
1038 // character belonging to that token. | 1038 // character belonging to that token. |
1039 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1039 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
1040 } | 1040 } |
1041 } | 1041 } |
1042 | 1042 |
1043 | 1043 |
1044 i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) { | |
1045 i::Handle<i::String> format = v8::Utils::OpenHandle( | |
1046 *v8::String::New(data->BuildMessage())); | |
1047 i::Vector<const char*> args = data->BuildArgs(); | |
1048 i::Handle<i::JSArray> args_array = FACTORY->NewJSArray(args.length()); | |
1049 for (int i = 0; i < args.length(); i++) { | |
1050 i::JSArray::SetElement(args_array, | |
1051 i, | |
1052 v8::Utils::OpenHandle(*v8::String::New(args[i])), | |
1053 NONE, | |
1054 i::kNonStrictMode); | |
1055 } | |
1056 i::Handle<i::JSObject> builtins(i::Isolate::Current()->js_builtins_object()); | |
1057 i::Handle<i::Object> format_fun = | |
1058 i::GetProperty(builtins, "FormatMessage"); | |
1059 i::Handle<i::Object> arg_handles[] = { format, args_array }; | |
1060 bool has_exception = false; | |
1061 i::Handle<i::Object> result = | |
1062 i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); | |
1063 CHECK(!has_exception); | |
1064 CHECK(result->IsString()); | |
1065 return i::Handle<i::String>::cast(result); | |
1066 } | |
1067 | |
1068 | |
1044 void TestParserSync(i::Handle<i::String> source, int flags) { | 1069 void TestParserSync(i::Handle<i::String> source, int flags) { |
1045 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 1070 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
1046 bool harmony_scoping = ((i::kLanguageModeMask & flags) == i::EXTENDED_MODE); | 1071 bool harmony_scoping = ((i::kLanguageModeMask & flags) == i::EXTENDED_MODE); |
1047 | 1072 |
1048 // Preparse the data. | 1073 // Preparse the data. |
1049 i::CompleteParserRecorder log; | 1074 i::CompleteParserRecorder log; |
1050 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 1075 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
1051 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1076 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
1052 scanner.SetHarmonyScoping(harmony_scoping); | 1077 scanner.SetHarmonyScoping(harmony_scoping); |
1053 scanner.Initialize(&stream); | 1078 scanner.Initialize(&stream); |
1054 v8::preparser::PreParser::PreParseResult result = | 1079 v8::preparser::PreParser::PreParseResult result = |
1055 v8::preparser::PreParser::PreParseProgram( | 1080 v8::preparser::PreParser::PreParseProgram( |
1056 &scanner, &log, flags, stack_limit); | 1081 &scanner, &log, flags, stack_limit); |
1057 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 1082 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
1058 i::ScriptDataImpl data(log.ExtractData()); | 1083 i::ScriptDataImpl data(log.ExtractData()); |
1059 | 1084 |
1060 // Parse the data | 1085 // Parse the data |
1061 i::Handle<i::Script> script = FACTORY->NewScript(source); | 1086 i::Handle<i::Script> script = FACTORY->NewScript(source); |
1062 bool save_harmony_scoping = i::FLAG_harmony_scoping; | 1087 bool save_harmony_scoping = i::FLAG_harmony_scoping; |
1063 i::FLAG_harmony_scoping = harmony_scoping; | 1088 i::FLAG_harmony_scoping = harmony_scoping; |
1064 i::CompilationInfoWithZone info(script); | 1089 i::CompilationInfoWithZone info(script); |
1065 i::Parser parser(&info, flags, NULL, NULL); | 1090 i::Parser parser(&info, flags, NULL, NULL); |
1066 info.MarkAsGlobal(); | 1091 info.MarkAsGlobal(); |
1067 i::FunctionLiteral* function = parser.ParseProgram(); | 1092 i::FunctionLiteral* function = parser.ParseProgram(); |
1068 i::FLAG_harmony_scoping = save_harmony_scoping; | 1093 i::FLAG_harmony_scoping = save_harmony_scoping; |
1069 | 1094 |
1070 i::String* type_string = NULL; | 1095 i::Handle<i::String> message_string; |
Sven Panne
2012/11/14 08:40:35
Remove this line, merging it with the initializati
| |
1071 if (function == NULL) { | 1096 if (function == NULL) { |
1072 // Extract exception from the parser. | 1097 // Extract exception from the parser. |
1073 i::Handle<i::String> type_symbol = FACTORY->LookupAsciiSymbol("type"); | |
1074 CHECK(i::Isolate::Current()->has_pending_exception()); | 1098 CHECK(i::Isolate::Current()->has_pending_exception()); |
1075 i::MaybeObject* maybe_object = i::Isolate::Current()->pending_exception(); | 1099 i::MaybeObject* maybe_object = i::Isolate::Current()->pending_exception(); |
1076 i::JSObject* exception = NULL; | 1100 i::JSObject* exception = NULL; |
1077 CHECK(maybe_object->To(&exception)); | 1101 CHECK(maybe_object->To(&exception)); |
1078 | 1102 i::Handle<i::JSObject> exception_handle(exception); |
1079 // Get the type string. | 1103 message_string = i::GetProperty(exception_handle, "message"); |
1080 maybe_object = exception->GetProperty(*type_symbol); | |
1081 CHECK(maybe_object->To(&type_string)); | |
1082 } | 1104 } |
1083 | 1105 |
1084 // Check that preparsing fails iff parsing fails. | 1106 // Check that preparsing fails iff parsing fails. |
1085 if (data.has_error() && function != NULL) { | 1107 if (data.has_error() && function != NULL) { |
1086 i::OS::Print( | 1108 i::OS::Print( |
1087 "Preparser failed on:\n" | 1109 "Preparser failed on:\n" |
1088 "\t%s\n" | 1110 "\t%s\n" |
1089 "with error:\n" | 1111 "with error:\n" |
1090 "\t%s\n" | 1112 "\t%s\n" |
1091 "However, the parser succeeded", | 1113 "However, the parser succeeded", |
1092 *source->ToCString(), data.BuildMessage()); | 1114 *source->ToCString(), *FormatMessage(&data)->ToCString()); |
1093 CHECK(false); | 1115 CHECK(false); |
1094 } else if (!data.has_error() && function == NULL) { | 1116 } else if (!data.has_error() && function == NULL) { |
1095 i::OS::Print( | 1117 i::OS::Print( |
1096 "Parser failed on:\n" | 1118 "Parser failed on:\n" |
1097 "\t%s\n" | 1119 "\t%s\n" |
1098 "with error:\n" | 1120 "with error:\n" |
1099 "\t%s\n" | 1121 "\t%s\n" |
1100 "However, the preparser succeeded", | 1122 "However, the preparser succeeded", |
1101 *source->ToCString(), *type_string->ToCString()); | 1123 *source->ToCString(), *message_string->ToCString()); |
1102 CHECK(false); | 1124 CHECK(false); |
1103 } | 1125 } |
1104 | 1126 |
1105 // Check that preparser and parser produce the same error. | 1127 // Check that preparser and parser produce the same error. |
1106 if (function == NULL) { | 1128 if (function == NULL) { |
1107 if (!type_string->IsEqualTo(i::CStrVector(data.BuildMessage()))) { | 1129 i::Handle<i::String> preparser_message = FormatMessage(&data); |
1130 if (!message_string->Equals(*preparser_message)) { | |
1108 i::OS::Print( | 1131 i::OS::Print( |
1109 "Expected parser and preparser to produce the same error on:\n" | 1132 "Expected parser and preparser to produce the same error on:\n" |
1110 "\t%s\n" | 1133 "\t%s\n" |
1111 "However, found the following error messages\n" | 1134 "However, found the following error messages\n" |
1112 "\tparser: %s\n" | 1135 "\tparser: %s\n" |
1113 "\tpreparser: %s\n", | 1136 "\tpreparser: %s\n", |
1114 *source->ToCString(), *type_string->ToCString(), data.BuildMessage()); | 1137 *source->ToCString(), |
1138 *message_string->ToCString(), | |
1139 *preparser_message->ToCString()); | |
1115 CHECK(false); | 1140 CHECK(false); |
1116 } | 1141 } |
1117 } | 1142 } |
1118 } | 1143 } |
1119 | 1144 |
1120 | 1145 |
1121 void TestParserSyncWithFlags(i::Handle<i::String> source) { | 1146 void TestParserSyncWithFlags(i::Handle<i::String> source) { |
1122 static const int kFlagsCount = 6; | 1147 static const int kFlagsCount = 6; |
1123 const int flags[kFlagsCount] = { | 1148 const int flags[kFlagsCount] = { |
1124 i::kNoParsingFlags | i::CLASSIC_MODE, | 1149 i::kNoParsingFlags | i::CLASSIC_MODE, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1254 " b = function() { \n" | 1279 " b = function() { \n" |
1255 " 01; \n" | 1280 " 01; \n" |
1256 " }; \n" | 1281 " }; \n" |
1257 "}; \n"; | 1282 "}; \n"; |
1258 v8::Script::Compile(v8::String::New(script)); | 1283 v8::Script::Compile(v8::String::New(script)); |
1259 CHECK(try_catch.HasCaught()); | 1284 CHECK(try_catch.HasCaught()); |
1260 v8::String::Utf8Value exception(try_catch.Exception()); | 1285 v8::String::Utf8Value exception(try_catch.Exception()); |
1261 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1286 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
1262 *exception); | 1287 *exception); |
1263 } | 1288 } |
OLD | NEW |