Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: V8: cherry-pick 86991d0587a1 #36254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.19',
'v8_embedder_string': '-node.20',

##### V8 defaults for Node.js #####

Expand Down
16 changes: 16 additions & 0 deletions deps/v8/src/builtins/builtins-callsite.cc
Expand Up @@ -53,6 +53,22 @@ BUILTIN(CallSitePrototypeGetColumnNumber) {
return PositiveNumberOrNull(it.Frame()->GetColumnNumber(), isolate);
}

BUILTIN(CallSitePrototypeGetEnclosingColumnNumber) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getEnclosingColumnNumber");
FrameArrayIterator it(isolate, GetFrameArray(isolate, recv),
GetFrameIndex(isolate, recv));
return PositiveNumberOrNull(it.Frame()->GetEnclosingColumnNumber(), isolate);
}

BUILTIN(CallSitePrototypeGetEnclosingLineNumber) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getEnclosingLineNumber");
FrameArrayIterator it(isolate, GetFrameArray(isolate, recv),
GetFrameIndex(isolate, recv));
return PositiveNumberOrNull(it.Frame()->GetEnclosingLineNumber(), isolate);
}

BUILTIN(CallSitePrototypeGetEvalOrigin) {
HandleScope scope(isolate);
CHECK_CALLSITE(recv, "getEvalOrigin");
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/src/builtins/builtins-definitions.h
Expand Up @@ -364,6 +364,8 @@ namespace internal {
\
/* CallSite */ \
CPP(CallSitePrototypeGetColumnNumber) \
CPP(CallSitePrototypeGetEnclosingColumnNumber) \
CPP(CallSitePrototypeGetEnclosingLineNumber) \
CPP(CallSitePrototypeGetEvalOrigin) \
CPP(CallSitePrototypeGetFileName) \
CPP(CallSitePrototypeGetFunction) \
Expand Down
46 changes: 46 additions & 0 deletions deps/v8/src/execution/messages.cc
Expand Up @@ -514,6 +514,26 @@ int JSStackFrame::GetColumnNumber() {
return kNone;
}

int JSStackFrame::GetEnclosingLineNumber() {
if (HasScript()) {
Handle<SharedFunctionInfo> shared = handle(function_->shared(), isolate_);
return Script::GetLineNumber(GetScript(),
shared->function_token_position()) + 1;
} else {
return kNone;
}
}

int JSStackFrame::GetEnclosingColumnNumber() {
if (HasScript()) {
Handle<SharedFunctionInfo> shared = handle(function_->shared(), isolate_);
return Script::GetColumnNumber(GetScript(),
shared->function_token_position()) + 1;
} else {
return kNone;
}
}

int JSStackFrame::GetPromiseIndex() const {
return (is_promise_all_ || is_promise_any_) ? offset_ : kNone;
}
Expand Down Expand Up @@ -602,6 +622,12 @@ int WasmStackFrame::GetPosition() const {

int WasmStackFrame::GetColumnNumber() { return GetModuleOffset(); }

int WasmStackFrame::GetEnclosingColumnNumber() {
const int function_offset =
GetWasmFunctionOffset(wasm_instance_->module(), wasm_func_index_);
return function_offset;
}

int WasmStackFrame::GetModuleOffset() const {
const int function_offset =
GetWasmFunctionOffset(wasm_instance_->module(), wasm_func_index_);
Expand Down Expand Up @@ -672,6 +698,26 @@ int AsmJsWasmStackFrame::GetColumnNumber() {
return Script::GetColumnNumber(script, GetPosition()) + 1;
}

int AsmJsWasmStackFrame::GetEnclosingLineNumber() {
DCHECK_LE(0, GetPosition());
Handle<Script> script(wasm_instance_->module_object().script(), isolate_);
DCHECK(script->IsUserJavaScript());
int byte_offset = GetSourcePosition(wasm_instance_->module(),
wasm_func_index_, 0,
is_at_number_conversion_);
return Script::GetLineNumber(script, byte_offset) + 1;
}

int AsmJsWasmStackFrame::GetEnclosingColumnNumber() {
DCHECK_LE(0, GetPosition());
Handle<Script> script(wasm_instance_->module_object().script(), isolate_);
DCHECK(script->IsUserJavaScript());
int byte_offset = GetSourcePosition(wasm_instance_->module(),
wasm_func_index_, 0,
is_at_number_conversion_);
return Script::GetColumnNumber(script, byte_offset) + 1;
}

FrameArrayIterator::FrameArrayIterator(Isolate* isolate,
Handle<FrameArray> array, int frame_ix)
: isolate_(isolate), array_(array), frame_ix_(frame_ix) {}
Expand Down
11 changes: 11 additions & 0 deletions deps/v8/src/execution/messages.h
Expand Up @@ -87,6 +87,9 @@ class StackFrameBase {
// Return 0-based Wasm function index. Returns -1 for non-Wasm frames.
virtual int GetWasmFunctionIndex();

virtual int GetEnclosingColumnNumber() = 0;
virtual int GetEnclosingLineNumber() = 0;

// Returns the index of the rejected promise in the Promise combinator input,
// or -1 if this frame is not a Promise combinator frame.
virtual int GetPromiseIndex() const = 0;
Expand Down Expand Up @@ -133,6 +136,9 @@ class JSStackFrame : public StackFrameBase {
int GetLineNumber() override;
int GetColumnNumber() override;

int GetEnclosingColumnNumber() override;
int GetEnclosingLineNumber() override;

int GetPromiseIndex() const override;

bool IsNative() override;
Expand Down Expand Up @@ -183,6 +189,8 @@ class WasmStackFrame : public StackFrameBase {
int GetPosition() const override;
int GetLineNumber() override { return 0; }
int GetColumnNumber() override;
int GetEnclosingColumnNumber() override;
int GetEnclosingLineNumber() override { return 0; }
int GetWasmFunctionIndex() override { return wasm_func_index_; }

int GetPromiseIndex() const override { return GetPosition(); }
Expand Down Expand Up @@ -231,6 +239,9 @@ class AsmJsWasmStackFrame : public WasmStackFrame {
int GetLineNumber() override;
int GetColumnNumber() override;

int GetEnclosingColumnNumber() override;
int GetEnclosingLineNumber() override;

private:
friend class FrameArrayIterator;
AsmJsWasmStackFrame() = default;
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/init/bootstrapper.cc
Expand Up @@ -4090,6 +4090,10 @@ void Genesis::InitializeCallSiteBuiltins() {

FunctionInfo infos[] = {
{"getColumnNumber", Builtins::kCallSitePrototypeGetColumnNumber},
{"getEnclosingColumnNumber",
Builtins::kCallSitePrototypeGetEnclosingColumnNumber},
{"getEnclosingLineNumber",
Builtins::kCallSitePrototypeGetEnclosingLineNumber},
{"getEvalOrigin", Builtins::kCallSitePrototypeGetEvalOrigin},
{"getFileName", Builtins::kCallSitePrototypeGetFileName},
{"getFunction", Builtins::kCallSitePrototypeGetFunction},
Expand Down
20 changes: 20 additions & 0 deletions deps/v8/test/mjsunit/stack-traces.js
Expand Up @@ -439,3 +439,23 @@ var constructor = new Error().stack[0].constructor;
assertThrows(() => constructor.call());
assertThrows(() => constructor.call(
null, {}, () => undefined, {valueOf() { return 0 }}, false));

// Test stack frames populated with line/column information for both call site
// and enclosing function:
Error.prepareStackTrace = function(e, frames) {
assertMatches(/stack-traces\.js/, frames[0].getFileName());
assertEquals(3, frames[0].getEnclosingColumnNumber());
assertEquals(11, frames[0].getColumnNumber());
assertTrue(frames[0].getEnclosingLineNumber() < frames[0].getLineNumber());
}
try {
function a() {
b();
}
function b() {
throw Error('hello world');
}
a();
} catch (err) {
err.stack;
}
15 changes: 15 additions & 0 deletions deps/v8/test/mjsunit/wasm/asm-wasm-stack.js
Expand Up @@ -154,3 +154,18 @@ function generateOverflowWasmFromAsmJs() {
['f', 135, 12] // --
]);
})();

(function EnclosingFunctionOffsets() {
const fun = generateWasmFromAsmJs(this, {throwFunc: throwException});
assertTrue(%IsWasmCode(fun));
let e = null;
try {
fun(0);
} catch (ex) {
e = ex;
}
assertEquals(68, e.stack[2].getLineNumber());
assertEquals(15, e.stack[2].getColumnNumber());
assertEquals(65, e.stack[2].getEnclosingLineNumber());
assertEquals(3, e.stack[2].getEnclosingColumnNumber());
})();