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 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 #endif // V8_SHARED | 1532 #endif // V8_SHARED |
1533 } | 1533 } |
1534 | 1534 |
1535 | 1535 |
1536 void Shell::InitializeDebugger(Isolate* isolate) { | 1536 void Shell::InitializeDebugger(Isolate* isolate) { |
1537 if (options.test_shell) return; | 1537 if (options.test_shell) return; |
1538 #ifndef V8_SHARED | 1538 #ifndef V8_SHARED |
1539 Locker lock(isolate); | 1539 Locker lock(isolate); |
1540 HandleScope scope(isolate); | 1540 HandleScope scope(isolate); |
1541 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 1541 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
1542 utility_context_.Reset(isolate, | 1542 utility_context_ = Context::New(NULL, global_template); |
1543 Context::New(isolate, NULL, global_template)); | |
1544 | 1543 |
1545 #ifdef ENABLE_DEBUGGER_SUPPORT | 1544 #ifdef ENABLE_DEBUGGER_SUPPORT |
1546 // Start the debugger agent if requested. | 1545 // Start the debugger agent if requested. |
1547 if (i::FLAG_debugger_agent) { | 1546 if (i::FLAG_debugger_agent) { |
1548 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 1547 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
1549 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); | 1548 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); |
1550 } | 1549 } |
1551 #endif // ENABLE_DEBUGGER_SUPPORT | 1550 #endif // ENABLE_DEBUGGER_SUPPORT |
1552 #endif // V8_SHARED | 1551 #endif // V8_SHARED |
1553 } | 1552 } |
1554 | 1553 |
1555 | 1554 |
1556 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { | 1555 Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) { |
1557 #ifndef V8_SHARED | 1556 #ifndef V8_SHARED |
1558 // This needs to be a critical section since this is not thread-safe | 1557 // This needs to be a critical section since this is not thread-safe |
1559 i::ScopedLock lock(context_mutex_); | 1558 i::ScopedLock lock(context_mutex_); |
1560 #endif // V8_SHARED | 1559 #endif // V8_SHARED |
1561 // Initialize the global objects | 1560 // Initialize the global objects |
1562 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 1561 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
| 1562 Persistent<Context> context = Context::New(NULL, global_template); |
| 1563 ASSERT(!context.IsEmpty()); |
1563 HandleScope handle_scope(isolate); | 1564 HandleScope handle_scope(isolate); |
1564 Local<Context> context = Context::New(isolate, NULL, global_template); | 1565 Context::Scope scope(isolate, context); |
1565 ASSERT(!context.IsEmpty()); | |
1566 Context::Scope scope(context); | |
1567 | 1566 |
1568 #ifndef V8_SHARED | 1567 #ifndef V8_SHARED |
1569 i::JSArguments js_args = i::FLAG_js_arguments; | 1568 i::JSArguments js_args = i::FLAG_js_arguments; |
1570 i::Handle<i::FixedArray> arguments_array = | 1569 i::Handle<i::FixedArray> arguments_array = |
1571 FACTORY->NewFixedArray(js_args.argc()); | 1570 FACTORY->NewFixedArray(js_args.argc()); |
1572 for (int j = 0; j < js_args.argc(); j++) { | 1571 for (int j = 0; j < js_args.argc(); j++) { |
1573 i::Handle<i::String> arg = | 1572 i::Handle<i::String> arg = |
1574 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 1573 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
1575 arguments_array->set(j, *arg); | 1574 arguments_array->set(j, *arg); |
1576 } | 1575 } |
1577 i::Handle<i::JSArray> arguments_jsarray = | 1576 i::Handle<i::JSArray> arguments_jsarray = |
1578 FACTORY->NewJSArrayWithElements(arguments_array); | 1577 FACTORY->NewJSArrayWithElements(arguments_array); |
1579 context->Global()->Set(String::New("arguments"), | 1578 context->Global()->Set(String::New("arguments"), |
1580 Utils::ToLocal(arguments_jsarray)); | 1579 Utils::ToLocal(arguments_jsarray)); |
1581 #endif // V8_SHARED | 1580 #endif // V8_SHARED |
1582 return handle_scope.Close(context); | 1581 return context; |
1583 } | 1582 } |
1584 | 1583 |
1585 | 1584 |
1586 void Shell::Exit(int exit_code) { | 1585 void Shell::Exit(int exit_code) { |
1587 // Use _exit instead of exit to avoid races between isolate | 1586 // Use _exit instead of exit to avoid races between isolate |
1588 // threads and static destructors. | 1587 // threads and static destructors. |
1589 fflush(stdout); | 1588 fflush(stdout); |
1590 fflush(stderr); | 1589 fflush(stderr); |
1591 _exit(exit_code); | 1590 _exit(exit_code); |
1592 } | 1591 } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 | 1802 |
1804 if (*ptr == '#') { | 1803 if (*ptr == '#') { |
1805 // Skip comment lines. | 1804 // Skip comment lines. |
1806 ptr = next_line; | 1805 ptr = next_line; |
1807 continue; | 1806 continue; |
1808 } | 1807 } |
1809 | 1808 |
1810 // Prepare the context for this thread. | 1809 // Prepare the context for this thread. |
1811 Locker locker(isolate_); | 1810 Locker locker(isolate_); |
1812 HandleScope outer_scope(isolate_); | 1811 HandleScope outer_scope(isolate_); |
1813 Local<Context> thread_context = | 1812 Persistent<Context> thread_context = |
1814 Shell::CreateEvaluationContext(isolate_); | 1813 Shell::CreateEvaluationContext(isolate_); |
1815 Context::Scope context_scope(thread_context); | 1814 Context::Scope context_scope(isolate_, thread_context); |
1816 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate_)); | 1815 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate_)); |
1817 | 1816 |
1818 while ((ptr != NULL) && (*ptr != '\0')) { | 1817 while ((ptr != NULL) && (*ptr != '\0')) { |
1819 HandleScope inner_scope(isolate_); | 1818 HandleScope inner_scope(isolate_); |
1820 char* filename = ptr; | 1819 char* filename = ptr; |
1821 ptr = ReadWord(ptr); | 1820 ptr = ReadWord(ptr); |
1822 | 1821 |
1823 // Skip empty strings. | 1822 // Skip empty strings. |
1824 if (strlen(filename) == 0) { | 1823 if (strlen(filename) == 0) { |
1825 continue; | 1824 continue; |
1826 } | 1825 } |
1827 | 1826 |
1828 Handle<String> str = Shell::ReadFile(isolate_, filename); | 1827 Handle<String> str = Shell::ReadFile(isolate_, filename); |
1829 if (str.IsEmpty()) { | 1828 if (str.IsEmpty()) { |
1830 printf("File '%s' not found\n", filename); | 1829 printf("File '%s' not found\n", filename); |
1831 Shell::Exit(1); | 1830 Shell::Exit(1); |
1832 } | 1831 } |
1833 | 1832 |
1834 Shell::ExecuteString(isolate_, str, String::New(filename), false, false); | 1833 Shell::ExecuteString(isolate_, str, String::New(filename), false, false); |
1835 } | 1834 } |
1836 | 1835 |
| 1836 thread_context.Dispose(thread_context->GetIsolate()); |
1837 ptr = next_line; | 1837 ptr = next_line; |
1838 } | 1838 } |
1839 } | 1839 } |
1840 #endif // V8_SHARED | 1840 #endif // V8_SHARED |
1841 | 1841 |
1842 | 1842 |
1843 SourceGroup::~SourceGroup() { | 1843 SourceGroup::~SourceGroup() { |
1844 #ifndef V8_SHARED | 1844 #ifndef V8_SHARED |
1845 delete next_semaphore_; | 1845 delete next_semaphore_; |
1846 next_semaphore_ = NULL; | 1846 next_semaphore_ = NULL; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 } | 1903 } |
1904 | 1904 |
1905 | 1905 |
1906 void SourceGroup::ExecuteInThread() { | 1906 void SourceGroup::ExecuteInThread() { |
1907 Isolate* isolate = Isolate::New(); | 1907 Isolate* isolate = Isolate::New(); |
1908 do { | 1908 do { |
1909 if (next_semaphore_ != NULL) next_semaphore_->Wait(); | 1909 if (next_semaphore_ != NULL) next_semaphore_->Wait(); |
1910 { | 1910 { |
1911 Isolate::Scope iscope(isolate); | 1911 Isolate::Scope iscope(isolate); |
1912 Locker lock(isolate); | 1912 Locker lock(isolate); |
| 1913 HandleScope scope(isolate); |
| 1914 PerIsolateData data(isolate); |
| 1915 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); |
1913 { | 1916 { |
1914 HandleScope scope(isolate); | 1917 Context::Scope cscope(isolate, context); |
1915 PerIsolateData data(isolate); | 1918 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
1916 Local<Context> context = Shell::CreateEvaluationContext(isolate); | 1919 Execute(isolate); |
1917 { | |
1918 Context::Scope cscope(context); | |
1919 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | |
1920 Execute(isolate); | |
1921 } | |
1922 } | 1920 } |
| 1921 context.Dispose(isolate); |
1923 if (Shell::options.send_idle_notification) { | 1922 if (Shell::options.send_idle_notification) { |
1924 const int kLongIdlePauseInMs = 1000; | 1923 const int kLongIdlePauseInMs = 1000; |
1925 V8::ContextDisposedNotification(); | 1924 V8::ContextDisposedNotification(); |
1926 V8::IdleNotification(kLongIdlePauseInMs); | 1925 V8::IdleNotification(kLongIdlePauseInMs); |
1927 } | 1926 } |
1928 } | 1927 } |
1929 if (done_semaphore_ != NULL) done_semaphore_->Signal(); | 1928 if (done_semaphore_ != NULL) done_semaphore_->Signal(); |
1930 } while (!Shell::options.last_run); | 1929 } while (!Shell::options.last_run); |
1931 isolate->Dispose(); | 1930 isolate->Dispose(); |
1932 } | 1931 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 thread->Start(); | 2102 thread->Start(); |
2104 threads.Add(thread); | 2103 threads.Add(thread); |
2105 } | 2104 } |
2106 } | 2105 } |
2107 for (int i = 1; i < options.num_isolates; ++i) { | 2106 for (int i = 1; i < options.num_isolates; ++i) { |
2108 options.isolate_sources[i].StartExecuteInThread(); | 2107 options.isolate_sources[i].StartExecuteInThread(); |
2109 } | 2108 } |
2110 #endif // V8_SHARED | 2109 #endif // V8_SHARED |
2111 { // NOLINT | 2110 { // NOLINT |
2112 Locker lock(isolate); | 2111 Locker lock(isolate); |
| 2112 HandleScope scope(isolate); |
| 2113 Persistent<Context> context = CreateEvaluationContext(isolate); |
| 2114 if (options.last_run) { |
| 2115 // Keep using the same context in the interactive shell. |
| 2116 evaluation_context_ = context; |
| 2117 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
| 2118 // If the interactive debugger is enabled make sure to activate |
| 2119 // it before running the files passed on the command line. |
| 2120 if (i::FLAG_debugger) { |
| 2121 InstallUtilityScript(isolate); |
| 2122 } |
| 2123 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 2124 } |
2113 { | 2125 { |
2114 HandleScope scope(isolate); | 2126 Context::Scope cscope(isolate, context); |
2115 Local<Context> context = CreateEvaluationContext(isolate); | 2127 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
2116 if (options.last_run) { | 2128 options.isolate_sources[0].Execute(isolate); |
2117 // Keep using the same context in the interactive shell. | |
2118 evaluation_context_.Reset(isolate, context); | |
2119 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | |
2120 // If the interactive debugger is enabled make sure to activate | |
2121 // it before running the files passed on the command line. | |
2122 if (i::FLAG_debugger) { | |
2123 InstallUtilityScript(isolate); | |
2124 } | |
2125 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | |
2126 } | |
2127 { | |
2128 Context::Scope cscope(context); | |
2129 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | |
2130 options.isolate_sources[0].Execute(isolate); | |
2131 } | |
2132 } | 2129 } |
2133 if (!options.last_run) { | 2130 if (!options.last_run) { |
| 2131 context.Dispose(isolate); |
2134 if (options.send_idle_notification) { | 2132 if (options.send_idle_notification) { |
2135 const int kLongIdlePauseInMs = 1000; | 2133 const int kLongIdlePauseInMs = 1000; |
2136 V8::ContextDisposedNotification(); | 2134 V8::ContextDisposedNotification(); |
2137 V8::IdleNotification(kLongIdlePauseInMs); | 2135 V8::IdleNotification(kLongIdlePauseInMs); |
2138 } | 2136 } |
2139 } | 2137 } |
2140 | 2138 |
2141 #ifndef V8_SHARED | 2139 #ifndef V8_SHARED |
2142 // Start preemption if threads have been created and preemption is enabled. | 2140 // Start preemption if threads have been created and preemption is enabled. |
2143 if (threads.length() > 0 | 2141 if (threads.length() > 0 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 } | 2235 } |
2238 | 2236 |
2239 } // namespace v8 | 2237 } // namespace v8 |
2240 | 2238 |
2241 | 2239 |
2242 #ifndef GOOGLE3 | 2240 #ifndef GOOGLE3 |
2243 int main(int argc, char* argv[]) { | 2241 int main(int argc, char* argv[]) { |
2244 return v8::Shell::Main(argc, argv); | 2242 return v8::Shell::Main(argc, argv); |
2245 } | 2243 } |
2246 #endif | 2244 #endif |
OLD | NEW |