source: webkit/trunk/JavaScriptCore/kjs/identifier.h@ 10701

Last change on this file since 10701 was 10563, checked in by mjs, 20 years ago

Reviewed by Geoff.

  • fixed <rdar://problem/4214783> REGRESSION: kjs_fast_malloc crash due to lack of locking on multiple threads (seen selecting volumes in the installer)

Make sure to lock using the InterpreterLock class in all places that need it
(including anything that uses the collector, the parser, the protect count hash table,
and anything that allocates via fast_malloc).

Also added assertions to ensure that the locking rules are followed for the relevant
resources.

  • Makefile.am:
  • bindings/NP_jsobject.cpp: (identifierFromNPIdentifier): (_NPN_Invoke): (_NPN_Evaluate): (_NPN_GetProperty): (_NPN_SetProperty): (_NPN_RemoveProperty): (_NPN_HasProperty): (_NPN_HasMethod): (_NPN_SetException):
  • bindings/jni/jni_jsobject.cpp: (JSObject::call): (JSObject::eval): (JSObject::getMember): (JSObject::setMember): (JSObject::removeMember): (JSObject::getSlot): (JSObject::setSlot): (JSObject::toString): (JSObject::convertJObjectToValue):
  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject callWebScriptMethod:withArguments:]): (-[WebScriptObject evaluateWebScript:]): (-[WebScriptObject setValue:forKey:]): (-[WebScriptObject valueForKey:]): (-[WebScriptObject removeWebScriptKey:]): (-[WebScriptObject stringRepresentation]): (-[WebScriptObject webScriptValueAtIndex:]): (-[WebScriptObject setWebScriptValueAtIndex:value:]): (+[WebScriptObject _convertValueToObjcValue:KJS::originExecutionContext:Bindings::executionContext:Bindings::]):
  • bindings/runtime.cpp: (Instance::createRuntimeObject):
  • bindings/runtime_root.h:
  • bindings/testbindings.cpp: (main):
  • bindings/testbindings.mm: (main):
  • kjs/fast_malloc.cpp: (KJS::kjs_fast_malloc): (KJS::kjs_fast_calloc): (KJS::kjs_fast_free): (KJS::kjs_fast_realloc):
  • kjs/fast_malloc.h:
  • kjs/identifier.h:
  • kjs/internal.cpp: (InterpreterImp::InterpreterImp): (InterpreterImp::clear): (InterpreterImp::mark): (InterpreterImp::checkSyntax): (InterpreterImp::evaluate):
  • kjs/internal.h: (KJS::InterpreterImp::globalObject):
  • kjs/interpreter.cpp: (Interpreter::evaluate):
  • kjs/interpreter.h: (KJS::InterpreterLock::InterpreterLock): (KJS::InterpreterLock::~InterpreterLock):
  • kjs/nodes.h:
  • kjs/protect.h: (KJS::ProtectedValue::ProtectedValue): (KJS::ProtectedValue::~ProtectedValue): (KJS::ProtectedValue::operator=): (KJS::ProtectedObject::ProtectedObject): (KJS::ProtectedObject::~ProtectedObject): (KJS::ProtectedObject::operator=): (KJS::ProtectedReference::ProtectedReference): (KJS::ProtectedReference::~ProtectedReference): (KJS::ProtectedReference::operator=):
  • kjs/protected_object.h:
  • kjs/protected_values.cpp: (KJS::ProtectedValues::getProtectCount): (KJS::ProtectedValues::increaseProtectCount): (KJS::ProtectedValues::decreaseProtectCount):
  • kjs/string_object.cpp: (StringObjectImp::StringObjectImp):
  • kjs/testkjs.cpp: (main):
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 2003 Apple Computer, Inc
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#ifndef KJS_IDENTIFIER_H
23#define KJS_IDENTIFIER_H
24
25#include "ustring.h"
26
27namespace KJS {
28
29 class Identifier {
30 friend class PropertyMap;
31 public:
32 static void init();
33
34 Identifier() { }
35 Identifier(const char *s) : _ustring(add(s)) { }
36 Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
37 explicit Identifier(const UString &s) : _ustring(add(s.rep)) { }
38
39 const UString &ustring() const { return _ustring; }
40 DOM::DOMString domString() const;
41 QString qstring() const;
42
43 const UChar *data() const { return _ustring.data(); }
44 int size() const { return _ustring.size(); }
45
46 const char *ascii() const { return _ustring.ascii(); }
47
48 static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
49
50 bool isNull() const { return _ustring.isNull(); }
51 bool isEmpty() const { return _ustring.isEmpty(); }
52
53 uint32_t toUInt32(bool *ok) const { return _ustring.toUInt32(ok); }
54 uint32_t toStrictUInt32(bool *ok) const { return _ustring.toStrictUInt32(ok); }
55 unsigned toArrayIndex(bool *ok) const { return _ustring.toArrayIndex(ok); }
56 double toDouble() const { return _ustring.toDouble(); }
57
58 static const Identifier &null();
59
60 friend bool operator==(const Identifier &, const Identifier &);
61 friend bool operator!=(const Identifier &, const Identifier &);
62
63 friend bool operator==(const Identifier &, const char *);
64
65 static void remove(UString::Rep *);
66
67 private:
68 UString _ustring;
69
70 static bool equal(UString::Rep *, const char *);
71 static bool equal(UString::Rep *, const UChar *, int length);
72 static bool equal(UString::Rep *, UString::Rep *);
73
74 static bool equal(const Identifier &a, const Identifier &b)
75 { return a._ustring.rep == b._ustring.rep; }
76 static bool equal(const Identifier &a, const char *b)
77 { return equal(a._ustring.rep, b); }
78
79 static UString::Rep *add(const char *);
80 static UString::Rep *add(const UChar *, int length);
81 static UString::Rep *add(UString::Rep *);
82
83 static void insert(UString::Rep *);
84
85 static void rehash(int newTableSize);
86 static void expand();
87 static void shrink();
88
89 static UString::Rep **_table;
90 static int _tableSize;
91 static int _tableSizeMask;
92 static int _keyCount;
93 };
94
95#if !KJS_IDENTIFIER_HIDE_GLOBALS
96 extern const Identifier nullIdentifier;
97
98 inline const Identifier &Identifier::null()
99 { return nullIdentifier; }
100#endif
101
102 inline bool operator==(const Identifier &a, const Identifier &b)
103 { return Identifier::equal(a, b); }
104
105 inline bool operator!=(const Identifier &a, const Identifier &b)
106 { return !Identifier::equal(a, b); }
107
108 inline bool operator==(const Identifier &a, const char *b)
109 { return Identifier::equal(a, b); }
110
111 // List of property names, passed to a macro so we can do set them up various
112 // ways without repeating the list.
113 #define KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(macro) \
114 macro(arguments) \
115 macro(callee) \
116 macro(constructor) \
117 macro(fromCharCode) \
118 macro(length) \
119 macro(message) \
120 macro(name) \
121 macro(prototype) \
122 macro(toLocaleString) \
123 macro(toString) \
124 macro(toFixed) \
125 macro(toExponential) \
126 macro(toPrecision) \
127 macro(valueOf)
128
129 // Define external global variables for all property names above (and one more).
130#if !KJS_IDENTIFIER_HIDE_GLOBALS
131 extern const Identifier specialPrototypePropertyName;
132
133 #define KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL(name) extern const Identifier name ## PropertyName;
134 KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
135 #undef KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL
136#endif
137
138}
139
140#endif
Note: See TracBrowser for help on using the repository browser.