OLD | NEW |
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 i::Factory::NewStringFromUtf8(i::CStrVector(js_args[j])); | 245 i::Factory::NewStringFromUtf8(i::CStrVector(js_args[j])); |
246 arguments_array->set(j, *arg); | 246 arguments_array->set(j, *arg); |
247 } | 247 } |
248 i::Handle<i::JSArray> arguments_jsarray = | 248 i::Handle<i::JSArray> arguments_jsarray = |
249 i::Factory::NewJSArrayWithElements(arguments_array); | 249 i::Factory::NewJSArrayWithElements(arguments_array); |
250 global_template->Set(String::New("arguments"), | 250 global_template->Set(String::New("arguments"), |
251 Utils::ToLocal(arguments_jsarray)); | 251 Utils::ToLocal(arguments_jsarray)); |
252 | 252 |
253 // Install the debugger object in the utility scope | 253 // Install the debugger object in the utility scope |
254 i::Debug::Load(); | 254 i::Debug::Load(); |
255 i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); | |
256 i::JSObject* debug = i::Debug::debug_context()->global(); | 255 i::JSObject* debug = i::Debug::debug_context()->global(); |
257 utility_context_->Global()->Set(String::New("$debug"), | 256 utility_context_->Global()->Set(String::New("$debug"), |
258 Utils::ToLocal(&debug)); | 257 Utils::ToLocal(&debug)); |
259 | 258 |
260 // Run the d8 shell utility script in the utility context | 259 // Run the d8 shell utility script in the utility context |
261 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | 260 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); |
262 i::Vector<const char> shell_source | 261 i::Vector<const char> shell_source |
263 = i::NativesCollection<i::D8>::GetScriptSource(source_index); | 262 = i::NativesCollection<i::D8>::GetScriptSource(source_index); |
264 i::Vector<const char> shell_source_name | 263 i::Vector<const char> shell_source_name |
265 = i::NativesCollection<i::D8>::GetScriptName(source_index); | 264 = i::NativesCollection<i::D8>::GetScriptName(source_index); |
266 Handle<String> source = String::New(shell_source.start(), | 265 Handle<String> source = String::New(shell_source.start(), |
267 shell_source.length()); | 266 shell_source.length()); |
268 Handle<String> name = String::New(shell_source_name.start(), | 267 Handle<String> name = String::New(shell_source_name.start(), |
269 shell_source_name.length()); | 268 shell_source_name.length()); |
270 Script::Compile(source, name)->Run(); | 269 Script::Compile(source, name)->Run(); |
271 | 270 |
272 // Create the evaluation context | 271 // Create the evaluation context |
273 evaluation_context_ = Context::New(NULL, global_template); | 272 evaluation_context_ = Context::New(NULL, global_template); |
274 evaluation_context_->SetSecurityToken(Undefined()); | 273 evaluation_context_->SetSecurityToken(Undefined()); |
| 274 |
| 275 // Set the security context of the debug context to allow access. |
| 276 i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); |
275 } | 277 } |
276 | 278 |
277 | 279 |
278 void Shell::OnExit() { | 280 void Shell::OnExit() { |
279 if (i::FLAG_dump_counters) { | 281 if (i::FLAG_dump_counters) { |
280 ::printf("+----------------------------------------+----------+\n"); | 282 ::printf("+----------------------------------------+----------+\n"); |
281 ::printf("| Name | Value |\n"); | 283 ::printf("| Name | Value |\n"); |
282 ::printf("+----------------------------------------+----------+\n"); | 284 ::printf("+----------------------------------------+----------+\n"); |
283 for (CounterMap::iterator i = counter_map_.begin(); | 285 for (CounterMap::iterator i = counter_map_.begin(); |
284 i != counter_map_.end(); | 286 i != counter_map_.end(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 int Shell::Main(int argc, char* argv[]) { | 336 int Shell::Main(int argc, char* argv[]) { |
335 i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | 337 i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
336 if (i::FLAG_help) { | 338 if (i::FLAG_help) { |
337 return 1; | 339 return 1; |
338 } | 340 } |
339 Initialize(); | 341 Initialize(); |
340 bool run_shell = (argc == 1); | 342 bool run_shell = (argc == 1); |
341 Context::Scope context_scope(evaluation_context_); | 343 Context::Scope context_scope(evaluation_context_); |
342 for (int i = 1; i < argc; i++) { | 344 for (int i = 1; i < argc; i++) { |
343 char* str = argv[i]; | 345 char* str = argv[i]; |
344 HandleScope handle_scope; | 346 if (strcmp(str, "-f") == 0) { |
345 Handle<String> file_name = v8::String::New(str); | 347 // Ignore any -f flags for compatibility with other stand-alone |
346 Handle<String> source = ReadFile(str); | 348 // JavaScript engines. |
347 if (source.IsEmpty()) { | 349 continue; |
348 printf("Error reading '%s'\n", str); | 350 } else if (strncmp(str, "--", 2) == 0) { |
349 return 1; | 351 printf("Warning: unknown flag %s.\nTry --help for options\n", str); |
| 352 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { |
| 353 // Execute argument given to -e option directly. |
| 354 v8::HandleScope handle_scope; |
| 355 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); |
| 356 v8::Handle<v8::String> source = v8::String::New(argv[i + 1]); |
| 357 if (!ExecuteString(source, file_name, false, true)) |
| 358 return 1; |
| 359 i++; |
| 360 } else { |
| 361 // Use all other arguments as names of files to load and run. |
| 362 HandleScope handle_scope; |
| 363 Handle<String> file_name = v8::String::New(str); |
| 364 Handle<String> source = ReadFile(str); |
| 365 if (source.IsEmpty()) { |
| 366 printf("Error reading '%s'\n", str); |
| 367 return 1; |
| 368 } |
| 369 if (!ExecuteString(source, file_name, false, true)) |
| 370 return 1; |
350 } | 371 } |
351 if (!ExecuteString(source, file_name, false, true)) | |
352 return 1; | |
353 } | 372 } |
354 if (run_shell) | 373 if (run_shell) |
355 RunShell(); | 374 RunShell(); |
356 OnExit(); | 375 OnExit(); |
357 return 0; | 376 return 0; |
358 } | 377 } |
359 | 378 |
360 | 379 |
361 } // namespace v8 | 380 } // namespace v8 |
362 | 381 |
363 | 382 |
364 int main(int argc, char* argv[]) { | 383 int main(int argc, char* argv[]) { |
365 return v8::Shell::Main(argc, argv); | 384 return v8::Shell::Main(argc, argv); |
366 } | 385 } |
OLD | NEW |