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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 reinterpret_cast<const i::byte*>(program), | 329 reinterpret_cast<const i::byte*>(program), |
330 static_cast<unsigned>(strlen(program))); | 330 static_cast<unsigned>(strlen(program))); |
331 i::ScriptDataImpl* data = i::PreParserApi::PreParse(&stream); | 331 i::ScriptDataImpl* data = i::PreParserApi::PreParse(&stream); |
332 CHECK(data->HasError()); | 332 CHECK(data->HasError()); |
333 delete data; | 333 delete data; |
334 } | 334 } |
335 | 335 |
336 | 336 |
337 TEST(Regress928) { | 337 TEST(Regress928) { |
338 v8::V8::Initialize(); | 338 v8::V8::Initialize(); |
| 339 i::Isolate* isolate = i::Isolate::Current(); |
| 340 i::Factory* factory = isolate->factory(); |
339 | 341 |
340 // Preparsing didn't consider the catch clause of a try statement | 342 // Preparsing didn't consider the catch clause of a try statement |
341 // as with-content, which made it assume that a function inside | 343 // as with-content, which made it assume that a function inside |
342 // the block could be lazily compiled, and an extra, unexpected, | 344 // the block could be lazily compiled, and an extra, unexpected, |
343 // entry was added to the data. | 345 // entry was added to the data. |
344 int marker; | 346 int marker; |
345 i::Isolate::Current()->stack_guard()->SetStackLimit( | 347 isolate->stack_guard()->SetStackLimit( |
346 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 348 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
347 | 349 |
348 const char* program = | 350 const char* program = |
349 "try { } catch (e) { var foo = function () { /* first */ } }" | 351 "try { } catch (e) { var foo = function () { /* first */ } }" |
350 "var bar = function () { /* second */ }"; | 352 "var bar = function () { /* second */ }"; |
351 | 353 |
352 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 354 v8::HandleScope handles(v8::Isolate::GetCurrent()); |
353 i::Handle<i::String> source( | 355 i::Handle<i::String> source( |
354 FACTORY->NewStringFromAscii(i::CStrVector(program))); | 356 factory->NewStringFromAscii(i::CStrVector(program))); |
355 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 357 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
356 i::ScriptDataImpl* data = i::PreParserApi::PreParse(&stream); | 358 i::ScriptDataImpl* data = i::PreParserApi::PreParse(&stream); |
357 CHECK(!data->HasError()); | 359 CHECK(!data->HasError()); |
358 | 360 |
359 data->Initialize(); | 361 data->Initialize(); |
360 | 362 |
361 int first_function = | 363 int first_function = |
362 static_cast<int>(strstr(program, "function") - program); | 364 static_cast<int>(strstr(program, "function") - program); |
363 int first_lbrace = first_function + i::StrLength("function () "); | 365 int first_lbrace = first_function + i::StrLength("function () "); |
364 CHECK_EQ('{', program[first_lbrace]); | 366 CHECK_EQ('{', program[first_lbrace]); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 429 |
428 | 430 |
429 #define CHECK_EQU(v1, v2) CHECK_EQ(static_cast<int>(v1), static_cast<int>(v2)) | 431 #define CHECK_EQU(v1, v2) CHECK_EQ(static_cast<int>(v1), static_cast<int>(v2)) |
430 | 432 |
431 void TestCharacterStream(const char* ascii_source, | 433 void TestCharacterStream(const char* ascii_source, |
432 unsigned length, | 434 unsigned length, |
433 unsigned start = 0, | 435 unsigned start = 0, |
434 unsigned end = 0) { | 436 unsigned end = 0) { |
435 if (end == 0) end = length; | 437 if (end == 0) end = length; |
436 unsigned sub_length = end - start; | 438 unsigned sub_length = end - start; |
437 i::HandleScope test_scope(i::Isolate::Current()); | 439 i::Isolate* isolate = i::Isolate::Current(); |
| 440 i::Factory* factory = isolate->factory(); |
| 441 i::HandleScope test_scope(isolate); |
438 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); | 442 i::SmartArrayPointer<i::uc16> uc16_buffer(new i::uc16[length]); |
439 for (unsigned i = 0; i < length; i++) { | 443 for (unsigned i = 0; i < length; i++) { |
440 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); | 444 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); |
441 } | 445 } |
442 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); | 446 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); |
443 i::Handle<i::String> ascii_string( | 447 i::Handle<i::String> ascii_string( |
444 FACTORY->NewStringFromAscii(ascii_vector)); | 448 factory->NewStringFromAscii(ascii_vector)); |
445 TestExternalResource resource(*uc16_buffer, length); | 449 TestExternalResource resource(*uc16_buffer, length); |
446 i::Handle<i::String> uc16_string( | 450 i::Handle<i::String> uc16_string( |
447 FACTORY->NewExternalStringFromTwoByte(&resource)); | 451 factory->NewExternalStringFromTwoByte(&resource)); |
448 | 452 |
449 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( | 453 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( |
450 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); | 454 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); |
451 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); | 455 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); |
452 i::Utf8ToUtf16CharacterStream utf8_stream( | 456 i::Utf8ToUtf16CharacterStream utf8_stream( |
453 reinterpret_cast<const i::byte*>(ascii_source), end); | 457 reinterpret_cast<const i::byte*>(ascii_source), end); |
454 utf8_stream.SeekForward(start); | 458 utf8_stream.SeekForward(start); |
455 | 459 |
456 unsigned i = start; | 460 unsigned i = start; |
457 while (i < end) { | 461 while (i < end) { |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, | 981 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
978 { " 'foo';\n" | 982 { " 'foo';\n" |
979 " (function fun", "(a,b) { 'bar\355\240\201\355\260\213'; }", ")();", | 983 " (function fun", "(a,b) { 'bar\355\240\201\355\260\213'; }", ")();", |
980 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, | 984 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
981 { " 'foo';\n" | 985 { " 'foo';\n" |
982 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", | 986 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", |
983 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, | 987 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
984 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } | 988 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } |
985 }; | 989 }; |
986 | 990 |
| 991 i::Isolate* isolate = i::Isolate::Current(); |
| 992 i::Factory* factory = isolate->factory(); |
| 993 |
987 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 994 v8::HandleScope handles(v8::Isolate::GetCurrent()); |
988 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent()); | 995 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent()); |
989 v8::Context::Scope context_scope(context); | 996 v8::Context::Scope context_scope(context); |
990 | 997 |
991 int marker; | 998 int marker; |
992 i::Isolate::Current()->stack_guard()->SetStackLimit( | 999 isolate->stack_guard()->SetStackLimit( |
993 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 1000 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
994 | 1001 |
995 for (int i = 0; source_data[i].outer_prefix; i++) { | 1002 for (int i = 0; source_data[i].outer_prefix; i++) { |
996 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); | 1003 int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); |
997 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); | 1004 int kInnerLen = Utf8LengthHelper(source_data[i].inner_source); |
998 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); | 1005 int kSuffixLen = Utf8LengthHelper(source_data[i].outer_suffix); |
999 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); | 1006 int kPrefixByteLen = i::StrLength(source_data[i].outer_prefix); |
1000 int kInnerByteLen = i::StrLength(source_data[i].inner_source); | 1007 int kInnerByteLen = i::StrLength(source_data[i].inner_source); |
1001 int kSuffixByteLen = i::StrLength(source_data[i].outer_suffix); | 1008 int kSuffixByteLen = i::StrLength(source_data[i].outer_suffix); |
1002 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; | 1009 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; |
1003 int kProgramByteSize = kPrefixByteLen + kInnerByteLen + kSuffixByteLen; | 1010 int kProgramByteSize = kPrefixByteLen + kInnerByteLen + kSuffixByteLen; |
1004 i::Vector<char> program = i::Vector<char>::New(kProgramByteSize + 1); | 1011 i::Vector<char> program = i::Vector<char>::New(kProgramByteSize + 1); |
1005 i::OS::SNPrintF(program, "%s%s%s", | 1012 i::OS::SNPrintF(program, "%s%s%s", |
1006 source_data[i].outer_prefix, | 1013 source_data[i].outer_prefix, |
1007 source_data[i].inner_source, | 1014 source_data[i].inner_source, |
1008 source_data[i].outer_suffix); | 1015 source_data[i].outer_suffix); |
1009 | 1016 |
1010 // Parse program source. | 1017 // Parse program source. |
1011 i::Handle<i::String> source( | 1018 i::Handle<i::String> source( |
1012 FACTORY->NewStringFromUtf8(i::CStrVector(program.start()))); | 1019 factory->NewStringFromUtf8(i::CStrVector(program.start()))); |
1013 CHECK_EQ(source->length(), kProgramSize); | 1020 CHECK_EQ(source->length(), kProgramSize); |
1014 i::Handle<i::Script> script = FACTORY->NewScript(source); | 1021 i::Handle<i::Script> script = factory->NewScript(source); |
1015 i::CompilationInfoWithZone info(script); | 1022 i::CompilationInfoWithZone info(script); |
1016 i::Parser parser(&info); | 1023 i::Parser parser(&info); |
1017 parser.set_allow_lazy(true); | 1024 parser.set_allow_lazy(true); |
1018 parser.set_allow_harmony_scoping(true); | 1025 parser.set_allow_harmony_scoping(true); |
1019 info.MarkAsGlobal(); | 1026 info.MarkAsGlobal(); |
1020 info.SetLanguageMode(source_data[i].language_mode); | 1027 info.SetLanguageMode(source_data[i].language_mode); |
1021 i::FunctionLiteral* function = parser.ParseProgram(); | 1028 i::FunctionLiteral* function = parser.ParseProgram(); |
1022 CHECK(function != NULL); | 1029 CHECK(function != NULL); |
1023 | 1030 |
1024 // Check scope types and positions. | 1031 // Check scope types and positions. |
1025 i::Scope* scope = function->scope(); | 1032 i::Scope* scope = function->scope(); |
1026 CHECK(scope->is_global_scope()); | 1033 CHECK(scope->is_global_scope()); |
1027 CHECK_EQ(scope->start_position(), 0); | 1034 CHECK_EQ(scope->start_position(), 0); |
1028 CHECK_EQ(scope->end_position(), kProgramSize); | 1035 CHECK_EQ(scope->end_position(), kProgramSize); |
1029 CHECK_EQ(scope->inner_scopes()->length(), 1); | 1036 CHECK_EQ(scope->inner_scopes()->length(), 1); |
1030 | 1037 |
1031 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1038 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
1032 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); | 1039 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); |
1033 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 1040 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
1034 // The end position of a token is one position after the last | 1041 // The end position of a token is one position after the last |
1035 // character belonging to that token. | 1042 // character belonging to that token. |
1036 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1043 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
1037 } | 1044 } |
1038 } | 1045 } |
1039 | 1046 |
1040 | 1047 |
1041 i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) { | 1048 i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) { |
| 1049 i::Isolate* isolate = i::Isolate::Current(); |
| 1050 i::Factory* factory = isolate->factory(); |
1042 i::Handle<i::String> format = v8::Utils::OpenHandle( | 1051 i::Handle<i::String> format = v8::Utils::OpenHandle( |
1043 *v8::String::New(data->BuildMessage())); | 1052 *v8::String::New(data->BuildMessage())); |
1044 i::Vector<const char*> args = data->BuildArgs(); | 1053 i::Vector<const char*> args = data->BuildArgs(); |
1045 i::Handle<i::JSArray> args_array = FACTORY->NewJSArray(args.length()); | 1054 i::Handle<i::JSArray> args_array = factory->NewJSArray(args.length()); |
1046 for (int i = 0; i < args.length(); i++) { | 1055 for (int i = 0; i < args.length(); i++) { |
1047 i::JSArray::SetElement(args_array, | 1056 i::JSArray::SetElement(args_array, |
1048 i, | 1057 i, |
1049 v8::Utils::OpenHandle(*v8::String::New(args[i])), | 1058 v8::Utils::OpenHandle(*v8::String::New(args[i])), |
1050 NONE, | 1059 NONE, |
1051 i::kNonStrictMode); | 1060 i::kNonStrictMode); |
1052 } | 1061 } |
1053 i::Handle<i::JSObject> builtins(i::Isolate::Current()->js_builtins_object()); | 1062 i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); |
1054 i::Handle<i::Object> format_fun = | 1063 i::Handle<i::Object> format_fun = |
1055 i::GetProperty(builtins, "FormatMessage"); | 1064 i::GetProperty(builtins, "FormatMessage"); |
1056 i::Handle<i::Object> arg_handles[] = { format, args_array }; | 1065 i::Handle<i::Object> arg_handles[] = { format, args_array }; |
1057 bool has_exception = false; | 1066 bool has_exception = false; |
1058 i::Handle<i::Object> result = | 1067 i::Handle<i::Object> result = |
1059 i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); | 1068 i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); |
1060 CHECK(!has_exception); | 1069 CHECK(!has_exception); |
1061 CHECK(result->IsString()); | 1070 CHECK(result->IsString()); |
1062 return i::Handle<i::String>::cast(result); | 1071 return i::Handle<i::String>::cast(result); |
1063 } | 1072 } |
(...skipping 17 matching lines...) Expand all Loading... |
1081 #define SET_PARSER_FLAGS(parser, flags) \ | 1090 #define SET_PARSER_FLAGS(parser, flags) \ |
1082 parser.set_allow_lazy(checkParserFlag(flags, kAllowLazy)); \ | 1091 parser.set_allow_lazy(checkParserFlag(flags, kAllowLazy)); \ |
1083 parser.set_allow_natives_syntax(checkParserFlag(flags, \ | 1092 parser.set_allow_natives_syntax(checkParserFlag(flags, \ |
1084 kAllowNativesSyntax)); \ | 1093 kAllowNativesSyntax)); \ |
1085 parser.set_allow_harmony_scoping(checkParserFlag(flags, \ | 1094 parser.set_allow_harmony_scoping(checkParserFlag(flags, \ |
1086 kAllowHarmonyScoping)); \ | 1095 kAllowHarmonyScoping)); \ |
1087 parser.set_allow_modules(checkParserFlag(flags, kAllowModules)); \ | 1096 parser.set_allow_modules(checkParserFlag(flags, kAllowModules)); \ |
1088 parser.set_allow_generators(checkParserFlag(flags, kAllowGenerators)); | 1097 parser.set_allow_generators(checkParserFlag(flags, kAllowGenerators)); |
1089 | 1098 |
1090 void TestParserSyncWithFlags(i::Handle<i::String> source, unsigned flags) { | 1099 void TestParserSyncWithFlags(i::Handle<i::String> source, unsigned flags) { |
1091 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 1100 i::Isolate* isolate = i::Isolate::Current(); |
| 1101 i::Factory* factory = isolate->factory(); |
| 1102 |
| 1103 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
1092 | 1104 |
1093 // Preparse the data. | 1105 // Preparse the data. |
1094 i::CompleteParserRecorder log; | 1106 i::CompleteParserRecorder log; |
1095 { | 1107 { |
1096 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 1108 i::Scanner scanner(isolate->unicode_cache()); |
1097 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1109 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
1098 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); | 1110 v8::preparser::PreParser preparser(&scanner, &log, stack_limit); |
1099 SET_PARSER_FLAGS(preparser, flags); | 1111 SET_PARSER_FLAGS(preparser, flags); |
1100 scanner.Initialize(&stream); | 1112 scanner.Initialize(&stream); |
1101 v8::preparser::PreParser::PreParseResult result = | 1113 v8::preparser::PreParser::PreParseResult result = |
1102 preparser.PreParseProgram(); | 1114 preparser.PreParseProgram(); |
1103 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 1115 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
1104 } | 1116 } |
1105 i::ScriptDataImpl data(log.ExtractData()); | 1117 i::ScriptDataImpl data(log.ExtractData()); |
1106 | 1118 |
1107 // Parse the data | 1119 // Parse the data |
1108 i::FunctionLiteral* function; | 1120 i::FunctionLiteral* function; |
1109 { | 1121 { |
1110 i::Handle<i::Script> script = FACTORY->NewScript(source); | 1122 i::Handle<i::Script> script = factory->NewScript(source); |
1111 i::CompilationInfoWithZone info(script); | 1123 i::CompilationInfoWithZone info(script); |
1112 i::Parser parser(&info); | 1124 i::Parser parser(&info); |
1113 SET_PARSER_FLAGS(parser, flags); | 1125 SET_PARSER_FLAGS(parser, flags); |
1114 info.MarkAsGlobal(); | 1126 info.MarkAsGlobal(); |
1115 function = parser.ParseProgram(); | 1127 function = parser.ParseProgram(); |
1116 } | 1128 } |
1117 | 1129 |
1118 // Check that preparsing fails iff parsing fails. | 1130 // Check that preparsing fails iff parsing fails. |
1119 if (function == NULL) { | 1131 if (function == NULL) { |
1120 // Extract exception from the parser. | 1132 // Extract exception from the parser. |
1121 CHECK(i::Isolate::Current()->has_pending_exception()); | 1133 CHECK(isolate->has_pending_exception()); |
1122 i::MaybeObject* maybe_object = i::Isolate::Current()->pending_exception(); | 1134 i::MaybeObject* maybe_object = isolate->pending_exception(); |
1123 i::JSObject* exception = NULL; | 1135 i::JSObject* exception = NULL; |
1124 CHECK(maybe_object->To(&exception)); | 1136 CHECK(maybe_object->To(&exception)); |
1125 i::Handle<i::JSObject> exception_handle(exception); | 1137 i::Handle<i::JSObject> exception_handle(exception); |
1126 i::Handle<i::String> message_string = | 1138 i::Handle<i::String> message_string = |
1127 i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); | 1139 i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); |
1128 | 1140 |
1129 if (!data.has_error()) { | 1141 if (!data.has_error()) { |
1130 i::OS::Print( | 1142 i::OS::Print( |
1131 "Parser failed on:\n" | 1143 "Parser failed on:\n" |
1132 "\t%s\n" | 1144 "\t%s\n" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 "\n", | 1248 "\n", |
1237 ";\n", | 1249 ";\n", |
1238 "\n;", | 1250 "\n;", |
1239 NULL | 1251 NULL |
1240 }; | 1252 }; |
1241 | 1253 |
1242 // TODO(mstarzinger): Disabled in GC stress mode for now, we should find the | 1254 // TODO(mstarzinger): Disabled in GC stress mode for now, we should find the |
1243 // correct timeout for this and re-enable this test again. | 1255 // correct timeout for this and re-enable this test again. |
1244 if (i::FLAG_stress_compaction) return; | 1256 if (i::FLAG_stress_compaction) return; |
1245 | 1257 |
| 1258 i::Isolate* isolate = i::Isolate::Current(); |
| 1259 i::Factory* factory = isolate->factory(); |
| 1260 |
1246 v8::HandleScope handles(v8::Isolate::GetCurrent()); | 1261 v8::HandleScope handles(v8::Isolate::GetCurrent()); |
1247 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent()); | 1262 v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent()); |
1248 v8::Context::Scope context_scope(context); | 1263 v8::Context::Scope context_scope(context); |
1249 | 1264 |
1250 int marker; | 1265 int marker; |
1251 i::Isolate::Current()->stack_guard()->SetStackLimit( | 1266 isolate->stack_guard()->SetStackLimit( |
1252 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 1267 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
1253 | 1268 |
1254 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1269 for (int i = 0; context_data[i][0] != NULL; ++i) { |
1255 for (int j = 0; statement_data[j] != NULL; ++j) { | 1270 for (int j = 0; statement_data[j] != NULL; ++j) { |
1256 for (int k = 0; termination_data[k] != NULL; ++k) { | 1271 for (int k = 0; termination_data[k] != NULL; ++k) { |
1257 int kPrefixLen = i::StrLength(context_data[i][0]); | 1272 int kPrefixLen = i::StrLength(context_data[i][0]); |
1258 int kStatementLen = i::StrLength(statement_data[j]); | 1273 int kStatementLen = i::StrLength(statement_data[j]); |
1259 int kTerminationLen = i::StrLength(termination_data[k]); | 1274 int kTerminationLen = i::StrLength(termination_data[k]); |
1260 int kSuffixLen = i::StrLength(context_data[i][1]); | 1275 int kSuffixLen = i::StrLength(context_data[i][1]); |
1261 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen | 1276 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen |
1262 + kSuffixLen + i::StrLength("label: for (;;) { }"); | 1277 + kSuffixLen + i::StrLength("label: for (;;) { }"); |
1263 | 1278 |
1264 // Plug the source code pieces together. | 1279 // Plug the source code pieces together. |
1265 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1); | 1280 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1); |
1266 int length = i::OS::SNPrintF(program, | 1281 int length = i::OS::SNPrintF(program, |
1267 "label: for (;;) { %s%s%s%s }", | 1282 "label: for (;;) { %s%s%s%s }", |
1268 context_data[i][0], | 1283 context_data[i][0], |
1269 statement_data[j], | 1284 statement_data[j], |
1270 termination_data[k], | 1285 termination_data[k], |
1271 context_data[i][1]); | 1286 context_data[i][1]); |
1272 CHECK(length == kProgramSize); | 1287 CHECK(length == kProgramSize); |
1273 i::Handle<i::String> source = | 1288 i::Handle<i::String> source = |
1274 FACTORY->NewStringFromAscii(i::CStrVector(program.start())); | 1289 factory->NewStringFromAscii(i::CStrVector(program.start())); |
1275 TestParserSync(source); | 1290 TestParserSync(source); |
1276 } | 1291 } |
1277 } | 1292 } |
1278 } | 1293 } |
1279 } | 1294 } |
1280 | 1295 |
1281 | 1296 |
1282 TEST(PreparserStrictOctal) { | 1297 TEST(PreparserStrictOctal) { |
1283 // Test that syntax error caused by octal literal is reported correctly as | 1298 // Test that syntax error caused by octal literal is reported correctly as |
1284 // such (issue 2220). | 1299 // such (issue 2220). |
1285 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. | 1300 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. |
1286 v8::V8::Initialize(); | 1301 v8::V8::Initialize(); |
1287 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1302 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
1288 v8::Context::Scope context_scope( | 1303 v8::Context::Scope context_scope( |
1289 v8::Context::New(v8::Isolate::GetCurrent())); | 1304 v8::Context::New(v8::Isolate::GetCurrent())); |
1290 v8::TryCatch try_catch; | 1305 v8::TryCatch try_catch; |
1291 const char* script = | 1306 const char* script = |
1292 "\"use strict\"; \n" | 1307 "\"use strict\"; \n" |
1293 "a = function() { \n" | 1308 "a = function() { \n" |
1294 " b = function() { \n" | 1309 " b = function() { \n" |
1295 " 01; \n" | 1310 " 01; \n" |
1296 " }; \n" | 1311 " }; \n" |
1297 "}; \n"; | 1312 "}; \n"; |
1298 v8::Script::Compile(v8::String::New(script)); | 1313 v8::Script::Compile(v8::String::New(script)); |
1299 CHECK(try_catch.HasCaught()); | 1314 CHECK(try_catch.HasCaught()); |
1300 v8::String::Utf8Value exception(try_catch.Exception()); | 1315 v8::String::Utf8Value exception(try_catch.Exception()); |
1301 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1316 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
1302 *exception); | 1317 *exception); |
1303 } | 1318 } |
OLD | NEW |