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

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

JavaScriptCore:

Reviewed by mjs.


On alternate threads, DOMObjects remain in the
ScriptInterpreter's cache because they're not collected. So, they
need an opportunity to mark their children.


I'm not particularly happy with this solution because it fails to
resolve many outstanding issues with the DOM object cache. Since none
of those issues is a crasher or a serious compatibility concern,
and since the behavior of other browsers is not much to go on in this
case, I've filed <rdar://problem/4561439> about that, and I'm moving on
with my life.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/collector.cpp: (KJS::Collector::collect):
  • kjs/internal.cpp: (KJS::InterpreterImp::mark):
  • kjs/internal.h:
  • kjs/interpreter.cpp: (KJS::Interpreter::mark):
  • kjs/interpreter.h:

LayoutTests:

Layout tests for DOM object cache and garbage collection,
<rdar://problem/4557926> TOT REGRESSION: Crash occurs when attempting
to view image in slideshow mode at http://d.smugmug.com/gallery/581716
( KJS::IfNode::execute (KJS::ExecState*) + 312) if you use a PAC file

  • fast/dom/gc-8-expected.txt: Added.
  • fast/dom/gc-8.html: Added.
  • fast/dom/gc-9-expected.txt: Added.
  • fast/dom/gc-9.html: Added.

WebCore:

Reviewed by mjs.

On alternate threads, DOMObjects remain in the
ScriptInterpreter's cache because they're not collected. So, they
need an opportunity to mark their children.


I'm not particularly happy with this solution because it fails to
resolve many outstanding issues with the DOM object cache. Since none
of those issues is a crasher or a serious compatibility concern,
and since the behavior of other browsers is not much to go on in this
case, I've filed <rdar://problem/4561439> about that, and I'm moving
on with my life.

Also added functionality for testing garbage collection from inside
DumpRenderTree.


Also removed XMLHttpRequest from the DOM object cache because XMLHttpRequest
objects aren't accessed through the DOM.


Also added JS locking around access to some shared data structures in
WebCoreJavaScript, even though it probably doesn't matter in practice.

  • bindings/js/JSXMLHttpRequest.cpp: (KJS::JSXMLHttpRequest::JSXMLHttpRequest): (KJS::JSXMLHttpRequest::~JSXMLHttpRequest):
  • bindings/js/kjs_binding.cpp: (KJS::ScriptInterpreter::mark):
  • bindings/js/kjs_binding.h:
  • bridge/mac/WebCoreJavaScript.h:
  • bridge/mac/WebCoreJavaScript.mm: (collect): (+[WebCoreJavaScript objectCount]): (+[WebCoreJavaScript interpreterCount]): (+[WebCoreJavaScript protectedObjectCount]): (+[WebCoreJavaScript garbageCollect]): (+[WebCoreJavaScript garbageCollectOnAlternateThread:]): (+[WebCoreJavaScript shouldPrintExceptions]): (+[WebCoreJavaScript setShouldPrintExceptions:]):

WebKitTools:

Reviewed by mjs.


Added 'GCController' to DRT to support garbage collection layout tests.


GCController.collect() and GCController.collectOnAlternateThread() do
what you would expect. The latter takes a boolean argument sepcifying
whether to wait for garbage collection to finish before continuing to
execute script.

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