Replace use of WTF::FixedArray with std::array
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
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 "Arguments.h"
34 #include "ArgumentsIteratorConstructor.h"
35 #include "ArgumentsIteratorPrototype.h"
36 #include "ArrayConstructor.h"
37 #include "ArrayIteratorConstructor.h"
38 #include "ArrayIteratorPrototype.h"
39 #include "ArrayPrototype.h"
40 #include "BooleanConstructor.h"
41 #include "BooleanPrototype.h"
42 #include "CodeBlock.h"
43 #include "CodeCache.h"
44 #include "DateConstructor.h"
45 #include "DatePrototype.h"
46 #include "Debugger.h"
47 #include "Error.h"
48 #include "ErrorConstructor.h"
49 #include "ErrorPrototype.h"
50 #include "FunctionConstructor.h"
51 #include "FunctionPrototype.h"
52 #include "GetterSetter.h"
53 #include "HeapIterationScope.h"
54 #include "Interpreter.h"
55 #include "JSAPIWrapperObject.h"
56 #include "JSActivation.h"
57 #include "JSArgumentsIterator.h"
58 #include "JSArrayBuffer.h"
59 #include "JSArrayBufferConstructor.h"
60 #include "JSArrayBufferPrototype.h"
61 #include "JSArrayIterator.h"
62 #include "JSBoundFunction.h"
63 #include "JSCallbackConstructor.h"
64 #include "JSCallbackFunction.h"
65 #include "JSCallbackObject.h"
66 #include "JSDataView.h"
67 #include "JSDataViewPrototype.h"
68 #include "JSFunction.h"
69 #include "JSGenericTypedArrayViewConstructorInlines.h"
70 #include "JSGenericTypedArrayViewInlines.h"
71 #include "JSGenericTypedArrayViewPrototypeInlines.h"
72 #include "JSGlobalObjectFunctions.h"
73 #include "JSLock.h"
74 #include "JSMap.h"
75 #include "JSMapIterator.h"
76 #include "JSNameScope.h"
77 #include "JSONObject.h"
78 #include "JSSet.h"
79 #include "JSSetIterator.h"
80 #include "JSTypedArrayConstructors.h"
81 #include "JSTypedArrayPrototypes.h"
82 #include "JSTypedArrays.h"
83 #include "JSWeakMap.h"
84 #include "JSWithScope.h"
85 #include "LegacyProfiler.h"
86 #include "Lookup.h"
87 #include "MapConstructor.h"
88 #include "MapIteratorConstructor.h"
89 #include "MapIteratorPrototype.h"
90 #include "MapPrototype.h"
91 #include "MathObject.h"
92 #include "NameConstructor.h"
93 #include "NameInstance.h"
94 #include "NamePrototype.h"
95 #include "NativeErrorConstructor.h"
96 #include "NativeErrorPrototype.h"
97 #include "NumberConstructor.h"
98 #include "NumberPrototype.h"
99 #include "ObjCCallbackFunction.h"
100 #include "ObjectConstructor.h"
101 #include "ObjectPrototype.h"
102 #include "Operations.h"
103 #include "ParserError.h"
104 #include "RegExpConstructor.h"
105 #include "RegExpMatchesArray.h"
106 #include "RegExpObject.h"
107 #include "RegExpPrototype.h"
108 #include "SetConstructor.h"
109 #include "SetIteratorConstructor.h"
110 #include "SetIteratorPrototype.h"
111 #include "SetPrototype.h"
112 #include "StrictEvalActivation.h"
113 #include "StringConstructor.h"
114 #include "StringPrototype.h"
115 #include "WeakMapConstructor.h"
116 #include "WeakMapPrototype.h"
117
118 #if ENABLE(PROMISES)
119 #include "JSPromise.h"
120 #include "JSPromiseCallback.h"
121 #include "JSPromiseConstructor.h"
122 #include "JSPromisePrototype.h"
123 #include "JSPromiseResolver.h"
124 #include "JSPromiseResolverConstructor.h"
125 #include "JSPromiseResolverPrototype.h"
126 #endif // ENABLE(PROMISES)
127
128 #if ENABLE(REMOTE_INSPECTOR)
129 #include "JSGlobalObjectDebuggable.h"
130 #include "RemoteInspector.h"
131 #endif
132
133 #include "JSGlobalObject.lut.h"
134
135 namespace JSC {
136
137 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
138
139 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0, &shouldInterruptScriptBeforeTimeout };
140
141 /* Source for JSGlobalObject.lut.h
142 @begin globalObjectTable
143   parseInt              globalFuncParseInt              DontEnum|Function 2
144   parseFloat            globalFuncParseFloat            DontEnum|Function 1
145   isNaN                 globalFuncIsNaN                 DontEnum|Function 1
146   isFinite              globalFuncIsFinite              DontEnum|Function 1
147   escape                globalFuncEscape                DontEnum|Function 1
148   unescape              globalFuncUnescape              DontEnum|Function 1
149   decodeURI             globalFuncDecodeURI             DontEnum|Function 1
150   decodeURIComponent    globalFuncDecodeURIComponent    DontEnum|Function 1
151   encodeURI             globalFuncEncodeURI             DontEnum|Function 1
152   encodeURIComponent    globalFuncEncodeURIComponent    DontEnum|Function 1
153 @end
154 */
155
156 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
157     : Base(vm, structure, 0)
158     , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
159     , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
160     , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
161     , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
162     , m_evalEnabled(true)
163     , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
164 {
165 }
166
167 JSGlobalObject::~JSGlobalObject()
168 {
169     if (m_debugger)
170         m_debugger->detach(this);
171
172     if (LegacyProfiler* profiler = vm().enabledProfiler())
173         profiler->stopProfiling(this);
174 }
175
176 void JSGlobalObject::destroy(JSCell* cell)
177 {
178     static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
179 }
180
181 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
182
183     m_globalThis.set(vm, this, globalThis);
184 }
185
186 void JSGlobalObject::init(JSObject* thisValue)
187 {
188     ASSERT(vm().currentThreadIsHoldingAPILock());
189
190     setGlobalThis(vm(), thisValue);
191     JSGlobalObject::globalExec()->init(0, 0, this, CallFrame::noCaller(), 0, 0);
192
193     m_debugger = 0;
194
195 #if ENABLE(REMOTE_INSPECTOR)
196     m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
197     m_inspectorDebuggable->init();
198     m_inspectorDebuggable->setRemoteDebuggingAllowed(true);
199 #endif
200
201     reset(prototype());
202 }
203
204 void JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
205 {
206     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
207     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
208
209     if (symbolTablePut(thisObject, exec, propertyName, value, slot.isStrictMode()))
210         return;
211     Base::put(thisObject, exec, propertyName, value, slot);
212 }
213
214 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
215 {
216     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
217     PropertySlot slot(thisObject);
218     // silently ignore attempts to add accessors aliasing vars.
219     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
220         return false;
221     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
222 }
223
224 JSGlobalObject::NewGlobalVar JSGlobalObject::addGlobalVar(const Identifier& ident, ConstantMode constantMode)
225 {
226     ConcurrentJITLocker locker(symbolTable()->m_lock);
227     int index = symbolTable()->size(locker);
228     SymbolTableEntry newEntry(index, (constantMode == IsConstant) ? ReadOnly : 0);
229     if (constantMode == IsVariable)
230         newEntry.prepareToWatch();
231     SymbolTable::Map::AddResult result = symbolTable()->add(locker, ident.impl(), newEntry);
232     if (result.isNewEntry)
233         addRegisters(1);
234     else
235         index = result.iterator->value.getIndex();
236     NewGlobalVar var;
237     var.registerNumber = index;
238     var.set = result.iterator->value.watchpointSet();
239     return var;
240 }
241
242 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName, JSValue value)
243 {
244     removeDirect(exec->vm(), propertyName); // Newly declared functions overwrite existing properties.
245     NewGlobalVar var = addGlobalVar(propertyName, IsVariable);
246     registerAt(var.registerNumber).set(exec->vm(), this, value);
247     if (var.set)
248         var.set->notifyWrite(value);
249 }
250
251 static inline JSObject* lastInPrototypeChain(JSObject* object)
252 {
253     JSObject* o = object;
254     while (o->prototype().isObject())
255         o = asObject(o->prototype());
256     return o;
257 }
258
259 void JSGlobalObject::reset(JSValue prototype)
260 {
261     ExecState* exec = JSGlobalObject::globalExec();
262     VM& vm = exec->vm();
263
264     m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
265     m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
266     m_boundFunctionStructure.set(vm, this, JSBoundFunction::createStructure(vm, this, m_functionPrototype.get()));
267     m_namedFunctionStructure.set(vm, this, Structure::addPropertyTransition(vm, m_functionStructure.get(), vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, 0, m_functionNameOffset));
268     m_internalFunctionStructure.set(vm, this, InternalFunction::createStructure(vm, this, m_functionPrototype.get()));
269     JSFunction* callFunction = 0;
270     JSFunction* applyFunction = 0;
271     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction);
272     m_callFunction.set(vm, this, callFunction);
273     m_applyFunction.set(vm, this, applyFunction);
274     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
275     GetterSetter* protoAccessor = GetterSetter::create(vm);
276     protoAccessor->setGetter(vm, JSFunction::create(vm, this, 0, String(), globalFuncProtoGetter));
277     protoAccessor->setSetter(vm, JSFunction::create(vm, this, 0, String(), globalFuncProtoSetter));
278     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
279     m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
280     
281     m_typedArrays[toIndex(TypeInt8)].prototype.set(vm, this, JSInt8ArrayPrototype::create(vm, this, JSInt8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
282     m_typedArrays[toIndex(TypeInt16)].prototype.set(vm, this, JSInt16ArrayPrototype::create(vm, this, JSInt16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
283     m_typedArrays[toIndex(TypeInt32)].prototype.set(vm, this, JSInt32ArrayPrototype::create(vm, this, JSInt32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
284     m_typedArrays[toIndex(TypeUint8)].prototype.set(vm, this, JSUint8ArrayPrototype::create(vm, this, JSUint8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
285     m_typedArrays[toIndex(TypeUint8Clamped)].prototype.set(vm, this, JSUint8ClampedArrayPrototype::create(vm, this, JSUint8ClampedArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
286     m_typedArrays[toIndex(TypeUint16)].prototype.set(vm, this, JSUint16ArrayPrototype::create(vm, this, JSUint16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
287     m_typedArrays[toIndex(TypeUint32)].prototype.set(vm, this, JSUint32ArrayPrototype::create(vm, this, JSUint32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
288     m_typedArrays[toIndex(TypeFloat32)].prototype.set(vm, this, JSFloat32ArrayPrototype::create(vm, this, JSFloat32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
289     m_typedArrays[toIndex(TypeFloat64)].prototype.set(vm, this, JSFloat64ArrayPrototype::create(vm, this, JSFloat64ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
290     m_typedArrays[toIndex(TypeDataView)].prototype.set(vm, this, JSDataViewPrototype::create(vm, JSDataViewPrototype::createStructure(vm, this, m_objectPrototype.get())));
291     
292     m_typedArrays[toIndex(TypeInt8)].structure.set(vm, this, JSInt8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt8)].prototype.get()));
293     m_typedArrays[toIndex(TypeInt16)].structure.set(vm, this, JSInt16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt16)].prototype.get()));
294     m_typedArrays[toIndex(TypeInt32)].structure.set(vm, this, JSInt32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt32)].prototype.get()));
295     m_typedArrays[toIndex(TypeUint8)].structure.set(vm, this, JSUint8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8)].prototype.get()));
296     m_typedArrays[toIndex(TypeUint8Clamped)].structure.set(vm, this, JSUint8ClampedArray::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get()));
297     m_typedArrays[toIndex(TypeUint16)].structure.set(vm, this, JSUint16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint16)].prototype.get()));
298     m_typedArrays[toIndex(TypeUint32)].structure.set(vm, this, JSUint32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint32)].prototype.get()));
299     m_typedArrays[toIndex(TypeFloat32)].structure.set(vm, this, JSFloat32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat32)].prototype.get()));
300     m_typedArrays[toIndex(TypeFloat64)].structure.set(vm, this, JSFloat64Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat64)].prototype.get()));
301     m_typedArrays[toIndex(TypeDataView)].structure.set(vm, this, JSDataView::createStructure(vm, this, m_typedArrays[toIndex(TypeDataView)].prototype.get()));
302
303     m_nameScopeStructure.set(vm, this, JSNameScope::createStructure(vm, this, jsNull()));
304     m_activationStructure.set(vm, this, JSActivation::createStructure(vm, this, jsNull()));
305     m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
306     m_withScopeStructure.set(vm, this, JSWithScope::createStructure(vm, this, jsNull()));
307
308     m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
309
310     m_callbackFunctionStructure.set(vm, this, JSCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
311     m_argumentsStructure.set(vm, this, Arguments::createStructure(vm, this, m_objectPrototype.get()));
312     m_callbackConstructorStructure.set(vm, this, JSCallbackConstructor::createStructure(vm, this, m_objectPrototype.get()));
313     m_callbackObjectStructure.set(vm, this, JSCallbackObject<JSDestructibleObject>::createStructure(vm, this, m_objectPrototype.get()));
314 #if JSC_OBJC_API_ENABLED
315     m_objcCallbackFunctionStructure.set(vm, this, ObjCCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
316     m_objcWrapperObjectStructure.set(vm, this, JSCallbackObject<JSAPIWrapperObject>::createStructure(vm, this, m_objectPrototype.get()));
317 #endif
318
319     m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
320     
321     m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
322     m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
323     m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
324     m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
325     m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
326     m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
327     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
328         m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
329     
330     m_regExpMatchesArrayStructure.set(vm, this, RegExpMatchesArray::createStructure(vm, this, m_arrayPrototype.get()));
331
332     RegExp* emptyRegex = RegExp::create(vm, "", NoFlags);
333     
334     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex));
335     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
336
337 #if ENABLE(PROMISES)
338     m_promisePrototype.set(vm, this, JSPromisePrototype::create(exec, this, JSPromisePrototype::createStructure(vm, this, m_objectPrototype.get())));
339     m_promiseStructure.set(vm, this, JSPromise::createStructure(vm, this, m_promisePrototype.get()));
340
341     m_promiseResolverPrototype.set(vm, this, JSPromiseResolverPrototype::create(exec, this, JSPromiseResolverPrototype::createStructure(vm, this, m_objectPrototype.get())));
342     m_promiseResolverStructure.set(vm, this, JSPromiseResolver::createStructure(vm, this, m_promiseResolverPrototype.get()));
343     m_promiseCallbackStructure.set(vm, this, JSPromiseCallback::createStructure(vm, this, m_functionPrototype.get()));
344     m_promiseWrapperCallbackStructure.set(vm, this, JSPromiseWrapperCallback::createStructure(vm, this, m_functionPrototype.get()));
345 #endif // ENABLE(PROMISES)
346
347 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
348     m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_objectPrototype.get()))); \
349     m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
350
351     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
352
353 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
354
355     // Constructors
356
357     JSCell* objectConstructor = ObjectConstructor::create(vm, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
358     JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
359     JSCell* arrayConstructor = ArrayConstructor::create(vm, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get());
360
361 #if ENABLE(PROMISES)
362     JSCell* promiseConstructor = JSPromiseConstructor::create(vm, JSPromiseConstructor::createStructure(vm, this, m_functionPrototype.get()), m_promisePrototype.get());
363     JSCell* promiseResolverConstructor = JSPromiseResolverConstructor::create(vm, JSPromiseResolverConstructor::createStructure(vm, this, m_functionPrototype.get()), m_promiseResolverPrototype.get());
364 #endif // ENABLE(PROMISES)
365
366     m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get()));
367
368 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
369     capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get()); \
370     m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \
371
372     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
373
374 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
375
376     m_errorConstructor.set(vm, this, errorConstructor);
377
378     Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get());
379     Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get());
380     m_evalErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("EvalError")));
381     m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("RangeError")));
382     m_referenceErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("ReferenceError")));
383     m_syntaxErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("SyntaxError")));
384     m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("TypeError")));
385     m_URIErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("URIError")));
386
387     m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum);
388     m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum);
389     m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, DontEnum);
390     m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum);
391 #if ENABLE(PROMISES)
392     m_promisePrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, promiseConstructor, DontEnum);
393     m_promiseResolverPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, promiseResolverConstructor, DontEnum);
394 #endif
395
396     putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum);
397     putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum);
398     putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum);
399     putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum);
400     putDirectWithoutTransition(vm, vm.propertyNames->EvalError, m_evalErrorConstructor.get(), DontEnum);
401     putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum);
402     putDirectWithoutTransition(vm, vm.propertyNames->ReferenceError, m_referenceErrorConstructor.get(), DontEnum);
403     putDirectWithoutTransition(vm, vm.propertyNames->SyntaxError, m_syntaxErrorConstructor.get(), DontEnum);
404     putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum);
405     putDirectWithoutTransition(vm, vm.propertyNames->URIError, m_URIErrorConstructor.get(), DontEnum);
406 #if ENABLE(PROMISES)
407     putDirectWithoutTransition(vm, vm.propertyNames->Promise, promiseConstructor, DontEnum);
408     putDirectWithoutTransition(vm, vm.propertyNames->PromiseResolver, promiseResolverConstructor, DontEnum);
409 #endif
410
411
412 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
413     putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \
414
415     FOR_EACH_SIMPLE_BUILTIN_TYPE(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
416
417 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
418     PrototypeMap& prototypeMap = vm.prototypeMap;
419     Structure* iteratorResultStructure = prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity());
420     PropertyOffset offset;
421     iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->done, 0, 0, offset);
422     iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->value, 0, 0, offset);
423     m_iteratorResultStructure.set(vm, this, iteratorResultStructure);
424
425     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
426     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
427
428     putDirectWithoutTransition(vm, vm.propertyNames->JSON, JSONObject::create(vm, JSONObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
429     putDirectWithoutTransition(vm, vm.propertyNames->Math, MathObject::create(vm, this, MathObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
430     
431     std::array<InternalFunction*, NUMBER_OF_TYPED_ARRAY_TYPES> typedArrayConstructors;
432     typedArrayConstructors[toIndex(TypeInt8)] = JSInt8ArrayConstructor::create(vm, JSInt8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt8)].prototype.get(), "Int8Array");
433     typedArrayConstructors[toIndex(TypeInt16)] = JSInt16ArrayConstructor::create(vm, JSInt16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt16)].prototype.get(), "Int16Array");
434     typedArrayConstructors[toIndex(TypeInt32)] = JSInt32ArrayConstructor::create(vm, JSInt32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt32)].prototype.get(), "Int32Array");
435     typedArrayConstructors[toIndex(TypeUint8)] = JSUint8ArrayConstructor::create(vm, JSUint8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8)].prototype.get(), "Uint8Array");
436     typedArrayConstructors[toIndex(TypeUint8Clamped)] = JSUint8ClampedArrayConstructor::create(vm, JSUint8ClampedArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get(), "Uint8ClampedArray");
437     typedArrayConstructors[toIndex(TypeUint16)] = JSUint16ArrayConstructor::create(vm, JSUint16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint16)].prototype.get(), "Uint16Array");
438     typedArrayConstructors[toIndex(TypeUint32)] = JSUint32ArrayConstructor::create(vm, JSUint32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint32)].prototype.get(), "Uint32Array");
439     typedArrayConstructors[toIndex(TypeFloat32)] = JSFloat32ArrayConstructor::create(vm, JSFloat32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat32)].prototype.get(), "Float32Array");
440     typedArrayConstructors[toIndex(TypeFloat64)] = JSFloat64ArrayConstructor::create(vm, JSFloat64ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat64)].prototype.get(), "Float64Array");
441     typedArrayConstructors[toIndex(TypeDataView)] = JSDataViewConstructor::create(vm, JSDataViewConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeDataView)].prototype.get(), "DataView");
442
443     for (unsigned typedArrayIndex = NUMBER_OF_TYPED_ARRAY_TYPES; typedArrayIndex--;) {
444         m_typedArrays[typedArrayIndex].prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, typedArrayConstructors[typedArrayIndex], DontEnum);
445         putDirectWithoutTransition(vm, Identifier(exec, typedArrayConstructors[typedArrayIndex]->name(exec)), typedArrayConstructors[typedArrayIndex], DontEnum);
446     }
447
448     GlobalPropertyInfo staticGlobals[] = {
449         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
450         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
451         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly)
452     };
453     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
454     
455     m_specialPointers[Special::CallFunction] = m_callFunction.get();
456     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
457     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
458     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
459
460     if (m_experimentsEnabled) {
461         NamePrototype* privateNamePrototype = NamePrototype::create(exec, NamePrototype::createStructure(vm, this, m_objectPrototype.get()));
462         m_privateNameStructure.set(vm, this, NameInstance::createStructure(vm, this, privateNamePrototype));
463
464         JSCell* privateNameConstructor = NameConstructor::create(vm, NameConstructor::createStructure(vm, this, m_functionPrototype.get()), privateNamePrototype);
465         privateNamePrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, privateNameConstructor, DontEnum);
466         putDirectWithoutTransition(vm, Identifier(exec, "Name"), privateNameConstructor, DontEnum);
467     }
468
469     resetPrototype(vm, prototype);
470 }
471
472 // Private namespace for helpers for JSGlobalObject::haveABadTime()
473 namespace {
474
475 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
476 public:
477     ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
478     void operator()(JSCell*);
479
480 private:
481     MarkedArgumentBuffer& m_foundObjects;
482     JSGlobalObject* m_globalObject;
483 };
484
485 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
486     MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
487     : m_foundObjects(foundObjects)
488     , m_globalObject(globalObject)
489 {
490 }
491
492 inline bool hasBrokenIndexing(JSObject* object)
493 {
494     // This will change if we have more indexing types.
495     IndexingType type = object->structure()->indexingType();
496     // This could be made obviously more efficient, but isn't made so right now, because
497     // we expect this to be an unlikely slow path anyway.
498     return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasFastArrayStorage(type);
499 }
500
501 void ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell)
502 {
503     if (!cell->isObject())
504         return;
505     
506     JSObject* object = asObject(cell);
507
508     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
509     if (!hasBrokenIndexing(object))
510         return;
511     
512     // We only want to have a bad time in the affected global object, not in the entire
513     // VM. But we have to be careful, since there may be objects that claim to belong to
514     // a different global object that have prototypes from our global object.
515     bool foundGlobalObject = false;
516     for (JSObject* current = object; ;) {
517         if (current->globalObject() == m_globalObject) {
518             foundGlobalObject = true;
519             break;
520         }
521         
522         JSValue prototypeValue = current->prototype();
523         if (prototypeValue.isNull())
524             break;
525         current = asObject(prototypeValue);
526     }
527     if (!foundGlobalObject)
528         return;
529     
530     m_foundObjects.append(object);
531 }
532
533 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
534
535 void JSGlobalObject::haveABadTime(VM& vm)
536 {
537     ASSERT(&vm == &this->vm());
538     
539     if (isHavingABadTime())
540         return;
541     
542     // Make sure that all allocations or indexed storage transitions that are inlining
543     // the assumption that it's safe to transition to a non-SlowPut array storage don't
544     // do so anymore.
545     m_havingABadTimeWatchpoint->fireAll();
546     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
547     
548     // Make sure that all JSArray allocations that load the appropriate structure from
549     // this object now load a structure that uses SlowPut.
550     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
551         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
552     
553     // Make sure that all objects that have indexed storage switch to the slow kind of
554     // indexed storage.
555     MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
556     ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
557     {
558         HeapIterationScope iterationScope(vm.heap);
559         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
560     }
561     while (!foundObjects.isEmpty()) {
562         JSObject* object = asObject(foundObjects.last());
563         foundObjects.removeLast();
564         ASSERT(hasBrokenIndexing(object));
565         object->switchToSlowPutArrayStorage(vm);
566     }
567 }
568
569 bool JSGlobalObject::objectPrototypeIsSane()
570 {
571     return !hasIndexedProperties(m_objectPrototype->structure()->indexingType())
572         && m_objectPrototype->prototype().isNull();
573 }
574
575 bool JSGlobalObject::arrayPrototypeChainIsSane()
576 {
577     return !hasIndexedProperties(m_arrayPrototype->structure()->indexingType())
578         && m_arrayPrototype->prototype() == m_objectPrototype.get()
579         && objectPrototypeIsSane();
580 }
581
582 bool JSGlobalObject::stringPrototypeChainIsSane()
583 {
584     return !hasIndexedProperties(m_stringPrototype->structure()->indexingType())
585         && m_stringPrototype->prototype() == m_objectPrototype.get()
586         && objectPrototypeIsSane();
587 }
588
589 void JSGlobalObject::createThrowTypeError(VM& vm)
590 {
591     JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
592     GetterSetter* getterSetter = GetterSetter::create(vm);
593     getterSetter->setGetter(vm, thrower);
594     getterSetter->setSetter(vm, thrower);
595     m_throwTypeErrorGetterSetter.set(vm, this, getterSetter);
596 }
597
598 // Set prototype, and also insert the object prototype at the end of the chain.
599 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
600 {
601     setPrototype(vm, prototype);
602
603     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
604     JSObject* objectPrototype = m_objectPrototype.get();
605     if (oldLastInPrototypeChain != objectPrototype)
606         oldLastInPrototypeChain->setPrototype(vm, objectPrototype);
607 }
608
609 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
610
611     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
612     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
613     COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
614     ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
615     Base::visitChildren(thisObject, visitor);
616
617     visitor.append(&thisObject->m_globalThis);
618
619     visitor.append(&thisObject->m_regExpConstructor);
620     visitor.append(&thisObject->m_errorConstructor);
621     visitor.append(&thisObject->m_evalErrorConstructor);
622     visitor.append(&thisObject->m_rangeErrorConstructor);
623     visitor.append(&thisObject->m_referenceErrorConstructor);
624     visitor.append(&thisObject->m_syntaxErrorConstructor);
625     visitor.append(&thisObject->m_typeErrorConstructor);
626     visitor.append(&thisObject->m_URIErrorConstructor);
627
628     visitor.append(&thisObject->m_evalFunction);
629     visitor.append(&thisObject->m_callFunction);
630     visitor.append(&thisObject->m_applyFunction);
631     visitor.append(&thisObject->m_throwTypeErrorGetterSetter);
632
633     visitor.append(&thisObject->m_objectPrototype);
634     visitor.append(&thisObject->m_functionPrototype);
635     visitor.append(&thisObject->m_arrayPrototype);
636     visitor.append(&thisObject->m_errorPrototype);
637 #if ENABLE(PROMISES)
638     visitor.append(&thisObject->m_promisePrototype);
639     visitor.append(&thisObject->m_promiseResolverPrototype);
640 #endif
641
642     visitor.append(&thisObject->m_withScopeStructure);
643     visitor.append(&thisObject->m_strictEvalActivationStructure);
644     visitor.append(&thisObject->m_activationStructure);
645     visitor.append(&thisObject->m_nameScopeStructure);
646     visitor.append(&thisObject->m_argumentsStructure);
647     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
648         visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
649     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
650         visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
651     visitor.append(&thisObject->m_booleanObjectStructure);
652     visitor.append(&thisObject->m_callbackConstructorStructure);
653     visitor.append(&thisObject->m_callbackFunctionStructure);
654     visitor.append(&thisObject->m_callbackObjectStructure);
655 #if JSC_OBJC_API_ENABLED
656     visitor.append(&thisObject->m_objcCallbackFunctionStructure);
657     visitor.append(&thisObject->m_objcWrapperObjectStructure);
658 #endif
659     visitor.append(&thisObject->m_nullPrototypeObjectStructure);
660     visitor.append(&thisObject->m_errorStructure);
661     visitor.append(&thisObject->m_functionStructure);
662     visitor.append(&thisObject->m_boundFunctionStructure);
663     visitor.append(&thisObject->m_namedFunctionStructure);
664     visitor.append(&thisObject->m_privateNameStructure);
665     visitor.append(&thisObject->m_regExpMatchesArrayStructure);
666     visitor.append(&thisObject->m_regExpStructure);
667     visitor.append(&thisObject->m_internalFunctionStructure);
668
669 #if ENABLE(PROMISES)
670     visitor.append(&thisObject->m_promiseStructure);
671     visitor.append(&thisObject->m_promiseResolverStructure);
672     visitor.append(&thisObject->m_promiseCallbackStructure);
673     visitor.append(&thisObject->m_promiseWrapperCallbackStructure);
674 #endif // ENABLE(PROMISES)
675
676 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
677     visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
678     visitor.append(&thisObject->m_ ## properName ## Structure); \
679
680     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
681
682 #undef VISIT_SIMPLE_TYPE
683
684     for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;) {
685         visitor.append(&thisObject->m_typedArrays[i].prototype);
686         visitor.append(&thisObject->m_typedArrays[i].structure);
687     }
688 }
689
690 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
691 {
692     if (ecmaMode == StrictMode)
693         return jsUndefined();
694     return exec->globalThisValue();
695 }
696
697 ExecState* JSGlobalObject::globalExec()
698 {
699     return CallFrame::create(m_globalCallFrame);
700 }
701
702 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
703 {
704     addRegisters(count);
705
706     for (int i = 0; i < count; ++i) {
707         GlobalPropertyInfo& global = globals[i];
708         ASSERT(global.attributes & DontDelete);
709         
710         int index = symbolTable()->size();
711         SymbolTableEntry newEntry(index, global.attributes);
712         symbolTable()->add(global.identifier.impl(), newEntry);
713         registerAt(index).set(vm(), this, global.value);
714     }
715 }
716
717 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
718 {
719     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
720     if (getStaticFunctionSlot<Base>(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, slot))
721         return true;
722     return symbolTableGet(thisObject, propertyName, slot);
723 }
724
725 void JSGlobalObject::clearRareData(JSCell* cell)
726 {
727     jsCast<JSGlobalObject*>(cell)->m_rareData.clear();
728 }
729
730 void slowValidateCell(JSGlobalObject* globalObject)
731 {
732     RELEASE_ASSERT(globalObject->isGlobalObject());
733     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
734 }
735
736 UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
737 {
738     ParserError error;
739     JSParserStrictness strictness = executable->isStrictMode() ? JSParseStrict : JSParseNormal;
740     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
741     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
742     UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock(vm(), executable, executable->source(), strictness, debuggerMode, profilerMode, error);
743
744     if (hasDebugger())
745         debugger()->sourceParsed(callFrame, executable->source().provider(), error.m_line, error.m_message);
746
747     if (error.m_type != ParserError::ErrorNone) {
748         *exception = error.toErrorObject(this, executable->source());
749         return 0;
750     }
751     
752     return unlinkedCodeBlock;
753 }
754
755 UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable)
756 {
757     ParserError error;
758     JSParserStrictness strictness = executable->isStrictMode() ? JSParseStrict : JSParseNormal;
759     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
760     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
761     UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock(vm(), executable, executable->source(), strictness, debuggerMode, profilerMode, error);
762
763     if (hasDebugger())
764         debugger()->sourceParsed(callFrame, executable->source().provider(), error.m_line, error.m_message);
765
766     if (error.m_type != ParserError::ErrorNone) {
767         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
768         return 0;
769     }
770
771     return unlinkedCodeBlock;
772 }
773
774 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
775 {
776 #if ENABLE(REMOTE_INSPECTOR)
777     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
778 #else
779     UNUSED_PARAM(enabled);
780 #endif
781 }
782
783 bool JSGlobalObject::remoteDebuggingEnabled() const
784 {
785 #if ENABLE(REMOTE_INSPECTOR)
786     return m_inspectorDebuggable->remoteDebuggingAllowed();
787 #else
788     return false;
789 #endif
790 }
791
792 void JSGlobalObject::setName(const String& name)
793 {
794     m_name = name;
795
796 #if ENABLE(REMOTE_INSPECTOR)
797     m_inspectorDebuggable->update();
798 #endif
799 }
800
801 } // namespace JSC