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

Side by Side Diff: samples/shell.cc

Issue 53089: Fixed test memory leaks (Closed)
Patch Set: Created 11 years, 9 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
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 27 matching lines...) Expand all
38 bool print_result, 38 bool print_result,
39 bool report_exceptions); 39 bool report_exceptions);
40 v8::Handle<v8::Value> Print(const v8::Arguments& args); 40 v8::Handle<v8::Value> Print(const v8::Arguments& args);
41 v8::Handle<v8::Value> Load(const v8::Arguments& args); 41 v8::Handle<v8::Value> Load(const v8::Arguments& args);
42 v8::Handle<v8::Value> Quit(const v8::Arguments& args); 42 v8::Handle<v8::Value> Quit(const v8::Arguments& args);
43 v8::Handle<v8::Value> Version(const v8::Arguments& args); 43 v8::Handle<v8::Value> Version(const v8::Arguments& args);
44 v8::Handle<v8::String> ReadFile(const char* name); 44 v8::Handle<v8::String> ReadFile(const char* name);
45 void ReportException(v8::TryCatch* handler); 45 void ReportException(v8::TryCatch* handler);
46 46
47 47
48 int main(int argc, char* argv[]) { 48 int RunMain(int argc, char* argv[]) {
49 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 49 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
50 v8::HandleScope handle_scope; 50 v8::HandleScope handle_scope;
51 // Create a template for the global object. 51 // Create a template for the global object.
52 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 52 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
53 // Bind the global 'print' function to the C++ Print callback. 53 // Bind the global 'print' function to the C++ Print callback.
54 global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print)); 54 global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
55 // Bind the global 'load' function to the C++ Load callback. 55 // Bind the global 'load' function to the C++ Load callback.
56 global->Set(v8::String::New("load"), v8::FunctionTemplate::New(Load)); 56 global->Set(v8::String::New("load"), v8::FunctionTemplate::New(Load));
57 // Bind the 'quit' function 57 // Bind the 'quit' function
58 global->Set(v8::String::New("quit"), v8::FunctionTemplate::New(Quit)); 58 global->Set(v8::String::New("quit"), v8::FunctionTemplate::New(Quit));
(...skipping 29 matching lines...) Expand all
88 v8::Handle<v8::String> file_name = v8::String::New(str); 88 v8::Handle<v8::String> file_name = v8::String::New(str);
89 v8::Handle<v8::String> source = ReadFile(str); 89 v8::Handle<v8::String> source = ReadFile(str);
90 if (source.IsEmpty()) { 90 if (source.IsEmpty()) {
91 printf("Error reading '%s'\n", str); 91 printf("Error reading '%s'\n", str);
92 return 1; 92 return 1;
93 } 93 }
94 if (!ExecuteString(source, file_name, false, true)) 94 if (!ExecuteString(source, file_name, false, true))
95 return 1; 95 return 1;
96 } 96 }
97 } 97 }
98 if (run_shell) RunShell(context);
99 return 0; 98 return 0;
100 } 99 }
101 100
102 101
102 int main(int argc, char* argv[]) {
103 int result = RunMain(argc, argv);
104 v8::V8::Dispose();
105 return result;
106 }
107
108
103 // Extracts a C string from a V8 Utf8Value. 109 // Extracts a C string from a V8 Utf8Value.
104 const char* ToCString(const v8::String::Utf8Value& value) { 110 const char* ToCString(const v8::String::Utf8Value& value) {
105 return *value ? *value : "<string conversion failed>"; 111 return *value ? *value : "<string conversion failed>";
106 } 112 }
107 113
108 114
109 // The callback that is invoked by v8 whenever the JavaScript 'print' 115 // The callback that is invoked by v8 whenever the JavaScript 'print'
110 // function is called. Prints its arguments on stdout separated by 116 // function is called. Prints its arguments on stdout separated by
111 // spaces and ending with a newline. 117 // spaces and ending with a newline.
112 v8::Handle<v8::Value> Print(const v8::Arguments& args) { 118 v8::Handle<v8::Value> Print(const v8::Arguments& args) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 for (int i = 0; i < start; i++) { 270 for (int i = 0; i < start; i++) {
265 printf(" "); 271 printf(" ");
266 } 272 }
267 int end = message->GetEndColumn(); 273 int end = message->GetEndColumn();
268 for (int i = start; i < end; i++) { 274 for (int i = start; i < end; i++) {
269 printf("^"); 275 printf("^");
270 } 276 }
271 printf("\n"); 277 printf("\n");
272 } 278 }
273 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698