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

Last change on this file since 13211 was 13089, checked in by mjs, 19 years ago

JavaScriptCore:

Reviewed by Darin.


  • Set up new prototype macros and avoid using #if without defined() in JSC


Added new PLATFORM macros and related, to make sure #if's all check if relevant macros
are defined, and to separate core OS-level dependencies from operating environment
dependencies so you can, e.g., build KDE on Mac or Windows.

  • kxmlcore/Platform.h: Added.


  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/jni/jni_utility.cpp: (KJS::Bindings::convertValueToJValue):
  • bindings/objc/WebScriptObject.mm:
  • bindings/objc/objc_instance.mm: (ObjcInstance::end):
  • bindings/softlinking.h:
  • bindings/testbindings.mm: (main):
  • kjs/JSLock.cpp:
  • kjs/collector.cpp: (KJS::Collector::markCurrentThreadConservatively): (KJS::Collector::markOtherThreadConservatively): (KJS::Collector::markStackObjectsConservatively):
  • kjs/config.h:
  • kjs/date_object.cpp: (gmtoffset): (KJS::formatTime): (KJS::DateProtoFunc::callAsFunction): (KJS::DateObjectImp::construct): (KJS::makeTime):
  • kjs/dtoa.cpp:
  • kjs/fpconst.cpp: (KJS::sizeof): (KJS::):
  • kjs/grammar.y:
  • kjs/identifier.cpp:
  • kjs/internal.cpp:
  • kjs/interpreter.cpp: (KJS::Interpreter::evaluate): (KJS::Interpreter::createLanguageInstanceForValue):
  • kjs/interpreter.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/math_object.cpp:
  • kjs/object.cpp:
  • kjs/object.h:
  • kjs/operations.cpp: (KJS::isNaN): (KJS::isInf): (KJS::isPosInf): (KJS::isNegInf):
  • kjs/operations.h:
  • kjs/regexp.cpp: (KJS::RegExp::RegExp): (KJS::RegExp::~RegExp): (KJS::RegExp::match):
  • kjs/regexp.h:
  • kjs/testkjs.cpp: (StopWatch::start): (StopWatch::stop): (StopWatch::getElapsedMS):
  • kjs/ustring.cpp:
  • kjs/ustring.h:
  • kxmlcore/AlwaysInline.h:
  • kxmlcore/Assertions.cpp:
  • kxmlcore/Assertions.h:
  • kxmlcore/FastMalloc.cpp: (KXMLCore::):
  • kxmlcore/FastMalloc.h:
  • kxmlcore/FastMallocInternal.h:
  • kxmlcore/HashTable.h:
  • kxmlcore/TCPageMap.h:
  • kxmlcore/TCSpinLock.h: (TCMalloc_SpinLock::Lock): (TCMalloc_SpinLock::Unlock): (TCMalloc_SlowLock):
  • kxmlcore/TCSystemAlloc.cpp: (TCMalloc_SystemAlloc):
  • os-win32/stdint.h:

JavaScriptGlue:

Not reviewed, but I noticed these trivial extra changes were needed to avoid
breaking the build with my reviewed patch for:


http://bugzilla.opendarwin.org/show_bug.cgi?id=7387


Add config.h, includes of it, and Platform.h forwarding header.

  • JSBase.cpp:
  • JSObject.cpp:
  • JSRun.cpp:
  • JSUtils.cpp:
  • JSValueWrapper.cpp:
  • JavaScriptGlue.cpp:
  • UserObjectImp.cpp:
  • config.h: Added.
  • kxmlcore/Platform.h: Added.

WebCore:

Reviewed by Darin.


Add Platform.h

  • ForwardingHeaders/kxmlcore/Platform.h: Added.
  • bridge/mac/WebCoreFrameNamespaces.m:
  • bridge/mac/WebCoreViewFactory.m:
  • bridge/mac/WebDashboardRegion.m:
  • config.h:
  • platform/Logging.cpp:
  • platform/mac/ScrollViewMac.mm: (WebCore::ScrollView::addChild):
  • platform/mac/WebCoreCookieAdapter.m:
  • platform/mac/WebCoreGraphicsBridge.m:
  • platform/mac/WebCoreHistory.m:
  • platform/mac/WebCoreImageRendererFactory.m:
  • platform/mac/WebCoreKeyGenerator.m:
  • platform/mac/WebCoreView.m:
  • Property svn:eol-style set to native
File size: 8.0 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
357
358void Interpreter::virtual_hook( int, void* )
359{ /*BASE::virtual_hook( id, data );*/ }
360
361
362Interpreter *ExecState::lexicalInterpreter() const
363{
364 if (!_context) {
365 return dynamicInterpreter();
366 }
367
368 InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
369
370 if (!result) {
371 return dynamicInterpreter();
372 }
373
374 return result->interpreter();
375}
376
377}
Note: See TracBrowser for help on using the repository browser.