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

Last change on this file since 6768 was 6768, checked in by kdecker, 21 years ago

JavaScriptCore:

Reviewed by Dave.

  • ObjC bindings do not (yet) pass along sourceurl or line numbers
  • we don't have a way as of yet to accomidate line numbers and urls for dynamic javascript
  • changed the wording of an error message
  • the lexer, parser, and interpreter have been made "sourceURL aware"
  • stored the url into Error
  • bindings/NP_jsobject.cpp: (NPN_Evaluate):
  • bindings/jni/jni_jsobject.cpp: (JSObject::eval):
  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject evaluateWebScript:]):
  • kjs/function.cpp: (GlobalFuncImp::call):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/internal.cpp: (Parser::parse): (InterpreterImp::checkSyntax): (InterpreterImp::evaluate):
  • kjs/internal.h:
  • kjs/interpreter.cpp: (Interpreter::evaluate):
  • kjs/interpreter.h:
  • kjs/lexer.cpp: (Lexer::setCode):
  • kjs/lexer.h: (KJS::Lexer::sourceURL):
  • kjs/nodes.cpp: (Node::Node): (Node::throwError): (FunctionCallNode::evaluate):
  • kjs/nodes.h:
  • kjs/object.cpp: (KJS::Error::create):
  • kjs/object.h:

WebCore:

Reviewed by Dave.

  • kwq/KWQKHTMLPart.mm: addMessagetoConsole places sourceURL in the dictionary
  • khtml/xml/dom_docimpl.cpp: right now, we don't have a way to get a url, so we leave this blank
  • khtml/ecma/kjs_window.cpp: still need to get the real line number and sourceURL
  • khtml/ecma/kjs_proxy.cpp: now passing the sourceURL to addMessageToConsole
  • khtml/ecma/kjs_events.cpp: still need to grab an accurate line number and sourceURL
  • khtml/ecma/kjs_events.cpp: (JSEventListener::handleEvent): (JSLazyEventListener::handleEvent):
  • khtml/ecma/kjs_proxy.cpp: (KJSProxyImpl::evaluate):
  • khtml/ecma/kjs_window.cpp: (Window::isSafeScript): (ScheduledAction::execute):
  • khtml/xml/dom_docimpl.cpp: (DocumentImpl::open):
  • kwq/KWQKHTMLPart.h:
  • kwq/KWQKHTMLPart.mm: (KWQKHTMLPart::addMessageToConsole):

WebBrowser:

Reviewed by Dave.

  • model is now source url aware
  • refined the ui with custom NSCells that now display error messages, line numbers, and source urls
  • increased the row size to 35 pixels to accomimdate for ErrorCells
  • Debug/ErrorCell.h: Added.
  • Debug/ErrorCell.m: Added. (-[ErrorCell setURL:]): (-[ErrorCell setErrorMessasge:]): (-[ErrorCell setLineNumber:]): (-[ErrorCell drawInteriorWithFrame:inView:]):
  • Debug/ErrorConsole.nib:
  • Debug/ErrorConsoleController.m: (-[ErrorConsoleController init]): (-[ErrorConsoleController awakeFromNib]):
  • Debug/ErrorConsoleModel.h:
  • Debug/ErrorConsoleModel.m: (-[ErrorConsoleModel tableView:willDisplayCell:forTableColumn:row:]): (-[ErrorConsoleModel count]): (-[ErrorConsoleModel selectedURL]):
  • WebBrowser.pbproj/project.pbxproj:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *
23 */
24
25#include "value.h"
26#include "object.h"
27#include "types.h"
28#include "interpreter.h"
29
30#include <assert.h>
31#include <math.h>
32#include <stdio.h>
33
34#include "internal.h"
35#include "collector.h"
36#include "operations.h"
37#include "error_object.h"
38#include "nodes.h"
39#include "context.h"
40
41using namespace KJS;
42
43// ------------------------------ Context --------------------------------------
44
45const ScopeChain &Context::scopeChain() const
46{
47 return rep->scopeChain();
48}
49
50Object Context::variableObject() const
51{
52 return rep->variableObject();
53}
54
55Object Context::thisValue() const
56{
57 return rep->thisValue();
58}
59
60const Context Context::callingContext() const
61{
62 return rep->callingContext();
63}
64
65// ------------------------------ Interpreter ----------------------------------
66
67Interpreter::Interpreter(const Object &global) : rep(0)
68{
69 rep = new InterpreterImp(this,global);
70}
71
72Interpreter::Interpreter()
73{
74 Object global(new ObjectImp());
75 rep = new InterpreterImp(this,global);
76}
77
78Interpreter::~Interpreter()
79{
80 delete rep;
81}
82
83Object &Interpreter::globalObject() const
84{
85 return rep->globalObject();
86}
87
88void Interpreter::initGlobalObject()
89{
90 rep->initGlobalObject();
91}
92
93void Interpreter::lock()
94{
95 InterpreterImp::lock();
96}
97
98void Interpreter::unlock()
99{
100 InterpreterImp::unlock();
101}
102
103int Interpreter::lockCount()
104{
105 return InterpreterImp::lockCount();
106}
107
108ExecState *Interpreter::globalExec()
109{
110 return rep->globalExec();
111}
112
113bool Interpreter::checkSyntax(const UString &code)
114{
115 return rep->checkSyntax(code);
116}
117
118Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, const Value &thisV)
119{
120 Completion comp = rep->evaluate(code,thisV, sourceURL, startingLineNumber);
121
122#if APPLE_CHANGES
123 if (shouldPrintExceptions() && comp.complType() == Throw) {
124 lock();
125 ExecState *exec = rep->globalExec();
126 char *f = strdup(sourceURL.ascii());
127 const char *message = comp.value().toObject(exec).toString(exec).ascii();
128 printf("%s:%s\n", f, message);
129 free(f);
130 unlock();
131 }
132#endif
133
134 return comp;
135}
136
137InterpreterImp *Interpreter::imp()
138{
139 return rep;
140}
141
142Object Interpreter::builtinObject() const
143{
144 return rep->builtinObject();
145}
146
147Object Interpreter::builtinFunction() const
148{
149 return rep->builtinFunction();
150}
151
152Object Interpreter::builtinArray() const
153{
154 return rep->builtinArray();
155}
156
157Object Interpreter::builtinBoolean() const
158{
159 return rep->builtinBoolean();
160}
161
162Object Interpreter::builtinString() const
163{
164 return rep->builtinString();
165}
166
167Object Interpreter::builtinNumber() const
168{
169 return rep->builtinNumber();
170}
171
172Object Interpreter::builtinDate() const
173{
174 return rep->builtinDate();
175}
176
177Object Interpreter::builtinRegExp() const
178{
179 return rep->builtinRegExp();
180}
181
182Object Interpreter::builtinError() const
183{
184 return rep->builtinError();
185}
186
187Object Interpreter::builtinObjectPrototype() const
188{
189 return rep->builtinObjectPrototype();
190}
191
192Object Interpreter::builtinFunctionPrototype() const
193{
194 return rep->builtinFunctionPrototype();
195}
196
197Object Interpreter::builtinArrayPrototype() const
198{
199 return rep->builtinArrayPrototype();
200}
201
202Object Interpreter::builtinBooleanPrototype() const
203{
204 return rep->builtinBooleanPrototype();
205}
206
207Object Interpreter::builtinStringPrototype() const
208{
209 return rep->builtinStringPrototype();
210}
211
212Object Interpreter::builtinNumberPrototype() const
213{
214 return rep->builtinNumberPrototype();
215}
216
217Object Interpreter::builtinDatePrototype() const
218{
219 return rep->builtinDatePrototype();
220}
221
222Object Interpreter::builtinRegExpPrototype() const
223{
224 return rep->builtinRegExpPrototype();
225}
226
227Object Interpreter::builtinErrorPrototype() const
228{
229 return rep->builtinErrorPrototype();
230}
231
232Object Interpreter::builtinEvalError() const
233{
234 return rep->builtinEvalError();
235}
236
237Object Interpreter::builtinRangeError() const
238{
239 return rep->builtinRangeError();
240}
241
242Object Interpreter::builtinReferenceError() const
243{
244 return rep->builtinReferenceError();
245}
246
247Object Interpreter::builtinSyntaxError() const
248{
249 return rep->builtinSyntaxError();
250}
251
252Object Interpreter::builtinTypeError() const
253{
254 return rep->builtinTypeError();
255}
256
257Object Interpreter::builtinURIError() const
258{
259 return rep->builtinURIError();
260}
261
262Object Interpreter::builtinEvalErrorPrototype() const
263{
264 return rep->builtinEvalErrorPrototype();
265}
266
267Object Interpreter::builtinRangeErrorPrototype() const
268{
269 return rep->builtinRangeErrorPrototype();
270}
271
272Object Interpreter::builtinReferenceErrorPrototype() const
273{
274 return rep->builtinReferenceErrorPrototype();
275}
276
277Object Interpreter::builtinSyntaxErrorPrototype() const
278{
279 return rep->builtinSyntaxErrorPrototype();
280}
281
282Object Interpreter::builtinTypeErrorPrototype() const
283{
284 return rep->builtinTypeErrorPrototype();
285}
286
287Object Interpreter::builtinURIErrorPrototype() const
288{
289 return rep->builtinURIErrorPrototype();
290}
291
292void Interpreter::setCompatMode(CompatMode mode)
293{
294 rep->setCompatMode(mode);
295}
296
297Interpreter::CompatMode Interpreter::compatMode() const
298{
299 return rep->compatMode();
300}
301
302#ifdef KJS_DEBUG_MEM
303#include "lexer.h"
304void Interpreter::finalCheck()
305{
306 fprintf(stderr,"Interpreter::finalCheck()\n");
307 // Garbage collect - as many times as necessary
308 // (we could delete an object which was holding another object, so
309 // the deref() will happen too late for deleting the impl of the 2nd object).
310 while( Collector::collect() )
311 ;
312
313 Node::finalCheck();
314 Collector::finalCheck();
315 Lexer::globalClear();
316 UString::globalClear();
317}
318#endif
319
320#if APPLE_CHANGES
321static bool printExceptions = false;
322
323bool Interpreter::shouldPrintExceptions()
324{
325 return printExceptions;
326}
327
328void Interpreter::setShouldPrintExceptions(bool print)
329{
330 printExceptions = print;
331}
332#endif
333
334void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
335{
336 rep->saveBuiltins(builtins);
337}
338
339void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
340{
341 rep->restoreBuiltins(builtins);
342}
343
344SavedBuiltins::SavedBuiltins() :
345 _internal(0)
346{
347}
348
349SavedBuiltins::~SavedBuiltins()
350{
351 delete _internal;
352}
353
354
355void Interpreter::virtual_hook( int, void* )
356{ /*BASE::virtual_hook( id, data );*/ }
357
358
359Interpreter *ExecState::lexicalInterpreter() const
360{
361 if (!_context) {
362 return dynamicInterpreter();
363 }
364
365 InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());
366
367 if (!result) {
368 return dynamicInterpreter();
369 }
370
371 return result->interpreter();
372}
Note: See TracBrowser for help on using the repository browser.