From c30f1137121315b0d3641af6dc61e3b047f940e1 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 7 Dec 2010 13:56:11 -0800 Subject: Upgrade V8 to 3.0.0 --- deps/v8/samples/shell.cc | 54 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'deps/v8/samples') diff --git a/deps/v8/samples/shell.cc b/deps/v8/samples/shell.cc index 1a13f5f80b..460457552c 100644 --- a/deps/v8/samples/shell.cc +++ b/deps/v8/samples/shell.cc @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include #include #include #include @@ -44,10 +45,10 @@ v8::Handle Quit(const v8::Arguments& args); v8::Handle Version(const v8::Arguments& args); v8::Handle ReadFile(const char* name); void ReportException(v8::TryCatch* handler); +void SetFlagsFromString(const char* flags); int RunMain(int argc, char* argv[]) { - v8::V8::SetFlagsFromCommandLine(&argc, argv, true); v8::HandleScope handle_scope; // Create a template for the global object. v8::Handle global = v8::ObjectTemplate::New(); @@ -63,11 +64,11 @@ int RunMain(int argc, char* argv[]) { global->Set(v8::String::New("version"), v8::FunctionTemplate::New(Version)); // Create a new execution environment containing the built-in // functions - v8::Handle context = v8::Context::New(NULL, global); - // Enter the newly created execution environment. - v8::Context::Scope context_scope(context); + v8::Persistent context = v8::Context::New(NULL, global); bool run_shell = (argc == 1); for (int i = 1; i < argc; i++) { + // Enter the execution environment before evaluating any code. + v8::Context::Scope context_scope(context); const char* str = argv[i]; if (strcmp(str, "--shell") == 0) { run_shell = true; @@ -99,12 +100,48 @@ int RunMain(int argc, char* argv[]) { } } if (run_shell) RunShell(context); + context.Dispose(); return 0; } int main(int argc, char* argv[]) { - int result = RunMain(argc, argv); + // Figure out if we're requested to stress the optimization + // infrastructure by running tests multiple times and forcing + // optimization in the last run. + bool FLAG_stress_opt = false; + bool FLAG_stress_deopt = false; + for (int i = 0; i < argc; i++) { + if (strcmp(argv[i], "--stress-opt") == 0) { + FLAG_stress_opt = true; + argv[i] = NULL; + } else if (strcmp(argv[i], "--stress-deopt") == 0) { + FLAG_stress_deopt = true; + argv[i] = NULL; + } else if (strcmp(argv[i], "--noalways-opt") == 0) { + // No support for stressing if we can't use --always-opt. + FLAG_stress_opt = false; + FLAG_stress_deopt = false; + break; + } + } + + v8::V8::SetFlagsFromCommandLine(&argc, argv, true); + int result = 0; + if (FLAG_stress_opt || FLAG_stress_deopt) { + v8::Testing::SetStressRunType(FLAG_stress_opt + ? v8::Testing::kStressTypeOpt + : v8::Testing::kStressTypeDeopt); + int stress_runs = v8::Testing::GetStressRuns(); + for (int i = 0; i < stress_runs && result == 0; i++) { + printf("============ Stress %d/%d ============\n", + i + 1, stress_runs); + v8::Testing::PrepareStressRun(i); + result = RunMain(argc, argv); + } + } else { + result = RunMain(argc, argv); + } v8::V8::Dispose(); return result; } @@ -221,6 +258,8 @@ v8::Handle ReadFile(const char* name) { void RunShell(v8::Handle context) { printf("V8 version %s\n", v8::V8::GetVersion()); static const int kBufferSize = 256; + // Enter the execution environment before evaluating any code. + v8::Context::Scope context_scope(context); while (true) { char buffer[kBufferSize]; printf("> "); @@ -306,3 +345,8 @@ void ReportException(v8::TryCatch* try_catch) { } } } + + +void SetFlagsFromString(const char* flags) { + v8::V8::SetFlagsFromString(flags, strlen(flags)); +} -- cgit v1.2.3