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

Last change on this file since 3009 was 3009, checked in by mjs, 22 years ago

Reviewed by Don.

  • Add kjsprint global function in Development build for ease of debugging.
  • Print uncaught JavaScript exceptions to the console in Development.
  • Improve wording of exception error messages.
  • kjs/function.cpp: (GlobalFuncImp::call):
  • kjs/function.h:
  • kjs/internal.cpp: (InterpreterImp::initGlobalObject):
  • kjs/interpreter.cpp: (Interpreter::evaluate):
  • kjs/nodes.cpp: (NewExprNode::evaluate): (FunctionCallNode::evaluate): (RelationalNode::evaluate):
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 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 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 */
23
24#include "value.h"
25#include "object.h"
26#include "types.h"
27#include "interpreter.h"
28
29#include <assert.h>
30#include <math.h>
31#include <stdio.h>
32
33#include "internal.h"
34#include "collector.h"
35#include "operations.h"
36#include "error_object.h"
37#include "nodes.h"
38#include "context.h"
39
40using namespace KJS;
41
42// ------------------------------ Context --------------------------------------
43
44const ScopeChain &Context::scopeChain() const
45{
46 return rep->scopeChain();
47}
48
49Object Context::variableObject() const
50{
51 return rep->variableObject();
52}
53
54Object Context::thisValue() const
55{
56 return rep->thisValue();
57}
58
59const Context Context::callingContext() const
60{
61 return rep->callingContext();
62}
63
64// ------------------------------ Interpreter ----------------------------------
65
66Interpreter::Interpreter(const Object &global) : rep(0)
67{
68 rep = new InterpreterImp(this,global);
69}
70
71Interpreter::Interpreter()
72{
73 Object global(new ObjectImp());
74 rep = new InterpreterImp(this,global);
75}
76
77Interpreter::~Interpreter()
78{
79 delete rep;
80}
81
82Object &Interpreter::globalObject() const
83{
84 return rep->globalObject();
85}
86
87void Interpreter::initGlobalObject()
88{
89 rep->initGlobalObject();
90}
91
92void Interpreter::lock()
93{
94 InterpreterImp::lock();
95}
96
97void Interpreter::unlock()
98{
99 InterpreterImp::unlock();
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, const Value &thisV)
113{
114 Completion comp = rep->evaluate(code,thisV);
115#if !NDEBUG
116 if (comp.complType() == Throw) {
117 lock();
118 ExecState *exec = rep->globalExec();
119 printf("Uncaught exception: %s\n", comp.value().toObject(exec).toString(exec).ascii());
120 unlock();
121 }
122#endif
123 return comp;
124}
125
126InterpreterImp *Interpreter::imp()
127{
128 return rep;
129}
130
131Object Interpreter::builtinObject() const
132{
133 return rep->builtinObject();
134}
135
136Object Interpreter::builtinFunction() const
137{
138 return rep->builtinFunction();
139}
140
141Object Interpreter::builtinArray() const
142{
143 return rep->builtinArray();
144}
145
146Object Interpreter::builtinBoolean() const
147{
148 return rep->builtinBoolean();
149}
150
151Object Interpreter::builtinString() const
152{
153 return rep->builtinString();
154}
155
156Object Interpreter::builtinNumber() const
157{
158 return rep->builtinNumber();
159}
160
161Object Interpreter::builtinDate() const
162{
163 return rep->builtinDate();
164}
165
166Object Interpreter::builtinRegExp() const
167{
168 return rep->builtinRegExp();
169}
170
171Object Interpreter::builtinError() const
172{
173 return rep->builtinError();
174}
175
176Object Interpreter::builtinObjectPrototype() const
177{
178 return rep->builtinObjectPrototype();
179}
180
181Object Interpreter::builtinFunctionPrototype() const
182{
183 return rep->builtinFunctionPrototype();
184}
185
186Object Interpreter::builtinArrayPrototype() const
187{
188 return rep->builtinArrayPrototype();
189}
190
191Object Interpreter::builtinBooleanPrototype() const
192{
193 return rep->builtinBooleanPrototype();
194}
195
196Object Interpreter::builtinStringPrototype() const
197{
198 return rep->builtinStringPrototype();
199}
200
201Object Interpreter::builtinNumberPrototype() const
202{
203 return rep->builtinNumberPrototype();
204}
205
206Object Interpreter::builtinDatePrototype() const
207{
208 return rep->builtinDatePrototype();
209}
210
211Object Interpreter::builtinRegExpPrototype() const
212{
213 return rep->builtinRegExpPrototype();
214}
215
216Object Interpreter::builtinErrorPrototype() const
217{
218 return rep->builtinErrorPrototype();
219}
220
221Object Interpreter::builtinEvalError() const
222{
223 return rep->builtinEvalError();
224}
225
226Object Interpreter::builtinRangeError() const
227{
228 return rep->builtinRangeError();
229}
230
231Object Interpreter::builtinReferenceError() const
232{
233 return rep->builtinReferenceError();
234}
235
236Object Interpreter::builtinSyntaxError() const
237{
238 return rep->builtinSyntaxError();
239}
240
241Object Interpreter::builtinTypeError() const
242{
243 return rep->builtinTypeError();
244}
245
246Object Interpreter::builtinURIError() const
247{
248 return rep->builtinURIError();
249}
250
251Object Interpreter::builtinEvalErrorPrototype() const
252{
253 return rep->builtinEvalErrorPrototype();
254}
255
256Object Interpreter::builtinRangeErrorPrototype() const
257{
258 return rep->builtinRangeErrorPrototype();
259}
260
261Object Interpreter::builtinReferenceErrorPrototype() const
262{
263 return rep->builtinReferenceErrorPrototype();
264}
265
266Object Interpreter::builtinSyntaxErrorPrototype() const
267{
268 return rep->builtinSyntaxErrorPrototype();
269}
270
271Object Interpreter::builtinTypeErrorPrototype() const
272{
273 return rep->builtinTypeErrorPrototype();
274}
275
276Object Interpreter::builtinURIErrorPrototype() const
277{
278 return rep->builtinURIErrorPrototype();
279}
280
281void Interpreter::setCompatMode(CompatMode mode)
282{
283 rep->setCompatMode(mode);
284}
285
286Interpreter::CompatMode Interpreter::compatMode() const
287{
288 return rep->compatMode();
289}
290
291#ifdef KJS_DEBUG_MEM
292#include "lexer.h"
293void Interpreter::finalCheck()
294{
295 fprintf(stderr,"Interpreter::finalCheck()\n");
296 // Garbage collect - as many times as necessary
297 // (we could delete an object which was holding another object, so
298 // the deref() will happen too late for deleting the impl of the 2nd object).
299 while( Collector::collect() )
300 ;
301
302 Node::finalCheck();
303 Collector::finalCheck();
304 Lexer::globalClear();
305 UString::globalClear();
306}
307#endif
308
309void Interpreter::virtual_hook( int, void* )
310{ /*BASE::virtual_hook( id, data );*/ }
Note: See TracBrowser for help on using the repository browser.