Changeset 37184 in webkit for trunk/JavaScriptCore/kjs/Parser.h


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):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/Parser.h

    r37050 r37184  
    4949    class Parser : Noncopyable {
    5050    public:
    51         template <class ParsedNode>
    52         PassRefPtr<ParsedNode> parse(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
    53                                      int* sourceId = 0, int* errLine = 0, UString* errMsg = 0);
    54 
    55         UString sourceURL() const { return m_sourceURL; }
    56         int sourceId() const { return m_sourceId; }
     51        template <class ParsedNode> PassRefPtr<ParsedNode> parse(ExecState*, PassRefPtr<SourceProvider>, int* errLine = 0, UString* errMsg = 0);
     52        template <class ParsedNode> PassRefPtr<ParsedNode> parse(ExecState*, const SourceCode&, int* errLine = 0, UString* errMsg = 0);
    5753
    5854        void didFinishParsing(SourceElements*, ParserRefCountedData<DeclarationStacks::VarStack>*,
     
    6157    private:
    6258        friend class JSGlobalData;
    63         Parser();
    6459
    65         void parse(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
    66                    int* sourceId, int* errLine, UString* errMsg);
     60        void parse(ExecState*, int* errLine, UString* errMsg);
    6761
    68         UString m_sourceURL;
    69         int m_sourceId;
     62        const SourceCode* m_source;
    7063        RefPtr<SourceElements> m_sourceElements;
    7164        RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> > m_varDeclarations;
     
    7871    };
    7972
    80     template <class ParsedNode>
    81     PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
    82                                          int* sourceId, int* errLine, UString* errMsg)
     73    template <class ParsedNode> PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, const SourceCode& source, int* errLine, UString* errMsg)
    8374    {
    84         m_sourceURL = sourceURL;
    85         RefPtr<SourceProvider> sourceProvider = source;
    86         parse(exec, sourceURL, startingLineNumber, sourceProvider.get(), sourceId, errLine, errMsg);
    87         if (!m_sourceElements) {
    88             m_sourceURL = UString();
    89             return 0;
     75        m_source = &source;
     76        parse(exec, errLine, errMsg);
     77        RefPtr<ParsedNode> result;
     78        if (m_sourceElements) {
     79            result = ParsedNode::create(&exec->globalData(),
     80                                         m_sourceElements.get(),
     81                                         m_varDeclarations ? &m_varDeclarations->data : 0,
     82                                         m_funcDeclarations ? &m_funcDeclarations->data : 0,
     83                                         *m_source,
     84                                         m_usesEval,
     85                                         m_needsClosure,
     86                                         m_usesArguments,
     87                                         m_numConstants);
     88            result->setLoc(m_source->firstLine(), m_lastLine);
    9089        }
    91         RefPtr<ParsedNode> node = ParsedNode::create(&exec->globalData(),
    92                                                      m_sourceElements.release().get(),
    93                                                      m_varDeclarations ? &m_varDeclarations->data : 0,
    94                                                      m_funcDeclarations ? &m_funcDeclarations->data : 0,
    95                                                      sourceProvider.get(),
    96                                                      m_usesEval,
    97                                                      m_needsClosure,
    98                                                      m_usesArguments,
    99                                                      m_numConstants);
     90
     91        m_source = 0;
     92        m_sourceElements = 0;
    10093        m_varDeclarations = 0;
    10194        m_funcDeclarations = 0;
    102         m_sourceURL = UString();
    103         node->setLoc(startingLineNumber, m_lastLine);
    104         return node.release();
     95        return result.release();
    10596    }
    10697
Note: See TracChangeset for help on using the changeset viewer.