[Webkit-unassigned] [Bug 66994] Implement Error.stack

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Aug 26 11:13:51 PDT 2011


https://bugs.webkit.org/show_bug.cgi?id=66994





--- Comment #9 from Oliver Hunt <oliver at apple.com>  2011-08-26 11:13:51 PST ---
(From update of attachment 105364)
View in context: https://bugs.webkit.org/attachment.cgi?id=105364&action=review

Have included a number of suggestions and questions

> Source/JavaScriptCore/interpreter/Interpreter.cpp:756
> +const UString Interpreter::getStackTrace(JSGlobalData* globalData, int line)

void Interpreter::getStackTrace(JSGlobalData& globalData, int line, Vector<TraceInfo>& result)

> Source/JavaScriptCore/interpreter/Interpreter.cpp:768
> +        while (callFrame && callFrame != CallFrame::noCaller() && !callFrame->codeBlock())
> +            callFrame = callFrame->callerFrame()->removeHostCallFrameFlag();

This has the effect of removing native calls from the stack -- we may want to show these, but currently it's not necessary

> Source/JavaScriptCore/interpreter/Interpreter.cpp:775
> +        trace += getTraceLine(callFrame, callFrame->codeBlock()->codeType(), sourceURL, line, i);

result.append(TraceInfo(globalData, callFrame->codeBlock()->ownerExecutable(), line));

> Source/JavaScriptCore/interpreter/Interpreter.cpp:777
> +        getCallerLine(globalData, callFrame, line);

If you're called by a host function, this will not update line, so your next iteration may produce a bogus line number, what happens if I do:
> var o = {}; o.toString = function() {  throw {}; }
function () {  throw {}; }
> print(o)

> Source/JavaScriptCore/interpreter/Interpreter.cpp:802
> +            UString stackTrace = getStackTrace(globalData, codeBlock->lineNumberForBytecodeOffset(bytecodeOffset));

Vector<TraceInfo> trace;
getStackTrace(*globalData, codeBlock->lineNumberForBytecodeOffset(bytecodeOffset), trace);
addErrorInfo(callFrame, exception, codeBlock->lineNumberForBytecodeOffset(bytecodeOffset), codeBlock->ownerExecutable()->source(), stackTrace);

> Source/JavaScriptCore/interpreter/Interpreter.h:131
> +        static const UString getStackTrace(JSGlobalData*, int);

I don't like this string return, i think you're better doing:

struct TraceInfo {
    Strong<Executable> code;
    int lineNumber;
}

static void getStackTrace(JSGlobalData&, Vector<TraceInfo>& result);

> Source/JavaScriptCore/runtime/Error.cpp:119
> +JSObject* addErrorInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source, const UString& stackTrace)

JSObject* addErrorInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source, const Vector<TraceInfo>& stackTrace)

> Source/JavaScriptCore/runtime/Error.cpp:131
> +        error->putWithAttributes(globalData, globalData->propertyNames->stack, jsString(globalData, stackTrace), ReadOnly | DontDelete);

JSArray* stackTrace = JSArray::createEmpty(*globalData, globalObject);
for (unsigned i = 0; i < stackTrace.size(); i++) { JSString* string = jsString(globalData, formatTraceLine(stackTrace[i])); stackTrace->push(*globalData, string); }
error->putWithAttributes(globalData, globalData->propertyNames->stack, stackTrace, ReadOnly | DontDelete);

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list