diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-12-07 13:56:11 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-12-07 13:56:11 -0800 |
commit | c30f1137121315b0d3641af6dc61e3b047f940e1 (patch) | |
tree | f118eaf670505e6a63f28bc8df845520f67adc55 /deps/v8/samples | |
parent | 5b8c62f7d12c1c5a553e765ba05bbd8a7e17ee47 (diff) | |
download | android-node-v8-c30f1137121315b0d3641af6dc61e3b047f940e1.tar.gz android-node-v8-c30f1137121315b0d3641af6dc61e3b047f940e1.tar.bz2 android-node-v8-c30f1137121315b0d3641af6dc61e3b047f940e1.zip |
Upgrade V8 to 3.0.0
Diffstat (limited to 'deps/v8/samples')
-rw-r--r-- | deps/v8/samples/shell.cc | 54 |
1 files changed, 49 insertions, 5 deletions
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 <v8.h> +#include <v8-testing.h> #include <fcntl.h> #include <string.h> #include <stdio.h> @@ -44,10 +45,10 @@ v8::Handle<v8::Value> Quit(const v8::Arguments& args); v8::Handle<v8::Value> Version(const v8::Arguments& args); v8::Handle<v8::String> 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<v8::ObjectTemplate> 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<v8::Context> context = v8::Context::New(NULL, global); - // Enter the newly created execution environment. - v8::Context::Scope context_scope(context); + v8::Persistent<v8::Context> 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<v8::String> ReadFile(const char* name) { void RunShell(v8::Handle<v8::Context> 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)); +} |