Changeset 147858 in webkit for trunk/Source/JavaScriptCore/interpreter
- Timestamp:
- Apr 6, 2013, 3:47:56 PM (12 years ago)
- Location:
- trunk/Source/JavaScriptCore/interpreter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
r147851 r147858 200 200 201 201 202 static CallFrame* getCallerInfo(JSGlobalData*, CallFrame*, int& lineNumber,unsigned& bytecodeOffset, CodeBlock*& callerOut);202 static CallFrame* getCallerInfo(JSGlobalData*, CallFrame*, 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* unusedCallerCodeBlock = 0; 426 getCallerInfo(&callFrame->globalData(), callFrame, line, bytecodeOffset, unusedCallerCodeBlock); 425 CodeBlock* callerCodeBlock = 0; 426 getCallerInfo(&callFrame->globalData(), callFrame, bytecodeOffset, callerCodeBlock); 427 line = callerCodeBlock->lineNumberForBytecodeOffset(bytecodeOffset); 427 428 dataLogF("[ReturnVPC] | %10p | %d (line %d)\n", it, bytecodeOffset, line); 428 429 ++it; … … 508 509 if (callerFrame->hasHostCallFrameFlag()) 509 510 return false; 510 int unusedLineNumber = 0; 511 callFrame = getCallerInfo(&callFrame->globalData(), callFrame, unusedLineNumber, bytecodeOffset, codeBlock); 511 callFrame = getCallerInfo(&callFrame->globalData(), callFrame, bytecodeOffset, codeBlock); 512 512 return true; 513 513 } … … 565 565 } 566 566 567 static int getLineNumberForCallFrame(JSGlobalData* globalData, CallFrame* callFrame) 568 { 569 UNUSED_PARAM(globalData); 567 static unsigned getBytecodeOffsetForCallFrame(CallFrame* callFrame) 568 { 570 569 callFrame = callFrame->removeHostCallFrameFlag(); 571 570 CodeBlock* codeBlock = callFrame->codeBlock(); 572 571 if (!codeBlock) 573 return -1;574 #if ENABLE(JIT) || ENABLE(LLINT)572 return 0; 573 #if ENABLE(JIT) 575 574 #if ENABLE(DFG_JIT) 576 575 if (codeBlock->getJITType() == JITCode::DFGJIT) 577 return codeBlock-> lineNumberForBytecodeOffset(codeBlock->codeOrigin(callFrame->codeOriginIndexForDFG()).bytecodeIndex);578 #endif 579 return c odeBlock->lineNumberForBytecodeOffset(callFrame->bytecodeOffsetForNonDFGCode());576 return codeBlock->codeOrigin(callFrame->codeOriginIndexForDFG()).bytecodeIndex; 577 #endif 578 return callFrame->bytecodeOffsetForNonDFGCode(); 580 579 #else 581 580 return 0; … … 583 582 } 584 583 585 static CallFrame* getCallerInfo(JSGlobalData* globalData, CallFrame* callFrame, int& lineNumber,unsigned& bytecodeOffset, CodeBlock*& caller)584 static CallFrame* getCallerInfo(JSGlobalData* globalData, CallFrame* callFrame, unsigned& bytecodeOffset, CodeBlock*& caller) 586 585 { 587 586 ASSERT_UNUSED(globalData, globalData); 588 587 bytecodeOffset = 0; 589 lineNumber = -1;590 588 ASSERT(!callFrame->hasHostCallFrameFlag()); 591 589 CallFrame* callerFrame = callFrame->codeBlock() ? callFrame->trueCallerFrame() : callFrame->callerFrame()->removeHostCallFrameFlag(); … … 657 655 RELEASE_ASSERT(callerCodeBlock); 658 656 caller = callerCodeBlock; 659 lineNumber = callerCodeBlock->lineNumberForBytecodeOffset(bytecodeOffset);660 657 return callerFrame; 661 658 } … … 683 680 } 684 681 685 void Interpreter::getStackTrace(JSGlobalData* globalData, Vector<StackFrame>& results) 682 unsigned StackFrame::line() 683 { 684 return codeBlock ? codeBlock->lineNumberForBytecodeOffset(bytecodeOffset) + lineOffset : 0; 685 } 686 687 unsigned StackFrame::column() 688 { 689 if (!code) 690 return 0; 691 int divot = 0; 692 int unusedStartOffset = 0; 693 int unusedEndOffset = 0; 694 expressionInfo(divot, unusedStartOffset, unusedEndOffset); 695 return code->charPositionToColumnNumber(divot); 696 } 697 698 void StackFrame::expressionInfo(int& divot, int& startOffset, int& endOffset) 699 { 700 codeBlock->expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset); 701 divot += startOffset; 702 } 703 704 String StackFrame::toString(CallFrame* callFrame) 705 { 706 StringBuilder traceBuild; 707 String functionName = friendlyFunctionName(callFrame); 708 String sourceURL = friendlySourceURL(); 709 traceBuild.append(functionName); 710 if (!sourceURL.isEmpty()) { 711 if (!functionName.isEmpty()) 712 traceBuild.append('@'); 713 traceBuild.append(sourceURL); 714 if (codeType != StackFrameNativeCode) { 715 traceBuild.append(':'); 716 traceBuild.appendNumber(line()); 717 } 718 } 719 return traceBuild.toString().impl(); 720 } 721 722 void Interpreter::getStackTrace(JSGlobalData* globalData, Vector<StackFrame>& results, size_t maxStackSize) 686 723 { 687 724 CallFrame* callFrame = globalData->topCallFrame->removeHostCallFrameFlag(); 688 725 if (!callFrame || callFrame == CallFrame::noCaller()) 689 726 return; 690 int line = getLineNumberForCallFrame(globalData, callFrame); 691 727 unsigned bytecodeOffset = getBytecodeOffsetForCallFrame(callFrame); 692 728 callFrame = callFrame->trueCallFrameFromVMCode(); 693 729 if (!callFrame) 694 730 return; 695 696 while (callFrame && callFrame != CallFrame::noCaller()) { 731 CodeBlock* callerCodeBlock = callFrame->codeBlock(); 732 733 while (callFrame && callFrame != CallFrame::noCaller() && maxStackSize--) { 697 734 String sourceURL; 698 if (call Frame->codeBlock()) {735 if (callerCodeBlock) { 699 736 sourceURL = getSourceURLFromCallFrame(callFrame); 700 StackFrame s = { Strong<JSObject>(*globalData, callFrame->callee()), getStackFrameCodeType(callFrame), Strong<ExecutableBase>(*globalData, callFrame->codeBlock()->ownerExecutable()), line, sourceURL}; 737 StackFrame s = { 738 Strong<JSObject>(*globalData, callFrame->callee()), 739 getStackFrameCodeType(callFrame), 740 Strong<ExecutableBase>(*globalData, callerCodeBlock->ownerExecutable()), 741 Strong<UnlinkedCodeBlock>(*globalData, callerCodeBlock->unlinkedCodeBlock()), 742 callerCodeBlock->source(), 743 callerCodeBlock->ownerExecutable()->lineNo(), 744 callerCodeBlock->sourceOffset(), 745 bytecodeOffset, 746 sourceURL 747 }; 701 748 results.append(s); 702 749 } else { 703 StackFrame s = { Strong<JSObject>(*globalData, callFrame->callee()), StackFrameNativeCode, Strong<ExecutableBase>(), -1, String()};750 StackFrame s = { Strong<JSObject>(*globalData, callFrame->callee()), StackFrameNativeCode, Strong<ExecutableBase>(), Strong<UnlinkedCodeBlock>(), 0, 0, 0, 0, String()}; 704 751 results.append(s); 705 752 } 706 unsigned unusedBytecodeOffset = 0; 707 CodeBlock* unusedCallerCodeBlock = 0; 708 callFrame = getCallerInfo(globalData, callFrame, line, unusedBytecodeOffset, unusedCallerCodeBlock); 709 } 710 } 711 712 void Interpreter::addStackTraceIfNecessary(CallFrame* callFrame, JSObject* error) 753 callFrame = getCallerInfo(globalData, callFrame, bytecodeOffset, callerCodeBlock); 754 } 755 } 756 757 void Interpreter::addStackTraceIfNecessary(CallFrame* callFrame, JSValue error) 713 758 { 714 759 JSGlobalData* globalData = &callFrame->globalData(); 715 760 ASSERT(callFrame == globalData->topCallFrame || callFrame == callFrame->lexicalGlobalObject()->globalExec() || callFrame == callFrame->dynamicGlobalObject()->globalExec()); 716 if (error->hasProperty(callFrame, globalData->propertyNames->stack))717 return;718 761 719 762 Vector<StackFrame> stackTrace; 720 763 getStackTrace(&callFrame->globalData(), stackTrace); 721 764 722 if (stackTrace.isEmpty() )765 if (stackTrace.isEmpty() || !error.isObject()) 723 766 return; 724 767 JSObject* errorObject = asObject(error); 725 768 JSGlobalObject* globalObject = 0; 726 769 if (isTerminatedExecutionException(error) || isInterruptedExecutionException(error)) 727 770 globalObject = globalData->dynamicGlobalObject; 728 771 else 729 globalObject = error ->globalObject();772 globalObject = errorObject->globalObject(); 730 773 731 774 // FIXME: JSStringJoiner could be more efficient than StringBuilder here. … … 736 779 builder.append('\n'); 737 780 } 738 739 error->putDirect(*globalData, globalData->propertyNames->stack, jsString(globalData, builder.toString()), ReadOnly | DontDelete); 781 782 if (errorObject->hasProperty(callFrame, globalData->propertyNames->stack)) 783 return; 784 errorObject->putDirect(*globalData, globalData->propertyNames->stack, jsString(globalData, builder.toString()), ReadOnly | DontDelete); 740 785 } 741 786 … … 1380 1425 return jsNull(); 1381 1426 1382 int lineNumber;1383 1427 unsigned bytecodeOffset; 1384 1428 CodeBlock* unusedCallerCodeBlock = 0; 1385 CallFrame* callerFrame = getCallerInfo(&callFrame->globalData(), functionCallFrame, lineNumber,bytecodeOffset, unusedCallerCodeBlock);1429 CallFrame* callerFrame = getCallerInfo(&callFrame->globalData(), functionCallFrame, bytecodeOffset, unusedCallerCodeBlock); 1386 1430 if (!callerFrame) 1387 1431 return jsNull(); … … 1393 1437 ASSERT(caller.isObject()); 1394 1438 while (asObject(caller)->inherits(&JSBoundFunction::s_info)) { 1395 callerFrame = getCallerInfo(&callFrame->globalData(), callerFrame, lineNumber,bytecodeOffset, unusedCallerCodeBlock);1439 callerFrame = getCallerInfo(&callFrame->globalData(), callerFrame, bytecodeOffset, unusedCallerCodeBlock); 1396 1440 if (!callerFrame) 1397 1441 return jsNull(); -
trunk/Source/JavaScriptCore/interpreter/Interpreter.h
r147846 r147858 80 80 StackFrameCodeType codeType; 81 81 Strong<ExecutableBase> executable; 82 int line; 82 Strong<UnlinkedCodeBlock> codeBlock; 83 RefPtr<SourceProvider> code; 84 int lineOffset; 85 unsigned characterOffset; 86 unsigned bytecodeOffset; 83 87 String sourceURL; 84 String toString(CallFrame* callFrame) const 85 { 86 StringBuilder traceBuild; 87 String functionName = friendlyFunctionName(callFrame); 88 String sourceURL = friendlySourceURL(); 89 traceBuild.append(functionName); 90 if (!sourceURL.isEmpty()) { 91 if (!functionName.isEmpty()) 92 traceBuild.append('@'); 93 traceBuild.append(sourceURL); 94 if (line > -1) { 95 traceBuild.append(':'); 96 traceBuild.appendNumber(line); 97 } 98 } 99 return traceBuild.toString().impl(); 100 } 88 JS_EXPORT_PRIVATE String toString(CallFrame*); 101 89 String friendlySourceURL() const 102 90 { … … 138 126 return traceLine.isNull() ? emptyString() : traceLine; 139 127 } 140 unsigned friendlyLineNumber() const 141 { 142 return line > -1 ? line : 0; 143 } 128 JS_EXPORT_PRIVATE unsigned line(); 129 JS_EXPORT_PRIVATE unsigned column(); 130 JS_EXPORT_PRIVATE void expressionInfo(int& divot, int& startOffset, int& endOffset); 144 131 }; 145 132 … … 233 220 NEVER_INLINE void debug(CallFrame*, DebugHookID, int firstLine, int lastLine, int column); 234 221 static const String getTraceLine(CallFrame*, StackFrameCodeType, const String&, int); 235 JS_EXPORT_PRIVATE static void getStackTrace(JSGlobalData*, Vector<StackFrame>& results );236 static void addStackTraceIfNecessary(CallFrame*, JS Object*error);222 JS_EXPORT_PRIVATE static void getStackTrace(JSGlobalData*, Vector<StackFrame>& results, size_t maxStackSize = std::numeric_limits<size_t>::max()); 223 static void addStackTraceIfNecessary(CallFrame*, JSValue error); 237 224 238 225 void dumpSampleData(ExecState* exec);
Note:
See TracChangeset
for help on using the changeset viewer.