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