source: webkit/trunk/JavaScriptCore/runtime/Protect.h@ 39951

Last change on this file since 39951 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: 7.1 KB
Line 
1/*
2 * Copyright (C) 2004, 2008, 2009 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21
22#ifndef Protect_h
23#define Protect_h
24
25#include "JSCell.h"
26#include "Collector.h"
27
28namespace JSC {
29
30 inline void gcProtect(JSCell* val)
31 {
32 Heap::heap(val)->protect(val);
33 }
34
35 inline void gcUnprotect(JSCell* val)
36 {
37 Heap::heap(val)->unprotect(val);
38 }
39
40 inline void gcProtectNullTolerant(JSCell* val)
41 {
42 if (val)
43 gcProtect(val);
44 }
45
46 inline void gcUnprotectNullTolerant(JSCell* val)
47 {
48 if (val)
49 gcUnprotect(val);
50 }
51
52 inline void gcProtect(JSValuePtr value)
53 {
54 if (value && value->isCell())
55 gcProtect(asCell(value));
56 }
57
58 inline void gcUnprotect(JSValuePtr value)
59 {
60 if (value && value->isCell())
61 gcUnprotect(asCell(value));
62 }
63
64 // FIXME: Share more code with RefPtr template? The only differences are the ref/deref operation
65 // and the implicit conversion to raw pointer
66 template <class T> class ProtectedPtr {
67 public:
68 ProtectedPtr() : m_ptr(0) {}
69 ProtectedPtr(T* ptr);
70 ProtectedPtr(const ProtectedPtr&);
71 ~ProtectedPtr();
72
73 template <class U> ProtectedPtr(const ProtectedPtr<U>&);
74
75 T* get() const { return m_ptr; }
76 operator T*() const { return m_ptr; }
77 operator JSValuePtr() const { return JSValuePtr(m_ptr); }
78 T* operator->() const { return m_ptr; }
79
80 operator bool() const { return m_ptr; }
81 bool operator!() const { return !m_ptr; }
82
83 ProtectedPtr& operator=(const ProtectedPtr&);
84 ProtectedPtr& operator=(T*);
85
86 private:
87 T* m_ptr;
88 };
89
90 class ProtectedJSValuePtr {
91 public:
92 ProtectedJSValuePtr() {}
93 ProtectedJSValuePtr(JSValuePtr value);
94 ProtectedJSValuePtr(const ProtectedJSValuePtr&);
95 ~ProtectedJSValuePtr();
96
97 template <class U> ProtectedJSValuePtr(const ProtectedPtr<U>&);
98
99 JSValuePtr get() const { return m_value; }
100 operator JSValuePtr() const { return m_value; }
101 JSValuePtr operator->() const { return m_value; }
102
103 operator bool() const { return m_value; }
104 bool operator!() const { return !m_value; }
105
106 ProtectedJSValuePtr& operator=(const ProtectedJSValuePtr&);
107 ProtectedJSValuePtr& operator=(JSValuePtr);
108
109 private:
110 JSValuePtr m_value;
111 };
112
113 template <class T> inline ProtectedPtr<T>::ProtectedPtr(T* ptr)
114 : m_ptr(ptr)
115 {
116 gcProtectNullTolerant(m_ptr);
117 }
118
119 template <class T> inline ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr& o)
120 : m_ptr(o.get())
121 {
122 gcProtectNullTolerant(m_ptr);
123 }
124
125 template <class T> inline ProtectedPtr<T>::~ProtectedPtr()
126 {
127 gcUnprotectNullTolerant(m_ptr);
128 }
129
130 template <class T> template <class U> inline ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr<U>& o)
131 : m_ptr(o.get())
132 {
133 gcProtectNullTolerant(m_ptr);
134 }
135
136 template <class T> inline ProtectedPtr<T>& ProtectedPtr<T>::operator=(const ProtectedPtr<T>& o)
137 {
138 T* optr = o.m_ptr;
139 gcProtectNullTolerant(optr);
140 gcUnprotectNullTolerant(m_ptr);
141 m_ptr = optr;
142 return *this;
143 }
144
145 template <class T> inline ProtectedPtr<T>& ProtectedPtr<T>::operator=(T* optr)
146 {
147 gcProtectNullTolerant(optr);
148 gcUnprotectNullTolerant(m_ptr);
149 m_ptr = optr;
150 return *this;
151 }
152
153 inline ProtectedJSValuePtr::ProtectedJSValuePtr(JSValuePtr value)
154 : m_value(value)
155 {
156 gcProtect(m_value);
157 }
158
159 inline ProtectedJSValuePtr::ProtectedJSValuePtr(const ProtectedJSValuePtr& o)
160 : m_value(o.get())
161 {
162 gcProtect(m_value);
163 }
164
165 inline ProtectedJSValuePtr::~ProtectedJSValuePtr()
166 {
167 gcUnprotect(m_value);
168 }
169
170 template <class U> ProtectedJSValuePtr::ProtectedJSValuePtr(const ProtectedPtr<U>& o)
171 : m_value(o.get())
172 {
173 gcProtect(m_value);
174 }
175
176 inline ProtectedJSValuePtr& ProtectedJSValuePtr::operator=(const ProtectedJSValuePtr& o)
177 {
178 JSValuePtr ovalue = o.m_value;
179 gcProtect(ovalue);
180 gcUnprotect(m_value);
181 m_value = ovalue;
182 return *this;
183 }
184
185 inline ProtectedJSValuePtr& ProtectedJSValuePtr::operator=(JSValuePtr ovalue)
186 {
187 gcProtect(ovalue);
188 gcUnprotect(m_value);
189 m_value = ovalue;
190 return *this;
191 }
192
193 template <class T> inline bool operator==(const ProtectedPtr<T>& a, const ProtectedPtr<T>& b) { return a.get() == b.get(); }
194 template <class T> inline bool operator==(const ProtectedPtr<T>& a, const T* b) { return a.get() == b; }
195 template <class T> inline bool operator==(const T* a, const ProtectedPtr<T>& b) { return a == b.get(); }
196
197 template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const ProtectedPtr<T>& b) { return a.get() != b.get(); }
198 template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const T* b) { return a.get() != b; }
199 template <class T> inline bool operator!=(const T* a, const ProtectedPtr<T>& b) { return a != b.get(); }
200
201 inline bool operator==(const ProtectedJSValuePtr& a, const ProtectedJSValuePtr& b) { return a.get() == b.get(); }
202 inline bool operator==(const ProtectedJSValuePtr& a, const JSValuePtr b) { return a.get() == b; }
203 template <class T> inline bool operator==(const ProtectedJSValuePtr& a, const ProtectedPtr<T>& b) { return a.get() == JSValuePtr(b.get()); }
204 inline bool operator==(const JSValuePtr a, const ProtectedJSValuePtr& b) { return a == b.get(); }
205 template <class T> inline bool operator==(const ProtectedPtr<T>& a, const ProtectedJSValuePtr& b) { return JSValuePtr(a.get()) == b.get(); }
206
207 inline bool operator!=(const ProtectedJSValuePtr& a, const ProtectedJSValuePtr& b) { return a.get() != b.get(); }
208 inline bool operator!=(const ProtectedJSValuePtr& a, const JSValuePtr b) { return a.get() != b; }
209 template <class T> inline bool operator!=(const ProtectedJSValuePtr& a, const ProtectedPtr<T>& b) { return a.get() != JSValuePtr(b.get()); }
210 inline bool operator!=(const JSValuePtr a, const ProtectedJSValuePtr& b) { return a != b.get(); }
211 template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const ProtectedJSValuePtr& b) { return JSValuePtr(a.get()) != b.get(); }
212
213} // namespace JSC
214
215#endif // Protect_h
Note: See TracBrowser for help on using the repository browser.