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

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

JavaScriptCore:

Reviewed by Geoff.

<rdar://problem/4139620> Seed: WebKit: hang when sending XMLHttpRequest if automatic proxy config is used

Also factored locking code completely into a separate class, and
added a convenient packaged way to temporarily drop locks.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/JSLock.cpp: Added. (KJS::initializeInterpreterLock): (KJS::InterpreterLock::lock): (KJS::InterpreterLock::unlock): (KJS::InterpreterLock::lockCount): (KJS::InterpreterLock::DropAllLocks::DropAllLocks): (KJS::InterpreterLock::DropAllLocks::~DropAllLocks):
  • kjs/JSLock.h: Added. (KJS::InterpreterLock::InterpreterLock): (KJS::InterpreterLock::~InterpreterLock):
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/protect.h:
  • kjs/testkjs.cpp: (TestFunctionImp::callAsFunction):

WebCore:

Reviewed by Geoff.

<rdar://problem/4139620> Seed: WebKit: hang when sending XMLHttpRequest if automatic proxy config is used

  • khtml/ecma/kjs_events.cpp: (KJS::JSLazyEventListener::parseCode):
  • khtml/ecma/xmlhttprequest.cpp: (KJS::XMLHttpRequest::send):
  • kwq/WebCoreJavaScript.mm:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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 "config.h"
26#include "value.h"
27#include "object.h"
28#include "types.h"
29#include "interpreter.h"
30#if APPLE_CHANGES
31#include "runtime.h"
32#endif
33
34#include <assert.h>
35#include <math.h>
36#include <stdio.h>
37
38#include "internal.h"
39#include "collector.h"
40#include "operations.h"
41#include "error_object.h"
42#include "nodes.h"
43#include "context.h"
44
45using namespace KJS;
46
47// ------------------------------ Context --------------------------------------
48
49const ScopeChain &Context::scopeChain() const
50{
51 return rep->scopeChain();
52}
53
54ObjectImp *Context::variableObject() const
55{
56 return rep->variableObject();
57}
58
59ObjectImp *Context::thisValue() const
60{
61 return rep->thisValue();
62}
63
64const Context Context::callingContext() const
65{
66 return rep->callingContext();
67}
68
69// ------------------------------ Interpreter ----------------------------------
70
71Interpreter::Interpreter(ObjectImp *global)
72 : rep(0)
73 , m_argumentsPropertyName(&argumentsPropertyName)
74 , m_specialPrototypePropertyName(&specialPrototypePropertyName)
75{
76 rep = new InterpreterImp(this, global);
77}
78
79Interpreter::Interpreter()
80 : rep(0)
81 , m_argumentsPropertyName(&argumentsPropertyName)
82 , m_specialPrototypePropertyName(&specialPrototypePropertyName)
83{
84 rep = new InterpreterImp(this, new ObjectImp);
85}
86
87Interpreter::~Interpreter()
88{
89 delete rep;
90}
91
92ObjectImp *Interpreter::globalObject() const
93{
94 return rep->globalObject();
95}
96
97void Interpreter::initGlobalObject()
98{
99 rep->initGlobalObject();
100}
101
102ExecState *Interpreter::globalExec()
103{
104 return rep->globalExec();
105}
106
107bool Interpreter::checkSyntax(const UString &code)
108{
109 return rep->checkSyntax(code);
110}
111
112Completion Interpreter::evaluate(const UString &code, ValueImp *thisV, const UString &)
113{
114 return evaluate(UString(), 0, code, thisV);
115}
116
117Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, ValueImp *thisV)
118{
119 Completion comp = rep->evaluate(code,thisV, sourceURL, startingLineNumber);
120
121#if APPLE_CHANGES
122 if (shouldPrintExceptions() && comp.complType() == Throw) {
123 InterpreterLock lock;
124 ExecState *exec = rep->globalExec();
125 char *f = strdup(sourceURL.ascii());
126 const char *message = comp.value()->toObject(exec)->toString(exec).ascii();
127 printf("[%d] %s:%s\n", getpid(), f, message);
128
129 free(f);
130 }
131#endif
132
133 return comp;
134}
135
136ObjectImp *Interpreter::builtinObject() const
137{
138 return rep->builtinObject();
139}
140
141ObjectImp *Interpreter::builtinFunction() const
142{
143 return rep->builtinFunction();
144}
145
146ObjectImp *Interpreter::builtinArray() const
147{
148 return rep->builtinArray();
149}
150
151ObjectImp *Interpreter::builtinBoolean() const
152{
153 return rep->builtinBoolean();
154}
155
156ObjectImp *Interpreter::builtinString() const
157{
158 return rep->builtinString();
159}
160
161ObjectImp *Interpreter::builtinNumber() const
162{
163 return rep->builtinNumber();
164}
165
166ObjectImp *Interpreter::builtinDate() const
167{
168 return rep->builtinDate();
169}
170
171ObjectImp *Interpreter::builtinRegExp() const
172{
173 return rep->builtinRegExp();
174}
175
176ObjectImp *Interpreter::builtinError() const
177{
178 return rep->builtinError();
179}
180
181ObjectImp *Interpreter::builtinObjectPrototype() const
182{
183 return rep->builtinObjectPrototype();
184}
185
186ObjectImp *Interpreter::builtinFunctionPrototype() const
187{
188 return rep->builtinFunctionPrototype();
189}
190
191ObjectImp *Interpreter::builtinArrayPrototype() const
192{
193 return rep->builtinArrayPrototype();
194}
195
196ObjectImp *Interpreter::builtinBooleanPrototype() const
197{
198 return rep->builtinBooleanPrototype();
199}
200
201ObjectImp *Interpreter::builtinStringPrototype() const
202{
203 return rep->builtinStringPrototype();
204}
205
206ObjectImp *Interpreter::builtinNumberPrototype() const
207{
208 return rep->builtinNumberPrototype();
209}
210
211ObjectImp *Interpreter::builtinDatePrototype() const
212{
213 return rep->builtinDatePrototype();
214}
215
216ObjectImp *Interpreter::builtinRegExpPrototype() const
217{
218 return rep->builtinRegExpPrototype();
219}
220
221ObjectImp *Interpreter::builtinErrorPrototype() const
222{
223 return rep->builtinErrorPrototype();
224}
225
226ObjectImp *Interpreter::builtinEvalError() const
227{
228 return rep->builtinEvalError();
229}
230
231ObjectImp *Interpreter::builtinRangeError() const
232{
233 return rep->builtinRangeError();
234}
235
236ObjectImp *Interpreter::builtinReferenceError() const
237{
238 return rep->builtinReferenceError();
239}
240
241ObjectImp *Interpreter::builtinSyntaxError() const
242{
243 return rep->builtinSyntaxError();
244}
245
246ObjectImp *Interpreter::builtinTypeError() const
247{
248 return rep->builtinTypeError();
249}
250
251ObjectImp *Interpreter::builtinURIError() const
252{
253 return rep->builtinURIError();
254}
255
256ObjectImp *Interpreter::builtinEvalErrorPrototype() const
257{
258 return rep->builtinEvalErrorPrototype();
259}
260
261ObjectImp *Interpreter::builtinRangeErrorPrototype() const
262{
263 return rep->builtinRangeErrorPrototype();
264}
265
266ObjectImp *Interpreter::builtinReferenceErrorPrototype() const
267{
268 return rep->builtinReferenceErrorPrototype();
269}
270
271ObjectImp *Interpreter::builtinSyntaxErrorPrototype() const
272{
273 return rep->builtinSyntaxErrorPrototype();
274}
275
276ObjectImp *Interpreter::builtinTypeErrorPrototype() const
277{
278 return rep->builtinTypeErrorPrototype();
279}
280
281ObjectImp *Interpreter::builtinURIErrorPrototype() const
282{
283 return rep->builtinURIErrorPrototype();
284}
285
286void Interpreter::setCompatMode(CompatMode mode)
287{
288 rep->setCompatMode(mode);
289}
290
291Interpreter::CompatMode Interpreter::compatMode() const
292{
293 return rep->compatMode();
294}
295
296#ifdef KJS_DEBUG_MEM
297#include "lexer.h"
298void Interpreter::finalCheck()
299{
300 fprintf(stderr,"Interpreter::finalCheck()\n");
301 Collector::collect();
302
303 Node::finalCheck();
304 Collector::finalCheck();
305 Lexer::globalClear();
306 UString::globalClear();
307}
308#endif
309
310#if APPLE_CHANGES
311static bool printExceptions = false;
312
313bool Interpreter::shouldPrintExceptions()
314{
315 return printExceptions;
316}
317
318void Interpreter::setShouldPrintExceptions(bool print)
319{
320 printExceptions = print;
321}
322
323
324void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, ObjectImp *value, const Bindings::RootObject *origin, const Bindings::RootObject *current)
325{
326 return Bindings::Instance::createLanguageInstanceForValue (exec, (Bindings::Instance::BindingLanguage)language, value, origin, current);
327}
328
329#endif
330
331void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
332{
333 rep->saveBuiltins(builtins);
334}
335
336void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
337{
338 rep->restoreBuiltins(builtins);
339}
340
341SavedBuiltins::SavedBuiltins() :
342 _internal(0)
343{
344}
345
346SavedBuiltins::~SavedBuiltins()
347{
348 delete _internal;
349}
350
351
352void Interpreter::virtual_hook( int, void* )
353{ /*BASE::virtual_hook( id, data );*/ }
354
355
356Interpreter *ExecState::lexicalInterpreter() const
357{
358 if (!_context) {
359 return dynamicInterpreter();
360 }
361
362 InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
363
364 if (!result) {
365 return dynamicInterpreter();
366 }
367
368 return result->interpreter();
369}
Note: See TracBrowser for help on using the repository browser.