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