Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 5db8321db414e78a8f9eb8687511cd22c2103247..9078fad2ff4738ffb51d1a7cddd88d7957a63fa3 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -23408,6 +23408,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->kWithOffset)); |
+ 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->kWithOffset)); |
+ 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->kWithOffset)); |
+ 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->kWithOffset)); |
+ 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->kWithOffset)); |
+ |
+ // Without offset. |
+ |
+ // Behave as if 0 was passed if position is negative. |
+ CHECK(script1->GetPositionInfo(-1, &info, script1->kNoOffset)); |
+ 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->kNoOffset)); |
+ 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->kNoOffset)); |
+ 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->kNoOffset)); |
+ 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->kNoOffset)); |
+} |
+ |
void CheckMagicComments(Local<Script> script, const char* expected_source_url, |
const char* expected_source_mapping_url) { |
if (expected_source_url != NULL) { |