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

Last change on this file since 11614 was 11614, checked in by darin, 19 years ago

JavaScriptCore:

Reviewed by Maciej.

  • kjs/internal.h:
  • kjs/internal.cpp: (KJS::InterpreterImp::evaluate): Change to take a character pointer and length rather than a UString.
  • kjs/interpreter.h:
  • kjs/interpreter.cpp: (Interpreter::evaluate): Ditto.
  • kjs/protect.h: Remove uneeded "convert to bool" operator since we already have a "convert to raw pointer" operator in this class.

WebCore:

Reviewed by Maciej.

  • khtml/ecma/kjs_dom.cpp: (KJS::DOMNode::getListener): Use listenerObj instead of listenerObjImp.
  • khtml/ecma/kjs_html.cpp: (KJS::Image::getValueProperty): Ditto.
  • khtml/ecma/xmlhttprequest.cpp: (KJS::XMLHttpRequest::getValueProperty): Ditto.
  • khtml/ecma/kjs_window.h:
  • khtml/ecma/kjs_window.cpp: (KJS::Window::getListener): Ditto. (KJS::Window::getJSLazyEventListener): Take code as a DOMString, not QString.
  • khtml/ecma/kjs_events.cpp: (KJS::jsStringOrUndefined): Renamed function and moved it to the top of the file. (KJS::JSAbstractEventListener::handleEvent): Cleaned up function, removed double logging, and fixed code path to not use UString::ascii(). (KJS::JSUnprotectedEventListener::JSUnprotectedEventListener): Updated since type of the window object is now Window. (KJS::JSUnprotectedEventListener::~JSUnprotectedEventListener): Ditto. (KJS::JSUnprotectedEventListener::windowObj): Ditto. (KJS::JSEventListener::JSEventListener): Ditto. (KJS::JSEventListener::~JSEventListener): Ditto. (KJS::JSEventListener::windowObj): Ditto. (KJS::JSLazyEventListener::JSLazyEventListener): Ditto. Also changed code to be a DOMString instead of a QString. (KJS::JSLazyEventListener::handleEvent): Removed function because the base class handleEvent already calls listenerObj which takes care of parseCode -- no need to do an additional parseCode here. (KJS::JSLazyEventListener::parseCode): Rearrange and clean up a bit. Code is now a DOMString instead of a QString. (KJS::Clipboard::Clipboard): Remove explicit ref since we now use a RefPtr for the clipboard object. (KJS::Clipboard::getValueProperty): Update to call jsStringOrUndefined.
  • khtml/ecma/kjs_events.h: Reformatted the file. Changed windowObj functions to return Window* instead of ObjectImp*. Removed listenerObjImp function. Removed destructors from many classes that don't need them. Used a RefPtr for the ClipboardImpl in a Clipboard object.
  • khtml/ecma/kjs_proxy.h:
  • khtml/ecma/kjs_proxy.cpp: (KJSProxyImpl::evaluate): Take filename and code as DOMString instead of QString. (KJSProxyImpl::createHTMLEventHandler): Take URL and code as DOMString.
  • khtml/xml/dom_docimpl.h:
  • khtml/xml/dom_docimpl.cpp: (DocumentImpl::createHTMLEventListener): Take a DOMString rather than a QString for the JavaScript code. (DocumentImpl::setHTMLWindowEventListener): Added an overload that takes an attribute pointer. Calls through after extracting the code from the attribute value.
  • khtml/html/html_elementimpl.h:
  • khtml/html/html_elementimpl.cpp: (HTMLElementImpl::setHTMLEventListener): New version of function that takes an attribute pointer; calls through to the base class after extracting the code from the attribute value.
  • khtml/html/html_baseimpl.cpp: (HTMLBodyElementImpl::parseMappedAttribute): Change to use new setHTMLWindowEventListener and setHTMLEventListener that takes an attribute pointer. (HTMLFrameElementImpl::parseMappedAttribute): Ditto. (HTMLFrameSetElementImpl::parseMappedAttribute): Ditto.
  • khtml/html/html_elementimpl.cpp: (HTMLElementImpl::parseMappedAttribute): Ditto.
  • khtml/html/html_formimpl.cpp: (DOM::HTMLFormElementImpl::parseMappedAttribute): Ditto. (DOM::HTMLButtonElementImpl::parseMappedAttribute): Ditto. (DOM::HTMLInputElementImpl::parseMappedAttribute): Ditto. (DOM::HTMLLabelElementImpl::parseMappedAttribute): Ditto. (DOM::HTMLSelectElementImpl::parseMappedAttribute): Ditto. (DOM::HTMLTextAreaElementImpl::parseMappedAttribute): Ditto.
  • khtml/html/html_imageimpl.cpp: (DOM::HTMLImageElementImpl::parseMappedAttribute): Ditto.
  • khtml/html/html_objectimpl.cpp: (DOM::HTMLObjectElementImpl::parseMappedAttribute): Ditto.
  • khtml/html/html_headimpl.h:
  • khtml/html/html_headimpl.cpp: (HTMLScriptElementImpl::notifyFinished): Don't convert URL to QString since we now take a DOMString. (HTMLScriptElementImpl::evaluateScript): Change to take script as a DOMString.
  • khtml/khtml_part.h:
  • khtml/khtml_part.cpp: (KHTMLPart::createHTMLEventListener): Take a DOMString rather than a QString for the JavaScript code.
  • kwq/WebCoreScriptDebugger.mm: (-[WebCoreScriptCallFrame evaluateWebScript:]): Change code path so it doesn't convert an NSString to UTF-8 to get it into the JavaScript machinery. Use QString::fromNSString instead for now.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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 "value.h"
27#include "object.h"
28#include "types.h"
29#include "interpreter.h"
30#if APPLE_CHANGES
31#include "runtime.h"
32#endif
33
34#include <assert.h>
35#include <math.h>
36#include <stdio.h>
37
38#include "internal.h"
39#include "collector.h"
40#include "operations.h"
41#include "error_object.h"
42#include "nodes.h"
43#include "context.h"
44
45using namespace 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 printf("[%d] %s:%s\n", getpid(), f.c_str(), message.c_str());
127 }
128
129 return comp;
130}
131
132JSObject *Interpreter::builtinObject() const
133{
134 return rep->builtinObject();
135}
136
137JSObject *Interpreter::builtinFunction() const
138{
139 return rep->builtinFunction();
140}
141
142JSObject *Interpreter::builtinArray() const
143{
144 return rep->builtinArray();
145}
146
147JSObject *Interpreter::builtinBoolean() const
148{
149 return rep->builtinBoolean();
150}
151
152JSObject *Interpreter::builtinString() const
153{
154 return rep->builtinString();
155}
156
157JSObject *Interpreter::builtinNumber() const
158{
159 return rep->builtinNumber();
160}
161
162JSObject *Interpreter::builtinDate() const
163{
164 return rep->builtinDate();
165}
166
167JSObject *Interpreter::builtinRegExp() const
168{
169 return rep->builtinRegExp();
170}
171
172JSObject *Interpreter::builtinError() const
173{
174 return rep->builtinError();
175}
176
177JSObject *Interpreter::builtinObjectPrototype() const
178{
179 return rep->builtinObjectPrototype();
180}
181
182JSObject *Interpreter::builtinFunctionPrototype() const
183{
184 return rep->builtinFunctionPrototype();
185}
186
187JSObject *Interpreter::builtinArrayPrototype() const
188{
189 return rep->builtinArrayPrototype();
190}
191
192JSObject *Interpreter::builtinBooleanPrototype() const
193{
194 return rep->builtinBooleanPrototype();
195}
196
197JSObject *Interpreter::builtinStringPrototype() const
198{
199 return rep->builtinStringPrototype();
200}
201
202JSObject *Interpreter::builtinNumberPrototype() const
203{
204 return rep->builtinNumberPrototype();
205}
206
207JSObject *Interpreter::builtinDatePrototype() const
208{
209 return rep->builtinDatePrototype();
210}
211
212JSObject *Interpreter::builtinRegExpPrototype() const
213{
214 return rep->builtinRegExpPrototype();
215}
216
217JSObject *Interpreter::builtinErrorPrototype() const
218{
219 return rep->builtinErrorPrototype();
220}
221
222JSObject *Interpreter::builtinEvalError() const
223{
224 return rep->builtinEvalError();
225}
226
227JSObject *Interpreter::builtinRangeError() const
228{
229 return rep->builtinRangeError();
230}
231
232JSObject *Interpreter::builtinReferenceError() const
233{
234 return rep->builtinReferenceError();
235}
236
237JSObject *Interpreter::builtinSyntaxError() const
238{
239 return rep->builtinSyntaxError();
240}
241
242JSObject *Interpreter::builtinTypeError() const
243{
244 return rep->builtinTypeError();
245}
246
247JSObject *Interpreter::builtinURIError() const
248{
249 return rep->builtinURIError();
250}
251
252JSObject *Interpreter::builtinEvalErrorPrototype() const
253{
254 return rep->builtinEvalErrorPrototype();
255}
256
257JSObject *Interpreter::builtinRangeErrorPrototype() const
258{
259 return rep->builtinRangeErrorPrototype();
260}
261
262JSObject *Interpreter::builtinReferenceErrorPrototype() const
263{
264 return rep->builtinReferenceErrorPrototype();
265}
266
267JSObject *Interpreter::builtinSyntaxErrorPrototype() const
268{
269 return rep->builtinSyntaxErrorPrototype();
270}
271
272JSObject *Interpreter::builtinTypeErrorPrototype() const
273{
274 return rep->builtinTypeErrorPrototype();
275}
276
277JSObject *Interpreter::builtinURIErrorPrototype() const
278{
279 return rep->builtinURIErrorPrototype();
280}
281
282void Interpreter::setCompatMode(CompatMode mode)
283{
284 rep->setCompatMode(mode);
285}
286
287Interpreter::CompatMode Interpreter::compatMode() const
288{
289 return rep->compatMode();
290}
291
292#ifdef KJS_DEBUG_MEM
293#include "lexer.h"
294void Interpreter::finalCheck()
295{
296 fprintf(stderr,"Interpreter::finalCheck()\n");
297 Collector::collect();
298
299 Node::finalCheck();
300 Collector::finalCheck();
301 Lexer::globalClear();
302 UString::globalClear();
303}
304#endif
305
306#if APPLE_CHANGES
307static bool printExceptions = false;
308
309bool Interpreter::shouldPrintExceptions()
310{
311 return printExceptions;
312}
313
314void Interpreter::setShouldPrintExceptions(bool print)
315{
316 printExceptions = print;
317}
318
319
320void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, JSObject *value, const Bindings::RootObject *origin, const Bindings::RootObject *current)
321{
322 return Bindings::Instance::createLanguageInstanceForValue (exec, (Bindings::Instance::BindingLanguage)language, value, origin, current);
323}
324
325#endif
326
327void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
328{
329 rep->saveBuiltins(builtins);
330}
331
332void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
333{
334 rep->restoreBuiltins(builtins);
335}
336
337SavedBuiltins::SavedBuiltins() :
338 _internal(0)
339{
340}
341
342SavedBuiltins::~SavedBuiltins()
343{
344 delete _internal;
345}
346
347
348void Interpreter::virtual_hook( int, void* )
349{ /*BASE::virtual_hook( id, data );*/ }
350
351
352Interpreter *ExecState::lexicalInterpreter() const
353{
354 if (!_context) {
355 return dynamicInterpreter();
356 }
357
358 InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
359
360 if (!result) {
361 return dynamicInterpreter();
362 }
363
364 return result->interpreter();
365}
Note: See TracBrowser for help on using the repository browser.