]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/JSGlobalObject.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / JSGlobalObject.cpp
CommitLineData
9dae56ea 1/*
ed1e77d3 2 * Copyright (C) 2007, 2008, 2009, 2014, 2015 Apple Inc. All rights reserved.
9dae56ea
A
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
81345200 10 * notice, this list of conditions and the following disclaimer.
9dae56ea
A
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
81345200
A
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
9dae56ea 15 * its contributors may be used to endorse or promote products derived
81345200 16 * from this software without specific prior written permission.
9dae56ea
A
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
9dae56ea 33#include "ArrayConstructor.h"
81345200 34#include "ArrayIteratorPrototype.h"
9dae56ea
A
35#include "ArrayPrototype.h"
36#include "BooleanConstructor.h"
37#include "BooleanPrototype.h"
ed1e77d3
A
38#include "BuiltinNames.h"
39#include "ClonedArguments.h"
9dae56ea 40#include "CodeBlock.h"
93a37866 41#include "CodeCache.h"
81345200 42#include "ConsolePrototype.h"
9dae56ea
A
43#include "DateConstructor.h"
44#include "DatePrototype.h"
93a37866 45#include "Debugger.h"
ed1e77d3
A
46#include "DebuggerScope.h"
47#include "DirectArguments.h"
6fe7ccc8 48#include "Error.h"
9dae56ea
A
49#include "ErrorConstructor.h"
50#include "ErrorPrototype.h"
51#include "FunctionConstructor.h"
52#include "FunctionPrototype.h"
6fe7ccc8 53#include "GetterSetter.h"
81345200 54#include "HeapIterationScope.h"
93a37866 55#include "Interpreter.h"
ed1e77d3 56#include "IteratorPrototype.h"
93a37866 57#include "JSAPIWrapperObject.h"
81345200
A
58#include "JSArrayBuffer.h"
59#include "JSArrayBufferConstructor.h"
60#include "JSArrayBufferPrototype.h"
61#include "JSArrayIterator.h"
6fe7ccc8 62#include "JSBoundFunction.h"
81345200 63#include "JSCInlines.h"
93a37866
A
64#include "JSCallbackConstructor.h"
65#include "JSCallbackFunction.h"
66#include "JSCallbackObject.h"
ed1e77d3 67#include "JSCatchScope.h"
81345200
A
68#include "JSConsole.h"
69#include "JSDataView.h"
70#include "JSDataViewPrototype.h"
ed1e77d3
A
71#include "JSDollarVM.h"
72#include "JSDollarVMPrototype.h"
ba379fdc 73#include "JSFunction.h"
ed1e77d3 74#include "JSFunctionNameScope.h"
81345200
A
75#include "JSGenericTypedArrayViewConstructorInlines.h"
76#include "JSGenericTypedArrayViewInlines.h"
77#include "JSGenericTypedArrayViewPrototypeInlines.h"
9dae56ea 78#include "JSGlobalObjectFunctions.h"
ed1e77d3
A
79#include "JSJob.h"
80#include "JSLexicalEnvironment.h"
9dae56ea 81#include "JSLock.h"
81345200
A
82#include "JSMap.h"
83#include "JSMapIterator.h"
ba379fdc 84#include "JSONObject.h"
81345200
A
85#include "JSSet.h"
86#include "JSSetIterator.h"
ed1e77d3
A
87#include "JSStringIterator.h"
88#include "JSTemplateRegistryKey.h"
81345200
A
89#include "JSTypedArrayConstructors.h"
90#include "JSTypedArrayPrototypes.h"
91#include "JSTypedArrays.h"
92#include "JSWeakMap.h"
ed1e77d3 93#include "JSWeakSet.h"
93a37866
A
94#include "JSWithScope.h"
95#include "LegacyProfiler.h"
14957cd0 96#include "Lookup.h"
81345200 97#include "MapConstructor.h"
81345200
A
98#include "MapIteratorPrototype.h"
99#include "MapPrototype.h"
9dae56ea 100#include "MathObject.h"
81345200 101#include "Microtask.h"
9dae56ea
A
102#include "NativeErrorConstructor.h"
103#include "NativeErrorPrototype.h"
ed1e77d3
A
104#include "NullGetterFunction.h"
105#include "NullSetterFunction.h"
9dae56ea
A
106#include "NumberConstructor.h"
107#include "NumberPrototype.h"
93a37866 108#include "ObjCCallbackFunction.h"
9dae56ea
A
109#include "ObjectConstructor.h"
110#include "ObjectPrototype.h"
93a37866 111#include "ParserError.h"
9dae56ea
A
112#include "RegExpConstructor.h"
113#include "RegExpMatchesArray.h"
114#include "RegExpObject.h"
115#include "RegExpPrototype.h"
ed1e77d3 116#include "ScopedArguments.h"
81345200 117#include "SetConstructor.h"
81345200
A
118#include "SetIteratorPrototype.h"
119#include "SetPrototype.h"
93a37866 120#include "StrictEvalActivation.h"
9dae56ea 121#include "StringConstructor.h"
ed1e77d3 122#include "StringIteratorPrototype.h"
9dae56ea 123#include "StringPrototype.h"
ed1e77d3
A
124#include "Symbol.h"
125#include "SymbolConstructor.h"
126#include "SymbolPrototype.h"
127#include "VariableWriteFireDetail.h"
128#include "WeakGCMapInlines.h"
81345200
A
129#include "WeakMapConstructor.h"
130#include "WeakMapPrototype.h"
ed1e77d3
A
131#include "WeakSetConstructor.h"
132#include "WeakSetPrototype.h"
133
134#if ENABLE(INTL)
135#include "IntlObject.h"
136#endif // ENABLE(INTL)
81345200
A
137
138#if ENABLE(PROMISES)
139#include "JSPromise.h"
140#include "JSPromiseConstructor.h"
141#include "JSPromisePrototype.h"
142#endif // ENABLE(PROMISES)
143
144#if ENABLE(REMOTE_INSPECTOR)
145#include "JSGlobalObjectDebuggable.h"
146#include "JSGlobalObjectInspectorController.h"
147#endif
148
149#if ENABLE(WEB_REPLAY)
150#include "EmptyInputCursor.h"
151#include "JSReplayInputs.h"
152#endif
9dae56ea 153
14957cd0
A
154#include "JSGlobalObject.lut.h"
155
9dae56ea
A
156namespace JSC {
157
ed1e77d3 158const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
6fe7ccc8 159
ed1e77d3 160const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, 0, &shouldInterruptScriptBeforeTimeout };
14957cd0
A
161
162/* Source for JSGlobalObject.lut.h
163@begin globalObjectTable
14957cd0
A
164 parseFloat globalFuncParseFloat DontEnum|Function 1
165 isNaN globalFuncIsNaN DontEnum|Function 1
166 isFinite globalFuncIsFinite DontEnum|Function 1
167 escape globalFuncEscape DontEnum|Function 1
168 unescape globalFuncUnescape DontEnum|Function 1
169 decodeURI globalFuncDecodeURI DontEnum|Function 1
170 decodeURIComponent globalFuncDecodeURIComponent DontEnum|Function 1
171 encodeURI globalFuncEncodeURI DontEnum|Function 1
172 encodeURIComponent globalFuncEncodeURIComponent DontEnum|Function 1
173@end
174*/
175
ed1e77d3
A
176static EncodedJSValue JSC_HOST_CALL getTemplateObject(ExecState* exec)
177{
178 JSValue thisValue = exec->thisValue();
179 ASSERT(thisValue.inherits(JSTemplateRegistryKey::info()));
180 return JSValue::encode(exec->lexicalGlobalObject()->templateRegistry().getTemplateObject(exec, jsCast<JSTemplateRegistryKey*>(thisValue)->templateRegistryKey()));
181}
182
183
184static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
185{
186 VM& vm = exec->vm();
187 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
188
189 JSValue job = exec->argument(0);
190 JSValue arguments = exec->argument(1);
191 ASSERT(arguments.inherits(JSArray::info()));
192
193 globalObject->queueMicrotask(createJSJob(vm, job, jsCast<JSArray*>(arguments)));
194
195 return JSValue::encode(jsUndefined());
196}
197
93a37866
A
198JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
199 : Base(vm, structure, 0)
81345200
A
200 , m_vm(vm)
201#if ENABLE(WEB_REPLAY)
202 , m_inputCursor(EmptyInputCursor::create())
203#endif
204 , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
205 , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
206 , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
93a37866 207 , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
ed1e77d3 208 , m_templateRegistry(vm)
93a37866 209 , m_evalEnabled(true)
ed1e77d3 210 , m_runtimeFlags()
81345200 211 , m_consoleClient(nullptr)
93a37866 212 , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
9dae56ea 213{
9dae56ea
A
214}
215
216JSGlobalObject::~JSGlobalObject()
217{
81345200
A
218#if ENABLE(REMOTE_INSPECTOR)
219 m_inspectorController->globalObjectDestroyed();
220#endif
221
14957cd0 222 if (m_debugger)
81345200 223 m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
9dae56ea 224
93a37866
A
225 if (LegacyProfiler* profiler = vm().enabledProfiler())
226 profiler->stopProfiling(this);
9dae56ea
A
227}
228
6fe7ccc8
A
229void JSGlobalObject::destroy(JSCell* cell)
230{
93a37866
A
231 static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
232}
233
234void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
81345200 235{
93a37866 236 m_globalThis.set(vm, this, globalThis);
6fe7ccc8
A
237}
238
ed1e77d3 239void JSGlobalObject::init(VM& vm)
9dae56ea 240{
ed1e77d3 241 ASSERT(vm.currentThreadIsHoldingAPILock());
9dae56ea 242
ed1e77d3 243 JSGlobalObject::globalExec()->init(0, 0, CallFrame::noCaller(), 0, 0);
9dae56ea 244
14957cd0 245 m_debugger = 0;
9dae56ea 246
81345200
A
247#if ENABLE(REMOTE_INSPECTOR)
248 m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
249 m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
250 m_inspectorDebuggable->init();
81345200
A
251 m_consoleClient = m_inspectorController->consoleClient();
252#endif
253
9dae56ea
A
254 ExecState* exec = JSGlobalObject::globalExec();
255
81345200 256 m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
ed1e77d3
A
257 m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
258
259 // Need to create the callee structure (above) before creating the callee.
260 m_globalCallee.set(vm, this, JSCallee::create(vm, this, this));
261 exec->setCallee(m_globalCallee.get());
262
81345200
A
263 m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
264 m_boundFunctionStructure.set(vm, this, JSBoundFunction::createStructure(vm, this, m_functionPrototype.get()));
ed1e77d3 265 m_namedFunctionStructure.set(vm, this, Structure::addPropertyTransition(vm, m_functionStructure.get(), vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, m_functionNameOffset));
81345200 266 m_internalFunctionStructure.set(vm, this, InternalFunction::createStructure(vm, this, m_functionPrototype.get()));
14957cd0
A
267 JSFunction* callFunction = 0;
268 JSFunction* applyFunction = 0;
6fe7ccc8 269 m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction);
81345200
A
270 m_callFunction.set(vm, this, callFunction);
271 m_applyFunction.set(vm, this, applyFunction);
ed1e77d3
A
272 m_arrayProtoValuesFunction.set(vm, this, JSFunction::create(vm, this, 0, vm.propertyNames->values.string(), arrayProtoFuncValues));
273#if ENABLE(PROMISES)
274 m_initializePromiseFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, operationsPromiseInitializePromiseCodeGenerator(vm), this));
275 m_newPromiseDeferredFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, operationsPromiseNewPromiseDeferredCodeGenerator(vm), this));
276#endif // ENABLE(PROMISES)
277 m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
278 m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
81345200 279 m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
ed1e77d3
A
280 GetterSetter* protoAccessor = GetterSetter::create(vm, this);
281 protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoGetter));
282 protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoSetter));
81345200
A
283 m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
284 m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
285
286 m_typedArrays[toIndex(TypeInt8)].prototype.set(vm, this, JSInt8ArrayPrototype::create(vm, this, JSInt8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
287 m_typedArrays[toIndex(TypeInt16)].prototype.set(vm, this, JSInt16ArrayPrototype::create(vm, this, JSInt16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
288 m_typedArrays[toIndex(TypeInt32)].prototype.set(vm, this, JSInt32ArrayPrototype::create(vm, this, JSInt32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
289 m_typedArrays[toIndex(TypeUint8)].prototype.set(vm, this, JSUint8ArrayPrototype::create(vm, this, JSUint8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
290 m_typedArrays[toIndex(TypeUint8Clamped)].prototype.set(vm, this, JSUint8ClampedArrayPrototype::create(vm, this, JSUint8ClampedArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
291 m_typedArrays[toIndex(TypeUint16)].prototype.set(vm, this, JSUint16ArrayPrototype::create(vm, this, JSUint16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
292 m_typedArrays[toIndex(TypeUint32)].prototype.set(vm, this, JSUint32ArrayPrototype::create(vm, this, JSUint32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
293 m_typedArrays[toIndex(TypeFloat32)].prototype.set(vm, this, JSFloat32ArrayPrototype::create(vm, this, JSFloat32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
294 m_typedArrays[toIndex(TypeFloat64)].prototype.set(vm, this, JSFloat64ArrayPrototype::create(vm, this, JSFloat64ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
295 m_typedArrays[toIndex(TypeDataView)].prototype.set(vm, this, JSDataViewPrototype::create(vm, JSDataViewPrototype::createStructure(vm, this, m_objectPrototype.get())));
296
297 m_typedArrays[toIndex(TypeInt8)].structure.set(vm, this, JSInt8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt8)].prototype.get()));
298 m_typedArrays[toIndex(TypeInt16)].structure.set(vm, this, JSInt16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt16)].prototype.get()));
299 m_typedArrays[toIndex(TypeInt32)].structure.set(vm, this, JSInt32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt32)].prototype.get()));
300 m_typedArrays[toIndex(TypeUint8)].structure.set(vm, this, JSUint8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8)].prototype.get()));
301 m_typedArrays[toIndex(TypeUint8Clamped)].structure.set(vm, this, JSUint8ClampedArray::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get()));
302 m_typedArrays[toIndex(TypeUint16)].structure.set(vm, this, JSUint16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint16)].prototype.get()));
303 m_typedArrays[toIndex(TypeUint32)].structure.set(vm, this, JSUint32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint32)].prototype.get()));
304 m_typedArrays[toIndex(TypeFloat32)].structure.set(vm, this, JSFloat32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat32)].prototype.get()));
305 m_typedArrays[toIndex(TypeFloat64)].structure.set(vm, this, JSFloat64Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat64)].prototype.get()));
306 m_typedArrays[toIndex(TypeDataView)].structure.set(vm, this, JSDataView::createStructure(vm, this, m_typedArrays[toIndex(TypeDataView)].prototype.get()));
ed1e77d3
A
307
308 m_catchScopeStructure.set(vm, this, JSCatchScope::createStructure(vm, this, jsNull()));
309 m_functionNameScopeStructure.set(vm, this, JSFunctionNameScope::createStructure(vm, this, jsNull()));
310 m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
81345200 311 m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
ed1e77d3 312 m_debuggerScopeStructure.set(m_vm, this, DebuggerScope::createStructure(m_vm, this));
81345200 313 m_withScopeStructure.set(vm, this, JSWithScope::createStructure(vm, this, jsNull()));
ed1e77d3 314
81345200 315 m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
ed1e77d3 316
81345200 317 m_callbackFunctionStructure.set(vm, this, JSCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
ed1e77d3
A
318 m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
319 m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
320 m_outOfBandArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
81345200
A
321 m_callbackConstructorStructure.set(vm, this, JSCallbackConstructor::createStructure(vm, this, m_objectPrototype.get()));
322 m_callbackObjectStructure.set(vm, this, JSCallbackObject<JSDestructibleObject>::createStructure(vm, this, m_objectPrototype.get()));
93a37866 323#if JSC_OBJC_API_ENABLED
81345200
A
324 m_objcCallbackFunctionStructure.set(vm, this, ObjCCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
325 m_objcWrapperObjectStructure.set(vm, this, JSCallbackObject<JSAPIWrapperObject>::createStructure(vm, this, m_objectPrototype.get()));
93a37866 326#endif
ed1e77d3 327
81345200 328 m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
93a37866 329
81345200
A
330 m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
331 m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
332 m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
333 m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
334 m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
335 m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
93a37866
A
336 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
337 m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
9dae56ea 338
81345200
A
339 RegExp* emptyRegex = RegExp::create(vm, "", NoFlags);
340
341 m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex));
342 m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
ed1e77d3
A
343 m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, *this));
344
81345200
A
345#if ENABLE(PROMISES)
346 m_promisePrototype.set(vm, this, JSPromisePrototype::create(exec, this, JSPromisePrototype::createStructure(vm, this, m_objectPrototype.get())));
347 m_promiseStructure.set(vm, this, JSPromise::createStructure(vm, this, m_promisePrototype.get()));
348#endif // ENABLE(PROMISES)
9dae56ea 349
ed1e77d3
A
350 m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, NoIntrinsic));
351 putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), DontEnum | Function);
9dae56ea 352
ed1e77d3
A
353#define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
354m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_objectPrototype.get()))); \
355m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
356
81345200 357 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
ed1e77d3 358
81345200 359#undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
9dae56ea 360
ed1e77d3
A
361 m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
362
363#define CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
364m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_iteratorPrototype.get()))); \
365m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
366
367 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE)
368
369#undef CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE
9dae56ea 370
ed1e77d3
A
371 // Constructors
372
373 ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
81345200 374 m_objectConstructor.set(vm, this, objectConstructor);
ed1e77d3
A
375
376 JSFunction* definePropertyFunction = m_objectConstructor->addDefineProperty(exec, this);
377 m_definePropertyFunction.set(vm, this, definePropertyFunction);
378
81345200
A
379 JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
380 JSCell* arrayConstructor = ArrayConstructor::create(vm, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get());
ed1e77d3 381
81345200 382 m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get()));
ed1e77d3 383
81345200 384#define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
ed1e77d3
A
385capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get()); \
386m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \
81345200
A
387
388 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
ed1e77d3 389
81345200 390#undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
ed1e77d3 391
81345200 392 m_errorConstructor.set(vm, this, errorConstructor);
ed1e77d3 393
81345200
A
394 Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get());
395 Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get());
396 m_evalErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("EvalError")));
397 m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("RangeError")));
398 m_referenceErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("ReferenceError")));
399 m_syntaxErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("SyntaxError")));
400 m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("TypeError")));
401 m_URIErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("URIError")));
402#if ENABLE(PROMISES)
403 m_promiseConstructor.set(vm, this, JSPromiseConstructor::create(vm, JSPromiseConstructor::createStructure(vm, this, m_functionPrototype.get()), m_promisePrototype.get()));
404#endif
ed1e77d3 405
81345200
A
406 m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum);
407 m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum);
408 m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, DontEnum);
409 m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum);
410#if ENABLE(PROMISES)
411 m_promisePrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_promiseConstructor.get(), DontEnum);
412#endif
ed1e77d3 413
81345200
A
414 putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum);
415 putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum);
416 putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum);
417 putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum);
418 putDirectWithoutTransition(vm, vm.propertyNames->EvalError, m_evalErrorConstructor.get(), DontEnum);
419 putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum);
420 putDirectWithoutTransition(vm, vm.propertyNames->ReferenceError, m_referenceErrorConstructor.get(), DontEnum);
421 putDirectWithoutTransition(vm, vm.propertyNames->SyntaxError, m_syntaxErrorConstructor.get(), DontEnum);
422 putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum);
423 putDirectWithoutTransition(vm, vm.propertyNames->URIError, m_URIErrorConstructor.get(), DontEnum);
424#if ENABLE(PROMISES)
ed1e77d3
A
425 if (!m_runtimeFlags.isPromiseDisabled())
426 putDirectWithoutTransition(vm, vm.propertyNames->Promise, m_promiseConstructor.get(), DontEnum);
81345200 427#endif
ed1e77d3
A
428
429
81345200 430#define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
ed1e77d3 431putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \
81345200
A
432
433 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
434
ed1e77d3
A
435 if (!m_runtimeFlags.isSymbolDisabled())
436 putDirectWithoutTransition(vm, vm.propertyNames->Symbol, symbolConstructor, DontEnum);
437
81345200
A
438#undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
439 PrototypeMap& prototypeMap = vm.prototypeMap;
440 Structure* iteratorResultStructure = prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity());
441 PropertyOffset offset;
ed1e77d3
A
442 iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->done, 0, offset);
443 iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->value, 0, offset);
81345200 444 m_iteratorResultStructure.set(vm, this, iteratorResultStructure);
ed1e77d3 445
81345200
A
446 m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
447 putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
ed1e77d3
A
448
449#if ENABLE(INTL)
450 putDirectWithoutTransition(vm, vm.propertyNames->Intl, IntlObject::create(vm, IntlObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
451#endif // ENABLE(INTL)
81345200
A
452 putDirectWithoutTransition(vm, vm.propertyNames->JSON, JSONObject::create(vm, JSONObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
453 putDirectWithoutTransition(vm, vm.propertyNames->Math, MathObject::create(vm, this, MathObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
454
455 std::array<InternalFunction*, NUMBER_OF_TYPED_ARRAY_TYPES> typedArrayConstructors;
ed1e77d3
A
456 typedArrayConstructors[toIndex(TypeInt8)] = JSInt8ArrayConstructor::create(vm, JSInt8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt8)].prototype.get(), ASCIILiteral("Int8Array"));
457 typedArrayConstructors[toIndex(TypeInt16)] = JSInt16ArrayConstructor::create(vm, JSInt16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt16)].prototype.get(), ASCIILiteral("Int16Array"));
458 typedArrayConstructors[toIndex(TypeInt32)] = JSInt32ArrayConstructor::create(vm, JSInt32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt32)].prototype.get(), ASCIILiteral("Int32Array"));
459 typedArrayConstructors[toIndex(TypeUint8)] = JSUint8ArrayConstructor::create(vm, JSUint8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8)].prototype.get(), ASCIILiteral("Uint8Array"));
460 typedArrayConstructors[toIndex(TypeUint8Clamped)] = JSUint8ClampedArrayConstructor::create(vm, JSUint8ClampedArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get(), ASCIILiteral("Uint8ClampedArray"));
461 typedArrayConstructors[toIndex(TypeUint16)] = JSUint16ArrayConstructor::create(vm, JSUint16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint16)].prototype.get(), ASCIILiteral("Uint16Array"));
462 typedArrayConstructors[toIndex(TypeUint32)] = JSUint32ArrayConstructor::create(vm, JSUint32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint32)].prototype.get(), ASCIILiteral("Uint32Array"));
463 typedArrayConstructors[toIndex(TypeFloat32)] = JSFloat32ArrayConstructor::create(vm, JSFloat32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat32)].prototype.get(), ASCIILiteral("Float32Array"));
464 typedArrayConstructors[toIndex(TypeFloat64)] = JSFloat64ArrayConstructor::create(vm, JSFloat64ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat64)].prototype.get(), ASCIILiteral("Float64Array"));
465 typedArrayConstructors[toIndex(TypeDataView)] = JSDataViewConstructor::create(vm, JSDataViewConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeDataView)].prototype.get(), ASCIILiteral("DataView"));
466
81345200
A
467 for (unsigned typedArrayIndex = NUMBER_OF_TYPED_ARRAY_TYPES; typedArrayIndex--;) {
468 m_typedArrays[typedArrayIndex].prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, typedArrayConstructors[typedArrayIndex], DontEnum);
ed1e77d3 469 putDirectWithoutTransition(vm, Identifier::fromString(exec, typedArrayConstructors[typedArrayIndex]->name(exec)), typedArrayConstructors[typedArrayIndex], DontEnum);
81345200
A
470 }
471
472 JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
ed1e77d3
A
473
474 JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic);
475 JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
476 JSFunction* privateFuncIsFinite = JSFunction::create(vm, this, 0, String(), globalFuncIsFinite);
477
478 JSFunction* privateFuncObjectKeys = JSFunction::create(vm, this, 0, String(), objectConstructorKeys);
479 JSFunction* privateFuncObjectGetOwnPropertyDescriptor = JSFunction::create(vm, this, 0, String(), objectConstructorGetOwnPropertyDescriptor);
480 JSFunction* privateFuncObjectGetOwnPropertySymbols = JSFunction::create(vm, this, 0, String(), objectConstructorGetOwnPropertySymbols);
481 JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject);
482 JSFunction* privateFuncToLength = JSFunction::createBuiltinFunction(vm, globalObjectToLengthCodeGenerator(vm), this);
483 JSFunction* privateFuncToInteger = JSFunction::createBuiltinFunction(vm, globalObjectToIntegerCodeGenerator(vm), this);
484
9dae56ea 485 GlobalPropertyInfo staticGlobals[] = {
81345200
A
486 GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
487 GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
488 GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
489 GlobalPropertyInfo(vm.propertyNames->undefinedPrivateName, jsUndefined(), DontEnum | DontDelete | ReadOnly),
490 GlobalPropertyInfo(vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly),
ed1e77d3
A
491 GlobalPropertyInfo(vm.propertyNames->objectKeysPrivateName, privateFuncObjectKeys, DontEnum | DontDelete | ReadOnly),
492 GlobalPropertyInfo(vm.propertyNames->objectGetOwnPropertyDescriptorPrivateName, privateFuncObjectGetOwnPropertyDescriptor, DontEnum | DontDelete | ReadOnly),
493 GlobalPropertyInfo(vm.propertyNames->objectGetOwnPropertySymbolsPrivateName, privateFuncObjectGetOwnPropertySymbols, DontEnum | DontDelete | ReadOnly),
494 GlobalPropertyInfo(vm.propertyNames->getTemplateObjectPrivateName, privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly),
495 GlobalPropertyInfo(vm.propertyNames->enqueueJobPrivateName, JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),
81345200 496 GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
ed1e77d3
A
497 GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly),
498 GlobalPropertyInfo(vm.propertyNames->ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly),
499 GlobalPropertyInfo(vm.propertyNames->NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly),
500 GlobalPropertyInfo(vm.propertyNames->StringPrivateName, stringConstructor, DontEnum | DontDelete | ReadOnly),
501 GlobalPropertyInfo(vm.propertyNames->absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly),
502 GlobalPropertyInfo(vm.propertyNames->floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
503 GlobalPropertyInfo(vm.propertyNames->getPrototypeOfPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
504 GlobalPropertyInfo(vm.propertyNames->getOwnPropertyNamesPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
505 GlobalPropertyInfo(vm.propertyNames->isFinitePrivateName, privateFuncIsFinite, DontEnum | DontDelete | ReadOnly),
506 GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyPrivateName, jsNumber(ArrayIterateKey), DontEnum | DontDelete | ReadOnly),
507 GlobalPropertyInfo(vm.propertyNames->arrayIterationKindValuePrivateName, jsNumber(ArrayIterateValue), DontEnum | DontDelete | ReadOnly),
508 GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyValuePrivateName, jsNumber(ArrayIterateKeyValue), DontEnum | DontDelete | ReadOnly),
509 GlobalPropertyInfo(vm.propertyNames->symbolIteratorPrivateName, Symbol::create(vm, static_cast<SymbolImpl&>(*vm.propertyNames->iteratorSymbol.impl())), DontEnum | DontDelete | ReadOnly),
510#if ENABLE(PROMISES)
511 GlobalPropertyInfo(vm.propertyNames->PromisePrivateName, m_promiseConstructor.get(), DontEnum | DontDelete | ReadOnly),
512 GlobalPropertyInfo(vm.propertyNames->promisePendingPrivateName, jsNumber(static_cast<unsigned>(JSPromise::Status::Pending)), DontEnum | DontDelete | ReadOnly),
513 GlobalPropertyInfo(vm.propertyNames->promiseFulfilledPrivateName, jsNumber(static_cast<unsigned>(JSPromise::Status::Fulfilled)), DontEnum | DontDelete | ReadOnly),
514 GlobalPropertyInfo(vm.propertyNames->promiseRejectedPrivateName, jsNumber(static_cast<unsigned>(JSPromise::Status::Rejected)), DontEnum | DontDelete | ReadOnly),
515#endif
516 GlobalPropertyInfo(vm.propertyNames->builtinNames().toLengthPrivateName(), privateFuncToLength, DontEnum | DontDelete | ReadOnly),
517 GlobalPropertyInfo(vm.propertyNames->builtinNames().toIntegerPrivateName(), privateFuncToInteger, DontEnum | DontDelete | ReadOnly),
518 GlobalPropertyInfo(vm.propertyNames->builtinNames().isObjectPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectIsObjectCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
519 GlobalPropertyInfo(vm.propertyNames->builtinNames().isPromisePrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseIsPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
520 GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseReactionPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseNewPromiseReactionCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
521 GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseCapabilityPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseNewPromiseCapabilityCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
522 GlobalPropertyInfo(vm.propertyNames->builtinNames().triggerPromiseReactionsPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseTriggerPromiseReactionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
523 GlobalPropertyInfo(vm.propertyNames->builtinNames().rejectPromisePrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseRejectPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
524 GlobalPropertyInfo(vm.propertyNames->builtinNames().fulfillPromisePrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseFulfillPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
525 GlobalPropertyInfo(vm.propertyNames->builtinNames().createResolvingFunctionsPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromiseCreateResolvingFunctionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
526 GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseReactionJobPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromisePromiseReactionJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
527 GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseResolveThenableJobPrivateName(), JSFunction::createBuiltinFunction(vm, operationsPromisePromiseResolveThenableJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
9dae56ea 528 };
14957cd0 529 addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
93a37866
A
530
531 m_specialPointers[Special::CallFunction] = m_callFunction.get();
532 m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
533 m_specialPointers[Special::ObjectConstructor] = objectConstructor;
534 m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
535
ed1e77d3
A
536 m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::DefinePropertyFunction)] = m_definePropertyFunction.get();
537
81345200
A
538 ConsolePrototype* consolePrototype = ConsolePrototype::create(vm, this, ConsolePrototype::createStructure(vm, this, m_objectPrototype.get()));
539 m_consoleStructure.set(vm, this, JSConsole::createStructure(vm, this, consolePrototype));
540 JSConsole* consoleObject = JSConsole::create(vm, m_consoleStructure.get());
ed1e77d3 541 putDirectWithoutTransition(vm, Identifier::fromString(exec, "console"), consoleObject, DontEnum);
81345200 542
ed1e77d3
A
543 if (UNLIKELY(Options::enableDollarVM())) {
544 JSDollarVMPrototype* dollarVMPrototype = JSDollarVMPrototype::create(vm, this, JSDollarVMPrototype::createStructure(vm, this, m_objectPrototype.get()));
545 m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, dollarVMPrototype));
546 JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
547 putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, DontEnum);
93a37866
A
548 }
549
ed1e77d3
A
550 resetPrototype(vm, prototype());
551}
552
553void JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
554{
555 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
556 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
557
558 if (symbolTablePut(thisObject, exec, propertyName, value, slot.isStrictMode()))
559 return;
560 Base::put(thisObject, exec, propertyName, value, slot);
561}
562
563bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
564{
565 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
566 PropertySlot slot(thisObject);
567 // silently ignore attempts to add accessors aliasing vars.
568 if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
569 return false;
570 return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
571}
572
573void JSGlobalObject::addGlobalVar(const Identifier& ident, ConstantMode constantMode)
574{
575 ConcurrentJITLocker locker(symbolTable()->m_lock);
576 SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
577 if (!entry.isNull())
578 return;
579
580 ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
581 SymbolTableEntry newEntry(VarOffset(offset), (constantMode == IsConstant) ? ReadOnly : 0);
582 if (constantMode == IsVariable)
583 newEntry.prepareToWatch();
584 else
585 newEntry.disableWatching();
586 symbolTable()->add(locker, ident.impl(), newEntry);
587
588 ScopeOffset offsetForAssert = addVariables(1);
589 RELEASE_ASSERT(offsetForAssert == offset);
590}
591
592void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
593{
594 VM& vm = exec->vm();
595 removeDirect(vm, propertyName); // Newly declared functions overwrite existing properties.
596 addGlobalVar(propertyName, IsVariable);
597}
598
599static inline JSObject* lastInPrototypeChain(JSObject* object)
600{
601 JSObject* o = object;
602 while (o->prototype().isObject())
603 o = asObject(o->prototype());
604 return o;
93a37866 605}
9dae56ea 606
93a37866
A
607// Private namespace for helpers for JSGlobalObject::haveABadTime()
608namespace {
609
610class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
611public:
612 ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
ed1e77d3 613 IterationStatus operator()(JSCell*);
93a37866
A
614
615private:
ed1e77d3
A
616 void visit(JSCell*);
617
93a37866
A
618 MarkedArgumentBuffer& m_foundObjects;
619 JSGlobalObject* m_globalObject;
620};
621
622ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
623 MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
624 : m_foundObjects(foundObjects)
625 , m_globalObject(globalObject)
626{
627}
628
629inline bool hasBrokenIndexing(JSObject* object)
630{
631 // This will change if we have more indexing types.
81345200 632 IndexingType type = object->indexingType();
93a37866
A
633 // This could be made obviously more efficient, but isn't made so right now, because
634 // we expect this to be an unlikely slow path anyway.
81345200 635 return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type);
93a37866
A
636}
637
ed1e77d3 638inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell)
93a37866
A
639{
640 if (!cell->isObject())
641 return;
642
643 JSObject* object = asObject(cell);
644
645 // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
646 if (!hasBrokenIndexing(object))
647 return;
648
649 // We only want to have a bad time in the affected global object, not in the entire
650 // VM. But we have to be careful, since there may be objects that claim to belong to
651 // a different global object that have prototypes from our global object.
652 bool foundGlobalObject = false;
653 for (JSObject* current = object; ;) {
654 if (current->globalObject() == m_globalObject) {
655 foundGlobalObject = true;
656 break;
657 }
658
659 JSValue prototypeValue = current->prototype();
660 if (prototypeValue.isNull())
661 break;
662 current = asObject(prototypeValue);
663 }
664 if (!foundGlobalObject)
665 return;
666
667 m_foundObjects.append(object);
668}
669
ed1e77d3
A
670IterationStatus ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell)
671{
672 visit(cell);
673 return IterationStatus::Continue;
674}
675
93a37866
A
676} // end private namespace for helpers for JSGlobalObject::haveABadTime()
677
678void JSGlobalObject::haveABadTime(VM& vm)
679{
680 ASSERT(&vm == &this->vm());
681
682 if (isHavingABadTime())
683 return;
684
685 // Make sure that all allocations or indexed storage transitions that are inlining
686 // the assumption that it's safe to transition to a non-SlowPut array storage don't
687 // do so anymore.
ed1e77d3 688 m_havingABadTimeWatchpoint->fireAll("Having a bad time");
93a37866
A
689 ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
690
691 // Make sure that all JSArray allocations that load the appropriate structure from
692 // this object now load a structure that uses SlowPut.
693 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
694 m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
695
696 // Make sure that all objects that have indexed storage switch to the slow kind of
697 // indexed storage.
698 MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
699 ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
81345200
A
700 {
701 HeapIterationScope iterationScope(vm.heap);
702 vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
703 }
93a37866
A
704 while (!foundObjects.isEmpty()) {
705 JSObject* object = asObject(foundObjects.last());
706 foundObjects.removeLast();
707 ASSERT(hasBrokenIndexing(object));
708 object->switchToSlowPutArrayStorage(vm);
709 }
710}
711
81345200
A
712bool JSGlobalObject::objectPrototypeIsSane()
713{
714 return !hasIndexedProperties(m_objectPrototype->indexingType())
715 && m_objectPrototype->prototype().isNull();
716}
717
93a37866
A
718bool JSGlobalObject::arrayPrototypeChainIsSane()
719{
81345200 720 return !hasIndexedProperties(m_arrayPrototype->indexingType())
93a37866 721 && m_arrayPrototype->prototype() == m_objectPrototype.get()
81345200
A
722 && objectPrototypeIsSane();
723}
724
725bool JSGlobalObject::stringPrototypeChainIsSane()
726{
727 return !hasIndexedProperties(m_stringPrototype->indexingType())
728 && m_stringPrototype->prototype() == m_objectPrototype.get()
729 && objectPrototypeIsSane();
9dae56ea
A
730}
731
81345200 732void JSGlobalObject::createThrowTypeError(VM& vm)
6fe7ccc8 733{
81345200 734 JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
ed1e77d3
A
735 GetterSetter* getterSetter = GetterSetter::create(vm, this);
736 getterSetter->setGetter(vm, this, thrower);
737 getterSetter->setSetter(vm, this, thrower);
81345200 738 m_throwTypeErrorGetterSetter.set(vm, this, getterSetter);
6fe7ccc8
A
739}
740
9dae56ea 741// Set prototype, and also insert the object prototype at the end of the chain.
93a37866 742void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
9dae56ea 743{
93a37866 744 setPrototype(vm, prototype);
9dae56ea 745
ba379fdc 746 JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
14957cd0 747 JSObject* objectPrototype = m_objectPrototype.get();
ba379fdc 748 if (oldLastInPrototypeChain != objectPrototype)
93a37866 749 oldLastInPrototypeChain->setPrototype(vm, objectPrototype);
81345200
A
750
751 // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
752 setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
9dae56ea
A
753}
754
6fe7ccc8
A
755void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
756{
757 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
81345200 758 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
93a37866
A
759 Base::visitChildren(thisObject, visitor);
760
761 visitor.append(&thisObject->m_globalThis);
762
ed1e77d3 763 visitor.append(&thisObject->m_globalCallee);
93a37866
A
764 visitor.append(&thisObject->m_regExpConstructor);
765 visitor.append(&thisObject->m_errorConstructor);
766 visitor.append(&thisObject->m_evalErrorConstructor);
767 visitor.append(&thisObject->m_rangeErrorConstructor);
768 visitor.append(&thisObject->m_referenceErrorConstructor);
769 visitor.append(&thisObject->m_syntaxErrorConstructor);
770 visitor.append(&thisObject->m_typeErrorConstructor);
771 visitor.append(&thisObject->m_URIErrorConstructor);
81345200
A
772 visitor.append(&thisObject->m_objectConstructor);
773#if ENABLE(PROMISES)
774 visitor.append(&thisObject->m_promiseConstructor);
775#endif
93a37866 776
ed1e77d3
A
777 visitor.append(&thisObject->m_nullGetterFunction);
778 visitor.append(&thisObject->m_nullSetterFunction);
779
780 visitor.append(&thisObject->m_parseIntFunction);
93a37866
A
781 visitor.append(&thisObject->m_evalFunction);
782 visitor.append(&thisObject->m_callFunction);
783 visitor.append(&thisObject->m_applyFunction);
ed1e77d3
A
784 visitor.append(&thisObject->m_definePropertyFunction);
785 visitor.append(&thisObject->m_arrayProtoValuesFunction);
786#if ENABLE(PROMISES)
787 visitor.append(&thisObject->m_initializePromiseFunction);
788 visitor.append(&thisObject->m_newPromiseDeferredFunction);
789#endif
93a37866
A
790 visitor.append(&thisObject->m_throwTypeErrorGetterSetter);
791
792 visitor.append(&thisObject->m_objectPrototype);
793 visitor.append(&thisObject->m_functionPrototype);
794 visitor.append(&thisObject->m_arrayPrototype);
93a37866 795 visitor.append(&thisObject->m_errorPrototype);
ed1e77d3 796 visitor.append(&thisObject->m_iteratorPrototype);
81345200
A
797#if ENABLE(PROMISES)
798 visitor.append(&thisObject->m_promisePrototype);
799#endif
93a37866 800
ed1e77d3 801 visitor.append(&thisObject->m_debuggerScopeStructure);
93a37866
A
802 visitor.append(&thisObject->m_withScopeStructure);
803 visitor.append(&thisObject->m_strictEvalActivationStructure);
ed1e77d3
A
804 visitor.append(&thisObject->m_lexicalEnvironmentStructure);
805 visitor.append(&thisObject->m_catchScopeStructure);
806 visitor.append(&thisObject->m_functionNameScopeStructure);
807 visitor.append(&thisObject->m_directArgumentsStructure);
808 visitor.append(&thisObject->m_scopedArgumentsStructure);
809 visitor.append(&thisObject->m_outOfBandArgumentsStructure);
93a37866
A
810 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
811 visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
812 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
813 visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
814 visitor.append(&thisObject->m_booleanObjectStructure);
815 visitor.append(&thisObject->m_callbackConstructorStructure);
816 visitor.append(&thisObject->m_callbackFunctionStructure);
817 visitor.append(&thisObject->m_callbackObjectStructure);
818#if JSC_OBJC_API_ENABLED
819 visitor.append(&thisObject->m_objcCallbackFunctionStructure);
820 visitor.append(&thisObject->m_objcWrapperObjectStructure);
821#endif
93a37866
A
822 visitor.append(&thisObject->m_nullPrototypeObjectStructure);
823 visitor.append(&thisObject->m_errorStructure);
ed1e77d3 824 visitor.append(&thisObject->m_calleeStructure);
93a37866
A
825 visitor.append(&thisObject->m_functionStructure);
826 visitor.append(&thisObject->m_boundFunctionStructure);
827 visitor.append(&thisObject->m_namedFunctionStructure);
ed1e77d3 828 visitor.append(&thisObject->m_symbolObjectStructure);
93a37866 829 visitor.append(&thisObject->m_regExpStructure);
ed1e77d3 830 visitor.append(&thisObject->m_regExpMatchesArrayStructure);
81345200 831 visitor.append(&thisObject->m_consoleStructure);
ed1e77d3 832 visitor.append(&thisObject->m_dollarVMStructure);
93a37866 833 visitor.append(&thisObject->m_internalFunctionStructure);
81345200
A
834
835#if ENABLE(PROMISES)
836 visitor.append(&thisObject->m_promiseStructure);
837#endif // ENABLE(PROMISES)
838
839#define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
840 visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
841 visitor.append(&thisObject->m_ ## properName ## Structure); \
842
843 FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
ed1e77d3 844 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE)
81345200
A
845
846#undef VISIT_SIMPLE_TYPE
847
848 for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;) {
849 visitor.append(&thisObject->m_typedArrays[i].prototype);
850 visitor.append(&thisObject->m_typedArrays[i].structure);
851 }
9dae56ea
A
852}
853
81345200 854JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
9dae56ea 855{
81345200
A
856 if (ecmaMode == StrictMode)
857 return jsUndefined();
858 return exec->globalThisValue();
9dae56ea
A
859}
860
93a37866 861ExecState* JSGlobalObject::globalExec()
14957cd0 862{
81345200 863 return CallFrame::create(m_globalCallFrame);
f9bf01c6
A
864}
865
14957cd0
A
866void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
867{
ed1e77d3 868 ScopeOffset startOffset = addVariables(count);
14957cd0 869
6fe7ccc8 870 for (int i = 0; i < count; ++i) {
14957cd0
A
871 GlobalPropertyInfo& global = globals[i];
872 ASSERT(global.attributes & DontDelete);
6fe7ccc8 873
ed1e77d3
A
874 ScopeOffset offset;
875 {
876 ConcurrentJITLocker locker(symbolTable()->m_lock);
877 offset = symbolTable()->takeNextScopeOffset(locker);
878 RELEASE_ASSERT(offset = startOffset + i);
879 SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
880 symbolTable()->add(locker, global.identifier.impl(), newEntry);
881 }
882 variableAt(offset).set(vm(), this, global.value);
14957cd0
A
883 }
884}
885
81345200 886bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
14957cd0 887{
6fe7ccc8 888 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
ed1e77d3 889 if (getStaticFunctionSlot<Base>(exec, globalObjectTable, thisObject, propertyName, slot))
14957cd0 890 return true;
81345200 891 return symbolTableGet(thisObject, propertyName, slot);
14957cd0
A
892}
893
6fe7ccc8 894void JSGlobalObject::clearRareData(JSCell* cell)
f9bf01c6 895{
ed1e77d3 896 jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
9dae56ea
A
897}
898
14957cd0
A
899void slowValidateCell(JSGlobalObject* globalObject)
900{
93a37866 901 RELEASE_ASSERT(globalObject->isGlobalObject());
81345200 902 ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
14957cd0
A
903}
904
93a37866
A
905UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
906{
907 ParserError error;
ed1e77d3 908 JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
93a37866
A
909 DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
910 ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
ed1e77d3
A
911 UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock(
912 vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode,
913 debuggerMode, profilerMode, error);
93a37866
A
914
915 if (hasDebugger())
ed1e77d3 916 debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
93a37866 917
ed1e77d3 918 if (error.isValid()) {
93a37866 919 *exception = error.toErrorObject(this, executable->source());
ed1e77d3 920 return nullptr;
93a37866
A
921 }
922
81345200 923 return unlinkedCodeBlock;
93a37866
A
924}
925
ed1e77d3 926UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable, ThisTDZMode thisTDZMode)
93a37866
A
927{
928 ParserError error;
ed1e77d3 929 JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
93a37866
A
930 DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
931 ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
ed1e77d3
A
932 UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock(
933 vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, thisTDZMode, debuggerMode, profilerMode, error);
93a37866
A
934
935 if (hasDebugger())
ed1e77d3 936 debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
93a37866 937
ed1e77d3 938 if (error.isValid()) {
81345200 939 throwVMError(callFrame, error.toErrorObject(this, executable->source()));
ed1e77d3 940 return nullptr;
93a37866
A
941 }
942
81345200
A
943 return unlinkedCodeBlock;
944}
945
946void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
947{
948#if ENABLE(REMOTE_INSPECTOR)
949 m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
950#else
951 UNUSED_PARAM(enabled);
952#endif
953}
954
955bool JSGlobalObject::remoteDebuggingEnabled() const
956{
957#if ENABLE(REMOTE_INSPECTOR)
958 return m_inspectorDebuggable->remoteDebuggingAllowed();
959#else
960 return false;
961#endif
962}
963
964#if ENABLE(WEB_REPLAY)
965void JSGlobalObject::setInputCursor(PassRefPtr<InputCursor> prpCursor)
966{
967 m_inputCursor = prpCursor;
968 ASSERT(m_inputCursor);
969
970 InputCursor& cursor = inputCursor();
971 // Save or set the random seed. This performed here rather than the constructor
972 // to avoid threading the input cursor through all the abstraction layers.
973 if (cursor.isCapturing())
974 cursor.appendInput<SetRandomSeed>(m_weakRandom.seedUnsafe());
975 else if (cursor.isReplaying()) {
976 if (SetRandomSeed* input = cursor.fetchInput<SetRandomSeed>())
977 m_weakRandom.initializeSeed(static_cast<unsigned>(input->randomSeed()));
978 }
979}
980#endif
981
982void JSGlobalObject::setName(const String& name)
983{
984 m_name = name;
985
986#if ENABLE(REMOTE_INSPECTOR)
987 m_inspectorDebuggable->update();
988#endif
989}
990
991void JSGlobalObject::queueMicrotask(PassRefPtr<Microtask> task)
992{
993 if (globalObjectMethodTable()->queueTaskToEventLoop)
994 globalObjectMethodTable()->queueTaskToEventLoop(this, task);
995 else
996 WTFLogAlways("ERROR: Event loop not supported.");
93a37866
A
997}
998
9dae56ea 999} // namespace JSC