Changeset 32290 in webkit


Ignore:
Timestamp:
Apr 21, 2008 12:39:36 AM (16 years ago)
Author:
mjs@apple.com
Message:

2008-04-21 Cameron Zwarich <cwzwarich@uwaterloo.ca>

Reviewed by Maciej.

Add support for variable declarations in eval code.

  • VM/CodeBlock.h: (KJS::EvalCodeBlock::EvalCodeBlock):
  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::CodeGenerator):
  • VM/CodeGenerator.h:
  • VM/Machine.cpp: (KJS::Machine::execute):
  • VM/Machine.h:
  • kjs/function.cpp: (KJS::globalFuncEval):
  • kjs/nodes.cpp: (KJS::EvalNode::generateCode):
  • kjs/nodes.h: (KJS::EvalNode::):
Location:
branches/squirrelfish/JavaScriptCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/squirrelfish/JavaScriptCore/ChangeLog

    r32289 r32290  
     12008-04-21  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
     2
     3        Reviewed by Maciej.
     4
     5        Add support for variable declarations in eval code.
     6
     7        * VM/CodeBlock.h:
     8        (KJS::EvalCodeBlock::EvalCodeBlock):
     9        * VM/CodeGenerator.cpp:
     10        (KJS::CodeGenerator::CodeGenerator):
     11        * VM/CodeGenerator.h:
     12        * VM/Machine.cpp:
     13        (KJS::Machine::execute):
     14        * VM/Machine.h:
     15        * kjs/function.cpp:
     16        (KJS::globalFuncEval):
     17        * kjs/nodes.cpp:
     18        (KJS::EvalNode::generateCode):
     19        * kjs/nodes.h:
     20        (KJS::EvalNode::):
     21
    1222008-04-20  Oliver Hunt  <oliver@apple.com>
    223
  • branches/squirrelfish/JavaScriptCore/VM/CodeBlock.h

    r32281 r32290  
    116116    };
    117117
     118    struct EvalCodeBlock : public ProgramCodeBlock {
     119        EvalCodeBlock(const UString& sourceURL_, bool usesEval_, bool needsClosure_, JSGlobalObject* globalObject_)
     120            : ProgramCodeBlock(sourceURL_, usesEval_, needsClosure_, globalObject_)
     121        {
     122        }
     123
     124        Vector<Identifier> declaredVariables;
     125    };
     126
    118127} // namespace KJS
    119128
  • branches/squirrelfish/JavaScriptCore/VM/CodeGenerator.cpp

    r32289 r32290  
    241241}
    242242
    243 CodeGenerator::CodeGenerator(EvalNode* evalNode, const ScopeChain& scopeChain, SymbolTable* symbolTable, CodeBlock* codeBlock)
     243CodeGenerator::CodeGenerator(EvalNode* evalNode, const ScopeChain& scopeChain, SymbolTable* symbolTable, EvalCodeBlock* codeBlock, VarStack& varStack)
    244244    : m_scopeChain(&scopeChain)
    245245    , m_symbolTable(symbolTable)
     
    254254{
    255255    addVar(m_propertyNames->thisIdentifier);
     256   
     257    for (size_t i = 0; i < varStack.size(); ++i)
     258        codeBlock->declaredVariables.append(varStack[i].first);
    256259}
    257260
  • branches/squirrelfish/JavaScriptCore/VM/CodeGenerator.h

    r32289 r32290  
    7474        CodeGenerator(ProgramNode*, const ScopeChain&, SymbolTable*, CodeBlock*, VarStack&, FunctionStack&);
    7575        CodeGenerator(FunctionBodyNode*, const ScopeChain&, SymbolTable*, CodeBlock*, VarStack&, FunctionStack&, Vector<Identifier>& parameters);
    76         CodeGenerator(EvalNode*, const ScopeChain&, SymbolTable*, CodeBlock*);
     76        CodeGenerator(EvalNode*, const ScopeChain&, SymbolTable*, EvalCodeBlock*, VarStack&);
    7777
    7878        const CommonIdentifiers& propertyNames() const { return *m_propertyNames; }
  • branches/squirrelfish/JavaScriptCore/VM/Machine.cpp

    r32286 r32290  
    577577}
    578578
    579 JSValue* Machine::execute(EvalNode* evalNode, ExecState* exec, JSObject* thisObj, RegisterFile* registerFile, int registerOffset, ScopeChainNode* scopeChain, JSValue** exception)
    580 {
    581     CodeBlock* codeBlock = &evalNode->code(scopeChain);
    582 
     579JSValue* Machine::execute(EvalNode* evalNode, ExecState* exec, JSObject* thisObj, RegisterFile* registerFile, int registerOffset, ScopeChainNode* scopeChain, JSValue** exception, JSObject* variableObject)
     580{
     581    EvalCodeBlock* codeBlock = &evalNode->code(scopeChain);
     582   
     583    if (!variableObject) {
     584        ScopeChainNode* node;
     585       
     586        for (node = scopeChain; !node->object->isActivationObject() && node->next; node = node->next) { }
     587        variableObject = node->object;
     588    }
     589   
     590    for (Vector<Identifier>::const_iterator iter = codeBlock->declaredVariables.begin(); iter != codeBlock->declaredVariables.end(); ++iter) {
     591        Identifier ident = *iter;
     592       
     593        if (!variableObject->hasProperty(exec, ident))
     594            variableObject->put(exec, ident, jsUndefined());
     595    }
     596   
    583597    size_t oldSize = registerFile->size();
    584598    size_t newSize = registerOffset + codeBlock->numVars + codeBlock->numTemporaries;
     
    594608}
    595609
    596 JSValue* Machine::execute(EvalNode* evalNode, ExecState* exec, JSObject* thisObj, RegisterFileStack* registerFileStack, ScopeChainNode* scopeChain, JSValue** exception)
     610JSValue* Machine::execute(EvalNode* evalNode, ExecState* exec, JSObject* thisObj, RegisterFileStack* registerFileStack, ScopeChainNode* scopeChain, JSValue** exception, JSObject* variableObject)
    597611{
    598612    RegisterFile* registerFile = registerFileStack->current();
    599     CodeBlock* codeBlock = &evalNode->code(scopeChain);
    600 
    601     size_t oldSize = registerFile->size();
    602     size_t newSize = oldSize + codeBlock->numVars + codeBlock->numTemporaries;
    603     registerFile->grow(newSize);
    604     Register* r = (*registerFile->basePointer()) + oldSize + codeBlock->numVars;
    605    
    606     r[ProgramCodeThisRegister].u.jsValue = thisObj;
    607     JSValue* result = privateExecute(Normal, exec, registerFile, r, scopeChain, codeBlock, exception);
    608    
    609     registerFile->shrink(oldSize);
    610    
    611     return result;
     613    return Machine::execute(evalNode, exec, thisObj, registerFile, registerFile->size(), scopeChain, exception, variableObject);
    612614}
    613615
  • branches/squirrelfish/JavaScriptCore/VM/Machine.h

    r32194 r32290  
    8181        JSValue* execute(ProgramNode*, ExecState*, JSObject* thisObj, RegisterFileStack*, ScopeChain*, JSValue** exception);
    8282        JSValue* execute(FunctionBodyNode*, const List& args, JSObject* thisObj, ExecState*, RegisterFileStack*, ScopeChain*, JSValue** exception);
    83         JSValue* execute(EvalNode*, ExecState*, JSObject* thisObj, RegisterFile*, int registerOffset, ScopeChainNode*, JSValue** exception);
    84         JSValue* execute(EvalNode*, ExecState*, JSObject* thisObj, RegisterFileStack*, ScopeChainNode*, JSValue** exception);
     83        JSValue* execute(EvalNode*, ExecState*, JSObject* thisObj, RegisterFile*, int registerOffset, ScopeChainNode*, JSValue** exception, JSObject* variableObject = 0);
     84        JSValue* execute(EvalNode*, ExecState*, JSObject* thisObj, RegisterFileStack*, ScopeChainNode*, JSValue** exception, JSObject* variableObject);
    8585       
    8686    private:
  • branches/squirrelfish/JavaScriptCore/kjs/function.cpp

    r32289 r32290  
    724724
    725725    JSValue* exception = 0;
    726     JSValue* value = machine().execute(evalNode.get(), &newExec, thisObj, &newExec.dynamicGlobalObject()->registerFileStack(), scopeChain.node(), &exception);
     726    JSValue* value = machine().execute(evalNode.get(), &newExec, thisObj, &newExec.dynamicGlobalObject()->registerFileStack(), scopeChain.node(), &exception, globalObject);
    727727
    728728#if JAVASCRIPT_PROFILING
  • branches/squirrelfish/JavaScriptCore/kjs/nodes.cpp

    r32289 r32290  
    56775677    ASSERT(globalObject->isGlobalObject());
    56785678   
    5679     m_code.set(new ProgramCodeBlock(sourceURL(), usesEval(), needsClosure(), globalObject));
     5679    m_code.set(new EvalCodeBlock(sourceURL(), usesEval(), needsClosure(), globalObject));
    56805680   
    5681     CodeGenerator generator(this, scopeChain, new SymbolTable(), m_code.get());
     5681    CodeGenerator generator(this, scopeChain, new SymbolTable(), m_code.get(), m_varStack);
    56825682    generator.generate();
    56835683
  • branches/squirrelfish/JavaScriptCore/kjs/nodes.h

    r32289 r32290  
    5151    class FuncDeclNode;
    5252    class Node;
     53    class EvalCodeBlock;
    5354    class ProgramCodeBlock;
    5455    class PropertyListNode;
     
    29872988        virtual JSValue* execute(ExecState*) KJS_FAST_CALL;
    29882989
    2989         ProgramCodeBlock& code(ScopeChainNode* scopeChain) KJS_FAST_CALL
     2990        EvalCodeBlock& code(ScopeChainNode* scopeChain) KJS_FAST_CALL
    29902991        {
    29912992            if (!m_code)
     
    30013002        virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
    30023003
    3003         OwnPtr<ProgramCodeBlock> m_code;
     3004        OwnPtr<EvalCodeBlock> m_code;
    30043005    };
    30053006
Note: See TracChangeset for help on using the changeset viewer.