Reviewers: Christian Plesner Hansen, Description: Update d8 so that it can be used to run the mjsunit tests.
Set the security token on the debugger context after all contexts have been created in d8. This ensures that all d8 contexts (including the debugger context) can access eachother. Copy extra command-line handling from the shell sample to d8. Please review this at http://codereview.chromium.org/12431 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/d8.cc M test/mjsunit/debug-script.js Index: test/mjsunit/debug-script.js =================================================================== --- test/mjsunit/debug-script.js (revision 833) +++ test/mjsunit/debug-script.js (working copy) @@ -58,7 +58,9 @@ // If no snapshot is used, only the 'gc' extension is loaded. // If snapshot is used, all extensions are cached in the snapshot. assertTrue(extension_count == 1 || extension_count == 5); -assertEquals(2, normal_count); // This script and mjsunit.js. +// This script and mjsunit.js has been loaded. If using d8, d8 loads +// a normal script during startup too. +assertTrue(normal_count == 2 || normal_count == 3); // Test a builtins script. var math_script = Debug.findScript('native math.js'); Index: src/d8.cc =================================================================== --- src/d8.cc (revision 833) +++ src/d8.cc (working copy) @@ -252,7 +252,6 @@ // Install the debugger object in the utility scope i::Debug::Load(); - i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); i::JSObject* debug = i::Debug::debug_context()->global(); utility_context_->Global()->Set(String::New("$debug"), Utils::ToLocal(&debug)); @@ -272,6 +271,9 @@ // Create the evaluation context evaluation_context_ = Context::New(NULL, global_template); evaluation_context_->SetSecurityToken(Undefined()); + + // Set the security context of the debug context to allow access. + i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); } @@ -341,15 +343,32 @@ Context::Scope context_scope(evaluation_context_); for (int i = 1; i < argc; i++) { char* str = argv[i]; - HandleScope handle_scope; - Handle<String> file_name = v8::String::New(str); - Handle<String> source = ReadFile(str); - if (source.IsEmpty()) { - printf("Error reading '%s'\n", str); - return 1; + if (strcmp(str, "-f") == 0) { + // Ignore any -f flags for compatibility with other stand-alone + // JavaScript engines. + continue; + } else if (strncmp(str, "--", 2) == 0) { + printf("Warning: unknown flag %s.\nTry --help for options\n", str); + } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { + // Execute argument given to -e option directly. + v8::HandleScope handle_scope; + v8::Handle<v8::String> file_name = v8::String::New("unnamed"); + v8::Handle<v8::String> source = v8::String::New(argv[i + 1]); + if (!ExecuteString(source, file_name, false, true)) + return 1; + i++; + } else { + // Use all other arguments as names of files to load and run. + HandleScope handle_scope; + Handle<String> file_name = v8::String::New(str); + Handle<String> source = ReadFile(str); + if (source.IsEmpty()) { + printf("Error reading '%s'\n", str); + return 1; + } + if (!ExecuteString(source, file_name, false, true)) + return 1; } - if (!ExecuteString(source, file_name, false, true)) - return 1; } if (run_shell) RunShell(); --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
