source: webkit/trunk/JavaScriptCore/kjs/JSGlobalObject.h@ 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: 13.4 KB
Line 
1/*
2 * Copyright (C) 2007 Eric Seidel <[email protected]>
3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#ifndef JSGlobalObject_h
23#define JSGlobalObject_h
24
25#include "JSGlobalData.h"
26#include "JSVariableObject.h"
27#include "NumberPrototype.h"
28#include "StringPrototype.h"
29#include <wtf/HashSet.h>
30#include <wtf/OwnPtr.h>
31
32namespace JSC {
33
34 class ArrayPrototype;
35 class BooleanPrototype;
36 class DatePrototype;
37 class Debugger;
38 class ErrorConstructor;
39 class FunctionPrototype;
40 class GlobalEvalFunction;
41 class NativeErrorConstructor;
42 class ProgramCodeBlock;
43 class RegExpConstructor;
44 class RegExpPrototype;
45 class RegisterFile;
46
47 struct ActivationStackNode;
48 struct HashTable;
49
50 typedef Vector<ExecState*, 16> ExecStateStack;
51
52 class JSGlobalObject : public JSVariableObject {
53 protected:
54 using JSVariableObject::JSVariableObjectData;
55
56 struct JSGlobalObjectData : public JSVariableObjectData {
57 JSGlobalObjectData(JSGlobalObject* globalObject, JSObject* thisValue)
58 : JSVariableObjectData(&symbolTable, 0)
59 , globalScopeChain(globalObject, thisValue)
60 , regExpConstructor(0)
61 , errorConstructor(0)
62 , evalErrorConstructor(0)
63 , rangeErrorConstructor(0)
64 , referenceErrorConstructor(0)
65 , syntaxErrorConstructor(0)
66 , typeErrorConstructor(0)
67 , URIErrorConstructor(0)
68 , evalFunction(0)
69 , objectPrototype(0)
70 , functionPrototype(0)
71 , arrayPrototype(0)
72 , booleanPrototype(0)
73 , stringPrototype(0)
74 , numberPrototype(0)
75 , datePrototype(0)
76 , regExpPrototype(0)
77 {
78 }
79
80 virtual ~JSGlobalObjectData()
81 {
82 }
83
84 JSGlobalObject* next;
85 JSGlobalObject* prev;
86
87 Debugger* debugger;
88
89 ScopeChain globalScopeChain;
90 OwnPtr<ExecState> globalExec;
91
92 int recursion;
93
94 RegExpConstructor* regExpConstructor;
95 ErrorConstructor* errorConstructor;
96 NativeErrorConstructor* evalErrorConstructor;
97 NativeErrorConstructor* rangeErrorConstructor;
98 NativeErrorConstructor* referenceErrorConstructor;
99 NativeErrorConstructor* syntaxErrorConstructor;
100 NativeErrorConstructor* typeErrorConstructor;
101 NativeErrorConstructor* URIErrorConstructor;
102
103 GlobalEvalFunction* evalFunction;
104
105 ObjectPrototype* objectPrototype;
106 FunctionPrototype* functionPrototype;
107 ArrayPrototype* arrayPrototype;
108 BooleanPrototype* booleanPrototype;
109 StringPrototype* stringPrototype;
110 NumberPrototype* numberPrototype;
111 DatePrototype* datePrototype;
112 RegExpPrototype* regExpPrototype;
113
114 RefPtr<StructureID> argumentsStructure;
115 RefPtr<StructureID> arrayStructure;
116 RefPtr<StructureID> booleanObjectStructure;
117 RefPtr<StructureID> callbackConstructorStructure;
118 RefPtr<StructureID> callbackFunctionStructure;
119 RefPtr<StructureID> callbackObjectStructure;
120 RefPtr<StructureID> dateStructure;
121 RefPtr<StructureID> emptyObjectStructure;
122 RefPtr<StructureID> errorStructure;
123 RefPtr<StructureID> functionStructure;
124 RefPtr<StructureID> numberObjectStructure;
125 RefPtr<StructureID> prototypeFunctionStructure;
126 RefPtr<StructureID> regExpMatchesArrayStructure;
127 RefPtr<StructureID> regExpStructure;
128 RefPtr<StructureID> stringObjectStructure;
129
130 SymbolTable symbolTable;
131 unsigned profileGroup;
132
133 RefPtr<JSGlobalData> globalData;
134
135 HashSet<ProgramCodeBlock*> codeBlocks;
136
137 OwnPtr<HashSet<JSObject*> > arrayVisitedElements; // Global data shared by array prototype functions.
138 };
139
140 public:
141 void* operator new(size_t, JSGlobalData*);
142
143 JSGlobalObject(JSGlobalData* globalData)
144 : JSVariableObject(globalData->nullProtoStructureID, new JSGlobalObjectData(this, this))
145 {
146 init(this);
147 }
148
149 protected:
150 JSGlobalObject(PassRefPtr<StructureID> structure, JSGlobalObjectData* data, JSObject* globalThisValue)
151 : JSVariableObject(structure, data)
152 {
153 init(globalThisValue);
154 }
155
156 public:
157 virtual ~JSGlobalObject();
158
159 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
160 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&, bool& slotIsWriteable);
161 virtual void put(ExecState*, const Identifier&, JSValue*, PutPropertySlot&);
162 virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue* value, unsigned attributes);
163
164 virtual void defineGetter(ExecState*, const Identifier& propertyName, JSObject* getterFunc);
165 virtual void defineSetter(ExecState*, const Identifier& propertyName, JSObject* setterFunc);
166
167 // Linked list of all global objects that use the same JSGlobalData.
168 JSGlobalObject*& head() { return d()->globalData->head; }
169 JSGlobalObject* next() { return d()->next; }
170
171 // The following accessors return pristine values, even if a script
172 // replaces the global object's associated property.
173
174 RegExpConstructor* regExpConstructor() const { return d()->regExpConstructor; }
175
176 ErrorConstructor* errorConstructor() const { return d()->errorConstructor; }
177 NativeErrorConstructor* evalErrorConstructor() const { return d()->evalErrorConstructor; }
178 NativeErrorConstructor* rangeErrorConstructor() const { return d()->rangeErrorConstructor; }
179 NativeErrorConstructor* referenceErrorConstructor() const { return d()->referenceErrorConstructor; }
180 NativeErrorConstructor* syntaxErrorConstructor() const { return d()->syntaxErrorConstructor; }
181 NativeErrorConstructor* typeErrorConstructor() const { return d()->typeErrorConstructor; }
182 NativeErrorConstructor* URIErrorConstructor() const { return d()->URIErrorConstructor; }
183
184 GlobalEvalFunction* evalFunction() const { return d()->evalFunction; }
185
186 ObjectPrototype* objectPrototype() const { return d()->objectPrototype; }
187 FunctionPrototype* functionPrototype() const { return d()->functionPrototype; }
188 ArrayPrototype* arrayPrototype() const { return d()->arrayPrototype; }
189 BooleanPrototype* booleanPrototype() const { return d()->booleanPrototype; }
190 StringPrototype* stringPrototype() const { return d()->stringPrototype; }
191 NumberPrototype* numberPrototype() const { return d()->numberPrototype; }
192 DatePrototype* datePrototype() const { return d()->datePrototype; }
193 RegExpPrototype* regExpPrototype() const { return d()->regExpPrototype; }
194
195 StructureID* argumentsStructure() const { return d()->argumentsStructure.get(); }
196 StructureID* arrayStructure() const { return d()->arrayStructure.get(); }
197 StructureID* booleanObjectStructure() const { return d()->booleanObjectStructure.get(); }
198 StructureID* callbackConstructorStructure() const { return d()->callbackConstructorStructure.get(); }
199 StructureID* callbackFunctionStructure() const { return d()->callbackFunctionStructure.get(); }
200 StructureID* callbackObjectStructure() const { return d()->callbackObjectStructure.get(); }
201 StructureID* dateStructure() const { return d()->dateStructure.get(); }
202 StructureID* emptyObjectStructure() const { return d()->emptyObjectStructure.get(); }
203 StructureID* errorStructure() const { return d()->errorStructure.get(); }
204 StructureID* functionStructure() const { return d()->functionStructure.get(); }
205 StructureID* numberObjectStructure() const { return d()->numberObjectStructure.get(); }
206 StructureID* prototypeFunctionStructure() const { return d()->prototypeFunctionStructure.get(); }
207 StructureID* regExpMatchesArrayStructure() const { return d()->regExpMatchesArrayStructure.get(); }
208 StructureID* regExpStructure() const { return d()->regExpStructure.get(); }
209 StructureID* stringObjectStructure() const { return d()->stringObjectStructure.get(); }
210
211 void setProfileGroup(unsigned value) { d()->profileGroup = value; }
212 unsigned profileGroup() const { return d()->profileGroup; }
213
214 void setTimeoutTime(unsigned timeoutTime);
215 void startTimeoutCheck();
216 void stopTimeoutCheck();
217
218 Debugger* debugger() const { return d()->debugger; }
219 void setDebugger(Debugger* debugger) { d()->debugger = debugger; }
220
221 int recursion() { return d()->recursion; }
222 void incRecursion() { ++d()->recursion; }
223 void decRecursion() { --d()->recursion; }
224
225 ScopeChain& globalScopeChain() { return d()->globalScopeChain; }
226
227 virtual void mark();
228
229 virtual bool isGlobalObject() const { return true; }
230 virtual JSGlobalObject* toGlobalObject(ExecState*) const;
231
232 virtual ExecState* globalExec();
233
234 virtual bool shouldInterruptScript() const { return true; }
235
236 virtual bool allowsAccessFrom(const JSGlobalObject*) const { return true; }
237
238 virtual bool isDynamicScope() const;
239
240 HashSet<JSObject*>& arrayVisitedElements() { if (!d()->arrayVisitedElements) d()->arrayVisitedElements.set(new HashSet<JSObject*>); return *d()->arrayVisitedElements; }
241
242 HashSet<ProgramCodeBlock*>& codeBlocks() { return d()->codeBlocks; }
243
244 void copyGlobalsFrom(RegisterFile&);
245 void copyGlobalsTo(RegisterFile&);
246
247 void resetPrototype(JSValue* prototype);
248
249 JSGlobalData* globalData() { return d()->globalData.get(); }
250 JSGlobalObjectData* d() const { return static_cast<JSGlobalObjectData*>(JSVariableObject::d); }
251
252 protected:
253 struct GlobalPropertyInfo {
254 GlobalPropertyInfo(const Identifier& i, JSValue* v, unsigned a)
255 : identifier(i)
256 , value(v)
257 , attributes(a)
258 {
259 }
260
261 const Identifier identifier;
262 JSValue* value;
263 unsigned attributes;
264 };
265 void addStaticGlobals(GlobalPropertyInfo*, int count);
266
267 private:
268 // FIXME: Fold these functions into the constructor.
269 void init(JSObject* thisValue);
270 void reset(JSValue* prototype);
271
272 void* operator new(size_t); // can only be allocated with JSGlobalData
273 };
274
275 inline void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
276 {
277 size_t registerArraySize = d()->registerArraySize;
278 Register* registerArray = new Register[registerArraySize + count];
279 if (d()->registerArray)
280 memcpy(registerArray + count, d()->registerArray.get(), registerArraySize * sizeof(Register));
281 setRegisterArray(registerArray, registerArraySize + count);
282
283 for (int i = 0, index = -static_cast<int>(registerArraySize) - 1; i < count; ++i, --index) {
284 GlobalPropertyInfo& global = globals[i];
285 ASSERT(global.attributes & DontDelete);
286 SymbolTableEntry newEntry(index, global.attributes);
287 symbolTable().add(global.identifier.ustring().rep(), newEntry);
288 registerAt(index) = global.value;
289 }
290 }
291
292 inline bool JSGlobalObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
293 {
294 if (JSVariableObject::getOwnPropertySlot(exec, propertyName, slot))
295 return true;
296 return symbolTableGet(propertyName, slot);
297 }
298
299 inline bool JSGlobalObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
300 {
301 if (JSVariableObject::getOwnPropertySlotForWrite(exec, propertyName, slot, slotIsWriteable))
302 return true;
303 return symbolTableGet(propertyName, slot, slotIsWriteable);
304 }
305
306 inline JSGlobalObject* ScopeChainNode::globalObject() const
307 {
308 JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(bottom());
309 ASSERT(globalObject->isGlobalObject());
310 return globalObject;
311 }
312
313 inline JSValue* StructureID::prototypeForLookup(ExecState* exec)
314 {
315 if (m_type == ObjectType)
316 return m_prototype;
317
318 if (m_type == StringType)
319 return exec->lexicalGlobalObject()->stringPrototype();
320
321 ASSERT(m_type == NumberType);
322 return exec->lexicalGlobalObject()->numberPrototype();
323 }
324
325} // namespace JSC
326
327#endif // JSGlobalObject_h
Note: See TracBrowser for help on using the repository browser.