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

Last change on this file since 13861 was 13603, checked in by eseidel, 19 years ago

2006-03-31 Eric Seidel <[email protected]>

Reviewed by mjs.

A bit more code cleanup.

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