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