v8/test/unittests/api/v8-script-unittest.cc
henrika fee2336535 [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/+/3627512
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Henrik Andreasson <henrika@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80429}
2022-05-09 14:29:24 +00:00

52 lines
1.5 KiB
C++

// 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