Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 } | 663 } |
| 661 | 664 |
| 662 int WasmStackFrame::GetPosition() const { | 665 int WasmStackFrame::GetPosition() const { |
| 663 return (offset_ < 0) ? (-1 - offset_) : code_->SourcePosition(offset_); | 666 return (offset_ < 0) ? (-1 - offset_) : code_->SourcePosition(offset_); |
| 664 } | 667 } |
| 665 | 668 |
| 666 Handle<Object> WasmStackFrame::Null() const { | 669 Handle<Object> WasmStackFrame::Null() const { |
| 667 return isolate_->factory()->null_value(); | 670 return isolate_->factory()->null_value(); |
| 668 } | 671 } |
| 669 | 672 |
| 673 Handle<Object> AsmJsWasmStackFrame::GetReceiver() const { | |
| 674 return isolate_->global_object(); | |
|
jgruber
2016/10/11 19:07:40
As far I understand, the global object should neve
Clemens Hammacher
2016/10/12 07:37:18
You are right. Fixed it.
| |
| 675 } | |
| 676 | |
| 677 Handle<Object> AsmJsWasmStackFrame::GetFunction() const { | |
| 678 // TODO(clemensh): Return lazily created JSFunction. | |
| 679 return Null(); | |
| 680 } | |
| 681 | |
| 682 Handle<Object> AsmJsWasmStackFrame::GetFileName() { | |
| 683 Handle<Script> script = | |
| 684 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_)); | |
| 685 return handle(script->name(), isolate_); | |
| 686 } | |
| 687 | |
| 688 Handle<Object> AsmJsWasmStackFrame::GetFunctionName() { | |
| 689 return wasm::GetWasmFunctionNameOrNull(isolate_, wasm_obj_, wasm_func_index_); | |
| 690 } | |
| 691 | |
| 692 Handle<Object> AsmJsWasmStackFrame::GetScriptNameOrSourceUrl() { | |
| 693 Handle<Script> script = | |
| 694 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_)); | |
| 695 return ScriptNameOrSourceUrl(script, isolate_); | |
| 696 } | |
| 697 | |
| 698 int AsmJsWasmStackFrame::GetPosition() const { | |
| 699 DCHECK_LE(0, offset_); | |
| 700 int byte_offset = code_->SourcePosition(offset_); | |
| 701 return wasm::GetAsmWasmSourcePosition(Handle<JSObject>::cast(wasm_obj_), | |
| 702 wasm_func_index_, byte_offset); | |
| 703 } | |
| 704 | |
| 705 int AsmJsWasmStackFrame::GetLineNumber() { | |
| 706 DCHECK_LE(0, GetPosition()); | |
| 707 Handle<Script> script = | |
| 708 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_)); | |
| 709 return Script::GetLineNumber(script, GetPosition()) + 1; | |
| 710 } | |
| 711 | |
| 712 int AsmJsWasmStackFrame::GetColumnNumber() { | |
| 713 DCHECK_LE(0, GetPosition()); | |
| 714 Handle<Script> script = | |
| 715 wasm::GetAsmWasmScript(Handle<JSObject>::cast(wasm_obj_)); | |
| 716 return Script::GetColumnNumber(script, GetPosition()) + 1; | |
| 717 } | |
| 718 | |
| 719 MaybeHandle<String> AsmJsWasmStackFrame::ToString() { | |
| 720 // The string should look exactly as the respective javascript frame string. | |
| 721 // Keep this method in line to JSStackFrame::ToString(). | |
| 722 | |
| 723 IncrementalStringBuilder builder(isolate_); | |
| 724 | |
| 725 Handle<Object> function_name = GetFunctionName(); | |
| 726 | |
| 727 if (IsNonEmptyString(function_name)) { | |
| 728 builder.AppendString(Handle<String>::cast(function_name)); | |
| 729 builder.AppendCString(" ("); | |
| 730 } | |
| 731 | |
| 732 AppendFileLocation(isolate_, this, &builder); | |
| 733 | |
| 734 if (IsNonEmptyString(function_name)) builder.AppendCString(")"); | |
| 735 | |
| 736 RETURN_RESULT(isolate_, builder.Finish(), String); | |
| 737 } | |
| 738 | |
| 670 FrameArrayIterator::FrameArrayIterator(Isolate* isolate, | 739 FrameArrayIterator::FrameArrayIterator(Isolate* isolate, |
| 671 Handle<FrameArray> array, int frame_ix) | 740 Handle<FrameArray> array, int frame_ix) |
| 672 : isolate_(isolate), array_(array), next_frame_ix_(frame_ix) {} | 741 : isolate_(isolate), array_(array), next_frame_ix_(frame_ix) {} |
| 673 | 742 |
| 674 bool FrameArrayIterator::HasNext() const { | 743 bool FrameArrayIterator::HasNext() const { |
| 675 return (next_frame_ix_ < array_->FrameCount()); | 744 return (next_frame_ix_ < array_->FrameCount()); |
| 676 } | 745 } |
| 677 | 746 |
| 678 void FrameArrayIterator::Next() { next_frame_ix_++; } | 747 void FrameArrayIterator::Next() { next_frame_ix_++; } |
| 679 | 748 |
| 680 StackFrameBase* FrameArrayIterator::Frame() { | 749 StackFrameBase* FrameArrayIterator::Frame() { |
| 681 DCHECK(HasNext()); | 750 DCHECK(HasNext()); |
| 682 const int flags = array_->Flags(next_frame_ix_)->value(); | 751 const int flags = array_->Flags(next_frame_ix_)->value(); |
| 683 const bool is_js_frame = (flags & FrameArray::kIsWasmFrame) == 0; | 752 const bool is_js_frame = (flags & FrameArray::kIsWasmFrame) == 0; |
| 684 if (is_js_frame) { | 753 if (is_js_frame) { |
| 685 js_frame_.FromFrameArray(isolate_, array_, next_frame_ix_); | 754 js_frame_.FromFrameArray(isolate_, array_, next_frame_ix_); |
| 686 return &js_frame_; | 755 return &js_frame_; |
| 687 } else { | |
| 688 wasm_frame_.FromFrameArray(isolate_, array_, next_frame_ix_); | |
| 689 return &wasm_frame_; | |
| 690 } | 756 } |
| 757 const bool is_asm_wasm_frame = (flags & FrameArray::kIsAsmWasmFrame) != 0; | |
|
jgruber
2016/10/11 19:07:40
Can we make this a switch on flags & (kIsWasmFrame
Clemens Hammacher
2016/10/12 07:37:18
Done.
| |
| 758 if (is_asm_wasm_frame) { | |
| 759 asm_wasm_frame_.FromFrameArray(isolate_, array_, next_frame_ix_); | |
| 760 return &asm_wasm_frame_; | |
| 761 } | |
| 762 wasm_frame_.FromFrameArray(isolate_, array_, next_frame_ix_); | |
| 763 return &wasm_frame_; | |
| 691 } | 764 } |
| 692 | 765 |
| 693 namespace { | 766 namespace { |
| 694 | 767 |
| 695 MaybeHandle<Object> ConstructCallSite(Isolate* isolate, | 768 MaybeHandle<Object> ConstructCallSite(Isolate* isolate, |
| 696 Handle<FrameArray> frame_array, | 769 Handle<FrameArray> frame_array, |
| 697 int frame_index) { | 770 int frame_index) { |
| 698 Handle<JSFunction> target = | 771 Handle<JSFunction> target = |
| 699 handle(isolate->native_context()->callsite_function(), isolate); | 772 handle(isolate->native_context()->callsite_function(), isolate); |
| 700 | 773 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 DCHECK(mode != SKIP_UNTIL_SEEN); | 1172 DCHECK(mode != SKIP_UNTIL_SEEN); |
| 1100 | 1173 |
| 1101 Handle<Object> no_caller; | 1174 Handle<Object> no_caller; |
| 1102 Handle<String> msg = FormatMessage(isolate, template_index, arg0, arg1, arg2); | 1175 Handle<String> msg = FormatMessage(isolate, template_index, arg0, arg1, arg2); |
| 1103 return ErrorUtils::Construct(isolate, constructor, constructor, msg, mode, | 1176 return ErrorUtils::Construct(isolate, constructor, constructor, msg, mode, |
| 1104 no_caller, false); | 1177 no_caller, false); |
| 1105 } | 1178 } |
| 1106 | 1179 |
| 1107 } // namespace internal | 1180 } // namespace internal |
| 1108 } // namespace v8 | 1181 } // namespace v8 |
| OLD | NEW |