0
|
1 |
/*
|
|
2 |
* Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
|
|
3 |
* Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca)
|
|
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 "JSCallbackConstructor.h"
|
|
34 |
#include "JSCallbackFunction.h"
|
|
35 |
#include "JSCallbackObject.h"
|
|
36 |
|
|
37 |
#include "Arguments.h"
|
|
38 |
#include "ArrayConstructor.h"
|
|
39 |
#include "ArrayPrototype.h"
|
|
40 |
#include "BooleanConstructor.h"
|
|
41 |
#include "BooleanPrototype.h"
|
|
42 |
#include "CodeBlock.h"
|
|
43 |
#include "DateConstructor.h"
|
|
44 |
#include "DatePrototype.h"
|
|
45 |
#include "ErrorConstructor.h"
|
|
46 |
#include "ErrorPrototype.h"
|
|
47 |
#include "FunctionConstructor.h"
|
|
48 |
#include "FunctionPrototype.h"
|
|
49 |
#include "GlobalEvalFunction.h"
|
|
50 |
#include "JSFunction.h"
|
|
51 |
#include "JSGlobalObjectFunctions.h"
|
|
52 |
#include "JSLock.h"
|
|
53 |
#include "JSONObject.h"
|
|
54 |
#include "Interpreter.h"
|
|
55 |
#include "MathObject.h"
|
|
56 |
#include "NativeErrorConstructor.h"
|
|
57 |
#include "NativeErrorPrototype.h"
|
|
58 |
#include "NumberConstructor.h"
|
|
59 |
#include "NumberPrototype.h"
|
|
60 |
#include "ObjectConstructor.h"
|
|
61 |
#include "ObjectPrototype.h"
|
|
62 |
// QTPROD-235: pick up proper Profiler.h file
|
|
63 |
#include "profiler/Profiler.h"
|
|
64 |
#include "PrototypeFunction.h"
|
|
65 |
#include "RegExpConstructor.h"
|
|
66 |
#include "RegExpMatchesArray.h"
|
|
67 |
#include "RegExpObject.h"
|
|
68 |
#include "RegExpPrototype.h"
|
|
69 |
#include "ScopeChainMark.h"
|
|
70 |
#include "StringConstructor.h"
|
|
71 |
#include "StringPrototype.h"
|
|
72 |
#include "Debugger.h"
|
|
73 |
|
|
74 |
namespace JSC {
|
|
75 |
|
|
76 |
ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
|
|
77 |
|
|
78 |
// Default number of ticks before a timeout check should be done.
|
|
79 |
static const int initialTickCountThreshold = 255;
|
|
80 |
|
|
81 |
// Preferred number of milliseconds between each timeout check
|
|
82 |
static const int preferredScriptCheckTimeInterval = 1000;
|
|
83 |
|
|
84 |
static inline void markIfNeeded(MarkStack& markStack, JSValue v)
|
|
85 |
{
|
|
86 |
if (v)
|
|
87 |
markStack.append(v);
|
|
88 |
}
|
|
89 |
|
|
90 |
static inline void markIfNeeded(MarkStack& markStack, const RefPtr<Structure>& s)
|
|
91 |
{
|
|
92 |
if (s)
|
|
93 |
markIfNeeded(markStack, s->storedPrototype());
|
|
94 |
}
|
|
95 |
|
|
96 |
JSGlobalObject::~JSGlobalObject()
|
|
97 |
{
|
|
98 |
ASSERT(JSLock::currentThreadIsHoldingLock());
|
|
99 |
|
|
100 |
if (d()->debugger)
|
|
101 |
d()->debugger->detach(this);
|
|
102 |
|
|
103 |
Profiler** profiler = Profiler::enabledProfilerReference();
|
|
104 |
if (UNLIKELY(*profiler != 0)) {
|
|
105 |
(*profiler)->stopProfiling(globalExec(), UString());
|
|
106 |
}
|
|
107 |
|
|
108 |
d()->next->d()->prev = d()->prev;
|
|
109 |
d()->prev->d()->next = d()->next;
|
|
110 |
JSGlobalObject*& headObject = head();
|
|
111 |
if (headObject == this)
|
|
112 |
headObject = d()->next;
|
|
113 |
if (headObject == this)
|
|
114 |
headObject = 0;
|
|
115 |
|
|
116 |
HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end();
|
|
117 |
for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
|
|
118 |
(*it)->clearGlobalObject();
|
|
119 |
|
|
120 |
RegisterFile& registerFile = globalData()->interpreter->registerFile();
|
|
121 |
if (registerFile.globalObject() == this) {
|
|
122 |
registerFile.setGlobalObject(0);
|
|
123 |
registerFile.setNumGlobals(0);
|
|
124 |
}
|
|
125 |
d()->destructor(d());
|
|
126 |
}
|
|
127 |
|
|
128 |
void JSGlobalObject::init(JSObject* thisValue)
|
|
129 |
{
|
|
130 |
ASSERT(JSLock::currentThreadIsHoldingLock());
|
|
131 |
|
|
132 |
d()->globalData = Heap::heap(this)->globalData();
|
|
133 |
d()->globalScopeChain = ScopeChain(this, d()->globalData.get(), this, thisValue);
|
|
134 |
|
|
135 |
JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain.node(), CallFrame::noCaller(), 0, 0, 0);
|
|
136 |
|
|
137 |
if (JSGlobalObject*& headObject = head()) {
|
|
138 |
d()->prev = headObject;
|
|
139 |
d()->next = headObject->d()->next;
|
|
140 |
headObject->d()->next->d()->prev = this;
|
|
141 |
headObject->d()->next = this;
|
|
142 |
} else
|
|
143 |
headObject = d()->next = d()->prev = this;
|
|
144 |
|
|
145 |
d()->recursion = 0;
|
|
146 |
d()->debugger = 0;
|
|
147 |
|
|
148 |
d()->profileGroup = 0;
|
|
149 |
|
|
150 |
reset(prototype());
|
|
151 |
}
|
|
152 |
|
|
153 |
void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
|
|
154 |
{
|
|
155 |
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
|
|
156 |
|
|
157 |
if (symbolTablePut(propertyName, value))
|
|
158 |
return;
|
|
159 |
JSVariableObject::put(exec, propertyName, value, slot);
|
|
160 |
}
|
|
161 |
|
|
162 |
void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
|
|
163 |
{
|
|
164 |
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
|
|
165 |
|
|
166 |
if (symbolTablePutWithAttributes(propertyName, value, attributes))
|
|
167 |
return;
|
|
168 |
|
|
169 |
JSValue valueBefore = getDirect(propertyName);
|
|
170 |
PutPropertySlot slot;
|
|
171 |
JSVariableObject::put(exec, propertyName, value, slot);
|
|
172 |
if (!valueBefore) {
|
|
173 |
JSValue valueAfter = getDirect(propertyName);
|
|
174 |
if (valueAfter)
|
|
175 |
JSObject::putWithAttributes(exec, propertyName, valueAfter, attributes);
|
|
176 |
}
|
|
177 |
}
|
|
178 |
|
|
179 |
void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc, unsigned attributes)
|
|
180 |
{
|
|
181 |
PropertySlot slot;
|
|
182 |
if (!symbolTableGet(propertyName, slot))
|
|
183 |
JSVariableObject::defineGetter(exec, propertyName, getterFunc, attributes);
|
|
184 |
}
|
|
185 |
|
|
186 |
void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc, unsigned attributes)
|
|
187 |
{
|
|
188 |
PropertySlot slot;
|
|
189 |
if (!symbolTableGet(propertyName, slot))
|
|
190 |
JSVariableObject::defineSetter(exec, propertyName, setterFunc, attributes);
|
|
191 |
}
|
|
192 |
|
|
193 |
static inline JSObject* lastInPrototypeChain(JSObject* object)
|
|
194 |
{
|
|
195 |
JSObject* o = object;
|
|
196 |
while (o->prototype().isObject())
|
|
197 |
o = asObject(o->prototype());
|
|
198 |
return o;
|
|
199 |
}
|
|
200 |
|
|
201 |
void JSGlobalObject::reset(JSValue prototype)
|
|
202 |
{
|
|
203 |
ExecState* exec = JSGlobalObject::globalExec();
|
|
204 |
|
|
205 |
// Prototypes
|
|
206 |
|
|
207 |
d()->functionPrototype = new (exec) FunctionPrototype(exec, FunctionPrototype::createStructure(jsNull())); // The real prototype will be set once ObjectPrototype is created.
|
|
208 |
d()->prototypeFunctionStructure = PrototypeFunction::createStructure(d()->functionPrototype);
|
|
209 |
NativeFunctionWrapper* callFunction = 0;
|
|
210 |
NativeFunctionWrapper* applyFunction = 0;
|
|
211 |
d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get(), &callFunction, &applyFunction);
|
|
212 |
d()->callFunction = callFunction;
|
|
213 |
d()->applyFunction = applyFunction;
|
|
214 |
d()->objectPrototype = new (exec) ObjectPrototype(exec, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure.get());
|
|
215 |
d()->functionPrototype->structure()->setPrototypeWithoutTransition(d()->objectPrototype);
|
|
216 |
|
|
217 |
d()->emptyObjectStructure = d()->objectPrototype->inheritorID();
|
|
218 |
|
|
219 |
d()->functionStructure = JSFunction::createStructure(d()->functionPrototype);
|
|
220 |
d()->callbackFunctionStructure = JSCallbackFunction::createStructure(d()->functionPrototype);
|
|
221 |
d()->argumentsStructure = Arguments::createStructure(d()->objectPrototype);
|
|
222 |
d()->callbackConstructorStructure = JSCallbackConstructor::createStructure(d()->objectPrototype);
|
|
223 |
d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructure(d()->objectPrototype);
|
|
224 |
|
|
225 |
d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructure(d()->objectPrototype));
|
|
226 |
d()->arrayStructure = JSArray::createStructure(d()->arrayPrototype);
|
|
227 |
d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructure(d()->arrayPrototype);
|
|
228 |
|
|
229 |
d()->stringPrototype = new (exec) StringPrototype(exec, StringPrototype::createStructure(d()->objectPrototype));
|
|
230 |
d()->stringObjectStructure = StringObject::createStructure(d()->stringPrototype);
|
|
231 |
|
|
232 |
d()->booleanPrototype = new (exec) BooleanPrototype(exec, BooleanPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
|
|
233 |
d()->booleanObjectStructure = BooleanObject::createStructure(d()->booleanPrototype);
|
|
234 |
|
|
235 |
d()->numberPrototype = new (exec) NumberPrototype(exec, NumberPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
|
|
236 |
d()->numberObjectStructure = NumberObject::createStructure(d()->numberPrototype);
|
|
237 |
|
|
238 |
d()->datePrototype = new (exec) DatePrototype(exec, DatePrototype::createStructure(d()->objectPrototype));
|
|
239 |
d()->dateStructure = DateInstance::createStructure(d()->datePrototype);
|
|
240 |
|
|
241 |
d()->regExpPrototype = new (exec) RegExpPrototype(exec, RegExpPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
|
|
242 |
d()->regExpStructure = RegExpObject::createStructure(d()->regExpPrototype);
|
|
243 |
|
|
244 |
d()->methodCallDummy = constructEmptyObject(exec);
|
|
245 |
|
|
246 |
ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
|
|
247 |
d()->errorStructure = ErrorInstance::createStructure(errorPrototype);
|
|
248 |
|
|
249 |
RefPtr<Structure> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(errorPrototype);
|
|
250 |
|
|
251 |
NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError");
|
|
252 |
NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError");
|
|
253 |
NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError");
|
|
254 |
NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError");
|
|
255 |
NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError");
|
|
256 |
NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError");
|
|
257 |
|
|
258 |
// Constructors
|
|
259 |
|
|
260 |
JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get());
|
|
261 |
JSCell* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype);
|
|
262 |
JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype, d()->prototypeFunctionStructure.get());
|
|
263 |
JSCell* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
|
|
264 |
JSCell* booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructure(d()->functionPrototype), d()->booleanPrototype);
|
|
265 |
JSCell* numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructure(d()->functionPrototype), d()->numberPrototype);
|
|
266 |
JSCell* dateConstructor = new (exec) DateConstructor(exec, DateConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype);
|
|
267 |
|
|
268 |
d()->regExpConstructor = new (exec) RegExpConstructor(exec, RegExpConstructor::createStructure(d()->functionPrototype), d()->regExpPrototype);
|
|
269 |
|
|
270 |
d()->errorConstructor = new (exec) ErrorConstructor(exec, ErrorConstructor::createStructure(d()->functionPrototype), errorPrototype);
|
|
271 |
|
|
272 |
RefPtr<Structure> nativeErrorStructure = NativeErrorConstructor::createStructure(d()->functionPrototype);
|
|
273 |
|
|
274 |
d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype);
|
|
275 |
d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype);
|
|
276 |
d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype);
|
|
277 |
d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype);
|
|
278 |
d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype);
|
|
279 |
d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype);
|
|
280 |
|
|
281 |
d()->objectPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, objectConstructor, DontEnum);
|
|
282 |
d()->functionPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, functionConstructor, DontEnum);
|
|
283 |
d()->arrayPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, arrayConstructor, DontEnum);
|
|
284 |
d()->booleanPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, booleanConstructor, DontEnum);
|
|
285 |
d()->stringPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, stringConstructor, DontEnum);
|
|
286 |
d()->numberPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, numberConstructor, DontEnum);
|
|
287 |
d()->datePrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, dateConstructor, DontEnum);
|
|
288 |
d()->regExpPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
|
|
289 |
errorPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
|
|
290 |
|
|
291 |
evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
|
|
292 |
rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
|
|
293 |
referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
|
|
294 |
syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
|
|
295 |
typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
|
|
296 |
URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum);
|
|
297 |
|
|
298 |
// Set global constructors
|
|
299 |
|
|
300 |
// FIXME: These properties could be handled by a static hash table.
|
|
301 |
|
|
302 |
putDirectFunctionWithoutTransition(Identifier(exec, "Object"), objectConstructor, DontEnum);
|
|
303 |
putDirectFunctionWithoutTransition(Identifier(exec, "Function"), functionConstructor, DontEnum);
|
|
304 |
putDirectFunctionWithoutTransition(Identifier(exec, "Array"), arrayConstructor, DontEnum);
|
|
305 |
putDirectFunctionWithoutTransition(Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
|
|
306 |
putDirectFunctionWithoutTransition(Identifier(exec, "String"), stringConstructor, DontEnum);
|
|
307 |
putDirectFunctionWithoutTransition(Identifier(exec, "Number"), numberConstructor, DontEnum);
|
|
308 |
putDirectFunctionWithoutTransition(Identifier(exec, "Date"), dateConstructor, DontEnum);
|
|
309 |
putDirectFunctionWithoutTransition(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum);
|
|
310 |
putDirectFunctionWithoutTransition(Identifier(exec, "Error"), d()->errorConstructor, DontEnum);
|
|
311 |
putDirectFunctionWithoutTransition(Identifier(exec, "EvalError"), d()->evalErrorConstructor);
|
|
312 |
putDirectFunctionWithoutTransition(Identifier(exec, "RangeError"), d()->rangeErrorConstructor);
|
|
313 |
putDirectFunctionWithoutTransition(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor);
|
|
314 |
putDirectFunctionWithoutTransition(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor);
|
|
315 |
putDirectFunctionWithoutTransition(Identifier(exec, "TypeError"), d()->typeErrorConstructor);
|
|
316 |
putDirectFunctionWithoutTransition(Identifier(exec, "URIError"), d()->URIErrorConstructor);
|
|
317 |
|
|
318 |
// Set global values.
|
|
319 |
GlobalPropertyInfo staticGlobals[] = {
|
|
320 |
GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete),
|
|
321 |
GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
|
|
322 |
GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
|
|
323 |
GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete),
|
|
324 |
GlobalPropertyInfo(Identifier(exec, "JSON"), new (exec) JSONObject(JSONObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete)
|
|
325 |
};
|
|
326 |
|
|
327 |
addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
|
|
328 |
|
|
329 |
// Set global functions.
|
|
330 |
|
|
331 |
d()->evalFunction = new (exec) GlobalEvalFunction(exec, GlobalEvalFunction::createStructure(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this);
|
|
332 |
putDirectFunctionWithoutTransition(exec, d()->evalFunction, DontEnum);
|
|
333 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
|
|
334 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
|
|
335 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
|
|
336 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
|
|
337 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
|
|
338 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
|
|
339 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
|
|
340 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
|
|
341 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
|
|
342 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
|
|
343 |
#ifndef NDEBUG
|
|
344 |
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "jscprint"), globalFuncJSCPrint), DontEnum);
|
|
345 |
#endif
|
|
346 |
|
|
347 |
resetPrototype(prototype);
|
|
348 |
}
|
|
349 |
|
|
350 |
// Set prototype, and also insert the object prototype at the end of the chain.
|
|
351 |
void JSGlobalObject::resetPrototype(JSValue prototype)
|
|
352 |
{
|
|
353 |
setPrototype(prototype);
|
|
354 |
|
|
355 |
JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
|
|
356 |
JSObject* objectPrototype = d()->objectPrototype;
|
|
357 |
if (oldLastInPrototypeChain != objectPrototype)
|
|
358 |
oldLastInPrototypeChain->setPrototype(objectPrototype);
|
|
359 |
}
|
|
360 |
|
|
361 |
void JSGlobalObject::markChildren(MarkStack& markStack)
|
|
362 |
{
|
|
363 |
JSVariableObject::markChildren(markStack);
|
|
364 |
|
|
365 |
HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end();
|
|
366 |
for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
|
|
367 |
(*it)->markAggregate(markStack);
|
|
368 |
|
|
369 |
RegisterFile& registerFile = globalData()->interpreter->registerFile();
|
|
370 |
if (registerFile.globalObject() == this)
|
|
371 |
registerFile.markGlobals(markStack, &globalData()->heap);
|
|
372 |
|
|
373 |
markIfNeeded(markStack, d()->regExpConstructor);
|
|
374 |
markIfNeeded(markStack, d()->errorConstructor);
|
|
375 |
markIfNeeded(markStack, d()->evalErrorConstructor);
|
|
376 |
markIfNeeded(markStack, d()->rangeErrorConstructor);
|
|
377 |
markIfNeeded(markStack, d()->referenceErrorConstructor);
|
|
378 |
markIfNeeded(markStack, d()->syntaxErrorConstructor);
|
|
379 |
markIfNeeded(markStack, d()->typeErrorConstructor);
|
|
380 |
markIfNeeded(markStack, d()->URIErrorConstructor);
|
|
381 |
|
|
382 |
markIfNeeded(markStack, d()->evalFunction);
|
|
383 |
markIfNeeded(markStack, d()->callFunction);
|
|
384 |
markIfNeeded(markStack, d()->applyFunction);
|
|
385 |
|
|
386 |
markIfNeeded(markStack, d()->objectPrototype);
|
|
387 |
markIfNeeded(markStack, d()->functionPrototype);
|
|
388 |
markIfNeeded(markStack, d()->arrayPrototype);
|
|
389 |
markIfNeeded(markStack, d()->booleanPrototype);
|
|
390 |
markIfNeeded(markStack, d()->stringPrototype);
|
|
391 |
markIfNeeded(markStack, d()->numberPrototype);
|
|
392 |
markIfNeeded(markStack, d()->datePrototype);
|
|
393 |
markIfNeeded(markStack, d()->regExpPrototype);
|
|
394 |
|
|
395 |
markIfNeeded(markStack, d()->methodCallDummy);
|
|
396 |
|
|
397 |
markIfNeeded(markStack, d()->errorStructure);
|
|
398 |
markIfNeeded(markStack, d()->argumentsStructure);
|
|
399 |
markIfNeeded(markStack, d()->arrayStructure);
|
|
400 |
markIfNeeded(markStack, d()->booleanObjectStructure);
|
|
401 |
markIfNeeded(markStack, d()->callbackConstructorStructure);
|
|
402 |
markIfNeeded(markStack, d()->callbackFunctionStructure);
|
|
403 |
markIfNeeded(markStack, d()->callbackObjectStructure);
|
|
404 |
markIfNeeded(markStack, d()->dateStructure);
|
|
405 |
markIfNeeded(markStack, d()->emptyObjectStructure);
|
|
406 |
markIfNeeded(markStack, d()->errorStructure);
|
|
407 |
markIfNeeded(markStack, d()->functionStructure);
|
|
408 |
markIfNeeded(markStack, d()->numberObjectStructure);
|
|
409 |
markIfNeeded(markStack, d()->prototypeFunctionStructure);
|
|
410 |
markIfNeeded(markStack, d()->regExpMatchesArrayStructure);
|
|
411 |
markIfNeeded(markStack, d()->regExpStructure);
|
|
412 |
markIfNeeded(markStack, d()->stringObjectStructure);
|
|
413 |
|
|
414 |
// No need to mark the other structures, because their prototypes are all
|
|
415 |
// guaranteed to be referenced elsewhere.
|
|
416 |
|
|
417 |
Register* registerArray = d()->registerArray.get();
|
|
418 |
if (!registerArray)
|
|
419 |
return;
|
|
420 |
|
|
421 |
size_t size = d()->registerArraySize;
|
|
422 |
markStack.appendValues(reinterpret_cast<JSValue*>(registerArray), size);
|
|
423 |
}
|
|
424 |
|
|
425 |
ExecState* JSGlobalObject::globalExec()
|
|
426 |
{
|
|
427 |
return CallFrame::create(d()->globalCallFrame + RegisterFile::CallFrameHeaderSize);
|
|
428 |
}
|
|
429 |
|
|
430 |
bool JSGlobalObject::isDynamicScope() const
|
|
431 |
{
|
|
432 |
return true;
|
|
433 |
}
|
|
434 |
|
|
435 |
void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
|
|
436 |
{
|
|
437 |
ASSERT(!d()->registerArray);
|
|
438 |
ASSERT(!d()->registerArraySize);
|
|
439 |
|
|
440 |
int numGlobals = registerFile.numGlobals();
|
|
441 |
if (!numGlobals) {
|
|
442 |
d()->registers = 0;
|
|
443 |
return;
|
|
444 |
}
|
|
445 |
|
|
446 |
Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals);
|
|
447 |
setRegisters(registerArray + numGlobals, registerArray, numGlobals);
|
|
448 |
}
|
|
449 |
|
|
450 |
void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile)
|
|
451 |
{
|
|
452 |
JSGlobalObject* lastGlobalObject = registerFile.globalObject();
|
|
453 |
if (lastGlobalObject && lastGlobalObject != this)
|
|
454 |
lastGlobalObject->copyGlobalsFrom(registerFile);
|
|
455 |
|
|
456 |
registerFile.setGlobalObject(this);
|
|
457 |
registerFile.setNumGlobals(symbolTable().size());
|
|
458 |
|
|
459 |
if (d()->registerArray) {
|
|
460 |
memcpy(registerFile.start() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register));
|
|
461 |
setRegisters(registerFile.start(), 0, 0);
|
|
462 |
}
|
|
463 |
}
|
|
464 |
|
|
465 |
void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
|
|
466 |
{
|
|
467 |
return globalData->heap.allocate(size);
|
|
468 |
}
|
|
469 |
|
|
470 |
void JSGlobalObject::destroyJSGlobalObjectData(void* jsGlobalObjectData)
|
|
471 |
{
|
|
472 |
delete static_cast<JSGlobalObjectData*>(jsGlobalObjectData);
|
|
473 |
}
|
|
474 |
|
|
475 |
} // namespace JSC
|