Changeset 33326

Show
Ignore:
Timestamp:
05/12/08 23:03:27 (6 months ago)
Author:
mrowe@apple.com
Message:

Bug 18864: SquirrelFish: Support getter and setter definition in object literals
<https://bugs.webkit.org/show_bug.cgi?id=18864>

Reviewed by Maciej

Add new opcodes to allow us to add getters and setters to an object. These are
only used by the codegen for object literals.

Location:
branches/squirrelfish/JavaScriptCore
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branches/squirrelfish/JavaScriptCore/ChangeLog

    r33325 r33326  
     12008-05-03  Oliver Hunt  <oliver@apple.com> 
     2 
     3        Reviewed by Maciej. 
     4 
     5        Bug 18864: SquirrelFish: Support getter and setter definition in object literals 
     6        <https://bugs.webkit.org/show_bug.cgi?id=18864> 
     7 
     8        Add new opcodes to allow us to add getters and setters to an object.  These are 
     9        only used by the codegen for object literals. 
     10 
     11        * VM/CodeGenerator.cpp: 
     12        (KJS::CodeGenerator::emitPutGetter): 
     13        (KJS::CodeGenerator::emitPutSetter): 
     14        * VM/CodeGenerator.h: 
     15        * VM/Machine.cpp: 
     16        (KJS::Machine::privateExecute): 
     17        * VM/Opcode.h: 
     18        * kjs/nodes.cpp: 
     19        (KJS::PropertyListNode::emitCode): 
     20 
    1212008-05-02  Maciej Stachowiak  <mjs@apple.com> 
    222 
  • branches/squirrelfish/JavaScriptCore/VM/CodeGenerator.cpp

    r33314 r33326  
    752752} 
    753753 
     754RegisterID* CodeGenerator::emitPutGetter(RegisterID* base, const Identifier& property, RegisterID* value) 
     755{ 
     756    instructions().append(machine().getOpcode(op_put_getter)); 
     757    instructions().append(base->index()); 
     758    instructions().append(addConstant(property)); 
     759    instructions().append(value->index()); 
     760    return value; 
     761} 
     762 
     763RegisterID* CodeGenerator::emitPutSetter(RegisterID* base, const Identifier& property, RegisterID* value) 
     764{ 
     765    instructions().append(machine().getOpcode(op_put_setter)); 
     766    instructions().append(base->index()); 
     767    instructions().append(addConstant(property)); 
     768    instructions().append(value->index()); 
     769    return value; 
     770} 
     771 
    754772RegisterID* CodeGenerator::emitDeletePropId(RegisterID* dst, RegisterID* base, const Identifier& property) 
    755773{ 
  • branches/squirrelfish/JavaScriptCore/VM/CodeGenerator.h

    r33305 r33326  
    202202        RegisterID* emitDeletePropVal(RegisterID* dst, RegisterID* base, RegisterID* property); 
    203203        RegisterID* emitPutPropIndex(RegisterID* base, unsigned index, RegisterID* value); 
     204        RegisterID* emitPutGetter(RegisterID* base, const Identifier& property, RegisterID* value); 
     205        RegisterID* emitPutSetter(RegisterID* base, const Identifier& property, RegisterID* value); 
    204206 
    205207        RegisterID* emitCall(RegisterID*, RegisterID*, RegisterID*, ArgumentsNode*); 
  • branches/squirrelfish/JavaScriptCore/VM/Machine.cpp

    r33324 r33326  
    17091709        return r[r0].u.jsValue; 
    17101710    } 
     1711    BEGIN_OPCODE(op_put_getter) { 
     1712        /* put_getter base(r) property(id) function(r) 
     1713          
     1714           Sets register function on register base as the getter named 
     1715           by identifier property. Base and function are assumed to be 
     1716           objects as this op should only be used for getters defined 
     1717           in object literal form. 
     1718          
     1719           Unlike many opcodes, this one does not write any output to 
     1720           the register file. 
     1721         */ 
     1722         
     1723        int base = (++vPC)->u.operand; 
     1724        int property = (++vPC)->u.operand; 
     1725        int function = (++vPC)->u.operand; 
     1726         
     1727        ASSERT(r[base].u.jsValue->isObject()); 
     1728        JSObject* baseObj = static_cast<JSObject*>(r[base].u.jsValue); 
     1729        Identifier& ident = codeBlock->identifiers[property]; 
     1730        ASSERT(r[function].u.jsValue->isObject()); 
     1731        baseObj->defineGetter(exec, ident, static_cast<JSObject* >(r[function].u.jsValue)); 
     1732 
     1733        ++vPC; 
     1734        NEXT_OPCODE; 
     1735    } 
     1736    BEGIN_OPCODE(op_put_setter) { 
     1737        /* put_setter base(r) property(id) function(r) 
     1738          
     1739         Sets register function on register base as the setter named 
     1740         by identifier property. Base and function are assumed to be 
     1741         objects as this op should only be used for setters defined 
     1742         in object literal form. 
     1743          
     1744         Unlike many opcodes, this one does not write any output to 
     1745         the register file. 
     1746         */ 
     1747         
     1748        int base = (++vPC)->u.operand; 
     1749        int property = (++vPC)->u.operand; 
     1750        int function = (++vPC)->u.operand; 
     1751         
     1752        ASSERT(r[base].u.jsValue->isObject()); 
     1753        JSObject* baseObj = static_cast<JSObject*>(r[base].u.jsValue); 
     1754        Identifier& ident = codeBlock->identifiers[property]; 
     1755        ASSERT(r[function].u.jsValue->isObject()); 
     1756        baseObj->defineSetter(exec, ident, static_cast<JSObject* >(r[function].u.jsValue)); 
     1757         
     1758        ++vPC; 
     1759        NEXT_OPCODE; 
     1760    } 
    17111761    BEGIN_OPCODE(op_jsr) { 
    17121762        /* jsr retAddrDst(r) target(offset) 
  • branches/squirrelfish/JavaScriptCore/VM/Opcode.h

    r33231 r33326  
    8787        macro(op_delete_prop_val) \ 
    8888        macro(op_put_prop_index) \ 
     89        macro(op_put_getter) \ 
     90        macro(op_put_setter) \ 
    8991        \ 
    9092        macro(op_jmp) \ 
  • branches/squirrelfish/JavaScriptCore/kjs/nodes.cpp

    r33306 r33326  
    963963                break; 
    964964            } 
    965             // FIXME: No support for getters and setters yet, as it caused a performance regression 
     965            case PropertyNode::Getter: { 
     966                generator.emitPutGetter(newObj.get(), p->m_node->name(), value); 
     967                break; 
     968            } 
     969            case PropertyNode::Setter: { 
     970                generator.emitPutSetter(newObj.get(), p->m_node->name(), value); 
     971                break; 
     972            } 
    966973            default: 
    967974                ASSERT_NOT_REACHED();