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 |
|
---|
39 | using namespace KJS;
|
---|
40 |
|
---|
41 | // ------------------------------ Context --------------------------------------
|
---|
42 |
|
---|
43 | Context::Context(ContextImp *c)
|
---|
44 | {
|
---|
45 | rep = c;
|
---|
46 | }
|
---|
47 |
|
---|
48 | Context::Context(const Context &c)
|
---|
49 | {
|
---|
50 | rep = c.rep;
|
---|
51 | }
|
---|
52 |
|
---|
53 | Context& Context::operator=(const Context &c)
|
---|
54 | {
|
---|
55 | rep = c.rep;
|
---|
56 | return *this;
|
---|
57 | }
|
---|
58 |
|
---|
59 | Context::~Context()
|
---|
60 | {
|
---|
61 | }
|
---|
62 |
|
---|
63 | bool Context::isNull() const
|
---|
64 | {
|
---|
65 | return (rep == 0);
|
---|
66 | }
|
---|
67 |
|
---|
68 | ContextImp *Context::imp() const
|
---|
69 | {
|
---|
70 | return rep;
|
---|
71 | }
|
---|
72 |
|
---|
73 | const List Context::scopeChain() const
|
---|
74 | {
|
---|
75 | return rep->scopeChain();
|
---|
76 | }
|
---|
77 |
|
---|
78 | Object Context::variableObject() const
|
---|
79 | {
|
---|
80 | return rep->variableObject();
|
---|
81 | }
|
---|
82 |
|
---|
83 | Object Context::thisValue() const
|
---|
84 | {
|
---|
85 | return rep->thisValue();
|
---|
86 | }
|
---|
87 |
|
---|
88 | const Context Context::callingContext() const
|
---|
89 | {
|
---|
90 | return rep->callingContext();
|
---|
91 | }
|
---|
92 |
|
---|
93 | // ------------------------------ Interpreter ----------------------------------
|
---|
94 |
|
---|
95 | Interpreter::Interpreter(const Object &global) : rep(0)
|
---|
96 | {
|
---|
97 | rep = new InterpreterImp(this,global);
|
---|
98 | }
|
---|
99 |
|
---|
100 | Interpreter::Interpreter()
|
---|
101 | {
|
---|
102 | Object global(new ObjectImp());
|
---|
103 | rep = new InterpreterImp(this,global);
|
---|
104 | }
|
---|
105 |
|
---|
106 | Interpreter::~Interpreter()
|
---|
107 | {
|
---|
108 | delete rep;
|
---|
109 | }
|
---|
110 |
|
---|
111 | Object Interpreter::globalObject() const
|
---|
112 | {
|
---|
113 | return rep->globalObject();
|
---|
114 | }
|
---|
115 |
|
---|
116 | void Interpreter::initGlobalObject()
|
---|
117 | {
|
---|
118 | rep->initGlobalObject();
|
---|
119 | }
|
---|
120 |
|
---|
121 | ExecState *Interpreter::globalExec()
|
---|
122 | {
|
---|
123 | return rep->globalExec();
|
---|
124 | }
|
---|
125 |
|
---|
126 | bool Interpreter::checkSyntax(const UString &code)
|
---|
127 | {
|
---|
128 | return rep->checkSyntax(code);
|
---|
129 | }
|
---|
130 |
|
---|
131 | Completion Interpreter::evaluate(const UString &code, const Value &thisV)
|
---|
132 | {
|
---|
133 | return rep->evaluate(code,thisV);
|
---|
134 | }
|
---|
135 |
|
---|
136 | InterpreterImp *Interpreter::imp()
|
---|
137 | {
|
---|
138 | return rep;
|
---|
139 | }
|
---|
140 |
|
---|
141 | Object Interpreter::builtinObject() const
|
---|
142 | {
|
---|
143 | return rep->builtinObject();
|
---|
144 | }
|
---|
145 |
|
---|
146 | Object Interpreter::builtinFunction() const
|
---|
147 | {
|
---|
148 | return rep->builtinFunction();
|
---|
149 | }
|
---|
150 |
|
---|
151 | Object Interpreter::builtinArray() const
|
---|
152 | {
|
---|
153 | return rep->builtinArray();
|
---|
154 | }
|
---|
155 |
|
---|
156 | Object Interpreter::builtinBoolean() const
|
---|
157 | {
|
---|
158 | return rep->builtinBoolean();
|
---|
159 | }
|
---|
160 |
|
---|
161 | Object Interpreter::builtinString() const
|
---|
162 | {
|
---|
163 | return rep->builtinString();
|
---|
164 | }
|
---|
165 |
|
---|
166 | Object Interpreter::builtinNumber() const
|
---|
167 | {
|
---|
168 | return rep->builtinNumber();
|
---|
169 | }
|
---|
170 |
|
---|
171 | Object Interpreter::builtinDate() const
|
---|
172 | {
|
---|
173 | return rep->builtinDate();
|
---|
174 | }
|
---|
175 |
|
---|
176 | Object Interpreter::builtinRegExp() const
|
---|
177 | {
|
---|
178 | return rep->builtinRegExp();
|
---|
179 | }
|
---|
180 |
|
---|
181 | Object Interpreter::builtinError() const
|
---|
182 | {
|
---|
183 | return rep->builtinError();
|
---|
184 | }
|
---|
185 |
|
---|
186 | Object Interpreter::builtinObjectPrototype() const
|
---|
187 | {
|
---|
188 | return rep->builtinObjectPrototype();
|
---|
189 | }
|
---|
190 |
|
---|
191 | Object Interpreter::builtinFunctionPrototype() const
|
---|
192 | {
|
---|
193 | return rep->builtinFunctionPrototype();
|
---|
194 | }
|
---|
195 |
|
---|
196 | Object Interpreter::builtinArrayPrototype() const
|
---|
197 | {
|
---|
198 | return rep->builtinArrayPrototype();
|
---|
199 | }
|
---|
200 |
|
---|
201 | Object Interpreter::builtinBooleanPrototype() const
|
---|
202 | {
|
---|
203 | return rep->builtinBooleanPrototype();
|
---|
204 | }
|
---|
205 |
|
---|
206 | Object Interpreter::builtinStringPrototype() const
|
---|
207 | {
|
---|
208 | return rep->builtinStringPrototype();
|
---|
209 | }
|
---|
210 |
|
---|
211 | Object Interpreter::builtinNumberPrototype() const
|
---|
212 | {
|
---|
213 | return rep->builtinNumberPrototype();
|
---|
214 | }
|
---|
215 |
|
---|
216 | Object Interpreter::builtinDatePrototype() const
|
---|
217 | {
|
---|
218 | return rep->builtinDatePrototype();
|
---|
219 | }
|
---|
220 |
|
---|
221 | Object Interpreter::builtinRegExpPrototype() const
|
---|
222 | {
|
---|
223 | return rep->builtinRegExpPrototype();
|
---|
224 | }
|
---|
225 |
|
---|
226 | Object Interpreter::builtinErrorPrototype() const
|
---|
227 | {
|
---|
228 | return rep->builtinErrorPrototype();
|
---|
229 | }
|
---|
230 |
|
---|
231 | Object Interpreter::builtinEvalError() const
|
---|
232 | {
|
---|
233 | return rep->builtinEvalError();
|
---|
234 | }
|
---|
235 |
|
---|
236 | Object Interpreter::builtinRangeError() const
|
---|
237 | {
|
---|
238 | return rep->builtinRangeError();
|
---|
239 | }
|
---|
240 |
|
---|
241 | Object Interpreter::builtinReferenceError() const
|
---|
242 | {
|
---|
243 | return rep->builtinReferenceError();
|
---|
244 | }
|
---|
245 |
|
---|
246 | Object Interpreter::builtinSyntaxError() const
|
---|
247 | {
|
---|
248 | return rep->builtinSyntaxError();
|
---|
249 | }
|
---|
250 |
|
---|
251 | Object Interpreter::builtinTypeError() const
|
---|
252 | {
|
---|
253 | return rep->builtinTypeError();
|
---|
254 | }
|
---|
255 |
|
---|
256 | Object Interpreter::builtinURIError() const
|
---|
257 | {
|
---|
258 | return rep->builtinURIError();
|
---|
259 | }
|
---|
260 |
|
---|
261 | Object Interpreter::builtinEvalErrorPrototype() const
|
---|
262 | {
|
---|
263 | return rep->builtinEvalErrorPrototype();
|
---|
264 | }
|
---|
265 |
|
---|
266 | Object Interpreter::builtinRangeErrorPrototype() const
|
---|
267 | {
|
---|
268 | return rep->builtinRangeErrorPrototype();
|
---|
269 | }
|
---|
270 |
|
---|
271 | Object Interpreter::builtinReferenceErrorPrototype() const
|
---|
272 | {
|
---|
273 | return rep->builtinReferenceErrorPrototype();
|
---|
274 | }
|
---|
275 |
|
---|
276 | Object Interpreter::builtinSyntaxErrorPrototype() const
|
---|
277 | {
|
---|
278 | return rep->builtinSyntaxErrorPrototype();
|
---|
279 | }
|
---|
280 |
|
---|
281 | Object Interpreter::builtinTypeErrorPrototype() const
|
---|
282 | {
|
---|
283 | return rep->builtinTypeErrorPrototype();
|
---|
284 | }
|
---|
285 |
|
---|
286 | Object Interpreter::builtinURIErrorPrototype() const
|
---|
287 | {
|
---|
288 | return rep->builtinURIErrorPrototype();
|
---|
289 | }
|
---|
290 |
|
---|
291 | void Interpreter::setCompatMode(CompatMode mode)
|
---|
292 | {
|
---|
293 | rep->setCompatMode(mode);
|
---|
294 | }
|
---|
295 |
|
---|
296 | Interpreter::CompatMode Interpreter::compatMode() const
|
---|
297 | {
|
---|
298 | return rep->compatMode();
|
---|
299 | }
|
---|
300 |
|
---|
301 | #ifdef KJS_DEBUG_MEM
|
---|
302 | void Interpreter::finalCheck()
|
---|
303 | {
|
---|
304 | fprintf(stderr,"Interpreter::finalCheck()\n");
|
---|
305 | // Garbage collect - as many times as necessary
|
---|
306 | // (we could delete an object which was holding another object, so
|
---|
307 | // the deref() will happen too late for deleting the impl of the 2nd object).
|
---|
308 | while( Collector::collect() )
|
---|
309 | ;
|
---|
310 |
|
---|
311 | fprintf(stderr,"ListImp::count = %d\n", KJS::ListImp::count);
|
---|
312 | Node::finalCheck();
|
---|
313 | Collector::finalCheck();
|
---|
314 | }
|
---|
315 | #endif
|
---|
316 |
|
---|
317 | // ------------------------------ ExecState --------------------------------------
|
---|
318 |
|
---|
319 | namespace KJS {
|
---|
320 | class ExecStateImp
|
---|
321 | {
|
---|
322 | public:
|
---|
323 | ExecStateImp(Interpreter *interp, ContextImp *con)
|
---|
324 | : interpreter(interp), context(con) {};
|
---|
325 | Interpreter *interpreter;
|
---|
326 | ContextImp *context;
|
---|
327 | Value exception;
|
---|
328 | };
|
---|
329 | };
|
---|
330 |
|
---|
331 | ExecState::~ExecState()
|
---|
332 | {
|
---|
333 | delete rep;
|
---|
334 | }
|
---|
335 |
|
---|
336 | Interpreter *ExecState::interpreter() const
|
---|
337 | {
|
---|
338 | return rep->interpreter;
|
---|
339 | }
|
---|
340 |
|
---|
341 | const Context ExecState::context() const
|
---|
342 | {
|
---|
343 | return rep->context;
|
---|
344 | }
|
---|
345 |
|
---|
346 | void ExecState::setException(const Value &e)
|
---|
347 | {
|
---|
348 | rep->exception = e;
|
---|
349 | }
|
---|
350 |
|
---|
351 | void ExecState::clearException()
|
---|
352 | {
|
---|
353 | rep->exception = Value();
|
---|
354 | }
|
---|
355 |
|
---|
356 | Value ExecState::exception() const
|
---|
357 | {
|
---|
358 | return rep->exception;
|
---|
359 | }
|
---|
360 |
|
---|
361 | bool ExecState::hadException() const
|
---|
362 | {
|
---|
363 | return !rep->exception.isNull();
|
---|
364 | }
|
---|
365 |
|
---|
366 | ExecState::ExecState(Interpreter *interp, ContextImp *con)
|
---|
367 | {
|
---|
368 | rep = new ExecStateImp(interp,con);
|
---|
369 | }
|
---|
370 |
|
---|
371 | void Interpreter::virtual_hook( int, void* )
|
---|
372 | { /*BASE::virtual_hook( id, data );*/ }
|
---|