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

Last change on this file since 9768 was 9145, checked in by darin, 20 years ago

Reviewed by John.

  • turn on conservative GC unconditionally and start on SPI changes to eliminate the now-unneeded smart pointers since we don't ref count any more
  • kjs/value.h: Removed macros to turn conservative GC on and off. Removed ref and deref functions. (KJS::ValueImp::ValueImp): Removed non-conservative-GC code path. (KJS::ValueImp::isUndefined): Added. New SPI to make it easier to deal with ValueImp directly. (KJS::ValueImp::isNull): Ditto. (KJS::ValueImp::isBoolean): Ditto. (KJS::ValueImp::isNumber): Ditto. (KJS::ValueImp::isString): Ditto. (KJS::ValueImp::isObject): Ditto. (KJS::Value::Value): Removed non-conservative-GC code path and made constructor no longer explicit so we can quietly create Value wrappers from ValueImp *; inexpensive with conservative GC and eases the transition. (KJS::Value::operator ValueImp *): Added. Quietly creates ValueImp * from Value. (KJS::ValueImp::marked): Removed non-conservative-GC code path.
  • kjs/value.cpp: (KJS::ValueImp::mark): Removed non-conservative-GC code path. (KJS::ValueImp::isUndefinedOrNull): Added. New SPI to make it easier to deal with ValueImp directly. (KJS::ValueImp::isBoolean): Ditto. (KJS::ValueImp::isNumber): Ditto. (KJS::ValueImp::isString): Ditto. (KJS::ValueImp::asString): Ditto. (KJS::ValueImp::isObject): Ditto. (KJS::undefined): Ditto. (KJS::null): Ditto. (KJS::boolean): Ditto. (KJS::string): Ditto. (KJS::zero): Ditto. (KJS::one): Ditto. (KJS::two): Ditto. (KJS::number): Ditto.
  • kjs/object.h: Made constructor no longer explicit so we can quietly create Object wrappers from ObjectImp *; inexpensive with conservative GC and eases the transition. (KJS::Object::operator ObjectImp *): Added. Quietly creates ObjectImp * from Object. (KJS::ValueImp::isObject): Added. Implementation of new object-related ValueImp function. (KJS::ValueImp::asObject): Ditto.
  • kjs/object.cpp: (KJS::ObjectImp::setInternalValue): Remove non-conservative-GC code path. (KJS::ObjectImp::putDirect): Ditto. (KJS::error): Added. Function in the new SPI style to create an error object.
  • kjs/internal.h: Added the new number-constructing functions as friends of NumberImp. There may be a more elegant way to do this later; what's important now is the new SPI.
  • kjs/collector.h: Remove non-conservative-GC code path and also take out some unneeded APPLE_CHANGES.
  • bindings/runtime_root.cpp: (KJS::Bindings::addNativeReference): Remove non-conservative-GC code path. (KJS::Bindings::removeNativeReference): Ditto. (RootObject::removeAllNativeReferences): Ditto.
  • bindings/runtime_root.h: (KJS::Bindings::RootObject::~RootObject): Ditto. (KJS::Bindings::RootObject::setRootObjectImp): Ditto.
  • kjs/collector.cpp: (KJS::Collector::allocate): Ditto. (KJS::Collector::collect): Ditto. (KJS::Collector::numGCNotAllowedObjects): Ditto. (KJS::Collector::numReferencedObjects): Ditto. (KJS::Collector::rootObjectClasses): Ditto.
  • kjs/internal.cpp: (NumberImp::create): Ditto. (InterpreterImp::globalInit): Ditto. (InterpreterImp::globalClear): Ditto.
  • kjs/list.cpp: (KJS::List::markProtectedLists): Ditto. (KJS::List::clear): Ditto. (KJS::List::append): Ditto.
  • kjs/list.h: (KJS::List::List): Ditto. (KJS::List::deref): Ditto. (KJS::List::operator=): Ditto.
  • kjs/protect.h: (KJS::gcProtect): Ditto. (KJS::gcUnprotect): Ditto.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
23
24#ifndef _KJS_PROTECT_H_
25#define _KJS_PROTECT_H_
26
27#include "object.h"
28#include "reference.h"
29#include "value.h"
30#include "protected_values.h"
31
32namespace KJS {
33
34 inline void gcProtect(ValueImp *val)
35 {
36 ProtectedValues::increaseProtectCount(val);
37 }
38 inline void gcUnprotect(ValueImp *val)
39 {
40 ProtectedValues::decreaseProtectCount(val);
41 }
42
43 inline void gcProtectNullTolerant(ValueImp *val)
44 {
45 if (val) gcProtect(val);
46 }
47
48 inline void gcUnprotectNullTolerant(ValueImp *val)
49 {
50 if (val) gcUnprotect(val);
51 }
52
53
54 class ProtectedValue : public Value {
55 public:
56 ProtectedValue() : Value() {}
57 ProtectedValue(const Value&v) : Value(v) { gcProtectNullTolerant(v.imp()); };
58 ProtectedValue(const ProtectedValue&v) : Value(v) { gcProtectNullTolerant(v.imp()); };
59 ~ProtectedValue() { gcUnprotectNullTolerant(imp());}
60 ProtectedValue& operator=(const Value &v)
61 {
62 ValueImp *old = imp();
63 Value::operator=(v);
64 gcProtectNullTolerant(v.imp());
65 gcUnprotectNullTolerant(old);
66 return *this;
67 }
68 ProtectedValue& operator=(const ProtectedValue &v)
69 {
70 ValueImp *old = imp();
71 Value::operator=(v);
72 gcProtectNullTolerant(v.imp());
73 gcUnprotectNullTolerant(old);
74 return *this;
75 }
76 private:
77 explicit ProtectedValue(ValueImp *v);
78 };
79
80
81 class ProtectedObject : public Object {
82 public:
83 ProtectedObject() : Object() {}
84 ProtectedObject(const Object &o) : Object(o) { gcProtectNullTolerant(o.imp()); };
85 ProtectedObject(const ProtectedObject &o) : Object(o) { gcProtectNullTolerant(o.imp()); };
86 ~ProtectedObject() { gcUnprotectNullTolerant(imp());}
87 ProtectedObject& operator=(const Object &o)
88 {
89 ValueImp *old = imp();
90 Object::operator=(o);
91 gcProtectNullTolerant(o.imp());
92 gcUnprotectNullTolerant(old);
93 return *this;
94 }
95 ProtectedObject& operator=(const ProtectedObject &o)
96 {
97 ValueImp *old = imp();
98 Object::operator=(o);
99 gcProtectNullTolerant(o.imp());
100 gcUnprotectNullTolerant(old);
101 return *this;
102 }
103 private:
104 explicit ProtectedObject(ObjectImp *o);
105 };
106
107
108 class ProtectedReference : public Reference {
109 public:
110 ProtectedReference(const Reference&r) : Reference(r) { gcProtectNullTolerant(r.base.imp()); };
111 ~ProtectedReference() { gcUnprotectNullTolerant(base.imp());}
112 ProtectedReference& operator=(const Reference &r)
113 {
114 ValueImp *old = base.imp();
115 Reference::operator=(r);
116 gcProtectNullTolerant(r.base.imp());
117 gcUnprotectNullTolerant(old);
118 return *this;
119 }
120 private:
121 ProtectedReference();
122 ProtectedReference(const Object& b, const Identifier& p);
123 ProtectedReference(const Object& b, unsigned p);
124 ProtectedReference(ObjectImp *b, const Identifier& p);
125 ProtectedReference(ObjectImp *b, unsigned p);
126 ProtectedReference(const Null& b, const Identifier& p);
127 ProtectedReference(const Null& b, unsigned p);
128 };
129
130}
131
132#endif
Note: See TracBrowser for help on using the repository browser.