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

Last change on this file since 15990 was 15990, checked in by andersca, 19 years ago

2006-08-23 Anders Carlsson <[email protected]>

Reviewed by Darin.

Make the bindings compile without CoreFoundation.


  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • bindings/c/c_instance.cpp:
  • bindings/c/c_utility.cpp: (KJS::Bindings::convertUTF8ToUTF16):
  • bindings/npapi.h:
  • bindings/runtime.cpp: (KJS::Bindings::Instance::createBindingForLanguageInstance): (KJS::Bindings::Instance::createLanguageInstanceForValue):
  • bindings/runtime_root.cpp:
  • bindings/runtime_root.h:
  • kjs/interpreter.cpp: (KJS::Interpreter::createLanguageInstanceForValue):
  • kjs/interpreter.h:
  • Property svn:eol-style set to native
File size: 26.2 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 "SavedBuiltins.h"
29#include "array_object.h"
30#include "bool_object.h"
31#include "collector.h"
32#include "context.h"
33#include "date_object.h"
34#include "debugger.h"
35#include "error_object.h"
36#include "function_object.h"
37#include "internal.h"
38#include "math_object.h"
39#include "nodes.h"
40#include "number_object.h"
41#include "object.h"
42#include "object_object.h"
43#include "operations.h"
44#include "regexp_object.h"
45#include "string_object.h"
46#include "types.h"
47#include "value.h"
48
49#include "runtime.h"
50
51#if HAVE(SYS_TIME_H)
52#include <sys/time.h>
53#endif
54
55#include <assert.h>
56#include <math.h>
57#include <signal.h>
58#include <stdio.h>
59
60namespace KJS {
61
62class TimeoutChecker {
63public:
64 void startTimeoutCheck(Interpreter*);
65 void stopTimeoutCheck(Interpreter*);
66 void pauseTimeoutCheck(Interpreter*);
67 void resumeTimeoutCheck(Interpreter*);
68
69private:
70#if HAVE(SYS_TIME_H)
71 static Interpreter* s_executingInterpreter;
72 static void alarmHandler(int);
73
74 Interpreter* m_oldInterpreter;
75 itimerval m_oldtv;
76 itimerval m_pausetv;
77 void (*m_oldAlarmHandler)(int);
78#endif
79};
80
81#if HAVE(SYS_TIME_H)
82Interpreter* TimeoutChecker::s_executingInterpreter = 0;
83#endif
84
85void TimeoutChecker::startTimeoutCheck(Interpreter *interpreter)
86{
87 if (!interpreter->m_timeoutTime)
88 return;
89
90 interpreter->m_startTimeoutCheckCount++;
91
92#if HAVE(SYS_TIME_H)
93 if (s_executingInterpreter == interpreter)
94 return;
95
96 // Block signals
97 m_oldAlarmHandler = signal(SIGALRM, SIG_IGN);
98
99 m_oldInterpreter = s_executingInterpreter;
100 s_executingInterpreter = interpreter;
101
102 itimerval tv = {
103 { interpreter->m_timeoutTime / 1000, (interpreter->m_timeoutTime % 1000) * 1000 },
104 { interpreter->m_timeoutTime / 1000, (interpreter->m_timeoutTime % 1000) * 1000 }
105 };
106 setitimer(ITIMER_REAL, &tv, &m_oldtv);
107
108 // Unblock signals
109 signal(SIGALRM, alarmHandler);
110#endif
111}
112
113void TimeoutChecker::stopTimeoutCheck(Interpreter* interpreter)
114{
115 if (!interpreter->m_timeoutTime)
116 return;
117
118 ASSERT(interpreter->m_startTimeoutCheckCount > 0);
119
120 interpreter->m_startTimeoutCheckCount--;
121
122 if (interpreter->m_startTimeoutCheckCount != 0)
123 return;
124
125#if HAVE(SYS_TIME_H)
126 signal(SIGALRM, SIG_IGN);
127
128 s_executingInterpreter = m_oldInterpreter;
129
130 setitimer(ITIMER_REAL, &m_oldtv, 0L);
131 signal(SIGALRM, m_oldAlarmHandler);
132#endif
133}
134
135#if HAVE(SYS_TIME_H)
136void TimeoutChecker::alarmHandler(int)
137{
138 s_executingInterpreter->m_timedOut = true;
139}
140#endif
141
142void TimeoutChecker::pauseTimeoutCheck(Interpreter* interpreter)
143{
144 if (interpreter->m_startTimeoutCheckCount == 0)
145 return;
146
147#if HAVE(SYS_TIME_H)
148 ASSERT(interpreter == s_executingInterpreter);
149
150 void (*currentSignalHandler)(int);
151
152 // Block signal
153 currentSignalHandler = signal(SIGALRM, SIG_IGN);
154
155 if (currentSignalHandler != alarmHandler) {
156 signal(SIGALRM, currentSignalHandler);
157 return;
158 }
159
160 setitimer(ITIMER_REAL, 0L, &m_pausetv);
161#endif
162
163 interpreter->m_pauseTimeoutCheckCount++;
164}
165
166void TimeoutChecker::resumeTimeoutCheck(Interpreter* interpreter)
167{
168 if (interpreter->m_startTimeoutCheckCount == 0)
169 return;
170
171#if HAVE(SYS_TIME_H)
172 ASSERT(interpreter == s_executingInterpreter);
173#endif
174
175 interpreter->m_pauseTimeoutCheckCount--;
176
177 if (interpreter->m_pauseTimeoutCheckCount != 0)
178 return;
179
180#if HAVE(SYS_TIME_H)
181 void (*currentSignalHandler)(int);
182
183 // Check so we have the right handler
184 currentSignalHandler = signal(SIGALRM, SIG_IGN);
185
186 if (currentSignalHandler != SIG_IGN) {
187 signal(SIGALRM, currentSignalHandler);
188 return;
189 }
190
191 setitimer(ITIMER_REAL, &m_pausetv, 0L);
192
193 // Unblock signal
194 currentSignalHandler = signal(SIGALRM, alarmHandler);
195#endif
196}
197
198Interpreter* Interpreter::s_hook = 0;
199
200typedef HashMap<JSObject*, Interpreter*> InterpreterMap;
201static inline InterpreterMap &interpreterMap()
202{
203 static InterpreterMap* map = new InterpreterMap;
204 return* map;
205}
206
207Interpreter::Interpreter(JSObject* globalObject)
208 : m_globalExec(this, 0)
209 , m_globalObject(globalObject)
210{
211 init();
212}
213
214Interpreter::Interpreter()
215 : m_globalExec(this, 0)
216 , m_globalObject(new JSObject())
217{
218 init();
219}
220
221void Interpreter::init()
222{
223 JSLock lock;
224
225 m_refCount = 0;
226 m_timeoutTime = 0;
227 m_recursion = 0;
228 m_debugger= 0;
229 m_context = 0;
230 m_timedOut = false;
231 m_timeoutChecker = 0;
232 m_startTimeoutCheckCount = 0;
233 m_pauseTimeoutCheckCount = 0;
234 m_compatMode = NativeMode;
235 m_argumentsPropertyName = &argumentsPropertyName;
236 m_specialPrototypePropertyName = &specialPrototypePropertyName;
237
238 interpreterMap().set(m_globalObject, this);
239
240 if (s_hook) {
241 prev = s_hook;
242 next = s_hook->next;
243 s_hook->next->prev = this;
244 s_hook->next = this;
245 } else {
246 // This is the first interpreter
247 s_hook = next = prev = this;
248 }
249
250 initGlobalObject();
251}
252
253Interpreter::~Interpreter()
254{
255 JSLock lock;
256
257 ASSERT (m_startTimeoutCheckCount == 0);
258 ASSERT (m_pauseTimeoutCheckCount == 0);
259
260 delete m_timeoutChecker;
261
262 if (m_debugger)
263 m_debugger->detach(this);
264
265 next->prev = prev;
266 prev->next = next;
267 s_hook = next;
268 if (s_hook == this)
269 {
270 // This was the last interpreter
271 s_hook = 0;
272 }
273
274 interpreterMap().remove(m_globalObject);
275}
276
277JSObject* Interpreter::globalObject() const
278{
279 return m_globalObject;
280}
281
282void Interpreter::initGlobalObject()
283{
284 Identifier::init();
285
286 FunctionPrototype *funcProto = new FunctionPrototype(&m_globalExec);
287 m_FunctionPrototype = funcProto;
288 ObjectPrototype *objProto = new ObjectPrototype(&m_globalExec, funcProto);
289 m_ObjectPrototype = objProto;
290 funcProto->setPrototype(m_ObjectPrototype);
291
292 ArrayPrototype *arrayProto = new ArrayPrototype(&m_globalExec, objProto);
293 m_ArrayPrototype = arrayProto;
294 StringPrototype *stringProto = new StringPrototype(&m_globalExec, objProto);
295 m_StringPrototype = stringProto;
296 BooleanPrototype *booleanProto = new BooleanPrototype(&m_globalExec, objProto, funcProto);
297 m_BooleanPrototype = booleanProto;
298 NumberPrototype *numberProto = new NumberPrototype(&m_globalExec, objProto, funcProto);
299 m_NumberPrototype = numberProto;
300 DatePrototype *dateProto = new DatePrototype(&m_globalExec, objProto);
301 m_DatePrototype = dateProto;
302 RegExpPrototype *regexpProto = new RegExpPrototype(&m_globalExec, objProto, funcProto);
303 m_RegExpPrototype = regexpProto;
304 ErrorPrototype *errorProto = new ErrorPrototype(&m_globalExec, objProto, funcProto);
305 m_ErrorPrototype = errorProto;
306
307 JSObject* o = m_globalObject;
308 while (o->prototype()->isObject())
309 o = static_cast<JSObject*>(o->prototype());
310 o->setPrototype(m_ObjectPrototype);
311
312 // Constructors (Object, Array, etc.)
313 m_Object = new ObjectObjectImp(&m_globalExec, objProto, funcProto);
314 m_Function = new FunctionObjectImp(&m_globalExec, funcProto);
315 m_Array = new ArrayObjectImp(&m_globalExec, funcProto, arrayProto);
316 m_String = new StringObjectImp(&m_globalExec, funcProto, stringProto);
317 m_Boolean = new BooleanObjectImp(&m_globalExec, funcProto, booleanProto);
318 m_Number = new NumberObjectImp(&m_globalExec, funcProto, numberProto);
319 m_Date = new DateObjectImp(&m_globalExec, funcProto, dateProto);
320 m_RegExp = new RegExpObjectImp(&m_globalExec, funcProto, regexpProto);
321 m_Error = new ErrorObjectImp(&m_globalExec, funcProto, errorProto);
322
323 // Error object prototypes
324 m_EvalErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, EvalError, "EvalError", "EvalError");
325 m_RangeErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, RangeError, "RangeError", "RangeError");
326 m_ReferenceErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, ReferenceError, "ReferenceError", "ReferenceError");
327 m_SyntaxErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, SyntaxError, "SyntaxError", "SyntaxError");
328 m_TypeErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, TypeError, "TypeError", "TypeError");
329 m_UriErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, URIError, "URIError", "URIError");
330
331 // Error objects
332 m_EvalError = new NativeErrorImp(&m_globalExec, funcProto, m_EvalErrorPrototype);
333 m_RangeError = new NativeErrorImp(&m_globalExec, funcProto, m_RangeErrorPrototype);
334 m_ReferenceError = new NativeErrorImp(&m_globalExec, funcProto, m_ReferenceErrorPrototype);
335 m_SyntaxError = new NativeErrorImp(&m_globalExec, funcProto, m_SyntaxErrorPrototype);
336 m_TypeError = new NativeErrorImp(&m_globalExec, funcProto, m_TypeErrorPrototype);
337 m_UriError = new NativeErrorImp(&m_globalExec, funcProto, m_UriErrorPrototype);
338
339 // ECMA 15.3.4.1
340 funcProto->put(&m_globalExec, constructorPropertyName, m_Function, DontEnum);
341
342 m_globalObject->put(&m_globalExec, "Object", m_Object, DontEnum);
343 m_globalObject->put(&m_globalExec, "Function", m_Function, DontEnum);
344 m_globalObject->put(&m_globalExec, "Array", m_Array, DontEnum);
345 m_globalObject->put(&m_globalExec, "Boolean", m_Boolean, DontEnum);
346 m_globalObject->put(&m_globalExec, "String", m_String, DontEnum);
347 m_globalObject->put(&m_globalExec, "Number", m_Number, DontEnum);
348 m_globalObject->put(&m_globalExec, "Date", m_Date, DontEnum);
349 m_globalObject->put(&m_globalExec, "RegExp", m_RegExp, DontEnum);
350 m_globalObject->put(&m_globalExec, "Error", m_Error, DontEnum);
351 // Using Internal for those to have something != 0
352 // (see kjs_window). Maybe DontEnum would be ok too ?
353 m_globalObject->put(&m_globalExec, "EvalError",m_EvalError, Internal);
354 m_globalObject->put(&m_globalExec, "RangeError",m_RangeError, Internal);
355 m_globalObject->put(&m_globalExec, "ReferenceError",m_ReferenceError, Internal);
356 m_globalObject->put(&m_globalExec, "SyntaxError",m_SyntaxError, Internal);
357 m_globalObject->put(&m_globalExec, "TypeError",m_TypeError, Internal);
358 m_globalObject->put(&m_globalExec, "URIError",m_UriError, Internal);
359
360 // Set the constructorPropertyName property of all builtin constructors
361 objProto->put(&m_globalExec, constructorPropertyName, m_Object, DontEnum | DontDelete | ReadOnly);
362 funcProto->put(&m_globalExec, constructorPropertyName, m_Function, DontEnum | DontDelete | ReadOnly);
363 arrayProto->put(&m_globalExec, constructorPropertyName, m_Array, DontEnum | DontDelete | ReadOnly);
364 booleanProto->put(&m_globalExec, constructorPropertyName, m_Boolean, DontEnum | DontDelete | ReadOnly);
365 stringProto->put(&m_globalExec, constructorPropertyName, m_String, DontEnum | DontDelete | ReadOnly);
366 numberProto->put(&m_globalExec, constructorPropertyName, m_Number, DontEnum | DontDelete | ReadOnly);
367 dateProto->put(&m_globalExec, constructorPropertyName, m_Date, DontEnum | DontDelete | ReadOnly);
368 regexpProto->put(&m_globalExec, constructorPropertyName, m_RegExp, DontEnum | DontDelete | ReadOnly);
369 errorProto->put(&m_globalExec, constructorPropertyName, m_Error, DontEnum | DontDelete | ReadOnly);
370 m_EvalErrorPrototype->put(&m_globalExec, constructorPropertyName, m_EvalError, DontEnum | DontDelete | ReadOnly);
371 m_RangeErrorPrototype->put(&m_globalExec, constructorPropertyName, m_RangeError, DontEnum | DontDelete | ReadOnly);
372 m_ReferenceErrorPrototype->put(&m_globalExec, constructorPropertyName, m_ReferenceError, DontEnum | DontDelete | ReadOnly);
373 m_SyntaxErrorPrototype->put(&m_globalExec, constructorPropertyName, m_SyntaxError, DontEnum | DontDelete | ReadOnly);
374 m_TypeErrorPrototype->put(&m_globalExec, constructorPropertyName, m_TypeError, DontEnum | DontDelete | ReadOnly);
375 m_UriErrorPrototype->put(&m_globalExec, constructorPropertyName, m_UriError, DontEnum | DontDelete | ReadOnly);
376
377 // built-in values
378 m_globalObject->put(&m_globalExec, "NaN", jsNaN(), DontEnum|DontDelete);
379 m_globalObject->put(&m_globalExec, "Infinity", jsNumber(Inf), DontEnum|DontDelete);
380 m_globalObject->put(&m_globalExec, "undefined", jsUndefined(), DontEnum|DontDelete);
381
382 // built-in functions
383 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
384 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
385 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
386 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
387 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
388 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
389 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
390 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
391 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
392 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
393 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
394#ifndef NDEBUG
395 m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
396#endif
397
398 // built-in objects
399 m_globalObject->put(&m_globalExec, "Math", new MathObjectImp(&m_globalExec, objProto), DontEnum);
400}
401
402ExecState* Interpreter::globalExec()
403{
404 return &m_globalExec;
405}
406
407Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNumber, const UString& code)
408{
409 return checkSyntax(sourceURL, startingLineNumber, code.data(), code.size());
410}
411
412Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength)
413{
414 JSLock lock;
415
416 int errLine;
417 UString errMsg;
418 RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg);
419 if (!progNode)
420 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, sourceURL));
421 return Completion(Normal);
422}
423
424Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
425{
426 return evaluate(sourceURL, startingLineNumber, code.data(), code.size(), thisV);
427}
428
429Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
430{
431 JSLock lock;
432
433 // prevent against infinite recursion
434 if (m_recursion >= 20)
435 return Completion(Throw, Error::create(&m_globalExec, GeneralError, "Recursion too deep"));
436
437 // parse the source code
438 int sid;
439 int errLine;
440 UString errMsg;
441 RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, &sid, &errLine, &errMsg);
442
443 // notify debugger that source has been parsed
444 if (m_debugger) {
445 bool cont = m_debugger->sourceParsed(&m_globalExec, sid, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg);
446 if (!cont)
447 return Completion(Break);
448 }
449
450 // no program node means a syntax error occurred
451 if (!progNode)
452 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, sourceURL));
453
454 m_globalExec.clearException();
455
456 m_recursion++;
457
458 JSObject* globalObj = m_globalObject;
459 JSObject* thisObj = globalObj;
460
461 // "this" must be an object... use same rules as Function.prototype.apply()
462 if (thisV && !thisV->isUndefinedOrNull())
463 thisObj = thisV->toObject(&m_globalExec);
464
465 Completion res;
466 if (m_globalExec.hadException())
467 // the thisV->toObject() conversion above might have thrown an exception - if so, propagate it
468 res = Completion(Throw, m_globalExec.exception());
469 else {
470 // execute the code
471 Context ctx(globalObj, this, thisObj, progNode.get());
472 ExecState newExec(this, &ctx);
473 progNode->processVarDecls(&newExec);
474 res = progNode->execute(&newExec);
475 }
476
477 m_recursion--;
478
479 if (shouldPrintExceptions() && res.complType() == Throw) {
480 JSLock lock;
481 ExecState* exec = globalExec();
482 CString f = sourceURL.UTF8String();
483 CString message = res.value()->toObject(exec)->toString(exec).UTF8String();
484 int line = res.value()->toObject(exec)->get(exec, "line")->toUInt32(exec);
485#if PLATFORM(WIN_OS)
486 printf("%s line %d: %s\n", f.c_str(), line, message.c_str());
487#else
488 printf("[%d] %s line %d: %s\n", getpid(), f.c_str(), line, message.c_str());
489#endif
490 }
491
492 return res;
493}
494
495JSObject *Interpreter::builtinObject() const
496{
497 return m_Object;
498}
499
500JSObject *Interpreter::builtinFunction() const
501{
502 return m_Function;
503}
504
505JSObject *Interpreter::builtinArray() const
506{
507 return m_Array;
508}
509
510JSObject *Interpreter::builtinBoolean() const
511{
512 return m_Boolean;
513}
514
515JSObject *Interpreter::builtinString() const
516{
517 return m_String;
518}
519
520JSObject *Interpreter::builtinNumber() const
521{
522 return m_Number;
523}
524
525JSObject *Interpreter::builtinDate() const
526{
527 return m_Date;
528}
529
530JSObject *Interpreter::builtinRegExp() const
531{
532 return m_RegExp;
533}
534
535JSObject *Interpreter::builtinError() const
536{
537 return m_Error;
538}
539
540JSObject *Interpreter::builtinObjectPrototype() const
541{
542 return m_ObjectPrototype;
543}
544
545JSObject *Interpreter::builtinFunctionPrototype() const
546{
547 return m_FunctionPrototype;
548}
549
550JSObject *Interpreter::builtinArrayPrototype() const
551{
552 return m_ArrayPrototype;
553}
554
555JSObject *Interpreter::builtinBooleanPrototype() const
556{
557 return m_BooleanPrototype;
558}
559
560JSObject *Interpreter::builtinStringPrototype() const
561{
562 return m_StringPrototype;
563}
564
565JSObject *Interpreter::builtinNumberPrototype() const
566{
567 return m_NumberPrototype;
568}
569
570JSObject *Interpreter::builtinDatePrototype() const
571{
572 return m_DatePrototype;
573}
574
575JSObject *Interpreter::builtinRegExpPrototype() const
576{
577 return m_RegExpPrototype;
578}
579
580JSObject *Interpreter::builtinErrorPrototype() const
581{
582 return m_ErrorPrototype;
583}
584
585JSObject *Interpreter::builtinEvalError() const
586{
587 return m_EvalError;
588}
589
590JSObject *Interpreter::builtinRangeError() const
591{
592 return m_RangeError;
593}
594
595JSObject *Interpreter::builtinReferenceError() const
596{
597 return m_ReferenceError;
598}
599
600JSObject *Interpreter::builtinSyntaxError() const
601{
602 return m_SyntaxError;
603}
604
605JSObject *Interpreter::builtinTypeError() const
606{
607 return m_TypeError;
608}
609
610JSObject *Interpreter::builtinURIError() const
611{
612 return m_UriError;
613}
614
615JSObject *Interpreter::builtinEvalErrorPrototype() const
616{
617 return m_EvalErrorPrototype;
618}
619
620JSObject *Interpreter::builtinRangeErrorPrototype() const
621{
622 return m_RangeErrorPrototype;
623}
624
625JSObject *Interpreter::builtinReferenceErrorPrototype() const
626{
627 return m_ReferenceErrorPrototype;
628}
629
630JSObject *Interpreter::builtinSyntaxErrorPrototype() const
631{
632 return m_SyntaxErrorPrototype;
633}
634
635JSObject *Interpreter::builtinTypeErrorPrototype() const
636{
637 return m_TypeErrorPrototype;
638}
639
640JSObject *Interpreter::builtinURIErrorPrototype() const
641{
642 return m_UriErrorPrototype;
643}
644
645bool Interpreter::collect()
646{
647 return Collector::collect();
648}
649
650void Interpreter::mark(bool)
651{
652 if (m_context)
653 m_context->mark();
654 if (m_globalObject && !m_globalObject->marked())
655 m_globalObject->mark();
656 if (m_globalExec.exception() && !m_globalExec.exception()->marked())
657 m_globalExec.exception()->mark();
658}
659
660Interpreter* Interpreter::interpreterWithGlobalObject(JSObject* globalObject)
661{
662 return interpreterMap().get(globalObject);
663}
664
665#ifdef KJS_DEBUG_MEM
666#include "lexer.h"
667void Interpreter::finalCheck()
668{
669 fprintf(stderr,"Interpreter::finalCheck()\n");
670 Collector::collect();
671
672 Node::finalCheck();
673 Collector::finalCheck();
674 Lexer::globalClear();
675 UString::globalClear();
676}
677#endif
678
679static bool printExceptions = false;
680
681bool Interpreter::shouldPrintExceptions()
682{
683 return printExceptions;
684}
685
686void Interpreter::setShouldPrintExceptions(bool print)
687{
688 printExceptions = print;
689}
690
691void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, JSObject *value, const Bindings::RootObject *origin, const Bindings::RootObject *current)
692{
693 return Bindings::Instance::createLanguageInstanceForValue (exec, (Bindings::Instance::BindingLanguage)language, value, origin, current);
694}
695
696void Interpreter::saveBuiltins (SavedBuiltins& builtins) const
697{
698 if (!builtins._internal)
699 builtins._internal = new SavedBuiltinsInternal;
700
701 builtins._internal->m_Object = m_Object;
702 builtins._internal->m_Function = m_Function;
703 builtins._internal->m_Array = m_Array;
704 builtins._internal->m_Boolean = m_Boolean;
705 builtins._internal->m_String = m_String;
706 builtins._internal->m_Number = m_Number;
707 builtins._internal->m_Date = m_Date;
708 builtins._internal->m_RegExp = m_RegExp;
709 builtins._internal->m_Error = m_Error;
710
711 builtins._internal->m_ObjectPrototype = m_ObjectPrototype;
712 builtins._internal->m_FunctionPrototype = m_FunctionPrototype;
713 builtins._internal->m_ArrayPrototype = m_ArrayPrototype;
714 builtins._internal->m_BooleanPrototype = m_BooleanPrototype;
715 builtins._internal->m_StringPrototype = m_StringPrototype;
716 builtins._internal->m_NumberPrototype = m_NumberPrototype;
717 builtins._internal->m_DatePrototype = m_DatePrototype;
718 builtins._internal->m_RegExpPrototype = m_RegExpPrototype;
719 builtins._internal->m_ErrorPrototype = m_ErrorPrototype;
720
721 builtins._internal->m_EvalError = m_EvalError;
722 builtins._internal->m_RangeError = m_RangeError;
723 builtins._internal->m_ReferenceError = m_ReferenceError;
724 builtins._internal->m_SyntaxError = m_SyntaxError;
725 builtins._internal->m_TypeError = m_TypeError;
726 builtins._internal->m_UriError = m_UriError;
727
728 builtins._internal->m_EvalErrorPrototype = m_EvalErrorPrototype;
729 builtins._internal->m_RangeErrorPrototype = m_RangeErrorPrototype;
730 builtins._internal->m_ReferenceErrorPrototype = m_ReferenceErrorPrototype;
731 builtins._internal->m_SyntaxErrorPrototype = m_SyntaxErrorPrototype;
732 builtins._internal->m_TypeErrorPrototype = m_TypeErrorPrototype;
733 builtins._internal->m_UriErrorPrototype = m_UriErrorPrototype;
734}
735
736void Interpreter::restoreBuiltins (const SavedBuiltins& builtins)
737{
738 if (!builtins._internal)
739 return;
740
741 m_Object = builtins._internal->m_Object;
742 m_Function = builtins._internal->m_Function;
743 m_Array = builtins._internal->m_Array;
744 m_Boolean = builtins._internal->m_Boolean;
745 m_String = builtins._internal->m_String;
746 m_Number = builtins._internal->m_Number;
747 m_Date = builtins._internal->m_Date;
748 m_RegExp = builtins._internal->m_RegExp;
749 m_Error = builtins._internal->m_Error;
750
751 m_ObjectPrototype = builtins._internal->m_ObjectPrototype;
752 m_FunctionPrototype = builtins._internal->m_FunctionPrototype;
753 m_ArrayPrototype = builtins._internal->m_ArrayPrototype;
754 m_BooleanPrototype = builtins._internal->m_BooleanPrototype;
755 m_StringPrototype = builtins._internal->m_StringPrototype;
756 m_NumberPrototype = builtins._internal->m_NumberPrototype;
757 m_DatePrototype = builtins._internal->m_DatePrototype;
758 m_RegExpPrototype = builtins._internal->m_RegExpPrototype;
759 m_ErrorPrototype = builtins._internal->m_ErrorPrototype;
760
761 m_EvalError = builtins._internal->m_EvalError;
762 m_RangeError = builtins._internal->m_RangeError;
763 m_ReferenceError = builtins._internal->m_ReferenceError;
764 m_SyntaxError = builtins._internal->m_SyntaxError;
765 m_TypeError = builtins._internal->m_TypeError;
766 m_UriError = builtins._internal->m_UriError;
767
768 m_EvalErrorPrototype = builtins._internal->m_EvalErrorPrototype;
769 m_RangeErrorPrototype = builtins._internal->m_RangeErrorPrototype;
770 m_ReferenceErrorPrototype = builtins._internal->m_ReferenceErrorPrototype;
771 m_SyntaxErrorPrototype = builtins._internal->m_SyntaxErrorPrototype;
772 m_TypeErrorPrototype = builtins._internal->m_TypeErrorPrototype;
773 m_UriErrorPrototype = builtins._internal->m_UriErrorPrototype;
774}
775
776void Interpreter::startTimeoutCheck()
777{
778 if (!m_timeoutChecker)
779 m_timeoutChecker = new TimeoutChecker;
780
781 m_timeoutChecker->startTimeoutCheck(this);
782}
783
784void Interpreter::stopTimeoutCheck()
785{
786 ASSERT(m_timeoutChecker);
787
788 m_timeoutChecker->stopTimeoutCheck(this);
789}
790
791void Interpreter::pauseTimeoutCheck()
792{
793 ASSERT(m_timeoutChecker);
794
795 m_timeoutChecker->pauseTimeoutCheck(this);
796}
797
798void Interpreter::resumeTimeoutCheck()
799{
800 ASSERT(m_timeoutChecker);
801
802 m_timeoutChecker->resumeTimeoutCheck(this);
803}
804
805bool Interpreter::handleTimeout()
806{
807 m_timedOut = false;
808
809 pauseTimeoutCheck();
810 bool retval = shouldInterruptScript();
811 resumeTimeoutCheck();
812
813 return retval;
814}
815
816
817SavedBuiltins::SavedBuiltins() :
818 _internal(0)
819{
820}
821
822SavedBuiltins::~SavedBuiltins()
823{
824 delete _internal;
825}
826
827}
Note: See TracBrowser for help on using the repository browser.