[async] Add CallSite#getPromiseIndex() builtin.

In order for Error.prepareStackTrace() to be able to reconstruct the
same stack frame that the internal mechanism can, we need to also
expose the index for the Promise.all() builtin. The newly added
CallSite#getPromiseIndex() does exactly that.

Bug: v8:7522
Change-Id: I904a4c1005f539536a71926ea1da38b31e2a2e8a
Reviewed-on: https://chromium-review.googlesource.com/c/1304293
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57055}
This commit is contained in:
Benedikt Meurer 2018-10-29 09:07:28 +01:00 committed by Commit Bot
parent ea8aa6a7c7
commit 93043d6482
6 changed files with 25 additions and 0 deletions

View File

@ -4354,6 +4354,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
{"getLineNumber", Builtins::kCallSitePrototypeGetLineNumber},
{"getMethodName", Builtins::kCallSitePrototypeGetMethodName},
{"getPosition", Builtins::kCallSitePrototypeGetPosition},
{"getPromiseIndex", Builtins::kCallSitePrototypeGetPromiseIndex},
{"getScriptNameOrSourceURL",
Builtins::kCallSitePrototypeGetScriptNameOrSourceURL},
{"getThis", Builtins::kCallSitePrototypeGetThis},

View File

@ -110,6 +110,14 @@ BUILTIN(CallSitePrototypeGetPosition) {
return Smi::FromInt(it.Frame()->GetPosition());
}
BUILTIN(CallSitePrototypeGetPromiseIndex) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getPromiseIndex");
FrameArrayIterator it(isolate, GetFrameArray(isolate, recv),
GetFrameIndex(isolate, recv));
return PositiveNumberOrNull(it.Frame()->GetPromiseIndex(), isolate);
}
BUILTIN(CallSitePrototypeGetScriptNameOrSourceURL) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getScriptNameOrSourceUrl");

View File

@ -459,6 +459,7 @@ namespace internal {
CPP(CallSitePrototypeGetLineNumber) \
CPP(CallSitePrototypeGetMethodName) \
CPP(CallSitePrototypeGetPosition) \
CPP(CallSitePrototypeGetPromiseIndex) \
CPP(CallSitePrototypeGetScriptNameOrSourceURL) \
CPP(CallSitePrototypeGetThis) \
CPP(CallSitePrototypeGetTypeName) \

View File

@ -468,6 +468,10 @@ int JSStackFrame::GetColumnNumber() {
return -1;
}
int JSStackFrame::GetPromiseIndex() const {
return is_promise_all_ ? offset_ : -1;
}
bool JSStackFrame::IsNative() {
return HasScript() && GetScript()->type() == Script::TYPE_NATIVE;
}

View File

@ -69,6 +69,9 @@ class StackFrameBase {
// Return 1-based column number, including column offset if first line.
virtual int GetColumnNumber() = 0;
// Returns index for Promise.all() async frames, or -1 for other frames.
virtual int GetPromiseIndex() const = 0;
virtual bool IsNative() = 0;
virtual bool IsToplevel() = 0;
virtual bool IsEval();
@ -109,6 +112,8 @@ class JSStackFrame : public StackFrameBase {
int GetLineNumber() override;
int GetColumnNumber() override;
int GetPromiseIndex() const override;
bool IsNative() override;
bool IsToplevel() override;
bool IsAsync() const override { return is_async_; }
@ -155,6 +160,8 @@ class WasmStackFrame : public StackFrameBase {
int GetLineNumber() override { return wasm_func_index_; }
int GetColumnNumber() override { return -1; }
int GetPromiseIndex() const override { return -1; }
bool IsNative() override { return false; }
bool IsToplevel() override { return false; }
bool IsAsync() const override { return false; }

View File

@ -9,13 +9,17 @@
Error.prepareStackTrace = (e, frames) => {
assertEquals(two, frames[0].getFunction());
assertEquals(two.name, frames[0].getFunctionName());
assertEquals(null, frames[0].getPromiseIndex());
assertFalse(frames[0].isAsync());
assertEquals(Promise.all, frames[1].getFunction());
assertEquals(0, frames[1].getPromiseIndex());
assertTrue(frames[1].isAsync());
assertTrue(frames[1].isPromiseAll());
assertEquals(one, frames[2].getFunction());
assertEquals(one.name, frames[2].getFunctionName());
assertEquals(null, frames[2].getPromiseIndex());
assertTrue(frames[2].isAsync());
assertFalse(frames[2].isPromiseAll());
return frames;
};