source: webkit/trunk/JavaScriptCore/kjs/interpreter.cpp@ 10563

Last change on this file since 10563 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: 7.8 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten ([email protected])
5 * Copyright (C) 2001 Peter Kelly ([email protected])
6 * Copyright (C) 2003 Apple Computer, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "value.h"
26#include "object.h"
27#include "types.h"
28#include "interpreter.h"
29#if APPLE_CHANGES
30#include "runtime.h"
31#endif
32
33#include <assert.h>
34#include <math.h>
35#include <stdio.h>
36
37#include "internal.h"
38#include "collector.h"
39#include "operations.h"
40#include "error_object.h"
41#include "nodes.h"
42#include "context.h"
43
44using namespace KJS;
45
46// ------------------------------ Context --------------------------------------
47
48const ScopeChain &Context::scopeChain() const
49{
50 return rep->scopeChain();
51}
52
53ObjectImp *Context::variableObject() const
54{
55 return rep->variableObject();
56}
57
58ObjectImp *Context::thisValue() const
59{
60 return rep->thisValue();
61}
62
63const Context Context::callingContext() const
64{
65 return rep->callingContext();
66}
67
68// ------------------------------ Interpreter ----------------------------------
69
70Interpreter::Interpreter(ObjectImp *global)
71 : rep(0)
72 , m_argumentsPropertyName(&argumentsPropertyName)
73 , m_specialPrototypePropertyName(&specialPrototypePropertyName)
74{
75 rep = new InterpreterImp(this, global);
76}
77
78Interpreter::Interpreter()
79 : rep(0)
80 , m_argumentsPropertyName(&argumentsPropertyName)
81 , m_specialPrototypePropertyName(&specialPrototypePropertyName)
82{
83 rep = new InterpreterImp(this, new ObjectImp);
84}
85
86Interpreter::~Interpreter()
87{
88 delete rep;
89}
90
91ObjectImp *Interpreter::globalObject() const
92{
93 return rep->globalObject();
94}
95
96void Interpreter::initGlobalObject()
97{
98 rep->initGlobalObject();
99}
100
101void Interpreter::lock()
102{
103 InterpreterImp::lock();
104}
105
106void Interpreter::unlock()
107{
108 InterpreterImp::unlock();
109}
110
111int Interpreter::lockCount()
112{
113 return InterpreterImp::lockCount();
114}
115
116ExecState *Interpreter::globalExec()
117{
118 return rep->globalExec();
119}
120
121bool Interpreter::checkSyntax(const UString &code)
122{
123 return rep->checkSyntax(code);
124}
125
126Completion Interpreter::evaluate(const UString &code, ValueImp *thisV, const UString &)
127{
128 return evaluate(UString(), 0, code, thisV);
129}
130
131Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, ValueImp *thisV)
132{
133 Completion comp = rep->evaluate(code,thisV, sourceURL, startingLineNumber);
134
135#if APPLE_CHANGES
136 if (shouldPrintExceptions() && comp.complType() == Throw) {
137 InterpreterLock lock;
138 ExecState *exec = rep->globalExec();
139 char *f = strdup(sourceURL.ascii());
140 const char *message = comp.value()->toObject(exec)->toString(exec).ascii();
141 printf("[%d] %s:%s\n", getpid(), f, message);
142
143 free(f);
144 }
145#endif
146
147 return comp;
148}
149
150ObjectImp *Interpreter::builtinObject() const
151{
152 return rep->builtinObject();
153}
154
155ObjectImp *Interpreter::builtinFunction() const
156{
157 return rep->builtinFunction();
158}
159
160ObjectImp *Interpreter::builtinArray() const
161{
162 return rep->builtinArray();
163}
164
165ObjectImp *Interpreter::builtinBoolean() const
166{
167 return rep->builtinBoolean();
168}
169
170ObjectImp *Interpreter::builtinString() const
171{
172 return rep->builtinString();
173}
174
175ObjectImp *Interpreter::builtinNumber() const
176{
177 return rep->builtinNumber();
178}
179
180ObjectImp *Interpreter::builtinDate() const
181{
182 return rep->builtinDate();
183}
184
185ObjectImp *Interpreter::builtinRegExp() const
186{
187 return rep->builtinRegExp();
188}
189
190ObjectImp *Interpreter::builtinError() const
191{
192 return rep->builtinError();
193}
194
195ObjectImp *Interpreter::builtinObjectPrototype() const
196{
197 return rep->builtinObjectPrototype();
198}
199
200ObjectImp *Interpreter::builtinFunctionPrototype() const
201{
202 return rep->builtinFunctionPrototype();
203}
204
205ObjectImp *Interpreter::builtinArrayPrototype() const
206{
207 return rep->builtinArrayPrototype();
208}
209
210ObjectImp *Interpreter::builtinBooleanPrototype() const
211{
212 return rep->builtinBooleanPrototype();
213}
214
215ObjectImp *Interpreter::builtinStringPrototype() const
216{
217 return rep->builtinStringPrototype();
218}
219
220ObjectImp *Interpreter::builtinNumberPrototype() const
221{
222 return rep->builtinNumberPrototype();
223}
224
225ObjectImp *Interpreter::builtinDatePrototype() const
226{
227 return rep->builtinDatePrototype();
228}
229
230ObjectImp *Interpreter::builtinRegExpPrototype() const
231{
232 return rep->builtinRegExpPrototype();
233}
234
235ObjectImp *Interpreter::builtinErrorPrototype() const
236{
237 return rep->builtinErrorPrototype();
238}
239
240ObjectImp *Interpreter::builtinEvalError() const
241{
242 return rep->builtinEvalError();
243}
244
245ObjectImp *Interpreter::builtinRangeError() const
246{
247 return rep->builtinRangeError();
248}
249
250ObjectImp *Interpreter::builtinReferenceError() const
251{
252 return rep->builtinReferenceError();
253}
254
255ObjectImp *Interpreter::builtinSyntaxError() const
256{
257 return rep->builtinSyntaxError();
258}
259
260ObjectImp *Interpreter::builtinTypeError() const
261{
262 return rep->builtinTypeError();
263}
264
265ObjectImp *Interpreter::builtinURIError() const
266{
267 return rep->builtinURIError();
268}
269
270ObjectImp *Interpreter::builtinEvalErrorPrototype() const
271{
272 return rep->builtinEvalErrorPrototype();
273}
274
275ObjectImp *Interpreter::builtinRangeErrorPrototype() const
276{
277 return rep->builtinRangeErrorPrototype();
278}
279
280ObjectImp *Interpreter::builtinReferenceErrorPrototype() const
281{
282 return rep->builtinReferenceErrorPrototype();
283}
284
285ObjectImp *Interpreter::builtinSyntaxErrorPrototype() const
286{
287 return rep->builtinSyntaxErrorPrototype();
288}
289
290ObjectImp *Interpreter::builtinTypeErrorPrototype() const
291{
292 return rep->builtinTypeErrorPrototype();
293}
294
295ObjectImp *Interpreter::builtinURIErrorPrototype() const
296{
297 return rep->builtinURIErrorPrototype();
298}
299
300void Interpreter::setCompatMode(CompatMode mode)
301{
302 rep->setCompatMode(mode);
303}
304
305Interpreter::CompatMode Interpreter::compatMode() const
306{
307 return rep->compatMode();
308}
309
310#ifdef KJS_DEBUG_MEM
311#include "lexer.h"
312void Interpreter::finalCheck()
313{
314 fprintf(stderr,"Interpreter::finalCheck()\n");
315 Collector::collect();
316
317 Node::finalCheck();
318 Collector::finalCheck();
319 Lexer::globalClear();
320 UString::globalClear();
321}
322#endif
323
324#if APPLE_CHANGES
325static bool printExceptions = false;
326
327bool Interpreter::shouldPrintExceptions()
328{
329 return printExceptions;
330}
331
332void Interpreter::setShouldPrintExceptions(bool print)
333{
334 printExceptions = print;
335}
336
337
338void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, ObjectImp *value, const Bindings::RootObject *origin, const Bindings::RootObject *current)
339{
340 return Bindings::Instance::createLanguageInstanceForValue (exec, (Bindings::Instance::BindingLanguage)language, value, origin, current);
341}
342
343#endif
344
345void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
346{
347 rep->saveBuiltins(builtins);
348}
349
350void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
351{
352 rep->restoreBuiltins(builtins);
353}
354
355SavedBuiltins::SavedBuiltins() :
356 _internal(0)
357{
358}
359
360SavedBuiltins::~SavedBuiltins()
361{
362 delete _internal;
363}
364
365
366void Interpreter::virtual_hook( int, void* )
367{ /*BASE::virtual_hook( id, data );*/ }
368
369
370Interpreter *ExecState::lexicalInterpreter() const
371{
372 if (!_context) {
373 return dynamicInterpreter();
374 }
375
376 InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
377
378 if (!result) {
379 return dynamicInterpreter();
380 }
381
382 return result->interpreter();
383}
Note: See TracBrowser for help on using the repository browser.