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/accessors.h" | 5 #include "src/accessors.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/contexts.h" | 8 #include "src/contexts.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/execution.h" | 10 #include "src/execution.h" |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 } | 837 } |
838 | 838 |
839 // Return the freshly allocated arguments object. | 839 // Return the freshly allocated arguments object. |
840 return arguments; | 840 return arguments; |
841 } | 841 } |
842 | 842 |
843 | 843 |
844 static int FindFunctionInFrame(JavaScriptFrame* frame, | 844 static int FindFunctionInFrame(JavaScriptFrame* frame, |
845 Handle<JSFunction> function) { | 845 Handle<JSFunction> function) { |
846 DisallowHeapAllocation no_allocation; | 846 DisallowHeapAllocation no_allocation; |
847 List<FrameSummary> frames(2); | 847 List<JSFunction*> functions(2); |
848 frame->Summarize(&frames); | 848 frame->GetFunctions(&functions); |
849 for (int i = frames.length() - 1; i >= 0; i--) { | 849 for (int i = functions.length() - 1; i >= 0; i--) { |
850 if (*frames[i].function() == *function) return i; | 850 if (functions[i] == *function) return i; |
851 } | 851 } |
852 return -1; | 852 return -1; |
853 } | 853 } |
854 | 854 |
855 | 855 |
856 namespace { | 856 namespace { |
857 | 857 |
858 Handle<Object> GetFunctionArguments(Isolate* isolate, | 858 Handle<Object> GetFunctionArguments(Isolate* isolate, |
859 Handle<JSFunction> function) { | 859 Handle<JSFunction> function) { |
860 // Find the top invocation of the function by traversing frames. | 860 // Find the top invocation of the function by traversing frames. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 | 944 |
945 static inline bool AllowAccessToFunction(Context* current_context, | 945 static inline bool AllowAccessToFunction(Context* current_context, |
946 JSFunction* function) { | 946 JSFunction* function) { |
947 return current_context->HasSameSecurityTokenAs(function->context()); | 947 return current_context->HasSameSecurityTokenAs(function->context()); |
948 } | 948 } |
949 | 949 |
950 | 950 |
951 class FrameFunctionIterator { | 951 class FrameFunctionIterator { |
952 public: | 952 public: |
953 FrameFunctionIterator(Isolate* isolate, const DisallowHeapAllocation& promise) | 953 FrameFunctionIterator(Isolate* isolate, const DisallowHeapAllocation& promise) |
954 : isolate_(isolate), frame_iterator_(isolate), frames_(2), index_(0) { | 954 : isolate_(isolate), |
955 GetFrames(); | 955 frame_iterator_(isolate), |
| 956 functions_(2), |
| 957 index_(0) { |
| 958 GetFunctions(); |
956 } | 959 } |
957 JSFunction* next() { | 960 JSFunction* next() { |
958 while (true) { | 961 while (true) { |
959 if (frames_.length() == 0) return NULL; | 962 if (functions_.length() == 0) return NULL; |
960 JSFunction* next_function = *frames_[index_].function(); | 963 JSFunction* next_function = functions_[index_]; |
961 index_--; | 964 index_--; |
962 if (index_ < 0) { | 965 if (index_ < 0) { |
963 GetFrames(); | 966 GetFunctions(); |
964 } | 967 } |
965 // Skip functions from other origins. | 968 // Skip functions from other origins. |
966 if (!AllowAccessToFunction(isolate_->context(), next_function)) continue; | 969 if (!AllowAccessToFunction(isolate_->context(), next_function)) continue; |
967 return next_function; | 970 return next_function; |
968 } | 971 } |
969 } | 972 } |
970 | 973 |
971 // Iterate through functions until the first occurence of 'function'. | 974 // Iterate through functions until the first occurence of 'function'. |
972 // Returns true if 'function' is found, and false if the iterator ends | 975 // Returns true if 'function' is found, and false if the iterator ends |
973 // without finding it. | 976 // without finding it. |
974 bool Find(JSFunction* function) { | 977 bool Find(JSFunction* function) { |
975 JSFunction* next_function; | 978 JSFunction* next_function; |
976 do { | 979 do { |
977 next_function = next(); | 980 next_function = next(); |
978 if (next_function == function) return true; | 981 if (next_function == function) return true; |
979 } while (next_function != NULL); | 982 } while (next_function != NULL); |
980 return false; | 983 return false; |
981 } | 984 } |
982 | 985 |
983 private: | 986 private: |
984 void GetFrames() { | 987 void GetFunctions() { |
985 frames_.Rewind(0); | 988 functions_.Rewind(0); |
986 if (frame_iterator_.done()) return; | 989 if (frame_iterator_.done()) return; |
987 JavaScriptFrame* frame = frame_iterator_.frame(); | 990 JavaScriptFrame* frame = frame_iterator_.frame(); |
988 frame->Summarize(&frames_); | 991 frame->GetFunctions(&functions_); |
989 DCHECK(frames_.length() > 0); | 992 DCHECK(functions_.length() > 0); |
990 frame_iterator_.Advance(); | 993 frame_iterator_.Advance(); |
991 index_ = frames_.length() - 1; | 994 index_ = functions_.length() - 1; |
992 } | 995 } |
993 Isolate* isolate_; | 996 Isolate* isolate_; |
994 JavaScriptFrameIterator frame_iterator_; | 997 JavaScriptFrameIterator frame_iterator_; |
995 List<FrameSummary> frames_; | 998 List<JSFunction*> functions_; |
996 int index_; | 999 int index_; |
997 }; | 1000 }; |
998 | 1001 |
999 | 1002 |
1000 MaybeHandle<JSFunction> FindCaller(Isolate* isolate, | 1003 MaybeHandle<JSFunction> FindCaller(Isolate* isolate, |
1001 Handle<JSFunction> function) { | 1004 Handle<JSFunction> function) { |
1002 DisallowHeapAllocation no_allocation; | 1005 DisallowHeapAllocation no_allocation; |
1003 FrameFunctionIterator it(isolate, no_allocation); | 1006 FrameFunctionIterator it(isolate, no_allocation); |
1004 if (function->shared()->native()) { | 1007 if (function->shared()->native()) { |
1005 return MaybeHandle<JSFunction>(); | 1008 return MaybeHandle<JSFunction>(); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 Handle<AccessorInfo> Accessors::ErrorStackInfo(Isolate* isolate, | 1246 Handle<AccessorInfo> Accessors::ErrorStackInfo(Isolate* isolate, |
1244 PropertyAttributes attributes) { | 1247 PropertyAttributes attributes) { |
1245 Handle<AccessorInfo> info = | 1248 Handle<AccessorInfo> info = |
1246 MakeAccessor(isolate, isolate->factory()->stack_string(), | 1249 MakeAccessor(isolate, isolate->factory()->stack_string(), |
1247 &ErrorStackGetter, &ErrorStackSetter, attributes); | 1250 &ErrorStackGetter, &ErrorStackSetter, attributes); |
1248 return info; | 1251 return info; |
1249 } | 1252 } |
1250 | 1253 |
1251 } // namespace internal | 1254 } // namespace internal |
1252 } // namespace v8 | 1255 } // namespace v8 |
OLD | NEW |