| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 255 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 256 for (int i = 0; programs[i]; i++) { | 256 for (int i = 0; programs[i]; i++) { |
| 257 const char* program = programs[i]; | 257 const char* program = programs[i]; |
| 258 i::Utf8ToUtf16CharacterStream stream( | 258 i::Utf8ToUtf16CharacterStream stream( |
| 259 reinterpret_cast<const i::byte*>(program), | 259 reinterpret_cast<const i::byte*>(program), |
| 260 static_cast<unsigned>(strlen(program))); | 260 static_cast<unsigned>(strlen(program))); |
| 261 i::CompleteParserRecorder log; | 261 i::CompleteParserRecorder log; |
| 262 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 262 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 263 scanner.Initialize(&stream); | 263 scanner.Initialize(&stream); |
| 264 | 264 |
| 265 int flags = i::kAllowLazy | i::kAllowNativesSyntax; | 265 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); |
| 266 preparser.set_allow_lazy(true); |
| 267 preparser.set_allow_natives_syntax(true); |
| 266 v8::preparser::PreParser::PreParseResult result = | 268 v8::preparser::PreParser::PreParseResult result = |
| 267 v8::preparser::PreParser::PreParseProgram(&scanner, | 269 preparser.PreParseProgram(); |
| 268 &log, | |
| 269 flags, | |
| 270 stack_limit); | |
| 271 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 270 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 272 i::ScriptDataImpl data(log.ExtractData()); | 271 i::ScriptDataImpl data(log.ExtractData()); |
| 273 CHECK(!data.has_error()); | 272 CHECK(!data.has_error()); |
| 274 } | 273 } |
| 275 } | 274 } |
| 276 | 275 |
| 277 | 276 |
| 278 TEST(StandAlonePreParserNoNatives) { | 277 TEST(StandAlonePreParserNoNatives) { |
| 279 v8::V8::Initialize(); | 278 v8::V8::Initialize(); |
| 280 | 279 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 291 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 290 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 292 for (int i = 0; programs[i]; i++) { | 291 for (int i = 0; programs[i]; i++) { |
| 293 const char* program = programs[i]; | 292 const char* program = programs[i]; |
| 294 i::Utf8ToUtf16CharacterStream stream( | 293 i::Utf8ToUtf16CharacterStream stream( |
| 295 reinterpret_cast<const i::byte*>(program), | 294 reinterpret_cast<const i::byte*>(program), |
| 296 static_cast<unsigned>(strlen(program))); | 295 static_cast<unsigned>(strlen(program))); |
| 297 i::CompleteParserRecorder log; | 296 i::CompleteParserRecorder log; |
| 298 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 297 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 299 scanner.Initialize(&stream); | 298 scanner.Initialize(&stream); |
| 300 | 299 |
| 301 // Flags don't allow natives syntax. | 300 // Preparser defaults to disallowing natives syntax. |
| 301 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); |
| 302 preparser.set_allow_lazy(true); |
| 302 v8::preparser::PreParser::PreParseResult result = | 303 v8::preparser::PreParser::PreParseResult result = |
| 303 v8::preparser::PreParser::PreParseProgram(&scanner, | 304 preparser.PreParseProgram(); |
| 304 &log, | |
| 305 i::kAllowLazy, | |
| 306 stack_limit); | |
| 307 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 305 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 308 i::ScriptDataImpl data(log.ExtractData()); | 306 i::ScriptDataImpl data(log.ExtractData()); |
| 309 // Data contains syntax error. | 307 // Data contains syntax error. |
| 310 CHECK(data.has_error()); | 308 CHECK(data.has_error()); |
| 311 } | 309 } |
| 312 } | 310 } |
| 313 | 311 |
| 314 | 312 |
| 315 TEST(RegressChromium62639) { | 313 TEST(RegressChromium62639) { |
| 316 v8::V8::Initialize(); | 314 v8::V8::Initialize(); |
| 317 | 315 |
| 318 int marker; | 316 int marker; |
| 319 i::Isolate::Current()->stack_guard()->SetStackLimit( | 317 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 320 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 318 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 321 | 319 |
| 322 const char* program = "var x = 'something';\n" | 320 const char* program = "var x = 'something';\n" |
| 323 "escape: function() {}"; | 321 "escape: function() {}"; |
| 324 // Fails parsing expecting an identifier after "function". | 322 // Fails parsing expecting an identifier after "function". |
| 325 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 323 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
| 326 // and then used the invalid currently scanned literal. This always | 324 // and then used the invalid currently scanned literal. This always |
| 327 // failed in debug mode, and sometimes crashed in release mode. | 325 // failed in debug mode, and sometimes crashed in release mode. |
| 328 | 326 |
| 329 i::Utf8ToUtf16CharacterStream stream( | 327 i::Utf8ToUtf16CharacterStream stream( |
| 330 reinterpret_cast<const i::byte*>(program), | 328 reinterpret_cast<const i::byte*>(program), |
| 331 static_cast<unsigned>(strlen(program))); | 329 static_cast<unsigned>(strlen(program))); |
| 332 i::ScriptDataImpl* data = i::ParserApi::PreParse(&stream); | 330 i::ScriptDataImpl* data = i::PreParserApi::PreParse(&stream); |
| 333 CHECK(data->HasError()); | 331 CHECK(data->HasError()); |
| 334 delete data; | 332 delete data; |
| 335 } | 333 } |
| 336 | 334 |
| 337 | 335 |
| 338 TEST(Regress928) { | 336 TEST(Regress928) { |
| 339 v8::V8::Initialize(); | 337 v8::V8::Initialize(); |
| 340 | 338 |
| 341 // Preparsing didn't consider the catch clause of a try statement | 339 // Preparsing didn't consider the catch clause of a try statement |
| 342 // as with-content, which made it assume that a function inside | 340 // as with-content, which made it assume that a function inside |
| 343 // the block could be lazily compiled, and an extra, unexpected, | 341 // the block could be lazily compiled, and an extra, unexpected, |
| 344 // entry was added to the data. | 342 // entry was added to the data. |
| 345 int marker; | 343 int marker; |
| 346 i::Isolate::Current()->stack_guard()->SetStackLimit( | 344 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 347 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 345 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 348 | 346 |
| 349 const char* program = | 347 const char* program = |
| 350 "try { } catch (e) { var foo = function () { /* first */ } }" | 348 "try { } catch (e) { var foo = function () { /* first */ } }" |
| 351 "var bar = function () { /* second */ }"; | 349 "var bar = function () { /* second */ }"; |
| 352 | 350 |
| 353 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 351 v8::HandleScope handles(v8::Isolate::GetCurrent()); |
| 354 i::Handle<i::String> source( | 352 i::Handle<i::String> source( |
| 355 FACTORY->NewStringFromAscii(i::CStrVector(program))); | 353 FACTORY->NewStringFromAscii(i::CStrVector(program))); |
| 356 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 354 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 357 i::ScriptDataImpl* data = i::ParserApi::PreParse(&stream); | 355 i::ScriptDataImpl* data = i::PreParserApi::PreParse(&stream); |
| 358 CHECK(!data->HasError()); | 356 CHECK(!data->HasError()); |
| 359 | 357 |
| 360 data->Initialize(); | 358 data->Initialize(); |
| 361 | 359 |
| 362 int first_function = | 360 int first_function = |
| 363 static_cast<int>(strstr(program, "function") - program); | 361 static_cast<int>(strstr(program, "function") - program); |
| 364 int first_lbrace = first_function + i::StrLength("function () "); | 362 int first_lbrace = first_function + i::StrLength("function () "); |
| 365 CHECK_EQ('{', program[first_lbrace]); | 363 CHECK_EQ('{', program[first_lbrace]); |
| 366 i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace); | 364 i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace); |
| 367 CHECK(!entry1.is_valid()); | 365 CHECK(!entry1.is_valid()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 393 | 391 |
| 394 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 392 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 395 | 393 |
| 396 i::Utf8ToUtf16CharacterStream stream( | 394 i::Utf8ToUtf16CharacterStream stream( |
| 397 reinterpret_cast<const i::byte*>(*program), | 395 reinterpret_cast<const i::byte*>(*program), |
| 398 static_cast<unsigned>(kProgramSize)); | 396 static_cast<unsigned>(kProgramSize)); |
| 399 i::CompleteParserRecorder log; | 397 i::CompleteParserRecorder log; |
| 400 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 398 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 401 scanner.Initialize(&stream); | 399 scanner.Initialize(&stream); |
| 402 | 400 |
| 403 | 401 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); |
| 402 preparser.set_allow_lazy(true); |
| 404 v8::preparser::PreParser::PreParseResult result = | 403 v8::preparser::PreParser::PreParseResult result = |
| 405 v8::preparser::PreParser::PreParseProgram(&scanner, | 404 preparser.PreParseProgram(); |
| 406 &log, | |
| 407 true, | |
| 408 stack_limit); | |
| 409 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); | 405 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); |
| 410 } | 406 } |
| 411 | 407 |
| 412 | 408 |
| 413 class TestExternalResource: public v8::String::ExternalStringResource { | 409 class TestExternalResource: public v8::String::ExternalStringResource { |
| 414 public: | 410 public: |
| 415 explicit TestExternalResource(uint16_t* data, int length) | 411 explicit TestExternalResource(uint16_t* data, int length) |
| 416 : data_(data), length_(static_cast<size_t>(length)) { } | 412 : data_(data), length_(static_cast<size_t>(length)) { } |
| 417 | 413 |
| 418 ~TestExternalResource() { } | 414 ~TestExternalResource() { } |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } | 983 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } |
| 988 }; | 984 }; |
| 989 | 985 |
| 990 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 986 v8::HandleScope handles(v8::Isolate::GetCurrent()); |
| 991 v8::Persistent<v8::Context> context = v8::Context::New(); | 987 v8::Persistent<v8::Context> context = v8::Context::New(); |
| 992 v8::Context::Scope context_scope(context); | 988 v8::Context::Scope context_scope(context); |
| 993 | 989 |
| 994 int marker; | 990 int marker; |
| 995 i::Isolate::Current()->stack_guard()->SetStackLimit( | 991 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 996 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 992 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 997 i::FLAG_harmony_scoping = true; | |
| 998 | 993 |
| 999 for (int i = 0; source_data[i].outer_prefix; i++) { | 994 for (int i = 0; source_data[i].outer_prefix; i++) { |
| 1000 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); | 995 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); |
| 1001 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); | 996 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); |
| 1002 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); | 997 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); |
| 1003 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); | 998 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); |
| 1004 int kInnerByteLen = i::StrLength(source_data[i].inner_source); | 999 int kInnerByteLen = i::StrLength(source_data[i].inner_source); |
| 1005 int kSuffixByteLen = i::StrLength(source_data[i].outer_suffix); | 1000 int kSuffixByteLen = i::StrLength(source_data[i].outer_suffix); |
| 1006 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; | 1001 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; |
| 1007 int kProgramByteSize = kPrefixByteLen + kInnerByteLen + kSuffixByteLen; | 1002 int kProgramByteSize = kPrefixByteLen + kInnerByteLen + kSuffixByteLen; |
| 1008 i::Vector<char> program = i::Vector<char>::New(kProgramByteSize + 1); | 1003 i::Vector<char> program = i::Vector<char>::New(kProgramByteSize + 1); |
| 1009 i::OS::SNPrintF(program, "%s%s%s", | 1004 i::OS::SNPrintF(program, "%s%s%s", |
| 1010 source_data[i].outer_prefix, | 1005 source_data[i].outer_prefix, |
| 1011 source_data[i].inner_source, | 1006 source_data[i].inner_source, |
| 1012 source_data[i].outer_suffix); | 1007 source_data[i].outer_suffix); |
| 1013 | 1008 |
| 1014 // Parse program source. | 1009 // Parse program source. |
| 1015 i::Handle<i::String> source( | 1010 i::Handle<i::String> source( |
| 1016 FACTORY->NewStringFromUtf8(i::CStrVector(program.start()))); | 1011 FACTORY->NewStringFromUtf8(i::CStrVector(program.start()))); |
| 1017 CHECK_EQ(source->length(), kProgramSize); | 1012 CHECK_EQ(source->length(), kProgramSize); |
| 1018 i::Handle<i::Script> script = FACTORY->NewScript(source); | 1013 i::Handle<i::Script> script = FACTORY->NewScript(source); |
| 1019 i::CompilationInfoWithZone info(script); | 1014 i::CompilationInfoWithZone info(script); |
| 1020 i::Parser parser(&info, i::kAllowLazy | i::EXTENDED_MODE, NULL, NULL); | 1015 i::Parser parser(&info); |
| 1016 parser.set_allow_lazy(true); |
| 1017 parser.set_allow_harmony_scoping(true); |
| 1021 info.MarkAsGlobal(); | 1018 info.MarkAsGlobal(); |
| 1022 info.SetLanguageMode(source_data[i].language_mode); | 1019 info.SetLanguageMode(source_data[i].language_mode); |
| 1023 i::FunctionLiteral* function = parser.ParseProgram(); | 1020 i::FunctionLiteral* function = parser.ParseProgram(); |
| 1024 CHECK(function != NULL); | 1021 CHECK(function != NULL); |
| 1025 | 1022 |
| 1026 // Check scope types and positions. | 1023 // Check scope types and positions. |
| 1027 i::Scope* scope = function->scope(); | 1024 i::Scope* scope = function->scope(); |
| 1028 CHECK(scope->is_global_scope()); | 1025 CHECK(scope->is_global_scope()); |
| 1029 CHECK_EQ(scope->start_position(), 0); | 1026 CHECK_EQ(scope->start_position(), 0); |
| 1030 CHECK_EQ(scope->end_position(), kProgramSize); | 1027 CHECK_EQ(scope->end_position(), kProgramSize); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1058 i::Handle<i::Object> arg_handles[] = { format, args_array }; | 1055 i::Handle<i::Object> arg_handles[] = { format, args_array }; |
| 1059 bool has_exception = false; | 1056 bool has_exception = false; |
| 1060 i::Handle<i::Object> result = | 1057 i::Handle<i::Object> result = |
| 1061 i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); | 1058 i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); |
| 1062 CHECK(!has_exception); | 1059 CHECK(!has_exception); |
| 1063 CHECK(result->IsString()); | 1060 CHECK(result->IsString()); |
| 1064 return i::Handle<i::String>::cast(result); | 1061 return i::Handle<i::String>::cast(result); |
| 1065 } | 1062 } |
| 1066 | 1063 |
| 1067 | 1064 |
| 1068 void TestParserSync(i::Handle<i::String> source, int flags) { | 1065 enum ParserFlag { |
| 1066 kAllowLazy, |
| 1067 kAllowNativesSyntax, |
| 1068 kAllowHarmonyScoping, |
| 1069 kAllowModules, |
| 1070 kAllowGenerators, |
| 1071 kParserFlagCount |
| 1072 }; |
| 1073 |
| 1074 |
| 1075 static bool checkParserFlag(unsigned flags, ParserFlag flag) { |
| 1076 return flags & (1 << flag); |
| 1077 } |
| 1078 |
| 1079 |
| 1080 #define SET_PARSER_FLAGS(parser, flags) \ |
| 1081 parser.set_allow_lazy(checkParserFlag(flags, kAllowLazy)); \ |
| 1082 parser.set_allow_natives_syntax(checkParserFlag(flags, \ |
| 1083 kAllowNativesSyntax)); \ |
| 1084 parser.set_allow_harmony_scoping(checkParserFlag(flags, \ |
| 1085 kAllowHarmonyScoping)); \ |
| 1086 parser.set_allow_modules(checkParserFlag(flags, kAllowModules)); \ |
| 1087 parser.set_allow_generators(checkParserFlag(flags, kAllowGenerators)); |
| 1088 |
| 1089 void TestParserSyncWithFlags(i::Handle<i::String> source, unsigned flags) { |
| 1069 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 1090 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 1070 bool harmony_scoping = ((i::kLanguageModeMask & flags) == i::EXTENDED_MODE); | |
| 1071 | 1091 |
| 1072 // Preparse the data. | 1092 // Preparse the data. |
| 1073 i::CompleteParserRecorder log; | 1093 i::CompleteParserRecorder log; |
| 1074 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 1094 { |
| 1075 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1095 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 1076 scanner.SetHarmonyScoping(harmony_scoping); | 1096 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 1077 scanner.Initialize(&stream); | 1097 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); |
| 1078 v8::preparser::PreParser::PreParseResult result = | 1098 SET_PARSER_FLAGS(preparser, flags); |
| 1079 v8::preparser::PreParser::PreParseProgram( | 1099 scanner.Initialize(&stream); |
| 1080 &scanner, &log, flags, stack_limit); | 1100 v8::preparser::PreParser::PreParseResult result = |
| 1081 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 1101 preparser.PreParseProgram(); |
| 1102 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 1103 } |
| 1082 i::ScriptDataImpl data(log.ExtractData()); | 1104 i::ScriptDataImpl data(log.ExtractData()); |
| 1083 | 1105 |
| 1084 // Parse the data | 1106 // Parse the data |
| 1085 i::Handle<i::Script> script = FACTORY->NewScript(source); | 1107 i::FunctionLiteral* function; |
| 1086 bool save_harmony_scoping = i::FLAG_harmony_scoping; | 1108 { |
| 1087 i::FLAG_harmony_scoping = harmony_scoping; | 1109 i::Handle<i::Script> script = FACTORY->NewScript(source); |
| 1088 i::CompilationInfoWithZone info(script); | 1110 i::CompilationInfoWithZone info(script); |
| 1089 i::Parser parser(&info, flags, NULL, NULL); | 1111 i::Parser parser(&info); |
| 1090 info.MarkAsGlobal(); | 1112 SET_PARSER_FLAGS(parser, flags); |
| 1091 i::FunctionLiteral* function = parser.ParseProgram(); | 1113 info.MarkAsGlobal(); |
| 1092 i::FLAG_harmony_scoping = save_harmony_scoping; | 1114 function = parser.ParseProgram(); |
| 1115 } |
| 1093 | 1116 |
| 1094 // Check that preparsing fails iff parsing fails. | 1117 // Check that preparsing fails iff parsing fails. |
| 1095 if (function == NULL) { | 1118 if (function == NULL) { |
| 1096 // Extract exception from the parser. | 1119 // Extract exception from the parser. |
| 1097 CHECK(i::Isolate::Current()->has_pending_exception()); | 1120 CHECK(i::Isolate::Current()->has_pending_exception()); |
| 1098 i::MaybeObject* maybe_object = i::Isolate::Current()->pending_exception(); | 1121 i::MaybeObject* maybe_object = i::Isolate::Current()->pending_exception(); |
| 1099 i::JSObject* exception = NULL; | 1122 i::JSObject* exception = NULL; |
| 1100 CHECK(maybe_object->To(&exception)); | 1123 CHECK(maybe_object->To(&exception)); |
| 1101 i::Handle<i::JSObject> exception_handle(exception); | 1124 i::Handle<i::JSObject> exception_handle(exception); |
| 1102 i::Handle<i::String> message_string = | 1125 i::Handle<i::String> message_string = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1132 "\t%s\n" | 1155 "\t%s\n" |
| 1133 "with error:\n" | 1156 "with error:\n" |
| 1134 "\t%s\n" | 1157 "\t%s\n" |
| 1135 "However, the parser succeeded", | 1158 "However, the parser succeeded", |
| 1136 *source->ToCString(), *FormatMessage(&data)->ToCString()); | 1159 *source->ToCString(), *FormatMessage(&data)->ToCString()); |
| 1137 CHECK(false); | 1160 CHECK(false); |
| 1138 } | 1161 } |
| 1139 } | 1162 } |
| 1140 | 1163 |
| 1141 | 1164 |
| 1142 void TestParserSyncWithFlags(i::Handle<i::String> source) { | 1165 void TestParserSync(i::Handle<i::String> source) { |
| 1143 static const int kFlagsCount = 6; | 1166 for (unsigned flags = 0; flags < (1 << kParserFlagCount); ++flags) { |
| 1144 const int flags[kFlagsCount] = { | 1167 TestParserSyncWithFlags(source, flags); |
| 1145 i::kNoParsingFlags | i::CLASSIC_MODE, | |
| 1146 i::kNoParsingFlags | i::STRICT_MODE, | |
| 1147 i::kNoParsingFlags | i::EXTENDED_MODE, | |
| 1148 i::kAllowLazy | i::CLASSIC_MODE, | |
| 1149 i::kAllowLazy | i::STRICT_MODE, | |
| 1150 i::kAllowLazy | i::EXTENDED_MODE | |
| 1151 }; | |
| 1152 | |
| 1153 for (int k = 0; k < kFlagsCount; ++k) { | |
| 1154 TestParserSync(source, flags[k]); | |
| 1155 } | 1168 } |
| 1156 } | 1169 } |
| 1157 | 1170 |
| 1158 | 1171 |
| 1159 TEST(ParserSync) { | 1172 TEST(ParserSync) { |
| 1160 const char* context_data[][2] = { | 1173 const char* context_data[][2] = { |
| 1161 { "", "" }, | 1174 { "", "" }, |
| 1162 { "{", "}" }, | 1175 { "{", "}" }, |
| 1163 { "if (true) ", " else {}" }, | 1176 { "if (true) ", " else {}" }, |
| 1164 { "if (true) {} else ", "" }, | 1177 { "if (true) {} else ", "" }, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1); | 1260 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1); |
| 1248 int length = i::OS::SNPrintF(program, | 1261 int length = i::OS::SNPrintF(program, |
| 1249 "label: for (;;) { %s%s%s%s }", | 1262 "label: for (;;) { %s%s%s%s }", |
| 1250 context_data[i][0], | 1263 context_data[i][0], |
| 1251 statement_data[j], | 1264 statement_data[j], |
| 1252 termination_data[k], | 1265 termination_data[k], |
| 1253 context_data[i][1]); | 1266 context_data[i][1]); |
| 1254 CHECK(length == kProgramSize); | 1267 CHECK(length == kProgramSize); |
| 1255 i::Handle<i::String> source = | 1268 i::Handle<i::String> source = |
| 1256 FACTORY->NewStringFromAscii(i::CStrVector(program.start())); | 1269 FACTORY->NewStringFromAscii(i::CStrVector(program.start())); |
| 1257 TestParserSyncWithFlags(source); | 1270 TestParserSync(source); |
| 1258 } | 1271 } |
| 1259 } | 1272 } |
| 1260 } | 1273 } |
| 1261 } | 1274 } |
| 1262 | 1275 |
| 1263 | 1276 |
| 1264 TEST(PreparserStrictOctal) { | 1277 TEST(PreparserStrictOctal) { |
| 1265 // Test that syntax error caused by octal literal is reported correctly as | 1278 // Test that syntax error caused by octal literal is reported correctly as |
| 1266 // such (issue 2220). | 1279 // such (issue 2220). |
| 1267 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. | 1280 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. |
| 1268 v8::V8::Initialize(); | 1281 v8::V8::Initialize(); |
| 1269 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1282 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 1270 v8::Context::Scope context_scope(v8::Context::New()); | 1283 v8::Context::Scope context_scope(v8::Context::New()); |
| 1271 v8::TryCatch try_catch; | 1284 v8::TryCatch try_catch; |
| 1272 const char* script = | 1285 const char* script = |
| 1273 "\"use strict\"; \n" | 1286 "\"use strict\"; \n" |
| 1274 "a = function() { \n" | 1287 "a = function() { \n" |
| 1275 " b = function() { \n" | 1288 " b = function() { \n" |
| 1276 " 01; \n" | 1289 " 01; \n" |
| 1277 " }; \n" | 1290 " }; \n" |
| 1278 "}; \n"; | 1291 "}; \n"; |
| 1279 v8::Script::Compile(v8::String::New(script)); | 1292 v8::Script::Compile(v8::String::New(script)); |
| 1280 CHECK(try_catch.HasCaught()); | 1293 CHECK(try_catch.HasCaught()); |
| 1281 v8::String::Utf8Value exception(try_catch.Exception()); | 1294 v8::String::Utf8Value exception(try_catch.Exception()); |
| 1282 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1295 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
| 1283 *exception); | 1296 *exception); |
| 1284 } | 1297 } |
| OLD | NEW |