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

Side by Side Diff: src/isolate.cc

Issue 2806373005: [v8] v8::StackTrace::AsArray returns correct array (Closed)
Patch Set: addressed comments Created 3 years, 8 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/api.cc ('k') | test/cctest/test-api.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 Handle<Name> key_detailed = factory()->detailed_stack_trace_symbol(); 648 Handle<Name> key_detailed = factory()->detailed_stack_trace_symbol();
649 Handle<Object> stack_trace = 649 Handle<Object> stack_trace =
650 JSReceiver::GetDataProperty(error_object, key_detailed); 650 JSReceiver::GetDataProperty(error_object, key_detailed);
651 if (stack_trace->IsJSArray()) return Handle<JSArray>::cast(stack_trace); 651 if (stack_trace->IsJSArray()) return Handle<JSArray>::cast(stack_trace);
652 return Handle<JSArray>(); 652 return Handle<JSArray>();
653 } 653 }
654 654
655 655
656 class CaptureStackTraceHelper { 656 class CaptureStackTraceHelper {
657 public: 657 public:
658 CaptureStackTraceHelper(Isolate* isolate, 658 explicit CaptureStackTraceHelper(Isolate* isolate) : isolate_(isolate) {}
659 StackTrace::StackTraceOptions options)
660 : isolate_(isolate), options_(options) {}
661 659
662 Handle<StackFrameInfo> NewStackFrameObject(FrameSummary& summ) { 660 Handle<StackFrameInfo> NewStackFrameObject(FrameSummary& summ) {
663 if (summ.IsJavaScript()) return NewStackFrameObject(summ.AsJavaScript()); 661 if (summ.IsJavaScript()) return NewStackFrameObject(summ.AsJavaScript());
664 if (summ.IsWasm()) return NewStackFrameObject(summ.AsWasm()); 662 if (summ.IsWasm()) return NewStackFrameObject(summ.AsWasm());
665 UNREACHABLE(); 663 UNREACHABLE();
666 return factory()->NewStackFrameInfo(); 664 return factory()->NewStackFrameInfo();
667 } 665 }
668 666
669 Handle<StackFrameInfo> NewStackFrameObject( 667 Handle<StackFrameInfo> NewStackFrameObject(
670 const FrameSummary::JavaScriptFrameSummary& summ) { 668 const FrameSummary::JavaScriptFrameSummary& summ) {
671 Handle<StackFrameInfo> frame = factory()->NewStackFrameInfo(); 669 Handle<StackFrameInfo> frame = factory()->NewStackFrameInfo();
672 Handle<Script> script = Handle<Script>::cast(summ.script()); 670 Handle<Script> script = Handle<Script>::cast(summ.script());
673 if (options_ & StackTrace::kLineNumber) { 671 Script::PositionInfo info;
674 Script::PositionInfo info; 672 bool valid_pos = Script::GetPositionInfo(script, summ.SourcePosition(),
675 bool valid_pos = Script::GetPositionInfo(script, summ.SourcePosition(), 673 &info, Script::WITH_OFFSET);
676 &info, Script::WITH_OFFSET); 674 if (valid_pos) {
677 if (valid_pos) { 675 frame->set_line_number(info.line + 1);
678 frame->set_line_number(info.line + 1); 676 frame->set_column_number(info.column + 1);
679 if (options_ & StackTrace::kColumnOffset) {
680 frame->set_column_number(info.column + 1);
681 }
682 }
683 } 677 }
684 678 frame->set_script_id(script->id());
685 if (options_ & StackTrace::kScriptId) frame->set_script_id(script->id()); 679 frame->set_script_name(script->name());
686 if (options_ & StackTrace::kScriptName) { 680 frame->set_script_name_or_source_url(script->GetNameOrSourceURL());
687 frame->set_script_name(script->name()); 681 frame->set_is_eval(script->compilation_type() ==
688 } 682 Script::COMPILATION_TYPE_EVAL);
689 if (options_ & StackTrace::kScriptNameOrSourceURL) { 683 Handle<String> function_name = summ.FunctionName();
690 frame->set_script_name_or_source_url(script->GetNameOrSourceURL()); 684 frame->set_function_name(*function_name);
691 } 685 frame->set_is_constructor(summ.is_constructor());
692 if (options_ & StackTrace::kIsEval) {
693 frame->set_is_eval(script->compilation_type() ==
694 Script::COMPILATION_TYPE_EVAL);
695 }
696 if (options_ & StackTrace::kFunctionName) {
697 Handle<String> name = summ.FunctionName();
698 frame->set_function_name(*name);
699 }
700 if (options_ & StackTrace::kIsConstructor) {
701 frame->set_is_constructor(summ.is_constructor());
702 }
703 frame->set_is_wasm(false); 686 frame->set_is_wasm(false);
704 return frame; 687 return frame;
705 } 688 }
706 689
707 Handle<StackFrameInfo> NewStackFrameObject( 690 Handle<StackFrameInfo> NewStackFrameObject(
708 const FrameSummary::WasmFrameSummary& summ) { 691 const FrameSummary::WasmFrameSummary& summ) {
709 Handle<StackFrameInfo> info = factory()->NewStackFrameInfo(); 692 Handle<StackFrameInfo> info = factory()->NewStackFrameInfo();
710 693
711 if (options_ & StackTrace::kFunctionName) { 694 Handle<WasmCompiledModule> compiled_module(
712 Handle<WasmCompiledModule> compiled_module( 695 summ.wasm_instance()->compiled_module(), isolate_);
713 summ.wasm_instance()->compiled_module(), isolate_); 696 Handle<String> name = WasmCompiledModule::GetFunctionName(
714 Handle<String> name = WasmCompiledModule::GetFunctionName( 697 isolate_, compiled_module, summ.function_index());
715 isolate_, compiled_module, summ.function_index()); 698 info->set_function_name(*name);
716 info->set_function_name(*name);
717 }
718 // Encode the function index as line number (1-based). 699 // Encode the function index as line number (1-based).
719 if (options_ & StackTrace::kLineNumber) { 700 info->set_line_number(summ.function_index() + 1);
720 info->set_line_number(summ.function_index() + 1);
721 }
722 // Encode the byte offset as column (1-based). 701 // Encode the byte offset as column (1-based).
723 if (options_ & StackTrace::kColumnOffset) { 702 int position = summ.byte_offset();
724 int position = summ.byte_offset(); 703 // Make position 1-based.
725 // Make position 1-based. 704 if (position >= 0) ++position;
726 if (position >= 0) ++position; 705 info->set_column_number(position);
727 info->set_column_number(position); 706 info->set_script_id(summ.script()->id());
728 }
729 if (options_ & StackTrace::kScriptId) {
730 info->set_script_id(summ.script()->id());
731 }
732 info->set_is_wasm(true); 707 info->set_is_wasm(true);
733 return info; 708 return info;
734 } 709 }
735 710
736 private: 711 private:
737 inline Factory* factory() { return isolate_->factory(); } 712 inline Factory* factory() { return isolate_->factory(); }
738 713
739 Isolate* isolate_; 714 Isolate* isolate_;
740 StackTrace::StackTraceOptions options_;
741 }; 715 };
742 716
743 Handle<JSArray> Isolate::CaptureCurrentStackTrace( 717 Handle<JSArray> Isolate::CaptureCurrentStackTrace(
744 int frame_limit, StackTrace::StackTraceOptions options) { 718 int frame_limit, StackTrace::StackTraceOptions options) {
745 DisallowJavascriptExecution no_js(this); 719 DisallowJavascriptExecution no_js(this);
746 CaptureStackTraceHelper helper(this, options); 720 CaptureStackTraceHelper helper(this);
747 721
748 // Ensure no negative values. 722 // Ensure no negative values.
749 int limit = Max(frame_limit, 0); 723 int limit = Max(frame_limit, 0);
750 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); 724 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit);
751 Handle<FixedArray> stack_trace_elems( 725 Handle<FixedArray> stack_trace_elems(
752 FixedArray::cast(stack_trace->elements()), this); 726 FixedArray::cast(stack_trace->elements()), this);
753 727
754 int frames_seen = 0; 728 int frames_seen = 0;
755 for (StackTraceFrameIterator it(this); !it.done() && (frames_seen < limit); 729 for (StackTraceFrameIterator it(this); !it.done() && (frames_seen < limit);
756 it.Advance()) { 730 it.Advance()) {
(...skipping 2986 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 // Then check whether this scope intercepts. 3717 // Then check whether this scope intercepts.
3744 if ((flag & intercept_mask_)) { 3718 if ((flag & intercept_mask_)) {
3745 intercepted_flags_ |= flag; 3719 intercepted_flags_ |= flag;
3746 return true; 3720 return true;
3747 } 3721 }
3748 return false; 3722 return false;
3749 } 3723 }
3750 3724
3751 } // namespace internal 3725 } // namespace internal
3752 } // namespace v8 3726 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698