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/liveedit.h" | 5 #include "src/debug/liveedit.h" |
6 | 6 |
7 #include "src/ast/scopeinfo.h" | 7 #include "src/ast/scopeinfo.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 FunctionInfoWrapper info = FunctionInfoWrapper::cast( | 713 FunctionInfoWrapper info = FunctionInfoWrapper::cast( |
714 *JSReceiver::GetElement(isolate(), result_, current_parent_index_) | 714 *JSReceiver::GetElement(isolate(), result_, current_parent_index_) |
715 .ToHandleChecked()); | 715 .ToHandleChecked()); |
716 current_parent_index_ = info.GetParentIndex(); | 716 current_parent_index_ = info.GetParentIndex(); |
717 } | 717 } |
718 | 718 |
719 // Saves full information about a function: its code, its scope info | 719 // Saves full information about a function: its code, its scope info |
720 // and a SharedFunctionInfo object. | 720 // and a SharedFunctionInfo object. |
721 void FunctionInfo(Handle<SharedFunctionInfo> shared, Scope* scope, | 721 void FunctionInfo(Handle<SharedFunctionInfo> shared, Scope* scope, |
722 Zone* zone) { | 722 Zone* zone) { |
723 if (!shared->IsSharedFunctionInfo()) { | 723 DCHECK(shared->IsSharedFunctionInfo()); |
Yang
2016/05/11 07:29:09
We should not need this check. I don't even know w
jgruber1
2016/05/12 12:30:25
Done.
| |
724 return; | |
725 } | |
726 FunctionInfoWrapper info = FunctionInfoWrapper::cast( | 724 FunctionInfoWrapper info = FunctionInfoWrapper::cast( |
727 *JSReceiver::GetElement(isolate(), result_, current_parent_index_) | 725 *JSReceiver::GetElement(isolate(), result_, current_parent_index_) |
728 .ToHandleChecked()); | 726 .ToHandleChecked()); |
729 info.SetFunctionCode(Handle<Code>(shared->code()), | 727 info.SetFunctionCode(Handle<Code>(shared->code()), |
730 Handle<HeapObject>(shared->scope_info())); | 728 Handle<HeapObject>(shared->scope_info())); |
731 info.SetSharedFunctionInfo(shared); | 729 info.SetSharedFunctionInfo(shared); |
732 | 730 |
733 Handle<Object> scope_info_list = SerializeFunctionScope(scope, zone); | 731 Handle<Object> scope_info_list = SerializeFunctionScope(scope, zone); |
734 info.SetFunctionScopeInfo(scope_info_list); | 732 info.SetFunctionScopeInfo(scope_info_list); |
735 } | 733 } |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1986 } | 1984 } |
1987 if (target.saved_status() == LiveEdit::FUNCTION_BLOCKED_UNDER_NATIVE_CODE) { | 1985 if (target.saved_status() == LiveEdit::FUNCTION_BLOCKED_UNDER_NATIVE_CODE) { |
1988 return "Function is blocked under native code"; | 1986 return "Function is blocked under native code"; |
1989 } | 1987 } |
1990 if (target.saved_status() == LiveEdit::FUNCTION_BLOCKED_UNDER_GENERATOR) { | 1988 if (target.saved_status() == LiveEdit::FUNCTION_BLOCKED_UNDER_GENERATOR) { |
1991 return "Function is blocked under a generator activation"; | 1989 return "Function is blocked under a generator activation"; |
1992 } | 1990 } |
1993 return NULL; | 1991 return NULL; |
1994 } | 1992 } |
1995 | 1993 |
1994 // Traverses the entire AST, and records information about all FunctionLiterals | |
1995 // for further use by LiveEdit code patching. | |
1996 class LiveEditFunctionVisitor : public AstTraversalVisitor { | |
1997 public: | |
1998 static void Visit(FunctionLiteral* node, Handle<Script> script, Zone* zone, | |
1999 Isolate* isolate); | |
1996 | 2000 |
1997 LiveEditFunctionTracker::LiveEditFunctionTracker(Isolate* isolate, | 2001 virtual ~LiveEditFunctionVisitor() {} |
1998 FunctionLiteral* fun) | 2002 void VisitFunctionLiteral(FunctionLiteral* node) override; |
1999 : isolate_(isolate) { | 2003 |
2000 if (isolate_->active_function_info_listener() != NULL) { | 2004 private: |
2001 isolate_->active_function_info_listener()->FunctionStarted(fun); | 2005 LiveEditFunctionVisitor(Handle<Script> script, Zone* zone, Isolate* isolate); |
2002 } | 2006 |
2007 Handle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun); | |
2008 | |
2009 FunctionInfoListener* function_info_listener_; | |
2010 Handle<Script> script_; | |
2011 Zone* zone_; | |
2012 | |
2013 DISALLOW_COPY_AND_ASSIGN(LiveEditFunctionVisitor); | |
2014 }; | |
2015 | |
2016 void LiveEditFunctionVisitor::Visit(FunctionLiteral* node, | |
2017 Handle<Script> script, Zone* zone, | |
2018 Isolate* isolate) { | |
2019 LiveEditFunctionVisitor visitor(script, zone, isolate); | |
2020 visitor.VisitFunctionLiteral(node); | |
2003 } | 2021 } |
2004 | 2022 |
2005 | 2023 LiveEditFunctionVisitor::LiveEditFunctionVisitor(Handle<Script> script, |
2006 LiveEditFunctionTracker::~LiveEditFunctionTracker() { | 2024 Zone* zone, Isolate* isolate) |
2007 if (isolate_->active_function_info_listener() != NULL) { | 2025 : AstTraversalVisitor(isolate), script_(script), zone_(zone) { |
2008 isolate_->active_function_info_listener()->FunctionDone(); | 2026 function_info_listener_ = isolate->active_function_info_listener(); |
2009 } | 2027 DCHECK_NOT_NULL(function_info_listener_); |
2010 } | 2028 } |
2011 | 2029 |
2012 | 2030 Handle<SharedFunctionInfo> LiveEditFunctionVisitor::FindSharedFunctionInfo( |
2013 void LiveEditFunctionTracker::RecordFunctionInfo( | 2031 FunctionLiteral* fun) { |
2014 Handle<SharedFunctionInfo> info, FunctionLiteral* lit, | 2032 // This is a near-duplicate of Script::FindSharedFunctionInfo, with the |
2015 Zone* zone) { | 2033 // difference being that here we also need to access top-level functions. |
2016 if (isolate_->active_function_info_listener() != NULL) { | 2034 // Possibly remove the assertion from Script:FindSharedFunctionInfo to |
2017 isolate_->active_function_info_listener()->FunctionInfo(info, lit->scope(), | 2035 // avoid duplicate code. |
Yang
2016/05/11 07:29:09
Yup. Let's use Script::FindSharedFunctionInfo inst
jgruber1
2016/05/12 12:30:25
Done.
| |
2018 zone); | 2036 WeakFixedArray::Iterator iterator(script_->shared_function_infos()); |
2037 SharedFunctionInfo* shared; | |
2038 while ((shared = iterator.Next<SharedFunctionInfo>())) { | |
2039 if (fun->function_token_position() == shared->function_token_position() && | |
2040 fun->start_position() == shared->start_position() && | |
2041 fun->end_position() == shared->end_position()) { | |
2042 return Handle<SharedFunctionInfo>(shared); | |
2043 } | |
2019 } | 2044 } |
2045 UNREACHABLE(); | |
2046 return Handle<SharedFunctionInfo>(); | |
2020 } | 2047 } |
2021 | 2048 |
2049 void LiveEditFunctionVisitor::VisitFunctionLiteral(FunctionLiteral* node) { | |
2050 Scope* scope = node->scope(); | |
2051 | |
2052 // FunctionStarted is called in pre-order. | |
2053 function_info_listener_->FunctionStarted(node); | |
2054 | |
2055 VisitDeclarations(scope->declarations()); | |
2056 VisitStatements(node->body()); | |
2057 | |
2058 // FunctionInfo and FunctionDone are called in post-order. | |
2059 Handle<SharedFunctionInfo> info = FindSharedFunctionInfo(node); | |
Yang
2016/05/11 07:29:09
For the number of shared function infos in the scr
jgruber1
2016/05/12 12:30:25
Good point. The repeated linear search is pretty u
| |
2060 function_info_listener_->FunctionInfo(info, scope, zone_); | |
2061 function_info_listener_->FunctionDone(); | |
2062 } | |
2063 | |
2064 void LiveEditFunctionTracker::Collect(Handle<Script> script, | |
2065 ParseInfo* parse_info, Isolate* isolate) { | |
2066 LiveEditFunctionVisitor::Visit(parse_info->literal(), script, | |
2067 parse_info->zone(), isolate); | |
2068 } | |
2022 | 2069 |
2023 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { | 2070 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { |
2024 return isolate->active_function_info_listener() != NULL; | 2071 return isolate->active_function_info_listener() != NULL; |
2025 } | 2072 } |
2026 | 2073 |
2027 } // namespace internal | 2074 } // namespace internal |
2028 } // namespace v8 | 2075 } // namespace v8 |
OLD | NEW |