Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index b517bef1fd1eb2d463b0a11fee3ba5425a7033dd..9cdedc1923f989790a4925cee4d0d33cf8e18737 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -18910,6 +18910,62 @@ void JSDate::SetCachedFields(int64_t local_time_ms, DateCache* date_cache) { |
set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
} |
+namespace { |
+ |
+Script* ScriptFromJSValue(Object* in) { |
+ DCHECK(in->IsJSValue()); |
+ JSValue* jsvalue = JSValue::cast(in); |
+ DCHECK(jsvalue->value()->IsScript()); |
+ return Script::cast(jsvalue->value()); |
+} |
+ |
+} // namespace |
+ |
+int JSMessageObject::GetLineNumber() const { |
+ if (start_position() == -1) return Message::kNoLineNumberInfo; |
+ |
+ Handle<Script> the_script = handle(ScriptFromJSValue(script())); |
+ |
+ Script::PositionInfo info; |
+ const Script::OffsetFlag offset_flag = Script::WITH_OFFSET; |
+ if (!the_script->GetPositionInfo(start_position(), &info, offset_flag)) { |
+ return Message::kNoLineNumberInfo; |
+ } |
+ |
+ return info.line + 1; |
+} |
+ |
+int JSMessageObject::GetColumnNumber() const { |
+ if (start_position() == -1) return -1; |
+ |
+ Handle<Script> the_script = handle(ScriptFromJSValue(script())); |
+ |
+ Script::PositionInfo info; |
+ const Script::OffsetFlag offset_flag = Script::WITH_OFFSET; |
+ if (!the_script->GetPositionInfo(start_position(), &info, offset_flag)) { |
+ return -1; |
+ } |
+ |
+ return info.column; // Note: No '+1' in contrast to GetLineNumber. |
+} |
+ |
+Handle<String> JSMessageObject::GetSourceLine() const { |
+ Handle<Script> the_script = handle(ScriptFromJSValue(script())); |
+ |
+ Isolate* isolate = the_script->GetIsolate(); |
+ if (the_script->type() == Script::TYPE_WASM) { |
+ return isolate->factory()->empty_string(); |
+ } |
+ |
+ Script::PositionInfo info; |
+ const Script::OffsetFlag offset_flag = Script::WITH_OFFSET; |
+ if (!the_script->GetPositionInfo(start_position(), &info, offset_flag)) { |
+ return isolate->factory()->empty_string(); |
+ } |
+ |
+ Handle<String> src = handle(String::cast(the_script->source()), isolate); |
+ return isolate->factory()->NewSubString(src, info.line_start, info.line_end); |
+} |
void JSArrayBuffer::Neuter() { |
CHECK(is_neuterable()); |