| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/debug/debug.h" | 5 #include "src/debug/debug.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
| (...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 ProcessCompileEvent(v8::CompileError, script); | 1881 ProcessCompileEvent(v8::CompileError, script); |
| 1882 } | 1882 } |
| 1883 | 1883 |
| 1884 | 1884 |
| 1885 // Handle debugger actions when a new script is compiled. | 1885 // Handle debugger actions when a new script is compiled. |
| 1886 void Debug::OnAfterCompile(Handle<Script> script) { | 1886 void Debug::OnAfterCompile(Handle<Script> script) { |
| 1887 ProcessCompileEvent(v8::AfterCompile, script); | 1887 ProcessCompileEvent(v8::AfterCompile, script); |
| 1888 } | 1888 } |
| 1889 | 1889 |
| 1890 namespace { | 1890 namespace { |
| 1891 struct CollectedCallbackData { | |
| 1892 Object** location; | |
| 1893 int id; | |
| 1894 Debug* debug; | |
| 1895 Isolate* isolate; | |
| 1896 | |
| 1897 CollectedCallbackData(Object** location, int id, Debug* debug, | |
| 1898 Isolate* isolate) | |
| 1899 : location(location), id(id), debug(debug), isolate(isolate) {} | |
| 1900 }; | |
| 1901 | |
| 1902 void SendAsyncTaskEventCancel(const v8::WeakCallbackInfo<void>& info) { | |
| 1903 std::unique_ptr<CollectedCallbackData> data( | |
| 1904 reinterpret_cast<CollectedCallbackData*>(info.GetParameter())); | |
| 1905 if (!data->debug->is_active()) return; | |
| 1906 HandleScope scope(data->isolate); | |
| 1907 data->debug->OnAsyncTaskEvent(debug::kDebugPromiseCollected, data->id, 0); | |
| 1908 } | |
| 1909 | |
| 1910 void ResetPromiseHandle(const v8::WeakCallbackInfo<void>& info) { | |
| 1911 CollectedCallbackData* data = | |
| 1912 reinterpret_cast<CollectedCallbackData*>(info.GetParameter()); | |
| 1913 GlobalHandles::Destroy(data->location); | |
| 1914 info.SetSecondPassCallback(&SendAsyncTaskEventCancel); | |
| 1915 } | |
| 1916 | |
| 1917 // In an async function, reuse the existing stack related to the outer | 1891 // In an async function, reuse the existing stack related to the outer |
| 1918 // Promise. Otherwise, e.g. in a direct call to then, save a new stack. | 1892 // Promise. Otherwise, e.g. in a direct call to then, save a new stack. |
| 1919 // Promises with multiple reactions with one or more of them being async | 1893 // Promises with multiple reactions with one or more of them being async |
| 1920 // functions will not get a good stack trace, as async functions require | 1894 // functions will not get a good stack trace, as async functions require |
| 1921 // different stacks from direct Promise use, but we save and restore a | 1895 // different stacks from direct Promise use, but we save and restore a |
| 1922 // stack once for all reactions. | 1896 // stack once for all reactions. |
| 1923 // | 1897 // |
| 1924 // If this isn't a case of async function, we return false, otherwise | 1898 // If this isn't a case of async function, we return false, otherwise |
| 1925 // we set the correct id and return true. | 1899 // we set the correct id and return true. |
| 1926 // | 1900 // |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 LookupIterator it(promise, isolate_->factory()->promise_async_id_symbol()); | 1949 LookupIterator it(promise, isolate_->factory()->promise_async_id_symbol()); |
| 1976 Maybe<bool> maybe = JSReceiver::HasProperty(&it); | 1950 Maybe<bool> maybe = JSReceiver::HasProperty(&it); |
| 1977 if (maybe.ToChecked()) { | 1951 if (maybe.ToChecked()) { |
| 1978 MaybeHandle<Object> result = Object::GetProperty(&it); | 1952 MaybeHandle<Object> result = Object::GetProperty(&it); |
| 1979 return Handle<Smi>::cast(result.ToHandleChecked())->value(); | 1953 return Handle<Smi>::cast(result.ToHandleChecked())->value(); |
| 1980 } | 1954 } |
| 1981 Handle<Smi> async_id = | 1955 Handle<Smi> async_id = |
| 1982 handle(Smi::FromInt(++thread_local_.async_task_count_), isolate_); | 1956 handle(Smi::FromInt(++thread_local_.async_task_count_), isolate_); |
| 1983 Object::SetProperty(&it, async_id, SLOPPY, Object::MAY_BE_STORE_FROM_KEYED) | 1957 Object::SetProperty(&it, async_id, SLOPPY, Object::MAY_BE_STORE_FROM_KEYED) |
| 1984 .ToChecked(); | 1958 .ToChecked(); |
| 1985 Handle<Object> global_handle = isolate_->global_handles()->Create(*promise); | |
| 1986 // We send EnqueueRecurring async task event when promise is fulfilled or | |
| 1987 // rejected, WillHandle and DidHandle for every scheduled microtask for this | |
| 1988 // promise. | |
| 1989 // We need to send a cancel event when no other microtasks can be | |
| 1990 // started for this promise and all current microtasks are finished. | |
| 1991 // Since we holding promise when at least one microtask is scheduled (inside | |
| 1992 // PromiseReactionJobInfo), we can send cancel event in weak callback. | |
| 1993 GlobalHandles::MakeWeak( | |
| 1994 global_handle.location(), | |
| 1995 new CollectedCallbackData(global_handle.location(), async_id->value(), | |
| 1996 this, isolate_), | |
| 1997 &ResetPromiseHandle, v8::WeakCallbackType::kParameter); | |
| 1998 return async_id->value(); | 1959 return async_id->value(); |
| 1999 } | 1960 } |
| 2000 | 1961 |
| 2001 namespace { | 1962 namespace { |
| 2002 debug::Location GetDebugLocation(Handle<Script> script, int source_position) { | 1963 debug::Location GetDebugLocation(Handle<Script> script, int source_position) { |
| 2003 Script::PositionInfo info; | 1964 Script::PositionInfo info; |
| 2004 Script::GetPositionInfo(script, source_position, &info, Script::WITH_OFFSET); | 1965 Script::GetPositionInfo(script, source_position, &info, Script::WITH_OFFSET); |
| 2005 return debug::Location(info.line, info.column); | 1966 return debug::Location(info.line, info.column); |
| 2006 } | 1967 } |
| 2007 } // namespace | 1968 } // namespace |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2492 isolate_->Throw(*isolate_->factory()->NewEvalError( | 2453 isolate_->Throw(*isolate_->factory()->NewEvalError( |
| 2493 MessageTemplate::kNoSideEffectDebugEvaluate)); | 2454 MessageTemplate::kNoSideEffectDebugEvaluate)); |
| 2494 } | 2455 } |
| 2495 isolate_->set_needs_side_effect_check(old_needs_side_effect_check_); | 2456 isolate_->set_needs_side_effect_check(old_needs_side_effect_check_); |
| 2496 isolate_->debug()->UpdateHookOnFunctionCall(); | 2457 isolate_->debug()->UpdateHookOnFunctionCall(); |
| 2497 isolate_->debug()->side_effect_check_failed_ = false; | 2458 isolate_->debug()->side_effect_check_failed_ = false; |
| 2498 } | 2459 } |
| 2499 | 2460 |
| 2500 } // namespace internal | 2461 } // namespace internal |
| 2501 } // namespace v8 | 2462 } // namespace v8 |
| OLD | NEW |