Changeset 147846 in webkit for trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
- Timestamp:
- Apr 6, 2013, 11:24:37 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
r147820 r147846 200 200 201 201 202 static CallFrame* getCallerInfo(JSGlobalData*, CallFrame*, unsigned& bytecodeOffset, CodeBlock*& callerOut);202 static CallFrame* getCallerInfo(JSGlobalData*, CallFrame*, int& lineNumber, unsigned& bytecodeOffset, CodeBlock*& callerOut); 203 203 204 204 // Returns the depth of the scope chain within a given call frame. … … 423 423 unsigned bytecodeOffset = 0; 424 424 int line = 0; 425 CodeBlock* callerCodeBlock = 0; 426 getCallerInfo(&callFrame->globalData(), callFrame, bytecodeOffset, callerCodeBlock); 427 line = callerCodeBlock->lineNumberForBytecodeOffset(bytecodeOffset); 425 CodeBlock* unusedCallerCodeBlock = 0; 426 getCallerInfo(&callFrame->globalData(), callFrame, line, bytecodeOffset, unusedCallerCodeBlock); 428 427 dataLogF("[ReturnVPC] | %10p | %d (line %d)\n", it, bytecodeOffset, line); 429 428 ++it; … … 509 508 if (callerFrame->hasHostCallFrameFlag()) 510 509 return false; 511 callFrame = getCallerInfo(&callFrame->globalData(), callFrame, bytecodeOffset, codeBlock); 510 int unusedLineNumber = 0; 511 callFrame = getCallerInfo(&callFrame->globalData(), callFrame, unusedLineNumber, bytecodeOffset, codeBlock); 512 512 return true; 513 513 } … … 565 565 } 566 566 567 static unsigned getBytecodeOffsetForCallFrame(CallFrame* callFrame) 568 { 567 static int getLineNumberForCallFrame(JSGlobalData* globalData, CallFrame* callFrame) 568 { 569 UNUSED_PARAM(globalData); 569 570 callFrame = callFrame->removeHostCallFrameFlag(); 570 571 CodeBlock* codeBlock = callFrame->codeBlock(); 571 572 if (!codeBlock) 572 return 0;573 #if ENABLE(JIT) 573 return -1; 574 #if ENABLE(JIT) || ENABLE(LLINT) 574 575 #if ENABLE(DFG_JIT) 575 576 if (codeBlock->getJITType() == JITCode::DFGJIT) 576 return codeBlock-> codeOrigin(callFrame->codeOriginIndexForDFG()).bytecodeIndex;577 #endif 578 return c allFrame->bytecodeOffsetForNonDFGCode();579 #endif 580 } 581 582 static CallFrame* getCallerInfo(JSGlobalData* globalData, CallFrame* callFrame, unsigned& bytecodeOffset, CodeBlock*& caller)577 return codeBlock->lineNumberForBytecodeOffset(codeBlock->codeOrigin(callFrame->codeOriginIndexForDFG()).bytecodeIndex); 578 #endif 579 return codeBlock->lineNumberForBytecodeOffset(callFrame->bytecodeOffsetForNonDFGCode()); 580 #endif 581 } 582 583 static CallFrame* getCallerInfo(JSGlobalData* globalData, CallFrame* callFrame, int& lineNumber, unsigned& bytecodeOffset, CodeBlock*& caller) 583 584 { 584 585 ASSERT_UNUSED(globalData, globalData); 585 586 bytecodeOffset = 0; 587 lineNumber = -1; 586 588 ASSERT(!callFrame->hasHostCallFrameFlag()); 587 589 CallFrame* callerFrame = callFrame->codeBlock() ? callFrame->trueCallerFrame() : callFrame->callerFrame()->removeHostCallFrameFlag(); … … 653 655 RELEASE_ASSERT(callerCodeBlock); 654 656 caller = callerCodeBlock; 657 lineNumber = callerCodeBlock->lineNumberForBytecodeOffset(bytecodeOffset); 655 658 return callerFrame; 656 659 } … … 678 681 } 679 682 680 unsigned StackFrame::line() 681 { 682 return codeBlock ? codeBlock->lineNumberForBytecodeOffset(bytecodeOffset) + lineOffset : 0; 683 } 684 685 unsigned StackFrame::column() 686 { 687 if (!code) 688 return 0; 689 int divot = 0; 690 int unusedStartOffset = 0; 691 int unusedEndOffset = 0; 692 expressionInfo(divot, unusedStartOffset, unusedEndOffset); 693 return code->charPositionToColumnNumber(divot); 694 } 695 696 void StackFrame::expressionInfo(int& divot, int& startOffset, int& endOffset) 697 { 698 codeBlock->expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset); 699 divot += startOffset; 700 } 701 702 String StackFrame::toString(CallFrame* callFrame) 703 { 704 StringBuilder traceBuild; 705 String functionName = friendlyFunctionName(callFrame); 706 String sourceURL = friendlySourceURL(); 707 traceBuild.append(functionName); 708 if (!sourceURL.isEmpty()) { 709 if (!functionName.isEmpty()) 710 traceBuild.append('@'); 711 traceBuild.append(sourceURL); 712 if (codeType != StackFrameNativeCode) { 713 traceBuild.append(':'); 714 traceBuild.appendNumber(line()); 715 } 716 } 717 return traceBuild.toString().impl(); 718 } 719 720 void Interpreter::getStackTrace(JSGlobalData* globalData, Vector<StackFrame>& results, size_t maxStackSize) 683 void Interpreter::getStackTrace(JSGlobalData* globalData, Vector<StackFrame>& results) 721 684 { 722 685 CallFrame* callFrame = globalData->topCallFrame->removeHostCallFrameFlag(); 723 686 if (!callFrame || callFrame == CallFrame::noCaller()) 724 687 return; 725 unsigned bytecodeOffset = getBytecodeOffsetForCallFrame(callFrame); 688 int line = getLineNumberForCallFrame(globalData, callFrame); 689 726 690 callFrame = callFrame->trueCallFrameFromVMCode(); 727 691 if (!callFrame) 728 692 return; 729 CodeBlock* callerCodeBlock = callFrame->codeBlock(); 730 731 while (callFrame && callFrame != CallFrame::noCaller() && maxStackSize--) { 693 694 while (callFrame && callFrame != CallFrame::noCaller()) { 732 695 String sourceURL; 733 if (call erCodeBlock) {696 if (callFrame->codeBlock()) { 734 697 sourceURL = getSourceURLFromCallFrame(callFrame); 735 StackFrame s = { 736 Strong<JSObject>(*globalData, callFrame->callee()), 737 getStackFrameCodeType(callFrame), 738 Strong<ExecutableBase>(*globalData, callerCodeBlock->ownerExecutable()), 739 Strong<UnlinkedCodeBlock>(*globalData, callerCodeBlock->unlinkedCodeBlock()), 740 callerCodeBlock->source(), 741 callerCodeBlock->ownerExecutable()->lineNo(), 742 callerCodeBlock->sourceOffset(), 743 bytecodeOffset, 744 sourceURL 745 }; 698 StackFrame s = { Strong<JSObject>(*globalData, callFrame->callee()), getStackFrameCodeType(callFrame), Strong<ExecutableBase>(*globalData, callFrame->codeBlock()->ownerExecutable()), line, sourceURL}; 746 699 results.append(s); 747 700 } else { 748 StackFrame s = { Strong<JSObject>(*globalData, callFrame->callee()), StackFrameNativeCode, Strong<ExecutableBase>(), Strong<UnlinkedCodeBlock>(), 0, 0, 0, 0, String()};701 StackFrame s = { Strong<JSObject>(*globalData, callFrame->callee()), StackFrameNativeCode, Strong<ExecutableBase>(), -1, String()}; 749 702 results.append(s); 750 703 } 751 callFrame = getCallerInfo(globalData, callFrame, bytecodeOffset, callerCodeBlock); 752 } 753 } 754 755 void Interpreter::addStackTraceIfNecessary(CallFrame* callFrame, JSValue error) 704 unsigned unusedBytecodeOffset = 0; 705 CodeBlock* unusedCallerCodeBlock = 0; 706 callFrame = getCallerInfo(globalData, callFrame, line, unusedBytecodeOffset, unusedCallerCodeBlock); 707 } 708 } 709 710 void Interpreter::addStackTraceIfNecessary(CallFrame* callFrame, JSObject* error) 756 711 { 757 712 JSGlobalData* globalData = &callFrame->globalData(); 758 713 ASSERT(callFrame == globalData->topCallFrame || callFrame == callFrame->lexicalGlobalObject()->globalExec() || callFrame == callFrame->dynamicGlobalObject()->globalExec()); 714 if (error->hasProperty(callFrame, globalData->propertyNames->stack)) 715 return; 759 716 760 717 Vector<StackFrame> stackTrace; 761 718 getStackTrace(&callFrame->globalData(), stackTrace); 762 719 763 if (stackTrace.isEmpty() || !error.isObject())720 if (stackTrace.isEmpty()) 764 721 return; 765 JSObject* errorObject = asObject(error);722 766 723 JSGlobalObject* globalObject = 0; 767 724 if (isTerminatedExecutionException(error) || isInterruptedExecutionException(error)) 768 725 globalObject = globalData->dynamicGlobalObject; 769 726 else 770 globalObject = error Object->globalObject();727 globalObject = error->globalObject(); 771 728 772 729 // FIXME: JSStringJoiner could be more efficient than StringBuilder here. … … 777 734 builder.append('\n'); 778 735 } 779 780 if (errorObject->hasProperty(callFrame, globalData->propertyNames->stack)) 781 return; 782 errorObject->putDirect(*globalData, globalData->propertyNames->stack, jsString(globalData, builder.toString()), ReadOnly | DontDelete); 736 737 error->putDirect(*globalData, globalData->propertyNames->stack, jsString(globalData, builder.toString()), ReadOnly | DontDelete); 783 738 } 784 739 … … 1423 1378 return jsNull(); 1424 1379 1380 int lineNumber; 1425 1381 unsigned bytecodeOffset; 1426 1382 CodeBlock* unusedCallerCodeBlock = 0; 1427 CallFrame* callerFrame = getCallerInfo(&callFrame->globalData(), functionCallFrame, bytecodeOffset, unusedCallerCodeBlock);1383 CallFrame* callerFrame = getCallerInfo(&callFrame->globalData(), functionCallFrame, lineNumber, bytecodeOffset, unusedCallerCodeBlock); 1428 1384 if (!callerFrame) 1429 1385 return jsNull(); … … 1435 1391 ASSERT(caller.isObject()); 1436 1392 while (asObject(caller)->inherits(&JSBoundFunction::s_info)) { 1437 callerFrame = getCallerInfo(&callFrame->globalData(), callerFrame, bytecodeOffset, unusedCallerCodeBlock);1393 callerFrame = getCallerInfo(&callFrame->globalData(), callerFrame, lineNumber, bytecodeOffset, unusedCallerCodeBlock); 1438 1394 if (!callerFrame) 1439 1395 return jsNull();
Note:
See TracChangeset
for help on using the changeset viewer.