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

Side by Side Diff: src/messages.cc

Issue 2404253002: [wasm] Provide better stack traces for asm.js code (Closed)
Patch Set: Address titzer's comments Created 4 years, 2 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/messages.h ('k') | src/objects.h » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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/messages.h" 5 #include "src/messages.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/execution.h" 10 #include "src/execution.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 Handle<String> result = JSFunction::GetName(function_); 204 Handle<String> result = JSFunction::GetName(function_);
205 if (result->length() != 0) return result; 205 if (result->length() != 0) return result;
206 206
207 if (HasScript() && 207 if (HasScript() &&
208 GetScript()->compilation_type() == Script::COMPILATION_TYPE_EVAL) { 208 GetScript()->compilation_type() == Script::COMPILATION_TYPE_EVAL) {
209 return isolate_->factory()->eval_string(); 209 return isolate_->factory()->eval_string();
210 } 210 }
211 return isolate_->factory()->null_value(); 211 return isolate_->factory()->null_value();
212 } 212 }
213 213
214 Handle<Object> JSStackFrame::GetScriptNameOrSourceUrl() {
215 if (!HasScript()) return isolate_->factory()->null_value();
216 Handle<Script> script = GetScript();
217 Object* source_url = script->source_url();
218 return (source_url->IsString()) ? handle(source_url, isolate_)
219 : handle(script->name(), isolate_);
220 }
221
222 namespace { 214 namespace {
223 215
224 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, 216 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name,
225 Handle<JSFunction> fun, 217 Handle<JSFunction> fun,
226 LookupIterator::Configuration config) { 218 LookupIterator::Configuration config) {
227 LookupIterator iter = 219 LookupIterator iter =
228 LookupIterator::PropertyOrElement(isolate, obj, name, config); 220 LookupIterator::PropertyOrElement(isolate, obj, name, config);
229 if (iter.state() == LookupIterator::DATA) { 221 if (iter.state() == LookupIterator::DATA) {
230 return iter.GetDataValue().is_identical_to(fun); 222 return iter.GetDataValue().is_identical_to(fun);
231 } else if (iter.state() == LookupIterator::ACCESSOR) { 223 } else if (iter.state() == LookupIterator::ACCESSOR) {
232 Handle<Object> accessors = iter.GetAccessors(); 224 Handle<Object> accessors = iter.GetAccessors();
233 if (accessors->IsAccessorPair()) { 225 if (accessors->IsAccessorPair()) {
234 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); 226 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors);
235 return pair->getter() == *fun || pair->setter() == *fun; 227 return pair->getter() == *fun || pair->setter() == *fun;
236 } 228 }
237 } 229 }
238 return false; 230 return false;
239 } 231 }
240 232
233 Handle<Object> ScriptNameOrSourceUrl(Handle<Script> script, Isolate* isolate) {
234 Object* name_or_url = script->source_url();
235 if (!name_or_url->IsString()) name_or_url = script->name();
236 return handle(name_or_url, isolate);
237 }
238
241 } // namespace 239 } // namespace
242 240
241 Handle<Object> JSStackFrame::GetScriptNameOrSourceUrl() {
242 if (!HasScript()) return isolate_->factory()->null_value();
243 return ScriptNameOrSourceUrl(GetScript(), isolate_);
244 }
245
243 Handle<Object> JSStackFrame::GetMethodName() { 246 Handle<Object> JSStackFrame::GetMethodName() {
244 if (receiver_->IsNull(isolate_) || receiver_->IsUndefined(isolate_)) { 247 if (receiver_->IsNull(isolate_) || receiver_->IsUndefined(isolate_)) {
245 return isolate_->factory()->null_value(); 248 return isolate_->factory()->null_value();
246 } 249 }
247 250
248 Handle<JSReceiver> receiver = 251 Handle<JSReceiver> receiver =
249 Object::ToObject(isolate_, receiver_).ToHandleChecked(); 252 Object::ToObject(isolate_, receiver_).ToHandleChecked();
250 if (!receiver->IsJSObject()) { 253 if (!receiver->IsJSObject()) {
251 return isolate_->factory()->null_value(); 254 return isolate_->factory()->null_value();
252 } 255 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 isolate_->factory()->constructor_string()); 451 isolate_->factory()->constructor_string());
449 return constructor.is_identical_to(function_); 452 return constructor.is_identical_to(function_);
450 } 453 }
451 454
452 namespace { 455 namespace {
453 456
454 bool IsNonEmptyString(Handle<Object> object) { 457 bool IsNonEmptyString(Handle<Object> object) {
455 return (object->IsString() && String::cast(*object)->length() > 0); 458 return (object->IsString() && String::cast(*object)->length() > 0);
456 } 459 }
457 460
458 void AppendFileLocation(Isolate* isolate, JSStackFrame* call_site, 461 void AppendFileLocation(Isolate* isolate, StackFrameBase* call_site,
459 IncrementalStringBuilder* builder) { 462 IncrementalStringBuilder* builder) {
460 if (call_site->IsNative()) { 463 if (call_site->IsNative()) {
461 builder->AppendCString("native"); 464 builder->AppendCString("native");
462 return; 465 return;
463 } 466 }
464 467
465 Handle<Object> file_name = call_site->GetScriptNameOrSourceUrl(); 468 Handle<Object> file_name = call_site->GetScriptNameOrSourceUrl();
466 if (!file_name->IsString() && call_site->IsEval()) { 469 if (!file_name->IsString() && call_site->IsEval()) {
467 Handle<Object> eval_origin = call_site->GetEvalOrigin(); 470 Handle<Object> eval_origin = call_site->GetEvalOrigin();
468 DCHECK(eval_origin->IsString()); 471 DCHECK(eval_origin->IsString());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 bool JSStackFrame::HasScript() const { 613 bool JSStackFrame::HasScript() const {
611 return function_->shared()->script()->IsScript(); 614 return function_->shared()->script()->IsScript();
612 } 615 }
613 616
614 Handle<Script> JSStackFrame::GetScript() const { 617 Handle<Script> JSStackFrame::GetScript() const {
615 return handle(Script::cast(function_->shared()->script()), isolate_); 618 return handle(Script::cast(function_->shared()->script()), isolate_);
616 } 619 }
617 620
618 void WasmStackFrame::FromFrameArray(Isolate* isolate, Handle<FrameArray> array, 621 void WasmStackFrame::FromFrameArray(Isolate* isolate, Handle<FrameArray> array,
619 int frame_ix) { 622 int frame_ix) {
620 DCHECK(array->IsWasmFrame(frame_ix)); 623 // This function is called for both wasm and asm.js->wasm frames.
624 DCHECK(array->IsWasmFrame(frame_ix) || array->IsAsmJsWasmFrame(frame_ix));
621 isolate_ = isolate; 625 isolate_ = isolate;
622 wasm_obj_ = handle(array->WasmObject(frame_ix), isolate); 626 wasm_obj_ = handle(array->WasmObject(frame_ix), isolate);
623 wasm_func_index_ = array->WasmFunctionIndex(frame_ix)->value(); 627 wasm_func_index_ = array->WasmFunctionIndex(frame_ix)->value();
624 code_ = handle(array->Code(frame_ix), isolate); 628 code_ = handle(array->Code(frame_ix), isolate);
625 offset_ = array->Offset(frame_ix)->value(); 629 offset_ = array->Offset(frame_ix)->value();
626 } 630 }
627 631
628 Handle<Object> WasmStackFrame::GetFunction() const { 632 Handle<Object> WasmStackFrame::GetFunction() const {
629 Handle<Object> obj(Smi::FromInt(wasm_func_index_), isolate_); 633 Handle<Object> obj(Smi::FromInt(wasm_func_index_), isolate_);
630 return obj; 634 return obj;
(...skipping 29 matching lines...) Expand all
660 } 664 }
661 665
662 int WasmStackFrame::GetPosition() const { 666 int WasmStackFrame::GetPosition() const {
663 return (offset_ < 0) ? (-1 - offset_) : code_->SourcePosition(offset_); 667 return (offset_ < 0) ? (-1 - offset_) : code_->SourcePosition(offset_);
664 } 668 }
665 669
666 Handle<Object> WasmStackFrame::Null() const { 670 Handle<Object> WasmStackFrame::Null() const {
667 return isolate_->factory()->null_value(); 671 return isolate_->factory()->null_value();
668 } 672 }
669 673
674 Handle<Object> AsmJsWasmStackFrame::GetReceiver() const {
675 return isolate_->global_proxy();
676 }
677
678 Handle<Object> AsmJsWasmStackFrame::GetFunction() const {
679 // TODO(clemensh): Return lazily created JSFunction.
680 return Null();
681 }
682
683 Handle<Object> AsmJsWasmStackFrame::GetFileName() {
684 Handle<Script> script =
685 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_));
686 return handle(script->name(), isolate_);
687 }
688
689 Handle<Object> AsmJsWasmStackFrame::GetFunctionName() {
690 return wasm::GetWasmFunctionNameOrNull(isolate_, wasm_obj_, wasm_func_index_);
691 }
692
693 Handle<Object> AsmJsWasmStackFrame::GetScriptNameOrSourceUrl() {
694 Handle<Script> script =
695 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_));
696 return ScriptNameOrSourceUrl(script, isolate_);
697 }
698
699 int AsmJsWasmStackFrame::GetPosition() const {
700 DCHECK_LE(0, offset_);
701 int byte_offset = code_->SourcePosition(offset_);
702 return wasm::GetAsmWasmSourcePosition(Handle<JSObject>::cast(wasm_obj_),
703 wasm_func_index_, byte_offset);
704 }
705
706 int AsmJsWasmStackFrame::GetLineNumber() {
707 DCHECK_LE(0, GetPosition());
708 Handle<Script> script =
709 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_));
710 return Script::GetLineNumber(script, GetPosition()) + 1;
711 }
712
713 int AsmJsWasmStackFrame::GetColumnNumber() {
714 DCHECK_LE(0, GetPosition());
715 Handle<Script> script =
716 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_));
717 return Script::GetColumnNumber(script, GetPosition()) + 1;
718 }
719
720 MaybeHandle<String> AsmJsWasmStackFrame::ToString() {
721 // The string should look exactly as the respective javascript frame string.
722 // Keep this method in line to JSStackFrame::ToString().
723
724 IncrementalStringBuilder builder(isolate_);
725
726 Handle<Object> function_name = GetFunctionName();
727
728 if (IsNonEmptyString(function_name)) {
729 builder.AppendString(Handle<String>::cast(function_name));
730 builder.AppendCString(" (");
731 }
732
733 AppendFileLocation(isolate_, this, &builder);
734
735 if (IsNonEmptyString(function_name)) builder.AppendCString(")");
736
737 RETURN_RESULT(isolate_, builder.Finish(), String);
738 }
739
670 FrameArrayIterator::FrameArrayIterator(Isolate* isolate, 740 FrameArrayIterator::FrameArrayIterator(Isolate* isolate,
671 Handle<FrameArray> array, int frame_ix) 741 Handle<FrameArray> array, int frame_ix)
672 : isolate_(isolate), array_(array), next_frame_ix_(frame_ix) {} 742 : isolate_(isolate), array_(array), next_frame_ix_(frame_ix) {}
673 743
674 bool FrameArrayIterator::HasNext() const { 744 bool FrameArrayIterator::HasNext() const {
675 return (next_frame_ix_ < array_->FrameCount()); 745 return (next_frame_ix_ < array_->FrameCount());
676 } 746 }
677 747
678 void FrameArrayIterator::Next() { next_frame_ix_++; } 748 void FrameArrayIterator::Next() { next_frame_ix_++; }
679 749
680 StackFrameBase* FrameArrayIterator::Frame() { 750 StackFrameBase* FrameArrayIterator::Frame() {
681 DCHECK(HasNext()); 751 DCHECK(HasNext());
682 const int flags = array_->Flags(next_frame_ix_)->value(); 752 const int flags = array_->Flags(next_frame_ix_)->value();
683 const bool is_js_frame = (flags & FrameArray::kIsWasmFrame) == 0; 753 switch (flags & (FrameArray::kIsWasmFrame | FrameArray::kIsAsmJsWasmFrame)) {
684 if (is_js_frame) { 754 case 0:
685 js_frame_.FromFrameArray(isolate_, array_, next_frame_ix_); 755 // JavaScript Frame.
686 return &js_frame_; 756 js_frame_.FromFrameArray(isolate_, array_, next_frame_ix_);
687 } else { 757 return &js_frame_;
688 wasm_frame_.FromFrameArray(isolate_, array_, next_frame_ix_); 758 case FrameArray::kIsWasmFrame:
689 return &wasm_frame_; 759 // Wasm Frame;
760 wasm_frame_.FromFrameArray(isolate_, array_, next_frame_ix_);
761 return &wasm_frame_;
762 case FrameArray::kIsAsmJsWasmFrame:
763 // Asm.js Wasm Frame:
764 asm_wasm_frame_.FromFrameArray(isolate_, array_, next_frame_ix_);
765 return &asm_wasm_frame_;
766 default:
767 UNREACHABLE();
768 return nullptr;
690 } 769 }
691 } 770 }
692 771
693 namespace { 772 namespace {
694 773
695 MaybeHandle<Object> ConstructCallSite(Isolate* isolate, 774 MaybeHandle<Object> ConstructCallSite(Isolate* isolate,
696 Handle<FrameArray> frame_array, 775 Handle<FrameArray> frame_array,
697 int frame_index) { 776 int frame_index) {
698 Handle<JSFunction> target = 777 Handle<JSFunction> target =
699 handle(isolate->native_context()->callsite_function(), isolate); 778 handle(isolate->native_context()->callsite_function(), isolate);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 DCHECK(mode != SKIP_UNTIL_SEEN); 1178 DCHECK(mode != SKIP_UNTIL_SEEN);
1100 1179
1101 Handle<Object> no_caller; 1180 Handle<Object> no_caller;
1102 Handle<String> msg = FormatMessage(isolate, template_index, arg0, arg1, arg2); 1181 Handle<String> msg = FormatMessage(isolate, template_index, arg0, arg1, arg2);
1103 return ErrorUtils::Construct(isolate, constructor, constructor, msg, mode, 1182 return ErrorUtils::Construct(isolate, constructor, constructor, msg, mode,
1104 no_caller, false); 1183 no_caller, false);
1105 } 1184 }
1106 1185
1107 } // namespace internal 1186 } // namespace internal
1108 } // namespace v8 1187 } // namespace v8
OLDNEW
« no previous file with comments | « src/messages.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698