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

Side by Side Diff: src/source-position.cc

Issue 2684033007: Allow a ParseInfo without a script for %SetCode users (Closed)
Patch Set: nit Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/parsing/parse-info.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/source-position.h" 5 #include "src/source-position.h"
6 #include "src/compilation-info.h" 6 #include "src/compilation-info.h"
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12 std::ostream& operator<<(std::ostream& out, const SourcePositionInfo& pos) { 12 std::ostream& operator<<(std::ostream& out, const SourcePositionInfo& pos) {
13 Handle<SharedFunctionInfo> function(pos.function); 13 Handle<SharedFunctionInfo> function(pos.function);
14 Handle<Script> script(Script::cast(function->script())); 14 String* name = nullptr;
15 if (function->script()->IsScript()) {
16 Script* script = Script::cast(function->script());
17 if (script->name()->IsString()) {
18 name = String::cast(script->name());
19 }
20 }
15 out << "<"; 21 out << "<";
16 if (script->name()->IsString()) { 22 if (name != nullptr) {
17 out << String::cast(script->name())->ToCString(DISALLOW_NULLS).get(); 23 out << name->ToCString(DISALLOW_NULLS).get();
18 } else { 24 } else {
19 out << "unknown"; 25 out << "unknown";
20 } 26 }
21 out << ":" << pos.line + 1 << ":" << pos.column + 1 << ">"; 27 out << ":" << pos.line + 1 << ":" << pos.column + 1 << ">";
22 return out; 28 return out;
23 } 29 }
24 30
25 std::ostream& operator<<(std::ostream& out, 31 std::ostream& operator<<(std::ostream& out,
26 const std::vector<SourcePositionInfo>& stack) { 32 const std::vector<SourcePositionInfo>& stack) {
27 bool first = true; 33 bool first = true;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 pos = inl.position; 77 pos = inl.position;
72 } 78 }
73 Handle<SharedFunctionInfo> function( 79 Handle<SharedFunctionInfo> function(
74 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo())); 80 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo()));
75 stack.push_back(SourcePositionInfo(pos, function)); 81 stack.push_back(SourcePositionInfo(pos, function));
76 return stack; 82 return stack;
77 } 83 }
78 84
79 void SourcePosition::Print(std::ostream& out, 85 void SourcePosition::Print(std::ostream& out,
80 SharedFunctionInfo* function) const { 86 SharedFunctionInfo* function) const {
81 Script* script = Script::cast(function->script());
82 Object* source_name = script->name();
83 Script::PositionInfo pos; 87 Script::PositionInfo pos;
84 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET); 88 Object* source_name = nullptr;
89 if (function->script()->IsScript()) {
90 Script* script = Script::cast(function->script());
91 source_name = script->name();
92 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET);
93 }
85 out << "<"; 94 out << "<";
86 if (source_name->IsString()) { 95 if (source_name != nullptr && source_name->IsString()) {
87 out << String::cast(source_name) 96 out << String::cast(source_name)
88 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL) 97 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)
89 .get(); 98 .get();
90 } else { 99 } else {
91 out << "unknown"; 100 out << "unknown";
92 } 101 }
93 out << ":" << pos.line + 1 << ":" << pos.column + 1 << ">"; 102 out << ":" << pos.line + 1 << ":" << pos.column + 1 << ">";
94 } 103 }
95 104
96 void SourcePosition::Print(std::ostream& out, Code* code) const { 105 void SourcePosition::Print(std::ostream& out, Code* code) const {
(...skipping 13 matching lines...) Expand all
110 Print(out, function); 119 Print(out, function);
111 } 120 }
112 out << " inlined at "; 121 out << " inlined at ";
113 inl.position.Print(out, code); 122 inl.position.Print(out, code);
114 } 123 }
115 } 124 }
116 125
117 SourcePositionInfo::SourcePositionInfo(SourcePosition pos, 126 SourcePositionInfo::SourcePositionInfo(SourcePosition pos,
118 Handle<SharedFunctionInfo> f) 127 Handle<SharedFunctionInfo> f)
119 : position(pos), function(f) { 128 : position(pos), function(f) {
120 Handle<Script> script(Script::cast(function->script())); 129 if (function->script()->IsScript()) {
121 Script::PositionInfo info; 130 Handle<Script> script(Script::cast(function->script()));
122 if (Script::GetPositionInfo(script, pos.ScriptOffset(), &info, 131 Script::PositionInfo info;
123 Script::WITH_OFFSET)) { 132 if (Script::GetPositionInfo(script, pos.ScriptOffset(), &info,
124 line = info.line; 133 Script::WITH_OFFSET)) {
125 column = info.column; 134 line = info.line;
135 column = info.column;
136 }
126 } 137 }
127 } 138 }
128 139
129 } // namespace internal 140 } // namespace internal
130 } // namespace v8 141 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parse-info.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698