Commit fee23365 authored by henrika's avatar henrika Committed by V8 LUCI CQ

[api] Adds script column number to code-creation events in CodeEventLogger

Bug: v8:11043
Change-Id: I8cbdd8a5f68bdadbe7fc44414c6d46cdd57e6802
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3627512Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Henrik Andreasson <henrika@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80429}
parent 190fda57
......@@ -78,7 +78,13 @@ class V8_EXPORT UnboundScript {
* Returns zero based line number of the code_pos location in the script.
* -1 will be returned if no information available.
*/
int GetLineNumber(int code_pos);
int GetLineNumber(int code_pos = 0);
/**
* Returns zero based column number of the code_pos location in the script.
* -1 will be returned if no information available.
*/
int GetColumnNumber(int code_pos = 0);
static const int kNoScriptId = 0;
};
......
......@@ -2063,6 +2063,20 @@ int UnboundScript::GetLineNumber(int code_pos) {
}
}
int UnboundScript::GetColumnNumber(int code_pos) {
i::Handle<i::SharedFunctionInfo> obj =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
i::Isolate* i_isolate = obj->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
API_RCS_SCOPE(i_isolate, UnboundScript, GetColumnNumber);
if (obj->script().IsScript()) {
i::Handle<i::Script> script(i::Script::cast(obj->script()), i_isolate);
return i::Script::GetColumnNumber(script, code_pos);
} else {
return -1;
}
}
Local<Value> UnboundScript::GetScriptName() {
i::Handle<i::SharedFunctionInfo> obj =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
......
......@@ -50,6 +50,14 @@ int GetScriptLineNumber(const JitCodeEvent* event) {
1;
}
int GetScriptColumnNumber(const JitCodeEvent* event) {
auto sfi = GetSharedFunctionInfo(event);
return sfi.is_null()
? -1 // invalid sentinel number
: Script::cast(sfi.script()).GetColumnNumber(sfi.StartPosition()) +
1;
}
void Register() {
DCHECK(!TraceLoggingProviderEnabled(g_v8Provider, 0, 0));
TraceLoggingRegister(g_v8Provider);
......@@ -125,8 +133,7 @@ void EventHandler(const JitCodeEvent* event) {
(uint16_t)0, // MethodFlags
(uint16_t)0, // MethodAddressRangeId
(uint64_t)script_id, (uint32_t)GetScriptLineNumber(event),
(uint32_t)0, // Line & Column
method_name);
(uint32_t)GetScriptColumnNumber(event), method_name);
}
} // namespace ETWJITInterface
......
......@@ -261,6 +261,8 @@ void CodeEventLogger::CodeCreateEvent(LogEventsAndTags tag,
}
name_buffer_->AppendByte(':');
name_buffer_->AppendInt(line);
name_buffer_->AppendByte(':');
name_buffer_->AppendInt(column);
LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
}
......
......@@ -280,6 +280,7 @@ class RuntimeCallTimer final {
V(Uint32Array_New) \
V(Uint8Array_New) \
V(Uint8ClampedArray_New) \
V(UnboundScript_GetColumnNumber) \
V(UnboundScript_GetId) \
V(UnboundScript_GetLineNumber) \
V(UnboundScript_GetName) \
......
......@@ -218,6 +218,7 @@ v8_source_set("unittests_sources") {
"api/resource-constraints-unittest.cc",
"api/v8-maybe-unittest.cc",
"api/v8-object-unittest.cc",
"api/v8-script-unittest.cc",
"base/address-region-unittest.cc",
"base/atomic-utils-unittest.cc",
"base/bignum-unittest.cc",
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/v8-context.h"
#include "include/v8-function.h"
#include "include/v8-isolate.h"
#include "include/v8-local-handle.h"
#include "include/v8-primitive.h"
#include "include/v8-template.h"
#include "src/api/api.h"
#include "src/objects/objects-inl.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace {
using ScriptTest = TestWithContext;
namespace {
bool ValueEqualsString(v8::Isolate* isolate, Local<Value> lhs,
const char* rhs) {
CHECK(!lhs.IsEmpty());
CHECK(lhs->IsString());
String::Utf8Value utf8_lhs(isolate, lhs);
return strcmp(rhs, *utf8_lhs) == 0;
}
} // namespace
TEST_F(ScriptTest, UnboundScriptPosition) {
const char* url = "http://www.foo.com/foo.js";
v8::ScriptOrigin origin(isolate(), NewString(url), 13, 0);
v8::ScriptCompiler::Source script_source(NewString("var foo;"), origin);
Local<Script> script =
v8::ScriptCompiler::Compile(v8_context(), &script_source).ToLocalChecked();
EXPECT_TRUE(
ValueEqualsString(isolate(), script->GetUnboundScript()->GetScriptName(),
url));
Local<UnboundScript> unbound_script = script->GetUnboundScript();
int line_number = unbound_script->GetLineNumber();
EXPECT_EQ(13, line_number);
int column_number = unbound_script->GetColumnNumber();
EXPECT_EQ(0, column_number);
}
} // namespace
} // namespace v8
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