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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 args, kExternalDoubleArray, sizeof(double)); // NOLINT | 879 args, kExternalDoubleArray, sizeof(double)); // NOLINT |
880 } | 880 } |
881 | 881 |
882 | 882 |
883 Handle<Value> Shell::Uint8ClampedArray(const Arguments& args) { | 883 Handle<Value> Shell::Uint8ClampedArray(const Arguments& args) { |
884 return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t)); | 884 return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t)); |
885 } | 885 } |
886 | 886 |
887 | 887 |
888 Handle<Value> Shell::Yield(const Arguments& args) { | 888 Handle<Value> Shell::Yield(const Arguments& args) { |
889 v8::Unlocker unlocker; | 889 v8::Unlocker unlocker(args.GetIsolate()); |
890 return Undefined(); | 890 return Undefined(); |
891 } | 891 } |
892 | 892 |
893 | 893 |
894 Handle<Value> Shell::Quit(const Arguments& args) { | 894 Handle<Value> Shell::Quit(const Arguments& args) { |
895 int exit_code = args[0]->Int32Value(); | 895 int exit_code = args[0]->Int32Value(); |
896 OnExit(); | 896 OnExit(); |
897 exit(exit_code); | 897 exit(exit_code); |
898 return Undefined(); | 898 return Undefined(); |
899 } | 899 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 return GetCounter(name, true); | 1086 return GetCounter(name, true); |
1087 } | 1087 } |
1088 | 1088 |
1089 | 1089 |
1090 void Shell::AddHistogramSample(void* histogram, int sample) { | 1090 void Shell::AddHistogramSample(void* histogram, int sample) { |
1091 Counter* counter = reinterpret_cast<Counter*>(histogram); | 1091 Counter* counter = reinterpret_cast<Counter*>(histogram); |
1092 counter->AddSample(sample); | 1092 counter->AddSample(sample); |
1093 } | 1093 } |
1094 | 1094 |
1095 | 1095 |
1096 void Shell::InstallUtilityScript() { | 1096 void Shell::InstallUtilityScript(Isolate* isolate) { |
1097 Locker lock; | 1097 Locker lock(isolate); |
1098 HandleScope scope; | 1098 HandleScope scope; |
1099 // If we use the utility context, we have to set the security tokens so that | 1099 // If we use the utility context, we have to set the security tokens so that |
1100 // utility, evaluation and debug context can all access each other. | 1100 // utility, evaluation and debug context can all access each other. |
1101 utility_context_->SetSecurityToken(Undefined()); | 1101 utility_context_->SetSecurityToken(Undefined()); |
1102 evaluation_context_->SetSecurityToken(Undefined()); | 1102 evaluation_context_->SetSecurityToken(Undefined()); |
1103 Context::Scope utility_scope(utility_context_); | 1103 Context::Scope utility_scope(utility_context_); |
1104 | 1104 |
1105 #ifdef ENABLE_DEBUGGER_SUPPORT | 1105 #ifdef ENABLE_DEBUGGER_SUPPORT |
1106 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); | 1106 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); |
1107 // Install the debugger object in the utility scope | 1107 // Install the debugger object in the utility scope |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 V8::SetCreateHistogramFunction(CreateHistogram); | 1271 V8::SetCreateHistogramFunction(CreateHistogram); |
1272 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 1272 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
1273 } | 1273 } |
1274 #endif // V8_SHARED | 1274 #endif // V8_SHARED |
1275 } | 1275 } |
1276 | 1276 |
1277 | 1277 |
1278 void Shell::InitializeDebugger(Isolate* isolate) { | 1278 void Shell::InitializeDebugger(Isolate* isolate) { |
1279 if (options.test_shell) return; | 1279 if (options.test_shell) return; |
1280 #ifndef V8_SHARED | 1280 #ifndef V8_SHARED |
1281 Locker lock; | 1281 Locker lock(isolate); |
1282 HandleScope scope; | 1282 HandleScope scope; |
1283 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 1283 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
1284 utility_context_ = Context::New(NULL, global_template); | 1284 utility_context_ = Context::New(NULL, global_template); |
1285 | 1285 |
1286 #ifdef ENABLE_DEBUGGER_SUPPORT | 1286 #ifdef ENABLE_DEBUGGER_SUPPORT |
1287 // Start the debugger agent if requested. | 1287 // Start the debugger agent if requested. |
1288 if (i::FLAG_debugger_agent) { | 1288 if (i::FLAG_debugger_agent) { |
1289 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 1289 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
1290 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); | 1290 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); |
1291 } | 1291 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 int size = 0; | 1489 int size = 0; |
1490 char* chars = ReadChars(isolate, name, &size); | 1490 char* chars = ReadChars(isolate, name, &size); |
1491 if (chars == NULL) return Handle<String>(); | 1491 if (chars == NULL) return Handle<String>(); |
1492 Handle<String> result = String::New(chars, size); | 1492 Handle<String> result = String::New(chars, size); |
1493 delete[] chars; | 1493 delete[] chars; |
1494 return result; | 1494 return result; |
1495 } | 1495 } |
1496 | 1496 |
1497 | 1497 |
1498 void Shell::RunShell(Isolate* isolate) { | 1498 void Shell::RunShell(Isolate* isolate) { |
1499 Locker locker; | 1499 Locker locker(isolate); |
1500 Context::Scope context_scope(evaluation_context_); | 1500 Context::Scope context_scope(evaluation_context_); |
1501 HandleScope outer_scope; | 1501 HandleScope outer_scope; |
1502 Handle<String> name = String::New("(d8)"); | 1502 Handle<String> name = String::New("(d8)"); |
1503 DumbLineEditor dumb_line_editor(isolate); | 1503 DumbLineEditor dumb_line_editor(isolate); |
1504 LineEditor* console = LineEditor::Get(); | 1504 LineEditor* console = LineEditor::Get(); |
1505 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); | 1505 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); |
1506 console->Open(); | 1506 console->Open(); |
1507 while (true) { | 1507 while (true) { |
1508 HandleScope inner_scope; | 1508 HandleScope inner_scope; |
1509 Handle<String> input = console->Prompt(Shell::kPrompt); | 1509 Handle<String> input = console->Prompt(Shell::kPrompt); |
(...skipping 29 matching lines...) Expand all Loading... |
1539 // For each newline-separated line. | 1539 // For each newline-separated line. |
1540 char* next_line = ReadLine(ptr); | 1540 char* next_line = ReadLine(ptr); |
1541 | 1541 |
1542 if (*ptr == '#') { | 1542 if (*ptr == '#') { |
1543 // Skip comment lines. | 1543 // Skip comment lines. |
1544 ptr = next_line; | 1544 ptr = next_line; |
1545 continue; | 1545 continue; |
1546 } | 1546 } |
1547 | 1547 |
1548 // Prepare the context for this thread. | 1548 // Prepare the context for this thread. |
1549 Locker locker; | 1549 Locker locker(isolate_); |
1550 HandleScope outer_scope; | 1550 HandleScope outer_scope; |
1551 Persistent<Context> thread_context = | 1551 Persistent<Context> thread_context = |
1552 Shell::CreateEvaluationContext(isolate_); | 1552 Shell::CreateEvaluationContext(isolate_); |
1553 Context::Scope context_scope(thread_context); | 1553 Context::Scope context_scope(thread_context); |
1554 | 1554 |
1555 while ((ptr != NULL) && (*ptr != '\0')) { | 1555 while ((ptr != NULL) && (*ptr != '\0')) { |
1556 HandleScope inner_scope; | 1556 HandleScope inner_scope; |
1557 char* filename = ptr; | 1557 char* filename = ptr; |
1558 ptr = ReadWord(ptr); | 1558 ptr = ReadWord(ptr); |
1559 | 1559 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 ShellThread* thread = new ShellThread(isolate, files); | 1838 ShellThread* thread = new ShellThread(isolate, files); |
1839 thread->Start(); | 1839 thread->Start(); |
1840 threads.Add(thread); | 1840 threads.Add(thread); |
1841 } | 1841 } |
1842 } | 1842 } |
1843 for (int i = 1; i < options.num_isolates; ++i) { | 1843 for (int i = 1; i < options.num_isolates; ++i) { |
1844 options.isolate_sources[i].StartExecuteInThread(); | 1844 options.isolate_sources[i].StartExecuteInThread(); |
1845 } | 1845 } |
1846 #endif // V8_SHARED | 1846 #endif // V8_SHARED |
1847 { // NOLINT | 1847 { // NOLINT |
1848 Locker lock; | 1848 Locker lock(isolate); |
1849 HandleScope scope; | 1849 HandleScope scope; |
1850 Persistent<Context> context = CreateEvaluationContext(isolate); | 1850 Persistent<Context> context = CreateEvaluationContext(isolate); |
1851 if (options.last_run) { | 1851 if (options.last_run) { |
1852 // Keep using the same context in the interactive shell. | 1852 // Keep using the same context in the interactive shell. |
1853 evaluation_context_ = context; | 1853 evaluation_context_ = context; |
1854 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1854 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
1855 // If the interactive debugger is enabled make sure to activate | 1855 // If the interactive debugger is enabled make sure to activate |
1856 // it before running the files passed on the command line. | 1856 // it before running the files passed on the command line. |
1857 if (i::FLAG_debugger) { | 1857 if (i::FLAG_debugger) { |
1858 InstallUtilityScript(); | 1858 InstallUtilityScript(isolate); |
1859 } | 1859 } |
1860 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1860 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
1861 } | 1861 } |
1862 { | 1862 { |
1863 Context::Scope cscope(context); | 1863 Context::Scope cscope(context); |
1864 options.isolate_sources[0].Execute(isolate); | 1864 options.isolate_sources[0].Execute(isolate); |
1865 } | 1865 } |
1866 if (!options.last_run) { | 1866 if (!options.last_run) { |
1867 context.Dispose(); | 1867 context.Dispose(); |
1868 if (options.send_idle_notification) { | 1868 if (options.send_idle_notification) { |
(...skipping 17 matching lines...) Expand all Loading... |
1886 options.isolate_sources[i].WaitForThread(); | 1886 options.isolate_sources[i].WaitForThread(); |
1887 } | 1887 } |
1888 | 1888 |
1889 for (int i = 0; i < threads.length(); i++) { | 1889 for (int i = 0; i < threads.length(); i++) { |
1890 i::Thread* thread = threads[i]; | 1890 i::Thread* thread = threads[i]; |
1891 thread->Join(); | 1891 thread->Join(); |
1892 delete thread; | 1892 delete thread; |
1893 } | 1893 } |
1894 | 1894 |
1895 if (threads.length() > 0 && options.use_preemption) { | 1895 if (threads.length() > 0 && options.use_preemption) { |
1896 Locker lock; | 1896 Locker lock(isolate); |
1897 Locker::StopPreemption(); | 1897 Locker::StopPreemption(); |
1898 } | 1898 } |
1899 #endif // V8_SHARED | 1899 #endif // V8_SHARED |
1900 return 0; | 1900 return 0; |
1901 } | 1901 } |
1902 | 1902 |
1903 | 1903 |
1904 int Shell::Main(int argc, char* argv[]) { | 1904 int Shell::Main(int argc, char* argv[]) { |
1905 if (!SetOptions(argc, argv)) return 1; | 1905 if (!SetOptions(argc, argv)) return 1; |
1906 int result = 0; | 1906 int result = 0; |
(...skipping 26 matching lines...) Expand all Loading... |
1933 } | 1933 } |
1934 #endif | 1934 #endif |
1935 } else { | 1935 } else { |
1936 result = RunMain(isolate, argc, argv); | 1936 result = RunMain(isolate, argc, argv); |
1937 } | 1937 } |
1938 | 1938 |
1939 | 1939 |
1940 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1940 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
1941 // Run remote debugger if requested, but never on --test | 1941 // Run remote debugger if requested, but never on --test |
1942 if (i::FLAG_remote_debugger && !options.test_shell) { | 1942 if (i::FLAG_remote_debugger && !options.test_shell) { |
1943 InstallUtilityScript(); | 1943 InstallUtilityScript(isolate); |
1944 RunRemoteDebugger(i::FLAG_debugger_port); | 1944 RunRemoteDebugger(i::FLAG_debugger_port); |
1945 return 0; | 1945 return 0; |
1946 } | 1946 } |
1947 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1947 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
1948 | 1948 |
1949 // Run interactive shell if explicitly requested or if no script has been | 1949 // Run interactive shell if explicitly requested or if no script has been |
1950 // executed, but never on --test | 1950 // executed, but never on --test |
1951 | 1951 |
1952 if (( options.interactive_shell || !options.script_executed ) | 1952 if (( options.interactive_shell || !options.script_executed ) |
1953 && !options.test_shell ) { | 1953 && !options.test_shell ) { |
1954 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1954 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
1955 if (!i::FLAG_debugger) { | 1955 if (!i::FLAG_debugger) { |
1956 InstallUtilityScript(); | 1956 InstallUtilityScript(isolate); |
1957 } | 1957 } |
1958 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1958 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
1959 RunShell(isolate); | 1959 RunShell(isolate); |
1960 } | 1960 } |
1961 } | 1961 } |
1962 V8::Dispose(); | 1962 V8::Dispose(); |
1963 | 1963 |
1964 OnExit(); | 1964 OnExit(); |
1965 | 1965 |
1966 return result; | 1966 return result; |
1967 } | 1967 } |
1968 | 1968 |
1969 } // namespace v8 | 1969 } // namespace v8 |
1970 | 1970 |
1971 | 1971 |
1972 #ifndef GOOGLE3 | 1972 #ifndef GOOGLE3 |
1973 int main(int argc, char* argv[]) { | 1973 int main(int argc, char* argv[]) { |
1974 return v8::Shell::Main(argc, argv); | 1974 return v8::Shell::Main(argc, argv); |
1975 } | 1975 } |
1976 #endif | 1976 #endif |
OLD | NEW |