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

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

-rolled in patches for http://bugzilla.opendarwin.org/show_bug.cgi?id=3945
[PATCH] Safe merges of comments and other trivialities from KDE's kjs

-patch by Martijn Klingens <[email protected]>

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