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

Unified Diff: src/objects.cc

Issue 2224973002: Move remaining Message functions to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 4 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/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698