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

Last change on this file since 38477 was 38137, checked in by [email protected], 17 years ago

2008-11-05 Cameron Zwarich <[email protected]>

Rubber-stamped by Sam Weinig.

Move more files to the runtime subdirectory of JavaScriptCore.

JavaScriptCore:

  • API/APICast.h:
  • API/JSBase.cpp:
  • API/JSCallbackObject.cpp:
  • API/JSClassRef.cpp:
  • API/JSClassRef.h:
  • API/JSStringRefCF.cpp:
  • API/JSValueRef.cpp:
  • API/OpaqueJSString.cpp:
  • API/OpaqueJSString.h:
  • AllInOneFile.cpp:
  • GNUmakefile.am:
  • JavaScriptCore.pri:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp:
  • VM/Machine.cpp:
  • VM/RegisterFile.h:
  • debugger/Debugger.h:
  • kjs/SourceProvider.h:
  • kjs/TypeInfo.h: Removed.
  • kjs/collector.cpp: Removed.
  • kjs/collector.h: Removed.
  • kjs/completion.h: Removed.
  • kjs/create_hash_table:
  • kjs/identifier.cpp: Removed.
  • kjs/identifier.h: Removed.
  • kjs/interpreter.cpp: Removed.
  • kjs/interpreter.h: Removed.
  • kjs/lexer.cpp:
  • kjs/lexer.h:
  • kjs/lookup.cpp: Removed.
  • kjs/lookup.h: Removed.
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/operations.cpp: Removed.
  • kjs/operations.h: Removed.
  • kjs/protect.h: Removed.
  • kjs/regexp.cpp: Removed.
  • kjs/regexp.h: Removed.
  • kjs/ustring.cpp: Removed.
  • kjs/ustring.h: Removed.
  • pcre/pcre_exec.cpp:
  • profiler/CallIdentifier.h:
  • profiler/Profile.h:
  • runtime/ArrayConstructor.cpp:
  • runtime/ArrayPrototype.cpp:
  • runtime/ArrayPrototype.h:
  • runtime/Collector.cpp: Copied from kjs/collector.cpp.
  • runtime/Collector.h: Copied from kjs/collector.h.
  • runtime/CollectorHeapIterator.h:
  • runtime/Completion.h: Copied from kjs/completion.h.
  • runtime/ErrorPrototype.cpp:
  • runtime/Identifier.cpp: Copied from kjs/identifier.cpp.
  • runtime/Identifier.h: Copied from kjs/identifier.h.
  • runtime/InitializeThreading.cpp:
  • runtime/Interpreter.cpp: Copied from kjs/interpreter.cpp.
  • runtime/Interpreter.h: Copied from kjs/interpreter.h.
  • runtime/JSCell.h:
  • runtime/JSGlobalData.cpp:
  • runtime/JSGlobalData.h:
  • runtime/JSLock.cpp:
  • runtime/JSNumberCell.cpp:
  • runtime/JSNumberCell.h:
  • runtime/JSObject.cpp:
  • runtime/JSValue.h:
  • runtime/Lookup.cpp: Copied from kjs/lookup.cpp.
  • runtime/Lookup.h: Copied from kjs/lookup.h.
  • runtime/MathObject.cpp:
  • runtime/NativeErrorPrototype.cpp:
  • runtime/NumberPrototype.cpp:
  • runtime/Operations.cpp: Copied from kjs/operations.cpp.
  • runtime/Operations.h: Copied from kjs/operations.h.
  • runtime/PropertyMapHashTable.h:
  • runtime/Protect.h: Copied from kjs/protect.h.
  • runtime/RegExp.cpp: Copied from kjs/regexp.cpp.
  • runtime/RegExp.h: Copied from kjs/regexp.h.
  • runtime/RegExpConstructor.cpp:
  • runtime/RegExpObject.h:
  • runtime/RegExpPrototype.cpp:
  • runtime/SmallStrings.h:
  • runtime/StringObjectThatMasqueradesAsUndefined.h:
  • runtime/StructureID.cpp:
  • runtime/StructureID.h:
  • runtime/StructureIDTransitionTable.h:
  • runtime/SymbolTable.h:
  • runtime/TypeInfo.h: Copied from kjs/TypeInfo.h.
  • runtime/UString.cpp: Copied from kjs/ustring.cpp.
  • runtime/UString.h: Copied from kjs/ustring.h.
  • wrec/CharacterClassConstructor.h:
  • wrec/WREC.h:

WebCore:

  • ForwardingHeaders/kjs/collector.h: Removed.
  • ForwardingHeaders/kjs/completion.h: Removed.
  • ForwardingHeaders/kjs/identifier.h: Removed.
  • ForwardingHeaders/kjs/interpreter.h: Removed.
  • ForwardingHeaders/kjs/lookup.h: Removed.
  • ForwardingHeaders/kjs/operations.h: Removed.
  • ForwardingHeaders/kjs/protect.h: Removed.
  • ForwardingHeaders/kjs/ustring.h: Removed.
  • ForwardingHeaders/runtime/Collector.h: Copied from ForwardingHeaders/kjs/collector.h.
  • ForwardingHeaders/runtime/Completion.h: Copied from ForwardingHeaders/kjs/completion.h.
  • ForwardingHeaders/runtime/Identifier.h: Copied from ForwardingHeaders/kjs/identifier.h.
  • ForwardingHeaders/runtime/Interpreter.h: Copied from ForwardingHeaders/kjs/interpreter.h.
  • ForwardingHeaders/runtime/Lookup.h: Copied from ForwardingHeaders/kjs/lookup.h.
  • ForwardingHeaders/runtime/Operations.h: Copied from ForwardingHeaders/kjs/operations.h.
  • ForwardingHeaders/runtime/Protect.h: Copied from ForwardingHeaders/kjs/protect.h.
  • ForwardingHeaders/runtime/UString.h: Copied from ForwardingHeaders/kjs/ustring.h.
  • bindings/js/GCController.cpp:
  • bindings/js/JSCustomPositionCallback.h:
  • bindings/js/JSCustomPositionErrorCallback.h:
  • bindings/js/JSCustomSQLStatementCallback.h:
  • bindings/js/JSCustomSQLStatementErrorCallback.h:
  • bindings/js/JSCustomSQLTransactionErrorCallback.h:
  • bindings/js/JSCustomVoidCallback.h:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSEventListener.h:
  • bindings/js/ScheduledAction.h:
  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptController.h:
  • bindings/objc/WebScriptObject.mm:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:
  • bridge/c/c_class.cpp:
  • bridge/jni/jni_class.cpp:
  • bridge/jni/jni_jsobject.mm:
  • bridge/npruntime.cpp:
  • bridge/runtime_root.h:
  • history/CachedPage.h:
  • html/CanvasRenderingContext2D.cpp:
  • html/HTMLCanvasElement.cpp:
  • inspector/InspectorController.cpp:
  • inspector/JavaScriptCallFrame.cpp:
  • page/Console.cpp:
  • page/Page.cpp:
  • platform/text/AtomicString.cpp:
  • platform/text/PlatformString.h:

WebKit/mac:

  • ForwardingHeaders/kjs/collector.h: Removed.
  • ForwardingHeaders/kjs/identifier.h: Removed.
  • ForwardingHeaders/kjs/interpreter.h: Removed.
  • ForwardingHeaders/kjs/lookup.h: Removed.
  • ForwardingHeaders/kjs/operations.h: Removed.
  • ForwardingHeaders/kjs/protect.h: Removed.
  • ForwardingHeaders/runtime/Interpreter.h: Copied from ForwardingHeaders/kjs/interpreter.h.
  • WebView/WebScriptDebugDelegate.mm:

WebKit/wx:

  • WebFrame.cpp:
  • WebView.cpp:
  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/*
2 * Copyright (C) 2004, 2008 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(JSValue* value)
53 {
54 if (JSImmediate::isImmediate(value))
55 return;
56 gcProtect(asCell(value));
57 }
58
59 inline void gcUnprotect(JSValue* value)
60 {
61 if (JSImmediate::isImmediate(value))
62 return;
63 gcUnprotect(asCell(value));
64 }
65
66 inline void gcProtectNullTolerant(JSValue* value)
67 {
68 if (!value || JSImmediate::isImmediate(value))
69 return;
70 gcProtect(asCell(value));
71 }
72
73 inline void gcUnprotectNullTolerant(JSValue* value)
74 {
75 if (!value || JSImmediate::isImmediate(value))
76 return;
77 gcUnprotect(asCell(value));
78 }
79
80 // FIXME: Share more code with RefPtr template? The only differences are the ref/deref operation
81 // and the implicit conversion to raw pointer
82 template <class T> class ProtectedPtr {
83 public:
84 ProtectedPtr() : m_ptr(0) { }
85 ProtectedPtr(T* ptr);
86 ProtectedPtr(const ProtectedPtr&);
87 ~ProtectedPtr();
88
89 template <class U> ProtectedPtr(const ProtectedPtr<U>&);
90
91 T* get() const { return m_ptr; }
92 operator T*() const { return m_ptr; }
93 T* operator->() const { return m_ptr; }
94
95 bool operator!() const { return !m_ptr; }
96
97 ProtectedPtr& operator=(const ProtectedPtr&);
98 ProtectedPtr& operator=(T*);
99
100 private:
101 T* m_ptr;
102 };
103
104 template <class T> ProtectedPtr<T>::ProtectedPtr(T* ptr)
105 : m_ptr(ptr)
106 {
107 gcProtectNullTolerant(m_ptr);
108 }
109
110 template <class T> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr& o)
111 : m_ptr(o.get())
112 {
113 gcProtectNullTolerant(m_ptr);
114 }
115
116 template <class T> ProtectedPtr<T>::~ProtectedPtr()
117 {
118 gcUnprotectNullTolerant(m_ptr);
119 }
120
121 template <class T> template <class U> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr<U>& o)
122 : m_ptr(o.get())
123 {
124 gcProtectNullTolerant(m_ptr);
125 }
126
127 template <class T> ProtectedPtr<T>& ProtectedPtr<T>::operator=(const ProtectedPtr<T>& o)
128 {
129 T* optr = o.m_ptr;
130 gcProtectNullTolerant(optr);
131 gcUnprotectNullTolerant(m_ptr);
132 m_ptr = optr;
133 return *this;
134 }
135
136 template <class T> inline ProtectedPtr<T>& ProtectedPtr<T>::operator=(T* optr)
137 {
138 gcProtectNullTolerant(optr);
139 gcUnprotectNullTolerant(m_ptr);
140 m_ptr = optr;
141 return *this;
142 }
143
144 template <class T> inline bool operator==(const ProtectedPtr<T>& a, const ProtectedPtr<T>& b) { return a.get() == b.get(); }
145 template <class T> inline bool operator==(const ProtectedPtr<T>& a, const T* b) { return a.get() == b; }
146 template <class T> inline bool operator==(const T* a, const ProtectedPtr<T>& b) { return a == b.get(); }
147
148 template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const ProtectedPtr<T>& b) { return a.get() != b.get(); }
149 template <class T> inline bool operator!=(const ProtectedPtr<T>& a, const T* b) { return a.get() != b; }
150 template <class T> inline bool operator!=(const T* a, const ProtectedPtr<T>& b) { return a != b.get(); }
151
152} // namespace JSC
153
154#endif // protect_h
Note: See TracBrowser for help on using the repository browser.