Commit b8cdefb1 authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[frames] Simplify frames.h by inlining or removing single-use utilities.

R=petermarshall@chromium.org

Bug: 
Change-Id: Id7187d9e323951e66655d1c6df4676a8e94787dd
Reviewed-on: https://chromium-review.googlesource.com/649247Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47815}
parent 29691f80
......@@ -851,7 +851,10 @@ Handle<Object> GetFunctionArguments(Isolate* isolate,
}
// Find the frame that holds the actual arguments passed to the function.
it.AdvanceToArgumentsFrame();
if (it.frame()->has_adapted_arguments()) {
it.AdvanceOneFrame();
DCHECK(it.frame()->is_arguments_adaptor());
}
frame = it.frame();
// Get the number of arguments and construct an arguments object
......
......@@ -137,25 +137,6 @@ void JavaScriptFrameIterator::Advance() {
} while (!iterator_.done() && !iterator_.frame()->is_java_script());
}
void JavaScriptFrameIterator::AdvanceToArgumentsFrame() {
if (!frame()->has_adapted_arguments()) return;
iterator_.Advance();
DCHECK(iterator_.frame()->is_arguments_adaptor());
}
void JavaScriptFrameIterator::AdvanceWhileDebugContext(Debug* debug) {
if (!debug->in_debug_scope()) return;
while (!done()) {
Context* context = Context::cast(frame()->context());
if (context->native_context() == *debug->debug_context()) {
Advance();
} else {
break;
}
}
}
// -------------------------------------------------------------------------
StackTraceFrameIterator::StackTraceFrameIterator(Isolate* isolate)
......@@ -185,12 +166,6 @@ bool StackTraceFrameIterator::IsValidFrame(StackFrame* frame) const {
return frame->is_wasm();
}
void StackTraceFrameIterator::AdvanceToArgumentsFrame() {
if (!is_javascript() || !javascript_frame()->has_adapted_arguments()) return;
iterator_.Advance();
DCHECK(iterator_.frame()->is_arguments_adaptor());
}
// -------------------------------------------------------------------------
namespace {
......@@ -2032,24 +2007,8 @@ void InternalFrame::Iterate(RootVisitor* v) const {
if (code->has_tagged_params()) IterateExpressions(v);
}
// -------------------------------------------------------------------------
JavaScriptFrame* StackFrameLocator::FindJavaScriptFrame(int n) {
DCHECK(n >= 0);
for (int i = 0; i <= n; i++) {
while (!iterator_.frame()->is_java_script()) iterator_.Advance();
if (i == n) return JavaScriptFrame::cast(iterator_.frame());
iterator_.Advance();
}
UNREACHABLE();
}
// -------------------------------------------------------------------------
static Map* GcSafeMapOfCodeSpaceObject(HeapObject* object) {
MapWord map_word = object->map_word();
return map_word.IsForwardingAddress() ?
......
......@@ -1205,14 +1205,7 @@ class JavaScriptFrameIterator BASE_EMBEDDED {
bool done() const { return iterator_.done(); }
void Advance();
// Advance to the frame holding the arguments for the current
// frame. This only affects the current frame if it has adapted
// arguments.
void AdvanceToArgumentsFrame();
// Skips the frames that point to the debug context.
void AdvanceWhileDebugContext(Debug* debug);
void AdvanceOneFrame() { iterator_.Advance(); }
private:
StackFrameIterator iterator_;
......@@ -1228,6 +1221,7 @@ class StackTraceFrameIterator BASE_EMBEDDED {
StackTraceFrameIterator(Isolate* isolate, StackFrame::Id id);
bool done() const { return iterator_.done(); }
void Advance();
void AdvanceOneFrame() { iterator_.Advance(); }
inline StandardFrame* frame() const;
......@@ -1235,11 +1229,6 @@ class StackTraceFrameIterator BASE_EMBEDDED {
inline bool is_wasm() const;
inline JavaScriptFrame* javascript_frame() const;
// Advance to the frame holding the arguments for the current
// frame. This only affects the current frame if it is a javascript frame and
// has adapted arguments.
void AdvanceToArgumentsFrame();
private:
StackFrameIterator iterator_;
bool IsValidFrame(StackFrame* frame) const;
......@@ -1274,20 +1263,6 @@ class SafeStackFrameIterator: public StackFrameIteratorBase {
ExternalCallbackScope* external_callback_scope_;
};
class StackFrameLocator BASE_EMBEDDED {
public:
explicit StackFrameLocator(Isolate* isolate) : iterator_(isolate) {}
// Find the nth JavaScript frame on the stack. The caller must
// guarantee that such a frame exists.
JavaScriptFrame* FindJavaScriptFrame(int n);
private:
StackFrameIterator iterator_;
};
// Reads all frames on the current stack and copies them into the current
// zone memory.
Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone);
......
......@@ -2030,10 +2030,24 @@ void Isolate::SetAbortOnUncaughtExceptionCallback(
abort_on_uncaught_exception_callback_ = callback;
}
namespace {
void AdvanceWhileDebugContext(JavaScriptFrameIterator& it, Debug* debug) {
if (!debug->in_debug_scope()) return;
while (!it.done()) {
Context* context = Context::cast(it.frame()->context());
if (context->native_context() == *debug->debug_context()) {
it.Advance();
} else {
break;
}
}
}
} // namespace
Handle<Context> Isolate::GetCallingNativeContext() {
JavaScriptFrameIterator it(this);
it.AdvanceWhileDebugContext(debug_);
AdvanceWhileDebugContext(it, debug_);
if (it.done()) return Handle<Context>::null();
JavaScriptFrame* frame = it.frame();
Context* context = Context::cast(frame->context());
......@@ -2042,7 +2056,7 @@ Handle<Context> Isolate::GetCallingNativeContext() {
Handle<Context> Isolate::GetIncumbentContext() {
JavaScriptFrameIterator it(this);
it.AdvanceWhileDebugContext(debug_);
AdvanceWhileDebugContext(it, debug_);
// 1st candidate: most-recently-entered author function's context
// if it's newer than the last Context::BackupIncumbentScope entry.
......
......@@ -635,7 +635,8 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
// information (except for what is collected above) is the same.
if ((inlined_frame_index == 0) &&
it.javascript_frame()->has_adapted_arguments()) {
it.AdvanceToArgumentsFrame();
it.AdvanceOneFrame();
DCHECK(it.frame()->is_arguments_adaptor());
frame_inspector.SetArgumentsFrame(it.frame());
}
......@@ -1022,12 +1023,13 @@ RUNTIME_FUNCTION(Runtime_DebugPrintScopes) {
#ifdef DEBUG
// Print the scopes for the top frame.
StackFrameLocator locator(isolate);
JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
FrameInspector frame_inspector(frame, 0, isolate);
for (ScopeIterator it(isolate, &frame_inspector); !it.Done(); it.Next()) {
it.DebugPrint();
JavaScriptFrameIterator it(isolate);
if (!it.done()) {
JavaScriptFrame* frame = it.frame();
FrameInspector frame_inspector(frame, 0, isolate);
for (ScopeIterator si(isolate, &frame_inspector); !si.Done(); si.Next()) {
si.DebugPrint();
}
}
#endif
return isolate->heap()->undefined_value();
......
......@@ -387,7 +387,10 @@ std::unique_ptr<Handle<Object>[]> GetCallerArguments(Isolate* isolate,
return param_data;
} else {
it.AdvanceToArgumentsFrame();
if (it.frame()->has_adapted_arguments()) {
it.AdvanceOneFrame();
DCHECK(it.frame()->is_arguments_adaptor());
}
frame = it.frame();
int args_count = frame->ComputeParametersCount();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment