Changeset 35027 in webkit for trunk/JavaScriptCore/kjs/JSNumberCell.h
- Timestamp:
- Jul 6, 2008, 7:49:29 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSNumberCell.h
r34921 r35027 35 35 namespace KJS { 36 36 37 class ExecState;38 class Identifier;39 class JSCell;40 class JSObject;41 class JSString;42 class PropertySlot;37 class ExecState; 38 class Identifier; 39 class JSCell; 40 class JSObject; 41 class JSString; 42 class PropertySlot; 43 43 44 struct ClassInfo;45 struct Instruction;44 struct ClassInfo; 45 struct Instruction; 46 46 47 class JSNumberCell : public JSCell {48 friend JSValue* jsNumberCell(ExecState*, double);49 public:50 double value() const { return val; }47 class JSNumberCell : public JSCell { 48 friend JSValue* jsNumberCell(ExecState*, double); 49 public: 50 double value() const { return m_value; } 51 51 52 virtual JSType type() const;52 virtual JSType type() const; 53 53 54 virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;55 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);56 virtual bool toBoolean(ExecState*) const;57 virtual double toNumber(ExecState*) const;58 virtual UString toString(ExecState*) const;59 virtual JSObject* toObject(ExecState*) const;54 virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const; 55 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 56 virtual bool toBoolean(ExecState*) const; 57 virtual double toNumber(ExecState*) const; 58 virtual UString toString(ExecState*) const; 59 virtual JSObject* toObject(ExecState*) const; 60 60 61 virtual UString toThisString(ExecState*) const;62 virtual JSObject* toThisObject(ExecState*) const;63 virtual JSValue* getJSNumber();61 virtual UString toThisString(ExecState*) const; 62 virtual JSObject* toThisObject(ExecState*) const; 63 virtual JSValue* getJSNumber(); 64 64 65 void* operator new(size_t size, ExecState* exec) 65 void* operator new(size_t size, ExecState* exec) 66 { 67 #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE 68 return exec->heap()->inlineAllocateNumber(size); 69 #else 70 return exec->heap()->allocateNumber(size); 71 #endif 72 } 73 74 private: 75 JSNumberCell(double value) 76 : m_value(value) 77 { 78 } 79 80 virtual bool getUInt32(uint32_t&) const; 81 virtual bool getTruncatedInt32(int32_t&) const; 82 virtual bool getTruncatedUInt32(uint32_t&) const; 83 84 double m_value; 85 }; 86 87 extern const double NaN; 88 extern const double Inf; 89 90 // Beware marking this function ALWAYS_INLINE: It takes a PIC branch, so 91 // inlining it may not always be a win. 92 inline JSValue* jsNumberCell(ExecState* exec, double d) 66 93 { 67 #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE 68 return exec->heap()->inlineAllocateNumber(size); 69 #else 70 return exec->heap()->allocateNumber(size); 71 #endif 94 return new (exec) JSNumberCell(d); 72 95 } 73 96 74 private: 75 JSNumberCell(double v) 76 : val(v) 97 inline JSValue* jsNaN(ExecState* exec) 77 98 { 99 return jsNumberCell(exec, NaN); 78 100 } 79 101 80 virtual bool getUInt32(uint32_t&) const; 81 virtual bool getTruncatedInt32(int32_t&) const; 82 virtual bool getTruncatedUInt32(uint32_t&) const; 102 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, double d) 103 { 104 JSValue* v = JSImmediate::from(d); 105 return v ? v : jsNumberCell(exec, d); 106 } 83 107 84 double val; 85 }; 108 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, int i) 109 { 110 JSValue* v = JSImmediate::from(i); 111 return v ? v : jsNumberCell(exec, i); 112 } 86 113 87 extern const double NaN; 88 extern const double Inf; 114 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned i) 115 { 116 JSValue* v = JSImmediate::from(i); 117 return v ? v : jsNumberCell(exec, i); 118 } 89 119 90 // Beware marking this function ALWAYS_INLINE: It takes a PIC branch, so 91 // inlining it may not always be a win. 92 inline JSValue* jsNumberCell(ExecState* exec, double d) 93 { 94 return new (exec) JSNumberCell(d); 95 } 120 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long i) 121 { 122 JSValue* v = JSImmediate::from(i); 123 return v ? v : jsNumberCell(exec, i); 124 } 96 125 97 inline JSValue* jsNaN(ExecState* exec) 98 { 99 return jsNumberCell(exec, NaN); 100 } 126 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long i) 127 { 128 JSValue* v = JSImmediate::from(i); 129 return v ? v : jsNumberCell(exec, i); 130 } 101 131 102 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, double d)103 {104 JSValue* v = JSImmediate::from(d);105 return v ? v : jsNumberCell(exec, d);106 }132 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long long i) 133 { 134 JSValue* v = JSImmediate::from(i); 135 return v ? v : jsNumberCell(exec, static_cast<double>(i)); 136 } 107 137 108 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, inti)109 {110 JSValue* v = JSImmediate::from(i);111 return v ? v : jsNumberCell(exec, i);112 }138 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long long i) 139 { 140 JSValue* v = JSImmediate::from(i); 141 return v ? v : jsNumberCell(exec, static_cast<double>(i)); 142 } 113 143 114 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned i) 115 { 116 JSValue* v = JSImmediate::from(i); 117 return v ? v : jsNumberCell(exec, i); 118 } 144 // --- JSValue inlines ---------------------------- 119 145 120 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long i) 121 {122 JSValue* v = JSImmediate::from(i);123 return v ? v : jsNumberCell(exec, i);124 }146 inline double JSValue::uncheckedGetNumber() const 147 { 148 ASSERT(JSImmediate::isImmediate(this) || asCell()->isNumber()); 149 return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : static_cast<const JSNumberCell*>(this)->value(); 150 } 125 151 126 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long i) 127 { 128 JSValue* v = JSImmediate::from(i); 129 return v ? v : jsNumberCell(exec, i); 130 } 131 132 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, long long i) 133 { 134 JSValue* v = JSImmediate::from(i); 135 return v ? v : jsNumberCell(exec, static_cast<double>(i)); 136 } 137 138 ALWAYS_INLINE JSValue* jsNumber(ExecState* exec, unsigned long long i) 139 { 140 JSValue* v = JSImmediate::from(i); 141 return v ? v : jsNumberCell(exec, static_cast<double>(i)); 142 } 143 144 // --- JSValue inlines ---------------------------- 145 146 inline double JSValue::uncheckedGetNumber() const 147 { 148 ASSERT(JSImmediate::isImmediate(this) || asCell()->isNumber()); 149 return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : static_cast<const JSNumberCell*>(this)->value(); 150 } 151 152 ALWAYS_INLINE JSValue* JSValue::toJSNumber(ExecState* exec) const 153 { 154 return JSImmediate::isNumber(this) ? const_cast<JSValue*>(this) : jsNumber(exec, this->toNumber(exec)); 155 } 156 157 // ------- 152 ALWAYS_INLINE JSValue* JSValue::toJSNumber(ExecState* exec) const 153 { 154 return JSImmediate::isNumber(this) ? const_cast<JSValue*>(this) : jsNumber(exec, this->toNumber(exec)); 155 } 158 156 159 157 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.