source: webkit/trunk/JavaScriptCore/kjs/JSGlobalObject.cpp@ 36726

Last change on this file since 36726 was 36726, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-09-20 Darin Adler <Darin Adler>

Reviewed by Maciej Stachowiak.

This also includes some optimizations that make the change an overall
small speedup. Without those it was a bit of a slowdown.

  • API/JSCallbackConstructor.cpp: (JSC::JSCallbackConstructor::JSCallbackConstructor): Take a structure.
  • API/JSCallbackConstructor.h: Ditto.
  • API/JSCallbackFunction.cpp: (JSC::JSCallbackFunction::JSCallbackFunction): Pass a structure.
  • API/JSCallbackObject.h: Take a structure.
  • API/JSCallbackObjectFunctions.h: (JSC::JSCallbackObject::JSCallbackObject): Ditto.
  • API/JSClassRef.cpp: (OpaqueJSClass::prototype): Pass in a structure. Call setPrototype if there's a custom prototype involved.
  • API/JSObjectRef.cpp: (JSObjectMake): Ditto. (JSObjectMakeConstructor): Pass in a structure.
  • VM/Machine.cpp: (JSC::jsLess): Added a special case for when both arguments are strings. This avoids converting both strings to with UString::toDouble. (JSC::jsLessEq): Ditto. (JSC::Machine::privateExecute): Pass in a structure. (JSC::Machine::cti_op_construct_JSConstruct): Ditto. (JSC::Machine::cti_op_new_regexp): Ditto. (JSC::Machine::cti_op_is_string): Ditto.
  • VM/Machine.h: Made isJSString public so it can be used in the CTI.
  • kjs/Arguments.cpp: (JSC::Arguments::Arguments): Pass in a structure.
  • kjs/JSCell.h: Mark constructor explicit.
  • kjs/JSGlobalObject.cpp: (JSC::markIfNeeded): Added an overload for marking structures. (JSC::JSGlobalObject::reset): Eliminate code to set data members to zero. We now do that in the constructor, and we no longer use this anywhere except in the constructor. Added code to create structures. Pass structures rather than prototypes when creating objects. (JSC::JSGlobalObject::mark): Mark the structures.
  • kjs/JSGlobalObject.h: Removed unneeded class declarations. Added initializers for raw pointers in JSGlobalObjectData so everything starts with a 0. Added structure data and accessor functions.
  • kjs/JSImmediate.cpp: (JSC::JSImmediate::nonInlineNaN): Added.
  • kjs/JSImmediate.h: (JSC::JSImmediate::toDouble): Rewrote to avoid PIC branches.
  • kjs/JSNumberCell.cpp: (JSC::jsNumberCell): Made non-inline to avoid PIC branches in functions that call this one. (JSC::jsNaN): Ditto.
  • kjs/JSNumberCell.h: Ditto.
  • kjs/JSObject.h: Removed constructor that takes a prototype. All callers now pass structures.
  • kjs/ArrayConstructor.cpp: (JSC::ArrayConstructor::ArrayConstructor): (JSC::constructArrayWithSizeQuirk):
  • kjs/ArrayConstructor.h:
  • kjs/ArrayPrototype.cpp: (JSC::ArrayPrototype::ArrayPrototype):
  • kjs/ArrayPrototype.h:
  • kjs/BooleanConstructor.cpp: (JSC::BooleanConstructor::BooleanConstructor): (JSC::constructBoolean): (JSC::constructBooleanFromImmediateBoolean):
  • kjs/BooleanConstructor.h:
  • kjs/BooleanObject.cpp: (JSC::BooleanObject::BooleanObject):
  • kjs/BooleanObject.h:
  • kjs/BooleanPrototype.cpp: (JSC::BooleanPrototype::BooleanPrototype):
  • kjs/BooleanPrototype.h:
  • kjs/DateConstructor.cpp: (JSC::DateConstructor::DateConstructor): (JSC::constructDate):
  • kjs/DateConstructor.h:
  • kjs/DateInstance.cpp: (JSC::DateInstance::DateInstance):
  • kjs/DateInstance.h:
  • kjs/DatePrototype.cpp: (JSC::DatePrototype::DatePrototype):
  • kjs/DatePrototype.h:
  • kjs/ErrorConstructor.cpp: (JSC::ErrorConstructor::ErrorConstructor): (JSC::constructError):
  • kjs/ErrorConstructor.h:
  • kjs/ErrorInstance.cpp: (JSC::ErrorInstance::ErrorInstance):
  • kjs/ErrorInstance.h:
  • kjs/ErrorPrototype.cpp: (JSC::ErrorPrototype::ErrorPrototype):
  • kjs/ErrorPrototype.h:
  • kjs/FunctionConstructor.cpp: (JSC::FunctionConstructor::FunctionConstructor):
  • kjs/FunctionConstructor.h:
  • kjs/FunctionPrototype.cpp: (JSC::FunctionPrototype::FunctionPrototype): (JSC::FunctionPrototype::addFunctionProperties):
  • kjs/FunctionPrototype.h:
  • kjs/GlobalEvalFunction.cpp: (JSC::GlobalEvalFunction::GlobalEvalFunction):
  • kjs/GlobalEvalFunction.h:
  • kjs/InternalFunction.cpp: (JSC::InternalFunction::InternalFunction):
  • kjs/InternalFunction.h: (JSC::InternalFunction::InternalFunction):
  • kjs/JSArray.cpp: (JSC::JSArray::JSArray): (JSC::constructEmptyArray): (JSC::constructArray):
  • kjs/JSArray.h:
  • kjs/JSFunction.cpp: (JSC::JSFunction::JSFunction): (JSC::JSFunction::construct):
  • kjs/JSObject.cpp: (JSC::constructEmptyObject):
  • kjs/JSString.cpp: (JSC::StringObject::create):
  • kjs/JSWrapperObject.h:
  • kjs/MathObject.cpp: (JSC::MathObject::MathObject):
  • kjs/MathObject.h:
  • kjs/NativeErrorConstructor.cpp: (JSC::NativeErrorConstructor::NativeErrorConstructor): (JSC::NativeErrorConstructor::construct):
  • kjs/NativeErrorConstructor.h:
  • kjs/NativeErrorPrototype.cpp: (JSC::NativeErrorPrototype::NativeErrorPrototype):
  • kjs/NativeErrorPrototype.h:
  • kjs/NumberConstructor.cpp: (JSC::NumberConstructor::NumberConstructor): (JSC::constructWithNumberConstructor):
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.cpp: (JSC::NumberObject::NumberObject): (JSC::constructNumber): (JSC::constructNumberFromImmediateNumber):
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.cpp: (JSC::NumberPrototype::NumberPrototype):
  • kjs/NumberPrototype.h:
  • kjs/ObjectConstructor.cpp: (JSC::ObjectConstructor::ObjectConstructor): (JSC::constructObject):
  • kjs/ObjectConstructor.h:
  • kjs/ObjectPrototype.cpp: (JSC::ObjectPrototype::ObjectPrototype):
  • kjs/ObjectPrototype.h:
  • kjs/PrototypeFunction.cpp: (JSC::PrototypeFunction::PrototypeFunction):
  • kjs/PrototypeFunction.h:
  • kjs/RegExpConstructor.cpp: (JSC::RegExpConstructor::RegExpConstructor): (JSC::RegExpMatchesArray::RegExpMatchesArray): (JSC::constructRegExp):
  • kjs/RegExpConstructor.h:
  • kjs/RegExpObject.cpp: (JSC::RegExpObject::RegExpObject):
  • kjs/RegExpObject.h:
  • kjs/RegExpPrototype.cpp: (JSC::RegExpPrototype::RegExpPrototype):
  • kjs/RegExpPrototype.h:
  • kjs/Shell.cpp: (GlobalObject::GlobalObject):
  • kjs/StringConstructor.cpp: (JSC::StringConstructor::StringConstructor): (JSC::constructWithStringConstructor):
  • kjs/StringConstructor.h:
  • kjs/StringObject.cpp: (JSC::StringObject::StringObject):
  • kjs/StringObject.h:
  • kjs/StringObjectThatMasqueradesAsUndefined.h: (JSC::StringObjectThatMasqueradesAsUndefined::StringObjectThatMasqueradesAsUndefined):
  • kjs/StringPrototype.cpp: (JSC::StringPrototype::StringPrototype):
  • kjs/StringPrototype.h: Take and pass structures.

WebCore:

2008-09-20 Darin Adler <Darin Adler>

Reviewed by Maciej Stachowiak.

  • bindings/js/JSCSSStyleDeclarationCustom.cpp: (WebCore::JSCSSStyleDeclaration::nameGetter): Pass in a structure ID. Note that this makes a new structure every time -- we could optimize this slightly be caching and reusing a single one.
  • bridge/runtime_method.cpp: (JSC::RuntimeMethod::RuntimeMethod): Create a unique structure using getDOMStructure.
  • bridge/runtime_method.h: (JSC::RuntimeMethod::createPrototype): Added createPrototype so getDOMStructure will work.
  • bindings/js/JSDOMWindowShell.cpp: (WebCore::JSDOMWindowShell::JSDOMWindowShell): Initialize m_window to 0; needed in case garbage collection happens while creating the JSDOMWindow.
  • Property svn:eol-style set to native
File size: 20.7 KB
Line 
1/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich ([email protected])
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "config.h"
31#include "JSGlobalObject.h"
32
33#include "ArrayConstructor.h"
34#include "ArrayPrototype.h"
35#include "BooleanConstructor.h"
36#include "BooleanPrototype.h"
37#include "CodeBlock.h"
38#include "DateConstructor.h"
39#include "DatePrototype.h"
40#include "ErrorConstructor.h"
41#include "ErrorPrototype.h"
42#include "FunctionConstructor.h"
43#include "FunctionPrototype.h"
44#include "GlobalEvalFunction.h"
45#include "JSGlobalObjectFunctions.h"
46#include "JSLock.h"
47#include "Machine.h"
48#include "MathObject.h"
49#include "NativeErrorConstructor.h"
50#include "NativeErrorPrototype.h"
51#include "NumberConstructor.h"
52#include "NumberPrototype.h"
53#include "ObjectConstructor.h"
54#include "ObjectPrototype.h"
55#include "Profiler.h"
56#include "PrototypeFunction.h"
57#include "RegExpConstructor.h"
58#include "RegExpPrototype.h"
59#include "ScopeChainMark.h"
60#include "StringConstructor.h"
61#include "StringPrototype.h"
62#include "debugger.h"
63
64namespace JSC {
65
66ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
67
68// Default number of ticks before a timeout check should be done.
69static const int initialTickCountThreshold = 255;
70
71// Preferred number of milliseconds between each timeout check
72static const int preferredScriptCheckTimeInterval = 1000;
73
74static inline void markIfNeeded(JSValue* v)
75{
76 if (v && !v->marked())
77 v->mark();
78}
79
80static inline void markIfNeeded(const RefPtr<StructureID>& s)
81{
82 if (s)
83 s->mark();
84}
85
86JSGlobalObject::~JSGlobalObject()
87{
88 ASSERT(JSLock::currentThreadIsHoldingLock());
89
90 if (d()->debugger)
91 d()->debugger->detach(this);
92
93 Profiler** profiler = Profiler::enabledProfilerReference();
94 if (UNLIKELY(*profiler != 0)) {
95 (*profiler)->stopProfiling(globalExec(), UString());
96 }
97
98 d()->next->d()->prev = d()->prev;
99 d()->prev->d()->next = d()->next;
100 JSGlobalObject*& headObject = head();
101 if (headObject == this)
102 headObject = d()->next;
103 if (headObject == this)
104 headObject = 0;
105
106 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
107 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
108 (*it)->globalObject = 0;
109
110 RegisterFile& registerFile = globalData()->machine->registerFile();
111 if (registerFile.globalObject() == this) {
112 registerFile.setGlobalObject(0);
113 registerFile.setNumGlobals(0);
114 }
115 delete d();
116}
117
118void JSGlobalObject::init(JSObject* thisValue)
119{
120 ASSERT(JSLock::currentThreadIsHoldingLock());
121
122 d()->globalData = Heap::heap(this)->globalData();
123
124 if (JSGlobalObject*& headObject = head()) {
125 d()->prev = headObject;
126 d()->next = headObject->d()->next;
127 headObject->d()->next->d()->prev = this;
128 headObject->d()->next = this;
129 } else
130 headObject = d()->next = d()->prev = this;
131
132 d()->recursion = 0;
133 d()->debugger = 0;
134 globalData()->machine->initTimeout();
135
136 d()->globalExec.set(new ExecState(this, thisValue, d()->globalScopeChain.node()));
137
138 d()->profileGroup = 0;
139
140 reset(prototype());
141}
142
143void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
144{
145 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
146
147 if (symbolTablePut(propertyName, value))
148 return;
149 JSVariableObject::put(exec, propertyName, value, slot);
150}
151
152void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue* value, unsigned attributes)
153{
154 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
155
156 if (symbolTablePutWithAttributes(propertyName, value, attributes))
157 return;
158
159 JSValue* valueBefore = getDirect(propertyName);
160 PutPropertySlot slot;
161 JSVariableObject::put(exec, propertyName, value, slot);
162 if (!valueBefore) {
163 if (JSValue* valueAfter = getDirect(propertyName))
164 putDirect(propertyName, valueAfter, attributes);
165 }
166}
167
168void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc)
169{
170 PropertySlot slot;
171 if (!symbolTableGet(propertyName, slot))
172 JSVariableObject::defineGetter(exec, propertyName, getterFunc);
173}
174
175void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc)
176{
177 PropertySlot slot;
178 if (!symbolTableGet(propertyName, slot))
179 JSVariableObject::defineSetter(exec, propertyName, setterFunc);
180}
181
182static inline JSObject* lastInPrototypeChain(JSObject* object)
183{
184 JSObject* o = object;
185 while (o->prototype()->isObject())
186 o = static_cast<JSObject*>(o->prototype());
187 return o;
188}
189
190void JSGlobalObject::reset(JSValue* prototype)
191{
192 // Clear before inititalizing, to avoid calling mark() on stale pointers --
193 // which would be wasteful -- or uninitialized pointers -- which would be
194 // dangerous. (The allocations below may cause a GC.)
195
196 ASSERT(!hasCustomProperties());
197 symbolTable().clear();
198 setRegisterArray(0, 0);
199
200 ExecState* exec = d()->globalExec.get();
201
202 // Prototypes
203
204 d()->functionPrototype = new (exec) FunctionPrototype(exec);
205 d()->functionStructure = StructureID::create(d()->functionPrototype);
206 d()->callbackFunctionStructure = StructureID::create(d()->functionPrototype);
207 d()->prototypeFunctionStructure = StructureID::create(d()->functionPrototype);
208 d()->callbackFunctionStructure = StructureID::create(d()->functionPrototype);
209 d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get());
210 d()->objectPrototype = new (exec) ObjectPrototype(exec, d()->prototypeFunctionStructure.get());
211 d()->emptyObjectStructure = d()->objectPrototype->inheritorID();
212 d()->functionPrototype->setPrototype(d()->objectPrototype);
213 d()->argumentsStructure = StructureID::create(d()->objectPrototype);
214 d()->callbackConstructorStructure = StructureID::create(d()->objectPrototype);
215 d()->callbackObjectStructure = StructureID::create(d()->objectPrototype);
216 d()->arrayPrototype = new (exec) ArrayPrototype(StructureID::create(d()->objectPrototype));
217 d()->arrayStructure = StructureID::create(d()->arrayPrototype);
218 d()->regExpMatchesArrayStructure = StructureID::create(d()->arrayPrototype);
219 d()->stringPrototype = new (exec) StringPrototype(exec, StructureID::create(d()->objectPrototype));
220 d()->stringObjectStructure = StructureID::create(d()->stringPrototype);
221 d()->booleanPrototype = new (exec) BooleanPrototype(exec, StructureID::create(d()->objectPrototype), d()->prototypeFunctionStructure.get());
222 d()->booleanObjectStructure = StructureID::create(d()->booleanPrototype);
223 d()->numberPrototype = new (exec) NumberPrototype(exec, StructureID::create(d()->objectPrototype), d()->prototypeFunctionStructure.get());
224 d()->numberObjectStructure = StructureID::create(d()->numberPrototype);
225 d()->datePrototype = new (exec) DatePrototype(exec, StructureID::create(d()->objectPrototype));
226 d()->dateStructure = StructureID::create(d()->datePrototype);
227 d()->regExpPrototype = new (exec) RegExpPrototype(exec, StructureID::create(d()->objectPrototype), d()->prototypeFunctionStructure.get());
228 d()->regExpStructure = StructureID::create(d()->regExpPrototype);
229 ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, StructureID::create(d()->objectPrototype), d()->prototypeFunctionStructure.get());
230 d()->errorStructure = StructureID::create(errorPrototype);
231
232 RefPtr<StructureID> nativeErrorPrototypeStructure = StructureID::create(errorPrototype);
233
234 NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError");
235 NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError");
236 NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError");
237 NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError");
238 NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError");
239 NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError");
240
241 // Constructors
242
243 JSValue* objectConstructor = new (exec) ObjectConstructor(exec, StructureID::create(d()->functionPrototype), d()->objectPrototype);
244 JSValue* functionConstructor = new (exec) FunctionConstructor(exec, StructureID::create(d()->functionPrototype), d()->functionPrototype);
245 JSValue* arrayConstructor = new (exec) ArrayConstructor(exec, StructureID::create(d()->functionPrototype), d()->arrayPrototype);
246 JSValue* stringConstructor = new (exec) StringConstructor(exec, StructureID::create(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
247 JSValue* booleanConstructor = new (exec) BooleanConstructor(exec, StructureID::create(d()->functionPrototype), d()->booleanPrototype);
248 JSValue* numberConstructor = new (exec) NumberConstructor(exec, StructureID::create(d()->functionPrototype), d()->numberPrototype);
249 JSValue* dateConstructor = new (exec) DateConstructor(exec, StructureID::create(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype);
250
251 d()->regExpConstructor = new (exec) RegExpConstructor(exec, StructureID::create(d()->functionPrototype), d()->regExpPrototype);
252
253 d()->errorConstructor = new (exec) ErrorConstructor(exec, StructureID::create(d()->functionPrototype), errorPrototype);
254
255 RefPtr<StructureID> nativeErrorStructure = StructureID::create(d()->functionPrototype);
256
257 d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype);
258 d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype);
259 d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype);
260 d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype);
261 d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype);
262 d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype);
263
264 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
265
266 d()->objectPrototype->putDirect(exec->propertyNames().constructor, objectConstructor, DontEnum);
267 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
268 d()->arrayPrototype->putDirect(exec->propertyNames().constructor, arrayConstructor, DontEnum);
269 d()->booleanPrototype->putDirect(exec->propertyNames().constructor, booleanConstructor, DontEnum);
270 d()->stringPrototype->putDirect(exec->propertyNames().constructor, stringConstructor, DontEnum);
271 d()->numberPrototype->putDirect(exec->propertyNames().constructor, numberConstructor, DontEnum);
272 d()->datePrototype->putDirect(exec->propertyNames().constructor, dateConstructor, DontEnum);
273 d()->regExpPrototype->putDirect(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
274 errorPrototype->putDirect(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
275 evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
276 rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
277 referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
278 syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
279 typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
280 URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum);
281
282 // Set global constructors
283
284 // FIXME: These properties could be handled by a static hash table.
285
286 putDirect(Identifier(exec, "Object"), objectConstructor, DontEnum);
287 putDirect(Identifier(exec, "Function"), functionConstructor, DontEnum);
288 putDirect(Identifier(exec, "Array"), arrayConstructor, DontEnum);
289 putDirect(Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
290 putDirect(Identifier(exec, "String"), stringConstructor, DontEnum);
291 putDirect(Identifier(exec, "Number"), numberConstructor, DontEnum);
292 putDirect(Identifier(exec, "Date"), dateConstructor, DontEnum);
293 putDirect(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum);
294 putDirect(Identifier(exec, "Error"), d()->errorConstructor, DontEnum);
295 putDirect(Identifier(exec, "EvalError"), d()->evalErrorConstructor);
296 putDirect(Identifier(exec, "RangeError"), d()->rangeErrorConstructor);
297 putDirect(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor);
298 putDirect(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor);
299 putDirect(Identifier(exec, "TypeError"), d()->typeErrorConstructor);
300 putDirect(Identifier(exec, "URIError"), d()->URIErrorConstructor);
301
302 // Set global values.
303 GlobalPropertyInfo staticGlobals[] = {
304 GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, StructureID::create(d()->objectPrototype)), DontEnum | DontDelete),
305 GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
306 GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
307 GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete)
308 };
309
310 addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
311
312 // Set global functions.
313
314 d()->evalFunction = new (exec) GlobalEvalFunction(exec, StructureID::create(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this);
315 putDirectFunction(exec, d()->evalFunction, DontEnum);
316 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
317 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
318 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
319 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
320 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
321 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
322 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
323 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
324 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
325 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
326#ifndef NDEBUG
327 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "kjsprint"), globalFuncKJSPrint), DontEnum);
328#endif
329
330 resetPrototype(prototype);
331}
332
333// Set prototype, and also insert the object prototype at the end of the chain.
334void JSGlobalObject::resetPrototype(JSValue* prototype)
335{
336 setPrototype(prototype);
337 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
338}
339
340void JSGlobalObject::setTimeoutTime(unsigned timeoutTime)
341{
342 globalData()->machine->setTimeoutTime(timeoutTime);
343}
344
345void JSGlobalObject::startTimeoutCheck()
346{
347 globalData()->machine->startTimeoutCheck();
348}
349
350void JSGlobalObject::stopTimeoutCheck()
351{
352 globalData()->machine->stopTimeoutCheck();
353}
354
355void JSGlobalObject::mark()
356{
357 JSVariableObject::mark();
358
359 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
360 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
361 (*it)->mark();
362
363 RegisterFile& registerFile = globalData()->machine->registerFile();
364 if (registerFile.globalObject() == this)
365 registerFile.markGlobals(globalData()->heap);
366
367 markIfNeeded(d()->globalExec->exception());
368
369 markIfNeeded(d()->regExpConstructor);
370 markIfNeeded(d()->errorConstructor);
371 markIfNeeded(d()->evalErrorConstructor);
372 markIfNeeded(d()->rangeErrorConstructor);
373 markIfNeeded(d()->referenceErrorConstructor);
374 markIfNeeded(d()->syntaxErrorConstructor);
375 markIfNeeded(d()->typeErrorConstructor);
376 markIfNeeded(d()->URIErrorConstructor);
377
378 markIfNeeded(d()->evalFunction);
379
380 markIfNeeded(d()->objectPrototype);
381 markIfNeeded(d()->functionPrototype);
382 markIfNeeded(d()->booleanPrototype);
383 markIfNeeded(d()->stringPrototype);
384 markIfNeeded(d()->numberPrototype);
385 markIfNeeded(d()->datePrototype);
386 markIfNeeded(d()->regExpPrototype);
387
388 markIfNeeded(d()->errorStructure);
389
390 // No need to mark the other structures, because their prototypes are all
391 // guaranteed to be referenced elsewhere.
392}
393
394JSGlobalObject* JSGlobalObject::toGlobalObject(ExecState*) const
395{
396 return const_cast<JSGlobalObject*>(this);
397}
398
399ExecState* JSGlobalObject::globalExec()
400{
401 return d()->globalExec.get();
402}
403
404bool JSGlobalObject::isDynamicScope() const
405{
406 return true;
407}
408
409void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
410{
411 ASSERT(!d()->registerArray);
412 ASSERT(!d()->registerArraySize);
413
414 int numGlobals = registerFile.numGlobals();
415 if (!numGlobals) {
416 d()->registers = 0;
417 return;
418 }
419 copyRegisterArray(registerFile.lastGlobal(), numGlobals);
420}
421
422void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile)
423{
424 JSGlobalObject* lastGlobalObject = registerFile.globalObject();
425 if (lastGlobalObject && lastGlobalObject != this)
426 lastGlobalObject->copyGlobalsFrom(registerFile);
427
428 registerFile.setGlobalObject(this);
429 registerFile.setNumGlobals(symbolTable().size());
430
431 if (d()->registerArray) {
432 memcpy(registerFile.base() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register));
433 setRegisterArray(0, 0);
434 }
435
436 d()->registers = registerFile.base();
437}
438
439void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
440{
441#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
442 return globalData->heap->inlineAllocate(size);
443#else
444 return globalData->heap->allocate(size);
445#endif
446}
447
448} // namespace JSC
Note: See TracBrowser for help on using the repository browser.