Changeset 47304 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Aug 14, 2009, 6:14:00 PM (16 years ago)
Author:
[email protected]
Message:

Remove AST nodes from use within the Runtime (outside of parsing), stage 1
https://bugs.webkit.org/show_bug.cgi?id=28330

Reviewed by Oliver Hunt.

Remove the EvalNode and ProgramNode from use in the runtime. They still exist
after this patch, but are hidden behind EvalExecutable and FunctionExecutable,
and are also still reachable behind CodeBlock::m_ownerNode.

The next step will be to beat back FunctionBodyNode in the same fashion.
Then remove the usage via CodeBlock, then only construct these nodes only on
demand during bytecode generation.

(JSC::GlobalCodeBlock::GlobalCodeBlock):
(JSC::GlobalCodeBlock::~GlobalCodeBlock):
(JSC::ProgramCodeBlock::ProgramCodeBlock):
(JSC::EvalCodeBlock::EvalCodeBlock):
(JSC::FunctionCodeBlock::FunctionCodeBlock):
(JSC::NativeCodeBlock::NativeCodeBlock):

  • bytecode/EvalCodeCache.h:

(JSC::EvalCodeCache::get):

  • debugger/Debugger.cpp:

(JSC::evaluateInGlobalCallFrame):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::evaluate):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::callEval):
(JSC::Interpreter::execute):

  • interpreter/Interpreter.h:
  • parser/Nodes.cpp:

(JSC::FunctionBodyNode::createNativeThunk):
(JSC::FunctionBodyNode::generateBytecode):
(JSC::FunctionBodyNode::bytecodeForExceptionInfoReparse):

  • parser/Parser.h:

(JSC::Parser::parse):
(JSC::Parser::reparse):
(JSC::Parser::parseFunctionFromGlobalCode):
(JSC::::parse):

  • runtime/Completion.cpp:

(JSC::checkSyntax):
(JSC::evaluate):

  • runtime/Error.cpp:

(JSC::throwError):

  • runtime/Error.h:
  • runtime/Executable.h: Added.

(JSC::TemplateExecutable::TemplateExecutable):
(JSC::TemplateExecutable::markAggregate):
(JSC::TemplateExecutable::sourceURL):
(JSC::TemplateExecutable::lineNo):
(JSC::TemplateExecutable::bytecode):
(JSC::TemplateExecutable::jitCode):
(JSC::EvalExecutable::EvalExecutable):
(JSC::ProgramExecutable::ProgramExecutable):

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunction):

  • runtime/FunctionConstructor.h:
  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::numericCompareFunction):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::~JSGlobalObject):
(JSC::JSGlobalObject::markChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::codeBlocks):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncEval):

Location:
trunk/JavaScriptCore/runtime
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Completion.cpp

    r44224 r47304  
    4242    JSLock lock(exec);
    4343
    44     int errLine;
    45     UString errMsg;
     44    ProgramExecutable program(source);
     45    JSObject* error = program.parse(exec);
     46    if (error)
     47        return Completion(Throw, error);
    4648
    47     RefPtr<ProgramNode> progNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
    48     if (!progNode)
    49         return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()));
    5049    return Completion(Normal);
    5150}
     
    5453{
    5554    JSLock lock(exec);
    56    
    57     int errLine;
    58     UString errMsg;
    59     RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
    6055
    61     if (!programNode)
    62         return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()));
     56    ProgramExecutable program(source);
     57    JSObject* error = program.parse(exec);
     58    if (error)
     59        return Completion(Throw, error);
    6360
    6461    JSObject* thisObj = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec);
    6562
    6663    JSValue exception;
    67     JSValue result = exec->interpreter()->execute(programNode.get(), exec, scopeChain.node(), thisObj, &exception);
     64    JSValue result = exec->interpreter()->execute(&program, exec, scopeChain.node(), thisObj, &exception);
    6865
    6966    if (exception) {
  • trunk/JavaScriptCore/runtime/Error.cpp

    r43222 r47304  
    9898}
    9999
     100JSObject* throwError(ExecState* exec, JSObject* error)
     101{
     102    exec->setException(error);
     103    return error;
     104}
     105
    100106JSObject* throwError(ExecState* exec, ErrorType type)
    101107{
  • trunk/JavaScriptCore/runtime/Error.h

    r37938 r47304  
    6060    JSObject* throwError(ExecState*, ErrorType, const char* message);
    6161    JSObject* throwError(ExecState*, ErrorType);
     62    JSObject* throwError(ExecState*, JSObject*);
    6263
    6364} // namespace JSC
  • trunk/JavaScriptCore/runtime/FunctionConstructor.cpp

    r43661 r47304  
    6767}
    6868
    69 FunctionBodyNode* extractFunctionBody(ProgramNode* program)
    70 {
    71     if (!program)
    72         return 0;
    73 
    74     StatementVector& children = program->children();
    75     if (children.size() != 1)
    76         return 0;
    77 
    78     StatementNode* exprStatement = children[0];
    79     ASSERT(exprStatement);
    80     ASSERT(exprStatement->isExprStatement());
    81     if (!exprStatement || !exprStatement->isExprStatement())
    82         return 0;
    83 
    84     ExpressionNode* funcExpr = static_cast<ExprStatementNode*>(exprStatement)->expr();
    85     ASSERT(funcExpr);
    86     ASSERT(funcExpr->isFuncExprNode());
    87     if (!funcExpr || !funcExpr->isFuncExprNode())
    88         return 0;
    89 
    90     FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body();
    91     ASSERT(body);
    92     return body;
    93 }
    94 
    9569// ECMA 15.3.2 The Function Constructor
    9670JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
     
    11488    UString errMsg;
    11589    SourceCode source = makeSource(program, sourceURL, lineNumber);
    116     RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
    117 
    118     FunctionBodyNode* body = extractFunctionBody(programNode.get());
     90    RefPtr<FunctionBodyNode> body = exec->globalData().parser->parseFunctionFromGlobalCode(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
    11991    if (!body)
    12092        return throwError(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url());
     
    12294    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    12395    ScopeChain scopeChain(globalObject, globalObject->globalData(), exec->globalThisValue());
    124     return new (exec) JSFunction(exec, functionName, body, scopeChain.node());
     96    return new (exec) JSFunction(exec, functionName, body.get(), scopeChain.node());
    12597}
    12698
  • trunk/JavaScriptCore/runtime/FunctionConstructor.h

    r40993 r47304  
    2727
    2828    class FunctionPrototype;
    29     class ProgramNode;
    30     class FunctionBodyNode;
    3129
    3230    class FunctionConstructor : public InternalFunction {
     
    4240    JSObject* constructFunction(ExecState*, const ArgList&);
    4341
    44     FunctionBodyNode* extractFunctionBody(ProgramNode*);
    45 
    4642} // namespace JSC
    4743
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r47267 r47304  
    237237    if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) {
    238238        initializingLazyNumericCompareFunction = true;
    239         RefPtr<ProgramNode> programNode = parser->parse<ProgramNode>(exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
    240         RefPtr<FunctionBodyNode> functionBody = extractFunctionBody(programNode.get());
     239        RefPtr<FunctionBodyNode> functionBody = parser->parseFunctionFromGlobalCode(exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
    241240        lazyNumericCompareFunction = functionBody->bytecode(exec->scopeChain()).instructions();
    242241        initializingLazyNumericCompareFunction = false;
  • trunk/JavaScriptCore/runtime/JSGlobalObject.cpp

    r47292 r47304  
    113113        headObject = 0;
    114114
    115     HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
    116     for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
     115    HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end();
     116    for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
    117117        (*it)->clearGlobalObject();
    118118       
     
    367367    JSVariableObject::markChildren(markStack);
    368368   
    369     HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
    370     for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
     369    HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end();
     370    for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
    371371        (*it)->markAggregate(markStack);
    372372
  • trunk/JavaScriptCore/runtime/JSGlobalObject.h

    r47292 r47304  
    4141    class GlobalEvalFunction;
    4242    class NativeErrorConstructor;
     43    class GlobalCodeBlock;
    4344    class ObjectConstructor;
    44     class ProgramCodeBlock;
    4545    class PrototypeFunction;
    4646    class RegExpConstructor;
     
    152152            RefPtr<JSGlobalData> globalData;
    153153
    154             HashSet<ProgramCodeBlock*> codeBlocks;
     154            HashSet<GlobalCodeBlock*> codeBlocks;
    155155        };
    156156
     
    258258        virtual bool isDynamicScope() const;
    259259
    260         HashSet<ProgramCodeBlock*>& codeBlocks() { return d()->codeBlocks; }
     260        HashSet<GlobalCodeBlock*>& codeBlocks() { return d()->codeBlocks; }
    261261
    262262        void copyGlobalsFrom(RegisterFile&);
  • trunk/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r46598 r47304  
    287287        return parsedObject;
    288288
    289     int errLine;
    290     UString errMsg;
    291 
    292     SourceCode source = makeSource(s);
    293     RefPtr<EvalNode> evalNode = exec->globalData().parser->parse<EvalNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
    294 
    295     if (!evalNode)
    296         return throwError(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), NULL);
    297 
    298     return exec->interpreter()->execute(evalNode.get(), exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot());
     289    EvalExecutable eval(makeSource(s));
     290    JSObject* error = eval.parse(exec);
     291    if (error)
     292        return throwError(exec, error);
     293
     294    return exec->interpreter()->execute(&eval, exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot());
    299295}
    300296
Note: See TracChangeset for help on using the changeset viewer.