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