source: webkit/trunk/JavaScriptCore/kjs/internal.h@ 10701

Last change on this file since 10701 was 10634, checked in by mjs, 20 years ago

JavaScriptCore:

Reviewed by John.

I also moved SharedPtr and the assertion code from WebCore into a
new kxmlcore directory.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/collector.cpp: (KJS::Collector::allocate): (KJS::Collector::collect):
  • kjs/config.h:
  • kjs/fast_malloc.cpp: Removed.
  • kjs/fast_malloc.h: Removed.
  • kjs/function.cpp:
  • kjs/function.h:
  • kjs/function_object.cpp:
  • kjs/identifier.cpp: (KJS::Identifier::add):
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/nodes.h:
  • kjs/nodes2string.cpp:
  • kjs/property_map.cpp: (KJS::PropertyMap::~PropertyMap): (KJS::PropertyMap::rehash):
  • kjs/scope_chain.h:
  • kjs/shared_ptr.h: Removed.
  • kjs/string_object.cpp: (StringObjectFuncImp::callAsFunction):
  • kjs/ustring.cpp: (KJS::UString::Rep::createCopying): (KJS::UString::Rep::destroy): (KJS::UString::expandCapacity): (KJS::UString::expandPreCapacity): (KJS::UString::UString): (KJS::UString::spliceSubstringsWithSeparators): (KJS::UString::append): (KJS::UString::operator=): (KJS::UString::detach):
  • kjs/ustring.h:
  • kxmlcore/Assertions.h: Added.
  • kxmlcore/Assertions.mm: Added.
  • kxmlcore/FastMalloc.cpp: Added. (KXMLCore::LgFloor): (KXMLCore::SizeClass): (KXMLCore::ByteSizeForClass): (KXMLCore::InitSizeClasses): (KXMLCore::MetaDataAlloc): (KXMLCore::PageHeapAllocator::Init): (KXMLCore::PageHeapAllocator::New): (KXMLCore::PageHeapAllocator::Delete): (KXMLCore::PageHeapAllocator::inuse): (KXMLCore::pages): (KXMLCore::AllocationSize): (KXMLCore::Event): (KXMLCore::NewSpan): (KXMLCore::DeleteSpan): (KXMLCore::DLL_Init): (KXMLCore::DLL_Remove): (KXMLCore::DLL_IsEmpty): (KXMLCore::DLL_Length): (KXMLCore::DLL_Print): (KXMLCore::DLL_Prepend): (KXMLCore::DLL_InsertOrdered): (KXMLCore::): (KXMLCore::TCMalloc_PageHeap::GetDescriptor): (KXMLCore::TCMalloc_PageHeap::SystemBytes): (KXMLCore::TCMalloc_PageHeap::FreeBytes): (KXMLCore::TCMalloc_PageHeap::RecordSpan): (KXMLCore::TCMalloc_PageHeap::TCMalloc_PageHeap): (KXMLCore::TCMalloc_PageHeap::New): (KXMLCore::TCMalloc_PageHeap::Split): (KXMLCore::TCMalloc_PageHeap::Carve): (KXMLCore::TCMalloc_PageHeap::Delete): (KXMLCore::TCMalloc_PageHeap::RegisterSizeClass): (KXMLCore::TCMalloc_PageHeap::Dump): (KXMLCore::TCMalloc_PageHeap::GrowHeap): (KXMLCore::TCMalloc_PageHeap::Check): (KXMLCore::TCMalloc_PageHeap::CheckList): (KXMLCore::TCMalloc_ThreadCache_FreeList::Init): (KXMLCore::TCMalloc_ThreadCache_FreeList::length): (KXMLCore::TCMalloc_ThreadCache_FreeList::empty): (KXMLCore::TCMalloc_ThreadCache_FreeList::lowwatermark): (KXMLCore::TCMalloc_ThreadCache_FreeList::clear_lowwatermark): (KXMLCore::TCMalloc_ThreadCache_FreeList::Push): (KXMLCore::TCMalloc_ThreadCache_FreeList::Pop): (KXMLCore::TCMalloc_ThreadCache::freelist_length): (KXMLCore::TCMalloc_ThreadCache::Size): (KXMLCore::TCMalloc_Central_FreeList::length): (KXMLCore::TCMalloc_Central_FreeList::Init): (KXMLCore::TCMalloc_Central_FreeList::Insert): (KXMLCore::TCMalloc_Central_FreeList::Remove): (KXMLCore::TCMalloc_Central_FreeList::Populate): (KXMLCore::TCMalloc_ThreadCache::SampleAllocation): (KXMLCore::TCMalloc_ThreadCache::Init): (KXMLCore::TCMalloc_ThreadCache::Cleanup): (KXMLCore::TCMalloc_ThreadCache::Allocate): (KXMLCore::TCMalloc_ThreadCache::Deallocate): (KXMLCore::TCMalloc_ThreadCache::FetchFromCentralCache): (KXMLCore::TCMalloc_ThreadCache::ReleaseToCentralCache): (KXMLCore::TCMalloc_ThreadCache::Scavenge): (KXMLCore::TCMalloc_ThreadCache::GetCache): (KXMLCore::TCMalloc_ThreadCache::GetCacheIfPresent): (KXMLCore::TCMalloc_ThreadCache::PickNextSample): (KXMLCore::TCMalloc_ThreadCache::InitModule): (KXMLCore::TCMalloc_ThreadCache::InitTSD): (KXMLCore::TCMalloc_ThreadCache::CreateCacheIfNecessary): (KXMLCore::TCMalloc_ThreadCache::DeleteCache): (KXMLCore::TCMalloc_ThreadCache::RecomputeThreadCacheSize): (KXMLCore::TCMalloc_ThreadCache::Print): (KXMLCore::ExtractStats): (KXMLCore::DumpStats): (KXMLCore::PrintStats): (KXMLCore::DumpStackTraces): (KXMLCore::TCMallocImplementation::GetStats): (KXMLCore::TCMallocImplementation::ReadStackTraces): (KXMLCore::TCMallocImplementation::GetNumericProperty): (KXMLCore::TCMallocImplementation::SetNumericProperty): (KXMLCore::DoSampledAllocation): (KXMLCore::do_malloc): (KXMLCore::do_free): (KXMLCore::do_memalign): (KXMLCore::TCMallocGuard::TCMallocGuard): (KXMLCore::TCMallocGuard::~TCMallocGuard): (KXMLCore::malloc): (KXMLCore::free): (KXMLCore::calloc): (KXMLCore::cfree): (KXMLCore::realloc): (KXMLCore::memalign): (KXMLCore::posix_memalign): (KXMLCore::valloc): (KXMLCore::pvalloc): (KXMLCore::malloc_stats): (KXMLCore::mallopt): (KXMLCore::mallinfo):
  • kxmlcore/FastMalloc.h: Added. (KXMLCore::FastAllocated::operator new): (KXMLCore::FastAllocated::operator delete): (KXMLCore::FastAllocated::operator new[]): (KXMLCore::FastAllocated::operator delete[]):
  • kxmlcore/SharedPtr.h: Added. (KXMLCore::SharedPtr::SharedPtr): (KXMLCore::SharedPtr::~SharedPtr): (KXMLCore::SharedPtr::isNull): (KXMLCore::SharedPtr::notNull): (KXMLCore::SharedPtr::reset): (KXMLCore::SharedPtr::get): (KXMLCore::SharedPtr::operator*): (KXMLCore::SharedPtr::operator->): (KXMLCore::SharedPtr::operator!): (KXMLCore::SharedPtr::operator bool): (KXMLCore::::operator): (KXMLCore::operator==): (KXMLCore::operator!=): (KXMLCore::static_pointer_cast): (KXMLCore::const_pointer_cast):
  • kxmlcore/TCPageMap.h: Added. (TCMalloc_PageMap1::TCMalloc_PageMap1): (TCMalloc_PageMap1::Ensure): (TCMalloc_PageMap1::get): (TCMalloc_PageMap1::set): (TCMalloc_PageMap2::TCMalloc_PageMap2): (TCMalloc_PageMap2::get): (TCMalloc_PageMap2::set): (TCMalloc_PageMap2::Ensure): (TCMalloc_PageMap3::NewNode): (TCMalloc_PageMap3::TCMalloc_PageMap3): (TCMalloc_PageMap3::get): (TCMalloc_PageMap3::set): (TCMalloc_PageMap3::Ensure):
  • kxmlcore/TCSpinLock.h: Added. (TCMalloc_SpinLock::Init): (TCMalloc_SpinLock::Finalize): (TCMalloc_SpinLock::Lock): (TCMalloc_SpinLock::Unlock): (TCMalloc_SlowLock): (TCMalloc_SpinLockHolder::TCMalloc_SpinLockHolder): (TCMalloc_SpinLockHolder::~TCMalloc_SpinLockHolder):
  • kxmlcore/TCSystemAlloc.cpp: Added. (TrySbrk): (TryMmap): (TryDevMem): (TCMalloc_SystemAlloc):
  • kxmlcore/TCSystemAlloc.h: Added.

WebCore:

Reviewed by John.

I also moved SharedPtr and the assertion code from WebCore into a
new kxmlcore directory.

  • ForwardingHeaders/kjs/shared_ptr.h: Removed.
  • ForwardingHeaders/kxmlcore/Assertions.h: Added.
  • ForwardingHeaders/kxmlcore/FastMalloc.h: Added.
  • ForwardingHeaders/kxmlcore/SharedPtr.h: Added.
  • ForwardingHeaders/misc/main_thread_malloc.h: Removed.
  • WebCore.xcodeproj/project.pbxproj:
  • khtml/css/css_base.h:
  • khtml/css/css_computedstyle.cpp:
  • khtml/css/css_ruleimpl.h:
  • khtml/css/css_valueimpl.h:
  • khtml/css/cssstyleselector.h:
  • khtml/ecma/domparser.h:
  • khtml/ecma/kjs_css.h:
  • khtml/ecma/kjs_dom.cpp:
  • khtml/ecma/kjs_dom.h:
  • khtml/ecma/kjs_events.h:
  • khtml/ecma/kjs_html.cpp:
  • khtml/ecma/kjs_html.h:
  • khtml/ecma/kjs_range.h:
  • khtml/ecma/kjs_traversal.h:
  • khtml/ecma/kjs_views.cpp:
  • khtml/ecma/kjs_views.h:
  • khtml/ecma/kjs_window.cpp:
  • khtml/ecma/xmlhttprequest.h:
  • khtml/editing/SelectionController.cpp:
  • khtml/editing/append_node_command.cpp:
  • khtml/editing/apply_style_command.cpp:
  • khtml/editing/break_blockquote_command.cpp:
  • khtml/editing/composite_edit_command.cpp:
  • khtml/editing/delete_from_text_node_command.cpp:
  • khtml/editing/delete_selection_command.cpp:
  • khtml/editing/edit_command.cpp:
  • khtml/editing/htmlediting.cpp:
  • khtml/editing/insert_into_text_node_command.cpp:
  • khtml/editing/insert_line_break_command.cpp:
  • khtml/editing/insert_node_before_command.cpp:
  • khtml/editing/insert_paragraph_separator_command.cpp:
  • khtml/editing/insert_text_command.cpp:
  • khtml/editing/join_text_nodes_command.cpp:
  • khtml/editing/markup.cpp:
  • khtml/editing/merge_identical_elements_command.cpp:
  • khtml/editing/move_selection_command.cpp:
  • khtml/editing/rebalance_whitespace_command.cpp:
  • khtml/editing/remove_css_property_command.cpp:
  • khtml/editing/remove_node_attribute_command.cpp:
  • khtml/editing/remove_node_command.cpp:
  • khtml/editing/remove_node_preserving_children_command.cpp:
  • khtml/editing/replace_selection_command.cpp:
  • khtml/editing/set_node_attribute_command.cpp:
  • khtml/editing/split_element_command.cpp:
  • khtml/editing/split_text_node_command.cpp:
  • khtml/editing/split_text_node_containing_element.cpp:
  • khtml/editing/typing_command.cpp:
  • khtml/editing/visible_position.cpp:
  • khtml/editing/visible_position.h:
  • khtml/editing/wrap_contents_in_dummy_span_command.cpp:
  • khtml/html/html_imageimpl.h:
  • khtml/html/html_tableimpl.h:
  • khtml/html/htmlparser.cpp:
  • khtml/khtmlpart_p.h:
  • khtml/misc/arena.cpp: (ArenaAllocate): (FreeArenaList): (ArenaFinish):
  • khtml/misc/hashtable.h: (khtml::HashTable::~HashTable): (khtml::::allocateTable): (khtml::::rehash): (khtml::::clear): (khtml::::HashTable):
  • khtml/misc/loader.cpp:
  • khtml/misc/main_thread_malloc.cpp: Removed.
  • khtml/misc/main_thread_malloc.h: Removed.
  • khtml/misc/shared.h:
  • khtml/rendering/render_style.h:
  • khtml/xml/dom2_eventsimpl.h:
  • khtml/xml/dom2_rangeimpl.h:
  • khtml/xml/dom2_traversalimpl.h:
  • khtml/xml/dom2_viewsimpl.h:
  • khtml/xml/dom_docimpl.h:
  • khtml/xml/dom_elementimpl.cpp: (NamedAttrMapImpl::clearAttributes): (NamedAttrMapImpl::operator=): (NamedAttrMapImpl::addAttribute): (NamedAttrMapImpl::removeAttribute):
  • khtml/xml/dom_elementimpl.h:
  • khtml/xml/dom_nodeimpl.cpp:
  • khtml/xml/dom_nodeimpl.h:
  • khtml/xml/dom_position.cpp:
  • khtml/xml/dom_stringimpl.h:
  • kwq/DOM-CSS.mm:
  • kwq/DOM.mm:
  • kwq/DOMEvents.mm:
  • kwq/DOMHTML.mm:
  • kwq/DOMInternal.mm:
  • kwq/DOMViews.mm:
  • kwq/KWQAccObject.mm:
  • kwq/KWQAccObjectCache.mm:
  • kwq/KWQArrayImpl.h:
  • kwq/KWQArrayImpl.mm: (KWQArrayImpl::KWQArrayPrivate::KWQArrayPrivate): (KWQArrayImpl::KWQArrayPrivate::~KWQArrayPrivate): (KWQArrayImpl::resize):
  • kwq/KWQAssertions.h: Removed.
  • kwq/KWQAssertions.m: Removed.
  • kwq/KWQButton.mm:
  • kwq/KWQCString.mm:
  • kwq/KWQClipboard.h:
  • kwq/KWQClipboard.mm:
  • kwq/KWQColor.mm:
  • kwq/KWQComboBox.mm:
  • kwq/KWQEditCommand.mm:
  • kwq/KWQExceptions.h:
  • kwq/KWQFileButton.mm:
  • kwq/KWQFontFamily.h:
  • kwq/KWQFormData.mm:
  • kwq/KWQKHTMLPart.h:
  • kwq/KWQKHTMLPart.mm:
  • kwq/KWQKPartsBrowserInterface.mm:
  • kwq/KWQKURL.mm:
  • kwq/KWQListBox.mm:
  • kwq/KWQListImpl.mm:
  • kwq/KWQLogging.h:
  • kwq/KWQLogging.m:
  • kwq/KWQMapImpl.h:
  • kwq/KWQMapImpl.mm:
  • kwq/KWQObject.mm:
  • kwq/KWQPageState.mm:
  • kwq/KWQPainter.mm:
  • kwq/KWQResourceLoader.mm:
  • kwq/KWQSignal.mm:
  • kwq/KWQSlot.mm:
  • kwq/KWQString.h:
  • kwq/KWQString.mm: (ALLOC_QCHAR): (QString::setBufferFromCFString): (allocatePageNode):
  • kwq/KWQTextArea.mm:
  • kwq/KWQTextCodec.mm:
  • kwq/KWQTextEdit.mm:
  • kwq/KWQTextField.mm:
  • kwq/KWQTimer.mm:
  • kwq/KWQValueListImpl.h:
  • kwq/KWQValueListImpl.mm:
  • kwq/WebCoreBridge.mm:
  • kwq/WebCoreCookieAdapter.m:
  • kwq/WebCoreGraphicsBridge.m:
  • kwq/WebCoreImageRendererFactory.m:
  • kwq/WebCoreKeyGenerator.m:
  • kwq/WebCoreTextRendererFactory.mm:
  • kwq/WebCoreViewFactory.m:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.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 Steet, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#ifndef INTERNAL_H
26#define INTERNAL_H
27
28#include "ustring.h"
29#include "value.h"
30#include "object.h"
31#include "protect.h"
32#include "types.h"
33#include "interpreter.h"
34#include "scope_chain.h"
35#include <kxmlcore/SharedPtr.h>
36
37#if !WIN32
38#define KJS_MULTIPLE_THREADS 1
39#endif
40
41#define I18N_NOOP(s) s
42
43namespace KJS {
44
45 class Node;
46 class ProgramNode;
47 class FunctionBodyNode;
48 class FunctionPrototypeImp;
49 class FunctionImp;
50 class Debugger;
51
52 // ---------------------------------------------------------------------------
53 // Primitive impls
54 // ---------------------------------------------------------------------------
55
56 class UndefinedImp : public AllocatedValueImp {
57 public:
58 Type type() const { return UndefinedType; }
59
60 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
61 bool toBoolean(ExecState *exec) const;
62 double toNumber(ExecState *exec) const;
63 UString toString(ExecState *exec) const;
64 ObjectImp *toObject(ExecState *exec) const;
65 };
66
67 class NullImp : public AllocatedValueImp {
68 public:
69 Type type() const { return NullType; }
70
71 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
72 bool toBoolean(ExecState *exec) const;
73 double toNumber(ExecState *exec) const;
74 UString toString(ExecState *exec) const;
75 ObjectImp *toObject(ExecState *exec) const;
76 };
77
78 class BooleanImp : public AllocatedValueImp {
79 public:
80 BooleanImp(bool v = false) : val(v) { }
81 bool value() const { return val; }
82
83 Type type() const { return BooleanType; }
84
85 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
86 bool toBoolean(ExecState *exec) const;
87 double toNumber(ExecState *exec) const;
88 UString toString(ExecState *exec) const;
89 ObjectImp *toObject(ExecState *exec) const;
90
91 private:
92 bool val;
93 };
94
95 class StringImp : public AllocatedValueImp {
96 public:
97 StringImp(const UString& v) : val(v) { }
98 UString value() const { return val; }
99
100 Type type() const { return StringType; }
101
102 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
103 bool toBoolean(ExecState *exec) const;
104 double toNumber(ExecState *exec) const;
105 UString toString(ExecState *exec) const;
106 ObjectImp *toObject(ExecState *exec) const;
107
108 private:
109 UString val;
110 };
111
112 class NumberImp : public AllocatedValueImp {
113 friend class ConstantValues;
114 friend class InterpreterImp;
115 friend ValueImp *jsNumber(int);
116 friend ValueImp *jsNumber(unsigned);
117 friend ValueImp *jsNumber(long);
118 friend ValueImp *jsNumber(unsigned long);
119 friend ValueImp *jsNumber(long long);
120 friend ValueImp *jsNumber(unsigned long long);
121 friend ValueImp *jsNumber(double);
122 friend ValueImp *jsNumber(double, bool);
123 public:
124 double value() const { return val; }
125
126 Type type() const { return NumberType; }
127
128 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
129 bool toBoolean(ExecState *exec) const;
130 double toNumber(ExecState *exec) const;
131 UString toString(ExecState *exec) const;
132 ObjectImp *toObject(ExecState *exec) const;
133
134 private:
135 NumberImp(double v) : val(v) { }
136
137 virtual bool getUInt32(uint32_t&) const;
138
139 double val;
140 };
141
142 /**
143 * @short The "label set" in Ecma-262 spec
144 */
145 class LabelStack {
146 public:
147 LabelStack(): tos(0L), iterationDepth(0), switchDepth(0) {}
148 ~LabelStack();
149
150 /**
151 * If id is not empty and is not in the stack already, puts it on top of
152 * the stack and returns true, otherwise returns false
153 */
154 bool push(const Identifier &id);
155 /**
156 * Is the id in the stack?
157 */
158 bool contains(const Identifier &id) const;
159 /**
160 * Removes from the stack the last pushed id (what else?)
161 */
162 void pop();
163
164 void pushIteration() { iterationDepth++; }
165 void popIteration() { iterationDepth--; }
166 bool inIteration() const { return (iterationDepth > 0); }
167
168 void pushSwitch() { switchDepth++; }
169 void popSwitch() { switchDepth--; }
170 bool inSwitch() const { return (switchDepth > 0); }
171
172 private:
173 LabelStack(const LabelStack &other);
174 LabelStack &operator=(const LabelStack &other);
175
176 struct StackElem {
177 Identifier id;
178 StackElem *prev;
179 };
180
181 StackElem *tos;
182 int iterationDepth;
183 int switchDepth;
184 };
185
186
187 // ---------------------------------------------------------------------------
188 // Parsing & evaluation
189 // ---------------------------------------------------------------------------
190
191 enum CodeType { GlobalCode,
192 EvalCode,
193 FunctionCode,
194 AnonymousCode };
195
196 /**
197 * @internal
198 *
199 * Parses ECMAScript source code and converts into ProgramNode objects, which
200 * represent the root of a parse tree. This class provides a conveniant workaround
201 * for the problem of the bison parser working in a static context.
202 */
203 class Parser {
204 public:
205 static SharedPtr<ProgramNode> parse(const UString &sourceURL, int startingLineNumber,
206 const UChar *code, unsigned int length, int *sourceId = 0,
207 int *errLine = 0, UString *errMsg = 0);
208 static void accept(ProgramNode *prog);
209
210 static void saveNewNode(Node *node);
211
212 static int sid;
213 };
214
215 class SavedBuiltinsInternal {
216 friend class InterpreterImp;
217 private:
218 ProtectedPtr<ObjectImp> b_Object;
219 ProtectedPtr<ObjectImp> b_Function;
220 ProtectedPtr<ObjectImp> b_Array;
221 ProtectedPtr<ObjectImp> b_Boolean;
222 ProtectedPtr<ObjectImp> b_String;
223 ProtectedPtr<ObjectImp> b_Number;
224 ProtectedPtr<ObjectImp> b_Date;
225 ProtectedPtr<ObjectImp> b_RegExp;
226 ProtectedPtr<ObjectImp> b_Error;
227
228 ProtectedPtr<ObjectImp> b_ObjectPrototype;
229 ProtectedPtr<ObjectImp> b_FunctionPrototype;
230 ProtectedPtr<ObjectImp> b_ArrayPrototype;
231 ProtectedPtr<ObjectImp> b_BooleanPrototype;
232 ProtectedPtr<ObjectImp> b_StringPrototype;
233 ProtectedPtr<ObjectImp> b_NumberPrototype;
234 ProtectedPtr<ObjectImp> b_DatePrototype;
235 ProtectedPtr<ObjectImp> b_RegExpPrototype;
236 ProtectedPtr<ObjectImp> b_ErrorPrototype;
237
238 ProtectedPtr<ObjectImp> b_evalError;
239 ProtectedPtr<ObjectImp> b_rangeError;
240 ProtectedPtr<ObjectImp> b_referenceError;
241 ProtectedPtr<ObjectImp> b_syntaxError;
242 ProtectedPtr<ObjectImp> b_typeError;
243 ProtectedPtr<ObjectImp> b_uriError;
244
245 ProtectedPtr<ObjectImp> b_evalErrorPrototype;
246 ProtectedPtr<ObjectImp> b_rangeErrorPrototype;
247 ProtectedPtr<ObjectImp> b_referenceErrorPrototype;
248 ProtectedPtr<ObjectImp> b_syntaxErrorPrototype;
249 ProtectedPtr<ObjectImp> b_typeErrorPrototype;
250 ProtectedPtr<ObjectImp> b_uriErrorPrototype;
251 };
252
253 class InterpreterImp {
254 friend class Collector;
255 public:
256 static void globalInit();
257 static void globalClear();
258
259 InterpreterImp(Interpreter *interp, ObjectImp *glob);
260 ~InterpreterImp();
261
262 ObjectImp *globalObject() { return global; }
263 Interpreter *interpreter() const { return m_interpreter; }
264
265 void initGlobalObject();
266 static void lock();
267 static void unlock();
268 static int lockCount();
269
270 void mark();
271
272 ExecState *globalExec() { return &globExec; }
273 bool checkSyntax(const UString &code);
274 Completion evaluate(const UString &code, ValueImp *thisV, const UString &sourceURL, int startingLineNumber);
275 Debugger *debugger() const { return dbg; }
276 void setDebugger(Debugger *d) { dbg = d; }
277
278 ObjectImp *builtinObject() const { return b_Object; }
279 ObjectImp *builtinFunction() const { return b_Function; }
280 ObjectImp *builtinArray() const { return b_Array; }
281 ObjectImp *builtinBoolean() const { return b_Boolean; }
282 ObjectImp *builtinString() const { return b_String; }
283 ObjectImp *builtinNumber() const { return b_Number; }
284 ObjectImp *builtinDate() const { return b_Date; }
285 ObjectImp *builtinRegExp() const { return b_RegExp; }
286 ObjectImp *builtinError() const { return b_Error; }
287
288 ObjectImp *builtinObjectPrototype() const { return b_ObjectPrototype; }
289 ObjectImp *builtinFunctionPrototype() const { return b_FunctionPrototype; }
290 ObjectImp *builtinArrayPrototype() const { return b_ArrayPrototype; }
291 ObjectImp *builtinBooleanPrototype() const { return b_BooleanPrototype; }
292 ObjectImp *builtinStringPrototype() const { return b_StringPrototype; }
293 ObjectImp *builtinNumberPrototype() const { return b_NumberPrototype; }
294 ObjectImp *builtinDatePrototype() const { return b_DatePrototype; }
295 ObjectImp *builtinRegExpPrototype() const { return b_RegExpPrototype; }
296 ObjectImp *builtinErrorPrototype() const { return b_ErrorPrototype; }
297
298 ObjectImp *builtinEvalError() const { return b_evalError; }
299 ObjectImp *builtinRangeError() const { return b_rangeError; }
300 ObjectImp *builtinReferenceError() const { return b_referenceError; }
301 ObjectImp *builtinSyntaxError() const { return b_syntaxError; }
302 ObjectImp *builtinTypeError() const { return b_typeError; }
303 ObjectImp *builtinURIError() const { return b_uriError; }
304
305 ObjectImp *builtinEvalErrorPrototype() const { return b_evalErrorPrototype; }
306 ObjectImp *builtinRangeErrorPrototype() const { return b_rangeErrorPrototype; }
307 ObjectImp *builtinReferenceErrorPrototype() const { return b_referenceErrorPrototype; }
308 ObjectImp *builtinSyntaxErrorPrototype() const { return b_syntaxErrorPrototype; }
309 ObjectImp *builtinTypeErrorPrototype() const { return b_typeErrorPrototype; }
310 ObjectImp *builtinURIErrorPrototype() const { return b_uriErrorPrototype; }
311
312 void setCompatMode(Interpreter::CompatMode mode) { m_compatMode = mode; }
313 Interpreter::CompatMode compatMode() const { return m_compatMode; }
314
315 // Chained list of interpreters (ring)
316 static InterpreterImp* firstInterpreter() { return s_hook; }
317 InterpreterImp *nextInterpreter() const { return next; }
318 InterpreterImp *prevInterpreter() const { return prev; }
319
320 static InterpreterImp *interpreterWithGlobalObject(ObjectImp *);
321
322 void setContext(ContextImp *c) { _context = c; }
323 ContextImp *context() const { return _context; }
324
325 void saveBuiltins (SavedBuiltins &builtins) const;
326 void restoreBuiltins (const SavedBuiltins &builtins);
327
328 private:
329 void clear();
330 Interpreter *m_interpreter;
331 ObjectImp *global;
332 Debugger *dbg;
333
334 // Built-in properties of the object prototype. These are accessible
335 // from here even if they are replaced by js code (e.g. assigning to
336 // Array.prototype)
337
338 ProtectedPtr<ObjectImp> b_Object;
339 ProtectedPtr<ObjectImp> b_Function;
340 ProtectedPtr<ObjectImp> b_Array;
341 ProtectedPtr<ObjectImp> b_Boolean;
342 ProtectedPtr<ObjectImp> b_String;
343 ProtectedPtr<ObjectImp> b_Number;
344 ProtectedPtr<ObjectImp> b_Date;
345 ProtectedPtr<ObjectImp> b_RegExp;
346 ProtectedPtr<ObjectImp> b_Error;
347
348 ProtectedPtr<ObjectImp> b_ObjectPrototype;
349 ProtectedPtr<ObjectImp> b_FunctionPrototype;
350 ProtectedPtr<ObjectImp> b_ArrayPrototype;
351 ProtectedPtr<ObjectImp> b_BooleanPrototype;
352 ProtectedPtr<ObjectImp> b_StringPrototype;
353 ProtectedPtr<ObjectImp> b_NumberPrototype;
354 ProtectedPtr<ObjectImp> b_DatePrototype;
355 ProtectedPtr<ObjectImp> b_RegExpPrototype;
356 ProtectedPtr<ObjectImp> b_ErrorPrototype;
357
358 ProtectedPtr<ObjectImp> b_evalError;
359 ProtectedPtr<ObjectImp> b_rangeError;
360 ProtectedPtr<ObjectImp> b_referenceError;
361 ProtectedPtr<ObjectImp> b_syntaxError;
362 ProtectedPtr<ObjectImp> b_typeError;
363 ProtectedPtr<ObjectImp> b_uriError;
364
365 ProtectedPtr<ObjectImp> b_evalErrorPrototype;
366 ProtectedPtr<ObjectImp> b_rangeErrorPrototype;
367 ProtectedPtr<ObjectImp> b_referenceErrorPrototype;
368 ProtectedPtr<ObjectImp> b_syntaxErrorPrototype;
369 ProtectedPtr<ObjectImp> b_typeErrorPrototype;
370 ProtectedPtr<ObjectImp> b_uriErrorPrototype;
371
372 ExecState globExec;
373 Interpreter::CompatMode m_compatMode;
374
375 // Chained list of interpreters (ring) - for collector
376 static InterpreterImp* s_hook;
377 InterpreterImp *next, *prev;
378
379 ContextImp *_context;
380
381 int recursion;
382 };
383
384 class AttachedInterpreter;
385 class DebuggerImp {
386 public:
387
388 DebuggerImp() {
389 interps = 0;
390 isAborted = false;
391 }
392
393 void abort() { isAborted = true; }
394 bool aborted() const { return isAborted; }
395
396 AttachedInterpreter *interps;
397 bool isAborted;
398 };
399
400
401
402 class InternalFunctionImp : public ObjectImp {
403 public:
404 InternalFunctionImp();
405 InternalFunctionImp(FunctionPrototypeImp *funcProto);
406 bool implementsHasInstance() const;
407 bool hasInstance(ExecState *exec, ValueImp *value);
408
409 virtual const ClassInfo *classInfo() const { return &info; }
410 static const ClassInfo info;
411 };
412
413 // helper function for toInteger, toInt32, toUInt32 and toUInt16
414 double roundValue(ExecState *, ValueImp *);
415
416#ifndef NDEBUG
417 void printInfo(ExecState *exec, const char *s, ValueImp *, int lineno = -1);
418#endif
419
420inline LabelStack::~LabelStack()
421{
422 StackElem *prev;
423 for (StackElem *e = tos; e; e = prev) {
424 prev = e->prev;
425 delete e;
426 }
427}
428
429inline void LabelStack::pop()
430{
431 if (StackElem *e = tos) {
432 tos = e->prev;
433 delete e;
434 }
435}
436
437} // namespace
438
439#endif // INTERNAL_H
Note: See TracBrowser for help on using the repository browser.