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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 V8::SetCreateHistogramFunction(CreateHistogram); | 1265 V8::SetCreateHistogramFunction(CreateHistogram); |
1266 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 1266 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
1267 } | 1267 } |
1268 #endif // V8_SHARED | 1268 #endif // V8_SHARED |
1269 } | 1269 } |
1270 | 1270 |
1271 | 1271 |
1272 void Shell::InitializeDebugger(Isolate* isolate) { | 1272 void Shell::InitializeDebugger(Isolate* isolate) { |
1273 if (options.test_shell) return; | 1273 if (options.test_shell) return; |
1274 #ifndef V8_SHARED | 1274 #ifndef V8_SHARED |
1275 Locker lock; | 1275 Locker lock(isolate); |
1276 HandleScope scope; | 1276 HandleScope scope; |
1277 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 1277 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
1278 utility_context_ = Context::New(NULL, global_template); | 1278 utility_context_ = Context::New(NULL, global_template); |
1279 | 1279 |
1280 #ifdef ENABLE_DEBUGGER_SUPPORT | 1280 #ifdef ENABLE_DEBUGGER_SUPPORT |
1281 // Start the debugger agent if requested. | 1281 // Start the debugger agent if requested. |
1282 if (i::FLAG_debugger_agent) { | 1282 if (i::FLAG_debugger_agent) { |
1283 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 1283 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
1284 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); | 1284 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); |
1285 } | 1285 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 int size = 0; | 1483 int size = 0; |
1484 char* chars = ReadChars(isolate, name, &size); | 1484 char* chars = ReadChars(isolate, name, &size); |
1485 if (chars == NULL) return Handle<String>(); | 1485 if (chars == NULL) return Handle<String>(); |
1486 Handle<String> result = String::New(chars, size); | 1486 Handle<String> result = String::New(chars, size); |
1487 delete[] chars; | 1487 delete[] chars; |
1488 return result; | 1488 return result; |
1489 } | 1489 } |
1490 | 1490 |
1491 | 1491 |
1492 void Shell::RunShell(Isolate* isolate) { | 1492 void Shell::RunShell(Isolate* isolate) { |
1493 Locker locker; | 1493 Locker locker(isolate); |
1494 Context::Scope context_scope(evaluation_context_); | 1494 Context::Scope context_scope(evaluation_context_); |
1495 HandleScope outer_scope; | 1495 HandleScope outer_scope; |
1496 Handle<String> name = String::New("(d8)"); | 1496 Handle<String> name = String::New("(d8)"); |
1497 DumbLineEditor dumb_line_editor(isolate); | 1497 DumbLineEditor dumb_line_editor(isolate); |
1498 LineEditor* console = LineEditor::Get(); | 1498 LineEditor* console = LineEditor::Get(); |
1499 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); | 1499 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); |
1500 console->Open(); | 1500 console->Open(); |
1501 while (true) { | 1501 while (true) { |
1502 HandleScope inner_scope; | 1502 HandleScope inner_scope; |
1503 Handle<String> input = console->Prompt(Shell::kPrompt); | 1503 Handle<String> input = console->Prompt(Shell::kPrompt); |
(...skipping 29 matching lines...) Expand all Loading... |
1533 // For each newline-separated line. | 1533 // For each newline-separated line. |
1534 char* next_line = ReadLine(ptr); | 1534 char* next_line = ReadLine(ptr); |
1535 | 1535 |
1536 if (*ptr == '#') { | 1536 if (*ptr == '#') { |
1537 // Skip comment lines. | 1537 // Skip comment lines. |
1538 ptr = next_line; | 1538 ptr = next_line; |
1539 continue; | 1539 continue; |
1540 } | 1540 } |
1541 | 1541 |
1542 // Prepare the context for this thread. | 1542 // Prepare the context for this thread. |
1543 Locker locker; | 1543 Locker locker(isolate_); |
1544 HandleScope outer_scope; | 1544 HandleScope outer_scope; |
1545 Persistent<Context> thread_context = | 1545 Persistent<Context> thread_context = |
1546 Shell::CreateEvaluationContext(isolate_); | 1546 Shell::CreateEvaluationContext(isolate_); |
1547 Context::Scope context_scope(thread_context); | 1547 Context::Scope context_scope(thread_context); |
1548 | 1548 |
1549 while ((ptr != NULL) && (*ptr != '\0')) { | 1549 while ((ptr != NULL) && (*ptr != '\0')) { |
1550 HandleScope inner_scope; | 1550 HandleScope inner_scope; |
1551 char* filename = ptr; | 1551 char* filename = ptr; |
1552 ptr = ReadWord(ptr); | 1552 ptr = ReadWord(ptr); |
1553 | 1553 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 ShellThread* thread = new ShellThread(isolate, files); | 1832 ShellThread* thread = new ShellThread(isolate, files); |
1833 thread->Start(); | 1833 thread->Start(); |
1834 threads.Add(thread); | 1834 threads.Add(thread); |
1835 } | 1835 } |
1836 } | 1836 } |
1837 for (int i = 1; i < options.num_isolates; ++i) { | 1837 for (int i = 1; i < options.num_isolates; ++i) { |
1838 options.isolate_sources[i].StartExecuteInThread(); | 1838 options.isolate_sources[i].StartExecuteInThread(); |
1839 } | 1839 } |
1840 #endif // V8_SHARED | 1840 #endif // V8_SHARED |
1841 { // NOLINT | 1841 { // NOLINT |
1842 Locker lock; | 1842 Locker lock(isolate); |
1843 HandleScope scope; | 1843 HandleScope scope; |
1844 Persistent<Context> context = CreateEvaluationContext(isolate); | 1844 Persistent<Context> context = CreateEvaluationContext(isolate); |
1845 if (options.last_run) { | 1845 if (options.last_run) { |
1846 // Keep using the same context in the interactive shell. | 1846 // Keep using the same context in the interactive shell. |
1847 evaluation_context_ = context; | 1847 evaluation_context_ = context; |
1848 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1848 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
1849 // If the interactive debugger is enabled make sure to activate | 1849 // If the interactive debugger is enabled make sure to activate |
1850 // it before running the files passed on the command line. | 1850 // it before running the files passed on the command line. |
1851 if (i::FLAG_debugger) { | 1851 if (i::FLAG_debugger) { |
1852 InstallUtilityScript(); | 1852 InstallUtilityScript(isolate); |
1853 } | 1853 } |
1854 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1854 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
1855 } | 1855 } |
1856 { | 1856 { |
1857 Context::Scope cscope(context); | 1857 Context::Scope cscope(context); |
1858 options.isolate_sources[0].Execute(isolate); | 1858 options.isolate_sources[0].Execute(isolate); |
1859 } | 1859 } |
1860 if (!options.last_run) { | 1860 if (!options.last_run) { |
1861 context.Dispose(); | 1861 context.Dispose(); |
1862 if (options.send_idle_notification) { | 1862 if (options.send_idle_notification) { |
(...skipping 17 matching lines...) Expand all Loading... |
1880 options.isolate_sources[i].WaitForThread(); | 1880 options.isolate_sources[i].WaitForThread(); |
1881 } | 1881 } |
1882 | 1882 |
1883 for (int i = 0; i < threads.length(); i++) { | 1883 for (int i = 0; i < threads.length(); i++) { |
1884 i::Thread* thread = threads[i]; | 1884 i::Thread* thread = threads[i]; |
1885 thread->Join(); | 1885 thread->Join(); |
1886 delete thread; | 1886 delete thread; |
1887 } | 1887 } |
1888 | 1888 |
1889 if (threads.length() > 0 && options.use_preemption) { | 1889 if (threads.length() > 0 && options.use_preemption) { |
1890 Locker lock; | 1890 Locker lock(isolate); |
1891 Locker::StopPreemption(); | 1891 Locker::StopPreemption(); |
1892 } | 1892 } |
1893 #endif // V8_SHARED | 1893 #endif // V8_SHARED |
1894 return 0; | 1894 return 0; |
1895 } | 1895 } |
1896 | 1896 |
1897 | 1897 |
1898 int Shell::Main(int argc, char* argv[]) { | 1898 int Shell::Main(int argc, char* argv[]) { |
1899 if (!SetOptions(argc, argv)) return 1; | 1899 if (!SetOptions(argc, argv)) return 1; |
1900 int result = 0; | 1900 int result = 0; |
(...skipping 26 matching lines...) Expand all Loading... |
1927 } | 1927 } |
1928 #endif | 1928 #endif |
1929 } else { | 1929 } else { |
1930 result = RunMain(isolate, argc, argv); | 1930 result = RunMain(isolate, argc, argv); |
1931 } | 1931 } |
1932 | 1932 |
1933 | 1933 |
1934 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1934 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
1935 // Run remote debugger if requested, but never on --test | 1935 // Run remote debugger if requested, but never on --test |
1936 if (i::FLAG_remote_debugger && !options.test_shell) { | 1936 if (i::FLAG_remote_debugger && !options.test_shell) { |
1937 InstallUtilityScript(); | 1937 InstallUtilityScript(isolate); |
1938 RunRemoteDebugger(i::FLAG_debugger_port); | 1938 RunRemoteDebugger(i::FLAG_debugger_port); |
1939 return 0; | 1939 return 0; |
1940 } | 1940 } |
1941 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1941 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
1942 | 1942 |
1943 // Run interactive shell if explicitly requested or if no script has been | 1943 // Run interactive shell if explicitly requested or if no script has been |
1944 // executed, but never on --test | 1944 // executed, but never on --test |
1945 | 1945 |
1946 if (( options.interactive_shell || !options.script_executed ) | 1946 if (( options.interactive_shell || !options.script_executed ) |
1947 && !options.test_shell ) { | 1947 && !options.test_shell ) { |
1948 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1948 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
1949 if (!i::FLAG_debugger) { | 1949 if (!i::FLAG_debugger) { |
1950 InstallUtilityScript(); | 1950 InstallUtilityScript(isolate); |
1951 } | 1951 } |
1952 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1952 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
1953 RunShell(isolate); | 1953 RunShell(isolate); |
1954 } | 1954 } |
1955 } | 1955 } |
1956 V8::Dispose(); | 1956 V8::Dispose(); |
1957 | 1957 |
1958 OnExit(); | 1958 OnExit(); |
1959 | 1959 |
1960 return result; | 1960 return result; |
1961 } | 1961 } |
1962 | 1962 |
1963 } // namespace v8 | 1963 } // namespace v8 |
1964 | 1964 |
1965 | 1965 |
1966 #ifndef GOOGLE3 | 1966 #ifndef GOOGLE3 |
1967 int main(int argc, char* argv[]) { | 1967 int main(int argc, char* argv[]) { |
1968 return v8::Shell::Main(argc, argv); | 1968 return v8::Shell::Main(argc, argv); |
1969 } | 1969 } |
1970 #endif | 1970 #endif |
OLD | NEW |