/ runtime / JSGlobalObject.cpp
JSGlobalObject.cpp
   1  /*
   2   * Copyright (C) 2007-2020 Apple Inc. All rights reserved.
   3   * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca)
   4   *
   5   * Redistribution and use in source and binary forms, with or without
   6   * modification, are permitted provided that the following conditions
   7   * are met:
   8   *
   9   * 1.  Redistributions of source code must retain the above copyright
  10   *     notice, this list of conditions and the following disclaimer.
  11   * 2.  Redistributions in binary form must reproduce the above copyright
  12   *     notice, this list of conditions and the following disclaimer in the
  13   *     documentation and/or other materials provided with the distribution.
  14   * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
  15   *     its contributors may be used to endorse or promote products derived
  16   *     from this software without specific prior written permission.
  17   *
  18   * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21   * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28   */
  29  
  30  #include "config.h"
  31  #include "JSGlobalObject.h"
  32  
  33  #include "AggregateError.h"
  34  #include "AggregateErrorConstructor.h"
  35  #include "AggregateErrorPrototype.h"
  36  #include "ArrayConstructor.h"
  37  #include "ArrayIteratorPrototype.h"
  38  #include "ArrayPrototype.h"
  39  #include "AsyncFromSyncIteratorPrototype.h"
  40  #include "AsyncFunctionConstructor.h"
  41  #include "AsyncFunctionPrototype.h"
  42  #include "AsyncGeneratorFunctionConstructor.h"
  43  #include "AsyncGeneratorFunctionPrototype.h"
  44  #include "AsyncGeneratorPrototype.h"
  45  #include "AsyncIteratorPrototype.h"
  46  #include "AtomicsObject.h"
  47  #include "BigIntConstructor.h"
  48  #include "BigIntObject.h"
  49  #include "BigIntPrototype.h"
  50  #include "BooleanConstructor.h"
  51  #include "BooleanPrototype.h"
  52  #include "BuiltinNames.h"
  53  #include "CatchScope.h"
  54  #include "ClonedArguments.h"
  55  #include "CodeBlock.h"
  56  #include "CodeBlockSetInlines.h"
  57  #include "ConsoleClient.h"
  58  #include "ConsoleObject.h"
  59  #include "DateConstructor.h"
  60  #include "DatePrototype.h"
  61  #include "Debugger.h"
  62  #include "DebuggerScope.h"
  63  #include "DirectArguments.h"
  64  #include "ErrorConstructor.h"
  65  #include "ErrorPrototype.h"
  66  #include "FinalizationRegistryConstructor.h"
  67  #include "FinalizationRegistryPrototype.h"
  68  #include "FunctionConstructor.h"
  69  #include "FunctionPrototype.h"
  70  #include "GeneratorFunctionConstructor.h"
  71  #include "GeneratorFunctionPrototype.h"
  72  #include "GeneratorPrototype.h"
  73  #include "GetterSetter.h"
  74  #include "HeapIterationScope.h"
  75  #include "InspectorInstrumentationObject.h"
  76  #include "IntlCollator.h"
  77  #include "IntlCollatorPrototype.h"
  78  #include "IntlDateTimeFormat.h"
  79  #include "IntlDateTimeFormatConstructor.h"
  80  #include "IntlDateTimeFormatPrototype.h"
  81  #include "IntlDisplayNames.h"
  82  #include "IntlDisplayNamesPrototype.h"
  83  #include "IntlListFormat.h"
  84  #include "IntlListFormatPrototype.h"
  85  #include "IntlLocale.h"
  86  #include "IntlLocalePrototype.h"
  87  #include "IntlNumberFormat.h"
  88  #include "IntlNumberFormatConstructor.h"
  89  #include "IntlNumberFormatPrototype.h"
  90  #include "IntlObject.h"
  91  #include "IntlPluralRules.h"
  92  #include "IntlPluralRulesPrototype.h"
  93  #include "IntlRelativeTimeFormat.h"
  94  #include "IntlRelativeTimeFormatPrototype.h"
  95  #include "IntlSegmentIterator.h"
  96  #include "IntlSegmentIteratorPrototype.h"
  97  #include "IntlSegmenter.h"
  98  #include "IntlSegmenterPrototype.h"
  99  #include "IntlSegments.h"
 100  #include "IntlSegmentsPrototype.h"
 101  #include "IteratorPrototype.h"
 102  #include "JSAPIWrapperObject.h"
 103  #include "JSArrayBuffer.h"
 104  #include "JSArrayBufferConstructor.h"
 105  #include "JSArrayBufferPrototype.h"
 106  #include "JSArrayIterator.h"
 107  #include "JSAsyncFunction.h"
 108  #include "JSAsyncGenerator.h"
 109  #include "JSAsyncGeneratorFunction.h"
 110  #include "JSBoundFunction.h"
 111  #include "JSCallbackConstructor.h"
 112  #include "JSCallbackFunction.h"
 113  #include "JSCallbackObject.h"
 114  #include "JSCustomGetterSetterFunction.h"
 115  #include "JSDataView.h"
 116  #include "JSDataViewPrototype.h"
 117  #include "JSDollarVM.h"
 118  #include "JSFinalizationRegistry.h"
 119  #include "JSFunction.h"
 120  #include "JSGenerator.h"
 121  #include "JSGeneratorFunction.h"
 122  #include "JSGenericTypedArrayViewConstructorInlines.h"
 123  #include "JSGenericTypedArrayViewInlines.h"
 124  #include "JSGenericTypedArrayViewPrototypeInlines.h"
 125  #include "JSGlobalObjectFunctions.h"
 126  #include "JSInternalPromise.h"
 127  #include "JSInternalPromiseConstructor.h"
 128  #include "JSInternalPromisePrototype.h"
 129  #include "JSLexicalEnvironment.h"
 130  #include "JSMap.h"
 131  #include "JSMapIterator.h"
 132  #include "JSMicrotask.h"
 133  #include "JSModuleEnvironment.h"
 134  #include "JSModuleLoader.h"
 135  #include "JSModuleNamespaceObject.h"
 136  #include "JSModuleRecord.h"
 137  #include "JSNativeStdFunction.h"
 138  #include "JSONObject.h"
 139  #include "JSPromise.h"
 140  #include "JSPromiseConstructor.h"
 141  #include "JSPromisePrototype.h"
 142  #include "JSSet.h"
 143  #include "JSSetIterator.h"
 144  #include "JSStringIterator.h"
 145  #include "JSTypedArrayConstructors.h"
 146  #include "JSTypedArrayPrototypes.h"
 147  #include "JSTypedArrayViewConstructor.h"
 148  #include "JSTypedArrayViewPrototype.h"
 149  #include "JSTypedArrays.h"
 150  #include "JSWeakMap.h"
 151  #include "JSWeakObjectRef.h"
 152  #include "JSWeakSet.h"
 153  #include "JSWebAssembly.h"
 154  #include "JSWebAssemblyCompileError.h"
 155  #include "JSWebAssemblyGlobal.h"
 156  #include "JSWebAssemblyInstance.h"
 157  #include "JSWebAssemblyLinkError.h"
 158  #include "JSWebAssemblyMemory.h"
 159  #include "JSWebAssemblyModule.h"
 160  #include "JSWebAssemblyRuntimeError.h"
 161  #include "JSWebAssemblyTable.h"
 162  #include "JSWithScope.h"
 163  #include "LazyClassStructureInlines.h"
 164  #include "LazyPropertyInlines.h"
 165  #include "LinkTimeConstant.h"
 166  #include "MapConstructor.h"
 167  #include "MapIteratorPrototype.h"
 168  #include "MapPrototype.h"
 169  #include "MarkedSpaceInlines.h"
 170  #include "MathObject.h"
 171  #include "NativeErrorConstructor.h"
 172  #include "NativeErrorPrototype.h"
 173  #include "NullGetterFunction.h"
 174  #include "NullSetterFunction.h"
 175  #include "NumberConstructor.h"
 176  #include "NumberPrototype.h"
 177  #include "ObjCCallbackFunction.h"
 178  #include "ObjectConstructor.h"
 179  #include "ObjectPropertyChangeAdaptiveWatchpoint.h"
 180  #include "ObjectPropertyConditionSet.h"
 181  #include "ObjectPrototype.h"
 182  #include "ProxyConstructor.h"
 183  #include "ProxyObject.h"
 184  #include "ProxyRevoke.h"
 185  #include "ReflectObject.h"
 186  #include "RegExpConstructor.h"
 187  #include "RegExpMatchesArray.h"
 188  #include "RegExpObject.h"
 189  #include "RegExpPrototype.h"
 190  #include "RegExpStringIteratorPrototype.h"
 191  #include "SamplingProfiler.h"
 192  #include "ScopedArguments.h"
 193  #include "SetConstructor.h"
 194  #include "SetIteratorPrototype.h"
 195  #include "SetPrototype.h"
 196  #include "StrictEvalActivation.h"
 197  #include "StringConstructor.h"
 198  #include "StringIteratorPrototype.h"
 199  #include "StringPrototype.h"
 200  #include "SymbolConstructor.h"
 201  #include "SymbolObject.h"
 202  #include "SymbolPrototype.h"
 203  #include "WasmCapabilities.h"
 204  #include "WeakMapConstructor.h"
 205  #include "WeakMapPrototype.h"
 206  #include "WeakObjectRefConstructor.h"
 207  #include "WeakObjectRefPrototype.h"
 208  #include "WeakSetConstructor.h"
 209  #include "WeakSetPrototype.h"
 210  #include "WebAssemblyCompileErrorConstructor.h"
 211  #include "WebAssemblyCompileErrorPrototype.h"
 212  #include "WebAssemblyFunction.h"
 213  #include "WebAssemblyGlobalConstructor.h"
 214  #include "WebAssemblyGlobalPrototype.h"
 215  #include "WebAssemblyInstanceConstructor.h"
 216  #include "WebAssemblyInstancePrototype.h"
 217  #include "WebAssemblyLinkErrorConstructor.h"
 218  #include "WebAssemblyLinkErrorPrototype.h"
 219  #include "WebAssemblyMemoryConstructor.h"
 220  #include "WebAssemblyMemoryPrototype.h"
 221  #include "WebAssemblyModuleConstructor.h"
 222  #include "WebAssemblyModulePrototype.h"
 223  #include "WebAssemblyModuleRecord.h"
 224  #include "WebAssemblyRuntimeErrorConstructor.h"
 225  #include "WebAssemblyRuntimeErrorPrototype.h"
 226  #include "WebAssemblyTableConstructor.h"
 227  #include "WebAssemblyTablePrototype.h"
 228  #include <wtf/RandomNumber.h>
 229  
 230  #if ENABLE(REMOTE_INSPECTOR)
 231  #include "JSGlobalObjectDebuggable.h"
 232  #include "JSGlobalObjectInspectorController.h"
 233  #endif
 234  
 235  #ifdef JSC_GLIB_API_ENABLED
 236  #include "JSCCallbackFunction.h"
 237  #include "JSCWrapperMap.h"
 238  #endif
 239  
 240  namespace JSC {
 241  
 242  #define CHECK_FEATURE_FLAG_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
 243  static_assert(std::is_same_v<std::remove_cv_t<decltype(featureFlag)>, bool> || std::is_same_v<std::remove_cv_t<decltype(featureFlag)>, bool&>);
 244  
 245  FOR_EACH_SIMPLE_BUILTIN_TYPE(CHECK_FEATURE_FLAG_TYPE)
 246  FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CHECK_FEATURE_FLAG_TYPE)
 247  FOR_EACH_LAZY_BUILTIN_TYPE(CHECK_FEATURE_FLAG_TYPE)
 248  
 249  static JSC_DECLARE_HOST_FUNCTION(makeBoundFunction);
 250  static JSC_DECLARE_HOST_FUNCTION(hasOwnLengthProperty);
 251  static JSC_DECLARE_HOST_FUNCTION(createPrivateSymbol);
 252  static JSC_DECLARE_HOST_FUNCTION(enableSuperSampler);
 253  static JSC_DECLARE_HOST_FUNCTION(disableSuperSampler);
 254  static JSC_DECLARE_HOST_FUNCTION(enqueueJob);
 255  #if ASSERT_ENABLED
 256  static JSC_DECLARE_HOST_FUNCTION(assertCall);
 257  #endif
 258  #if ENABLE(SAMPLING_PROFILER)
 259  static JSC_DECLARE_HOST_FUNCTION(enableSamplingProfiler);
 260  static JSC_DECLARE_HOST_FUNCTION(disableSamplingProfiler);
 261  #endif
 262  
 263  static JSValue createProxyProperty(VM& vm, JSObject* object)
 264  {
 265      JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
 266      return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
 267  }
 268  
 269  static JSValue createJSONProperty(VM& vm, JSObject* object)
 270  {
 271      JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
 272      return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
 273  }
 274  
 275  static JSValue createMathProperty(VM& vm, JSObject* object)
 276  {
 277      JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
 278      return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
 279  }
 280  
 281  static JSValue createReflectProperty(VM& vm, JSObject* object)
 282  {
 283      JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
 284      return ReflectObject::create(vm, global, ReflectObject::createStructure(vm, global, global->objectPrototype()));
 285  }
 286  
 287  static JSValue createConsoleProperty(VM& vm, JSObject* object)
 288  {
 289      JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
 290      return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global)));
 291  }
 292  
 293  JSC_DEFINE_HOST_FUNCTION(makeBoundFunction, (JSGlobalObject* globalObject, CallFrame* callFrame))
 294  {
 295      VM& vm = globalObject->vm();
 296      auto scope = DECLARE_THROW_SCOPE(vm);
 297  
 298      JSObject* target = asObject(callFrame->uncheckedArgument(0));
 299      JSValue boundThis = callFrame->uncheckedArgument(1);
 300      JSValue boundArgs = callFrame->uncheckedArgument(2);
 301      double length = callFrame->uncheckedArgument(3).asNumber();
 302      JSString* nameString = asString(callFrame->uncheckedArgument(4));
 303  
 304      RELEASE_AND_RETURN(scope, JSValue::encode(JSBoundFunction::create(vm, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSImmutableButterfly*>(boundArgs) : nullptr, length, nameString)));
 305  }
 306  
 307  JSC_DEFINE_HOST_FUNCTION(hasOwnLengthProperty, (JSGlobalObject* globalObject, CallFrame* callFrame))
 308  {
 309      VM& vm = globalObject->vm();
 310      auto scope = DECLARE_THROW_SCOPE(vm);
 311  
 312      JSObject* target = asObject(callFrame->uncheckedArgument(0));
 313      JSFunction* function = jsDynamicCast<JSFunction*>(vm, target);
 314      if (function && function->canAssumeNameAndLengthAreOriginal(vm)) {
 315  #if ASSERT_ENABLED
 316          bool result = target->hasOwnProperty(globalObject, vm.propertyNames->length);
 317          RETURN_IF_EXCEPTION(scope, { });
 318          ASSERT(result);
 319  #endif
 320          return JSValue::encode(jsBoolean(true));
 321      }
 322      RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(target->hasOwnProperty(globalObject, vm.propertyNames->length))));
 323  }
 324  
 325  // FIXME: use a bytecode or intrinsic for creating a private symbol.
 326  // https://bugs.webkit.org/show_bug.cgi?id=212782
 327  JSC_DEFINE_HOST_FUNCTION(createPrivateSymbol, (JSGlobalObject* globalObject, CallFrame*))
 328  {
 329      VM& vm = globalObject->vm();
 330      return JSValue::encode(Symbol::create(vm, PrivateSymbolImpl::createNullSymbol().get()));
 331  }
 332  
 333  #if ASSERT_ENABLED
 334  JSC_DEFINE_HOST_FUNCTION(assertCall, (JSGlobalObject* globalObject, CallFrame* callFrame))
 335  {
 336      RELEASE_ASSERT(callFrame->argument(0).isBoolean());
 337      if (callFrame->argument(0).asBoolean())
 338          return JSValue::encode(jsUndefined());
 339  
 340      bool iteratedOnce = false;
 341      CodeBlock* codeBlock = nullptr;
 342      unsigned line;
 343      callFrame->iterate(globalObject->vm(), [&] (StackVisitor& visitor) {
 344          if (!iteratedOnce) {
 345              iteratedOnce = true;
 346              return StackVisitor::Continue;
 347          }
 348  
 349          RELEASE_ASSERT(visitor->hasLineAndColumnInfo());
 350          unsigned column;
 351          visitor->computeLineAndColumn(line, column);
 352          codeBlock = visitor->codeBlock();
 353          return StackVisitor::Done;
 354      });
 355      RELEASE_ASSERT(!!codeBlock);
 356      RELEASE_ASSERT_WITH_MESSAGE(false, "JS assertion failed at line %u in:\n%s\n", line, codeBlock->sourceCodeForTools().data());
 357      return JSValue::encode(jsUndefined());
 358  }
 359  #endif // ASSERT_ENABLED
 360  
 361  #if ENABLE(SAMPLING_PROFILER)
 362  JSC_DEFINE_HOST_FUNCTION(enableSamplingProfiler, (JSGlobalObject* globalObject, CallFrame*))
 363  {
 364      SamplingProfiler* profiler = globalObject->vm().samplingProfiler();
 365      if (!profiler)
 366          profiler = &globalObject->vm().ensureSamplingProfiler(Stopwatch::create());
 367      profiler->start();
 368      return JSValue::encode(jsUndefined());
 369  }
 370  
 371  JSC_DEFINE_HOST_FUNCTION(disableSamplingProfiler, (JSGlobalObject* globalObject, CallFrame*))
 372  {
 373      SamplingProfiler* profiler = globalObject->vm().samplingProfiler();
 374      if (!profiler)
 375          profiler = &globalObject->vm().ensureSamplingProfiler(Stopwatch::create());
 376  
 377      {
 378          auto locker = holdLock(profiler->getLock());
 379          profiler->pause(locker);
 380      }
 381  
 382      return JSValue::encode(jsUndefined());
 383  }
 384  #endif
 385  
 386  JSC_DEFINE_HOST_FUNCTION(enableSuperSampler, (JSGlobalObject*, CallFrame*))
 387  {
 388      enableSuperSampler();
 389      return JSValue::encode(jsUndefined());
 390  }
 391  
 392  JSC_DEFINE_HOST_FUNCTION(disableSuperSampler, (JSGlobalObject*, CallFrame*))
 393  {
 394      disableSuperSampler();
 395      return JSValue::encode(jsUndefined());
 396  }
 397  
 398  } // namespace JSC
 399  
 400  #include "JSGlobalObject.lut.h"
 401  
 402  namespace JSC {
 403  
 404  const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, nullptr, CREATE_METHOD_TABLE(JSGlobalObject) };
 405  
 406  const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
 407      &supportsRichSourceInfo,
 408      &shouldInterruptScript,
 409      &javaScriptRuntimeFlags,
 410      nullptr, // queueTaskToEventLoop
 411      &shouldInterruptScriptBeforeTimeout,
 412      nullptr, // moduleLoaderImportModule
 413      nullptr, // moduleLoaderResolve
 414      nullptr, // moduleLoaderFetch
 415      nullptr, // moduleLoaderCreateImportMetaProperties
 416      nullptr, // moduleLoaderEvaluate
 417      nullptr, // promiseRejectionTracker
 418      &reportUncaughtExceptionAtEventLoop,
 419      &currentScriptExecutionOwner,
 420      &scriptExecutionStatus,
 421      nullptr, // defaultLanguage
 422      nullptr, // compileStreaming
 423      nullptr, // instantiateStreaming
 424  };
 425  
 426  /* Source for JSGlobalObject.lut.h
 427  @begin globalObjectTable
 428    isNaN                 JSBuiltin                                    DontEnum|Function 1
 429    isFinite              JSBuiltin                                    DontEnum|Function 1
 430    escape                globalFuncEscape                             DontEnum|Function 1
 431    unescape              globalFuncUnescape                           DontEnum|Function 1
 432    decodeURI             globalFuncDecodeURI                          DontEnum|Function 1
 433    decodeURIComponent    globalFuncDecodeURIComponent                 DontEnum|Function 1
 434    encodeURI             globalFuncEncodeURI                          DontEnum|Function 1
 435    encodeURIComponent    globalFuncEncodeURIComponent                 DontEnum|Function 1
 436    eval                  JSGlobalObject::m_evalFunction               DontEnum|CellProperty
 437    globalThis            JSGlobalObject::m_globalThis                 DontEnum|CellProperty
 438    parseInt              JSGlobalObject::m_parseIntFunction           DontEnum|CellProperty
 439    parseFloat            JSGlobalObject::m_parseFloatFunction         DontEnum|CellProperty
 440    ArrayBuffer           JSGlobalObject::m_arrayBufferStructure       DontEnum|ClassStructure
 441    EvalError             JSGlobalObject::m_evalErrorStructure         DontEnum|ClassStructure
 442    RangeError            JSGlobalObject::m_rangeErrorStructure        DontEnum|ClassStructure
 443    ReferenceError        JSGlobalObject::m_referenceErrorStructure    DontEnum|ClassStructure
 444    SyntaxError           JSGlobalObject::m_syntaxErrorStructure       DontEnum|ClassStructure
 445    TypeError             JSGlobalObject::m_typeErrorStructure         DontEnum|ClassStructure
 446    URIError              JSGlobalObject::m_URIErrorStructure          DontEnum|ClassStructure
 447    AggregateError        JSGlobalObject::m_aggregateErrorStructure    DontEnum|ClassStructure
 448    Proxy                 createProxyProperty                          DontEnum|PropertyCallback
 449    Reflect               createReflectProperty                        DontEnum|PropertyCallback
 450    JSON                  createJSONProperty                           DontEnum|PropertyCallback
 451    Math                  createMathProperty                           DontEnum|PropertyCallback
 452    console               createConsoleProperty                        DontEnum|PropertyCallback
 453    Int8Array             JSGlobalObject::m_typedArrayInt8             DontEnum|ClassStructure
 454    Int16Array            JSGlobalObject::m_typedArrayInt16            DontEnum|ClassStructure
 455    Int32Array            JSGlobalObject::m_typedArrayInt32            DontEnum|ClassStructure
 456    Uint8Array            JSGlobalObject::m_typedArrayUint8            DontEnum|ClassStructure
 457    Uint8ClampedArray     JSGlobalObject::m_typedArrayUint8Clamped     DontEnum|ClassStructure
 458    Uint16Array           JSGlobalObject::m_typedArrayUint16           DontEnum|ClassStructure
 459    Uint32Array           JSGlobalObject::m_typedArrayUint32           DontEnum|ClassStructure
 460    Float32Array          JSGlobalObject::m_typedArrayFloat32          DontEnum|ClassStructure
 461    Float64Array          JSGlobalObject::m_typedArrayFloat64          DontEnum|ClassStructure
 462    DataView              JSGlobalObject::m_typedArrayDataView         DontEnum|ClassStructure
 463    Date                  JSGlobalObject::m_dateStructure              DontEnum|ClassStructure
 464    Error                 JSGlobalObject::m_errorStructure             DontEnum|ClassStructure
 465    Boolean               JSGlobalObject::m_booleanObjectStructure     DontEnum|ClassStructure
 466    Map                   JSGlobalObject::m_mapStructure               DontEnum|ClassStructure
 467    Number                JSGlobalObject::m_numberObjectStructure      DontEnum|ClassStructure
 468    Set                   JSGlobalObject::m_setStructure               DontEnum|ClassStructure
 469    Symbol                JSGlobalObject::m_symbolObjectStructure      DontEnum|ClassStructure
 470    WeakMap               JSGlobalObject::m_weakMapStructure           DontEnum|ClassStructure
 471    WeakSet               JSGlobalObject::m_weakSetStructure           DontEnum|ClassStructure
 472  @end
 473  */
 474  
 475  JSC_DEFINE_HOST_FUNCTION(enqueueJob, (JSGlobalObject* globalObject, CallFrame* callFrame))
 476  {
 477      VM& vm = globalObject->vm();
 478  
 479      JSValue job = callFrame->argument(0);
 480      JSValue argument0 = callFrame->argument(1);
 481      JSValue argument1 = callFrame->argument(2);
 482      JSValue argument2 = callFrame->argument(3);
 483  
 484      globalObject->queueMicrotask(createJSMicrotask(vm, job, argument0, argument1, argument2));
 485  
 486      return JSValue::encode(jsUndefined());
 487  }
 488  
 489  JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
 490      : Base(vm, structure, nullptr)
 491      , m_vm(&vm)
 492      , m_linkTimeConstants(numberOfLinkTimeConstants)
 493      , m_masqueradesAsUndefinedWatchpoint(WatchpointSet::create(IsWatched))
 494      , m_havingABadTimeWatchpoint(WatchpointSet::create(IsWatched))
 495      , m_varInjectionWatchpoint(WatchpointSet::create(IsWatched))
 496      , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
 497      , m_arrayIteratorProtocolWatchpointSet(IsWatched)
 498      , m_mapIteratorProtocolWatchpointSet(IsWatched)
 499      , m_setIteratorProtocolWatchpointSet(IsWatched)
 500      , m_stringIteratorProtocolWatchpointSet(IsWatched)
 501      , m_mapSetWatchpointSet(IsWatched)
 502      , m_setAddWatchpointSet(IsWatched)
 503      , m_arrayJoinWatchpointSet(IsWatched)
 504      , m_numberToStringWatchpointSet(IsWatched)
 505      , m_runtimeFlags()
 506      , m_stackTraceLimit(Options::defaultErrorStackTraceLimit())
 507      , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
 508  {
 509  }
 510  
 511  JSGlobalObject::~JSGlobalObject()
 512  {
 513  #if ENABLE(REMOTE_INSPECTOR)
 514      m_inspectorController->globalObjectDestroyed();
 515  #endif
 516  
 517      if (m_debugger)
 518          m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
 519  }
 520  
 521  void JSGlobalObject::destroy(JSCell* cell)
 522  {
 523      static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
 524  }
 525  
 526  void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
 527  {
 528      m_globalThis.set(vm, this, globalThis);
 529  }
 530  
 531  static GetterSetter* getGetterById(JSGlobalObject* globalObject, JSObject* base, const Identifier& ident)
 532  {
 533      VM& vm = globalObject->vm();
 534      JSValue baseValue = JSValue(base);
 535      PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry, &vm);
 536      baseValue.getPropertySlot(globalObject, ident, slot);
 537      return jsCast<GetterSetter*>(slot.getPureResult());
 538  }
 539  
 540  static ObjectPropertyCondition setupAdaptiveWatchpoint(JSGlobalObject* globalObject, JSObject* base, const Identifier& ident)
 541  {
 542      // Performing these gets should not throw.
 543      VM& vm = globalObject->vm();
 544      auto catchScope = DECLARE_CATCH_SCOPE(vm);
 545      PropertySlot slot(base, PropertySlot::InternalMethodType::Get);
 546      bool result = base->getOwnPropertySlot(base, globalObject, ident, slot);
 547      ASSERT_UNUSED(result, result);
 548      catchScope.assertNoException();
 549      RELEASE_ASSERT(slot.isCacheableValue());
 550      JSValue functionValue = slot.getValue(globalObject, ident);
 551      catchScope.assertNoException();
 552      ASSERT(jsDynamicCast<JSFunction*>(vm, functionValue));
 553  
 554      ObjectPropertyCondition condition = generateConditionForSelfEquivalence(vm, nullptr, base, ident.impl());
 555      RELEASE_ASSERT(condition.requiredValue() == functionValue);
 556  
 557      bool isWatchable = condition.isWatchable(PropertyCondition::EnsureWatchability);
 558      RELEASE_ASSERT(isWatchable); // We allow this to install the necessary watchpoints.
 559  
 560      return condition;
 561  }
 562  
 563  template<ErrorType errorType>
 564  void JSGlobalObject::initializeErrorConstructor(LazyClassStructure::Initializer& init)
 565  {
 566      init.setPrototype(NativeErrorPrototype::create(init.vm, NativeErrorPrototype::createStructure(init.vm, this, m_errorStructure.prototype(this)), errorTypeName(errorType)));
 567      init.setStructure(ErrorInstance::createStructure(init.vm, this, init.prototype));
 568      init.setConstructor(NativeErrorConstructor<errorType>::create(init.vm, NativeErrorConstructor<errorType>::createStructure(init.vm, this, m_errorStructure.constructor(this)), jsCast<NativeErrorPrototype*>(init.prototype)));
 569  }
 570  
 571  void JSGlobalObject::initializeAggregateErrorConstructor(LazyClassStructure::Initializer& init)
 572  {
 573      init.setPrototype(AggregateErrorPrototype::create(init.vm, AggregateErrorPrototype::createStructure(init.vm, this, m_errorStructure.prototype(this))));
 574      init.setStructure(AggregateError::createStructure(init.vm, this, init.prototype));
 575      init.setConstructor(AggregateErrorConstructor::create(init.vm, AggregateErrorConstructor::createStructure(init.vm, this, m_errorStructure.constructor(this)), jsCast<AggregateErrorPrototype*>(init.prototype)));
 576  }
 577  
 578  SUPPRESS_ASAN inline void JSGlobalObject::initStaticGlobals(VM& vm)
 579  {
 580      GlobalPropertyInfo staticGlobals[] = {
 581          GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
 582          GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
 583          GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
 584  #if ASSERT_ENABLED
 585          GlobalPropertyInfo(vm.propertyNames->builtinNames().assertPrivateName(), JSFunction::create(vm, this, 1, String(), assertCall), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
 586  #endif
 587      };
 588      addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
 589  }
 590  
 591  void JSGlobalObject::init(VM& vm)
 592  {
 593      ASSERT(vm.currentThreadIsHoldingAPILock());
 594      auto catchScope = DECLARE_CATCH_SCOPE(vm);
 595  
 596      Base::setStructure(vm, Structure::toCacheableDictionaryTransition(vm, structure(vm)));
 597  
 598      m_debugger = nullptr;
 599  
 600  #if ENABLE(REMOTE_INSPECTOR)
 601      m_inspectorController = makeUnique<Inspector::JSGlobalObjectInspectorController>(*this);
 602      m_inspectorDebuggable = makeUnique<JSGlobalObjectDebuggable>(*this);
 603      m_inspectorDebuggable->init();
 604      m_consoleClient = m_inspectorController->consoleClient();
 605  #endif
 606  
 607      m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
 608      m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
 609  
 610      m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
 611  
 612      // Need to create the callee structure (above) before creating the callee.
 613      JSCallee* globalCallee = JSCallee::create(vm, this, globalScope());
 614      m_globalCallee.set(vm, this, globalCallee);
 615  
 616      CallFrame::initDeprecatedCallFrameForDebugger(JSGlobalObject::deprecatedCallFrameForDebugger(), globalCallee);
 617  
 618      JSCallee* stackOverflowFrameCallee = JSCallee::create(vm, this, globalScope());
 619      m_stackOverflowFrameCallee.set(vm, this, stackOverflowFrameCallee);
 620  
 621      m_hostFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
 622  
 623      auto initFunctionStructures = [&] (FunctionStructures& structures) {
 624          structures.strictFunctionStructure.set(vm, this, JSStrictFunction::createStructure(vm, this, m_functionPrototype.get()));
 625          structures.sloppyFunctionStructure.set(vm, this, JSSloppyFunction::createStructure(vm, this, m_functionPrototype.get()));
 626          structures.arrowFunctionStructure.set(vm, this, JSArrowFunction::createStructure(vm, this, m_functionPrototype.get()));
 627      };
 628      initFunctionStructures(m_builtinFunctions);
 629      initFunctionStructures(m_ordinaryFunctions);
 630  
 631      m_customGetterSetterFunctionStructure.initLater(
 632          [] (const Initializer<Structure>& init) {
 633              init.set(JSCustomGetterSetterFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
 634          });
 635      m_boundFunctionStructure.initLater(
 636          [] (const Initializer<Structure>& init) {
 637              init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
 638          });
 639      m_nativeStdFunctionStructure.initLater(
 640          [] (const Initializer<Structure>& init) {
 641              init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
 642          });
 643      JSFunction* callFunction = nullptr;
 644      JSFunction* applyFunction = nullptr;
 645      JSFunction* hasInstanceSymbolFunction = nullptr;
 646      m_functionPrototype->addFunctionProperties(vm, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
 647      m_objectProtoToStringFunction.initLater(
 648          [] (const Initializer<JSFunction>& init) {
 649              init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), objectProtoFuncToString, NoIntrinsic));
 650          });
 651      m_arrayProtoToStringFunction.initLater(
 652          [] (const Initializer<JSFunction>& init) {
 653              init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
 654          });
 655      m_arrayProtoValuesFunction.initLater(
 656          [] (const Initializer<JSFunction>& init) {
 657              init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->builtinNames().valuesPublicName().string(), arrayProtoFuncValues, ArrayValuesIntrinsic));
 658          });
 659  
 660      m_iteratorProtocolFunction.initLater(
 661          [] (const Initializer<JSFunction>& init) {
 662              init.set(JSFunction::create(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
 663          });
 664  
 665      m_promiseResolveFunction.initLater(
 666          [] (const Initializer<JSFunction>& init) {
 667              init.set(JSFunction::create(init.vm, promiseConstructorResolveCodeGenerator(init.vm), init.owner));
 668          });
 669  
 670      m_numberProtoToStringFunction.initLater(
 671          [] (const Initializer<JSFunction>& init) {
 672              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, init.vm.propertyNames->toString.string(), numberProtoFuncToString, NumberPrototypeToStringIntrinsic));
 673          });
 674  
 675      m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
 676      m_throwTypeErrorGetterSetter.initLater(
 677          [] (const Initializer<GetterSetter>& init) {
 678              JSFunction* thrower = init.owner->throwTypeErrorFunction();
 679              GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner, thrower, thrower);
 680              init.set(getterSetter);
 681          });
 682  
 683      m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
 684      Structure* nullSetterFunctionStructure = NullSetterFunction::createStructure(vm, this, m_functionPrototype.get());
 685      m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, nullSetterFunctionStructure, ECMAMode::sloppy()));
 686      m_nullSetterStrictFunction.set(vm, this, NullSetterFunction::create(vm, nullSetterFunctionStructure, ECMAMode::strict()));
 687      m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
 688      // We have to manually set this here because we make it a prototype without transition below.
 689      m_objectPrototype.get()->didBecomePrototype();
 690      GetterSetter* protoAccessor = GetterSetter::create(vm, this,
 691          JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter, UnderscoreProtoIntrinsic),
 692          JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
 693      m_objectPrototype->putDirectNonIndexAccessorWithoutTransition(vm, vm.propertyNames->underscoreProto, protoAccessor, PropertyAttribute::Accessor | PropertyAttribute::DontEnum);
 694      m_functionPrototype->structure(vm)->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
 695      m_objectStructureForObjectConstructor.set(vm, this, vm.structureCache.emptyObjectStructureForPrototype(this, m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
 696      m_objectProtoValueOfFunction.set(vm, this, jsCast<JSFunction*>(objectPrototype()->getDirect(vm, vm.propertyNames->valueOf)));
 697      
 698      JSFunction* thrower = JSFunction::create(vm, this, 0, emptyString(), globalFuncThrowTypeErrorArgumentsCalleeAndCaller);
 699      thrower->freeze(vm);
 700      GetterSetter* getterSetter = GetterSetter::create(vm, this, thrower, thrower);
 701      m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.set(vm, this, getterSetter);
 702      
 703      m_functionPrototype->initRestrictedProperties(vm, this);
 704  
 705      m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this, JSFunction::create(vm, globalOperationsSpeciesGetterCodeGenerator(vm), this), nullptr));
 706  
 707      m_typedArrayProto.initLater(
 708          [] (const Initializer<JSTypedArrayViewPrototype>& init) {
 709              init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
 710              
 711              // Make sure that the constructor gets initialized, too.
 712              init.owner->m_typedArraySuperConstructor.get(init.owner);
 713          });
 714      m_typedArraySuperConstructor.initLater(
 715          [] (const Initializer<JSTypedArrayViewConstructor>& init) {
 716              JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
 717              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());
 718              prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 719              init.set(constructor);
 720          });
 721      
 722  #define INIT_TYPED_ARRAY_LATER(type) \
 723      m_typedArray ## type.initLater( \
 724          [] (LazyClassStructure::Initializer& init) { \
 725              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)))); \
 726              init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
 727              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)); \
 728              init.global->putDirect(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
 729          });
 730      FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
 731  #undef INIT_TYPED_ARRAY_LATER
 732      
 733      m_typedArrayDataView.initLater(
 734          [] (LazyClassStructure::Initializer& init) {
 735              init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
 736              init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
 737              init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, "DataView"_s));
 738          });
 739      
 740      m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
 741      m_moduleEnvironmentStructure.initLater(
 742          [] (const Initializer<Structure>& init) {
 743              init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
 744          });
 745      m_strictEvalActivationStructure.initLater(
 746          [] (const Initializer<Structure>& init) {
 747              init.set(StrictEvalActivation::createStructure(init.vm, init.owner, jsNull()));
 748          });
 749      m_debuggerScopeStructure.initLater(
 750          [] (const Initializer<Structure>& init) {
 751              init.set(DebuggerScope::createStructure(init.vm, init.owner));
 752          });
 753      m_withScopeStructure.initLater(
 754          [] (const Initializer<Structure>& init) {
 755              init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
 756          });
 757      
 758      m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
 759      
 760      m_callbackFunctionStructure.initLater(
 761          [] (const Initializer<Structure>& init) {
 762              init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
 763          });
 764      m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
 765      m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
 766      m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
 767      m_callbackConstructorStructure.initLater(
 768          [] (const Initializer<Structure>& init) {
 769              init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
 770          });
 771      m_callbackObjectStructure.initLater(
 772          [] (const Initializer<Structure>& init) {
 773              init.set(JSCallbackObject<JSNonFinalObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
 774          });
 775  
 776  #if JSC_OBJC_API_ENABLED
 777      m_objcCallbackFunctionStructure.initLater(
 778          [] (const Initializer<Structure>& init) {
 779              init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
 780          });
 781      m_objcWrapperObjectStructure.initLater(
 782          [] (const Initializer<Structure>& init) {
 783              init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
 784          });
 785  #endif
 786  #ifdef JSC_GLIB_API_ENABLED
 787      m_glibCallbackFunctionStructure.initLater(
 788          [] (const Initializer<Structure>& init) {
 789              init.set(JSCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
 790          });
 791      m_glibWrapperObjectStructure.initLater(
 792          [] (const Initializer<Structure>& init) {
 793              init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
 794          });
 795  #endif
 796      m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
 797      
 798      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(UndecidedShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
 799      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(Int32Shape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
 800      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(DoubleShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
 801      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ContiguousShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
 802      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
 803      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(SlowPutArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
 804      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithInt32)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithInt32));
 805      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithDouble)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithDouble));
 806      m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithContiguous));
 807      for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
 808          m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
 809  
 810      m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
 811      m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
 812      m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
 813  
 814      m_moduleRecordStructure.initLater(
 815          [] (const Initializer<Structure>& init) {
 816              init.set(JSModuleRecord::createStructure(init.vm, init.owner, jsNull()));
 817          });
 818      m_moduleNamespaceObjectStructure.initLater(
 819          [] (const Initializer<Structure>& init) {
 820              init.set(JSModuleNamespaceObject::createStructure(init.vm, init.owner, jsNull()));
 821          });
 822      m_proxyObjectStructure.initLater(
 823          [] (const Initializer<Structure>& init) {
 824              bool isCallable = false;
 825              init.set(ProxyObject::createStructure(init.vm, init.owner, jsNull(), isCallable));
 826          });
 827      m_callableProxyObjectStructure.initLater(
 828          [] (const Initializer<Structure>& init) {
 829              bool isCallable = true;
 830              init.set(ProxyObject::createStructure(init.vm, init.owner, jsNull(), isCallable));
 831          });
 832      m_proxyRevokeStructure.initLater(
 833          [] (const Initializer<Structure>& init) {
 834              init.set(ProxyRevoke::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
 835          });
 836  
 837      m_parseIntFunction.initLater(
 838          [] (const Initializer<JSFunction>& init) {
 839              init.set(JSFunction::create(init.vm, init.owner, 2, init.vm.propertyNames->parseInt.string(), globalFuncParseInt, ParseIntIntrinsic));
 840          });
 841      m_parseFloatFunction.initLater(
 842          [] (const Initializer<JSFunction>& init) {
 843              init.set(JSFunction::create(init.vm, init.owner, 1, init.vm.propertyNames->parseFloat.string(), globalFuncParseFloat, NoIntrinsic));
 844          });
 845  
 846      if (Options::useSharedArrayBuffer()) {
 847          m_sharedArrayBufferStructure.initLater(
 848              [] (LazyClassStructure::Initializer& init) {
 849                  init.setPrototype(JSArrayBufferPrototype::create(init.vm, init.global, JSArrayBufferPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get()), ArrayBufferSharingMode::Shared));
 850                  init.setStructure(JSArrayBuffer::createStructure(init.vm, init.global, init.prototype));
 851                  init.setConstructor(JSSharedArrayBufferConstructor::create(init.vm, JSSharedArrayBufferConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), jsCast<JSArrayBufferPrototype*>(init.prototype), init.global->m_speciesGetterSetter.get()));
 852              });
 853      }
 854  
 855      m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
 856      m_asyncIteratorPrototype.set(vm, this, AsyncIteratorPrototype::create(vm, this, AsyncIteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
 857  
 858      m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
 859      m_asyncGeneratorPrototype.set(vm, this, AsyncGeneratorPrototype::create(vm, this, AsyncGeneratorPrototype::createStructure(vm, this, m_asyncIteratorPrototype.get())));
 860  
 861      auto* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
 862      m_arrayIteratorPrototype.set(vm, this, arrayIteratorPrototype);
 863      m_arrayIteratorStructure.set(vm, this, JSArrayIterator::createStructure(vm, this, arrayIteratorPrototype));
 864  
 865      auto* mapIteratorPrototype = MapIteratorPrototype::create(vm, this, MapIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
 866      m_mapIteratorPrototype.set(vm, this, mapIteratorPrototype);
 867      m_mapIteratorStructure.set(vm, this, JSMapIterator::createStructure(vm, this, mapIteratorPrototype));
 868  
 869      auto* setIteratorPrototype = SetIteratorPrototype::create(vm, this, SetIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
 870      m_setIteratorPrototype.set(vm, this, setIteratorPrototype);
 871      m_setIteratorStructure.set(vm, this, JSSetIterator::createStructure(vm, this, setIteratorPrototype));
 872  
 873      JSFunction* defaultPromiseThen = JSFunction::create(vm, promisePrototypeThenCodeGenerator(vm), this);
 874      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::defaultPromiseThen)].set(vm, this, defaultPromiseThen);
 875  
 876  #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) if (featureFlag) { \
 877          m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_ ## prototypeBase ## Prototype.get()))); \
 878          m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get())); \
 879      }
 880      
 881      FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
 882      FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
 883      
 884  #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
 885  
 886  #define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) if (featureFlag) {  \
 887      m_ ## properName ## Structure.initLater(\
 888          [] (LazyClassStructure::Initializer& init) { \
 889              init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_ ## prototypeBase ## Prototype.get()))); \
 890              init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
 891              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())); \
 892          }); \
 893      }
 894      
 895      FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
 896      
 897      // Constructors
 898  
 899      ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
 900      m_objectConstructor.set(vm, this, objectConstructor);
 901      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::Object)].set(vm, this, objectConstructor);
 902  
 903      JSFunction* throwTypeErrorFunction = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
 904      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::throwTypeErrorFunction)].set(vm, this, throwTypeErrorFunction);
 905  
 906      FunctionConstructor* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
 907      m_functionConstructor.set(vm, this, functionConstructor);
 908  
 909      ArrayConstructor* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
 910      m_arrayConstructor.set(vm, this, arrayConstructor);
 911      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::Array)].set(vm, this, arrayConstructor);
 912      
 913      RegExpConstructor* regExpConstructor = RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get());
 914      m_regExpConstructor.set(vm, this, regExpConstructor);
 915      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::RegExp)].set(vm, this, regExpConstructor);
 916      m_regExpGlobalData.cachedResult().record(vm, this, nullptr, jsEmptyString(vm), MatchResult(0, 0));
 917      
 918      AtomicsObject* atomicsObject = nullptr;
 919      if (Options::useSharedArrayBuffer())
 920          atomicsObject = AtomicsObject::create(vm, this, AtomicsObject::createStructure(vm, this, m_objectPrototype.get()));
 921  
 922  #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
 923  capitalName ## Constructor* lowerName ## Constructor = featureFlag ? capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()) : nullptr; \
 924      if (featureFlag) \
 925          m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
 926  
 927      FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
 928      
 929  #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
 930  
 931      m_promiseConstructor.set(vm, this, promiseConstructor);
 932      m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
 933      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::Promise)].set(vm, this, promiseConstructor);
 934      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::InternalPromise)].set(vm, this, internalPromiseConstructor);
 935      
 936      m_evalErrorStructure.initLater(
 937          [] (LazyClassStructure::Initializer& init) {
 938              init.global->initializeErrorConstructor<ErrorType::EvalError>(init);
 939          });
 940      m_rangeErrorStructure.initLater(
 941          [] (LazyClassStructure::Initializer& init) {
 942              init.global->initializeErrorConstructor<ErrorType::RangeError>(init);
 943          });
 944      m_referenceErrorStructure.initLater(
 945          [] (LazyClassStructure::Initializer& init) {
 946              init.global->initializeErrorConstructor<ErrorType::ReferenceError>(init);
 947          });
 948      m_syntaxErrorStructure.initLater(
 949          [] (LazyClassStructure::Initializer& init) {
 950              init.global->initializeErrorConstructor<ErrorType::SyntaxError>(init);
 951          });
 952      m_typeErrorStructure.initLater(
 953          [] (LazyClassStructure::Initializer& init) {
 954              init.global->initializeErrorConstructor<ErrorType::TypeError>(init);
 955          });
 956      m_URIErrorStructure.initLater(
 957          [] (LazyClassStructure::Initializer& init) {
 958              init.global->initializeErrorConstructor<ErrorType::URIError>(init);
 959          });
 960      m_aggregateErrorStructure.initLater(
 961          [] (LazyClassStructure::Initializer& init) {
 962              init.global->initializeAggregateErrorConstructor(init);
 963          });
 964  
 965      m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
 966      GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
 967      m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 968      m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
 969  
 970      m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 971      m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 972      m_generatorStructure.set(vm, this, JSGenerator::createStructure(vm, this, m_generatorPrototype.get()));
 973  
 974      m_asyncFunctionPrototype.set(vm, this, AsyncFunctionPrototype::create(vm, AsyncFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
 975      AsyncFunctionConstructor* asyncFunctionConstructor = AsyncFunctionConstructor::create(vm, AsyncFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncFunctionPrototype.get());
 976      m_asyncFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 977      m_asyncFunctionStructure.set(vm, this, JSAsyncFunction::createStructure(vm, this, m_asyncFunctionPrototype.get()));
 978  
 979      m_asyncGeneratorFunctionPrototype.set(vm, this, AsyncGeneratorFunctionPrototype::create(vm, AsyncGeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
 980      AsyncGeneratorFunctionConstructor* asyncGeneratorFunctionConstructor = AsyncGeneratorFunctionConstructor::create(vm, AsyncGeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncGeneratorFunctionPrototype.get());
 981      m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncGeneratorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 982      m_asyncGeneratorFunctionStructure.set(vm, this, JSAsyncGeneratorFunction::createStructure(vm, this, m_asyncGeneratorFunctionPrototype.get()));
 983  
 984      m_asyncGeneratorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_asyncGeneratorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 985      m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_asyncGeneratorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
 986      m_asyncGeneratorStructure.set(vm, this, JSAsyncGenerator::createStructure(vm, this, m_asyncGeneratorPrototype.get()));
 987      
 988      m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 989      m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 990      m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 991      m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 992      
 993      putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 994      putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 995      putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 996      putDirectWithoutTransition(vm, vm.propertyNames->RegExp, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
 997  
 998      if (Options::useSharedArrayBuffer()) {
 999          putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, m_sharedArrayBufferStructure.constructor(this), static_cast<unsigned>(PropertyAttribute::DontEnum));
1000          putDirectWithoutTransition(vm, vm.propertyNames->Atomics, atomicsObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
1001      }
1002  
1003  #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
1004      if (featureFlag) \
1005          putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
1006  
1007  
1008      FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
1009  
1010  #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
1011      m_iteratorResultObjectStructure.initLater(
1012          [] (const Initializer<Structure>& init) {
1013              init.set(createIteratorResultObjectStructure(init.vm, *init.owner));
1014          });
1015      m_dataPropertyDescriptorObjectStructure.initLater(
1016          [] (const Initializer<Structure>& init) {
1017              init.set(createDataPropertyDescriptorObjectStructure(init.vm, *init.owner));
1018          });
1019      m_accessorPropertyDescriptorObjectStructure.initLater(
1020          [] (const Initializer<Structure>& init) {
1021              init.set(createAccessorPropertyDescriptorObjectStructure(init.vm, *init.owner));
1022          });
1023      
1024      m_evalFunction.initLater(
1025          [] (const Initializer<JSFunction>& init) {
1026              init.set(JSFunction::create(init.vm, init.owner, 1, init.vm.propertyNames->eval.string(), globalFuncEval, NoIntrinsic));
1027          });
1028  
1029      m_collatorStructure.initLater(
1030          [] (const Initializer<Structure>& init) {
1031              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1032              IntlCollatorPrototype* collatorPrototype = IntlCollatorPrototype::create(init.vm, globalObject, IntlCollatorPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1033              init.set(IntlCollator::createStructure(init.vm, globalObject, collatorPrototype));
1034          });
1035      m_displayNamesStructure.initLater(
1036          [] (const Initializer<Structure>& init) {
1037              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1038              IntlDisplayNamesPrototype* displayNamesPrototype = IntlDisplayNamesPrototype::create(init.vm, IntlDisplayNamesPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1039              init.set(IntlDisplayNames::createStructure(init.vm, globalObject, displayNamesPrototype));
1040          });
1041      m_listFormatStructure.initLater(
1042          [] (const Initializer<Structure>& init) {
1043              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1044              IntlListFormatPrototype* listFormatPrototype = IntlListFormatPrototype::create(init.vm, IntlListFormatPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1045              init.set(IntlListFormat::createStructure(init.vm, globalObject, listFormatPrototype));
1046          });
1047      m_localeStructure.initLater(
1048          [] (const Initializer<Structure>& init) {
1049              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1050              IntlLocalePrototype* localePrototype = IntlLocalePrototype::create(init.vm, IntlLocalePrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1051              init.set(IntlLocale::createStructure(init.vm, globalObject, localePrototype));
1052          });
1053      m_pluralRulesStructure.initLater(
1054          [] (const Initializer<Structure>& init) {
1055              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1056              IntlPluralRulesPrototype* pluralRulesPrototype = IntlPluralRulesPrototype::create(init.vm, globalObject, IntlPluralRulesPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1057              init.set(IntlPluralRules::createStructure(init.vm, globalObject, pluralRulesPrototype));
1058          });
1059      m_relativeTimeFormatStructure.initLater(
1060          [] (const Initializer<Structure>& init) {
1061              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1062              IntlRelativeTimeFormatPrototype* relativeTimeFormatPrototype = IntlRelativeTimeFormatPrototype::create(init.vm, IntlRelativeTimeFormatPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1063              init.set(IntlRelativeTimeFormat::createStructure(init.vm, globalObject, relativeTimeFormatPrototype));
1064          });
1065      m_segmentIteratorStructure.initLater(
1066          [] (const Initializer<Structure>& init) {
1067              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1068              IntlSegmentIteratorPrototype* segmentIteratorPrototype = IntlSegmentIteratorPrototype::create(init.vm, IntlSegmentIteratorPrototype::createStructure(init.vm, globalObject, globalObject->iteratorPrototype()));
1069              init.set(IntlSegmentIterator::createStructure(init.vm, globalObject, segmentIteratorPrototype));
1070          });
1071      m_segmenterStructure.initLater(
1072          [] (const Initializer<Structure>& init) {
1073              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1074              IntlSegmenterPrototype* segmenterPrototype = IntlSegmenterPrototype::create(init.vm, IntlSegmenterPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1075              init.set(IntlSegmenter::createStructure(init.vm, globalObject, segmenterPrototype));
1076          });
1077      m_segmentsStructure.initLater(
1078          [] (const Initializer<Structure>& init) {
1079              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1080              IntlSegmentsPrototype* segmentsPrototype = IntlSegmentsPrototype::create(init.vm, globalObject, IntlSegmentsPrototype::createStructure(init.vm, globalObject, globalObject->objectPrototype()));
1081              init.set(IntlSegments::createStructure(init.vm, globalObject, segmentsPrototype));
1082          });
1083  
1084      m_dateTimeFormatStructure.initLater(
1085          [] (LazyClassStructure::Initializer& init) {
1086              init.setPrototype(IntlDateTimeFormatPrototype::create(init.vm, init.global, IntlDateTimeFormatPrototype::createStructure(init.vm, init.global, init.global->objectPrototype())));
1087              init.setStructure(IntlDateTimeFormat::createStructure(init.vm, init.global, init.prototype));
1088              init.setConstructor(IntlDateTimeFormatConstructor::create(init.vm, IntlDateTimeFormatConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<IntlDateTimeFormatPrototype*>(init.prototype)));
1089          });
1090      m_numberFormatStructure.initLater(
1091          [] (LazyClassStructure::Initializer& init) {
1092              init.setPrototype(IntlNumberFormatPrototype::create(init.vm, init.global, IntlNumberFormatPrototype::createStructure(init.vm, init.global, init.global->objectPrototype())));
1093              init.setStructure(IntlNumberFormat::createStructure(init.vm, init.global, init.prototype));
1094              init.setConstructor(IntlNumberFormatConstructor::create(init.vm, IntlNumberFormatConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<IntlNumberFormatPrototype*>(init.prototype)));
1095          });
1096  
1097      m_defaultCollator.initLater(
1098          [] (const Initializer<IntlCollator>& init) {
1099              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1100              VM& vm = init.vm;
1101              auto scope = DECLARE_CATCH_SCOPE(vm);
1102              IntlCollator* collator = IntlCollator::create(vm, globalObject->collatorStructure());
1103              collator->initializeCollator(globalObject, jsUndefined(), jsUndefined());
1104              scope.releaseAssertNoException();
1105              init.set(collator);
1106          });
1107  
1108      IntlObject* intl = IntlObject::create(vm, this, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
1109      putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, static_cast<unsigned>(PropertyAttribute::DontEnum));
1110  
1111      m_moduleLoader.initLater(
1112          [] (const Initializer<JSModuleLoader>& init) {
1113              auto catchScope = DECLARE_CATCH_SCOPE(init.vm);
1114              init.set(JSModuleLoader::create(init.owner, init.vm, JSModuleLoader::createStructure(init.vm, init.owner, jsNull())));
1115              catchScope.releaseAssertNoException();
1116          });
1117      if (Options::exposeInternalModuleLoader())
1118          putDirectWithoutTransition(vm, vm.propertyNames->Loader, moduleLoader(), static_cast<unsigned>(PropertyAttribute::DontEnum));
1119  
1120      GetterSetter* regExpProtoFlagsGetter = getGetterById(this, m_regExpPrototype.get(), vm.propertyNames->flags);
1121      catchScope.assertNoException();
1122      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpProtoFlagsGetter)].set(vm, this, regExpProtoFlagsGetter);
1123      GetterSetter* regExpProtoGlobalGetter = getGetterById(this, m_regExpPrototype.get(), vm.propertyNames->global);
1124      catchScope.assertNoException();
1125      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpProtoGlobalGetter)].set(vm, this, regExpProtoGlobalGetter);
1126      GetterSetter* regExpProtoIgnoreCaseGetter = getGetterById(this, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
1127      catchScope.assertNoException();
1128      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpProtoIgnoreCaseGetter)].set(vm, this, regExpProtoIgnoreCaseGetter);
1129      GetterSetter* regExpProtoMultilineGetter = getGetterById(this, m_regExpPrototype.get(), vm.propertyNames->multiline);
1130      catchScope.assertNoException();
1131      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpProtoMultilineGetter)].set(vm, this, regExpProtoMultilineGetter);
1132      GetterSetter* regExpProtoSourceGetter = getGetterById(this, m_regExpPrototype.get(), vm.propertyNames->source);
1133      catchScope.assertNoException();
1134      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpProtoSourceGetter)].set(vm, this, regExpProtoSourceGetter);
1135      GetterSetter* regExpProtoStickyGetter = getGetterById(this, m_regExpPrototype.get(), vm.propertyNames->sticky);
1136      catchScope.assertNoException();
1137      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpProtoStickyGetter)].set(vm, this, regExpProtoStickyGetter);
1138      GetterSetter* regExpProtoUnicodeGetter = getGetterById(this, m_regExpPrototype.get(), vm.propertyNames->unicode);
1139      catchScope.assertNoException();
1140      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpProtoUnicodeGetter)].set(vm, this, regExpProtoUnicodeGetter);
1141      JSFunction* regExpSymbolReplace = jsCast<JSFunction*>(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol));
1142      m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
1143      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpBuiltinExec)].set(vm, this, jsCast<JSFunction*>(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec)));
1144      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpPrototypeSymbolMatch)].set(vm, this, m_regExpPrototype->getDirect(vm, vm.propertyNames->matchSymbol).asCell());
1145      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpPrototypeSymbolReplace)].set(vm, this, m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
1146  
1147      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::isArray)].set(vm, this, arrayConstructor->getDirect(vm, vm.propertyNames->isArray).asCell());
1148      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::callFunction)].set(vm, this, callFunction);
1149      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::applyFunction)].set(vm, this, applyFunction);
1150  
1151      {
1152          JSValue hasOwnPropertyFunction = jsCast<JSFunction*>(objectPrototype()->get(this, vm.propertyNames->hasOwnProperty));
1153          catchScope.assertNoException();
1154          RELEASE_ASSERT(!!jsDynamicCast<JSFunction*>(vm, hasOwnPropertyFunction));
1155          m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::hasOwnPropertyFunction)].set(vm, this, jsCast<JSFunction*>(hasOwnPropertyFunction));
1156      }
1157  
1158  #define INIT_PRIVATE_GLOBAL(funcName, code) \
1159      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::funcName)].initLater([] (const Initializer<JSCell>& init) { \
1160              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner); \
1161              init.set(JSFunction::create(init.vm, code ## CodeGenerator(init.vm), globalObject)); \
1162          });
1163      JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
1164  #undef INIT_PRIVATE_GLOBAL
1165  
1166      // FIXME: Initializing them lazily.
1167      // https://bugs.webkit.org/show_bug.cgi?id=203795
1168      JSObject* asyncFromSyncIteratorPrototype = AsyncFromSyncIteratorPrototype::create(vm, this, AsyncFromSyncIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
1169      jsCast<JSObject*>(linkTimeConstant(LinkTimeConstant::AsyncFromSyncIterator))->putDirect(vm, vm.propertyNames->prototype, asyncFromSyncIteratorPrototype);
1170  
1171      JSObject* regExpStringIteratorPrototype = RegExpStringIteratorPrototype::create(vm, this, RegExpStringIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
1172      jsCast<JSObject*>(linkTimeConstant(LinkTimeConstant::RegExpStringIterator))->putDirect(vm, vm.propertyNames->prototype, regExpStringIteratorPrototype);
1173  
1174      // Map and Set helpers.
1175      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::Set)].initLater([] (const Initializer<JSCell>& init) {
1176              init.set(jsCast<JSGlobalObject*>(init.owner)->setConstructor());
1177          });
1178      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::mapBucketHead)].initLater([] (const Initializer<JSCell>& init) {
1179              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mapPrivateFuncMapBucketHead, JSMapBucketHeadIntrinsic));
1180          });
1181      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::mapBucketNext)].initLater([] (const Initializer<JSCell>& init) {
1182              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mapPrivateFuncMapBucketNext, JSMapBucketNextIntrinsic));
1183          });
1184      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::mapBucketKey)].initLater([] (const Initializer<JSCell>& init) {
1185              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mapPrivateFuncMapBucketKey, JSMapBucketKeyIntrinsic));
1186          });
1187      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::mapBucketValue)].initLater([] (const Initializer<JSCell>& init) {
1188              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mapPrivateFuncMapBucketValue, JSMapBucketValueIntrinsic));
1189          });
1190      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::setBucketHead)].initLater([] (const Initializer<JSCell>& init) {
1191              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), setPrivateFuncSetBucketHead, JSSetBucketHeadIntrinsic));
1192          });
1193      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::setBucketNext)].initLater([] (const Initializer<JSCell>& init) {
1194              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), setPrivateFuncSetBucketNext, JSSetBucketNextIntrinsic));
1195          });
1196      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::setBucketKey)].initLater([] (const Initializer<JSCell>& init) {
1197              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), setPrivateFuncSetBucketKey, JSSetBucketKeyIntrinsic));
1198          });
1199  
1200      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::importModule)].initLater([] (const Initializer<JSCell>& init) {
1201              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), globalFuncImportModule));
1202          });
1203      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::propertyIsEnumerable)].initLater([] (const Initializer<JSCell>& init) {
1204              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), globalFuncPropertyIsEnumerable));
1205          });
1206      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::copyDataProperties)].initLater([] (const Initializer<JSCell>& init) {
1207              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), globalFuncCopyDataProperties));
1208          });
1209      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::enqueueJob)].initLater([] (const Initializer<JSCell>& init) {
1210              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, "enqueueJob"_s, enqueueJob));
1211          });
1212      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::makeTypeError)].initLater([] (const Initializer<JSCell>& init) {
1213              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), globalFuncMakeTypeError));
1214          });
1215      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::AggregateError)].initLater([] (const Initializer<JSCell>& init) {
1216              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1217              init.set(globalObject->m_aggregateErrorStructure.constructor(globalObject));
1218          });
1219      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::typedArrayLength)].initLater([] (const Initializer<JSCell>& init) {
1220              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), typedArrayViewPrivateFuncLength));
1221          });
1222      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::typedArrayGetOriginalConstructor)].initLater([] (const Initializer<JSCell>& init) {
1223              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor));
1224          });
1225      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::typedArraySort)].initLater([] (const Initializer<JSCell>& init) {
1226              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), typedArrayViewPrivateFuncSort));
1227          });
1228      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::isTypedArrayView)].initLater([] (const Initializer<JSCell>& init) {
1229              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), typedArrayViewPrivateFuncIsTypedArrayView, IsTypedArrayViewIntrinsic));
1230          });
1231      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::isSharedTypedArrayView)].initLater([] (const Initializer<JSCell>& init) {
1232              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), typedArrayViewPrivateFuncIsSharedTypedArrayView));
1233          });
1234      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::isDetached)].initLater([] (const Initializer<JSCell>& init) {
1235              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), typedArrayViewPrivateFuncIsDetached));
1236          });
1237      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::typedArrayDefaultComparator)].initLater([] (const Initializer<JSCell>& init) {
1238              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), typedArrayViewPrivateFuncDefaultComparator));
1239          });
1240      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::typedArraySubarrayCreate)].initLater([] (const Initializer<JSCell>& init) {
1241              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), typedArrayViewPrivateFuncSubarrayCreate));
1242          });
1243      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::isBoundFunction)].initLater([] (const Initializer<JSCell>& init) {
1244              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), isBoundFunction));
1245          });
1246      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::hasInstanceBoundFunction)].initLater([] (const Initializer<JSCell>& init) {
1247              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), hasInstanceBoundFunction));
1248          });
1249      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::instanceOf)].initLater([] (const Initializer<JSCell>& init) {
1250              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), objectPrivateFuncInstanceOf));
1251          });
1252      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::BuiltinLog)].initLater([] (const Initializer<JSCell>& init) {
1253              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), globalFuncBuiltinLog));
1254          });
1255      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::BuiltinDescribe)].initLater([] (const Initializer<JSCell>& init) {
1256              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), globalFuncBuiltinDescribe));
1257          });
1258      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::min)].initLater([] (const Initializer<JSCell>& init) {
1259              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mathProtoFuncMin, MinIntrinsic));
1260          });
1261      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::trunc)].initLater([] (const Initializer<JSCell>& init) {
1262              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), mathProtoFuncTrunc, TruncIntrinsic));
1263          });
1264      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::repeatCharacter)].initLater([] (const Initializer<JSCell>& init) {
1265              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), stringProtoFuncRepeatCharacter));
1266          });
1267      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::arraySpeciesCreate)].initLater([] (const Initializer<JSCell>& init) {
1268              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), arrayProtoFuncSpeciesCreate));
1269          });
1270      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::isArraySlow)].initLater([] (const Initializer<JSCell>& init) {
1271              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), arrayConstructorPrivateFuncIsArraySlow));
1272          });
1273      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::concatMemcpy)].initLater([] (const Initializer<JSCell>& init) {
1274              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), arrayProtoPrivateFuncConcatMemcpy));
1275          });
1276      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::appendMemcpy)].initLater([] (const Initializer<JSCell>& init) {
1277              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), arrayProtoPrivateFuncAppendMemcpy));
1278          });
1279      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::hostPromiseRejectionTracker)].initLater([] (const Initializer<JSCell>& init) {
1280              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), globalFuncHostPromiseRejectionTracker));
1281          });
1282      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::InspectorInstrumentation)].initLater([] (const Initializer<JSCell>& init) {
1283              JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
1284              init.set(InspectorInstrumentationObject::create(init.vm, globalObject, InspectorInstrumentationObject::createStructure(init.vm, globalObject, globalObject->m_objectPrototype.get())));
1285          });
1286      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::thisTimeValue)].initLater([] (const Initializer<JSCell>& init) {
1287              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), dateProtoFuncGetTime, DatePrototypeGetTimeIntrinsic));
1288          });
1289      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::sameValue)].initLater([] (const Initializer<JSCell>& init) {
1290              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), objectConstructorIs, ObjectIsIntrinsic));
1291          });
1292      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::setPrototypeDirect)].initLater([] (const Initializer<JSCell>& init) {
1293              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), globalFuncSetPrototypeDirect));
1294          });
1295  
1296      // RegExp.prototype helpers.
1297      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpCreate)].initLater([] (const Initializer<JSCell>& init) {
1298              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), esSpecRegExpCreate, NoIntrinsic));
1299          });
1300      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::isRegExp)].initLater([] (const Initializer<JSCell>& init) {
1301              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), esSpecIsRegExp, NoIntrinsic));
1302          });
1303      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpMatchFast)].initLater([] (const Initializer<JSCell>& init) {
1304              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), regExpProtoFuncMatchFast, RegExpMatchFastIntrinsic));
1305          });
1306      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpSearchFast)].initLater([] (const Initializer<JSCell>& init) {
1307              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), regExpProtoFuncSearchFast));
1308          });
1309      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpSplitFast)].initLater([] (const Initializer<JSCell>& init) {
1310              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), regExpProtoFuncSplitFast));
1311          });
1312      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::regExpTestFast)].initLater([] (const Initializer<JSCell>& init) {
1313              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic));
1314          });
1315  
1316      // String.prototype helpers.
1317      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::stringIncludesInternal)].initLater([] (const Initializer<JSCell>& init) {
1318              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), builtinStringIncludesInternal));
1319          });
1320      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::stringIndexOfInternal)].initLater([] (const Initializer<JSCell>& init) {
1321              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), builtinStringIndexOfInternal));
1322          });
1323      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::stringSplitFast)].initLater([] (const Initializer<JSCell>& init) {
1324              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), stringProtoFuncSplitFast));
1325          });
1326      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::stringSubstringInternal)].initLater([] (const Initializer<JSCell>& init) {
1327              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 2, String(), builtinStringSubstringInternal));
1328          });
1329  
1330      // Function prototype helpers.
1331      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::makeBoundFunction)].initLater([] (const Initializer<JSCell>& init) {
1332              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 5, String(), makeBoundFunction));
1333          });
1334      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::hasOwnLengthProperty)].initLater([] (const Initializer<JSCell>& init) {
1335              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), hasOwnLengthProperty));
1336          });
1337  
1338      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::dateTimeFormat)].initLater([] (const Initializer<JSCell>& init) {
1339              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), globalFuncDateTimeFormat));
1340          });
1341  
1342      // PrivateSymbols / PrivateNames
1343      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::createPrivateSymbol)].initLater([] (const Initializer<JSCell>& init) {
1344              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 0, String(), createPrivateSymbol));
1345          });
1346  
1347  #if ENABLE(WEBASSEMBLY) && ENABLE(WEBASSEMBLY_STREAMING_API)
1348      // WebAssembly Streaming API
1349      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::webAssemblyCompileStreamingInternal)].initLater([] (const Initializer<JSCell>& init) {
1350              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), webAssemblyCompileStreamingInternal));
1351          });
1352      m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::webAssemblyInstantiateStreamingInternal)].initLater([] (const Initializer<JSCell>& init) {
1353              init.set(JSFunction::create(init.vm, jsCast<JSGlobalObject*>(init.owner), 1, String(), webAssemblyInstantiateStreamingInternal));
1354          });
1355  #endif
1356  
1357      if (Options::exposeProfilersOnGlobalObject()) {
1358  #if ENABLE(SAMPLING_PROFILER)
1359          putDirectWithoutTransition(vm, Identifier::fromString(vm, "__enableSamplingProfiler"), JSFunction::create(vm, this, 1, String(), enableSamplingProfiler), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
1360          putDirectWithoutTransition(vm, Identifier::fromString(vm, "__disableSamplingProfiler"), JSFunction::create(vm, this, 1, String(), disableSamplingProfiler), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
1361  #endif
1362          putDirectWithoutTransition(vm, Identifier::fromString(vm, "__enableSuperSampler"), JSFunction::create(vm, this, 1, String(), enableSuperSampler), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
1363          putDirectWithoutTransition(vm, Identifier::fromString(vm, "__disableSuperSampler"), JSFunction::create(vm, this, 1, String(), disableSuperSampler), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
1364      }
1365  
1366      initStaticGlobals(vm);
1367      
1368      if (UNLIKELY(Options::useDollarVM()))
1369          exposeDollarVM(vm);
1370  
1371  #if ENABLE(WEBASSEMBLY)
1372      if (Wasm::isSupported()) {
1373          m_webAssemblyModuleRecordStructure.initLater(
1374              [] (const Initializer<Structure>& init) {
1375                  init.set(WebAssemblyModuleRecord::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
1376              });
1377          m_webAssemblyFunctionStructure.initLater(
1378              [] (const Initializer<Structure>& init) {
1379                  init.set(WebAssemblyFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
1380              });
1381          m_jsToWasmICCalleeStructure.initLater(
1382              [] (const Initializer<Structure>& init) {
1383                  init.set(JSToWasmICCallee::createStructure(init.vm, init.owner, jsNull()));
1384              });
1385          m_webAssemblyWrapperFunctionStructure.initLater(
1386              [] (const Initializer<Structure>& init) {
1387                  init.set(WebAssemblyWrapperFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
1388              });
1389          auto* webAssembly = JSWebAssembly::create(vm, this, JSWebAssembly::createStructure(vm, this, m_objectPrototype.get()));
1390          putDirectWithoutTransition(vm, Identifier::fromString(vm, "WebAssembly"), webAssembly, static_cast<unsigned>(PropertyAttribute::DontEnum));
1391  
1392  #define CREATE_WEBASSEMBLY_PROTOTYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
1393      if (featureFlag) {\
1394          m_ ## properName ## Structure.initLater(\
1395              [] (LazyClassStructure::Initializer& init) { \
1396                  init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->prototypeBase ## Prototype()))); \
1397                  init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
1398                  auto* constructorPrototype = strcmp(#prototypeBase, "error") == 0 ? init.global->m_errorStructure.constructor(init.global) : init.global->functionPrototype(); \
1399                  init.setConstructor(capitalName ## Constructor::create(init.vm, capitalName ## Constructor::createStructure(init.vm, init.global, constructorPrototype), jsCast<capitalName ## Prototype*>(init.prototype))); \
1400              }); \
1401      }
1402  
1403          FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(CREATE_WEBASSEMBLY_PROTOTYPE)
1404  
1405  #undef CREATE_WEBASSEMBLY_CONSTRUCTOR
1406      }
1407  #endif // ENABLE(WEBASSEMBLY)
1408  
1409  #undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
1410  
1411  
1412      {
1413          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, arrayIteratorPrototype, vm.propertyNames->next);
1414          m_arrayIteratorPrototypeNext = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_arrayIteratorProtocolWatchpointSet);
1415          m_arrayIteratorPrototypeNext->install(vm);
1416      }
1417      {
1418          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, this->arrayPrototype(), vm.propertyNames->iteratorSymbol);
1419          m_arrayPrototypeSymbolIteratorWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_arrayIteratorProtocolWatchpointSet);
1420          m_arrayPrototypeSymbolIteratorWatchpoint->install(vm);
1421      }
1422      {
1423          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, this->arrayPrototype(), vm.propertyNames->join);
1424          m_arrayPrototypeJoinWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_arrayJoinWatchpointSet);
1425          m_arrayPrototypeJoinWatchpoint->install(vm);
1426      }
1427  
1428      {
1429          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, mapIteratorPrototype, vm.propertyNames->next);
1430          m_mapIteratorPrototypeNextWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_mapIteratorProtocolWatchpointSet);
1431          m_mapIteratorPrototypeNextWatchpoint->install(vm);
1432      }
1433      {
1434          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, setIteratorPrototype, vm.propertyNames->next);
1435          m_setIteratorPrototypeNextWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_setIteratorProtocolWatchpointSet);
1436          m_setIteratorPrototypeNextWatchpoint->install(vm);
1437      }
1438      {
1439          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, m_stringIteratorPrototype.get(), vm.propertyNames->next);
1440          m_stringIteratorPrototypeNextWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_stringIteratorProtocolWatchpointSet);
1441          m_stringIteratorPrototypeNextWatchpoint->install(vm);
1442      }
1443      {
1444          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, m_stringPrototype.get(), vm.propertyNames->iteratorSymbol);
1445          m_stringPrototypeSymbolIteratorWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_stringIteratorProtocolWatchpointSet);
1446          m_stringPrototypeSymbolIteratorWatchpoint->install(vm);
1447      }
1448  
1449      // Unfortunately, the prototype objects of the builtin objects can be touched from concurrent compilers. So eagerly initialize them only if we use JIT.
1450      if (Options::useJIT()) {
1451          this->booleanPrototype();
1452          this->numberPrototype();
1453          this->symbolPrototype();
1454      }
1455  
1456      fixupPrototypeChainWithObjectPrototype(vm);
1457  }
1458  
1459  bool JSGlobalObject::put(JSCell* cell, JSGlobalObject* globalObject, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
1460  {
1461      VM& vm = globalObject->vm();
1462      auto scope = DECLARE_THROW_SCOPE(vm);
1463      JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1464      ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
1465  
1466      if (UNLIKELY(isThisValueAltered(slot, thisObject)))
1467          RELEASE_AND_RETURN(scope, ordinarySetSlow(globalObject, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode()));
1468  
1469      bool shouldThrowReadOnlyError = slot.isStrictMode();
1470      bool ignoreReadOnlyErrors = false;
1471      bool putResult = false;
1472      bool done = symbolTablePutTouchWatchpointSet(thisObject, globalObject, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
1473      EXCEPTION_ASSERT((!!scope.exception() == (done && !putResult)) || !shouldThrowReadOnlyError);
1474      if (done)
1475          return putResult;
1476      RELEASE_AND_RETURN(scope, Base::put(thisObject, globalObject, propertyName, value, slot));
1477  }
1478  
1479  bool JSGlobalObject::defineOwnProperty(JSObject* object, JSGlobalObject* globalObject, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
1480  {
1481      VM& vm = globalObject->vm();
1482      JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
1483      PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry, &vm);
1484      // silently ignore attempts to add accessors aliasing vars.
1485      if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
1486          return false;
1487      slot.disallowVMEntry.reset();
1488      return Base::defineOwnProperty(thisObject, globalObject, propertyName, descriptor, shouldThrow);
1489  }
1490  
1491  void JSGlobalObject::addGlobalVar(const Identifier& ident)
1492  {
1493      ConcurrentJSLocker locker(symbolTable()->m_lock);
1494      SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
1495      if (!entry.isNull())
1496          return;
1497      
1498      ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1499      SymbolTableEntry newEntry(VarOffset(offset), 0);
1500      newEntry.prepareToWatch();
1501      symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
1502      
1503      ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
1504      RELEASE_ASSERT(offsetForAssert == offset);
1505  }
1506  
1507  void JSGlobalObject::addFunction(JSGlobalObject* globalObject, const Identifier& propertyName)
1508  {
1509      VM& vm = globalObject->vm();
1510      VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
1511      JSCell::deleteProperty(this, globalObject, propertyName);
1512      addGlobalVar(propertyName);
1513  }
1514  
1515  void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
1516  {
1517      m_globalScopeExtension.set(vm(), this, scope);
1518  }
1519  
1520  void JSGlobalObject::clearGlobalScopeExtension()
1521  {
1522      m_globalScopeExtension.clear();
1523  }
1524  
1525  static inline JSObject* lastInPrototypeChain(VM& vm, JSObject* object)
1526  {
1527      JSObject* o = object;
1528      while (o->getPrototypeDirect(vm).isObject())
1529          o = asObject(o->getPrototypeDirect(vm));
1530      return o;
1531  }
1532  
1533  // Private namespace for helpers for JSGlobalObject::haveABadTime()
1534  namespace {
1535  
1536  class GlobalObjectDependencyFinder : public MarkedBlock::VoidFunctor {
1537  public:
1538      GlobalObjectDependencyFinder(VM& vm)
1539          : m_vm(vm)
1540      { }
1541  
1542      IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1543  
1544      void addDependency(JSGlobalObject* key, JSGlobalObject* dependent);
1545      HashSet<JSGlobalObject*>* dependentsFor(JSGlobalObject* key);
1546  
1547  private:
1548      void visit(JSObject*);
1549  
1550      VM& m_vm;
1551      HashMap<JSGlobalObject*, HashSet<JSGlobalObject*>> m_dependencies;
1552  };
1553  
1554  inline void GlobalObjectDependencyFinder::addDependency(JSGlobalObject* key, JSGlobalObject* dependent)
1555  {
1556      auto keyResult = m_dependencies.add(key, HashSet<JSGlobalObject*>());
1557      keyResult.iterator->value.add(dependent);
1558  }
1559  
1560  inline HashSet<JSGlobalObject*>* GlobalObjectDependencyFinder::dependentsFor(JSGlobalObject* key)
1561  {
1562      auto iterator = m_dependencies.find(key);
1563      if (iterator == m_dependencies.end())
1564          return nullptr;
1565      return &iterator->value;
1566  }
1567  
1568  inline void GlobalObjectDependencyFinder::visit(JSObject* object)
1569  {
1570      VM& vm = m_vm;
1571  
1572      if (!object->mayBePrototype())
1573          return;
1574  
1575      JSObject* current = object;
1576      JSGlobalObject* objectGlobalObject = object->globalObject(vm);
1577      do {
1578          JSValue prototypeValue = current->getPrototypeDirect(vm);
1579          if (prototypeValue.isNull())
1580              return;
1581          current = asObject(prototypeValue);
1582  
1583          JSGlobalObject* protoGlobalObject = current->globalObject(vm);
1584          if (protoGlobalObject != objectGlobalObject)
1585              addDependency(protoGlobalObject, objectGlobalObject);
1586      } while (true);
1587  }
1588  
1589  IterationStatus GlobalObjectDependencyFinder::operator()(HeapCell* cell, HeapCell::Kind kind) const
1590  {
1591      if (isJSCellKind(kind) && static_cast<JSCell*>(cell)->isObject()) {
1592          // FIXME: This const_cast exists because this isn't a C++ lambda.
1593          // https://bugs.webkit.org/show_bug.cgi?id=159644
1594          const_cast<GlobalObjectDependencyFinder*>(this)->visit(jsCast<JSObject*>(static_cast<JSCell*>(cell)));
1595      }
1596      return IterationStatus::Continue;
1597  }
1598  
1599  enum class BadTimeFinderMode {
1600      SingleGlobal,
1601      MultipleGlobals
1602  };
1603  
1604  template<BadTimeFinderMode mode>
1605  class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
1606  public:
1607      ObjectsWithBrokenIndexingFinder(VM&, Vector<JSObject*>&, JSGlobalObject*);
1608      ObjectsWithBrokenIndexingFinder(VM&, Vector<JSObject*>&, HashSet<JSGlobalObject*>&);
1609  
1610      bool needsMultiGlobalsScan() const { return m_needsMultiGlobalsScan; }
1611      IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1612  
1613  private:
1614      IterationStatus visit(JSObject*);
1615  
1616      VM& m_vm;
1617      Vector<JSObject*>& m_foundObjects;
1618      JSGlobalObject* m_globalObject { nullptr }; // Only used for SingleBadTimeGlobal mode.
1619      HashSet<JSGlobalObject*>* m_globalObjects { nullptr }; // Only used for BadTimeGlobalGraph mode;
1620      bool m_needsMultiGlobalsScan { false };
1621  };
1622  
1623  template<>
1624  ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::SingleGlobal>::ObjectsWithBrokenIndexingFinder(
1625      VM& vm, Vector<JSObject*>& foundObjects, JSGlobalObject* globalObject)
1626      : m_vm(vm)
1627      , m_foundObjects(foundObjects)
1628      , m_globalObject(globalObject)
1629  {
1630  }
1631  
1632  template<>
1633  ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::MultipleGlobals>::ObjectsWithBrokenIndexingFinder(
1634      VM& vm, Vector<JSObject*>& foundObjects, HashSet<JSGlobalObject*>& globalObjects)
1635      : m_vm(vm)
1636      , m_foundObjects(foundObjects)
1637      , m_globalObjects(&globalObjects)
1638  {
1639  }
1640  
1641  inline bool hasBrokenIndexing(IndexingType type)
1642  {
1643      return type && !hasSlowPutArrayStorage(type);
1644  }
1645  
1646  inline bool hasBrokenIndexing(JSObject* object)
1647  {
1648      IndexingType type = object->indexingType();
1649      return hasBrokenIndexing(type);
1650  }
1651  
1652  template<BadTimeFinderMode mode>
1653  inline IterationStatus ObjectsWithBrokenIndexingFinder<mode>::visit(JSObject* object)
1654  {
1655      VM& vm = m_vm;
1656  
1657      // We only want to have a bad time in the affected global object, not in the entire
1658      // VM. But we have to be careful, since there may be objects that claim to belong to
1659      // a different global object that have prototypes from our global object.
1660      auto isInAffectedGlobalObject = [&] (JSObject* object) {
1661          JSGlobalObject* objectGlobalObject { nullptr };
1662          bool objectMayBePrototype { false };
1663  
1664          if (mode == BadTimeFinderMode::SingleGlobal) {
1665              objectGlobalObject = object->globalObject(vm);
1666              if (objectGlobalObject == m_globalObject)
1667                  return true;
1668  
1669              objectMayBePrototype = object->mayBePrototype();
1670          }
1671  
1672          for (JSObject* current = object; ;) {
1673              JSGlobalObject* currentGlobalObject = current->globalObject(vm);
1674              if (mode == BadTimeFinderMode::SingleGlobal) {
1675                  if (objectMayBePrototype && currentGlobalObject != objectGlobalObject)
1676                      m_needsMultiGlobalsScan = true;
1677                  if (currentGlobalObject == m_globalObject)
1678                      return true;
1679              } else {
1680                  if (m_globalObjects->contains(currentGlobalObject))
1681                      return true;
1682              }
1683  
1684              JSValue prototypeValue = current->getPrototypeDirect(vm);
1685              if (prototypeValue.isNull())
1686                  return false;
1687              current = asObject(prototypeValue);
1688          }
1689          RELEASE_ASSERT_NOT_REACHED();
1690      };
1691  
1692      if (JSFunction* function = jsDynamicCast<JSFunction*>(vm, object)) {
1693          if (FunctionRareData* rareData = function->rareData()) {
1694              // We only use this to cache JSFinalObjects. They do not start off with a broken indexing type.
1695              ASSERT(!(rareData->objectAllocationStructure() && hasBrokenIndexing(rareData->objectAllocationStructure()->indexingType())));
1696  
1697              if (Structure* structure = rareData->internalFunctionAllocationStructure()) {
1698                  if (hasBrokenIndexing(structure->indexingType())) {
1699                      bool isRelevantGlobalObject =
1700                          (mode == BadTimeFinderMode::SingleGlobal
1701                              ? m_globalObject == structure->globalObject()
1702                              : m_globalObjects->contains(structure->globalObject()))
1703                          || (structure->hasMonoProto() && !structure->storedPrototype().isNull() && isInAffectedGlobalObject(asObject(structure->storedPrototype())));
1704                      if (mode == BadTimeFinderMode::SingleGlobal && m_needsMultiGlobalsScan)
1705                          return IterationStatus::Done; // Bailing early and let the MultipleGlobals path handle everything.
1706                      if (isRelevantGlobalObject)
1707                          rareData->clearInternalFunctionAllocationProfile("have a bad time breaking internal function allocation");
1708                  }
1709              }
1710          }
1711      }
1712  
1713      // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
1714      if (!hasBrokenIndexing(object))
1715          return IterationStatus::Continue;
1716  
1717      if (isInAffectedGlobalObject(object))
1718          m_foundObjects.append(object);
1719  
1720      if (mode == BadTimeFinderMode::SingleGlobal && m_needsMultiGlobalsScan)
1721          return IterationStatus::Done; // Bailing early and let the MultipleGlobals path handle everything.
1722  
1723      return IterationStatus::Continue;
1724  }
1725  
1726  template<BadTimeFinderMode mode>
1727  IterationStatus ObjectsWithBrokenIndexingFinder<mode>::operator()(HeapCell* cell, HeapCell::Kind kind) const
1728  {
1729      if (isJSCellKind(kind) && static_cast<JSCell*>(cell)->isObject()) {
1730          // FIXME: This const_cast exists because this isn't a C++ lambda.
1731          // https://bugs.webkit.org/show_bug.cgi?id=159644
1732          return const_cast<ObjectsWithBrokenIndexingFinder*>(this)->visit(jsCast<JSObject*>(static_cast<JSCell*>(cell)));
1733      }
1734      return IterationStatus::Continue;
1735  }
1736  
1737  } // end private namespace for helpers for JSGlobalObject::haveABadTime()
1738  
1739  void JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut(VM& vm)
1740  {
1741      if (isHavingABadTime())
1742          return;
1743  
1744      // Make sure that all JSArray allocations that load the appropriate structure from
1745      // this object now load a structure that uses SlowPut.
1746      for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1747          m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
1748  
1749      // Same for any special array structures.
1750      Structure* slowPutStructure;
1751      slowPutStructure = createRegExpMatchesArraySlowPutStructure(vm, this);
1752      m_regExpMatchesArrayStructure.set(vm, this, slowPutStructure);
1753      slowPutStructure = ClonedArguments::createSlowPutStructure(vm, this, m_objectPrototype.get());
1754      m_clonedArgumentsStructure.set(vm, this, slowPutStructure);
1755  
1756      // Make sure that all allocations or indexed storage transitions that are inlining
1757      // the assumption that it's safe to transition to a non-SlowPut array storage don't
1758      // do so anymore.
1759      // Note: we are deliberately firing the watchpoint here at the end only after
1760      // making all the array structures SlowPut. This ensures that the concurrent
1761      // JIT threads will always get the SlowPut versions of the structures if
1762      // isHavingABadTime() returns true. The concurrent JIT relies on this.
1763      m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
1764      ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
1765  };
1766  
1767  void JSGlobalObject::haveABadTime(VM& vm)
1768  {
1769      ASSERT(&vm == &this->vm());
1770      
1771      if (isHavingABadTime())
1772          return;
1773  
1774      vm.structureCache.clear(); // We may be caching array structures in here.
1775  
1776      DeferGC deferGC(vm.heap);
1777  
1778      // Consider the following objects and prototype chains:
1779      //    O (of global G1) -> A (of global G1)
1780      //    B (of global G2) where G2 has a bad time
1781      //
1782      // If we set B as the prototype of A, G1 will need to have a bad time.
1783      // See comments in Structure::mayInterceptIndexedAccesses() for why.
1784      //
1785      // Now, consider the following objects and prototype chains:
1786      //    O1 (of global G1) -> A1 (of global G1) -> B1 (of global G2)
1787      //    O2 (of global G2) -> A2 (of global G2)
1788      //    B2 (of global G3) where G3 has a bad time.
1789      //
1790      // G1 and G2 does not have a bad time, but G3 already has a bad time.
1791      // If we set B2 as the prototype of A2, then G2 needs to have a bad time.
1792      // Note that by induction, G1 also now needs to have a bad time because of
1793      // O1 -> A1 -> B1.
1794      //
1795      // We describe this as global G1 being affected by global G2, and G2 by G3.
1796      // Similarly, we say that G1 is dependent on G2, and G2 on G3.
1797      // Hence, when G3 has a bad time, we need to ensure that all globals that
1798      // are transitively dependent on it also have a bad time (G2 and G1 in this
1799      // example).
1800      //
1801      // Apart from clearing the VM structure cache above, there are 2 more things
1802      // that we have to do when globals have a bad time:
1803      // 1. For each affected global:
1804      //    a. Fire its HaveABadTime watchpoint.
1805      //    b. Convert all of its array structures to SlowPutArrayStorage.
1806      // 2. Make sure that all affected objects  switch to the slow kind of
1807      //    indexed storage. An object is considered to be affected if it has
1808      //    indexed storage and has a prototype object which may have indexed
1809      //    accessors. If the prototype object belongs to a global having a bad
1810      //    time, then the prototype object is considered to possibly have indexed
1811      //    accessors. See comments in Structure::mayInterceptIndexedAccesses()
1812      //    for details.
1813      //
1814      // Note: step 1 must be completed before step 2 because step 2 relies on
1815      // the HaveABadTime watchpoint having already been fired on all affected
1816      // globals.
1817      //
1818      // In the common case, only this global will start having a bad time here,
1819      // and no other globals are affected by it. So, we first proceed on this assumption
1820      // with a simpler ObjectsWithBrokenIndexingFinder scan to find heap objects
1821      // affected by this global that need to be converted to SlowPutArrayStorage.
1822      // We'll also have the finder check for the presence of other global objects
1823      // depending on this one.
1824      //
1825      // If we do discover other globals depending on this one, we'll abort this
1826      // first ObjectsWithBrokenIndexingFinder scan because it will be insufficient
1827      // to find all affected objects that need to be converted to SlowPutArrayStorage.
1828      // It also does not make dependent globals have a bad time. Instead, we'll
1829      // take a more comprehensive approach of first creating a dependency graph
1830      // between globals, and then using that graph to determine all affected
1831      // globals and objects. With that, we can make all affected globals have a
1832      // bad time, and convert all affected objects to SlowPutArrayStorage.
1833  
1834      fireWatchpointAndMakeAllArrayStructuresSlowPut(vm); // Step 1 above.
1835      
1836      Vector<JSObject*> foundObjects;
1837      ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::SingleGlobal> finder(vm, foundObjects, this);
1838      {
1839          HeapIterationScope iterationScope(vm.heap);
1840          vm.heap.objectSpace().forEachLiveCell(iterationScope, finder); // Attempt step 2 above.
1841      }
1842  
1843      if (finder.needsMultiGlobalsScan()) {
1844          foundObjects.clear();
1845  
1846          // Find all globals that will also have a bad time as a side effect of
1847          // this global having a bad time.
1848          GlobalObjectDependencyFinder dependencies(vm);
1849          {
1850              HeapIterationScope iterationScope(vm.heap);
1851              vm.heap.objectSpace().forEachLiveCell(iterationScope, dependencies);
1852          }
1853  
1854          HashSet<JSGlobalObject*> globalsHavingABadTime;
1855          Deque<JSGlobalObject*> globals;
1856  
1857          globals.append(this);
1858          while (!globals.isEmpty()) {
1859              JSGlobalObject* global = globals.takeFirst();
1860              global->fireWatchpointAndMakeAllArrayStructuresSlowPut(vm); // Step 1 above.
1861              auto result = globalsHavingABadTime.add(global);
1862              if (result.isNewEntry) {
1863                  if (HashSet<JSGlobalObject*>* dependents = dependencies.dependentsFor(global)) {
1864                      for (JSGlobalObject* dependentGlobal : *dependents)
1865                          globals.append(dependentGlobal);
1866                  }
1867              }
1868          }
1869  
1870          ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::MultipleGlobals> finder(vm, foundObjects, globalsHavingABadTime);
1871          {
1872              HeapIterationScope iterationScope(vm.heap);
1873              vm.heap.objectSpace().forEachLiveCell(iterationScope, finder); // Step 2 above.
1874          }
1875      }
1876  
1877      while (!foundObjects.isEmpty()) {
1878          JSObject* object = asObject(foundObjects.last());
1879          foundObjects.removeLast();
1880          ASSERT(hasBrokenIndexing(object));
1881          object->switchToSlowPutArrayStorage(vm);
1882      }
1883  }
1884  
1885  void JSGlobalObject::fixupPrototypeChainWithObjectPrototype(VM& vm)
1886  {
1887      JSObject* oldLastInPrototypeChain = lastInPrototypeChain(vm, this);
1888      JSObject* objectPrototype = m_objectPrototype.get();
1889      if (oldLastInPrototypeChain != objectPrototype)
1890          oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1891  }
1892  
1893  // Set prototype, and also insert the object prototype at the end of the chain.
1894  void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1895  {
1896      if (getPrototypeDirect(vm) == prototype)
1897          return;
1898      setPrototypeDirect(vm, prototype);
1899      fixupPrototypeChainWithObjectPrototype(vm);
1900      // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1901      setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1902  }
1903  
1904  void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1905  { 
1906      JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1907      ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1908      Base::visitChildren(thisObject, visitor);
1909  
1910      visitor.append(thisObject->m_globalThis);
1911  
1912      visitor.append(thisObject->m_globalLexicalEnvironment);
1913      visitor.append(thisObject->m_globalScopeExtension);
1914      visitor.append(thisObject->m_globalCallee);
1915      visitor.append(thisObject->m_stackOverflowFrameCallee);
1916      thisObject->m_evalErrorStructure.visit(visitor);
1917      thisObject->m_rangeErrorStructure.visit(visitor);
1918      thisObject->m_referenceErrorStructure.visit(visitor);
1919      thisObject->m_syntaxErrorStructure.visit(visitor);
1920      thisObject->m_typeErrorStructure.visit(visitor);
1921      thisObject->m_URIErrorStructure.visit(visitor);
1922      thisObject->m_aggregateErrorStructure.visit(visitor);
1923      visitor.append(thisObject->m_arrayConstructor);
1924      visitor.append(thisObject->m_regExpConstructor);
1925      visitor.append(thisObject->m_objectConstructor);
1926      visitor.append(thisObject->m_functionConstructor);
1927      visitor.append(thisObject->m_promiseConstructor);
1928      visitor.append(thisObject->m_internalPromiseConstructor);
1929  
1930      thisObject->m_defaultCollator.visit(visitor);
1931      thisObject->m_collatorStructure.visit(visitor);
1932      thisObject->m_displayNamesStructure.visit(visitor);
1933      thisObject->m_listFormatStructure.visit(visitor);
1934      thisObject->m_localeStructure.visit(visitor);
1935      thisObject->m_pluralRulesStructure.visit(visitor);
1936      thisObject->m_relativeTimeFormatStructure.visit(visitor);
1937      thisObject->m_segmentIteratorStructure.visit(visitor);
1938      thisObject->m_segmenterStructure.visit(visitor);
1939      thisObject->m_segmentsStructure.visit(visitor);
1940      thisObject->m_dateTimeFormatStructure.visit(visitor);
1941      thisObject->m_numberFormatStructure.visit(visitor);
1942  
1943      visitor.append(thisObject->m_nullGetterFunction);
1944      visitor.append(thisObject->m_nullSetterFunction);
1945      visitor.append(thisObject->m_nullSetterStrictFunction);
1946  
1947      thisObject->m_parseIntFunction.visit(visitor);
1948      thisObject->m_parseFloatFunction.visit(visitor);
1949      thisObject->m_objectProtoToStringFunction.visit(visitor);
1950      thisObject->m_arrayProtoToStringFunction.visit(visitor);
1951      thisObject->m_arrayProtoValuesFunction.visit(visitor);
1952      thisObject->m_evalFunction.visit(visitor);
1953      thisObject->m_iteratorProtocolFunction.visit(visitor);
1954      thisObject->m_promiseResolveFunction.visit(visitor);
1955      visitor.append(thisObject->m_objectProtoValueOfFunction);
1956      thisObject->m_numberProtoToStringFunction.visit(visitor);
1957      visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
1958      thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1959      visitor.append(thisObject->m_regExpProtoSymbolReplace);
1960      visitor.append(thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
1961      thisObject->m_moduleLoader.visit(visitor);
1962  
1963      visitor.append(thisObject->m_objectPrototype);
1964      visitor.append(thisObject->m_functionPrototype);
1965      visitor.append(thisObject->m_arrayPrototype);
1966      visitor.append(thisObject->m_iteratorPrototype);
1967      visitor.append(thisObject->m_generatorFunctionPrototype);
1968      visitor.append(thisObject->m_generatorPrototype);
1969      visitor.append(thisObject->m_arrayIteratorPrototype);
1970      visitor.append(thisObject->m_mapIteratorPrototype);
1971      visitor.append(thisObject->m_setIteratorPrototype);
1972      visitor.append(thisObject->m_asyncFunctionPrototype);
1973      visitor.append(thisObject->m_asyncGeneratorPrototype);
1974      visitor.append(thisObject->m_asyncIteratorPrototype);
1975      visitor.append(thisObject->m_asyncGeneratorFunctionPrototype);
1976  
1977      thisObject->m_debuggerScopeStructure.visit(visitor);
1978      thisObject->m_withScopeStructure.visit(visitor);
1979      thisObject->m_strictEvalActivationStructure.visit(visitor);
1980      visitor.append(thisObject->m_lexicalEnvironmentStructure);
1981      thisObject->m_moduleEnvironmentStructure.visit(visitor);
1982      visitor.append(thisObject->m_directArgumentsStructure);
1983      visitor.append(thisObject->m_scopedArgumentsStructure);
1984      visitor.append(thisObject->m_clonedArgumentsStructure);
1985      visitor.append(thisObject->m_objectStructureForObjectConstructor);
1986      for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1987          visitor.append(thisObject->m_originalArrayStructureForIndexingShape[i]);
1988      for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1989          visitor.append(thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1990      thisObject->m_callbackConstructorStructure.visit(visitor);
1991      thisObject->m_callbackFunctionStructure.visit(visitor);
1992      thisObject->m_callbackObjectStructure.visit(visitor);
1993  #if JSC_OBJC_API_ENABLED
1994      thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1995      thisObject->m_objcWrapperObjectStructure.visit(visitor);
1996  #endif
1997  #ifdef JSC_GLIB_API_ENABLED
1998      thisObject->m_glibCallbackFunctionStructure.visit(visitor);
1999      thisObject->m_glibWrapperObjectStructure.visit(visitor);
2000  #endif
2001      visitor.append(thisObject->m_nullPrototypeObjectStructure);
2002      visitor.append(thisObject->m_calleeStructure);
2003  
2004      visitor.append(thisObject->m_hostFunctionStructure);
2005      auto visitFunctionStructures = [&] (FunctionStructures& structures) {
2006          visitor.append(structures.arrowFunctionStructure);
2007          visitor.append(structures.sloppyFunctionStructure);
2008          visitor.append(structures.strictFunctionStructure);
2009      };
2010      visitFunctionStructures(thisObject->m_builtinFunctions);
2011      visitFunctionStructures(thisObject->m_ordinaryFunctions);
2012  
2013      thisObject->m_customGetterSetterFunctionStructure.visit(visitor);
2014      thisObject->m_boundFunctionStructure.visit(visitor);
2015      thisObject->m_nativeStdFunctionStructure.visit(visitor);
2016      visitor.append(thisObject->m_regExpStructure);
2017      visitor.append(thisObject->m_generatorFunctionStructure);
2018      visitor.append(thisObject->m_asyncFunctionStructure);
2019      visitor.append(thisObject->m_asyncGeneratorFunctionStructure);
2020      visitor.append(thisObject->m_generatorStructure);
2021      visitor.append(thisObject->m_asyncGeneratorStructure);
2022      visitor.append(thisObject->m_arrayIteratorStructure);
2023      visitor.append(thisObject->m_mapIteratorStructure);
2024      visitor.append(thisObject->m_setIteratorStructure);
2025      thisObject->m_iteratorResultObjectStructure.visit(visitor);
2026      thisObject->m_dataPropertyDescriptorObjectStructure.visit(visitor);
2027      thisObject->m_accessorPropertyDescriptorObjectStructure.visit(visitor);
2028      visitor.append(thisObject->m_regExpMatchesArrayStructure);
2029      thisObject->m_moduleRecordStructure.visit(visitor);
2030      thisObject->m_moduleNamespaceObjectStructure.visit(visitor);
2031      thisObject->m_proxyObjectStructure.visit(visitor);
2032      thisObject->m_callableProxyObjectStructure.visit(visitor);
2033      thisObject->m_proxyRevokeStructure.visit(visitor);
2034      thisObject->m_sharedArrayBufferStructure.visit(visitor);
2035  
2036      for (auto& property : thisObject->m_linkTimeConstants)
2037          property.visit(visitor);
2038  
2039  #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) if (featureFlag) { \
2040          visitor.append(thisObject->m_ ## lowerName ## Prototype); \
2041          visitor.append(thisObject->m_ ## properName ## Structure); \
2042      }
2043  
2044      FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
2045      FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE)
2046  
2047  #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) if (featureFlag) \
2048          thisObject->m_ ## properName ## Structure.visit(visitor);
2049  
2050      FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
2051  
2052  #if ENABLE(WEBASSEMBLY)
2053      thisObject->m_webAssemblyModuleRecordStructure.visit(visitor);
2054      thisObject->m_webAssemblyFunctionStructure.visit(visitor);
2055      thisObject->m_jsToWasmICCalleeStructure.visit(visitor);
2056      thisObject->m_webAssemblyWrapperFunctionStructure.visit(visitor);
2057      FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(VISIT_LAZY_TYPE)
2058  #endif // ENABLE(WEBASSEMBLY)
2059  
2060  #undef VISIT_SIMPLE_TYPE
2061  #undef VISIT_LAZY_TYPE
2062  
2063      for (unsigned i = NumberOfTypedArrayTypes; i--;)
2064          thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
2065      
2066      visitor.append(thisObject->m_speciesGetterSetter);
2067      thisObject->m_typedArrayProto.visit(visitor);
2068      thisObject->m_typedArraySuperConstructor.visit(visitor);
2069      thisObject->m_regExpGlobalData.visitAggregate(visitor);
2070  }
2071  
2072  CallFrame* JSGlobalObject::deprecatedCallFrameForDebugger()
2073  {
2074      return CallFrame::create(m_deprecatedCallFrameForDebugger);
2075  }
2076  
2077  SUPPRESS_ASAN void JSGlobalObject::exposeDollarVM(VM& vm)
2078  {
2079      RELEASE_ASSERT(g_jscConfig.restrictedOptionsEnabled && Options::useDollarVM());
2080      if (hasOwnProperty(this, vm.propertyNames->builtinNames().dollarVMPrivateName()))
2081          return;
2082  
2083      JSDollarVM* dollarVM = JSDollarVM::create(vm, JSDollarVM::createStructure(vm, this, m_objectPrototype.get()));
2084  
2085      GlobalPropertyInfo extraStaticGlobals[] = {
2086          GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
2087      };
2088      addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
2089  
2090      putDirect(vm, Identifier::fromString(vm, "$vm"), dollarVM, static_cast<unsigned>(PropertyAttribute::DontEnum));
2091  }
2092  
2093  void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
2094  {
2095      ScopeOffset startOffset = addVariables(count, jsUndefined());
2096  
2097      for (int i = 0; i < count; ++i) {
2098          GlobalPropertyInfo& global = globals[i];
2099          // This `configurable = false` is necessary condition for static globals,
2100          // otherwise lexical bindings can change the result of GlobalVar queries too.
2101          // We won't be able to declare a global lexical variable with the sanem name to
2102          // the static globals because configurable = false.
2103          ASSERT(global.attributes & PropertyAttribute::DontDelete);
2104          
2105          WatchpointSet* watchpointSet = nullptr;
2106          WriteBarrierBase<Unknown>* variable = nullptr;
2107          {
2108              ConcurrentJSLocker locker(symbolTable()->m_lock);
2109              ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
2110              RELEASE_ASSERT(offset == startOffset + i);
2111              SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
2112              newEntry.prepareToWatch();
2113              watchpointSet = newEntry.watchpointSet();
2114              symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
2115              variable = &variableAt(offset);
2116          }
2117          symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
2118      }
2119  }
2120  
2121  bool JSGlobalObject::getOwnPropertySlot(JSObject* object, JSGlobalObject* globalObject, PropertyName propertyName, PropertySlot& slot)
2122  {
2123      if (Base::getOwnPropertySlot(object, globalObject, propertyName, slot))
2124          return true;
2125      return symbolTableGet(jsCast<JSGlobalObject*>(object), propertyName, slot);
2126  }
2127  
2128  void JSGlobalObject::clearRareData(JSCell* cell)
2129  {
2130      jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
2131  }
2132  
2133  void JSGlobalObject::tryInstallSpeciesWatchpoint(JSObject* prototype, JSObject* constructor, std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>& constructorWatchpoint, std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>& speciesWatchpoint, InlineWatchpointSet& speciesWatchpointSet)
2134  {
2135      RELEASE_ASSERT(!constructorWatchpoint);
2136      RELEASE_ASSERT(!speciesWatchpoint);
2137  
2138      VM& vm = this->vm();
2139      auto scope = DECLARE_THROW_SCOPE(vm);
2140  
2141      // First we need to make sure that the %prototype%.constructor property points to a %constructor%
2142      // and that %constructor%[Symbol.species] is the primordial GetterSetter.
2143  
2144      // We only initialize once so flattening the structures does not have any real cost.
2145      Structure* prototypeStructure = prototype->structure(vm);
2146      if (prototypeStructure->isDictionary())
2147          prototypeStructure = prototypeStructure->flattenDictionaryStructure(vm, prototype);
2148      RELEASE_ASSERT(!prototypeStructure->isDictionary());
2149  
2150      auto invalidateWatchpoint = [&] {
2151          speciesWatchpointSet.invalidate(vm, StringFireDetail("Was not able to set up species watchpoint."));
2152      };
2153  
2154      PropertySlot constructorSlot(prototype, PropertySlot::InternalMethodType::VMInquiry, &vm);
2155      prototype->getOwnPropertySlot(prototype, this, vm.propertyNames->constructor, constructorSlot);
2156      scope.assertNoException();
2157      if (constructorSlot.slotBase() != prototype
2158          || !constructorSlot.isCacheableValue()
2159          || constructorSlot.getValue(this, vm.propertyNames->constructor) != constructor) {
2160          invalidateWatchpoint();
2161          return;
2162      }
2163  
2164      Structure* constructorStructure = constructor->structure(vm);
2165      if (constructorStructure->isDictionary())
2166          constructorStructure = constructorStructure->flattenDictionaryStructure(vm, constructor);
2167  
2168      PropertySlot speciesSlot(constructor, PropertySlot::InternalMethodType::VMInquiry, &vm);
2169      constructor->getOwnPropertySlot(constructor, this, vm.propertyNames->speciesSymbol, speciesSlot);
2170      scope.assertNoException();
2171      if (speciesSlot.slotBase() != constructor
2172          || !speciesSlot.isCacheableGetter()
2173          || speciesSlot.getterSetter() != speciesGetterSetter()) {
2174          invalidateWatchpoint();
2175          return;
2176      }
2177  
2178      // Now we need to setup the watchpoints to make sure these conditions remain valid.
2179      prototypeStructure->startWatchingPropertyForReplacements(vm, constructorSlot.cachedOffset());
2180      constructorStructure->startWatchingPropertyForReplacements(vm, speciesSlot.cachedOffset());
2181  
2182      ObjectPropertyCondition constructorCondition = ObjectPropertyCondition::equivalence(vm, prototype, prototype, vm.propertyNames->constructor.impl(), constructor);
2183      ObjectPropertyCondition speciesCondition = ObjectPropertyCondition::equivalence(vm, prototype, constructor, vm.propertyNames->speciesSymbol.impl(), speciesGetterSetter());
2184  
2185      if (!constructorCondition.isWatchable() || !speciesCondition.isWatchable()) {
2186          invalidateWatchpoint();
2187          return;
2188      }
2189  
2190      // We only watch this from the DFG, and the DFG makes sure to only start watching if the watchpoint is in the IsWatched state.
2191      RELEASE_ASSERT(!speciesWatchpointSet.isBeingWatched());
2192      speciesWatchpointSet.touch(vm, "Set up species watchpoint.");
2193  
2194      constructorWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, constructorCondition, speciesWatchpointSet);
2195      constructorWatchpoint->install(vm);
2196  
2197      speciesWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, speciesCondition, speciesWatchpointSet);
2198      speciesWatchpoint->install(vm);
2199  }
2200  
2201  void JSGlobalObject::tryInstallArraySpeciesWatchpoint()
2202  {
2203      RELEASE_ASSERT(!m_arrayPrototypeConstructorWatchpoint);
2204      RELEASE_ASSERT(!m_arrayConstructorSpeciesWatchpoint);
2205  
2206      tryInstallSpeciesWatchpoint(arrayPrototype(), arrayConstructor(), m_arrayPrototypeConstructorWatchpoint, m_arrayConstructorSpeciesWatchpoint, m_arraySpeciesWatchpointSet);
2207  }
2208  
2209  void JSGlobalObject::tryInstallArrayBufferSpeciesWatchpoint(ArrayBufferSharingMode sharingMode)
2210  {
2211      static_assert(static_cast<unsigned>(ArrayBufferSharingMode::Default) == 0);
2212      static_assert(static_cast<unsigned>(ArrayBufferSharingMode::Shared) == 1);
2213      unsigned index = static_cast<unsigned>(sharingMode);
2214      tryInstallSpeciesWatchpoint(arrayBufferPrototype(sharingMode), arrayBufferConstructor(sharingMode), m_arrayBufferPrototypeConstructorWatchpoints[index], m_arrayBufferConstructorSpeciesWatchpoints[index], arrayBufferSpeciesWatchpointSet(sharingMode));
2215  }
2216  
2217  void JSGlobalObject::installNumberPrototypeWatchpoint(NumberPrototype* numberPrototype)
2218  {
2219      VM& vm = this->vm();
2220      ASSERT(m_numberToStringWatchpointSet.isStillValid());
2221      ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, numberPrototype, vm.propertyNames->toString);
2222      m_numberPrototypeToStringWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_numberToStringWatchpointSet);
2223      m_numberPrototypeToStringWatchpoint->install(vm);
2224  }
2225  
2226  void JSGlobalObject::installMapPrototypeWatchpoint(MapPrototype* mapPrototype)
2227  {
2228      VM& vm = this->vm();
2229      if (m_mapIteratorProtocolWatchpointSet.isStillValid()) {
2230          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, mapPrototype, vm.propertyNames->iteratorSymbol);
2231          m_mapPrototypeSymbolIteratorWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_mapIteratorProtocolWatchpointSet);
2232          m_mapPrototypeSymbolIteratorWatchpoint->install(vm);
2233      }
2234      ASSERT(m_mapSetWatchpointSet.isStillValid());
2235      ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, mapPrototype, vm.propertyNames->set);
2236      m_mapPrototypeSetWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_mapSetWatchpointSet);
2237      m_mapPrototypeSetWatchpoint->install(vm);
2238  }
2239  
2240  void JSGlobalObject::installSetPrototypeWatchpoint(SetPrototype* setPrototype)
2241  {
2242      VM& vm = this->vm();
2243      if (m_setIteratorProtocolWatchpointSet.isStillValid()) {
2244          ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, setPrototype, vm.propertyNames->iteratorSymbol);
2245          m_setPrototypeSymbolIteratorWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_setIteratorProtocolWatchpointSet);
2246          m_setPrototypeSymbolIteratorWatchpoint->install(vm);
2247      }
2248      ASSERT(m_setAddWatchpointSet.isStillValid());
2249      ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this, setPrototype, vm.propertyNames->add);
2250      m_setPrototypeAddWatchpoint = makeUnique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(this, condition, m_setAddWatchpointSet);
2251      m_setPrototypeAddWatchpoint->install(vm);
2252  }
2253  
2254  void slowValidateCell(JSGlobalObject* globalObject)
2255  {
2256      RELEASE_ASSERT(globalObject->isGlobalObject());
2257      ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
2258  }
2259  
2260  void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
2261  {
2262  #if ENABLE(REMOTE_INSPECTOR)
2263      m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
2264  #else
2265      UNUSED_PARAM(enabled);
2266  #endif
2267  }
2268  
2269  bool JSGlobalObject::remoteDebuggingEnabled() const
2270  {
2271  #if ENABLE(REMOTE_INSPECTOR)
2272      return m_inspectorDebuggable->remoteDebuggingAllowed();
2273  #else
2274      return false;
2275  #endif
2276  }
2277  
2278  void JSGlobalObject::setIsITML()
2279  {
2280  #if ENABLE(REMOTE_INSPECTOR)
2281      m_inspectorDebuggable->setIsITML();
2282  #endif
2283  }
2284  
2285  void JSGlobalObject::setName(const String& name)
2286  {
2287      m_name = name;
2288  
2289  #if ENABLE(REMOTE_INSPECTOR)
2290      m_inspectorDebuggable->update();
2291  #endif
2292  }
2293  
2294  void JSGlobalObject::bumpGlobalLexicalBindingEpoch(VM& vm)
2295  {
2296      if (++m_globalLexicalBindingEpoch == Options::thresholdForGlobalLexicalBindingEpoch()) {
2297          // Since the epoch overflows, we should rewrite all the CodeBlock to adjust to the newly started generation.
2298          m_globalLexicalBindingEpoch = 1;
2299          vm.heap.codeBlockSet().iterate([&] (CodeBlock* codeBlock) {
2300              if (codeBlock->globalObject() != this)
2301                  return;
2302              codeBlock->notifyLexicalBindingUpdate();
2303          });
2304      }
2305  }
2306  
2307  void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
2308  {
2309      if (globalObjectMethodTable()->queueTaskToEventLoop) {
2310          globalObjectMethodTable()->queueTaskToEventLoop(*this, WTFMove(task));
2311          return;
2312      }
2313  
2314      vm().queueMicrotask(*this, WTFMove(task));
2315  }
2316  
2317  void JSGlobalObject::reportUncaughtExceptionAtEventLoop(JSGlobalObject*, Exception* exception)
2318  {
2319      dataLogLn("Uncaught Exception at run loop: ", exception->value());
2320  }
2321  
2322  void JSGlobalObject::setConsoleClient(WeakPtr<ConsoleClient>&& consoleClient)
2323  {
2324      m_consoleClient = WTFMove(consoleClient);
2325  }
2326  
2327  void JSGlobalObject::setDebugger(Debugger* debugger)
2328  {
2329      m_debugger = debugger;
2330      if (debugger)
2331          vm().ensureShadowChicken();
2332  }
2333  
2334  bool JSGlobalObject::hasDebugger() const
2335  { 
2336      return m_debugger;
2337  }
2338  
2339  bool JSGlobalObject::hasInteractiveDebugger() const 
2340  { 
2341      return m_debugger && m_debugger->isInteractivelyDebugging();
2342  }
2343  
2344  #if ENABLE(DFG_JIT)
2345  WatchpointSet* JSGlobalObject::getReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
2346  {
2347      ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
2348      return m_referencedGlobalPropertyWatchpointSets.get(uid);
2349  }
2350  
2351  WatchpointSet& JSGlobalObject::ensureReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
2352  {
2353      ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
2354      return m_referencedGlobalPropertyWatchpointSets.ensure(uid, [] {
2355          return WatchpointSet::create(IsWatched);
2356      }).iterator->value.get();
2357  }
2358  #endif
2359  
2360  JSGlobalObject* JSGlobalObject::create(VM& vm, Structure* structure)
2361  {
2362      JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
2363      globalObject->finishCreation(vm);
2364      return globalObject;
2365  }
2366  
2367  void JSGlobalObject::finishCreation(VM& vm)
2368  {
2369      Base::finishCreation(vm);
2370      structure(vm)->setGlobalObject(vm, this);
2371      m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
2372      init(vm);
2373      setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, getPrototypeDirect(vm), PureForwardingProxyType), this));
2374      ASSERT(type() == GlobalObjectType);
2375  }
2376  
2377  void JSGlobalObject::finishCreation(VM& vm, JSObject* thisValue)
2378  {
2379      Base::finishCreation(vm);
2380      structure(vm)->setGlobalObject(vm, this);
2381      m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
2382      init(vm);
2383      setGlobalThis(vm, thisValue);
2384      ASSERT(type() == GlobalObjectType);
2385  }
2386  
2387  #ifdef JSC_GLIB_API_ENABLED
2388  void JSGlobalObject::setWrapperMap(std::unique_ptr<WrapperMap>&& map)
2389  {
2390      m_wrapperMap = WTFMove(map);
2391  }
2392  #endif
2393  
2394  } // namespace JSC