source: webkit/trunk/JavaScriptCore/runtime/JSCell.cpp@ 42478

Last change on this file since 42478 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: 5.6 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 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#include "config.h"
24#include "JSCell.h"
25
26#include "JSFunction.h"
27#include "JSString.h"
28#include "JSObject.h"
29#include <wtf/MathExtras.h>
30
31namespace JSC {
32
33#if defined NAN && defined INFINITY
34
35extern const double NaN = NAN;
36extern const double Inf = INFINITY;
37
38#else // !(defined NAN && defined INFINITY)
39
40// The trick is to define the NaN and Inf globals with a different type than the declaration.
41// This trick works because the mangled name of the globals does not include the type, although
42// I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
43// characters don't necessarily need the same alignment doubles do, but for now it seems to work.
44// It would be good to figure out a 100% clean way that still avoids code that runs at init time.
45
46// Note, we have to use union to ensure alignment. Otherwise, NaN_Bytes can start anywhere,
47// while NaN_double has to be 4-byte aligned for 32-bits.
48// With -fstrict-aliasing enabled, unions are the only safe way to do type masquerading.
49
50static const union {
51 struct {
52 unsigned char NaN_Bytes[8];
53 unsigned char Inf_Bytes[8];
54 } bytes;
55
56 struct {
57 double NaN_Double;
58 double Inf_Double;
59 } doubles;
60
61} NaNInf = { {
62#if PLATFORM(BIG_ENDIAN)
63 { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 },
64 { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
65#elif PLATFORM(MIDDLE_ENDIAN)
66 { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 },
67 { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 }
68#else
69 { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f },
70 { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }
71#endif
72} } ;
73
74extern const double NaN = NaNInf.doubles.NaN_Double;
75extern const double Inf = NaNInf.doubles.Inf_Double;
76
77#endif // !(defined NAN && defined INFINITY)
78
79void* JSCell::operator new(size_t size, ExecState* exec)
80{
81#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
82 return exec->heap()->inlineAllocate(size);
83#else
84 return exec->heap()->allocate(size);
85#endif
86}
87
88bool JSCell::getUInt32(uint32_t&) const
89{
90 return false;
91}
92
93bool JSCell::getTruncatedInt32(int32_t&) const
94{
95 return false;
96}
97
98bool JSCell::getTruncatedUInt32(uint32_t&) const
99{
100 return false;
101}
102
103bool JSCell::getString(UString&stringValue) const
104{
105 if (!isString())
106 return false;
107 stringValue = static_cast<const JSString*>(this)->value();
108 return true;
109}
110
111UString JSCell::getString() const
112{
113 return isString() ? static_cast<const JSString*>(this)->value() : UString();
114}
115
116JSObject* JSCell::getObject()
117{
118 return isObject() ? static_cast<JSObject*>(this) : 0;
119}
120
121const JSObject* JSCell::getObject() const
122{
123 return isObject() ? static_cast<const JSObject*>(this) : 0;
124}
125
126CallType JSCell::getCallData(CallData&)
127{
128 return CallTypeNone;
129}
130
131ConstructType JSCell::getConstructData(ConstructData&)
132{
133 return ConstructTypeNone;
134}
135
136bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
137{
138 // This is not a general purpose implementation of getOwnPropertySlot.
139 // It should only be called by JSValue::get.
140 // It calls getPropertySlot, not getOwnPropertySlot.
141 JSObject* object = toObject(exec);
142 slot.setBase(object);
143 if (!object->getPropertySlot(exec, identifier, slot))
144 slot.setUndefined();
145 return true;
146}
147
148bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
149{
150 // This is not a general purpose implementation of getOwnPropertySlot.
151 // It should only be called by JSValue::get.
152 // It calls getPropertySlot, not getOwnPropertySlot.
153 JSObject* object = toObject(exec);
154 slot.setBase(object);
155 if (!object->getPropertySlot(exec, identifier, slot))
156 slot.setUndefined();
157 return true;
158}
159
160void JSCell::put(ExecState* exec, const Identifier& identifier, JSValuePtr value, PutPropertySlot& slot)
161{
162 toObject(exec)->put(exec, identifier, value, slot);
163}
164
165void JSCell::put(ExecState* exec, unsigned identifier, JSValuePtr value)
166{
167 toObject(exec)->put(exec, identifier, value);
168}
169
170bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
171{
172 return toObject(exec)->deleteProperty(exec, identifier);
173}
174
175bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
176{
177 return toObject(exec)->deleteProperty(exec, identifier);
178}
179
180JSObject* JSCell::toThisObject(ExecState* exec) const
181{
182 return toObject(exec);
183}
184
185UString JSCell::toThisString(ExecState* exec) const
186{
187 return toThisObject(exec)->toString(exec);
188}
189
190JSString* JSCell::toThisJSString(ExecState* exec)
191{
192 return jsString(exec, toThisString(exec));
193}
194
195const ClassInfo* JSCell::classInfo() const
196{
197 return 0;
198}
199
200JSValuePtr JSCell::getJSNumber()
201{
202 return noValue();
203}
204
205bool JSCell::isGetterSetter() const
206{
207 return false;
208}
209
210} // namespace JSC
Note: See TracBrowser for help on using the repository browser.