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