source: webkit/trunk/JavaScriptCore/runtime/JSNumberCell.h@ 39851

Last change on this file since 39851 was 39851, checked in by [email protected], 16 years ago

JavaScriptCore:

2009-01-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Make the JSImmediate interface private.

All manipulation of JS values should be through the JSValuePtr class, not by using JSImmediate
directly. The key missing methods on JSValuePtr are:

  • isCell() - check for values that are JSCell*s, and as such where asCell() may be used.
  • isInt32Fast() getInt32Fast() - fast check/access for integer immediates.
  • isUInt32Fast() getUInt32Fast() - ditto for unsigned integer immediates.

The JIT is allowed full access to JSImmediate, since it needs to be able to directly
manipulate JSValuePtrs. The Interpreter is provided access to perform operations directly
on JSValuePtrs through the new JSFastMath interface.

No performance impact.

  • API/JSCallbackObjectFunctions.h: (JSC::::toNumber):
  • API/JSValueRef.cpp: (JSValueIsEqual): (JSValueIsStrictEqual):
  • JavaScriptCore.exp:
  • bytecode/CodeBlock.h: (JSC::CodeBlock::isKnownNotImmediate):
  • bytecompiler/BytecodeGenerator.cpp: (JSC::keyForImmediateSwitch):
  • bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::JSValueHashTraits::constructDeletedValue): (JSC::BytecodeGenerator::JSValueHashTraits::isDeletedValue):
  • interpreter/Interpreter.cpp: (JSC::jsLess): (JSC::jsLessEq): (JSC::jsAdd): (JSC::jsIsObjectType): (JSC::cachePrototypeChain): (JSC::Interpreter::tryCachePutByID): (JSC::Interpreter::tryCacheGetByID): (JSC::Interpreter::privateExecute): (JSC::Interpreter::tryCTICachePutByID): (JSC::Interpreter::tryCTICacheGetByID): (JSC::Interpreter::cti_op_add): (JSC::Interpreter::cti_op_get_by_id_self_fail): (JSC::Interpreter::cti_op_get_by_id_proto_list): (JSC::Interpreter::cti_op_instanceof): (JSC::Interpreter::cti_op_mul): (JSC::Interpreter::cti_op_get_by_val): (JSC::Interpreter::cti_op_get_by_val_byte_array): (JSC::Interpreter::cti_op_sub): (JSC::Interpreter::cti_op_put_by_val): (JSC::Interpreter::cti_op_put_by_val_array): (JSC::Interpreter::cti_op_put_by_val_byte_array): (JSC::Interpreter::cti_op_negate): (JSC::Interpreter::cti_op_div): (JSC::Interpreter::cti_op_eq): (JSC::Interpreter::cti_op_lshift): (JSC::Interpreter::cti_op_bitand): (JSC::Interpreter::cti_op_rshift): (JSC::Interpreter::cti_op_bitnot): (JSC::Interpreter::cti_op_neq): (JSC::Interpreter::cti_op_urshift): (JSC::Interpreter::cti_op_call_eval): (JSC::Interpreter::cti_op_throw): (JSC::Interpreter::cti_op_is_undefined): (JSC::Interpreter::cti_op_stricteq): (JSC::Interpreter::cti_op_nstricteq): (JSC::Interpreter::cti_op_switch_imm): (JSC::Interpreter::cti_vm_throw):
  • interpreter/Interpreter.h: (JSC::Interpreter::isJSArray): (JSC::Interpreter::isJSString): (JSC::Interpreter::isJSByteArray):
  • jit/JIT.cpp: (JSC::JIT::compileOpStrictEq): (JSC::JIT::privateCompileMainPass):
  • jit/JIT.h: (JSC::JIT::isStrictEqCaseHandledInJITCode):
  • jit/JITArithmetic.cpp: (JSC::JIT::compileFastArith_op_rshift): (JSC::JIT::compileFastArith_op_bitand): (JSC::JIT::compileFastArith_op_mod):
  • jit/JITCall.cpp: (JSC::JIT::unlinkCall): (JSC::JIT::compileOpCall):
  • jit/JITInlineMethods.h: (JSC::JIT::getConstantOperandImmediateInt): (JSC::JIT::isOperandConstantImmediateInt):
  • parser/Nodes.cpp: (JSC::processClauseList):
  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncIndexOf): (JSC::arrayProtoFuncLastIndexOf):
  • runtime/BooleanPrototype.cpp: (JSC::booleanProtoFuncValueOf):
  • runtime/Collector.cpp: (JSC::Heap::protect): (JSC::Heap::unprotect): (JSC::Heap::heap):
  • runtime/JSByteArray.cpp: (JSC::JSByteArray::getOwnPropertySlot):
  • runtime/JSByteArray.h: (JSC::JSByteArray::getIndex):
  • runtime/JSCell.cpp:
  • runtime/JSCell.h: (JSC::JSValuePtr::isNumberCell): (JSC::JSValuePtr::asCell): (JSC::JSValuePtr::isNumber):
  • runtime/JSGlobalObjectFunctions.cpp: (JSC::globalFuncParseInt):
  • runtime/JSImmediate.h: (JSC::js0): (JSC::jsImpossibleValue): (JSC::JSValuePtr::toInt32): (JSC::JSValuePtr::toUInt32): (JSC::JSValuePtr::isCell): (JSC::JSValuePtr::isInt32Fast): (JSC::JSValuePtr::getInt32Fast): (JSC::JSValuePtr::isUInt32Fast): (JSC::JSValuePtr::getUInt32Fast): (JSC::JSValuePtr::makeInt32Fast): (JSC::JSValuePtr::areBothInt32Fast): (JSC::JSFastMath::canDoFastBitwiseOperations): (JSC::JSFastMath::equal): (JSC::JSFastMath::notEqual): (JSC::JSFastMath::andImmediateNumbers): (JSC::JSFastMath::xorImmediateNumbers): (JSC::JSFastMath::orImmediateNumbers): (JSC::JSFastMath::canDoFastRshift): (JSC::JSFastMath::canDoFastUrshift): (JSC::JSFastMath::rightShiftImmediateNumbers): (JSC::JSFastMath::canDoFastAdditiveOperations): (JSC::JSFastMath::addImmediateNumbers): (JSC::JSFastMath::subImmediateNumbers): (JSC::JSFastMath::incImmediateNumber): (JSC::JSFastMath::decImmediateNumber):
  • runtime/JSNumberCell.h: (JSC::JSValuePtr::asNumberCell): (JSC::jsNumber): (JSC::JSValuePtr::uncheckedGetNumber): (JSC::JSNumberCell::toInt32): (JSC::JSNumberCell::toUInt32): (JSC::JSValuePtr::toJSNumber): (JSC::JSValuePtr::getNumber): (JSC::JSValuePtr::numberToInt32): (JSC::JSValuePtr::numberToUInt32):
  • runtime/JSObject.h: (JSC::JSValuePtr::isObject): (JSC::JSValuePtr::get): (JSC::JSValuePtr::put):
  • runtime/JSValue.cpp: (JSC::JSValuePtr::toInteger): (JSC::JSValuePtr::toIntegerPreserveNaN):
  • runtime/JSValue.h:
  • runtime/Operations.cpp: (JSC::JSValuePtr::equalSlowCase): (JSC::JSValuePtr::strictEqualSlowCase):
  • runtime/Operations.h: (JSC::JSValuePtr::equal): (JSC::JSValuePtr::equalSlowCaseInline): (JSC::JSValuePtr::strictEqual): (JSC::JSValuePtr::strictEqualSlowCaseInline):
  • runtime/Protect.h: (JSC::gcProtect): (JSC::gcUnprotect):
  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncCharAt): (JSC::stringProtoFuncCharCodeAt):
  • runtime/Structure.cpp: (JSC::Structure::createCachedPrototypeChain):

WebCore:

2009-01-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Deprecate JSValuePtr::getNumber() - two ways to get a number should be enough.

  • bindings/js/JSSQLTransactionCustom.cpp: (WebCore::JSSQLTransaction::executeSql):
  • bindings/objc/WebScriptObject.mm: (+[WebScriptObject _convertValueToObjcValue:originRootObject:rootObject:]):

WebKit/mac:

2009-01-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Deprecate JSValuePtr::getNumber() - two ways to get a number should be enough.

  • WebView/WebView.mm: (aeDescFromJSValue):
  • Property svn:eol-style set to native
File size: 9.5 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef JSNumberCell_h
24#define JSNumberCell_h
25
26#include "CallFrame.h"
27#include "JSCell.h"
28#include "JSImmediate.h"
29#include "Collector.h"
30#include "UString.h"
31#include <stddef.h> // for size_t
32
33namespace JSC {
34
35 class Identifier;
36 class JSCell;
37 class JSObject;
38 class JSString;
39 class PropertySlot;
40
41 struct ClassInfo;
42 struct Instruction;
43
44 class JSNumberCell : public JSCell {
45 friend class JIT;
46 friend JSValuePtr jsNumberCell(JSGlobalData*, double);
47 friend JSValuePtr jsNaN(JSGlobalData*);
48 friend JSValuePtr jsNumberCell(ExecState*, double);
49 friend JSValuePtr jsNaN(ExecState*);
50 public:
51 double value() const { return m_value; }
52
53 virtual JSValuePtr toPrimitive(ExecState*, PreferredPrimitiveType) const;
54 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValuePtr& value);
55 virtual bool toBoolean(ExecState*) const;
56 virtual double toNumber(ExecState*) const;
57 virtual UString toString(ExecState*) const;
58 virtual JSObject* toObject(ExecState*) const;
59
60 virtual UString toThisString(ExecState*) const;
61 virtual JSObject* toThisObject(ExecState*) const;
62 virtual JSValuePtr getJSNumber();
63
64 int32_t toInt32() const;
65 uint32_t toUInt32() const;
66
67 void* operator new(size_t size, ExecState* exec)
68 {
69 #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
70 return exec->heap()->inlineAllocateNumber(size);
71 #else
72 return exec->heap()->allocateNumber(size);
73 #endif
74 }
75
76 void* operator new(size_t size, JSGlobalData* globalData)
77 {
78 #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
79 return globalData->heap.inlineAllocateNumber(size);
80 #else
81 return globalData->heap.allocateNumber(size);
82 #endif
83 }
84
85 static PassRefPtr<Structure> createStructure(JSValuePtr proto) { return Structure::create(proto, TypeInfo(NumberType, NeedsThisConversion)); }
86
87 private:
88 JSNumberCell(JSGlobalData* globalData, double value)
89 : JSCell(globalData->numberStructure.get())
90 , m_value(value)
91 {
92 }
93
94 JSNumberCell(ExecState* exec, double value)
95 : JSCell(exec->globalData().numberStructure.get())
96 , m_value(value)
97 {
98 }
99
100 virtual bool getUInt32(uint32_t&) const;
101 virtual bool getTruncatedInt32(int32_t&) const;
102 virtual bool getTruncatedUInt32(uint32_t&) const;
103
104 double m_value;
105 };
106
107 extern const double NaN;
108 extern const double Inf;
109
110 JSValuePtr jsNumberCell(JSGlobalData*, double);
111 JSValuePtr jsNaN(JSGlobalData*);
112 JSValuePtr jsNumberCell(ExecState*, double);
113 JSValuePtr jsNaN(ExecState*);
114
115 inline JSNumberCell* JSValuePtr::asNumberCell() const
116 {
117 ASSERT(isNumberCell());
118 return static_cast<JSNumberCell*>(asCell());
119 }
120
121 ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, double d)
122 {
123 JSValuePtr v = JSImmediate::from(d);
124 return v ? v : jsNumberCell(exec, d);
125 }
126
127 ALWAYS_INLINE JSValuePtr jsNumber(ExecState*, char i)
128 {
129 ASSERT(JSImmediate::from(i));
130 return JSImmediate::from(i);
131 }
132
133 ALWAYS_INLINE JSValuePtr jsNumber(ExecState*, unsigned char i)
134 {
135 ASSERT(JSImmediate::from(i));
136 return JSImmediate::from(i);
137 }
138
139 ALWAYS_INLINE JSValuePtr jsNumber(ExecState*, short i)
140 {
141 ASSERT(JSImmediate::from(i));
142 return JSImmediate::from(i);
143 }
144
145 ALWAYS_INLINE JSValuePtr jsNumber(ExecState*, unsigned short i)
146 {
147 ASSERT(JSImmediate::from(i));
148 return JSImmediate::from(i);
149 }
150
151 ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, int i)
152 {
153 JSValuePtr v = JSImmediate::from(i);
154 return v ? v : jsNumberCell(exec, i);
155 }
156
157 ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, unsigned i)
158 {
159 JSValuePtr v = JSImmediate::from(i);
160 return v ? v : jsNumberCell(exec, i);
161 }
162
163 ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, long i)
164 {
165 JSValuePtr v = JSImmediate::from(i);
166 return v ? v : jsNumberCell(exec, i);
167 }
168
169 ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, unsigned long i)
170 {
171 JSValuePtr v = JSImmediate::from(i);
172 return v ? v : jsNumberCell(exec, i);
173 }
174
175 ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, long long i)
176 {
177 JSValuePtr v = JSImmediate::from(i);
178 return v ? v : jsNumberCell(exec, static_cast<double>(i));
179 }
180
181 ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, unsigned long long i)
182 {
183 JSValuePtr v = JSImmediate::from(i);
184 return v ? v : jsNumberCell(exec, static_cast<double>(i));
185 }
186
187 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, double d)
188 {
189 JSValuePtr v = JSImmediate::from(d);
190 return v ? v : jsNumberCell(globalData, d);
191 }
192
193 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, short i)
194 {
195 JSValuePtr v = JSImmediate::from(i);
196 return v ? v : jsNumberCell(globalData, i);
197 }
198
199 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned short i)
200 {
201 JSValuePtr v = JSImmediate::from(i);
202 return v ? v : jsNumberCell(globalData, i);
203 }
204
205 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, int i)
206 {
207 JSValuePtr v = JSImmediate::from(i);
208 return v ? v : jsNumberCell(globalData, i);
209 }
210
211 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned i)
212 {
213 JSValuePtr v = JSImmediate::from(i);
214 return v ? v : jsNumberCell(globalData, i);
215 }
216
217 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, long i)
218 {
219 JSValuePtr v = JSImmediate::from(i);
220 return v ? v : jsNumberCell(globalData, i);
221 }
222
223 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long i)
224 {
225 JSValuePtr v = JSImmediate::from(i);
226 return v ? v : jsNumberCell(globalData, i);
227 }
228
229 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, long long i)
230 {
231 JSValuePtr v = JSImmediate::from(i);
232 return v ? v : jsNumberCell(globalData, static_cast<double>(i));
233 }
234
235 ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long long i)
236 {
237 JSValuePtr v = JSImmediate::from(i);
238 return v ? v : jsNumberCell(globalData, static_cast<double>(i));
239 }
240
241 // --- JSValue inlines ----------------------------
242
243 inline double JSValuePtr::uncheckedGetNumber() const
244 {
245 ASSERT(isNumber());
246 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asNumberCell()->value();
247 }
248
249 inline int32_t JSNumberCell::toInt32() const
250 {
251 if (m_value >= -2147483648.0 && m_value < 2147483648.0)
252 return static_cast<int32_t>(m_value);
253 bool ignored;
254 return toInt32SlowCase(m_value, ignored);
255 }
256
257 inline uint32_t JSNumberCell::toUInt32() const
258 {
259 if (m_value >= 0.0 && m_value < 4294967296.0)
260 return static_cast<uint32_t>(m_value);
261 bool ignored;
262 return toUInt32SlowCase(m_value, ignored);
263 }
264
265 ALWAYS_INLINE JSValuePtr JSValuePtr::toJSNumber(ExecState* exec) const
266 {
267 return isNumber() ? asValue() : jsNumber(exec, this->toNumber(exec));
268 }
269
270 inline bool JSValuePtr::getNumber(double &result) const
271 {
272 if (isInt32Fast())
273 result = getInt32Fast();
274 else if (LIKELY(isNumberCell()))
275 result = asNumberCell()->value();
276 else {
277 ASSERT(!isNumber());
278 return false;
279 }
280 return true;
281 }
282
283 inline bool JSValuePtr::numberToInt32(int32_t& arg)
284 {
285 if (isInt32Fast())
286 arg = getInt32Fast();
287 else if (LIKELY(isNumberCell()))
288 arg = asNumberCell()->toInt32();
289 else {
290 ASSERT(!isNumber());
291 return false;
292 }
293 return true;
294 }
295
296 inline bool JSValuePtr::numberToUInt32(uint32_t& arg)
297 {
298 if (isUInt32Fast())
299 arg = getUInt32Fast();
300 else if (LIKELY(isNumberCell()))
301 arg = asNumberCell()->toUInt32();
302 else if (isInt32Fast()) {
303 // FIXME: I think this case can be merged with the uint case; toUInt32SlowCase
304 // on a negative value is equivalent to simple static_casting.
305 bool ignored;
306 arg = toUInt32SlowCase(getInt32Fast(), ignored);
307 } else {
308 ASSERT(!isNumber());
309 return false;
310 }
311 return true;
312 }
313
314} // namespace JSC
315
316#endif // JSNumberCell_h
Note: See TracBrowser for help on using the repository browser.