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) { |