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