Ignore:
Timestamp:
Oct 19, 2008, 10:58:02 PM (17 years ago)
Author:
Darin Adler
Message:

2008-10-19 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Change JSValuePtr from a typedef into a class. This allows us to support
conversion from JSCell* to JSValuePtr even if JSCell isn't derived from
JSValue.

  • JavaScriptCore.exp: Updated symbols that involve JSValuePtr, since it's now a distinct type.
  • API/APICast.h: (toRef): Extract the JSValuePtr payload explicitly since we can't just cast any more.
  • VM/CTI.cpp: (JSC::CTI::asInteger): Ditto.
  • VM/CodeGenerator.cpp: (JSC::CodeGenerator::addConstant): Get at the payload directly. (JSC::CodeGenerator::emitLoad): Added an overload of JSCell* because otherwise classes derived from JSValue end up calling the bool overload instead of JSValuePtr.
  • VM/CodeGenerator.h: Ditto. Also update traits to use JSValue* and the payload functions.
  • VM/Register.h: Added a JSCell* overload and use of payload functions.
  • kjs/JSCell.h: (JSC::asCell): Use payload function. (JSC::JSValue::asCell): Use JSValue* instead of JSValuePtr. (JSC::JSValuePtr::JSValuePtr): Added. Constructor that takes JSCell* and creates a JSValuePtr.
  • kjs/JSImmediate.h: Added JSValuePtr class. Also updated makeValue and makeInt to work with JSValue* and the payload function.
  • kjs/JSValue.h: Added == and != operators for JSValuePtr. Put them here because eventually all the JSValue functions should go here except what's needed by JSImmediate. Also fix asValue to use JSValue* instead of JSValuePtr.
  • kjs/PropertySlot.h: Change constructor to take JSValuePtr.
  • kjs/protect.h: Update gcProtect functions to work with JSCell* as well as JSValuePtr. Also updated the ProtectedPtr<JSValuePtr> specialization to work more directly. Also changed all the call sites to use gcProtectNullTolerant.
File:
1 edited

Legend:

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

    r37684 r37712  
    3535
    3636    class ExecState;
     37    class JSCell;
    3738    class JSObject;
    3839    class JSValue;
    3940    class UString;
    4041
    41     typedef JSValue* JSValuePtr;
    42 
    43     inline JSValuePtr noValue() { return 0; }
    44     inline void* asPointer(JSValuePtr value) { return value; }
     42    class JSValuePtr {
     43    public:
     44        JSValuePtr() { } // uninitialized (not zero)
     45        JSValuePtr(const JSValue* payload) : m_payload(const_cast<JSValue*>(payload)) { }
     46        JSValuePtr(const JSCell*);
     47
     48        JSValue* payload() const { return m_payload; }
     49        JSValue** payloadPtr() { return &m_payload; }
     50
     51        bool operator!() const { return !payload(); }
     52   
     53        // This conversion operator allows implicit conversion to bool but not to other integer types.
     54        typedef JSValue* JSValuePtr::*UnspecifiedBoolType;
     55        operator UnspecifiedBoolType() const { return payload() ? &JSValuePtr::m_payload : 0; }
     56
     57        JSValue* operator->() const { return payload(); }
     58
     59    private:
     60        JSValue* m_payload;
     61    };
     62
     63    inline JSValuePtr noValue() { return static_cast<JSValue*>(0); }
     64    inline void* asPointer(JSValuePtr value) { return value.payload(); }
    4565
    4666    /*
     
    262282        static ALWAYS_INLINE JSValuePtr makeValue(uintptr_t integer)
    263283        {
    264             return reinterpret_cast<JSValuePtr>(integer);
     284            return reinterpret_cast<JSValue*>(integer);
    265285        }
    266286
     
    302322        static ALWAYS_INLINE uintptr_t rawValue(JSValuePtr v)
    303323        {
    304             return reinterpret_cast<uintptr_t>(v);
     324            return reinterpret_cast<uintptr_t>(v.payload());
    305325        }
    306326
Note: See TracChangeset for help on using the changeset viewer.