source: webkit/trunk/JavaScriptCore/kjs/protect.h@ 29059

Last change on this file since 29059 was 14834, checked in by ggaren, 19 years ago

JavaScriptCore:

Reviewed by TimO, Maciej.


  • Merged InterpreterImp code into Interpreter, which implements all interpreter functionality now. This is part of my continuing quest to create an external notion of JS "execution context" that is unified and simple -- something to replace the mix of Context, ContextImp, ExecState, Interpreter, InterpreterImp, and JSRun.


All tests pass. Leaks test has not regressed from its baseline ~207 leaks
with ~3460 leaked nodes.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/NP_jsobject.cpp:
  • bindings/objc/WebScriptObject.mm: (+[WebScriptObject throwException:]):
  • bindings/runtime_root.cpp:
  • bindings/runtime_root.h:
  • kjs/Context.cpp: (KJS::Context::Context):
  • kjs/ExecState.cpp: Added. (KJS::ExecState::lexicalInterpreter):
  • kjs/ExecState.h: Added. (KJS::ExecState::dynamicInterpreter):
  • kjs/SavedBuiltins.h: Added.
  • kjs/bool_object.cpp: (BooleanPrototype::BooleanPrototype):
  • kjs/collector.cpp: (KJS::Collector::collect): (KJS::Collector::numInterpreters):
  • kjs/context.h:
  • kjs/debugger.cpp: (Debugger::attach): (Debugger::detach):
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp: (KJS::interpreterMap): (KJS::Interpreter::Interpreter): (KJS::Interpreter::init): (KJS::Interpreter::~Interpreter): (KJS::Interpreter::globalObject): (KJS::Interpreter::initGlobalObject): (KJS::Interpreter::globalExec): (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate): (KJS::Interpreter::builtinObject): (KJS::Interpreter::builtinFunction): (KJS::Interpreter::builtinArray): (KJS::Interpreter::builtinBoolean): (KJS::Interpreter::builtinString): (KJS::Interpreter::builtinNumber): (KJS::Interpreter::builtinDate): (KJS::Interpreter::builtinRegExp): (KJS::Interpreter::builtinError): (KJS::Interpreter::builtinObjectPrototype): (KJS::Interpreter::builtinFunctionPrototype): (KJS::Interpreter::builtinArrayPrototype): (KJS::Interpreter::builtinBooleanPrototype): (KJS::Interpreter::builtinStringPrototype): (KJS::Interpreter::builtinNumberPrototype): (KJS::Interpreter::builtinDatePrototype): (KJS::Interpreter::builtinRegExpPrototype): (KJS::Interpreter::builtinErrorPrototype): (KJS::Interpreter::builtinEvalError): (KJS::Interpreter::builtinRangeError): (KJS::Interpreter::builtinReferenceError): (KJS::Interpreter::builtinSyntaxError): (KJS::Interpreter::builtinTypeError): (KJS::Interpreter::builtinURIError): (KJS::Interpreter::builtinEvalErrorPrototype): (KJS::Interpreter::builtinRangeErrorPrototype): (KJS::Interpreter::builtinReferenceErrorPrototype): (KJS::Interpreter::builtinSyntaxErrorPrototype): (KJS::Interpreter::builtinTypeErrorPrototype): (KJS::Interpreter::builtinURIErrorPrototype): (KJS::Interpreter::mark): (KJS::Interpreter::interpreterWithGlobalObject): (KJS::Interpreter::saveBuiltins): (KJS::Interpreter::restoreBuiltins):
  • kjs/interpreter.h: (KJS::Interpreter::setCompatMode): (KJS::Interpreter::compatMode): (KJS::Interpreter::firstInterpreter): (KJS::Interpreter::nextInterpreter): (KJS::Interpreter::prevInterpreter): (KJS::Interpreter::debugger): (KJS::Interpreter::setDebugger): (KJS::Interpreter::setContext): (KJS::Interpreter::context):
  • kjs/nodes.cpp: (StatementNode::hitStatement): (RegExpNode::evaluate):
  • kjs/protect.h:

JavaScriptGlue:

Reviewed by TimO, Maciej.


  • JSGlue part of merging InterpreterImp into Interpreter.


Since there's now a kjs forwarding header, I moved all forwarding
headers into a "ForwardingHeaders" directory, like in WebCore.

  • ForwardingHeaders: Added.
  • ForwardingHeaders/kjs: Added.
  • ForwardingHeaders/kjs/ExecState.h: Added.
  • ForwardingHeaders/wtf: Added.
  • JavaScriptGlue.xcodeproj/project.pbxproj:
  • config.h:
  • wtf: Removed.
  • wtf/AlwaysInline.h: Removed.
  • wtf/Assertions.h: Removed.
  • wtf/FastMalloc.h: Removed.
  • wtf/Forward.h: Removed.
  • wtf/HashCountedSet.h: Removed.
  • wtf/HashSet.h: Removed.
  • wtf/Noncopyable.h: Removed.
  • wtf/OwnArrayPtr.h: Removed.
  • wtf/OwnPtr.h: Removed.
  • wtf/PassRefPtr.h: Removed.
  • wtf/Platform.h: Removed.
  • wtf/RefPtr.h: Removed.
  • wtf/Vector.h: Removed.

WebCore:

Reviewed by TimO, Maciej.

  • WebCore part of merging InterpreterImp into Interpreter. No test because there's no behavior change.


A substantive change here is that ScriptInterpreter::mark must now chain to
Interpreter::mark, since Interpreter needs to mark the things that
InterpreterImp used to mark.


  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/kjs_binding.cpp:
  • bindings/js/kjs_window.cpp: (KJS::Window::put):
  • bridge/mac/WebCoreFrameBridge.mm:
  • bridge/mac/WebCoreScriptDebugger.mm: (-[WebCoreScriptCallFrame evaluateWebScript:]):
  • kwq/KWQPageState.mm:
  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 2004 Apple Computer, Inc.
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
24#ifndef _KJS_PROTECT_H_
25#define _KJS_PROTECT_H_
26
27#include "value.h"
28#include "collector.h"
29#include "JSLock.h"
30
31namespace KJS {
32
33 inline void gcProtect(JSValue *val)
34 {
35 Collector::protect(val);
36 }
37
38 inline void gcUnprotect(JSValue *val)
39 {
40 Collector::unprotect(val);
41 }
42
43 inline void gcProtectNullTolerant(JSValue *val)
44 {
45 if (val)
46 gcProtect(val);
47 }
48
49 inline void gcUnprotectNullTolerant(JSValue *val)
50 {
51 if (val)
52 gcUnprotect(val);
53 }
54
55 // FIXME: Share more code with RefPtr template? The only differences are the ref/deref operation
56 // and the implicit conversion to raw pointer
57 template <class T> class ProtectedPtr {
58 public:
59 ProtectedPtr() : m_ptr(NULL) { }
60 ProtectedPtr(T *ptr);
61 ProtectedPtr(const ProtectedPtr &);
62 ~ProtectedPtr();
63
64 template <class U> ProtectedPtr(const ProtectedPtr<U> &);
65
66 T *get() const { return m_ptr; }
67 operator T *() const { return m_ptr; }
68 T *operator->() const { return m_ptr; }
69
70 bool operator!() const { return m_ptr == NULL; }
71
72 ProtectedPtr &operator=(const ProtectedPtr &);
73 ProtectedPtr &operator=(T *);
74
75 private:
76 T *m_ptr;
77 };
78
79 template <class T> ProtectedPtr<T>::ProtectedPtr(T *ptr)
80 : m_ptr(ptr)
81 {
82 if (ptr) {
83 JSLock lock;
84 gcProtect(ptr);
85 }
86 }
87
88 template <class T> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr &o)
89 : m_ptr(o.get())
90 {
91 if (T *ptr = m_ptr) {
92 JSLock lock;
93 gcProtect(ptr);
94 }
95 }
96
97 template <class T> ProtectedPtr<T>::~ProtectedPtr()
98 {
99 if (T *ptr = m_ptr) {
100 JSLock lock;
101 gcUnprotect(ptr);
102 }
103 }
104
105 template <class T> template <class U> ProtectedPtr<T>::ProtectedPtr(const ProtectedPtr<U> &o)
106 : m_ptr(o.get())
107 {
108 if (T *ptr = m_ptr) {
109 JSLock lock;
110 gcProtect(ptr);
111 }
112 }
113
114 template <class T> ProtectedPtr<T> &ProtectedPtr<T>::operator=(const ProtectedPtr<T> &o)
115 {
116 JSLock lock;
117 T *optr = o.m_ptr;
118 gcProtectNullTolerant(optr);
119 gcUnprotectNullTolerant(m_ptr);
120 m_ptr = optr;
121 return *this;
122 }
123
124 template <class T> inline ProtectedPtr<T> &ProtectedPtr<T>::operator=(T *optr)
125 {
126 JSLock lock;
127 gcProtectNullTolerant(optr);
128 gcUnprotectNullTolerant(m_ptr);
129 m_ptr = optr;
130 return *this;
131 }
132
133 template <class T> inline bool operator==(const ProtectedPtr<T> &a, const ProtectedPtr<T> &b) { return a.get() == b.get(); }
134 template <class T> inline bool operator==(const ProtectedPtr<T> &a, const T *b) { return a.get() == b; }
135 template <class T> inline bool operator==(const T *a, const ProtectedPtr<T> &b) { return a == b.get(); }
136
137 template <class T> inline bool operator!=(const ProtectedPtr<T> &a, const ProtectedPtr<T> &b) { return a.get() != b.get(); }
138 template <class T> inline bool operator!=(const ProtectedPtr<T> &a, const T *b) { return a.get() != b; }
139 template <class T> inline bool operator!=(const T *a, const ProtectedPtr<T> &b) { return a != b.get(); }
140
141} // namespace
142
143#endif
Note: See TracBrowser for help on using the repository browser.