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

Last change on this file since 12305 was 12305, checked in by staikos, 19 years ago

Reviewed by Maciej and Darin.

  • kxmlcore/Assertions.h: This file only works with APPLE right now
  • kjs/interpreter.cpp: ditto
  • kjs/simple_number.h: Add assert.h and remove from config.h
  • kjs/array_object.cpp: Use relative paths for kxmlcore includes
  • kjs/testkjs.cpp: Use relative paths for kxmlcore includes
  • Property svn:eol-style set to native
File size: 7.9 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., 51 Franklin Steet, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "config.h"
26#include "interpreter.h"
27
28#include <assert.h>
29#include <math.h>
30#include <stdio.h>
31
32#include "collector.h"
33#include "context.h"
34#include "error_object.h"
35#include "internal.h"
36#include "nodes.h"
37#include "object.h"
38#include "operations.h"
39#if __APPLE__
40#include "runtime.h"
41#endif
42#include "types.h"
43#include "value.h"
44
45namespace KJS {
46
47// ------------------------------ Context --------------------------------------
48
49const ScopeChain &Context::scopeChain() const
50{
51 return rep->scopeChain();
52}
53
54JSObject *Context::variableObject() const
55{
56 return rep->variableObject();
57}
58
59JSObject *Context::thisValue() const
60{
61 return rep->thisValue();
62}
63
64const Context Context::callingContext() const
65{
66 return rep->callingContext();
67}
68
69// ------------------------------ Interpreter ----------------------------------
70
71Interpreter::Interpreter(JSObject *global)
72 : rep(0)
73 , m_argumentsPropertyName(&argumentsPropertyName)
74 , m_specialPrototypePropertyName(&specialPrototypePropertyName)
75{
76 rep = new InterpreterImp(this, global);
77}
78
79Interpreter::Interpreter()
80 : rep(0)
81 , m_argumentsPropertyName(&argumentsPropertyName)
82 , m_specialPrototypePropertyName(&specialPrototypePropertyName)
83{
84 rep = new InterpreterImp(this, new JSObject);
85}
86
87Interpreter::~Interpreter()
88{
89 delete rep;
90}
91
92JSObject *Interpreter::globalObject() const
93{
94 return rep->globalObject();
95}
96
97void Interpreter::initGlobalObject()
98{
99 rep->initGlobalObject();
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& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
113{
114 return evaluate(sourceURL, startingLineNumber, code.data(), code.size());
115}
116
117Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
118{
119 Completion comp = rep->evaluate(code, codeLength, thisV, sourceURL, startingLineNumber);
120
121 if (shouldPrintExceptions() && comp.complType() == Throw) {
122 JSLock lock;
123 ExecState *exec = rep->globalExec();
124 CString f = sourceURL.UTF8String();
125 CString message = comp.value()->toObject(exec)->toString(exec).UTF8String();
126#ifdef WIN32
127 printf("%s:%s\n", f.c_str(), message.c_str());
128#else
129 printf("[%d] %s:%s\n", getpid(), f.c_str(), message.c_str());
130#endif
131 }
132
133 return comp;
134}
135
136JSObject *Interpreter::builtinObject() const
137{
138 return rep->builtinObject();
139}
140
141JSObject *Interpreter::builtinFunction() const
142{
143 return rep->builtinFunction();
144}
145
146JSObject *Interpreter::builtinArray() const
147{
148 return rep->builtinArray();
149}
150
151JSObject *Interpreter::builtinBoolean() const
152{
153 return rep->builtinBoolean();
154}
155
156JSObject *Interpreter::builtinString() const
157{
158 return rep->builtinString();
159}
160
161JSObject *Interpreter::builtinNumber() const
162{
163 return rep->builtinNumber();
164}
165
166JSObject *Interpreter::builtinDate() const
167{
168 return rep->builtinDate();
169}
170
171JSObject *Interpreter::builtinRegExp() const
172{
173 return rep->builtinRegExp();
174}
175
176JSObject *Interpreter::builtinError() const
177{
178 return rep->builtinError();
179}
180
181JSObject *Interpreter::builtinObjectPrototype() const
182{
183 return rep->builtinObjectPrototype();
184}
185
186JSObject *Interpreter::builtinFunctionPrototype() const
187{
188 return rep->builtinFunctionPrototype();
189}
190
191JSObject *Interpreter::builtinArrayPrototype() const
192{
193 return rep->builtinArrayPrototype();
194}
195
196JSObject *Interpreter::builtinBooleanPrototype() const
197{
198 return rep->builtinBooleanPrototype();
199}
200
201JSObject *Interpreter::builtinStringPrototype() const
202{
203 return rep->builtinStringPrototype();
204}
205
206JSObject *Interpreter::builtinNumberPrototype() const
207{
208 return rep->builtinNumberPrototype();
209}
210
211JSObject *Interpreter::builtinDatePrototype() const
212{
213 return rep->builtinDatePrototype();
214}
215
216JSObject *Interpreter::builtinRegExpPrototype() const
217{
218 return rep->builtinRegExpPrototype();
219}
220
221JSObject *Interpreter::builtinErrorPrototype() const
222{
223 return rep->builtinErrorPrototype();
224}
225
226JSObject *Interpreter::builtinEvalError() const
227{
228 return rep->builtinEvalError();
229}
230
231JSObject *Interpreter::builtinRangeError() const
232{
233 return rep->builtinRangeError();
234}
235
236JSObject *Interpreter::builtinReferenceError() const
237{
238 return rep->builtinReferenceError();
239}
240
241JSObject *Interpreter::builtinSyntaxError() const
242{
243 return rep->builtinSyntaxError();
244}
245
246JSObject *Interpreter::builtinTypeError() const
247{
248 return rep->builtinTypeError();
249}
250
251JSObject *Interpreter::builtinURIError() const
252{
253 return rep->builtinURIError();
254}
255
256JSObject *Interpreter::builtinEvalErrorPrototype() const
257{
258 return rep->builtinEvalErrorPrototype();
259}
260
261JSObject *Interpreter::builtinRangeErrorPrototype() const
262{
263 return rep->builtinRangeErrorPrototype();
264}
265
266JSObject *Interpreter::builtinReferenceErrorPrototype() const
267{
268 return rep->builtinReferenceErrorPrototype();
269}
270
271JSObject *Interpreter::builtinSyntaxErrorPrototype() const
272{
273 return rep->builtinSyntaxErrorPrototype();
274}
275
276JSObject *Interpreter::builtinTypeErrorPrototype() const
277{
278 return rep->builtinTypeErrorPrototype();
279}
280
281JSObject *Interpreter::builtinURIErrorPrototype() const
282{
283 return rep->builtinURIErrorPrototype();
284}
285
286void Interpreter::setCompatMode(CompatMode mode)
287{
288 rep->setCompatMode(mode);
289}
290
291Interpreter::CompatMode Interpreter::compatMode() const
292{
293 return rep->compatMode();
294}
295
296bool Interpreter::collect()
297{
298 return Collector::collect();
299}
300
301#ifdef KJS_DEBUG_MEM
302#include "lexer.h"
303void Interpreter::finalCheck()
304{
305 fprintf(stderr,"Interpreter::finalCheck()\n");
306 Collector::collect();
307
308 Node::finalCheck();
309 Collector::finalCheck();
310 Lexer::globalClear();
311 UString::globalClear();
312}
313#endif
314
315static bool printExceptions = false;
316
317bool Interpreter::shouldPrintExceptions()
318{
319 return printExceptions;
320}
321
322void Interpreter::setShouldPrintExceptions(bool print)
323{
324 printExceptions = print;
325}
326
327#if __APPLE__
328void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, JSObject *value, const Bindings::RootObject *origin, const Bindings::RootObject *current)
329{
330 return Bindings::Instance::createLanguageInstanceForValue (exec, (Bindings::Instance::BindingLanguage)language, value, origin, current);
331}
332
333#endif
334
335void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
336{
337 rep->saveBuiltins(builtins);
338}
339
340void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
341{
342 rep->restoreBuiltins(builtins);
343}
344
345SavedBuiltins::SavedBuiltins() :
346 _internal(0)
347{
348}
349
350SavedBuiltins::~SavedBuiltins()
351{
352 delete _internal;
353}
354
355
356void Interpreter::virtual_hook( int, void* )
357{ /*BASE::virtual_hook( id, data );*/ }
358
359
360Interpreter *ExecState::lexicalInterpreter() const
361{
362 if (!_context) {
363 return dynamicInterpreter();
364 }
365
366 InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
367
368 if (!result) {
369 return dynamicInterpreter();
370 }
371
372 return result->interpreter();
373}
374
375}
Note: See TracBrowser for help on using the repository browser.