1/*
2 * Copyright (C) 2007-2019 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 "ArrayConstructor.h"
34#include "ArrayIteratorPrototype.h"
35#include "ArrayPrototype.h"
36#include "AsyncFromSyncIteratorPrototype.h"
37#include "AtomicsObject.h"
38#include "AsyncFunctionConstructor.h"
39#include "AsyncFunctionPrototype.h"
40#include "AsyncGeneratorFunctionConstructor.h"
41#include "AsyncGeneratorFunctionPrototype.h"
42#include "AsyncGeneratorPrototype.h"
43#include "AsyncIteratorPrototype.h"
44#include "BigIntConstructor.h"
45#include "BigIntObject.h"
46#include "BigIntPrototype.h"
47#include "BooleanConstructor.h"
48#include "BooleanPrototype.h"
49#include "BuiltinNames.h"
50#include "CatchScope.h"
51#include "ClonedArguments.h"
52#include "CodeBlock.h"
53#include "CodeBlockSetInlines.h"
54#include "CodeCache.h"
55#include "ConsoleObject.h"
56#include "DateConstructor.h"
57#include "DatePrototype.h"
58#include "Debugger.h"
59#include "DebuggerScope.h"
60#include "DirectArguments.h"
61#include "DirectEvalExecutable.h"
62#include "ECMAScriptSpecInternalFunctions.h"
63#include "Error.h"
64#include "ErrorConstructor.h"
65#include "ErrorPrototype.h"
66#include "Exception.h"
67#include "FunctionConstructor.h"
68#include "FunctionPrototype.h"
69#include "GeneratorFunctionConstructor.h"
70#include "GeneratorFunctionPrototype.h"
71#include "GeneratorPrototype.h"
72#include "GetterSetter.h"
73#include "HeapIterationScope.h"
74#include "IndirectEvalExecutable.h"
75#include "InspectorInstrumentationObject.h"
76#include "Interpreter.h"
77#include "IteratorPrototype.h"
78#include "JSAPIWrapperObject.h"
79#include "JSArrayBuffer.h"
80#include "JSArrayBufferConstructor.h"
81#include "JSArrayBufferPrototype.h"
82#include "JSAsyncFunction.h"
83#include "JSAsyncGeneratorFunction.h"
84#include "JSBigInt.h"
85#include "JSBoundFunction.h"
86#include "JSCInlines.h"
87#include "JSCallbackConstructor.h"
88#include "JSCallbackFunction.h"
89#include "JSCallbackObject.h"
90#include "JSCustomGetterSetterFunction.h"
91#include "JSDataView.h"
92#include "JSDataViewPrototype.h"
93#include "JSDollarVM.h"
94#include "JSFunction.h"
95#include "JSGeneratorFunction.h"
96#include "JSGenericTypedArrayViewConstructorInlines.h"
97#include "JSGenericTypedArrayViewInlines.h"
98#include "JSGenericTypedArrayViewPrototypeInlines.h"
99#include "JSGlobalObjectFunctions.h"
100#include "JSInternalPromise.h"
101#include "JSInternalPromiseConstructor.h"
102#include "JSInternalPromisePrototype.h"
103#include "JSLexicalEnvironment.h"
104#include "JSLock.h"
105#include "JSMap.h"
106#include "JSMicrotask.h"
107#include "JSModuleEnvironment.h"
108#include "JSModuleLoader.h"
109#include "JSModuleNamespaceObject.h"
110#include "JSModuleRecord.h"
111#include "JSNativeStdFunction.h"
112#include "JSNonDestructibleProxy.h"
113#include "JSONObject.h"
114#include "JSPromise.h"
115#include "JSPromiseConstructor.h"
116#include "JSPromisePrototype.h"
117#include "JSSet.h"
118#include "JSStringIterator.h"
119#include "JSTypedArrayConstructors.h"
120#include "JSTypedArrayPrototypes.h"
121#include "JSTypedArrayViewConstructor.h"
122#include "JSTypedArrayViewPrototype.h"
123#include "JSTypedArrays.h"
124#include "JSWeakMap.h"
125#include "JSWeakSet.h"
126#include "JSWebAssembly.h"
127#include "JSWithScope.h"
128#include "LazyClassStructureInlines.h"
129#include "LazyPropertyInlines.h"
130#include "Lookup.h"
131#include "MapConstructor.h"
132#include "MapIteratorPrototype.h"
133#include "MapPrototype.h"
134#include "MarkedSpaceInlines.h"
135#include "MathObject.h"
136#include "Microtask.h"
137#include "NativeErrorConstructor.h"
138#include "NativeErrorPrototype.h"
139#include "NullGetterFunction.h"
140#include "NullSetterFunction.h"
141#include "NumberConstructor.h"
142#include "NumberPrototype.h"
143#include "ObjCCallbackFunction.h"
144#include "ObjectConstructor.h"
145#include "ObjectPropertyChangeAdaptiveWatchpoint.h"
146#include "ObjectPropertyConditionSet.h"
147#include "ObjectPrototype.h"
148#include "ParserError.h"
149#include "ProxyConstructor.h"
150#include "ProxyObject.h"
151#include "ProxyRevoke.h"
152#include "ReflectObject.h"
153#include "RegExpCache.h"
154#include "RegExpConstructor.h"
155#include "RegExpMatchesArray.h"
156#include "RegExpObject.h"
157#include "RegExpPrototype.h"
158#include "ScopedArguments.h"
159#include "SetConstructor.h"
160#include "SetIteratorPrototype.h"
161#include "SetPrototype.h"
162#include "StrictEvalActivation.h"
163#include "StringConstructor.h"
164#include "StringIteratorPrototype.h"
165#include "StringPrototype.h"
166#include "Symbol.h"
167#include "SymbolConstructor.h"
168#include "SymbolObject.h"
169#include "SymbolPrototype.h"
170#include "VariableWriteFireDetail.h"
171#include "WasmCapabilities.h"
172#include "WeakGCMapInlines.h"
173#include "WeakMapConstructor.h"
174#include "WeakMapPrototype.h"
175#include "WeakSetConstructor.h"
176#include "WeakSetPrototype.h"
177#include "WebAssemblyPrototype.h"
178#include "WebAssemblyToJSCallee.h"
179#include <wtf/RandomNumber.h>
180
181#if ENABLE(INTL)
182#include "IntlCollator.h"
183#include "IntlCollatorPrototype.h"
184#include "IntlDateTimeFormat.h"
185#include "IntlDateTimeFormatPrototype.h"
186#include "IntlNumberFormat.h"
187#include "IntlNumberFormatPrototype.h"
188#include "IntlObject.h"
189#include "IntlPluralRules.h"
190#include "IntlPluralRulesPrototype.h"
191#include <unicode/ucol.h>
192#include <unicode/udat.h>
193#include <unicode/unum.h>
194#endif // ENABLE(INTL)
195
196#if ENABLE(REMOTE_INSPECTOR)
197#include "JSGlobalObjectDebuggable.h"
198#include "JSGlobalObjectInspectorController.h"
199#endif
200
201#ifdef JSC_GLIB_API_ENABLED
202#include "JSCCallbackFunction.h"
203#include "JSCWrapperMap.h"
204#endif
205
206namespace JSC {
207
208static JSValue createProxyProperty(VM& vm, JSObject* object)
209{
210 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
211 return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
212}
213
214static JSValue createJSONProperty(VM& vm, JSObject* object)
215{
216 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
217 return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
218}
219
220static JSValue createMathProperty(VM& vm, JSObject* object)
221{
222 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
223 return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
224}
225
226static JSValue createReflectProperty(VM& vm, JSObject* object)
227{
228 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
229 return ReflectObject::create(vm, global, ReflectObject::createStructure(vm, global, global->objectPrototype()));
230}
231
232static JSValue createConsoleProperty(VM& vm, JSObject* object)
233{
234 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
235 return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global->globalExec())));
236}
237
238static EncodedJSValue JSC_HOST_CALL makeBoundFunction(ExecState* exec)
239{
240 VM& vm = exec->vm();
241 auto scope = DECLARE_THROW_SCOPE(vm);
242
243 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
244
245 JSObject* target = asObject(exec->uncheckedArgument(0));
246 JSValue boundThis = exec->uncheckedArgument(1);
247 JSValue boundArgs = exec->uncheckedArgument(2);
248 //JSValue lengthValue = exec->uncheckedArgument(3);
249 //JSString* nameString = asString(exec->uncheckedArgument(4));
250 JSString* name = asString(exec->uncheckedArgument(4));
251
252 //ASSERT(lengthValue.isAnyInt());
253 //ASSERT(lengthValue.asAnyInt() <= INT32_MAX);
254 //ASSERT(lengthValue.asAnyInt() >= INT32_MIN);
255 //int32_t length = lengthValue.toInt32(exec);
256 JSValue length = exec->uncheckedArgument(3);
257 scope.assertNoException();
258
259 //String name = nameString->value(exec);
260 RETURN_IF_EXCEPTION(scope, { });
261
262 //RELEASE_AND_RETURN(scope, JSValue::encode(JSBoundFunction::create(vm, exec, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSArray*>(boundArgs) : nullptr, length, WTFMove(name))));
263 return JSValue::encode(JSBoundFunction::create( vm, exec, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSArray*>(boundArgs) : nullptr, length.asInt32(), name->value(exec)));
264}
265
266static EncodedJSValue JSC_HOST_CALL hasOwnLengthProperty(ExecState* exec)
267{
268 VM& vm = exec->vm();
269 JSObject* target = asObject(exec->uncheckedArgument(0));
270 return JSValue::encode(jsBoolean(target->hasOwnProperty(exec, vm.propertyNames->length)));
271}
272
273#if !ASSERT_DISABLED
274static EncodedJSValue JSC_HOST_CALL assertCall(ExecState* exec)
275{
276 RELEASE_ASSERT(exec->argument(0).isBoolean());
277 if (exec->argument(0).asBoolean())
278 return JSValue::encode(jsUndefined());
279
280 bool iteratedOnce = false;
281 CodeBlock* codeBlock = nullptr;
282 unsigned line;
283 exec->iterate([&] (StackVisitor& visitor) {
284 if (!iteratedOnce) {
285 iteratedOnce = true;
286 return StackVisitor::Continue;
287 }
288
289 RELEASE_ASSERT(visitor->hasLineAndColumnInfo());
290 unsigned column;
291 visitor->computeLineAndColumn(line, column);
292 codeBlock = visitor->codeBlock();
293 return StackVisitor::Done;
294 });
295 RELEASE_ASSERT(!!codeBlock);
296 RELEASE_ASSERT_WITH_MESSAGE(false, "JS assertion failed at line %u in:\n%s\n", line, codeBlock->sourceCodeForTools().data());
297 return JSValue::encode(jsUndefined());
298}
299#endif
300
301} // namespace JSC
302
303#include "JSGlobalObject.lut.h"
304
305namespace JSC {
306
307const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, nullptr, CREATE_METHOD_TABLE(JSGlobalObject) };
308
309const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
310 &supportsRichSourceInfo,
311 &shouldInterruptScript,
312 &javaScriptRuntimeFlags,
313 nullptr, // queueTaskToEventLoop
314 &shouldInterruptScriptBeforeTimeout,
315 nullptr, // moduleLoaderImportModule
316 nullptr, // moduleLoaderResolve
317 nullptr, // moduleLoaderFetch
318 nullptr, // moduleLoaderCreateImportMetaProperties
319 nullptr, // moduleLoaderEvaluate
320 nullptr, // promiseRejectionTracker
321 nullptr, // defaultLanguage
322 nullptr, // compileStreaming
323 nullptr, // instantiateStreaming
324};
325
326/* Source for JSGlobalObject.lut.h
327@begin globalObjectTable
328 isNaN JSBuiltin DontEnum|Function 1
329 isFinite JSBuiltin DontEnum|Function 1
330 escape globalFuncEscape DontEnum|Function 1
331 unescape globalFuncUnescape DontEnum|Function 1
332 decodeURI globalFuncDecodeURI DontEnum|Function 1
333 decodeURIComponent globalFuncDecodeURIComponent DontEnum|Function 1
334 encodeURI globalFuncEncodeURI DontEnum|Function 1
335 encodeURIComponent globalFuncEncodeURIComponent DontEnum|Function 1
336 eval JSGlobalObject::m_evalFunction DontEnum|CellProperty
337 globalThis JSGlobalObject::m_globalThis DontEnum|CellProperty
338 parseInt JSGlobalObject::m_parseIntFunction DontEnum|CellProperty
339 parseFloat JSGlobalObject::m_parseFloatFunction DontEnum|CellProperty
340 ArrayBuffer JSGlobalObject::m_arrayBufferStructure DontEnum|ClassStructure
341 EvalError JSGlobalObject::m_evalErrorStructure DontEnum|ClassStructure
342 RangeError JSGlobalObject::m_rangeErrorStructure DontEnum|ClassStructure
343 ReferenceError JSGlobalObject::m_referenceErrorStructure DontEnum|ClassStructure
344 SyntaxError JSGlobalObject::m_syntaxErrorStructure DontEnum|ClassStructure
345 TypeError JSGlobalObject::m_typeErrorStructure DontEnum|ClassStructure
346 URIError JSGlobalObject::m_URIErrorStructure DontEnum|ClassStructure
347 Proxy createProxyProperty DontEnum|PropertyCallback
348 Reflect createReflectProperty DontEnum|PropertyCallback
349 JSON createJSONProperty DontEnum|PropertyCallback
350 Math createMathProperty DontEnum|PropertyCallback
351 console createConsoleProperty DontEnum|PropertyCallback
352 Int8Array JSGlobalObject::m_typedArrayInt8 DontEnum|ClassStructure
353 Int16Array JSGlobalObject::m_typedArrayInt16 DontEnum|ClassStructure
354 Int32Array JSGlobalObject::m_typedArrayInt32 DontEnum|ClassStructure
355 Uint8Array JSGlobalObject::m_typedArrayUint8 DontEnum|ClassStructure
356 Uint8ClampedArray JSGlobalObject::m_typedArrayUint8Clamped DontEnum|ClassStructure
357 Uint16Array JSGlobalObject::m_typedArrayUint16 DontEnum|ClassStructure
358 Uint32Array JSGlobalObject::m_typedArrayUint32 DontEnum|ClassStructure
359 Float32Array JSGlobalObject::m_typedArrayFloat32 DontEnum|ClassStructure
360 Float64Array JSGlobalObject::m_typedArrayFloat64 DontEnum|ClassStructure
361 DataView JSGlobalObject::m_typedArrayDataView DontEnum|ClassStructure
362 Date JSGlobalObject::m_dateStructure DontEnum|ClassStructure
363 Error JSGlobalObject::m_errorStructure DontEnum|ClassStructure
364 Boolean JSGlobalObject::m_booleanObjectStructure DontEnum|ClassStructure
365 Number JSGlobalObject::m_numberObjectStructure DontEnum|ClassStructure
366 Symbol JSGlobalObject::m_symbolObjectStructure DontEnum|ClassStructure
367 WeakMap JSGlobalObject::m_weakMapStructure DontEnum|ClassStructure
368 WeakSet JSGlobalObject::m_weakSetStructure DontEnum|ClassStructure
369@end
370*/
371
372static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
373{
374 VM& vm = exec->vm();
375 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
376
377 JSValue job = exec->argument(0);
378 JSValue arguments = exec->argument(1);
379 ASSERT(arguments.inherits<JSArray>(vm));
380
381 globalObject->queueMicrotask(createJSMicrotask(vm, job, jsCast<JSArray*>(arguments)));
382
383 return JSValue::encode(jsUndefined());
384}
385
386JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
387 : Base(vm, structure, 0)
388 , m_vm(vm)
389 , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
390 , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
391 , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
392 , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
393 , m_arrayIteratorProtocolWatchpoint(IsWatched)
394 , m_mapIteratorProtocolWatchpoint(IsWatched)
395 , m_setIteratorProtocolWatchpoint(IsWatched)
396 , m_stringIteratorProtocolWatchpoint(IsWatched)
397 , m_mapSetWatchpoint(IsWatched)
398 , m_setAddWatchpoint(IsWatched)
399 , m_arraySpeciesWatchpoint(ClearWatchpoint)
400 , m_numberToStringWatchpoint(IsWatched)
401 , m_runtimeFlags()
402 , m_stackTraceLimit(Options::defaultErrorStackTraceLimit())
403 , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
404{
405}
406
407JSGlobalObject::~JSGlobalObject()
408{
409#if ENABLE(REMOTE_INSPECTOR)
410 m_inspectorController->globalObjectDestroyed();
411#endif
412
413 if (m_debugger)
414 m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
415}
416
417void JSGlobalObject::destroy(JSCell* cell)
418{
419 static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
420}
421
422void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
423{
424 m_globalThis.set(vm, this, globalThis);
425}
426
427static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier& ident)
428{
429 JSValue baseValue = JSValue(base);
430 PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry);
431 baseValue.getPropertySlot(exec, ident, slot);
432 return slot.getPureResult().toObject(exec);
433}
434
435template<ErrorType errorType>
436void JSGlobalObject::initializeErrorConstructor(LazyClassStructure::Initializer& init)
437{
438 init.setPrototype(NativeErrorPrototype::create(init.vm, NativeErrorPrototype::createStructure(init.vm, this, m_errorStructure.prototype(this)), errorTypeName(errorType)));
439 init.setStructure(ErrorInstance::createStructure(init.vm, this, init.prototype));
440 init.setConstructor(NativeErrorConstructor<errorType>::create(init.vm, NativeErrorConstructor<errorType>::createStructure(init.vm, this, m_errorStructure.constructor(this)), jsCast<NativeErrorPrototype*>(init.prototype)));
441}
442
443void JSGlobalObject::init(VM& vm)
444{
445 ASSERT(vm.currentThreadIsHoldingAPILock());
446 auto catchScope = DECLARE_CATCH_SCOPE(vm);
447
448 Base::setStructure(vm, Structure::toCacheableDictionaryTransition(vm, structure(vm)));
449
450 m_debugger = 0;
451
452#if ENABLE(REMOTE_INSPECTOR)
453 m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
454 m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
455 m_inspectorDebuggable->init();
456 m_consoleClient = m_inspectorController->consoleClient();
457#endif
458
459 m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
460 m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
461
462 m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
463 // Need to create the callee structure (above) before creating the callee.
464 JSCallee* globalCallee = JSCallee::create(vm, this, globalScope());
465 m_globalCallee.set(vm, this, globalCallee);
466
467 ExecState::initGlobalExec(JSGlobalObject::globalExec(), globalCallee);
468 ExecState* exec = JSGlobalObject::globalExec();
469
470 JSCallee* stackOverflowFrameCallee = JSCallee::create(vm, this, globalScope());
471 m_stackOverflowFrameCallee.set(vm, this, stackOverflowFrameCallee);
472
473 m_hostFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
474
475 auto initFunctionStructures = [&] (FunctionStructures& structures) {
476 structures.strictFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
477 structures.sloppyFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
478 structures.arrowFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
479 };
480 initFunctionStructures(m_builtinFunctions);
481 initFunctionStructures(m_ordinaryFunctions);
482
483 m_customGetterSetterFunctionStructure.initLater(
484 [] (const Initializer<Structure>& init) {
485 init.set(JSCustomGetterSetterFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
486 });
487 m_boundFunctionStructure.initLater(
488 [] (const Initializer<Structure>& init) {
489 init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
490 });
491 m_getterSetterStructure.set(vm, this, GetterSetter::createStructure(vm, this, jsNull()));
492 m_nativeStdFunctionStructure.initLater(
493 [] (const Initializer<Structure>& init) {
494 init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
495 });
496 JSFunction* callFunction = nullptr;
497 JSFunction* applyFunction = nullptr;
498 JSFunction* hasInstanceSymbolFunction = nullptr;
499 m_functionPrototype->addFunctionProperties(vm, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
500 m_callFunction.set(vm, this, callFunction);
501 m_applyFunction.set(vm, this, applyFunction);
502 m_arrayProtoToStringFunction.initLater(
503 [] (const Initializer<JSFunction>& init) {
504 init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
505 });
506 m_arrayProtoValuesFunction.initLater(
507 [] (const Initializer<JSFunction>& init) {
508 init.set(JSFunction::create(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
509 });
510 m_initializePromiseFunction.initLater(
511 [] (const Initializer<JSFunction>& init) {
512 init.set(JSFunction::create(init.vm, promiseOperationsInitializePromiseCodeGenerator(init.vm), init.owner));
513 });
514
515 m_iteratorProtocolFunction.initLater(
516 [] (const Initializer<JSFunction>& init) {
517 init.set(JSFunction::create(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
518 });
519
520 m_promiseResolveFunction.initLater(
521 [] (const Initializer<JSFunction>& init) {
522 init.set(JSFunction::create(init.vm, promiseConstructorResolveCodeGenerator(init.vm), init.owner));
523 });
524
525 m_newPromiseCapabilityFunction.set(vm, this, JSFunction::create(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
526 m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
527 m_throwTypeErrorGetterSetter.initLater(
528 [] (const Initializer<GetterSetter>& init) {
529 JSFunction* thrower = init.owner->throwTypeErrorFunction();
530 GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner, thrower, thrower);
531 init.set(getterSetter);
532 });
533
534 m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
535 m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
536 m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
537 GetterSetter* protoAccessor = GetterSetter::create(vm, this,
538 JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter, UnderscoreProtoIntrinsic),
539 JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
540 m_objectPrototype->putDirectNonIndexAccessorWithoutTransition(vm, vm.propertyNames->underscoreProto, protoAccessor, PropertyAttribute::Accessor | PropertyAttribute::DontEnum);
541 m_functionPrototype->structure(vm)->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
542 m_objectStructureForObjectConstructor.set(vm, this, vm.structureCache.emptyObjectStructureForPrototype(this, m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
543 m_objectProtoValueOfFunction.set(vm, this, jsCast<JSFunction*>(objectPrototype()->getDirect(vm, vm.propertyNames->valueOf)));
544
545 JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeErrorArgumentsCalleeAndCaller);
546 GetterSetter* getterSetter = GetterSetter::create(vm, this, thrower, thrower);
547 m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.set(vm, this, getterSetter);
548
549 m_functionPrototype->initRestrictedProperties(vm, this);
550
551 m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this, JSFunction::create(vm, globalOperationsSpeciesGetterCodeGenerator(vm), this), nullptr));
552
553 m_typedArrayProto.initLater(
554 [] (const Initializer<JSTypedArrayViewPrototype>& init) {
555 init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
556
557 // Make sure that the constructor gets initialized, too.
558 init.owner->m_typedArraySuperConstructor.get(init.owner);
559 });
560 m_typedArraySuperConstructor.initLater(
561 [] (const Initializer<JSTypedArrayViewConstructor>& init) {
562 JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
563 JSTypedArrayViewConstructor* constructor = JSTypedArrayViewConstructor::create(init.vm, init.owner, JSTypedArrayViewConstructor::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()), prototype, init.owner->m_speciesGetterSetter.get());
564 prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
565 init.set(constructor);
566 });
567
568#define INIT_TYPED_ARRAY_LATER(type) \
569 m_typedArray ## type.initLater( \
570 [] (LazyClassStructure::Initializer& init) { \
571 init.setPrototype(JS ## type ## ArrayPrototype::create(init.vm, init.global, JS ## type ## ArrayPrototype::createStructure(init.vm, init.global, init.global->m_typedArrayProto.get(init.global)))); \
572 init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
573 init.setConstructor(JS ## type ## ArrayConstructor::create(init.vm, init.global, JS ## type ## ArrayConstructor::createStructure(init.vm, init.global, init.global->m_typedArraySuperConstructor.get(init.global)), init.prototype, #type "Array"_s, typedArrayConstructorAllocate ## type ## ArrayCodeGenerator(init.vm))); \
574 init.global->putDirectWithoutTransition(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
575 });
576 FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
577#undef INIT_TYPED_ARRAY_LATER
578
579 m_typedArrayDataView.initLater(
580 [] (LazyClassStructure::Initializer& init) {
581 init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
582 init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
583 init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, "DataView"_s, nullptr));
584 });
585
586 m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
587 m_moduleEnvironmentStructure.initLater(
588 [] (const Initializer<Structure>& init) {
589 init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
590 });
591 m_strictEvalActivationStructure.initLater(
592 [] (const Initializer<Structure>& init) {
593 init.set(StrictEvalActivation::createStructure(init.vm, init.owner, jsNull()));
594 });
595 m_debuggerScopeStructure.initLater(
596 [] (const Initializer<Structure>& init) {
597 init.set(DebuggerScope::createStructure(init.vm, init.owner));
598 });
599 m_withScopeStructure.initLater(
600 [] (const Initializer<Structure>& init) {
601 init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
602 });
603
604 m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
605
606 m_callbackFunctionStructure.initLater(
607 [] (const Initializer<Structure>& init) {
608 init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
609 });
610 m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
611 m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
612 m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
613 m_callbackConstructorStructure.initLater(
614 [] (const Initializer<Structure>& init) {
615 init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
616 });
617 m_callbackObjectStructure.initLater(
618 [] (const Initializer<Structure>& init) {
619 init.set(JSCallbackObject<JSDestructibleObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
620 });
621
622#if JSC_OBJC_API_ENABLED
623 m_objcCallbackFunctionStructure.initLater(
624 [] (const Initializer<Structure>& init) {
625 init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
626 });
627 m_objcWrapperObjectStructure.initLater(
628 [] (const Initializer<Structure>& init) {
629 init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
630 });
631#endif
632#ifdef JSC_GLIB_API_ENABLED
633 m_glibCallbackFunctionStructure.initLater(
634 [] (const Initializer<Structure>& init) {
635 init.set(JSCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
636 });
637 m_glibWrapperObjectStructure.initLater(
638 [] (const Initializer<Structure>& init) {
639 init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
640 });
641#endif
642 m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
643
644 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(UndecidedShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
645 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(Int32Shape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
646 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(DoubleShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
647 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ContiguousShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
648 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
649 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(SlowPutArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
650 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithInt32)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithInt32));
651 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithDouble)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithDouble));
652 m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithContiguous));
653 for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
654 m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
655
656 m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
657 m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
658 m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
659 m_regExpMatchesArrayWithGroupsStructure.set(vm, this, createRegExpMatchesArrayWithGroupsStructure(vm, this));
660
661 m_moduleRecordStructure.initLater(
662 [] (const Initializer<Structure>& init) {
663 init.set(JSModuleRecord::createStructure(init.vm, init.owner, jsNull()));
664 });
665 m_moduleNamespaceObjectStructure.initLater(
666 [] (const Initializer<Structure>& init) {
667 init.set(JSModuleNamespaceObject::createStructure(init.vm, init.owner, jsNull()));
668 });
669 m_proxyObjectStructure.initLater(
670 [] (const Initializer<Structure>& init) {
671 bool isCallable = false;
672 init.set(ProxyObject::createStructure(init.vm, init.owner, jsNull(), isCallable));
673 });
674 m_callableProxyObjectStructure.initLater(
675 [] (const Initializer<Structure>& init) {
676 bool isCallable = true;
677 init.set(ProxyObject::createStructure(init.vm, init.owner, jsNull(), isCallable));
678 });
679 m_proxyRevokeStructure.initLater(
680 [] (const Initializer<Structure>& init) {
681 init.set(ProxyRevoke::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
682 });
683
684 m_parseIntFunction.initLater(
685 [] (const Initializer<JSFunction>& init) {
686 init.set(JSFunction::create(init.vm, init.owner, 2, init.vm.propertyNames->parseInt.string(), globalFuncParseInt, ParseIntIntrinsic));
687 });
688 m_parseFloatFunction.initLater(
689 [] (const Initializer<JSFunction>& init) {
690 init.set(JSFunction::create(init.vm, init.owner, 1, init.vm.propertyNames->parseFloat.string(), globalFuncParseFloat, NoIntrinsic));
691 });
692
693#if ENABLE(SHARED_ARRAY_BUFFER)
694 m_sharedArrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Shared));
695 m_sharedArrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_sharedArrayBufferPrototype.get()));
696#endif
697
698 m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
699 m_asyncIteratorPrototype.set(vm, this, AsyncIteratorPrototype::create(vm, this, AsyncIteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
700
701 m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
702 m_asyncGeneratorPrototype.set(vm, this, AsyncGeneratorPrototype::create(vm, this, AsyncGeneratorPrototype::createStructure(vm, this, m_asyncIteratorPrototype.get())));
703
704#define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
705 m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_ ## prototypeBase ## Prototype.get()))); \
706 m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get())); \
707 } while (0);
708
709 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
710
711 if (UNLIKELY(Options::useBigInt()))
712 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
713
714 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
715
716#undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
717
718#define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
719 m_ ## properName ## Structure.initLater(\
720 [] (LazyClassStructure::Initializer& init) { \
721 init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_ ## prototypeBase ## Prototype.get()))); \
722 init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
723 init.setConstructor(capitalName ## Constructor::create(init.vm, capitalName ## Constructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), jsCast<capitalName ## Prototype*>(init.prototype), init.global->m_speciesGetterSetter.get())); \
724 });
725
726 FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
727
728 // Constructors
729
730 ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
731 m_objectConstructor.set(vm, this, objectConstructor);
732
733 JSFunction* throwTypeErrorFunction = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
734 m_throwTypeErrorFunction.set(vm, this, throwTypeErrorFunction);
735
736 JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
737
738 ArrayConstructor* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
739 m_arrayConstructor.set(vm, this, arrayConstructor);
740
741 RegExpConstructor* regExpConstructor = RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get());
742 m_regExpGlobalData.cachedResult().record(vm, this, nullptr, jsEmptyString(&vm), MatchResult(0, 0));
743
744#if ENABLE(SHARED_ARRAY_BUFFER)
745 JSSharedArrayBufferConstructor* sharedArrayBufferConstructor = nullptr;
746 sharedArrayBufferConstructor = JSSharedArrayBufferConstructor::create(vm, JSSharedArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_sharedArrayBufferPrototype.get(), m_speciesGetterSetter.get());
747 m_sharedArrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
748
749 AtomicsObject* atomicsObject = AtomicsObject::create(vm, this, AtomicsObject::createStructure(vm, this, m_objectPrototype.get()));
750#endif
751
752#define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
753capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()); \
754m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
755
756 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
757 BigIntConstructor* bigIntConstructor = nullptr;
758 if (UNLIKELY(Options::useBigInt())) {
759 bigIntConstructor = BigIntConstructor::create(vm, BigIntConstructor::createStructure(vm, this, m_functionPrototype.get()), m_bigIntPrototype.get(), m_speciesGetterSetter.get());
760 m_bigIntPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, bigIntConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
761 }
762
763#undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
764
765 m_promiseConstructor.set(vm, this, promiseConstructor);
766 m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
767
768 m_evalErrorStructure.initLater(
769 [] (LazyClassStructure::Initializer& init) {
770 init.global->initializeErrorConstructor<ErrorType::EvalError>(init);
771 });
772 m_rangeErrorStructure.initLater(
773 [] (LazyClassStructure::Initializer& init) {
774 init.global->initializeErrorConstructor<ErrorType::RangeError>(init);
775 });
776 m_referenceErrorStructure.initLater(
777 [] (LazyClassStructure::Initializer& init) {
778 init.global->initializeErrorConstructor<ErrorType::ReferenceError>(init);
779 });
780 m_syntaxErrorStructure.initLater(
781 [] (LazyClassStructure::Initializer& init) {
782 init.global->initializeErrorConstructor<ErrorType::SyntaxError>(init);
783 });
784 m_typeErrorStructure.initLater(
785 [] (LazyClassStructure::Initializer& init) {
786 init.global->initializeErrorConstructor<ErrorType::TypeError>(init);
787 });
788 m_URIErrorStructure.initLater(
789 [] (LazyClassStructure::Initializer& init) {
790 init.global->initializeErrorConstructor<ErrorType::URIError>(init);
791 });
792
793 m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
794 GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
795 m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
796 m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
797
798 m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
799 m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
800
801 m_asyncFunctionPrototype.set(vm, this, AsyncFunctionPrototype::create(vm, AsyncFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
802 AsyncFunctionConstructor* asyncFunctionConstructor = AsyncFunctionConstructor::create(vm, AsyncFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncFunctionPrototype.get());
803 m_asyncFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
804 m_asyncFunctionStructure.set(vm, this, JSAsyncFunction::createStructure(vm, this, m_asyncFunctionPrototype.get()));
805
806 m_asyncGeneratorFunctionPrototype.set(vm, this, AsyncGeneratorFunctionPrototype::create(vm, AsyncGeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
807 AsyncGeneratorFunctionConstructor* asyncGeneratorFunctionConstructor = AsyncGeneratorFunctionConstructor::create(vm, AsyncGeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncGeneratorFunctionPrototype.get());
808 m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncGeneratorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
809 m_asyncGeneratorFunctionStructure.set(vm, this, JSAsyncGeneratorFunction::createStructure(vm, this, m_asyncGeneratorFunctionPrototype.get()));
810
811 m_asyncGeneratorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_asyncGeneratorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
812 m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_asyncGeneratorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
813
814 m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
815 m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
816 m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
817 m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
818
819 putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
820 putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
821 putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
822 putDirectWithoutTransition(vm, vm.propertyNames->RegExp, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
823
824 putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ObjectPrivateName(), objectConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
825 putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ArrayPrivateName(), arrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
826
827#if ENABLE(SHARED_ARRAY_BUFFER)
828 putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
829 putDirectWithoutTransition(vm, Identifier::fromString(exec, "Atomics"), atomicsObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
830#endif
831
832#define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
833putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
834
835 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
836 if (UNLIKELY(Options::useBigInt()))
837 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
838
839#undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
840 m_iteratorResultObjectStructure.initLater(
841 [] (const Initializer<Structure>& init) {
842 init.set(createIteratorResultObjectStructure(init.vm, *init.owner));
843 });
844
845 m_evalFunction.initLater(
846 [] (const Initializer<JSFunction>& init) {
847 init.set(JSFunction::create(init.vm, init.owner, 1, init.vm.propertyNames->eval.string(), globalFuncEval, NoIntrinsic));
848 });
849
850#if ENABLE(INTL)
851 m_collatorStructure.initLater(
852 [] (const Initializer<Structure>& init) {
853 JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
854 IntlCollatorPrototype* collatorPrototype = IntlCollatorPrototype::create(init.vm, globalObject, IntlCollatorPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
855 init.set(IntlCollator::createStructure(init.vm, globalObject, collatorPrototype));
856 });
857 m_numberFormatStructure.initLater(
858 [] (const Initializer<Structure>& init) {
859 JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
860 IntlNumberFormatPrototype* numberFormatPrototype = IntlNumberFormatPrototype::create(init.vm, globalObject, IntlNumberFormatPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
861 init.set(IntlNumberFormat::createStructure(init.vm, globalObject, numberFormatPrototype));
862 });
863 m_dateTimeFormatStructure.initLater(
864 [] (const Initializer<Structure>& init) {
865 JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
866 IntlDateTimeFormatPrototype* dateTimeFormatPrototype = IntlDateTimeFormatPrototype::create(init.vm, globalObject, IntlDateTimeFormatPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
867 init.set(IntlDateTimeFormat::createStructure(init.vm, globalObject, dateTimeFormatPrototype));
868 });
869 m_pluralRulesStructure.initLater(
870 [] (const Initializer<Structure>& init) {
871 JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
872 IntlPluralRulesPrototype* pluralRulesPrototype = IntlPluralRulesPrototype::create(init.vm, globalObject, IntlPluralRulesPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
873 init.set(IntlPluralRules::createStructure(init.vm, globalObject, pluralRulesPrototype));
874 });
875
876 IntlObject* intl = IntlObject::create(vm, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
877 putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, static_cast<unsigned>(PropertyAttribute::DontEnum));
878#endif // ENABLE(INTL)
879
880 m_moduleLoader.initLater(
881 [] (const Initializer<JSModuleLoader>& init) {
882 auto catchScope = DECLARE_CATCH_SCOPE(init.vm);
883 init.set(JSModuleLoader::create(init.owner->globalExec(), init.vm, init.owner, JSModuleLoader::createStructure(init.vm, init.owner, jsNull())));
884 catchScope.releaseAssertNoException();
885 });
886 if (Options::exposeInternalModuleLoader())
887 putDirectWithoutTransition(vm, vm.propertyNames->Loader, moduleLoader(), static_cast<unsigned>(PropertyAttribute::DontEnum));
888
889 JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
890 JSFunction* builtinDescribe = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinDescribe);
891
892 JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
893
894 JSFunction* privateFuncPropertyIsEnumerable = JSFunction::create(vm, this, 0, String(), globalFuncPropertyIsEnumerable);
895 JSFunction* privateFuncOwnKeys = JSFunction::create(vm, this, 0, String(), globalFuncOwnKeys);
896 JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule);
897 JSFunction* privateFuncMakeTypeError = JSFunction::create(vm, this, 0, String(), globalFuncMakeTypeError);
898 JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
899 JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
900 JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
901 JSFunction* privateFuncIsTypedArrayView = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncIsTypedArrayView, IsTypedArrayViewIntrinsic);
902 JSFunction* privateFuncTypedArraySubarrayCreate = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSubarrayCreate);
903 JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
904 JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
905 JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
906 JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
907#if ENABLE(INTL)
908 JSFunction* privateFuncDateTimeFormat = JSFunction::create(vm, this, 0, String(), globalFuncDateTimeFormat);
909#endif
910 JSFunction* privateFuncIsArrayConstructor = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArrayConstructor);
911 JSFunction* privateFuncIsArraySlow = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArraySlow);
912 JSFunction* privateFuncConcatMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncConcatMemcpy);
913 JSFunction* privateFuncAppendMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncAppendMemcpy);
914 JSFunction* privateFuncMapBucketHead = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketHead, JSMapBucketHeadIntrinsic);
915 JSFunction* privateFuncMapBucketNext = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketNext, JSMapBucketNextIntrinsic);
916 JSFunction* privateFuncMapBucketKey = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketKey, JSMapBucketKeyIntrinsic);
917 JSFunction* privateFuncMapBucketValue = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketValue, JSMapBucketValueIntrinsic);
918 JSFunction* privateFuncSetBucketHead = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketHead, JSSetBucketHeadIntrinsic);
919 JSFunction* privateFuncSetBucketNext = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketNext, JSSetBucketNextIntrinsic);
920 JSFunction* privateFuncSetBucketKey = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketKey, JSSetBucketKeyIntrinsic);
921
922 JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
923 catchScope.assertNoException();
924 JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
925 catchScope.assertNoException();
926 m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
927 JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
928 catchScope.assertNoException();
929 JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
930 catchScope.assertNoException();
931 JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
932 catchScope.assertNoException();
933 JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
934 catchScope.assertNoException();
935 JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
936 catchScope.assertNoException();
937 m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
938 JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
939 m_regExpProtoExec.set(vm, this, builtinRegExpExec);
940 JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
941 m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
942
943#define CREATE_PRIVATE_GLOBAL_FUNCTION(name, code) JSFunction* name ## PrivateFunction = JSFunction::create(vm, code ## CodeGenerator(vm), this);
944 JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(CREATE_PRIVATE_GLOBAL_FUNCTION)
945#undef CREATE_PRIVATE_GLOBAL_FUNCTION
946
947 JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
948 createArrayIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
949
950 JSObject* asyncFromSyncIteratorPrototype = AsyncFromSyncIteratorPrototype::create(vm, this, AsyncFromSyncIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
951 AsyncFromSyncIteratorConstructorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, asyncFromSyncIteratorPrototype);
952
953 JSObject* mapIteratorPrototype = MapIteratorPrototype::create(vm, this, MapIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
954 createMapIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, mapIteratorPrototype);
955
956 JSObject* setIteratorPrototype = SetIteratorPrototype::create(vm, this, SetIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
957 createSetIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, setIteratorPrototype);
958
959 GlobalPropertyInfo staticGlobals[] = {
960#define INIT_PRIVATE_GLOBAL(name, code) GlobalPropertyInfo(vm.propertyNames->builtinNames().name ## PrivateName(), name ## PrivateFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
961 JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
962#undef INIT_PRIVATE_GLOBAL
963 GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
964 GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
965 GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
966 GlobalPropertyInfo(vm.propertyNames->builtinNames().propertyIsEnumerablePrivateName(), privateFuncPropertyIsEnumerable, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
967 GlobalPropertyInfo(vm.propertyNames->builtinNames().ownKeysPrivateName(), privateFuncOwnKeys, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
968 GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
969 GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
970 GlobalPropertyInfo(vm.propertyNames->builtinNames().makeTypeErrorPrivateName(), privateFuncMakeTypeError, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
971 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayLengthPrivateName(), privateFuncTypedArrayLength, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
972 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayGetOriginalConstructorPrivateName(), privateFuncTypedArrayGetOriginalConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
973 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySortPrivateName(), privateFuncTypedArraySort, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
974 GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
975 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySubarrayCreatePrivateName(), privateFuncTypedArraySubarrayCreate, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
976 GlobalPropertyInfo(vm.propertyNames->builtinNames().isBoundFunctionPrivateName(), privateFuncIsBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
977 GlobalPropertyInfo(vm.propertyNames->builtinNames().hasInstanceBoundFunctionPrivateName(), privateFuncHasInstanceBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
978 GlobalPropertyInfo(vm.propertyNames->builtinNames().instanceOfPrivateName(), privateFuncInstanceOf, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
979 GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinLogPrivateName(), builtinLog, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
980 GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinDescribePrivateName(), builtinDescribe, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
981 GlobalPropertyInfo(vm.propertyNames->builtinNames().RegExpPrivateName(), regExpConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
982 GlobalPropertyInfo(vm.propertyNames->builtinNames().truncPrivateName(), privateFuncTrunc, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
983 GlobalPropertyInfo(vm.propertyNames->builtinNames().PromisePrivateName(), promiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
984 GlobalPropertyInfo(vm.propertyNames->builtinNames().InternalPromisePrivateName(), internalPromiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
985
986 GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharacterPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
987 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayPrivateName(), arrayConstructor->getDirect(vm, vm.propertyNames->isArray), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
988 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArraySlowPrivateName(), privateFuncIsArraySlow, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
989 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayConstructorPrivateName(), privateFuncIsArrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
990 GlobalPropertyInfo(vm.propertyNames->builtinNames().concatMemcpyPrivateName(), privateFuncConcatMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
991 GlobalPropertyInfo(vm.propertyNames->builtinNames().appendMemcpyPrivateName(), privateFuncAppendMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
992
993 GlobalPropertyInfo(vm.propertyNames->builtinNames().hostPromiseRejectionTrackerPrivateName(), JSFunction::create(vm, this, 2, String(), globalFuncHostPromiseRejectionTracker), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
994 GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
995 GlobalPropertyInfo(vm.propertyNames->builtinNames().SetPrivateName(), setConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
996 GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
997#if ENABLE(INTL)
998 GlobalPropertyInfo(vm.propertyNames->builtinNames().dateTimeFormatPrivateName(), privateFuncDateTimeFormat, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
999#endif // ENABLE(INTL)
1000
1001 GlobalPropertyInfo(vm.propertyNames->builtinNames().isConstructorPrivateName(), JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1002
1003 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoFlagsGetterPrivateName(), regExpProtoFlagsGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1004 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoGlobalGetterPrivateName(), regExpProtoGlobalGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1005 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoIgnoreCaseGetterPrivateName(), regExpProtoIgnoreCaseGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1006 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoMultilineGetterPrivateName(), regExpProtoMultilineGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1007 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoSourceGetterPrivateName(), regExpProtoSourceGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1008 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoStickyGetterPrivateName(), regExpProtoStickyGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1009 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoUnicodeGetterPrivateName(), regExpProtoUnicodeGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1010
1011 // RegExp.prototype helpers.
1012 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpBuiltinExecPrivateName(), builtinRegExpExec, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1013 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpCreatePrivateName(), JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1014 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpMatchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast, RegExpMatchFastIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1015 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSearchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1016 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1017 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpPrototypeSymbolReplacePrivateName(), m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1018 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpTestFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1019
1020 // String.prototype helpers.
1021 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringIncludesInternalPrivateName(), JSFunction::create(vm, this, 1, String(), builtinStringIncludesInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1022 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncSplitFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1023 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSubstrInternalPrivateName(), JSFunction::create(vm, this, 2, String(), builtinStringSubstrInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1024
1025 // Function prototype helpers.
1026 GlobalPropertyInfo(vm.propertyNames->builtinNames().makeBoundFunctionPrivateName(), JSFunction::create(vm, this, 5, String(), makeBoundFunction), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1027 GlobalPropertyInfo(vm.propertyNames->builtinNames().hasOwnLengthPropertyPrivateName(), JSFunction::create(vm, this, 1, String(), hasOwnLengthProperty), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1028
1029 // Map and Set helpers.
1030 GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketHeadPrivateName(), privateFuncMapBucketHead, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1031 GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketNextPrivateName(), privateFuncMapBucketNext, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1032 GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketKeyPrivateName(), privateFuncMapBucketKey, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1033 GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketValuePrivateName(), privateFuncMapBucketValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1034 GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketHeadPrivateName(), privateFuncSetBucketHead, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1035 GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketNextPrivateName(), privateFuncSetBucketNext, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1036 GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketKeyPrivateName(), privateFuncSetBucketKey, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1037#if ENABLE(WEBASSEMBLY) && ENABLE(WEBASSEMBLY_STREAMING_API)
1038 // WebAssembly Streaming API
1039 GlobalPropertyInfo(vm.propertyNames->builtinNames().webAssemblyCompileStreamingInternalPrivateName(), JSFunction::create(vm, this, 1, String(), webAssemblyCompileStreamingInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1040 GlobalPropertyInfo(vm.propertyNames->builtinNames().webAssemblyInstantiateStreamingInternalPrivateName(), JSFunction::create(vm, this, 1, String(), webAssemblyInstantiateStreamingInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1041#endif
1042#if !ASSERT_DISABLED
1043 GlobalPropertyInfo(vm.propertyNames->builtinNames().assertPrivateName(), JSFunction::create(vm, this, 1, String(), assertCall), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1044#endif
1045 };
1046 addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
1047
1048 m_specialPointers[Special::CallFunction] = m_callFunction.get();
1049 m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
1050 m_specialPointers[Special::ObjectConstructor] = objectConstructor;
1051 m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
1052
1053 m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::ThrowTypeErrorFunction)] = m_throwTypeErrorFunction.get();
1054
1055 if (UNLIKELY(Options::useDollarVM()))
1056 exposeDollarVM(vm);
1057
1058#if ENABLE(WEBASSEMBLY)
1059 if (Wasm::isSupported()) {
1060 auto* webAssemblyPrototype = WebAssemblyPrototype::create(vm, this, WebAssemblyPrototype::createStructure(vm, this, m_objectPrototype.get()));
1061 m_webAssemblyModuleRecordStructure.initLater(
1062 [] (const Initializer<Structure>& init) {
1063 init.set(WebAssemblyModuleRecord::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
1064 });
1065 m_webAssemblyFunctionStructure.initLater(
1066 [] (const Initializer<Structure>& init) {
1067 init.set(WebAssemblyFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
1068 });
1069 m_jsToWasmICCalleeStructure.initLater(
1070 [] (const Initializer<Structure>& init) {
1071 init.set(JSToWasmICCallee::createStructure(init.vm, init.owner, JSValue()));
1072 });
1073 m_webAssemblyWrapperFunctionStructure.initLater(
1074 [] (const Initializer<Structure>& init) {
1075 init.set(WebAssemblyWrapperFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
1076 });
1077 m_webAssemblyToJSCalleeStructure.initLater(
1078 [] (const Initializer<Structure>& init) {
1079 init.set(WebAssemblyToJSCallee::createStructure(init.vm, init.owner, jsNull()));
1080 });
1081 auto* webAssembly = JSWebAssembly::create(vm, this, JSWebAssembly::createStructure(vm, this, webAssemblyPrototype));
1082 putDirectWithoutTransition(vm, Identifier::fromString(exec, "WebAssembly"), webAssembly, static_cast<unsigned>(PropertyAttribute::DontEnum));
1083
1084#define CREATE_WEBASSEMBLY_PROTOTYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1085 m_ ## properName ## Structure.initLater(\
1086 [] (LazyClassStructure::Initializer& init) { \
1087 init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->prototypeBase ## Prototype()))); \
1088 init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
1089 init.setConstructor(capitalName ## Constructor::create(init.vm, capitalName ## Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<capitalName ## Prototype*>(init.prototype))); \
1090 });
1091
1092 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(CREATE_WEBASSEMBLY_PROTOTYPE)
1093
1094#undef CREATE_WEBASSEMBLY_CONSTRUCTOR
1095 }
1096#endif // ENABLE(WEBASSEMBLY)
1097
1098#undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
1099
1100 auto setupAdaptiveWatchpoint = [&] (JSObject* base, const Identifier& ident) -> ObjectPropertyCondition {
1101 // Performing these gets should not throw.
1102 ExecState* exec = globalExec();
1103 PropertySlot slot(base, PropertySlot::InternalMethodType::Get);
1104 bool result = base->getOwnPropertySlot(base, exec, ident, slot);
1105 ASSERT_UNUSED(result, result);
1106 catchScope.assertNoException();
1107 RELEASE_ASSERT(slot.isCacheableValue());
1108 JSValue functionValue = slot.getValue(exec, ident);
1109 catchScope.assertNoException();
1110 ASSERT(jsDynamicCast<JSFunction*>(vm, functionValue));
1111
1112 ObjectPropertyCondition condition = generateConditionForSelfEquivalence(m_vm, nullptr, base, ident.impl());
1113 RELEASE_ASSERT(condition.requiredValue() == functionValue);
1114
1115 bool isWatchable = condition.isWatchable(PropertyCondition::EnsureWatchability);
1116 RELEASE_ASSERT(isWatchable); // We allow this to install the necessary watchpoints.
1117
1118 return condition;
1119 };
1120
1121 {
1122 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(arrayIteratorPrototype, m_vm.propertyNames->next);
1123 m_arrayIteratorPrototypeNext = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_arrayIteratorProtocolWatchpoint);
1124 m_arrayIteratorPrototypeNext->install(vm);
1125 }
1126 {
1127 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this->arrayPrototype(), m_vm.propertyNames->iteratorSymbol);
1128 m_arrayPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_arrayIteratorProtocolWatchpoint);
1129 m_arrayPrototypeSymbolIteratorWatchpoint->install(vm);
1130 }
1131
1132 {
1133 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(mapIteratorPrototype, m_vm.propertyNames->next);
1134 m_mapIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_mapIteratorProtocolWatchpoint);
1135 m_mapIteratorPrototypeNextWatchpoint->install(vm);
1136 }
1137 {
1138 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_mapPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1139 m_mapPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_mapIteratorProtocolWatchpoint);
1140 m_mapPrototypeSymbolIteratorWatchpoint->install(vm);
1141 }
1142
1143 {
1144 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(setIteratorPrototype, m_vm.propertyNames->next);
1145 m_setIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_setIteratorProtocolWatchpoint);
1146 m_setIteratorPrototypeNextWatchpoint->install(vm);
1147 }
1148 {
1149 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_setPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1150 m_setPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_setIteratorProtocolWatchpoint);
1151 m_setPrototypeSymbolIteratorWatchpoint->install(vm);
1152 }
1153
1154 {
1155 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_stringIteratorPrototype.get(), m_vm.propertyNames->next);
1156 m_stringIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_stringIteratorProtocolWatchpoint);
1157 m_stringIteratorPrototypeNextWatchpoint->install(vm);
1158 }
1159 {
1160 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_stringPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1161 m_stringPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_stringIteratorProtocolWatchpoint);
1162 m_stringPrototypeSymbolIteratorWatchpoint->install(vm);
1163 }
1164
1165 {
1166 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_mapPrototype.get(), m_vm.propertyNames->set);
1167 m_mapPrototypeSetWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_mapSetWatchpoint);
1168 m_mapPrototypeSetWatchpoint->install(vm);
1169 }
1170
1171 {
1172 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_setPrototype.get(), m_vm.propertyNames->add);
1173 m_setPrototypeAddWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_setAddWatchpoint);
1174 m_setPrototypeAddWatchpoint->install(vm);
1175 }
1176
1177 // Unfortunately, the prototype objects of the builtin objects can be touched from concurrent compilers. So eagerly initialize them only if we use JIT.
1178 if (VM::canUseJIT()) {
1179 this->booleanPrototype();
1180 auto* numberPrototype = this->numberPrototype();
1181 this->symbolPrototype();
1182
1183 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(numberPrototype, m_vm.propertyNames->toString);
1184 m_numberPrototypeToStringWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_numberToStringWatchpoint);
1185 m_numberPrototypeToStringWatchpoint->install(vm);
1186 m_numberProtoToStringFunction.set(vm, this, jsCast<JSFunction*>(numberPrototype->getDirect(vm, vm.propertyNames->toString)));
1187 }
1188
1189 fixupPrototypeChainWithObjectPrototype(vm);
1190}
1191
1192bool JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
1193{
1194 VM& vm = exec->vm();
1195 auto scope = DECLARE_THROW_SCOPE(vm);
1196 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1197 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
1198
1199 if (UNLIKELY(isThisValueAltered(slot, thisObject)))
1200 RELEASE_AND_RETURN(scope, ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode()));
1201
1202 bool shouldThrowReadOnlyError = slot.isStrictMode();
1203 bool ignoreReadOnlyErrors = false;
1204 bool putResult = false;
1205 bool done = symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
1206 EXCEPTION_ASSERT((!!scope.exception() == (done && !putResult)) || !shouldThrowReadOnlyError);
1207 if (done)
1208 return putResult;
1209 RELEASE_AND_RETURN(scope, Base::put(thisObject, exec, propertyName, value, slot));
1210}
1211
1212bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
1213{
1214 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
1215 PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry);
1216 // silently ignore attempts to add accessors aliasing vars.
1217 if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
1218 return false;
1219 return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
1220}
1221
1222void JSGlobalObject::addGlobalVar(const Identifier& ident)
1223{
1224 ConcurrentJSLocker locker(symbolTable()->m_lock);
1225 SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
1226 if (!entry.isNull())
1227 return;
1228
1229 ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1230 SymbolTableEntry newEntry(VarOffset(offset), 0);
1231 newEntry.prepareToWatch();
1232 symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
1233
1234 ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
1235 RELEASE_ASSERT(offsetForAssert == offset);
1236}
1237
1238void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
1239{
1240 VM& vm = exec->vm();
1241 VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
1242 methodTable(vm)->deleteProperty(this, exec, propertyName);
1243 addGlobalVar(propertyName);
1244}
1245
1246void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
1247{
1248 m_globalScopeExtension.set(vm(), this, scope);
1249}
1250
1251void JSGlobalObject::clearGlobalScopeExtension()
1252{
1253 m_globalScopeExtension.clear();
1254}
1255
1256static inline JSObject* lastInPrototypeChain(VM& vm, JSObject* object)
1257{
1258 JSObject* o = object;
1259 while (o->getPrototypeDirect(vm).isObject())
1260 o = asObject(o->getPrototypeDirect(vm));
1261 return o;
1262}
1263
1264// Private namespace for helpers for JSGlobalObject::haveABadTime()
1265namespace {
1266
1267class GlobalObjectDependencyFinder : public MarkedBlock::VoidFunctor {
1268public:
1269 GlobalObjectDependencyFinder(VM& vm)
1270 : m_vm(vm)
1271 { }
1272
1273 IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1274
1275 void addDependency(JSGlobalObject* key, JSGlobalObject* dependent);
1276 HashSet<JSGlobalObject*>* dependentsFor(JSGlobalObject* key);
1277
1278private:
1279 void visit(JSObject*);
1280
1281 VM& m_vm;
1282 HashMap<JSGlobalObject*, HashSet<JSGlobalObject*>> m_dependencies;
1283};
1284
1285inline void GlobalObjectDependencyFinder::addDependency(JSGlobalObject* key, JSGlobalObject* dependent)
1286{
1287 auto keyResult = m_dependencies.add(key, HashSet<JSGlobalObject*>());
1288 keyResult.iterator->value.add(dependent);
1289}
1290
1291inline HashSet<JSGlobalObject*>* GlobalObjectDependencyFinder::dependentsFor(JSGlobalObject* key)
1292{
1293 auto iterator = m_dependencies.find(key);
1294 if (iterator == m_dependencies.end())
1295 return nullptr;
1296 return &iterator->value;
1297}
1298
1299inline void GlobalObjectDependencyFinder::visit(JSObject* object)
1300{
1301 VM& vm = m_vm;
1302
1303 if (!object->mayBePrototype())
1304 return;
1305
1306 JSObject* current = object;
1307 JSGlobalObject* objectGlobalObject = object->globalObject(vm);
1308 do {
1309 JSValue prototypeValue = current->getPrototypeDirect(vm);
1310 if (prototypeValue.isNull())
1311 return;
1312 current = asObject(prototypeValue);
1313
1314 JSGlobalObject* protoGlobalObject = current->globalObject(vm);
1315 if (protoGlobalObject != objectGlobalObject)
1316 addDependency(protoGlobalObject, objectGlobalObject);
1317 } while (true);
1318}
1319
1320IterationStatus GlobalObjectDependencyFinder::operator()(HeapCell* cell, HeapCell::Kind kind) const
1321{
1322 if (isJSCellKind(kind) && static_cast<JSCell*>(cell)->isObject()) {
1323 // FIXME: This const_cast exists because this isn't a C++ lambda.
1324 // https://bugs.webkit.org/show_bug.cgi?id=159644
1325 const_cast<GlobalObjectDependencyFinder*>(this)->visit(jsCast<JSObject*>(static_cast<JSCell*>(cell)));
1326 }
1327 return IterationStatus::Continue;
1328}
1329
1330enum class BadTimeFinderMode {
1331 SingleGlobal,
1332 MultipleGlobals
1333};
1334
1335template<BadTimeFinderMode mode>
1336class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
1337public:
1338 ObjectsWithBrokenIndexingFinder(VM&, Vector<JSObject*>&, JSGlobalObject*);
1339 ObjectsWithBrokenIndexingFinder(VM&, Vector<JSObject*>&, HashSet<JSGlobalObject*>&);
1340
1341 bool needsMultiGlobalsScan() const { return m_needsMultiGlobalsScan; }
1342 IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1343
1344private:
1345 IterationStatus visit(JSObject*);
1346
1347 VM& m_vm;
1348 Vector<JSObject*>& m_foundObjects;
1349 JSGlobalObject* m_globalObject { nullptr }; // Only used for SingleBadTimeGlobal mode.
1350 HashSet<JSGlobalObject*>* m_globalObjects { nullptr }; // Only used for BadTimeGlobalGraph mode;
1351 bool m_needsMultiGlobalsScan { false };
1352};
1353
1354template<>
1355ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::SingleGlobal>::ObjectsWithBrokenIndexingFinder(
1356 VM& vm, Vector<JSObject*>& foundObjects, JSGlobalObject* globalObject)
1357 : m_vm(vm)
1358 , m_foundObjects(foundObjects)
1359 , m_globalObject(globalObject)
1360{
1361}
1362
1363template<>
1364ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::MultipleGlobals>::ObjectsWithBrokenIndexingFinder(
1365 VM& vm, Vector<JSObject*>& foundObjects, HashSet<JSGlobalObject*>& globalObjects)
1366 : m_vm(vm)
1367 , m_foundObjects(foundObjects)
1368 , m_globalObjects(&globalObjects)
1369{
1370}
1371
1372inline bool hasBrokenIndexing(IndexingType type)
1373{
1374 return type && !hasSlowPutArrayStorage(type);
1375}
1376
1377inline bool hasBrokenIndexing(JSObject* object)
1378{
1379 IndexingType type = object->indexingType();
1380 return hasBrokenIndexing(type);
1381}
1382
1383template<BadTimeFinderMode mode>
1384inline IterationStatus ObjectsWithBrokenIndexingFinder<mode>::visit(JSObject* object)
1385{
1386 VM& vm = m_vm;
1387
1388 // We only want to have a bad time in the affected global object, not in the entire
1389 // VM. But we have to be careful, since there may be objects that claim to belong to
1390 // a different global object that have prototypes from our global object.
1391 auto isInAffectedGlobalObject = [&] (JSObject* object) {
1392 JSGlobalObject* objectGlobalObject { nullptr };
1393 bool objectMayBePrototype { false };
1394
1395 if (mode == BadTimeFinderMode::SingleGlobal) {
1396 objectGlobalObject = object->globalObject(vm);
1397 if (objectGlobalObject == m_globalObject)
1398 return true;
1399
1400 objectMayBePrototype = object->mayBePrototype();
1401 }
1402
1403 for (JSObject* current = object; ;) {
1404 JSGlobalObject* currentGlobalObject = current->globalObject(vm);
1405 if (mode == BadTimeFinderMode::SingleGlobal) {
1406 if (objectMayBePrototype && currentGlobalObject != objectGlobalObject)
1407 m_needsMultiGlobalsScan = true;
1408 if (currentGlobalObject == m_globalObject)
1409 return true;
1410 } else {
1411 if (m_globalObjects->contains(currentGlobalObject))
1412 return true;
1413 }
1414
1415 JSValue prototypeValue = current->getPrototypeDirect(vm);
1416 if (prototypeValue.isNull())
1417 return false;
1418 current = asObject(prototypeValue);
1419 }
1420 RELEASE_ASSERT_NOT_REACHED();
1421 };
1422
1423 if (JSFunction* function = jsDynamicCast<JSFunction*>(vm, object)) {
1424 if (FunctionRareData* rareData = function->rareData()) {
1425 // We only use this to cache JSFinalObjects. They do not start off with a broken indexing type.
1426 ASSERT(!(rareData->objectAllocationStructure() && hasBrokenIndexing(rareData->objectAllocationStructure()->indexingType())));
1427
1428 if (Structure* structure = rareData->internalFunctionAllocationStructure()) {
1429 if (hasBrokenIndexing(structure->indexingType())) {
1430 bool isRelevantGlobalObject =
1431 (mode == BadTimeFinderMode::SingleGlobal
1432 ? m_globalObject == structure->globalObject()
1433 : m_globalObjects->contains(structure->globalObject()))
1434 || (structure->hasMonoProto() && !structure->storedPrototype().isNull() && isInAffectedGlobalObject(asObject(structure->storedPrototype())));
1435 if (mode == BadTimeFinderMode::SingleGlobal && m_needsMultiGlobalsScan)
1436 return IterationStatus::Done; // Bailing early and let the MultipleGlobals path handle everything.
1437 if (isRelevantGlobalObject)
1438 rareData->clearInternalFunctionAllocationProfile();
1439 }
1440 }
1441 }
1442 }
1443
1444 // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
1445 if (!hasBrokenIndexing(object))
1446 return IterationStatus::Continue;
1447
1448 if (isInAffectedGlobalObject(object))
1449 m_foundObjects.append(object);
1450
1451 if (mode == BadTimeFinderMode::SingleGlobal && m_needsMultiGlobalsScan)
1452 return IterationStatus::Done; // Bailing early and let the MultipleGlobals path handle everything.
1453
1454 return IterationStatus::Continue;
1455}
1456
1457template<BadTimeFinderMode mode>
1458IterationStatus ObjectsWithBrokenIndexingFinder<mode>::operator()(HeapCell* cell, HeapCell::Kind kind) const
1459{
1460 if (isJSCellKind(kind) && static_cast<JSCell*>(cell)->isObject()) {
1461 // FIXME: This const_cast exists because this isn't a C++ lambda.
1462 // https://bugs.webkit.org/show_bug.cgi?id=159644
1463 return const_cast<ObjectsWithBrokenIndexingFinder*>(this)->visit(jsCast<JSObject*>(static_cast<JSCell*>(cell)));
1464 }
1465 return IterationStatus::Continue;
1466}
1467
1468} // end private namespace for helpers for JSGlobalObject::haveABadTime()
1469
1470void JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut(VM& vm)
1471{
1472 if (isHavingABadTime())
1473 return;
1474
1475 // Make sure that all allocations or indexed storage transitions that are inlining
1476 // the assumption that it's safe to transition to a non-SlowPut array storage don't
1477 // do so anymore.
1478 m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
1479 ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
1480
1481 // Make sure that all JSArray allocations that load the appropriate structure from
1482 // this object now load a structure that uses SlowPut.
1483 for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1484 m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
1485
1486 // Same for any special array structures.
1487 Structure* slowPutStructure;
1488 slowPutStructure = createRegExpMatchesArraySlowPutStructure(vm, this);
1489 m_regExpMatchesArrayStructure.set(vm, this, slowPutStructure);
1490 slowPutStructure = createRegExpMatchesArrayWithGroupsSlowPutStructure(vm, this);
1491 m_regExpMatchesArrayWithGroupsStructure.set(vm, this, slowPutStructure);
1492 slowPutStructure = ClonedArguments::createSlowPutStructure(vm, this, m_objectPrototype.get());
1493 m_clonedArgumentsStructure.set(vm, this, slowPutStructure);
1494};
1495
1496void JSGlobalObject::haveABadTime(VM& vm)
1497{
1498 ASSERT(&vm == &this->vm());
1499
1500 if (isHavingABadTime())
1501 return;
1502
1503 vm.structureCache.clear(); // We may be caching array structures in here.
1504
1505 DeferGC deferGC(vm.heap);
1506
1507 // Consider the following objects and prototype chains:
1508 // O (of global G1) -> A (of global G1)
1509 // B (of global G2) where G2 has a bad time
1510 //
1511 // If we set B as the prototype of A, G1 will need to have a bad time.
1512 // See comments in Structure::mayInterceptIndexedAccesses() for why.
1513 //
1514 // Now, consider the following objects and prototype chains:
1515 // O1 (of global G1) -> A1 (of global G1) -> B1 (of global G2)
1516 // O2 (of global G2) -> A2 (of global G2)
1517 // B2 (of global G3) where G3 has a bad time.
1518 //
1519 // G1 and G2 does not have a bad time, but G3 already has a bad time.
1520 // If we set B2 as the prototype of A2, then G2 needs to have a bad time.
1521 // Note that by induction, G1 also now needs to have a bad time because of
1522 // O1 -> A1 -> B1.
1523 //
1524 // We describe this as global G1 being affected by global G2, and G2 by G3.
1525 // Similarly, we say that G1 is dependent on G2, and G2 on G3.
1526 // Hence, when G3 has a bad time, we need to ensure that all globals that
1527 // are transitively dependent on it also have a bad time (G2 and G1 in this
1528 // example).
1529 //
1530 // Apart from clearing the VM structure cache above, there are 2 more things
1531 // that we have to do when globals have a bad time:
1532 // 1. For each affected global:
1533 // a. Fire its HaveABadTime watchpoint.
1534 // b. Convert all of its array structures to SlowPutArrayStorage.
1535 // 2. Make sure that all affected objects switch to the slow kind of
1536 // indexed storage. An object is considered to be affected if it has
1537 // indexed storage and has a prototype object which may have indexed
1538 // accessors. If the prototype object belongs to a global having a bad
1539 // time, then the prototype object is considered to possibly have indexed
1540 // accessors. See comments in Structure::mayInterceptIndexedAccesses()
1541 // for details.
1542 //
1543 // Note: step 1 must be completed before step 2 because step 2 relies on
1544 // the HaveABadTime watchpoint having already been fired on all affected
1545 // globals.
1546 //
1547 // In the common case, only this global will start having a bad time here,
1548 // and no other globals are affected by it. So, we first proceed on this assumption
1549 // with a simpler ObjectsWithBrokenIndexingFinder scan to find heap objects
1550 // affected by this global that need to be converted to SlowPutArrayStorage.
1551 // We'll also have the finder check for the presence of other global objects
1552 // depending on this one.
1553 //
1554 // If we do discover other globals depending on this one, we'll abort this
1555 // first ObjectsWithBrokenIndexingFinder scan because it will be insufficient
1556 // to find all affected objects that need to be converted to SlowPutArrayStorage.
1557 // It also does not make dependent globals have a bad time. Instead, we'll
1558 // take a more comprehensive approach of first creating a dependency graph
1559 // between globals, and then using that graph to determine all affected
1560 // globals and objects. With that, we can make all affected globals have a
1561 // bad time, and convert all affected objects to SlowPutArrayStorage.
1562
1563 fireWatchpointAndMakeAllArrayStructuresSlowPut(vm); // Step 1 above.
1564
1565 Vector<JSObject*> foundObjects;
1566 ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::SingleGlobal> finder(vm, foundObjects, this);
1567 {
1568 HeapIterationScope iterationScope(vm.heap);
1569 vm.heap.objectSpace().forEachLiveCell(iterationScope, finder); // Attempt step 2 above.
1570 }
1571
1572 if (finder.needsMultiGlobalsScan()) {
1573 foundObjects.clear();
1574
1575 // Find all globals that will also have a bad time as a side effect of
1576 // this global having a bad time.
1577 GlobalObjectDependencyFinder dependencies(vm);
1578 {
1579 HeapIterationScope iterationScope(vm.heap);
1580 vm.heap.objectSpace().forEachLiveCell(iterationScope, dependencies);
1581 }
1582
1583 HashSet<JSGlobalObject*> globalsHavingABadTime;
1584 Deque<JSGlobalObject*> globals;
1585
1586 globals.append(this);
1587 while (!globals.isEmpty()) {
1588 JSGlobalObject* global = globals.takeFirst();
1589 global->fireWatchpointAndMakeAllArrayStructuresSlowPut(vm); // Step 1 above.
1590 auto result = globalsHavingABadTime.add(global);
1591 if (result.isNewEntry) {
1592 if (HashSet<JSGlobalObject*>* dependents = dependencies.dependentsFor(global)) {
1593 for (JSGlobalObject* dependentGlobal : *dependents)
1594 globals.append(dependentGlobal);
1595 }
1596 }
1597 }
1598
1599 ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::MultipleGlobals> finder(vm, foundObjects, globalsHavingABadTime);
1600 {
1601 HeapIterationScope iterationScope(vm.heap);
1602 vm.heap.objectSpace().forEachLiveCell(iterationScope, finder); // Step 2 above.
1603 }
1604 }
1605
1606 while (!foundObjects.isEmpty()) {
1607 JSObject* object = asObject(foundObjects.last());
1608 foundObjects.removeLast();
1609 ASSERT(hasBrokenIndexing(object));
1610 object->switchToSlowPutArrayStorage(vm);
1611 }
1612}
1613
1614void JSGlobalObject::fixupPrototypeChainWithObjectPrototype(VM& vm)
1615{
1616 JSObject* oldLastInPrototypeChain = lastInPrototypeChain(vm, this);
1617 JSObject* objectPrototype = m_objectPrototype.get();
1618 if (oldLastInPrototypeChain != objectPrototype)
1619 oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1620}
1621
1622// Set prototype, and also insert the object prototype at the end of the chain.
1623void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1624{
1625 if (getPrototypeDirect(vm) == prototype)
1626 return;
1627 setPrototypeDirect(vm, prototype);
1628 fixupPrototypeChainWithObjectPrototype(vm);
1629 // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1630 setGlobalThis(vm, JSNonDestructibleProxy::create(vm, JSNonDestructibleProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1631}
1632
1633void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1634{
1635 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1636 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1637 Base::visitChildren(thisObject, visitor);
1638
1639 visitor.append(thisObject->m_globalThis);
1640
1641 visitor.append(thisObject->m_globalLexicalEnvironment);
1642 visitor.append(thisObject->m_globalScopeExtension);
1643 visitor.append(thisObject->m_globalCallee);
1644 visitor.append(thisObject->m_stackOverflowFrameCallee);
1645 thisObject->m_evalErrorStructure.visit(visitor);
1646 thisObject->m_rangeErrorStructure.visit(visitor);
1647 thisObject->m_referenceErrorStructure.visit(visitor);
1648 thisObject->m_syntaxErrorStructure.visit(visitor);
1649 thisObject->m_typeErrorStructure.visit(visitor);
1650 thisObject->m_URIErrorStructure.visit(visitor);
1651 visitor.append(thisObject->m_objectConstructor);
1652 visitor.append(thisObject->m_promiseConstructor);
1653
1654#if ENABLE(INTL)
1655 visitor.append(thisObject->m_defaultCollator);
1656 thisObject->m_collatorStructure.visit(visitor);
1657 thisObject->m_numberFormatStructure.visit(visitor);
1658 thisObject->m_dateTimeFormatStructure.visit(visitor);
1659 thisObject->m_pluralRulesStructure.visit(visitor);
1660#endif
1661 visitor.append(thisObject->m_nullGetterFunction);
1662 visitor.append(thisObject->m_nullSetterFunction);
1663
1664 thisObject->m_parseIntFunction.visit(visitor);
1665 thisObject->m_parseFloatFunction.visit(visitor);
1666 visitor.append(thisObject->m_callFunction);
1667 visitor.append(thisObject->m_applyFunction);
1668 visitor.append(thisObject->m_throwTypeErrorFunction);
1669 thisObject->m_arrayProtoToStringFunction.visit(visitor);
1670 thisObject->m_arrayProtoValuesFunction.visit(visitor);
1671 thisObject->m_evalFunction.visit(visitor);
1672 thisObject->m_initializePromiseFunction.visit(visitor);
1673 thisObject->m_iteratorProtocolFunction.visit(visitor);
1674 thisObject->m_promiseResolveFunction.visit(visitor);
1675 visitor.append(thisObject->m_objectProtoValueOfFunction);
1676 visitor.append(thisObject->m_numberProtoToStringFunction);
1677 visitor.append(thisObject->m_newPromiseCapabilityFunction);
1678 visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
1679 thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1680 visitor.append(thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
1681 thisObject->m_moduleLoader.visit(visitor);
1682
1683 visitor.append(thisObject->m_objectPrototype);
1684 visitor.append(thisObject->m_functionPrototype);
1685 visitor.append(thisObject->m_arrayPrototype);
1686 visitor.append(thisObject->m_iteratorPrototype);
1687 visitor.append(thisObject->m_generatorFunctionPrototype);
1688 visitor.append(thisObject->m_generatorPrototype);
1689 visitor.append(thisObject->m_asyncFunctionPrototype);
1690 visitor.append(thisObject->m_asyncGeneratorPrototype);
1691 visitor.append(thisObject->m_asyncIteratorPrototype);
1692 visitor.append(thisObject->m_asyncGeneratorFunctionPrototype);
1693
1694 thisObject->m_debuggerScopeStructure.visit(visitor);
1695 thisObject->m_withScopeStructure.visit(visitor);
1696 thisObject->m_strictEvalActivationStructure.visit(visitor);
1697 visitor.append(thisObject->m_lexicalEnvironmentStructure);
1698 thisObject->m_moduleEnvironmentStructure.visit(visitor);
1699 visitor.append(thisObject->m_directArgumentsStructure);
1700 visitor.append(thisObject->m_scopedArgumentsStructure);
1701 visitor.append(thisObject->m_clonedArgumentsStructure);
1702 visitor.append(thisObject->m_objectStructureForObjectConstructor);
1703 for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1704 visitor.append(thisObject->m_originalArrayStructureForIndexingShape[i]);
1705 for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1706 visitor.append(thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1707 thisObject->m_callbackConstructorStructure.visit(visitor);
1708 thisObject->m_callbackFunctionStructure.visit(visitor);
1709 thisObject->m_callbackObjectStructure.visit(visitor);
1710#if JSC_OBJC_API_ENABLED
1711 thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1712 thisObject->m_objcWrapperObjectStructure.visit(visitor);
1713#endif
1714#ifdef JSC_GLIB_API_ENABLED
1715 thisObject->m_glibCallbackFunctionStructure.visit(visitor);
1716 thisObject->m_glibWrapperObjectStructure.visit(visitor);
1717#endif
1718 visitor.append(thisObject->m_nullPrototypeObjectStructure);
1719 visitor.append(thisObject->m_calleeStructure);
1720
1721 visitor.append(thisObject->m_hostFunctionStructure);
1722 auto visitFunctionStructures = [&] (FunctionStructures& structures) {
1723 visitor.append(structures.arrowFunctionStructure);
1724 visitor.append(structures.sloppyFunctionStructure);
1725 visitor.append(structures.strictFunctionStructure);
1726 };
1727 visitFunctionStructures(thisObject->m_builtinFunctions);
1728 visitFunctionStructures(thisObject->m_ordinaryFunctions);
1729
1730 thisObject->m_customGetterSetterFunctionStructure.visit(visitor);
1731 thisObject->m_boundFunctionStructure.visit(visitor);
1732 visitor.append(thisObject->m_getterSetterStructure);
1733 thisObject->m_nativeStdFunctionStructure.visit(visitor);
1734 visitor.append(thisObject->m_bigIntObjectStructure);
1735 visitor.append(thisObject->m_regExpStructure);
1736 visitor.append(thisObject->m_generatorFunctionStructure);
1737 visitor.append(thisObject->m_asyncFunctionStructure);
1738 visitor.append(thisObject->m_asyncGeneratorFunctionStructure);
1739 thisObject->m_iteratorResultObjectStructure.visit(visitor);
1740 visitor.append(thisObject->m_regExpMatchesArrayStructure);
1741 visitor.append(thisObject->m_regExpMatchesArrayWithGroupsStructure);
1742 thisObject->m_moduleRecordStructure.visit(visitor);
1743 thisObject->m_moduleNamespaceObjectStructure.visit(visitor);
1744 thisObject->m_proxyObjectStructure.visit(visitor);
1745 thisObject->m_callableProxyObjectStructure.visit(visitor);
1746 thisObject->m_proxyRevokeStructure.visit(visitor);
1747
1748#if ENABLE(SHARED_ARRAY_BUFFER)
1749 visitor.append(thisObject->m_sharedArrayBufferPrototype);
1750 visitor.append(thisObject->m_sharedArrayBufferStructure);
1751#endif
1752
1753#define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
1754 visitor.append(thisObject->m_ ## lowerName ## Prototype); \
1755 visitor.append(thisObject->m_ ## properName ## Structure); \
1756 } while (0);
1757
1758#define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1759 thisObject->m_ ## properName ## Structure.visit(visitor);
1760
1761 FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1762 if (UNLIKELY(Options::useBigInt()))
1763 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(VISIT_SIMPLE_TYPE)
1764 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE)
1765
1766 FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1767
1768#if ENABLE(WEBASSEMBLY)
1769 thisObject->m_webAssemblyModuleRecordStructure.visit(visitor);
1770 thisObject->m_webAssemblyFunctionStructure.visit(visitor);
1771 thisObject->m_jsToWasmICCalleeStructure.visit(visitor);
1772 thisObject->m_webAssemblyWrapperFunctionStructure.visit(visitor);
1773 thisObject->m_webAssemblyToJSCalleeStructure.visit(visitor);
1774 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(VISIT_LAZY_TYPE)
1775#endif // ENABLE(WEBASSEMBLY)
1776
1777#undef VISIT_SIMPLE_TYPE
1778#undef VISIT_LAZY_TYPE
1779
1780 for (unsigned i = NumberOfTypedArrayTypes; i--;)
1781 thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1782
1783 visitor.append(thisObject->m_speciesGetterSetter);
1784 thisObject->m_typedArrayProto.visit(visitor);
1785 thisObject->m_typedArraySuperConstructor.visit(visitor);
1786 thisObject->m_regExpGlobalData.visitAggregate(visitor);
1787}
1788
1789ExecState* JSGlobalObject::globalExec()
1790{
1791 return CallFrame::create(m_globalCallFrame);
1792}
1793
1794void JSGlobalObject::exposeDollarVM(VM& vm)
1795{
1796 if (hasOwnProperty(globalExec(), vm.propertyNames->builtinNames().dollarVMPrivateName()))
1797 return;
1798
1799 JSDollarVM* dollarVM = JSDollarVM::create(vm, JSDollarVM::createStructure(vm, this, m_objectPrototype.get()));
1800
1801 GlobalPropertyInfo extraStaticGlobals[] = {
1802 GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1803 };
1804 addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
1805
1806 putDirect(vm, Identifier::fromString(globalExec(), "$vm"), dollarVM, static_cast<unsigned>(PropertyAttribute::DontEnum));
1807}
1808
1809void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1810{
1811 ScopeOffset startOffset = addVariables(count, jsUndefined());
1812
1813 for (int i = 0; i < count; ++i) {
1814 GlobalPropertyInfo& global = globals[i];
1815 // This `configurable = false` is necessary condition for static globals,
1816 // otherwise lexical bindings can change the result of GlobalVar queries too.
1817 // We won't be able to declare a global lexical variable with the sanem name to
1818 // the static globals because configurable = false.
1819 ASSERT(global.attributes & PropertyAttribute::DontDelete);
1820
1821 WatchpointSet* watchpointSet = nullptr;
1822 WriteBarrierBase<Unknown>* variable = nullptr;
1823 {
1824 ConcurrentJSLocker locker(symbolTable()->m_lock);
1825 ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1826 RELEASE_ASSERT(offset == startOffset + i);
1827 SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1828 newEntry.prepareToWatch();
1829 watchpointSet = newEntry.watchpointSet();
1830 symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1831 variable = &variableAt(offset);
1832 }
1833 symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1834 }
1835}
1836
1837bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1838{
1839 if (Base::getOwnPropertySlot(object, exec, propertyName, slot))
1840 return true;
1841 return symbolTableGet(jsCast<JSGlobalObject*>(object), propertyName, slot);
1842}
1843
1844void JSGlobalObject::clearRareData(JSCell* cell)
1845{
1846 jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1847}
1848
1849void JSGlobalObject::tryInstallArraySpeciesWatchpoint(ExecState* exec)
1850{
1851 RELEASE_ASSERT(!m_arrayPrototypeConstructorWatchpoint);
1852 RELEASE_ASSERT(!m_arrayConstructorSpeciesWatchpoint);
1853
1854 VM& vm = exec->vm();
1855 auto scope = DECLARE_THROW_SCOPE(vm);
1856
1857 // First we need to make sure that the Array.prototype.constructor property points to Array
1858 // and that Array[Symbol.species] is the primordial GetterSetter.
1859 ArrayPrototype* arrayPrototype = this->arrayPrototype();
1860
1861 // We only initialize once so flattening the structures does not have any real cost.
1862 Structure* prototypeStructure = arrayPrototype->structure(vm);
1863 if (prototypeStructure->isDictionary())
1864 prototypeStructure = prototypeStructure->flattenDictionaryStructure(vm, arrayPrototype);
1865 RELEASE_ASSERT(!prototypeStructure->isDictionary());
1866
1867 ArrayConstructor* arrayConstructor = this->arrayConstructor();
1868
1869 auto invalidateWatchpoint = [&] {
1870 m_arraySpeciesWatchpoint.invalidate(vm, StringFireDetail("Was not able to set up array species watchpoint."));
1871 };
1872
1873 PropertySlot constructorSlot(arrayPrototype, PropertySlot::InternalMethodType::VMInquiry);
1874 arrayPrototype->getOwnPropertySlot(arrayPrototype, exec, vm.propertyNames->constructor, constructorSlot);
1875 scope.assertNoException();
1876 if (constructorSlot.slotBase() != arrayPrototype
1877 || !constructorSlot.isCacheableValue()
1878 || constructorSlot.getValue(exec, vm.propertyNames->constructor) != arrayConstructor) {
1879 invalidateWatchpoint();
1880 return;
1881 }
1882
1883 Structure* constructorStructure = arrayConstructor->structure(vm);
1884 if (constructorStructure->isDictionary())
1885 constructorStructure = constructorStructure->flattenDictionaryStructure(vm, arrayConstructor);
1886
1887 PropertySlot speciesSlot(arrayConstructor, PropertySlot::InternalMethodType::VMInquiry);
1888 arrayConstructor->getOwnPropertySlot(arrayConstructor, exec, vm.propertyNames->speciesSymbol, speciesSlot);
1889 scope.assertNoException();
1890 if (speciesSlot.slotBase() != arrayConstructor
1891 || !speciesSlot.isCacheableGetter()
1892 || speciesSlot.getterSetter() != speciesGetterSetter()) {
1893 invalidateWatchpoint();
1894 return;
1895 }
1896
1897 // Now we need to setup the watchpoints to make sure these conditions remain valid.
1898 prototypeStructure->startWatchingPropertyForReplacements(vm, constructorSlot.cachedOffset());
1899 constructorStructure->startWatchingPropertyForReplacements(vm, speciesSlot.cachedOffset());
1900
1901 ObjectPropertyCondition constructorCondition = ObjectPropertyCondition::equivalence(vm, arrayPrototype, arrayPrototype, vm.propertyNames->constructor.impl(), arrayConstructor);
1902 ObjectPropertyCondition speciesCondition = ObjectPropertyCondition::equivalence(vm, arrayPrototype, arrayConstructor, vm.propertyNames->speciesSymbol.impl(), speciesGetterSetter());
1903
1904 if (!constructorCondition.isWatchable() || !speciesCondition.isWatchable()) {
1905 invalidateWatchpoint();
1906 return;
1907 }
1908
1909 // We only watch this from the DFG, and the DFG makes sure to only start watching if the watchpoint is in the IsWatched state.
1910 RELEASE_ASSERT(!m_arraySpeciesWatchpoint.isBeingWatched());
1911 m_arraySpeciesWatchpoint.touch(vm, "Set up array species watchpoint.");
1912
1913 m_arrayPrototypeConstructorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, constructorCondition, m_arraySpeciesWatchpoint);
1914 m_arrayPrototypeConstructorWatchpoint->install(vm);
1915
1916 m_arrayConstructorSpeciesWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, speciesCondition, m_arraySpeciesWatchpoint);
1917 m_arrayConstructorSpeciesWatchpoint->install(vm);
1918}
1919
1920void slowValidateCell(JSGlobalObject* globalObject)
1921{
1922 RELEASE_ASSERT(globalObject->isGlobalObject());
1923 ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1924}
1925
1926void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1927{
1928#if ENABLE(REMOTE_INSPECTOR)
1929 m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1930#else
1931 UNUSED_PARAM(enabled);
1932#endif
1933}
1934
1935bool JSGlobalObject::remoteDebuggingEnabled() const
1936{
1937#if ENABLE(REMOTE_INSPECTOR)
1938 return m_inspectorDebuggable->remoteDebuggingAllowed();
1939#else
1940 return false;
1941#endif
1942}
1943
1944void JSGlobalObject::setName(const String& name)
1945{
1946 m_name = name;
1947
1948#if ENABLE(REMOTE_INSPECTOR)
1949 m_inspectorDebuggable->update();
1950#endif
1951}
1952
1953# if ENABLE(INTL)
1954static void addMissingScriptLocales(HashSet<String>& availableLocales)
1955{
1956 if (availableLocales.contains("pa-Arab-PK"))
1957 availableLocales.add("pa-PK"_s);
1958 if (availableLocales.contains("zh-Hans-CN"))
1959 availableLocales.add("zh-CN"_s);
1960 if (availableLocales.contains("zh-Hant-HK"))
1961 availableLocales.add("zh-HK"_s);
1962 if (availableLocales.contains("zh-Hans-SG"))
1963 availableLocales.add("zh-SG"_s);
1964 if (availableLocales.contains("zh-Hant-TW"))
1965 availableLocales.add("zh-TW"_s);
1966}
1967
1968const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1969{
1970 if (m_intlCollatorAvailableLocales.isEmpty()) {
1971 int32_t count = ucol_countAvailable();
1972 for (int32_t i = 0; i < count; ++i) {
1973 String locale = convertICULocaleToBCP47LanguageTag(ucol_getAvailable(i));
1974 if (!locale.isEmpty())
1975 m_intlCollatorAvailableLocales.add(locale);
1976 }
1977 addMissingScriptLocales(m_intlCollatorAvailableLocales);
1978 }
1979 return m_intlCollatorAvailableLocales;
1980}
1981
1982const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1983{
1984 if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1985 int32_t count = udat_countAvailable();
1986 for (int32_t i = 0; i < count; ++i) {
1987 String locale = convertICULocaleToBCP47LanguageTag(udat_getAvailable(i));
1988 if (!locale.isEmpty())
1989 m_intlDateTimeFormatAvailableLocales.add(locale);
1990 }
1991 addMissingScriptLocales(m_intlDateTimeFormatAvailableLocales);
1992 }
1993 return m_intlDateTimeFormatAvailableLocales;
1994}
1995
1996const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1997{
1998 if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1999 int32_t count = unum_countAvailable();
2000 for (int32_t i = 0; i < count; ++i) {
2001 String locale = convertICULocaleToBCP47LanguageTag(unum_getAvailable(i));
2002 if (!locale.isEmpty())
2003 m_intlNumberFormatAvailableLocales.add(locale);
2004 }
2005 addMissingScriptLocales(m_intlNumberFormatAvailableLocales);
2006 }
2007 return m_intlNumberFormatAvailableLocales;
2008}
2009
2010const HashSet<String>& JSGlobalObject::intlPluralRulesAvailableLocales()
2011{
2012 if (m_intlPluralRulesAvailableLocales.isEmpty()) {
2013 int32_t count = uloc_countAvailable();
2014 for (int32_t i = 0; i < count; ++i) {
2015 String locale = convertICULocaleToBCP47LanguageTag(uloc_getAvailable(i));
2016 if (!locale.isEmpty())
2017 m_intlPluralRulesAvailableLocales.add(locale);
2018 }
2019 addMissingScriptLocales(m_intlPluralRulesAvailableLocales);
2020 }
2021 return m_intlPluralRulesAvailableLocales;
2022}
2023
2024IntlCollator* JSGlobalObject::defaultCollator(ExecState* exec)
2025{
2026 VM& vm = exec->vm();
2027 auto scope = DECLARE_THROW_SCOPE(vm);
2028
2029 if (m_defaultCollator)
2030 return m_defaultCollator.get();
2031
2032 IntlCollator* collator = IntlCollator::create(vm, collatorStructure());
2033 collator->initializeCollator(*exec, jsUndefined(), jsUndefined());
2034 RETURN_IF_EXCEPTION(scope, nullptr);
2035 m_defaultCollator.set(vm, this, collator);
2036 return collator;
2037}
2038
2039#endif // ENABLE(INTL)
2040
2041void JSGlobalObject::bumpGlobalLexicalBindingEpoch(VM& vm)
2042{
2043 if (++m_globalLexicalBindingEpoch == Options::thresholdForGlobalLexicalBindingEpoch()) {
2044 // Since the epoch overflows, we should rewrite all the CodeBlock to adjust to the newly started generation.
2045 m_globalLexicalBindingEpoch = 1;
2046 vm.heap.codeBlockSet().iterate([&] (CodeBlock* codeBlock) {
2047 if (codeBlock->globalObject() != this)
2048 return;
2049 codeBlock->notifyLexicalBindingUpdate();
2050 });
2051 }
2052}
2053
2054void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
2055{
2056 if (globalObjectMethodTable()->queueTaskToEventLoop) {
2057 globalObjectMethodTable()->queueTaskToEventLoop(*this, WTFMove(task));
2058 return;
2059 }
2060
2061 vm().queueMicrotask(*this, WTFMove(task));
2062}
2063
2064void JSGlobalObject::setDebugger(Debugger* debugger)
2065{
2066 m_debugger = debugger;
2067 if (debugger)
2068 vm().ensureShadowChicken();
2069}
2070
2071bool JSGlobalObject::hasDebugger() const
2072{
2073 return m_debugger;
2074}
2075
2076bool JSGlobalObject::hasInteractiveDebugger() const
2077{
2078 return m_debugger && m_debugger->isInteractivelyDebugging();
2079}
2080
2081#if ENABLE(DFG_JIT)
2082WatchpointSet* JSGlobalObject::getReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
2083{
2084 ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
2085 return m_referencedGlobalPropertyWatchpointSets.get(uid);
2086}
2087
2088WatchpointSet& JSGlobalObject::ensureReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
2089{
2090 ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
2091 return m_referencedGlobalPropertyWatchpointSets.ensure(uid, [] {
2092 return WatchpointSet::create(IsWatched);
2093 }).iterator->value.get();
2094}
2095#endif
2096
2097JSGlobalObject* JSGlobalObject::create(VM& vm, Structure* structure)
2098{
2099 JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
2100 globalObject->finishCreation(vm);
2101 return globalObject;
2102}
2103
2104void JSGlobalObject::finishCreation(VM& vm)
2105{
2106 Base::finishCreation(vm);
2107 structure(vm)->setGlobalObject(vm, this);
2108 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
2109 init(vm);
2110 setGlobalThis(vm, JSNonDestructibleProxy::create(vm, JSNonDestructibleProxy::createStructure(vm, this, getPrototypeDirect(vm), PureForwardingProxyType), this));
2111 ASSERT(type() == GlobalObjectType);
2112}
2113
2114void JSGlobalObject::finishCreation(VM& vm, JSObject* thisValue)
2115{
2116 Base::finishCreation(vm);
2117 structure(vm)->setGlobalObject(vm, this);
2118 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
2119 init(vm);
2120 setGlobalThis(vm, thisValue);
2121 ASSERT(type() == GlobalObjectType);
2122}
2123
2124#ifdef JSC_GLIB_API_ENABLED
2125void JSGlobalObject::setWrapperMap(std::unique_ptr<WrapperMap>&& map)
2126{
2127 m_wrapperMap = WTFMove(map);
2128}
2129#endif
2130
2131} // namespace JSC
2132