Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1091)

Unified Diff: test/cctest/test-api.cc

Issue 2002993002: Refactor script position calculation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index f3cd40b53ecd4d69a02bde14b012360f9b4ad18f..96717346ebf810cce554508752c9a81ef54709a4 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -23422,6 +23422,88 @@ TEST(ScriptNameAndLineNumber) {
CHECK_EQ(13, line_number);
}
+TEST(ScriptPositionInfo) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+ const char* url = "http://www.foo.com/foo.js";
+ v8::ScriptOrigin origin(v8_str(url), v8::Integer::New(isolate, 13));
+ v8::ScriptCompiler::Source script_source(v8_str("var foo;\n"
+ "var bar;\n"
+ "var fisk = foo + bar;\n"),
+ origin);
+ Local<Script> script =
+ v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked();
+
+ i::Handle<i::SharedFunctionInfo> obj = i::Handle<i::SharedFunctionInfo>::cast(
+ v8::Utils::OpenHandle(*script->GetUnboundScript()));
+ CHECK(obj->script()->IsScript());
+
+ i::Handle<i::Script> script1(i::Script::cast(obj->script()));
+
+ v8::internal::Script::PositionInfo info;
+
+ // With offset.
+
+ // Behave as if 0 was passed if position is negative.
+ CHECK(script1->GetPositionInfo(-1, &info, script1->WITH_OFFSET));
+ CHECK_EQ(13, info.line);
+ CHECK_EQ(0, info.column);
+ CHECK_EQ(0, info.line_start);
+ CHECK_EQ(8, info.line_end);
+
+ CHECK(script1->GetPositionInfo(0, &info, script1->WITH_OFFSET));
+ CHECK_EQ(13, info.line);
+ CHECK_EQ(0, info.column);
+ CHECK_EQ(0, info.line_start);
+ CHECK_EQ(8, info.line_end);
+
+ CHECK(script1->GetPositionInfo(8, &info, script1->WITH_OFFSET));
+ CHECK_EQ(13, info.line);
+ CHECK_EQ(8, info.column);
+ CHECK_EQ(0, info.line_start);
+ CHECK_EQ(8, info.line_end);
+
+ CHECK(script1->GetPositionInfo(9, &info, script1->WITH_OFFSET));
+ CHECK_EQ(14, info.line);
+ CHECK_EQ(0, info.column);
+ CHECK_EQ(9, info.line_start);
+ CHECK_EQ(17, info.line_end);
+
+ // Fail when position is larger than script size.
+ CHECK(!script1->GetPositionInfo(220384, &info, script1->WITH_OFFSET));
+
+ // Without offset.
+
+ // Behave as if 0 was passed if position is negative.
+ CHECK(script1->GetPositionInfo(-1, &info, script1->NO_OFFSET));
+ CHECK_EQ(0, info.line);
+ CHECK_EQ(0, info.column);
+ CHECK_EQ(0, info.line_start);
+ CHECK_EQ(8, info.line_end);
+
+ CHECK(script1->GetPositionInfo(0, &info, script1->NO_OFFSET));
+ CHECK_EQ(0, info.line);
+ CHECK_EQ(0, info.column);
+ CHECK_EQ(0, info.line_start);
+ CHECK_EQ(8, info.line_end);
+
+ CHECK(script1->GetPositionInfo(8, &info, script1->NO_OFFSET));
+ CHECK_EQ(0, info.line);
+ CHECK_EQ(8, info.column);
+ CHECK_EQ(0, info.line_start);
+ CHECK_EQ(8, info.line_end);
+
+ CHECK(script1->GetPositionInfo(9, &info, script1->NO_OFFSET));
+ CHECK_EQ(1, info.line);
+ CHECK_EQ(0, info.column);
+ CHECK_EQ(9, info.line_start);
+ CHECK_EQ(17, info.line_end);
+
+ // Fail when position is larger than script size.
+ CHECK(!script1->GetPositionInfo(220384, &info, script1->NO_OFFSET));
+}
+
void CheckMagicComments(Local<Script> script, const char* expected_source_url,
const char* expected_source_mapping_url) {
if (expected_source_url != NULL) {
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698