Changeset 37184 in webkit for trunk/JavaScriptCore/VM


Ignore:
Timestamp:
Oct 1, 2008, 11:44:37 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-10-01 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler and Cameron Zwarich.

Preliminary step toward dynamic recompilation: Standardized and
simplified the parsing interface.


The main goal in this patch is to make it easy to ask for a duplicate
compilation, and get back a duplicate result -- same source URL, same
debugger / profiler ID, same toString behavior, etc.


The basic unit of compilation and evaluation is now SourceCode, which
encompasses a SourceProvider, a range in that provider, and a starting
line number.

A SourceProvider now encompasses a source URL, and *is* a source ID,
since a pointer is a unique identifier.

  • API/JSBase.cpp: (JSEvaluateScript): (JSCheckScriptSyntax): Provide a SourceCode to the Interpreter, since other APIs are no longer supported.


  • VM/CodeBlock.h: (JSC::EvalCodeCache::get): Provide a SourceCode to the Interpreter, since other APIs are no longer supported. (JSC::CodeBlock::CodeBlock): ASSERT something that used to be ASSERTed by our caller -- this is a better bottleneck.
  • VM/CodeGenerator.cpp: (JSC::CodeGenerator::CodeGenerator): Updated for the fact that FunctionBodyNode's parameters are no longer a WTF::Vector.
  • kjs/Arguments.cpp: (JSC::Arguments::Arguments): ditto
  • kjs/DebuggerCallFrame.cpp: (JSC::DebuggerCallFrame::evaluate): Provide a SourceCode to the Parser, since other APIs are no longer supported.
  • kjs/FunctionConstructor.cpp: (JSC::constructFunction): Provide a SourceCode to the Parser, since other APIs are no longer supported. Adopt FunctionBodyNode's new "finishParsing" API.
  • kjs/JSFunction.cpp: (JSC::JSFunction::lengthGetter): (JSC::JSFunction::getParameterName): Updated for the fact that FunctionBodyNode's parameters are no longer a wtf::Vector.
  • kjs/JSFunction.h: Nixed some cruft.
  • kjs/JSGlobalObjectFunctions.cpp: (JSC::globalFuncEval): Provide a SourceCode to the Parser, since other APIs are no longer supported.
  • kjs/Parser.cpp: (JSC::Parser::parse): Require a SourceCode argument, instead of a bunch of broken out parameters. Stop tracking sourceId as an integer, since we use the SourceProvider pointer for this now. Don't clamp the startingLineNumber, since SourceCode does that now.
  • kjs/Parser.h: (JSC::Parser::parse): Standardized the parsing interface to require a SourceCode.
  • kjs/Shell.cpp: (functionRun): (functionLoad): (prettyPrintScript): (runWithScripts): (runInteractive): Provide a SourceCode to the Interpreter, since other APIs are no longer supported.
  • kjs/SourceProvider.h: (JSC::SourceProvider::SourceProvider): (JSC::SourceProvider::url): (JSC::SourceProvider::asId): (JSC::UStringSourceProvider::create): (JSC::UStringSourceProvider::UStringSourceProvider): Added new responsibilities described above.
  • kjs/SourceRange.h: (JSC::SourceCode::SourceCode): (JSC::SourceCode::toString): (JSC::SourceCode::provider): (JSC::SourceCode::firstLine): (JSC::SourceCode::data): (JSC::SourceCode::length): Added new responsibilities described above. Renamed SourceRange to SourceCode, based on review feedback. Added a makeSource function for convenience.
  • kjs/debugger.h: Provide a SourceCode to the client, since other APIs are no longer supported.
  • kjs/grammar.y: Provide startingLineNumber when creating a SourceCode.
  • kjs/debugger.h: Treat sourceId as intptr_t to avoid loss of precision on 64bit platforms.
  • kjs/interpreter.cpp: (JSC::Interpreter::checkSyntax): (JSC::Interpreter::evaluate):
  • kjs/interpreter.h: Require a SourceCode instead of broken out arguments.
  • kjs/lexer.cpp: (JSC::Lexer::setCode):
  • kjs/lexer.h: (JSC::Lexer::sourceRange): Fold together the SourceProvider and line number into a SourceCode. Fixed a bug where the Lexer would accidentally keep alive the last SourceProvider forever.
  • kjs/nodes.cpp: (JSC::ScopeNode::ScopeNode): (JSC::ProgramNode::ProgramNode): (JSC::ProgramNode::create): (JSC::EvalNode::EvalNode): (JSC::EvalNode::generateCode): (JSC::EvalNode::create): (JSC::FunctionBodyNode::FunctionBodyNode): (JSC::FunctionBodyNode::finishParsing): (JSC::FunctionBodyNode::create): (JSC::FunctionBodyNode::generateCode): (JSC::ProgramNode::generateCode): (JSC::FunctionBodyNode::paramString):
  • kjs/nodes.h: (JSC::ScopeNode::): (JSC::ScopeNode::sourceId): (JSC::FunctionBodyNode::): (JSC::FunctionBodyNode::parameterCount): (JSC::FuncExprNode::): (JSC::FuncDeclNode::): Store a SourceCode in all ScopeNodes, since SourceCode is now responsible for tracking URL, ID, etc. Streamlined some ad hoc FunctionBodyNode fixups into a "finishParsing" function, to help make clear what you need to do in order to finish parsing a FunctionBodyNode.
  • wtf/Vector.h: (WTF::::releaseBuffer): Don't ASSERT that releaseBuffer() is only called when buffer is not 0, since FunctionBodyNode is more than happy to get back a 0 buffer, and other functions like RefPtr::release() allow for 0, too.

JavaScriptGlue:

2008-10-01 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler and Cameron Zwarich.

  • JSRun.cpp: (JSRun::Evaluate): (JSRun::CheckSyntax): Provide a SourceCode to the Interpreter, since other APIs are no longer supported.

WebCore:

2008-10-01 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler and Cameron Zwarich.

Updated for JavaScriptCore API changes: use a SourceCode instead of
broken out parameters; treat sourceId as intptr_t.

  • ForwardingHeaders/kjs/SourceRange.h: Copied from ForwardingHeaders/kjs/SourceProvider.h.
  • bindings/js/JSXMLHttpRequestCustom.cpp: (WebCore::JSXMLHttpRequest::send):
  • bindings/js/ScriptController.cpp: (WebCore::ScriptController::evaluate):
  • bindings/js/StringSourceProvider.h: (WebCore::StringSourceProvider::create): (WebCore::StringSourceProvider::StringSourceProvider):

(WebCore::makeSource): Added a makeSource function for convenience.

  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject evaluateWebScript:]):
  • bridge/NP_jsobject.cpp: (_NPN_Evaluate):
  • bridge/jni/jni_jsobject.mm: (JavaJSObject::call): (JavaJSObject::eval): (JavaJSObject::getMember): (JavaJSObject::setMember): (JavaJSObject::removeMember):
  • bridge/jni/jni_runtime.h: (JSC::Bindings::JavaString::operator UString): Replaced the explicit ustring() function with an implicit operator because this class already holds a UString::rep.
  • page/Console.cpp: (WebCore::retrieveLastCaller): (WebCore::Console::trace):
  • page/InspectorController.cpp: (WebCore::jsStringRef): (WebCore::InspectorController::addBreakpoint): (WebCore::InspectorController::removeBreakpoint): (WebCore::InspectorController::didParseSource): (WebCore::InspectorController::failedToParseSource):
  • page/InspectorController.h:
  • page/JavaScriptCallFrame.cpp: (WebCore::JavaScriptCallFrame::JavaScriptCallFrame):
  • page/JavaScriptCallFrame.h: (WebCore::JavaScriptCallFrame::create): (WebCore::JavaScriptCallFrame::sourceIdentifier): (WebCore::JavaScriptCallFrame::update):
  • page/JavaScriptDebugListener.h:
  • page/JavaScriptDebugServer.cpp: (WebCore::JavaScriptDebugServer::addBreakpoint): (WebCore::JavaScriptDebugServer::removeBreakpoint): (WebCore::JavaScriptDebugServer::hasBreakpoint): (WebCore::dispatchDidParseSource): (WebCore::dispatchFailedToParseSource): (WebCore::JavaScriptDebugServer::sourceParsed): (WebCore::JavaScriptDebugServer::callEvent): (WebCore::JavaScriptDebugServer::atStatement): (WebCore::JavaScriptDebugServer::returnEvent): (WebCore::JavaScriptDebugServer::exception): (WebCore::JavaScriptDebugServer::willExecuteProgram): (WebCore::JavaScriptDebugServer::didExecuteProgram): (WebCore::JavaScriptDebugServer::didReachBreakpoint):
  • page/JavaScriptDebugServer.h:
  • page/inspector/ScriptsPanel.js: Renamed internal uses of sourceId and sourceIdentifier to sourceID.

WebKit/mac:

2008-10-01 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler and Cameron Zwarich.

Updated for JavaScriptCore API changes: use a SourceCode instead of
broken out parameters; treat sourceId as intptr_t.


We still treat sourceId as int in some cases because of DashCode. See
<rdar://problem/6263293> WebScriptDebugDelegate should use intptr_t for
sourceId, not int.

  • WebView/WebScriptDebugger.h:
  • WebView/WebScriptDebugger.mm: (toNSString): (WebScriptDebugger::sourceParsed): (WebScriptDebugger::callEvent): (WebScriptDebugger::atStatement): (WebScriptDebugger::returnEvent): (WebScriptDebugger::exception): (WebScriptDebugger::willExecuteProgram): (WebScriptDebugger::didExecuteProgram): (WebScriptDebugger::didReachBreakpoint):
Location:
trunk/JavaScriptCore/VM
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/CodeBlock.h

    r37160 r37184  
    156156
    157157            if (!evalNode) {
    158                 int sourceId;
    159158                int errLine;
    160159                UString errMsg;
    161160               
    162                 evalNode = exec->parser()->parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(evalSource), &sourceId, &errLine, &errMsg);
     161                SourceCode source = makeSource(evalSource);
     162                evalNode = exec->parser()->parse<EvalNode>(exec, source, &errLine, &errMsg);
    163163                if (evalNode) {
    164164                    if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && cacheMap.size() < maxCacheEntries)
    165165                        cacheMap.set(evalSource.rep(), evalNode);
    166166                } else {
    167                     exceptionValue = Error::create(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
     167                    exceptionValue = Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), NULL);
    168168                    return 0;
    169169                }
     
    197197            , sourceOffset(sourceOffset_)
    198198        {
     199            ASSERT(source);
    199200        }
    200201
  • trunk/JavaScriptCore/VM/CodeGenerator.cpp

    r37160 r37184  
    313313        addVar(varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant);
    314314
    315     Vector<Identifier>& parameters = functionBody->parameters();
    316     m_nextParameter = -RegisterFile::CallFrameHeaderSize - parameters.size() - 1;
    317     m_parameters.resize(1 + parameters.size()); // reserve space for "this"
     315    const Identifier* parameters = functionBody->parameters();
     316    size_t parameterCount = functionBody->parameterCount();
     317    m_nextParameter = -RegisterFile::CallFrameHeaderSize - parameterCount - 1;
     318    m_parameters.resize(1 + parameterCount); // reserve space for "this"
    318319
    319320    // Add "this" as a parameter
     
    322323    ++m_codeBlock->numParameters;
    323324   
    324     for (size_t i = 0; i < parameters.size(); ++i)
     325    for (size_t i = 0; i < parameterCount; ++i)
    325326        addParameter(parameters[i]);
    326327
  • trunk/JavaScriptCore/VM/ExceptionHelpers.cpp

    r36973 r37184  
    9696    UString message = "Can't find variable: ";
    9797    message.append(ident.ustring());
    98     JSObject* exception = Error::create(exec, ReferenceError, message, line, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());
     98    JSObject* exception = Error::create(exec, ReferenceError, message, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
    9999    exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
    100100    exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
     
    160160    int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
    161161    UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint, divotPoint + endOffset, value, message);
    162     JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());
     162    JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
    163163    exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
    164164    exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
     
    181181   
    182182    UString errorMessage = createErrorMessage(exec, codeBlock, line, startPoint, divotPoint, value, "not a constructor");
    183     JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());
     183    JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
    184184    exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
    185185    exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
     
    195195    int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
    196196    UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint - startOffset, divotPoint, value, "not a function");
    197     JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());   
     197    JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());   
    198198    exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
    199199    exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
     
    219219    int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
    220220    UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint - startOffset, divotPoint, error->isNull() ? jsNull() : jsUndefined(), "not an object");
    221     JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());
     221    JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
    222222    exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
    223223    exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
  • trunk/JavaScriptCore/VM/Machine.cpp

    r37160 r37184  
    787787        DebuggerCallFrame debuggerCallFrame(exec, exec->dynamicGlobalObject(), codeBlock, scopeChain, r, exceptionValue);
    788788        if (r[RegisterFile::Callee].jsValue(exec))
    789             debugger->returnEvent(debuggerCallFrame, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->lastLine());
     789            debugger->returnEvent(debuggerCallFrame, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->lastLine());
    790790        else
    791             debugger->didExecuteProgram(debuggerCallFrame, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->lastLine());
     791            debugger->didExecuteProgram(debuggerCallFrame, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->lastLine());
    792792    }
    793793
     
    852852                } else
    853853                    exception->putWithAttributes(exec, Identifier(exec, "line"), jsNumber(exec, codeBlock->lineNumberForVPC(vPC)), ReadOnly | DontDelete);
    854                 exception->putWithAttributes(exec, Identifier(exec, "sourceId"), jsNumber(exec, codeBlock->ownerNode->sourceId()), ReadOnly | DontDelete);
     854                exception->putWithAttributes(exec, Identifier(exec, "sourceId"), jsNumber(exec, codeBlock->ownerNode->sourceID()), ReadOnly | DontDelete);
    855855                exception->putWithAttributes(exec, Identifier(exec, "sourceURL"), jsOwnedString(exec, codeBlock->ownerNode->sourceURL()), ReadOnly | DontDelete);
    856856            }
     
    868868        ScopeChainNode* scopeChain = this->scopeChain(r);
    869869        DebuggerCallFrame debuggerCallFrame(exec, exec->dynamicGlobalObject(), codeBlock, scopeChain, r, exceptionValue);
    870         debugger->exception(debuggerCallFrame, codeBlock->ownerNode->sourceId(), codeBlock->lineNumberForVPC(vPC));
     870        debugger->exception(debuggerCallFrame, codeBlock->ownerNode->sourceID(), codeBlock->lineNumberForVPC(vPC));
    871871    }
    872872
     
    11071107    switch (debugHookID) {
    11081108        case DidEnterCallFrame:
    1109             debugger->callEvent(debuggerCallFrame, codeBlock->ownerNode->sourceId(), firstLine);
     1109            debugger->callEvent(debuggerCallFrame, codeBlock->ownerNode->sourceID(), firstLine);
    11101110            return;
    11111111        case WillLeaveCallFrame:
    1112             debugger->returnEvent(debuggerCallFrame, codeBlock->ownerNode->sourceId(), lastLine);
     1112            debugger->returnEvent(debuggerCallFrame, codeBlock->ownerNode->sourceID(), lastLine);
    11131113            return;
    11141114        case WillExecuteStatement:
    1115             debugger->atStatement(debuggerCallFrame, codeBlock->ownerNode->sourceId(), firstLine);
     1115            debugger->atStatement(debuggerCallFrame, codeBlock->ownerNode->sourceID(), firstLine);
    11161116            return;
    11171117        case WillExecuteProgram:
    1118             debugger->willExecuteProgram(debuggerCallFrame, codeBlock->ownerNode->sourceId(), firstLine);
     1118            debugger->willExecuteProgram(debuggerCallFrame, codeBlock->ownerNode->sourceID(), firstLine);
    11191119            return;
    11201120        case DidExecuteProgram:
    1121             debugger->didExecuteProgram(debuggerCallFrame, codeBlock->ownerNode->sourceId(), lastLine);
     1121            debugger->didExecuteProgram(debuggerCallFrame, codeBlock->ownerNode->sourceID(), lastLine);
    11221122            return;
    11231123        case DidReachBreakpoint:
    1124             debugger->didReachBreakpoint(debuggerCallFrame, codeBlock->ownerNode->sourceId(), lastLine);
     1124            debugger->didReachBreakpoint(debuggerCallFrame, codeBlock->ownerNode->sourceID(), lastLine);
    11251125            return;
    11261126    }
     
    37293729
    37303730        CodeBlock* codeBlock = this->codeBlock(r);
    3731         r[dst] = Error::create(exec, (ErrorType)type, codeBlock->unexpectedConstants[message]->toString(exec), codeBlock->lineNumberForVPC(vPC), codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());
     3731        r[dst] = Error::create(exec, (ErrorType)type, codeBlock->unexpectedConstants[message]->toString(exec), codeBlock->lineNumberForVPC(vPC), codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
    37323732
    37333733        ++vPC;
     
    39043904}
    39053905
    3906 void Machine::retrieveLastCaller(ExecState* exec, int& lineNumber, int& sourceId, UString& sourceURL, JSValue*& function) const
     3906void Machine::retrieveLastCaller(ExecState* exec, int& lineNumber, intptr_t& sourceID, UString& sourceURL, JSValue*& function) const
    39073907{
    39083908    function = 0;
     
    39213921    Instruction* vPC = vPCForPC(callerCodeBlock, r[RegisterFile::ReturnPC].v());
    39223922    lineNumber = callerCodeBlock->lineNumberForVPC(vPC - 1);
    3923     sourceId = callerCodeBlock->ownerNode->sourceId();
     3923    sourceID = callerCodeBlock->ownerNode->sourceID();
    39243924    sourceURL = callerCodeBlock->ownerNode->sourceURL();
    39253925
     
    56595659    unsigned lineNumber = ARG_int3;
    56605660
    5661     return Error::create(exec, static_cast<ErrorType>(type), message->toString(exec), lineNumber, codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());
     5661    return Error::create(exec, static_cast<ErrorType>(type), message->toString(exec), lineNumber, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
    56625662}
    56635663
  • trunk/JavaScriptCore/VM/Machine.h

    r37160 r37184  
    102102        JSValue* retrieveArguments(ExecState*, JSFunction*) const;
    103103        JSValue* retrieveCaller(ExecState*, InternalFunction*) const;
    104         void retrieveLastCaller(ExecState* exec, int& lineNumber, int& sourceId, UString& sourceURL, JSValue*& function) const;
     104        void retrieveLastCaller(ExecState* exec, int& lineNumber, intptr_t& sourceID, UString& sourceURL, JSValue*& function) const;
    105105       
    106106        static ScopeChainNode* scopeChain(const Register* r) { return r[RegisterFile::ScopeChain].scopeChain(); }
Note: See TracChangeset for help on using the changeset viewer.