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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } else { | 206 } else { |
207 Handle<Value> result = script->Run(); | 207 Handle<Value> result = script->Run(); |
208 if (result.IsEmpty()) { | 208 if (result.IsEmpty()) { |
209 ASSERT(try_catch.HasCaught()); | 209 ASSERT(try_catch.HasCaught()); |
210 // Print errors that happened during execution. | 210 // Print errors that happened during execution. |
211 if (report_exceptions && !FLAG_debugger) | 211 if (report_exceptions && !FLAG_debugger) |
212 ReportException(&try_catch); | 212 ReportException(&try_catch); |
213 return false; | 213 return false; |
214 } else { | 214 } else { |
215 ASSERT(!try_catch.HasCaught()); | 215 ASSERT(!try_catch.HasCaught()); |
216 if (print_result && !result->IsUndefined()) { | 216 if (print_result) { |
217 // If all went well and the result wasn't undefined then print | 217 if (options.test_shell) { |
218 // the returned value. | 218 if (!result->IsUndefined()) { |
219 v8::String::Utf8Value str(result); | 219 // If all went well and the result wasn't undefined then print |
220 size_t count = fwrite(*str, sizeof(**str), str.length(), stdout); | 220 // the returned value. |
221 (void) count; // Silence GCC-4.5.x "unused result" warning. | 221 v8::String::Utf8Value str(result); |
222 printf("\n"); | 222 fwrite(*str, sizeof(**str), str.length(), stdout); |
| 223 printf("\n"); |
| 224 } |
| 225 } else { |
| 226 Context::Scope context_scope(utility_context_); |
| 227 Handle<Object> global = utility_context_->Global(); |
| 228 Handle<Value> fun = global->Get(String::New("Stringify")); |
| 229 Handle<Value> argv[1] = { result }; |
| 230 Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv); |
| 231 v8::String::Utf8Value str(s); |
| 232 fwrite(*str, sizeof(**str), str.length(), stdout); |
| 233 printf("\n"); |
| 234 } |
223 } | 235 } |
224 return true; | 236 return true; |
225 } | 237 } |
226 } | 238 } |
227 } | 239 } |
228 | 240 |
229 | 241 |
230 Handle<Value> Shell::Print(const Arguments& args) { | 242 Handle<Value> Shell::Print(const Arguments& args) { |
231 Handle<Value> val = Write(args); | 243 Handle<Value> val = Write(args); |
232 printf("\n"); | 244 printf("\n"); |
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 } | 1974 } |
1963 | 1975 |
1964 } // namespace v8 | 1976 } // namespace v8 |
1965 | 1977 |
1966 | 1978 |
1967 #ifndef GOOGLE3 | 1979 #ifndef GOOGLE3 |
1968 int main(int argc, char* argv[]) { | 1980 int main(int argc, char* argv[]) { |
1969 return v8::Shell::Main(argc, argv); | 1981 return v8::Shell::Main(argc, argv); |
1970 } | 1982 } |
1971 #endif | 1983 #endif |
OLD | NEW |