• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
interpreter.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
4  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
5  * Copyright (C) 2003 Apple Computer, Inc.
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., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, 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 "debugger.h"
38 #include "nodes.h"
39 #include "context.h"
40 
41 using namespace KJS;
42 
43 // ------------------------------ Context --------------------------------------
44 
45 const ScopeChain &Context::scopeChain() const
46 {
47  return rep->scopeChain();
48 }
49 
50 Object Context::variableObject() const
51 {
52  return rep->variableObject();
53 }
54 
55 Object Context::thisValue() const
56 {
57  return rep->thisValue();
58 }
59 
60 const Context Context::callingContext() const
61 {
62  return rep->callingContext();
63 }
64 
65 CodeType Context::codeType() const
66 {
67  return rep->codeType();
68 }
69 
70 int Context::sourceId() const
71 {
72  return rep->sourceId;
73 }
74 
75 int Context::curStmtFirstLine() const
76 {
77  return rep->line0;
78 }
79 
80 int Context::curStmtLastLine() const
81 {
82  return rep->line1;
83 }
84 
85 Object Context::function() const
86 {
87  return Object(rep->function());
88 }
89 
90 Identifier Context::functionName() const
91 {
92  return rep->functionName;
93 }
94 
95 List Context::args() const
96 {
97  return rep->args;
98 }
99 
100 bool KJS::operator==(const Context &c1, const Context &c2)
101 {
102  return (c1.imp() == c2.imp());
103 }
104 
105 bool KJS::operator!=(const Context &c1, const Context &c2)
106 {
107  return (c1.imp() != c2.imp());
108 }
109 
110 // ------------------------------ Interpreter ---------------------------------
111 
112 Interpreter::Interpreter(const Object &global)
113 {
114  rep = new InterpreterImp(this,global);
115 }
116 
117 Interpreter::Interpreter()
118 {
119  Object global(new ObjectImp());
120  rep = new InterpreterImp(this,global);
121 }
122 
123 Interpreter::~Interpreter()
124 {
125  delete rep;
126 }
127 
128 Object &Interpreter::globalObject() const
129 {
130  return rep->globalObject();
131 }
132 
133 void Interpreter::initGlobalObject()
134 {
135  rep->initGlobalObject();
136 }
137 
138 void Interpreter::lock()
139 {
140  InterpreterImp::lock();
141 }
142 
143 void Interpreter::unlock()
144 {
145  InterpreterImp::unlock();
146 }
147 
148 ExecState *Interpreter::globalExec()
149 {
150  return rep->globalExec();
151 }
152 
153 bool Interpreter::checkSyntax(const UString &code, int *errLine, UString *errMsg)
154 {
155  return rep->checkSyntax(code,errLine,errMsg);
156 }
157 
158 bool Interpreter::checkSyntax(const UString &code)
159 {
160  return rep->checkSyntax(code);
161 }
162 
163 Completion Interpreter::evaluate(const UString &code, const Value &thisV)
164 {
165  return rep->evaluate(code,thisV);
166 }
167 
168 InterpreterImp *Interpreter::imp()
169 {
170  return rep;
171 }
172 
173 Object Interpreter::builtinObject() const
174 {
175  return rep->builtinObject();
176 }
177 
178 Object Interpreter::builtinFunction() const
179 {
180  return rep->builtinFunction();
181 }
182 
183 Object Interpreter::builtinArray() const
184 {
185  return rep->builtinArray();
186 }
187 
188 Object Interpreter::builtinBoolean() const
189 {
190  return rep->builtinBoolean();
191 }
192 
193 Object Interpreter::builtinString() const
194 {
195  return rep->builtinString();
196 }
197 
198 Object Interpreter::builtinNumber() const
199 {
200  return rep->builtinNumber();
201 }
202 
203 Object Interpreter::builtinDate() const
204 {
205  return rep->builtinDate();
206 }
207 
208 Object Interpreter::builtinRegExp() const
209 {
210  return rep->builtinRegExp();
211 }
212 
213 Object Interpreter::builtinError() const
214 {
215  return rep->builtinError();
216 }
217 
218 Object Interpreter::builtinObjectPrototype() const
219 {
220  return rep->builtinObjectPrototype();
221 }
222 
223 Object Interpreter::builtinFunctionPrototype() const
224 {
225  return rep->builtinFunctionPrototype();
226 }
227 
228 Object Interpreter::builtinArrayPrototype() const
229 {
230  return rep->builtinArrayPrototype();
231 }
232 
233 Object Interpreter::builtinBooleanPrototype() const
234 {
235  return rep->builtinBooleanPrototype();
236 }
237 
238 Object Interpreter::builtinStringPrototype() const
239 {
240  return rep->builtinStringPrototype();
241 }
242 
243 Object Interpreter::builtinNumberPrototype() const
244 {
245  return rep->builtinNumberPrototype();
246 }
247 
248 Object Interpreter::builtinDatePrototype() const
249 {
250  return rep->builtinDatePrototype();
251 }
252 
253 Object Interpreter::builtinRegExpPrototype() const
254 {
255  return rep->builtinRegExpPrototype();
256 }
257 
258 Object Interpreter::builtinErrorPrototype() const
259 {
260  return rep->builtinErrorPrototype();
261 }
262 
263 Object Interpreter::builtinEvalError() const
264 {
265  return rep->builtinEvalError();
266 }
267 
268 Object Interpreter::builtinRangeError() const
269 {
270  return rep->builtinRangeError();
271 }
272 
273 Object Interpreter::builtinReferenceError() const
274 {
275  return rep->builtinReferenceError();
276 }
277 
278 Object Interpreter::builtinSyntaxError() const
279 {
280  return rep->builtinSyntaxError();
281 }
282 
283 Object Interpreter::builtinTypeError() const
284 {
285  return rep->builtinTypeError();
286 }
287 
288 Object Interpreter::builtinURIError() const
289 {
290  return rep->builtinURIError();
291 }
292 
293 Object Interpreter::builtinEvalErrorPrototype() const
294 {
295  return rep->builtinEvalErrorPrototype();
296 }
297 
298 Object Interpreter::builtinRangeErrorPrototype() const
299 {
300  return rep->builtinRangeErrorPrototype();
301 }
302 
303 Object Interpreter::builtinReferenceErrorPrototype() const
304 {
305  return rep->builtinReferenceErrorPrototype();
306 }
307 
308 Object Interpreter::builtinSyntaxErrorPrototype() const
309 {
310  return rep->builtinSyntaxErrorPrototype();
311 }
312 
313 Object Interpreter::builtinTypeErrorPrototype() const
314 {
315  return rep->builtinTypeErrorPrototype();
316 }
317 
318 Object Interpreter::builtinURIErrorPrototype() const
319 {
320  return rep->builtinURIErrorPrototype();
321 }
322 
323 void Interpreter::setCompatMode(CompatMode mode)
324 {
325  rep->setCompatMode(mode);
326 }
327 
328 Interpreter::CompatMode Interpreter::compatMode() const
329 {
330  return rep->compatMode();
331 }
332 
333 bool Interpreter::collect()
334 {
335  return Collector::collect();
336 }
337 
338 #ifdef KJS_DEBUG_MEM
339 #include "lexer.h"
340 void Interpreter::finalCheck()
341 {
342  fprintf(stderr,"Interpreter::finalCheck()\n");
343  // Garbage collect - as many times as necessary
344  // (we could delete an object which was holding another object, so
345  // the deref() will happen too late for deleting the impl of the 2nd object).
346  while( Collector::collect() )
347  ;
348 
349  Node::finalCheck();
350  Collector::finalCheck();
351  Lexer::globalClear();
352  UString::globalClear();
353 }
354 #endif
355 
356 // ------------------------------ ExecState --------------------------------------
357 
358 void ExecState::setException(const Value &e)
359 {
360  if (e.isValid()) {
361  Debugger *dbg = _interpreter->imp()->debugger();
362  if (dbg)
363  dbg->exception(this,e,_context->inTryCatch());
364  }
365  _exception = e;
366 }
367 
368 void ExecState::clearException()
369 {
370  terminate_request = false;
371  _exception = Value();
372 }
373 
374 bool ExecState::terminate_request = false;
375 
376 static bool defaultConfirm() { return true; }
377 
378 bool (*ExecState::confirmTerminate)() = defaultConfirm;
379 
380 bool ExecState::hadException()
381 {
382  if (terminate_request) {
383  terminate_request = false;
384  if (confirmTerminate())
385  _exception = Error::create((ExecState*)this);
386  }
387  return _exception.isValid();
388 }
389 
390 void Interpreter::virtual_hook( int, void* )
391 { /*BASE::virtual_hook( id, data );*/ }
392 
393 
394 Interpreter *ExecState::lexicalInterpreter() const
395 {
396  // TODO: use proper implementation
397 #if 1
398  return dynamicInterpreter();
399 #else
400  if (!_context) {
401  return dynamicInterpreter();
402  }
403 
404  InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
405 
406  if (!result) {
407  return dynamicInterpreter();
408  }
409 
410  return result->interpreter();
411 #endif
412 }

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.