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

Last change on this file since 6783 was 6783, checked in by darin, 21 years ago
  • fixed <rdar://problem/3682489>: (JavaScriptGlue no longer compiles because Interpreter::evaluate parameters changed)
  • kjs/interpreter.h: Added an overload to make JavaScriptGlue compile.
  • kjs/interpreter.cpp: (KJS::Interpreter::evaluate): Implemented the overload.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, 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("%s:%s\n", f, message);
134 free(f);
135 unlock();
136 }
137#endif
138
139 return comp;
140}
141
142InterpreterImp *Interpreter::imp()
143{
144 return rep;
145}
146
147Object Interpreter::builtinObject() const
148{
149 return rep->builtinObject();
150}
151
152Object Interpreter::builtinFunction() const
153{
154 return rep->builtinFunction();
155}
156
157Object Interpreter::builtinArray() const
158{
159 return rep->builtinArray();
160}
161
162Object Interpreter::builtinBoolean() const
163{
164 return rep->builtinBoolean();
165}
166
167Object Interpreter::builtinString() const
168{
169 return rep->builtinString();
170}
171
172Object Interpreter::builtinNumber() const
173{
174 return rep->builtinNumber();
175}
176
177Object Interpreter::builtinDate() const
178{
179 return rep->builtinDate();
180}
181
182Object Interpreter::builtinRegExp() const
183{
184 return rep->builtinRegExp();
185}
186
187Object Interpreter::builtinError() const
188{
189 return rep->builtinError();
190}
191
192Object Interpreter::builtinObjectPrototype() const
193{
194 return rep->builtinObjectPrototype();
195}
196
197Object Interpreter::builtinFunctionPrototype() const
198{
199 return rep->builtinFunctionPrototype();
200}
201
202Object Interpreter::builtinArrayPrototype() const
203{
204 return rep->builtinArrayPrototype();
205}
206
207Object Interpreter::builtinBooleanPrototype() const
208{
209 return rep->builtinBooleanPrototype();
210}
211
212Object Interpreter::builtinStringPrototype() const
213{
214 return rep->builtinStringPrototype();
215}
216
217Object Interpreter::builtinNumberPrototype() const
218{
219 return rep->builtinNumberPrototype();
220}
221
222Object Interpreter::builtinDatePrototype() const
223{
224 return rep->builtinDatePrototype();
225}
226
227Object Interpreter::builtinRegExpPrototype() const
228{
229 return rep->builtinRegExpPrototype();
230}
231
232Object Interpreter::builtinErrorPrototype() const
233{
234 return rep->builtinErrorPrototype();
235}
236
237Object Interpreter::builtinEvalError() const
238{
239 return rep->builtinEvalError();
240}
241
242Object Interpreter::builtinRangeError() const
243{
244 return rep->builtinRangeError();
245}
246
247Object Interpreter::builtinReferenceError() const
248{
249 return rep->builtinReferenceError();
250}
251
252Object Interpreter::builtinSyntaxError() const
253{
254 return rep->builtinSyntaxError();
255}
256
257Object Interpreter::builtinTypeError() const
258{
259 return rep->builtinTypeError();
260}
261
262Object Interpreter::builtinURIError() const
263{
264 return rep->builtinURIError();
265}
266
267Object Interpreter::builtinEvalErrorPrototype() const
268{
269 return rep->builtinEvalErrorPrototype();
270}
271
272Object Interpreter::builtinRangeErrorPrototype() const
273{
274 return rep->builtinRangeErrorPrototype();
275}
276
277Object Interpreter::builtinReferenceErrorPrototype() const
278{
279 return rep->builtinReferenceErrorPrototype();
280}
281
282Object Interpreter::builtinSyntaxErrorPrototype() const
283{
284 return rep->builtinSyntaxErrorPrototype();
285}
286
287Object Interpreter::builtinTypeErrorPrototype() const
288{
289 return rep->builtinTypeErrorPrototype();
290}
291
292Object Interpreter::builtinURIErrorPrototype() const
293{
294 return rep->builtinURIErrorPrototype();
295}
296
297void Interpreter::setCompatMode(CompatMode mode)
298{
299 rep->setCompatMode(mode);
300}
301
302Interpreter::CompatMode Interpreter::compatMode() const
303{
304 return rep->compatMode();
305}
306
307#ifdef KJS_DEBUG_MEM
308#include "lexer.h"
309void Interpreter::finalCheck()
310{
311 fprintf(stderr,"Interpreter::finalCheck()\n");
312 // Garbage collect - as many times as necessary
313 // (we could delete an object which was holding another object, so
314 // the deref() will happen too late for deleting the impl of the 2nd object).
315 while( Collector::collect() )
316 ;
317
318 Node::finalCheck();
319 Collector::finalCheck();
320 Lexer::globalClear();
321 UString::globalClear();
322}
323#endif
324
325#if APPLE_CHANGES
326static bool printExceptions = false;
327
328bool Interpreter::shouldPrintExceptions()
329{
330 return printExceptions;
331}
332
333void Interpreter::setShouldPrintExceptions(bool print)
334{
335 printExceptions = print;
336}
337#endif
338
339void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
340{
341 rep->saveBuiltins(builtins);
342}
343
344void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
345{
346 rep->restoreBuiltins(builtins);
347}
348
349SavedBuiltins::SavedBuiltins() :
350 _internal(0)
351{
352}
353
354SavedBuiltins::~SavedBuiltins()
355{
356 delete _internal;
357}
358
359
360void Interpreter::virtual_hook( int, void* )
361{ /*BASE::virtual_hook( id, data );*/ }
362
363
364Interpreter *ExecState::lexicalInterpreter() const
365{
366 if (!_context) {
367 return dynamicInterpreter();
368 }
369
370 InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
371
372 if (!result) {
373 return dynamicInterpreter();
374 }
375
376 return result->interpreter();
377}
Note: See TracBrowser for help on using the repository browser.