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 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 // 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 |
1042 // character belonging to that token. | 1042 // character belonging to that token. |
1043 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1043 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
1044 } | 1044 } |
1045 } | 1045 } |
1046 | 1046 |
1047 | 1047 |
1048 i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) { | 1048 i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) { |
1049 i::Isolate* isolate = i::Isolate::Current(); | 1049 i::Isolate* isolate = i::Isolate::Current(); |
1050 i::Factory* factory = isolate->factory(); | 1050 i::Factory* factory = isolate->factory(); |
1051 const char* message = data->BuildMessage(); | |
1051 i::Handle<i::String> format = v8::Utils::OpenHandle( | 1052 i::Handle<i::String> format = v8::Utils::OpenHandle( |
1052 *v8::String::New(data->BuildMessage())); | 1053 *v8::String::New(message)); |
1053 i::Vector<const char*> args = data->BuildArgs(); | 1054 i::Vector<const char*> args = data->BuildArgs(); |
1054 i::Handle<i::JSArray> args_array = factory->NewJSArray(args.length()); | 1055 i::Handle<i::JSArray> args_array = factory->NewJSArray(args.length()); |
1055 for (int i = 0; i < args.length(); i++) { | 1056 for (int i = 0; i < args.length(); i++) { |
1056 i::JSArray::SetElement(args_array, | 1057 i::JSArray::SetElement(args_array, |
1057 i, | 1058 i, |
1058 v8::Utils::OpenHandle(*v8::String::New(args[i])), | 1059 v8::Utils::OpenHandle(*v8::String::New(args[i])), |
1059 NONE, | 1060 NONE, |
1060 i::kNonStrictMode); | 1061 i::kNonStrictMode); |
1061 } | 1062 } |
1062 i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); | 1063 i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); |
1063 i::Handle<i::Object> format_fun = | 1064 i::Handle<i::Object> format_fun = |
1064 i::GetProperty(builtins, "FormatMessage"); | 1065 i::GetProperty(builtins, "FormatMessage"); |
1065 i::Handle<i::Object> arg_handles[] = { format, args_array }; | 1066 i::Handle<i::Object> arg_handles[] = { format, args_array }; |
1066 bool has_exception = false; | 1067 bool has_exception = false; |
1067 i::Handle<i::Object> result = | 1068 i::Handle<i::Object> result = |
1068 i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); | 1069 i::Execution::Call(format_fun, builtins, 2, arg_handles, &has_exception); |
1069 CHECK(!has_exception); | 1070 CHECK(!has_exception); |
1070 CHECK(result->IsString()); | 1071 CHECK(result->IsString()); |
1072 for (int i = 0; i < args.length(); i++) { | |
1073 i::DeleteArray(args[i]); | |
1074 } | |
1075 i::DeleteArray(args.start()); | |
1076 i::DeleteArray(message); | |
Dmitry Lomov (no reviews)
2013/07/04 15:22:29
Not too happy about explicit deletions here - woul
| |
1071 return i::Handle<i::String>::cast(result); | 1077 return i::Handle<i::String>::cast(result); |
1072 } | 1078 } |
1073 | 1079 |
1074 | 1080 |
1075 enum ParserFlag { | 1081 enum ParserFlag { |
1076 kAllowLazy, | 1082 kAllowLazy, |
1077 kAllowNativesSyntax, | 1083 kAllowNativesSyntax, |
1078 kAllowHarmonyScoping, | 1084 kAllowHarmonyScoping, |
1079 kAllowModules, | 1085 kAllowModules, |
1080 kAllowGenerators, | 1086 kAllowGenerators, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 int length = i::OS::SNPrintF(program, | 1289 int length = i::OS::SNPrintF(program, |
1284 "label: for (;;) { %s%s%s%s }", | 1290 "label: for (;;) { %s%s%s%s }", |
1285 context_data[i][0], | 1291 context_data[i][0], |
1286 statement_data[j], | 1292 statement_data[j], |
1287 termination_data[k], | 1293 termination_data[k], |
1288 context_data[i][1]); | 1294 context_data[i][1]); |
1289 CHECK(length == kProgramSize); | 1295 CHECK(length == kProgramSize); |
1290 i::Handle<i::String> source = | 1296 i::Handle<i::String> source = |
1291 factory->NewStringFromAscii(i::CStrVector(program.start())); | 1297 factory->NewStringFromAscii(i::CStrVector(program.start())); |
1292 TestParserSync(source); | 1298 TestParserSync(source); |
1299 i::DeleteArray(program.start()); | |
Dmitry Lomov (no reviews)
2013/07/04 15:22:29
Replace Vector with ScopedVector here, then explic
earthdok
2013/07/04 15:31:14
done
| |
1293 } | 1300 } |
1294 } | 1301 } |
1295 } | 1302 } |
1296 } | 1303 } |
1297 | 1304 |
1298 | 1305 |
1299 TEST(PreparserStrictOctal) { | 1306 TEST(PreparserStrictOctal) { |
1300 // Test that syntax error caused by octal literal is reported correctly as | 1307 // Test that syntax error caused by octal literal is reported correctly as |
1301 // such (issue 2220). | 1308 // such (issue 2220). |
1302 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. | 1309 v8::internal::FLAG_min_preparse_length = 1; // Force preparsing. |
1303 v8::V8::Initialize(); | 1310 v8::V8::Initialize(); |
1304 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1311 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
1305 v8::Context::Scope context_scope( | 1312 v8::Context::Scope context_scope( |
1306 v8::Context::New(v8::Isolate::GetCurrent())); | 1313 v8::Context::New(v8::Isolate::GetCurrent())); |
1307 v8::TryCatch try_catch; | 1314 v8::TryCatch try_catch; |
1308 const char* script = | 1315 const char* script = |
1309 "\"use strict\"; \n" | 1316 "\"use strict\"; \n" |
1310 "a = function() { \n" | 1317 "a = function() { \n" |
1311 " b = function() { \n" | 1318 " b = function() { \n" |
1312 " 01; \n" | 1319 " 01; \n" |
1313 " }; \n" | 1320 " }; \n" |
1314 "}; \n"; | 1321 "}; \n"; |
1315 v8::Script::Compile(v8::String::New(script)); | 1322 v8::Script::Compile(v8::String::New(script)); |
1316 CHECK(try_catch.HasCaught()); | 1323 CHECK(try_catch.HasCaught()); |
1317 v8::String::Utf8Value exception(try_catch.Exception()); | 1324 v8::String::Utf8Value exception(try_catch.Exception()); |
1318 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", | 1325 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", |
1319 *exception); | 1326 *exception); |
1320 } | 1327 } |
OLD | NEW |