source: webkit/trunk/JavaScriptCore/kjs/interpreter.h@ 1371

Last change on this file since 1371 was 1024, checked in by darin, 23 years ago

Merged KDE 3.0 final code in and:

JavaScriptCore:

  • kjs/internal.cpp:
  • kjs/property_map.cpp:
  • kjs/ustring.h: Removed some unneeded <config.h> includes so we are more similar to the real KDE sources.

Merged changes from KDE 3.0 final and did some build fixes.

  • kjs/grammar.*: Regenerated.
  • kjs/*.lut.h: Regenerated.

WebCore:

  • src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration): Remove some minor gratuitous diffs vs. KDE.
  • src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration): Richard updated to reflect changes in KDE.
  • src/kdelibs/khtml/css/css_valueimpl.cpp: (FontFamilyValueImpl::FontFamilyValueImpl): Fix comment.
  • src/kdelibs/khtml/css/cssstyleselector.cpp: Remove some gratuitous diffs vs. KDE.
  • src/kdelibs/khtml/html/html_objectimpl.cpp: (HTMLEmbedElementImpl::parseAttribute): Remove unneeded copy from KWQ's early days.
  • src/kdelibs/khtml/html/html_tableimpl.cpp: (HTMLTableElementImpl::parseAttribute), (HTMLTablePartElementImpl::parseAttribute): Remove unneeded copy from KWQ's early days.
  • src/kdelibs/khtml/html/htmltokenizer.cpp: (HTMLTokenizer::processToken): Redo the APPLE_CHANGES ifdef here.
  • src/kdelibs/khtml/khtmlpart_p.h: Update to latest kde.
  • src/kdelibs/khtml/khtmlview.cpp: (KHTMLView::KHTMLView): Add ifdef APPLE_CHANGES. (KHTMLView::~KHTMLView): Add ifdef APPLE_CHANGES. (KHTMLView::print): Remove code left in here during merge process.
  • src/kwq/KWQKHTMLPart.mm: Remove unused setFontSizes(), fontSizes(), and resetFontSizes(). After the merge is landed, remove more.
  • src/libwebcore.exp: Export updateStyleSelector() for WebKit.

Fix text to it displays at the right font size.

  • src/kdelibs/khtml/css/cssstyleselector.cpp: (CSSStyleSelector::computeFontSizes): Apply the same SCREEN_RESOLUTION hack here that we do elsewhere.
  • src/kdelibs/khtml/rendering/font.cpp: (Font::width): Use kMin instead of max (oops). (Font::update): Turn off font database chicanery.
  • src/kwq/KWQKHTMLPart.mm: (KHTMLPart::zoomFactor): Use zoom factor 100, not 1.

More fixes so text displays (still at wrong font size).

  • src/kdelibs/khtml/rendering/font.cpp: (max): New helper. (Font::drawText): Simplified implementation for now. (Font::width): Simplified implementation for now.
  • src/kwq/KWQColorGroup.mm: Reinstated QCOLOR_GROUP_SIZE.
  • src/kwq/qt/qfontmetrics.h: Removed charWidth and changed _width to take QChar *.
  • src/kwq/KWQFontMetrics.mm: Removed charWidth and changed _width to take QChar *.

Merged changes from KDE 3.0 final. Other fixes to get things compiling.

  • src/kdelibs/khtml/css/css_valueimpl.cpp: (CSSStyleDeclarationImpl::setProperty): Fix unused variable.
  • src/kdelibs/khtml/khtmlview.cpp: (KHTMLView::contentsContextMenuEvent): Fix unused variable.
  • src/kdelibs/khtml/rendering/font.cpp: (Font::drawText), (Font::width), (Font::update): Disable special "nsbp" logic for now. We can reenable it if necessary.
  • src/kdelibs/khtml/rendering/render_replaced.cpp: Fix mismerge.
  • src/kdelibs/khtml/rendering/render_text.cpp: (RenderText::nodeAtPoint): Fix unused variable.
  • src/kwq/KWQApplication.mm: (QDesktopWidget::width), (QApplication::desktop): Fix mismerge.
  • src/kwq/KWQColorGroup.mm: Fix QCOLOR_GROUP_SIZE.
  • src/kwq/KWQFontMetrics.mm: (QFontMetrics::lineSpacing): New. (QFontMetrics::width): Remove unused optimization.
  • src/kwq/qt/qfontmetrics.h: Add lineSpacing().

Merged changes from previous merge pass.

2002-03-25 Darin Adler <Darin Adler>

Last bit of making stuff compile and link. Probably will drop the merge now
and take it up again when it's time to merge in KDE 3.0 final.

  • src/kwq/KWQEvent.mm: (QFocusEvent::reason): New.
  • src/kwq/KWQPainter.mm: (QPainter::drawText): New overload.

2002-03-25 Darin Adler <Darin Adler>

  • src/kdelibs/khtml/rendering/font.cpp: (Font::width): Make it call _width so we don't lose the optimization.
  • src/kwq/KWQApplication.mm: (QDesktopWidget::screenNumber): New. (QDesktopWidget::screenGeometry): New. (QApplication::style): New.
  • src/kwq/KWQColorGroup.mm: (QColorGroup::highlight): New. (QColorGroup::highlightedText): New.
  • src/kwq/KWQFont.mm: (QFont::setPixelSize): New.
  • src/kwq/KWQFontMetrics.mm: (QFontMetrics::charWidth): New.
  • src/kwq/KWQKGlobal.mm: (KGlobal::locale): Implement. (KLocale::KLocale): New. (KLocale::languageList): New.
  • src/kwq/KWQKHTMLPart.mm: (KHTMLPart::sheetUsed): New. (KHTMLPart::setSheetUsed): New. (KHTMLPart::zoomFactor): New.
  • src/kwq/KWQKHTMLSettings.mm: (KHTMLSettings::mediumFontSize): New.
  • src/kwq/KWQScrollView.mm: (QScrollView::childX): New. (QScrollView::childY): New.
  • src/kwq/qt/qapplication.h: style() returns a QStyle &.
  • src/kwq/qt/qpalette.h: Add Highlight and HighlightedText.

2002-03-24 Darin Adler <Darin Adler>

More compiling. Still won't link.

  • src/kdelibs/khtml/khtmlview.cpp: Disable printing and drag and drop code.
  • src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration): Temporarily turn off our smarter underlining since it relies on access to the string, and TextSlave doesn't have that any more. (RenderText::nodeAtPoint): Get rid of a workaround we don't need any more for a bug that was fixed by KDE folks.
  • src/kwq/KWQApplication.mm: (QApplication::desktop): Make the desktop be a QDesktopWidget.
  • src/kwq/qt/qnamespace.h: Add MetaButton.
  • src/kwq/qt/qtooltip.h: Add a maybeTip virtual function member and a virtual destructor.

2002-03-24 Darin Adler <Darin Adler>

Some fixes to get more stuff to compile.

  • src/kdelibs/khtml/ecma/kjs_dom.cpp: (DOMDocument::getValueProperty): Don't try to look at the private m_bComplete to display "complete". Just do "loading" and "loaded".
  • src/kdelibs/khtml/khtmlpart_p.h: #ifdef this all out for APPLE_CHANGES.
  • src/kdelibs/khtml/rendering/font.cpp: (Font::update): Add an explicit cast to int to avoid float -> int warning.
  • src/kdelibs/khtml/rendering/render_table.cpp: (RenderTable::calcColMinMax): Add an explicit cast to int to avoid uint compared with int warning.
  • src/kdelibs/khtml/xml/dom_docimpl.cpp: (DocumentImpl::recalcStyleSelector): Use sheetUsed() and setSheetUsed() functions on KHTMLPart intead of getting at private fields the way the real KDE code does.
  • src/kwq/KWQKHTMLPart.h: Declare zoomFactor(), sheetUsed(), and setSheetUsed().
  • src/kwq/KWQStyle.h: Add PM_DefaultFramWidth as another metric.
  • src/kwq/kdecore/klocale.h: Add languageList().
  • src/kwq/khtml/khtml_settings.h: Add mediumFontSize().
  • src/kwq/qt/qapplication.h: Add style() and QDesktopWidget.
  • src/kwq/qt/qevent.h: Add reason().
  • src/kwq/qt/qfont.h: Add setPixelSize(int).
  • src/kwq/qt/qfontmetrics.h: Add charWidth() and _charWidth() functions.
  • src/kwq/qt/qpainter.h: Add drawText() overload with position parameter.
  • src/kwq/qt/qpalette.h: Add highlight() and highlightedText().
  • src/kwq/qt/qscrollview.h: Add childX() and childY().
  • src/kwq/KWQApplication.mm: Change KWQDesktopWidget to QDesktopWidget.

WebKit:

  • WebView.subproj/IFPreferences.h:
  • WebView.subproj/IFPreferences.mm: (+[IFPreferences load]): Remove the old WebKitFontSizes preference. (-[IFPreferences mediumFontSize]), (-[IFPreferences setMediumFontSize:]): New.
  • WebView.subproj/IFWebView.mm: (-[IFWebView reapplyStyles]): Call updateStyleSelector() instead of recalcStyle().

Merged changes from previous merge branch.

2002-03-25 Darin Adler <Darin Adler>

  • WebView.subproj/IFPreferences.mm: (+[IFPreferences load]): Add WebKitMediumFontSizePreferenceKey.

WebBrowser:

  • Preferences.subproj/TextPreferences.m: (-[TextPreferences defaultFontSize]), (-[TextPreferences setDefaultFontSize:]): Just get and set the new mediumFontSize preference rather than doing the whole fontSizes preference dance.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 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 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 */
23
24#ifndef _KJS_INTERPRETER_H_
25#define _KJS_INTERPRETER_H_
26
27#include "value.h"
28#include "object.h"
29#include "types.h"
30
31namespace KJS {
32
33 class ContextImp;
34 class ExecStateImp;
35 class InterpreterImp;
36
37 /**
38 * Represents an execution context, as specified by section 10 of the ECMA
39 * spec.
40 *
41 * An execution context contains information about the current state of the
42 * script - the scope for variable lookup, the value of "this", etc. A new
43 * execution context is entered whenever global code is executed (e.g. with
44 * @ref Interpreter::evaluate()), a function is called (see @ref
45 * Object::call()), or the builtin "eval" function is executed.
46 *
47 * Most inheritable functions in the KJS api take a @ref ExecState pointer as
48 * their first parameter. This can be used to obtain a handle to the current
49 * execution context.
50 *
51 * Note: Context objects are wrapper classes/smart pointers for the internal
52 * KJS ContextImp type. When one context variable is assigned to another, it
53 * is still referencing the same internal object.
54 */
55 class Context {
56 public:
57 Context(ContextImp *);
58 Context(const Context &c);
59 Context& operator=(const Context &c);
60 virtual ~Context();
61
62 bool isNull() const;
63 ContextImp *imp() const;
64
65 /**
66 * Returns the scope chain for this execution context. This is used for
67 * variable lookup, with the list being searched from start to end until a
68 * variable is found.
69 *
70 * @return The execution context's scope chain
71 */
72 const List scopeChain() const;
73
74 /**
75 * Returns the variable object for the execution context. This contains a
76 * property for each variable declared in the execution context.
77 *
78 * @return The execution context's variable object
79 */
80 Object variableObject() const;
81
82 /**
83 * Returns the "this" value for the execution context. This is the value
84 * returned when a script references the special variable "this". It should
85 * always be an Object, unless application-specific code has passed in a
86 * different type.
87 *
88 * The object that is used as the "this" value depends on the type of
89 * execution context - for global contexts, the global object is used. For
90 * function objewcts, the value is given by the caller (e.g. in the case of
91 * obj.func(), obj would be the "this" value). For code executed by the
92 * built-in "eval" function, the this value is the same as the calling
93 * context.
94 *
95 * @return The execution context's "this" value
96 */
97 Object thisValue() const;
98
99 /**
100 * Returns the context from which the current context was invoked. For
101 * global code this will be a null context (i.e. one for which @ref
102 * isNull() returns true). You should check @ref isNull() on the returned
103 * value before calling any of it's methods.
104 *
105 * @return The calling execution context
106 */
107 const Context callingContext() const;
108 private:
109 ContextImp *rep;
110 };
111
112 /**
113 * Interpreter objects can be used to evaluate ECMAScript code. Each
114 * interpreter has a global object which is used for the purposes of code
115 * evaluation, and also provides access to built-in properties such as
116 * " Object" and "Number".
117 */
118 class Interpreter {
119 public:
120 /**
121 * Creates a new interpreter. The supplied object will be used as the global
122 * object for all scripts executed with this interpreter. During
123 * constuction, all the standard properties such as "Object" and "Number"
124 * will be added to the global object.
125 *
126 * Note: You should not use the same global object for multiple
127 * interpreters.
128 *
129 * This is due do the fact that the built-in properties are set in the
130 * constructor, and if these objects have been modified from another
131 * interpreter (e.g. a script modifying String.prototype), the changes will
132 * be overridden.
133 *
134 * @param global The object to use as the global object for this interpreter
135 */
136 Interpreter(const Object &global);
137 /**
138 * Creates a new interpreter. A global object will be created and
139 * initialized with the standard global properties.
140 */
141 Interpreter();
142 virtual ~Interpreter();
143
144 /**
145 * Returns the object that is used as the global object during all script
146 * execution performed by this interpreter
147 */
148 Object globalObject() const;
149
150 void initGlobalObject();
151
152 /**
153 * Returns the execution state object which can be used to execute
154 * scripts using this interpreter at a the "global" level, i.e. one
155 * with a execution context that has the global object as the "this"
156 * value, and who's scope chain contains only the global object.
157 *
158 * Note: this pointer remains constant for the life of the interpreter
159 * and should not be manually deleted.
160 *
161 * @return The interpreter global execution state object
162 */
163 ExecState *globalExec();
164
165 /**
166 * Parses the supplied ECMAScript code and checks for syntax errors.
167 *
168 * @param code The code to check
169 * @return true if there were no syntax errors in the code, otherwise false
170 */
171 bool checkSyntax(const UString &code);
172
173 /**
174 * Evaluates the supplied ECMAScript code.
175 *
176 * Since this method returns a Completion, you should check the type of
177 * completion to detect an error or before attempting to access the returned
178 * value. For example, if an error occurs during script execution and is not
179 * caught by the script, the completion type will be Throw.
180 *
181 * If the supplied code is invalid, a SyntaxError will be thrown.
182 *
183 * @param code The code to evaluate
184 * @param thisV The value to pass in as the "this" value for the script
185 * execution. This should either be Null() or an Object.
186 * @return A completion object representing the result of the execution.
187 */
188 Completion evaluate(const UString &code, const Value &thisV = Value());
189
190 /**
191 * @internal
192 *
193 * Returns the implementation object associated with this interpreter.
194 * Only useful for internal KJS operations.
195 */
196 InterpreterImp *imp();
197
198 /**
199 * Returns the builtin "Object" object. This is the object that was set
200 * as a property of the global object during construction; if the property
201 * is replaced by script code, this method will still return the original
202 * object.
203 *
204 * @return The builtin "Object" object
205 */
206 Object builtinObject() const;
207
208 /**
209 * Returns the builtin "Function" object.
210 */
211 Object builtinFunction() const;
212
213 /**
214 * Returns the builtin "Array" object.
215 */
216 Object builtinArray() const;
217
218
219 /**
220 * Returns the builtin "Boolean" object.
221 */
222 Object builtinBoolean() const;
223
224 /**
225 * Returns the builtin "String" object.
226 */
227 Object builtinString() const;
228
229 /**
230 * Returns the builtin "Number" object.
231 */
232 Object builtinNumber() const;
233
234 /**
235 * Returns the builtin "Date" object.
236 */
237 Object builtinDate() const;
238
239 /**
240 * Returns the builtin "RegExp" object.
241 */
242 Object builtinRegExp() const;
243
244 /**
245 * Returns the builtin "Error" object.
246 */
247 Object builtinError() const;
248
249 /**
250 * Returns the builtin "Object.prototype" object.
251 */
252 Object builtinObjectPrototype() const;
253
254 /**
255 * Returns the builtin "Function.prototype" object.
256 */
257 Object builtinFunctionPrototype() const;
258
259 /**
260 * Returns the builtin "Array.prototype" object.
261 */
262 Object builtinArrayPrototype() const;
263
264 /**
265 * Returns the builtin "Boolean.prototype" object.
266 */
267 Object builtinBooleanPrototype() const;
268
269 /**
270 * Returns the builtin "String.prototype" object.
271 */
272 Object builtinStringPrototype() const;
273
274 /**
275 * Returns the builtin "Number.prototype" object.
276 */
277 Object builtinNumberPrototype() const;
278
279 /**
280 * Returns the builtin "Date.prototype" object.
281 */
282 Object builtinDatePrototype() const;
283
284 /**
285 * Returns the builtin "RegExp.prototype" object.
286 */
287 Object builtinRegExpPrototype() const;
288
289 /**
290 * Returns the builtin "Error.prototype" object.
291 */
292 Object builtinErrorPrototype() const;
293
294 /**
295 * The initial value of "Error" global property
296 */
297 Object builtinEvalError() const;
298 Object builtinRangeError() const;
299 Object builtinReferenceError() const;
300 Object builtinSyntaxError() const;
301 Object builtinTypeError() const;
302 Object builtinURIError() const;
303
304 Object builtinEvalErrorPrototype() const;
305 Object builtinRangeErrorPrototype() const;
306 Object builtinReferenceErrorPrototype() const;
307 Object builtinSyntaxErrorPrototype() const;
308 Object builtinTypeErrorPrototype() const;
309 Object builtinURIErrorPrototype() const;
310
311 enum CompatMode { NativeMode, IECompat, NetscapeCompat };
312 /**
313 * Call this to enable a compatibility mode with another browser.
314 * (by default konqueror is in "native mode").
315 * Currently, in KJS, this only changes the behaviour of Date::getYear()
316 * which returns the full year under IE.
317 */
318 void setCompatMode(CompatMode mode);
319 CompatMode compatMode() const;
320
321 /**
322 * Called by InterpreterImp during the mark phase of the garbage collector
323 * Default implementation does nothing, this exist for classes that reimplement Interpreter.
324 */
325 virtual void mark() {}
326
327 /**
328 * Provides a way to distinguish derived classes.
329 * Only useful if you reimplement Interpreter and if different kind of
330 * interpreters are created in the same process.
331 * The base class returns 0, the ECMA-bindings interpreter returns 1.
332 */
333 virtual int rtti() { return 0; }
334
335#ifdef KJS_DEBUG_MEM
336 /**
337 * @internal
338 */
339 static void finalCheck();
340#endif
341 private:
342 InterpreterImp *rep;
343
344 /**
345 * This constructor is not implemented, in order to prevent
346 * copy-construction of Interpreter objects. You should always pass around
347 * pointers to an interpreter instance instead.
348 */
349 Interpreter(const Interpreter&);
350
351 /**
352 * This constructor is not implemented, in order to prevent assignment of
353 * Interpreter objects. You should always pass around pointers to an
354 * interpreter instance instead.
355 */
356 Interpreter operator=(const Interpreter&);
357 protected:
358 virtual void virtual_hook( int id, void* data );
359 };
360
361 /**
362 * Represents the current state of script execution. This object allows you
363 * obtain a handle the interpreter that is currently executing the script,
364 * and also the current execution state context.
365 */
366 class ExecState {
367 friend class InterpreterImp;
368 friend class FunctionImp;
369 friend class GlobalFuncImp;
370 public:
371 virtual ~ExecState();
372
373 /**
374 * Returns the interpreter associated with this execution state
375 *
376 * @return The interpreter executing the script
377 */
378 Interpreter *interpreter() const;
379
380 /**
381 * Returns the execution context associated with this execution state
382 *
383 * @return The current execution state context
384 */
385 const Context context() const;
386
387 void setException(const Value &e);
388 void clearException();
389 Value exception() const;
390 bool hadException() const;
391
392 private:
393 ExecState(Interpreter *interp, ContextImp *con);
394 ExecStateImp *rep;
395 };
396
397}; // namespace
398
399#endif // _KJS_INTERPRETER_H_
Note: See TracBrowser for help on using the repository browser.