Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 18694004: Plug some memory leaks in parser tests. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: use ScopedVector Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 for (int j = 0; statement_data[j] != NULL; ++j) { 1278 for (int j = 0; statement_data[j] != NULL; ++j) {
1273 for (int k = 0; termination_data[k] != NULL; ++k) { 1279 for (int k = 0; termination_data[k] != NULL; ++k) {
1274 int kPrefixLen = i::StrLength(context_data[i][0]); 1280 int kPrefixLen = i::StrLength(context_data[i][0]);
1275 int kStatementLen = i::StrLength(statement_data[j]); 1281 int kStatementLen = i::StrLength(statement_data[j]);
1276 int kTerminationLen = i::StrLength(termination_data[k]); 1282 int kTerminationLen = i::StrLength(termination_data[k]);
1277 int kSuffixLen = i::StrLength(context_data[i][1]); 1283 int kSuffixLen = i::StrLength(context_data[i][1]);
1278 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1284 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
1279 + kSuffixLen + i::StrLength("label: for (;;) { }"); 1285 + kSuffixLen + i::StrLength("label: for (;;) { }");
1280 1286
1281 // Plug the source code pieces together. 1287 // Plug the source code pieces together.
1282 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1); 1288 i::ScopedVector<char> program(kProgramSize + 1);
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);
(...skipping 18 matching lines...) Expand all
1311 " b = function() { \n" 1317 " b = function() { \n"
1312 " 01; \n" 1318 " 01; \n"
1313 " }; \n" 1319 " }; \n"
1314 "}; \n"; 1320 "}; \n";
1315 v8::Script::Compile(v8::String::New(script)); 1321 v8::Script::Compile(v8::String::New(script));
1316 CHECK(try_catch.HasCaught()); 1322 CHECK(try_catch.HasCaught());
1317 v8::String::Utf8Value exception(try_catch.Exception()); 1323 v8::String::Utf8Value exception(try_catch.Exception());
1318 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1324 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1319 *exception); 1325 *exception);
1320 } 1326 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698