2 * Copyright (C) 2007-2009, 2014-2016 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
31 #include "JSGlobalObject.h"
33 #include "ArrayConstructor.h"
34 #include "ArrayIteratorAdaptiveWatchpoint.h"
35 #include "ArrayIteratorPrototype.h"
36 #include "ArrayPrototype.h"
37 #include "AtomicsObject.h"
38 #include "AsyncFunctionConstructor.h"
39 #include "AsyncFunctionPrototype.h"
40 #include "BooleanConstructor.h"
41 #include "BooleanPrototype.h"
42 #include "BuiltinNames.h"
43 #include "ClonedArguments.h"
44 #include "CodeBlock.h"
45 #include "CodeCache.h"
46 #include "ConsoleObject.h"
47 #include "DateConstructor.h"
48 #include "DatePrototype.h"
50 #include "DebuggerScope.h"
51 #include "DirectArguments.h"
52 #include "DirectEvalExecutable.h"
53 #include "ECMAScriptSpecInternalFunctions.h"
55 #include "ErrorConstructor.h"
56 #include "ErrorPrototype.h"
57 #include "FunctionConstructor.h"
58 #include "FunctionPrototype.h"
59 #include "GeneratorFunctionConstructor.h"
60 #include "GeneratorFunctionPrototype.h"
61 #include "GeneratorPrototype.h"
62 #include "GetterSetter.h"
63 #include "HeapIterationScope.h"
64 #include "IndirectEvalExecutable.h"
65 #include "InspectorInstrumentationObject.h"
66 #include "Interpreter.h"
67 #include "IteratorPrototype.h"
68 #include "JSAPIWrapperObject.h"
69 #include "JSArrayBuffer.h"
70 #include "JSArrayBufferConstructor.h"
71 #include "JSArrayBufferPrototype.h"
72 #include "JSAsyncFunction.h"
73 #include "JSBoundFunction.h"
74 #include "JSCInlines.h"
75 #include "JSCallbackConstructor.h"
76 #include "JSCallbackFunction.h"
77 #include "JSCallbackObject.h"
78 #include "JSCustomGetterSetterFunction.h"
79 #include "JSDataView.h"
80 #include "JSDataViewPrototype.h"
81 #include "JSDollarVM.h"
82 #include "JSDollarVMPrototype.h"
83 #include "JSFixedArray.h"
84 #include "JSFunction.h"
85 #include "JSGeneratorFunction.h"
86 #include "JSGenericTypedArrayViewConstructorInlines.h"
87 #include "JSGenericTypedArrayViewInlines.h"
88 #include "JSGenericTypedArrayViewPrototypeInlines.h"
89 #include "JSGlobalObjectFunctions.h"
90 #include "JSInternalPromise.h"
91 #include "JSInternalPromiseConstructor.h"
92 #include "JSInternalPromisePrototype.h"
94 #include "JSLexicalEnvironment.h"
97 #include "JSMapIterator.h"
98 #include "JSModuleEnvironment.h"
99 #include "JSModuleLoader.h"
100 #include "JSModuleNamespaceObject.h"
101 #include "JSModuleRecord.h"
102 #include "JSNativeStdFunction.h"
103 #include "JSONObject.h"
104 #include "JSPromise.h"
105 #include "JSPromiseConstructor.h"
106 #include "JSPromisePrototype.h"
107 #include "JSPropertyNameIterator.h"
109 #include "JSSetIterator.h"
110 #include "JSStringIterator.h"
111 #include "JSTemplateRegistryKey.h"
112 #include "JSTypedArrayConstructors.h"
113 #include "JSTypedArrayPrototypes.h"
114 #include "JSTypedArrayViewConstructor.h"
115 #include "JSTypedArrayViewPrototype.h"
116 #include "JSTypedArrays.h"
117 #include "JSWeakMap.h"
118 #include "JSWeakSet.h"
119 #include "JSWebAssembly.h"
120 #include "JSWebAssemblyCallee.h"
121 #include "JSWithScope.h"
122 #include "LazyClassStructureInlines.h"
123 #include "LazyPropertyInlines.h"
125 #include "MapConstructor.h"
126 #include "MapIteratorPrototype.h"
127 #include "MapPrototype.h"
128 #include "MarkedSpaceInlines.h"
129 #include "MathObject.h"
130 #include "Microtask.h"
131 #include "ModuleLoaderPrototype.h"
132 #include "NativeErrorConstructor.h"
133 #include "NativeErrorPrototype.h"
134 #include "NullGetterFunction.h"
135 #include "NullSetterFunction.h"
136 #include "NumberConstructor.h"
137 #include "NumberPrototype.h"
138 #include "ObjCCallbackFunction.h"
139 #include "ObjectConstructor.h"
140 #include "ObjectPropertyConditionSet.h"
141 #include "ObjectPrototype.h"
142 #include "ParserError.h"
143 #include "ProxyConstructor.h"
144 #include "ProxyObject.h"
145 #include "ProxyRevoke.h"
146 #include "ReflectObject.h"
147 #include "RegExpConstructor.h"
148 #include "RegExpMatchesArray.h"
149 #include "RegExpObject.h"
150 #include "RegExpPrototype.h"
151 #include "ScopedArguments.h"
152 #include "SetConstructor.h"
153 #include "SetIteratorPrototype.h"
154 #include "SetPrototype.h"
155 #include "StrictEvalActivation.h"
156 #include "StringConstructor.h"
157 #include "StringIteratorPrototype.h"
158 #include "StringPrototype.h"
160 #include "SymbolConstructor.h"
161 #include "SymbolPrototype.h"
162 #include "VariableWriteFireDetail.h"
163 #include "WeakGCMapInlines.h"
164 #include "WeakMapConstructor.h"
165 #include "WeakMapPrototype.h"
166 #include "WeakSetConstructor.h"
167 #include "WeakSetPrototype.h"
168 #include <wtf/RandomNumber.h>
171 #include "IntlObject.h"
172 #include <unicode/ucol.h>
173 #include <unicode/udat.h>
174 #include <unicode/unum.h>
175 #endif // ENABLE(INTL)
177 #if ENABLE(REMOTE_INSPECTOR)
178 #include "JSGlobalObjectDebuggable.h"
179 #include "JSGlobalObjectInspectorController.h"
182 #if ENABLE(WEB_REPLAY)
183 #include "EmptyInputCursor.h"
184 #include "JSReplayInputs.h"
189 static JSValue createProxyProperty(VM& vm, JSObject* object)
191 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
192 return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
195 static JSValue createJSONProperty(VM& vm, JSObject* object)
197 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
198 return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
201 static JSValue createMathProperty(VM& vm, JSObject* object)
203 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
204 return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
207 static JSValue createConsoleProperty(VM& vm, JSObject* object)
209 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
210 return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global->globalExec())));
213 static JSValue createAtomicsProperty(VM& vm, JSObject* object)
215 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
216 return AtomicsObject::create(vm, global, AtomicsObject::createStructure(vm, global, global->objectPrototype()));
219 static EncodedJSValue JSC_HOST_CALL makeBoundFunction(ExecState* exec)
222 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
224 JSObject* target = asObject(exec->uncheckedArgument(0));
225 JSValue boundThis = exec->uncheckedArgument(1);
226 JSValue boundArgs = exec->uncheckedArgument(2);
227 JSValue length = exec->uncheckedArgument(3);
228 JSString* name = asString(exec->uncheckedArgument(4));
230 return JSValue::encode(JSBoundFunction::create(
231 vm, exec, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSArray*>(boundArgs) : nullptr, length.asInt32(), name->value(exec)));
234 static EncodedJSValue JSC_HOST_CALL hasOwnLengthProperty(ExecState* exec)
237 JSObject* target = asObject(exec->uncheckedArgument(0));
238 return JSValue::encode(jsBoolean(target->hasOwnProperty(exec, vm.propertyNames->length)));
243 #include "JSGlobalObject.lut.h"
247 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
249 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
250 &supportsRichSourceInfo,
251 &shouldInterruptScript,
252 &javaScriptRuntimeFlags,
254 &shouldInterruptScriptBeforeTimeout,
262 /* Source for JSGlobalObject.lut.h
263 @begin globalObjectTable
264 parseFloat globalFuncParseFloat DontEnum|Function 1
265 isNaN JSBuiltin DontEnum|Function 1
266 isFinite JSBuiltin DontEnum|Function 1
267 escape globalFuncEscape DontEnum|Function 1
268 unescape globalFuncUnescape DontEnum|Function 1
269 decodeURI globalFuncDecodeURI DontEnum|Function 1
270 decodeURIComponent globalFuncDecodeURIComponent DontEnum|Function 1
271 encodeURI globalFuncEncodeURI DontEnum|Function 1
272 encodeURIComponent globalFuncEncodeURIComponent DontEnum|Function 1
273 EvalError JSGlobalObject::m_evalErrorConstructor DontEnum|CellProperty
274 ReferenceError JSGlobalObject::m_referenceErrorConstructor DontEnum|CellProperty
275 SyntaxError JSGlobalObject::m_syntaxErrorConstructor DontEnum|CellProperty
276 URIError JSGlobalObject::m_URIErrorConstructor DontEnum|CellProperty
277 Proxy createProxyProperty DontEnum|PropertyCallback
278 JSON createJSONProperty DontEnum|PropertyCallback
279 Math createMathProperty DontEnum|PropertyCallback
280 Atomics createAtomicsProperty DontEnum|PropertyCallback
281 console createConsoleProperty DontEnum|PropertyCallback
282 Int8Array JSGlobalObject::m_typedArrayInt8 DontEnum|ClassStructure
283 Int16Array JSGlobalObject::m_typedArrayInt16 DontEnum|ClassStructure
284 Int32Array JSGlobalObject::m_typedArrayInt32 DontEnum|ClassStructure
285 Uint8Array JSGlobalObject::m_typedArrayUint8 DontEnum|ClassStructure
286 Uint8ClampedArray JSGlobalObject::m_typedArrayUint8Clamped DontEnum|ClassStructure
287 Uint16Array JSGlobalObject::m_typedArrayUint16 DontEnum|ClassStructure
288 Uint32Array JSGlobalObject::m_typedArrayUint32 DontEnum|ClassStructure
289 Float32Array JSGlobalObject::m_typedArrayFloat32 DontEnum|ClassStructure
290 Float64Array JSGlobalObject::m_typedArrayFloat64 DontEnum|ClassStructure
291 DataView JSGlobalObject::m_typedArrayDataView DontEnum|ClassStructure
292 Set JSGlobalObject::m_setStructure DontEnum|ClassStructure
293 Date JSGlobalObject::m_dateStructure DontEnum|ClassStructure
294 Boolean JSGlobalObject::m_booleanObjectStructure DontEnum|ClassStructure
295 Number JSGlobalObject::m_numberObjectStructure DontEnum|ClassStructure
296 WeakMap JSGlobalObject::m_weakMapStructure DontEnum|ClassStructure
297 WeakSet JSGlobalObject::m_weakSetStructure DontEnum|ClassStructure
301 static EncodedJSValue JSC_HOST_CALL getTemplateObject(ExecState* exec)
303 JSValue thisValue = exec->thisValue();
304 ASSERT(thisValue.inherits(JSTemplateRegistryKey::info()));
305 return JSValue::encode(exec->lexicalGlobalObject()->templateRegistry().getTemplateObject(exec, jsCast<JSTemplateRegistryKey*>(thisValue)));
309 static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
312 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
314 JSValue job = exec->argument(0);
315 JSValue arguments = exec->argument(1);
316 ASSERT(arguments.inherits(JSArray::info()));
318 globalObject->queueMicrotask(createJSJob(vm, job, jsCast<JSArray*>(arguments)));
320 return JSValue::encode(jsUndefined());
323 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
324 : Base(vm, structure, 0)
326 #if ENABLE(WEB_REPLAY)
327 , m_inputCursor(EmptyInputCursor::create())
329 , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
330 , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
331 , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
332 , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
333 , m_arrayIteratorProtocolWatchpoint(IsWatched)
334 , m_templateRegistry(vm)
335 , m_evalEnabled(true)
337 , m_consoleClient(nullptr)
338 , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
342 JSGlobalObject::~JSGlobalObject()
344 #if ENABLE(REMOTE_INSPECTOR)
345 m_inspectorController->globalObjectDestroyed();
349 m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
352 void JSGlobalObject::destroy(JSCell* cell)
354 static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
357 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
359 m_globalThis.set(vm, this, globalThis);
362 static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier& ident)
364 JSValue baseValue = JSValue(base);
365 PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry);
366 baseValue.getPropertySlot(exec, ident, slot);
367 return slot.getPureResult().toObject(exec);
370 void JSGlobalObject::init(VM& vm)
372 ASSERT(vm.currentThreadIsHoldingAPILock());
373 auto catchScope = DECLARE_CATCH_SCOPE(vm);
375 Base::setStructure(vm, Structure::toCacheableDictionaryTransition(vm, structure()));
379 #if ENABLE(REMOTE_INSPECTOR)
380 m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
381 m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
382 m_inspectorDebuggable->init();
383 m_consoleClient = m_inspectorController->consoleClient();
386 m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
387 m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
389 m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
390 // Need to create the callee structure (above) before creating the callee.
391 JSCallee* globalCallee = JSCallee::create(vm, this, globalScope());
392 m_globalCallee.set(vm, this, globalCallee);
394 ExecState::initGlobalExec(JSGlobalObject::globalExec(), globalCallee);
395 ExecState* exec = JSGlobalObject::globalExec();
397 m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
398 m_customGetterSetterFunctionStructure.initLater(
399 [] (const Initializer<Structure>& init) {
400 init.set(JSCustomGetterSetterFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
402 m_boundFunctionStructure.initLater(
403 [] (const Initializer<Structure>& init) {
404 init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
406 m_getterSetterStructure.set(vm, this, GetterSetter::createStructure(vm, this, jsNull()));
407 m_nativeStdFunctionStructure.initLater(
408 [] (const Initializer<Structure>& init) {
409 init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
411 m_namedFunctionStructure.initLater(
412 [] (const Initializer<Structure>& init) {
413 init.set(Structure::addPropertyTransition(init.vm, init.owner->m_functionStructure.get(), init.vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, init.owner->m_functionNameOffset));
415 JSFunction* callFunction = 0;
416 JSFunction* applyFunction = 0;
417 JSFunction* hasInstanceSymbolFunction = 0;
418 m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
419 m_callFunction.set(vm, this, callFunction);
420 m_applyFunction.set(vm, this, applyFunction);
421 m_arrayProtoToStringFunction.initLater(
422 [] (const Initializer<JSFunction>& init) {
423 init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
425 m_arrayProtoValuesFunction.initLater(
426 [] (const Initializer<JSFunction>& init) {
427 init.set(JSFunction::createBuiltinFunction(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
429 m_initializePromiseFunction.initLater(
430 [] (const Initializer<JSFunction>& init) {
431 init.set(JSFunction::createBuiltinFunction(init.vm, promiseOperationsInitializePromiseCodeGenerator(init.vm), init.owner));
434 m_iteratorProtocolFunction.initLater(
435 [] (const Initializer<JSFunction>& init) {
436 init.set(JSFunction::createBuiltinFunction(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
439 m_newPromiseCapabilityFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
440 m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
441 m_throwTypeErrorGetterSetter.initLater(
442 [] (const Initializer<GetterSetter>& init) {
443 JSFunction* thrower = init.owner->throwTypeErrorFunction();
444 GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner);
445 getterSetter->setGetter(init.vm, init.owner, thrower);
446 getterSetter->setSetter(init.vm, init.owner, thrower);
447 init.set(getterSetter);
450 m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
451 m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
452 m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
453 GetterSetter* protoAccessor = GetterSetter::create(vm, this);
454 protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter));
455 protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
456 m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
457 m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
458 m_objectStructureForObjectConstructor.set(vm, this, vm.prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
460 JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeErrorArgumentsCalleeAndCaller);
461 GetterSetter* getterSetter = GetterSetter::create(vm, this);
462 getterSetter->setGetter(vm, this, thrower);
463 getterSetter->setSetter(vm, this, thrower);
464 m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.set(vm, this, getterSetter);
466 m_functionPrototype->initRestrictedProperties(exec, this);
468 m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this));
469 m_speciesGetterSetter->setGetter(vm, this, JSFunction::createBuiltinFunction(vm, globalOperationsSpeciesGetterCodeGenerator(vm), this, "get [Symbol.species]"));
471 m_typedArrayProto.initLater(
472 [] (const Initializer<JSTypedArrayViewPrototype>& init) {
473 init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
475 // Make sure that the constructor gets initialized, too.
476 init.owner->m_typedArraySuperConstructor.get(init.owner);
478 m_typedArraySuperConstructor.initLater(
479 [] (const Initializer<JSTypedArrayViewConstructor>& init) {
480 JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
481 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());
482 prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, DontEnum);
483 init.set(constructor);
486 #define INIT_TYPED_ARRAY_LATER(type) \
487 m_typedArray ## type.initLater( \
488 [] (LazyClassStructure::Initializer& init) { \
489 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)))); \
490 init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
491 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, ASCIILiteral(#type "Array"), typedArrayConstructorAllocate ## type ## ArrayCodeGenerator(init.vm))); \
492 init.global->putDirectWithoutTransition(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, DontEnum); \
494 FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
495 #undef INIT_TYPED_ARRAY_LATER
497 m_typedArrayDataView.initLater(
498 [] (LazyClassStructure::Initializer& init) {
499 init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
500 init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
501 init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, ASCIILiteral("DataView"), nullptr));
504 m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
505 m_moduleEnvironmentStructure.initLater(
506 [] (const Initializer<Structure>& init) {
507 init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
509 m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
510 m_debuggerScopeStructure.initLater(
511 [] (const Initializer<Structure>& init) {
512 init.set(DebuggerScope::createStructure(init.vm, init.owner));
514 m_withScopeStructure.initLater(
515 [] (const Initializer<Structure>& init) {
516 init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
519 m_nullPrototypeObjectStructure.initLater(
520 [] (const Initializer<Structure>& init) {
521 init.set(JSFinalObject::createStructure(init.vm, init.owner, jsNull(), JSFinalObject::defaultInlineCapacity()));
524 m_callbackFunctionStructure.initLater(
525 [] (const Initializer<Structure>& init) {
526 init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
528 m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
529 m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
530 m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
531 m_callbackConstructorStructure.initLater(
532 [] (const Initializer<Structure>& init) {
533 init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
535 m_callbackObjectStructure.initLater(
536 [] (const Initializer<Structure>& init) {
537 init.set(JSCallbackObject<JSDestructibleObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
540 #if JSC_OBJC_API_ENABLED
541 m_objcCallbackFunctionStructure.initLater(
542 [] (const Initializer<Structure>& init) {
543 init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
545 m_objcWrapperObjectStructure.initLater(
546 [] (const Initializer<Structure>& init) {
547 init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
551 m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
553 m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
554 m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
555 m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
556 m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
557 m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
558 m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
559 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
560 m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
562 m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
563 m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
564 m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
566 m_moduleRecordStructure.set(vm, this, JSModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
567 m_moduleNamespaceObjectStructure.set(vm, this, JSModuleNamespaceObject::createStructure(vm, this, jsNull()));
569 bool isCallable = false;
570 m_proxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
572 m_callableProxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
574 m_proxyRevokeStructure.set(vm, this, ProxyRevoke::createStructure(vm, this, m_functionPrototype.get()));
576 m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, NoIntrinsic));
577 putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), DontEnum);
579 m_arrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Default));
580 m_arrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_arrayBufferPrototype.get()));
581 m_sharedArrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Shared));
582 m_sharedArrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_sharedArrayBufferPrototype.get()));
584 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
585 m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_ ## prototypeBase ## Prototype.get()))); \
586 m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
588 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
590 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
592 #define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
593 m_ ## properName ## Structure.initLater(\
594 [] (LazyClassStructure::Initializer& init) { \
595 init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_ ## prototypeBase ## Prototype.get()))); \
596 init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
597 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())); \
600 FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
602 #undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
604 m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
606 #define CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
607 m_ ## lowerName ## Structure.initLater( \
608 [] (const Initializer<Structure>& init) { \
609 JSObject* prototype = capitalName ## Prototype::create(init.vm, init.owner, capitalName ## Prototype::createStructure(init.vm, init.owner, init.owner->m_iteratorPrototype.get())); \
610 init.set(instanceType::createStructure(init.vm, init.owner, prototype)); \
612 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE)
613 #undef CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE
615 m_propertyNameIteratorStructure.set(vm, this, JSPropertyNameIterator::createStructure(vm, this, m_iteratorPrototype.get()));
616 m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
617 m_moduleLoaderPrototype.set(vm, this, ModuleLoaderPrototype::create(vm, this, ModuleLoaderPrototype::createStructure(vm, this, m_objectPrototype.get())));
621 ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
622 m_objectConstructor.set(vm, this, objectConstructor);
624 JSFunction* throwTypeErrorFunction = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
625 m_throwTypeErrorFunction.set(vm, this, throwTypeErrorFunction);
627 JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
629 ArrayConstructor* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
630 m_arrayConstructor.set(vm, this, arrayConstructor);
632 m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get()));
634 JSArrayBufferConstructor* arrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayBufferPrototype.get(), m_speciesGetterSetter.get(), ArrayBufferSharingMode::Default);
635 m_arrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayBufferConstructor, DontEnum);
636 JSArrayBufferConstructor* sharedArrayBufferConstructor = nullptr;
637 sharedArrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_sharedArrayBufferPrototype.get(), m_speciesGetterSetter.get(), ArrayBufferSharingMode::Shared);
638 m_sharedArrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, sharedArrayBufferConstructor, DontEnum);
640 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
641 capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()); \
642 m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \
644 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
646 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
648 m_errorConstructor.set(vm, this, errorConstructor);
649 m_promiseConstructor.set(vm, this, promiseConstructor);
650 m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
652 m_nativeErrorPrototypeStructure.set(vm, this, NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get()));
653 m_nativeErrorStructure.set(vm, this, NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get()));
654 m_evalErrorConstructor.initLater(
655 [] (const Initializer<NativeErrorConstructor>& init) {
656 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("EvalError")));
658 m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("RangeError")));
659 m_referenceErrorConstructor.initLater(
660 [] (const Initializer<NativeErrorConstructor>& init) {
661 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("ReferenceError")));
663 m_syntaxErrorConstructor.initLater(
664 [] (const Initializer<NativeErrorConstructor>& init) {
665 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("SyntaxError")));
667 m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("TypeError")));
668 m_URIErrorConstructor.initLater(
669 [] (const Initializer<NativeErrorConstructor>& init) {
670 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("URIError")));
673 m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
674 GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
675 m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, DontEnum | ReadOnly);
676 m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
678 m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), DontEnum | ReadOnly);
679 m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), DontEnum | ReadOnly);
681 m_asyncFunctionPrototype.set(vm, this, AsyncFunctionPrototype::create(vm, AsyncFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
682 AsyncFunctionConstructor* asyncFunctionConstructor = AsyncFunctionConstructor::create(vm, AsyncFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncFunctionPrototype.get());
683 m_asyncFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncFunctionConstructor, DontEnum | ReadOnly);
684 m_asyncFunctionStructure.set(vm, this, JSAsyncFunction::createStructure(vm, this, m_asyncFunctionPrototype.get()));
686 m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum);
687 m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum);
688 m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, DontEnum);
689 m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum);
691 putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum);
692 putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum);
693 putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum);
694 putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum);
695 putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum);
696 putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum);
698 putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ObjectPrivateName(), objectConstructor, DontEnum | DontDelete | ReadOnly);
699 putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ArrayPrivateName(), arrayConstructor, DontEnum | DontDelete | ReadOnly);
701 putDirectWithoutTransition(vm, vm.propertyNames->ArrayBuffer, arrayBufferConstructor, DontEnum);
702 putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, sharedArrayBufferConstructor, DontEnum);
704 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
705 putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \
707 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
709 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
710 m_iteratorResultObjectStructure.set(vm, this, createIteratorResultObjectStructure(vm, *this));
712 m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
713 putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
716 IntlObject* intl = IntlObject::create(vm, this, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
717 putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, DontEnum);
718 #endif // ENABLE(INTL)
719 ReflectObject* reflectObject = ReflectObject::create(vm, this, ReflectObject::createStructure(vm, this, m_objectPrototype.get()));
720 putDirectWithoutTransition(vm, vm.propertyNames->Reflect, reflectObject, DontEnum);
722 m_moduleLoaderStructure.set(vm, this, JSModuleLoader::createStructure(vm, this, m_moduleLoaderPrototype.get()));
723 m_moduleLoader.set(vm, this, JSModuleLoader::create(globalExec(), vm, this, m_moduleLoaderStructure.get()));
724 if (Options::exposeInternalModuleLoader())
725 putDirectWithoutTransition(vm, vm.propertyNames->Loader, m_moduleLoader.get(), DontEnum);
727 JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
729 JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic);
730 JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
731 JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
733 JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject);
734 JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
735 JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
736 JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
737 JSFunction* privateFuncIsTypedArrayView = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncIsTypedArrayView, IsTypedArrayViewIntrinsic);
738 JSFunction* privateFuncTypedArraySubarrayCreate = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSubarrayCreate);
739 JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
740 JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
741 JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
742 JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
743 JSFunction* privateFuncThisNumberValue = JSFunction::create(vm, this, 0, String(), numberProtoFuncValueOf);
744 JSFunction* privateFuncIsArrayConstructor = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArrayConstructor);
745 JSFunction* privateFuncIsArraySlow = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArraySlow);
746 JSFunction* privateFuncConcatMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncConcatMemcpy);
747 JSFunction* privateFuncAppendMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncAppendMemcpy);
748 JSFunction* privateFuncConcatSlowPath = JSFunction::createBuiltinFunction(vm, arrayPrototypeConcatSlowPathCodeGenerator(vm), this);
750 JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
751 ASSERT_UNUSED(catchScope, !catchScope.exception());
752 JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
753 ASSERT(!catchScope.exception());
754 m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
755 JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
756 ASSERT(!catchScope.exception());
757 JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
758 ASSERT(!catchScope.exception());
759 JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
760 ASSERT(!catchScope.exception());
761 JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
762 ASSERT(!catchScope.exception());
763 JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
764 ASSERT(!catchScope.exception());
765 m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
766 JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
767 m_regExpProtoExec.set(vm, this, builtinRegExpExec);
768 JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
769 m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
771 #define CREATE_PRIVATE_GLOBAL_FUNCTION(name, code) JSFunction* name ## PrivateFunction = JSFunction::createBuiltinFunction(vm, code ## CodeGenerator(vm), this);
772 JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(CREATE_PRIVATE_GLOBAL_FUNCTION)
773 #undef CREATE_PRIVATE_GLOBAL_FUNCTION
775 JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
776 createArrayIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
778 GlobalPropertyInfo staticGlobals[] = {
779 #define INIT_PRIVATE_GLOBAL(name, code) GlobalPropertyInfo(vm.propertyNames->builtinNames().name ## PrivateName(), name ## PrivateFunction, DontEnum | DontDelete | ReadOnly),
780 JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
781 #undef INIT_PRIVATE_GLOBAL
782 GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
783 GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
784 GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
785 GlobalPropertyInfo(vm.propertyNames->builtinNames().ownEnumerablePropertyKeysPrivateName(), JSFunction::create(vm, this, 0, String(), ownEnumerablePropertyKeys), DontEnum | DontDelete | ReadOnly),
786 GlobalPropertyInfo(vm.propertyNames->builtinNames().getTemplateObjectPrivateName(), privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly),
787 GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),
788 GlobalPropertyInfo(vm.propertyNames->builtinNames().ErrorPrivateName(), m_errorConstructor.get(), DontEnum | DontDelete | ReadOnly),
789 GlobalPropertyInfo(vm.propertyNames->builtinNames().RangeErrorPrivateName(), m_rangeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
790 GlobalPropertyInfo(vm.propertyNames->builtinNames().TypeErrorPrivateName(), m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
791 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayLengthPrivateName(), privateFuncTypedArrayLength, DontEnum | DontDelete | ReadOnly),
792 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayGetOriginalConstructorPrivateName(), privateFuncTypedArrayGetOriginalConstructor, DontEnum | DontDelete | ReadOnly),
793 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySortPrivateName(), privateFuncTypedArraySort, DontEnum | DontDelete | ReadOnly),
794 GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, DontEnum | DontDelete | ReadOnly),
795 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySubarrayCreatePrivateName(), privateFuncTypedArraySubarrayCreate, DontEnum | DontDelete | ReadOnly),
796 GlobalPropertyInfo(vm.propertyNames->builtinNames().isBoundFunctionPrivateName(), privateFuncIsBoundFunction, DontEnum | DontDelete | ReadOnly),
797 GlobalPropertyInfo(vm.propertyNames->builtinNames().hasInstanceBoundFunctionPrivateName(), privateFuncHasInstanceBoundFunction, DontEnum | DontDelete | ReadOnly),
798 GlobalPropertyInfo(vm.propertyNames->builtinNames().instanceOfPrivateName(), privateFuncInstanceOf, DontEnum | DontDelete | ReadOnly),
799 GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinLogPrivateName(), builtinLog, DontEnum | DontDelete | ReadOnly),
800 GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberPrivateName(), numberConstructor, DontEnum | DontDelete | ReadOnly),
801 GlobalPropertyInfo(vm.propertyNames->builtinNames().RegExpPrivateName(), m_regExpConstructor.get(), DontEnum | DontDelete | ReadOnly),
802 GlobalPropertyInfo(vm.propertyNames->builtinNames().StringPrivateName(), stringConstructor, DontEnum | DontDelete | ReadOnly),
803 GlobalPropertyInfo(vm.propertyNames->builtinNames().absPrivateName(), privateFuncAbs, DontEnum | DontDelete | ReadOnly),
804 GlobalPropertyInfo(vm.propertyNames->builtinNames().floorPrivateName(), privateFuncFloor, DontEnum | DontDelete | ReadOnly),
805 GlobalPropertyInfo(vm.propertyNames->builtinNames().truncPrivateName(), privateFuncTrunc, DontEnum | DontDelete | ReadOnly),
806 GlobalPropertyInfo(vm.propertyNames->builtinNames().PromisePrivateName(), promiseConstructor, DontEnum | DontDelete | ReadOnly),
807 GlobalPropertyInfo(vm.propertyNames->builtinNames().ReflectPrivateName(), reflectObject, DontEnum | DontDelete | ReadOnly),
808 GlobalPropertyInfo(vm.propertyNames->builtinNames().InternalPromisePrivateName(), internalPromiseConstructor, DontEnum | DontDelete | ReadOnly),
810 GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharacterPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), DontEnum | DontDelete | ReadOnly),
811 GlobalPropertyInfo(vm.propertyNames->builtinNames().SetIteratorPrivateName(), JSFunction::create(vm, this, 1, String(), privateFuncSetIterator), DontEnum | DontDelete | ReadOnly),
812 GlobalPropertyInfo(vm.propertyNames->builtinNames().setIteratorNextPrivateName(), JSFunction::create(vm, this, 0, String(), privateFuncSetIteratorNext), DontEnum | DontDelete | ReadOnly),
813 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayPrivateName(), arrayConstructor->getDirect(vm, vm.propertyNames->isArray), DontEnum | DontDelete | ReadOnly),
814 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArraySlowPrivateName(), privateFuncIsArraySlow, DontEnum | DontDelete | ReadOnly),
815 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayConstructorPrivateName(), privateFuncIsArrayConstructor, DontEnum | DontDelete | ReadOnly),
816 GlobalPropertyInfo(vm.propertyNames->builtinNames().concatMemcpyPrivateName(), privateFuncConcatMemcpy, DontEnum | DontDelete | ReadOnly),
817 GlobalPropertyInfo(vm.propertyNames->builtinNames().appendMemcpyPrivateName(), privateFuncAppendMemcpy, DontEnum | DontDelete | ReadOnly),
818 GlobalPropertyInfo(vm.propertyNames->builtinNames().concatSlowPathPrivateName(), privateFuncConcatSlowPath, DontEnum | DontDelete | ReadOnly),
819 GlobalPropertyInfo(vm.propertyNames->builtinNames().MapIteratorPrivateName(), JSFunction::create(vm, this, 1, String(), privateFuncMapIterator), DontEnum | DontDelete | ReadOnly),
820 GlobalPropertyInfo(vm.propertyNames->builtinNames().mapIteratorNextPrivateName(), JSFunction::create(vm, this, 0, String(), privateFuncMapIteratorNext), DontEnum | DontDelete | ReadOnly),
822 GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum | DontDelete | ReadOnly),
823 GlobalPropertyInfo(vm.propertyNames->builtinNames().MapPrivateName(), mapConstructor, DontEnum | DontDelete | ReadOnly),
824 GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, DontEnum | DontDelete | ReadOnly),
825 GlobalPropertyInfo(vm.propertyNames->builtinNames().thisNumberValuePrivateName(), privateFuncThisNumberValue, DontEnum | DontDelete | ReadOnly),
827 GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), DontEnum | DontDelete | ReadOnly),
828 GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), DontEnum | DontDelete | ReadOnly),
829 GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), DontEnum | DontDelete | ReadOnly),
830 #endif // ENABLE(INTL)
832 GlobalPropertyInfo(vm.propertyNames->builtinNames().isConstructorPrivateName(), JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
834 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoFlagsGetterPrivateName(), regExpProtoFlagsGetterObject, DontEnum | DontDelete | ReadOnly),
835 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoGlobalGetterPrivateName(), regExpProtoGlobalGetterObject, DontEnum | DontDelete | ReadOnly),
836 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoIgnoreCaseGetterPrivateName(), regExpProtoIgnoreCaseGetterObject, DontEnum | DontDelete | ReadOnly),
837 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoMultilineGetterPrivateName(), regExpProtoMultilineGetterObject, DontEnum | DontDelete | ReadOnly),
838 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoSourceGetterPrivateName(), regExpProtoSourceGetterObject, DontEnum | DontDelete | ReadOnly),
839 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoStickyGetterPrivateName(), regExpProtoStickyGetterObject, DontEnum | DontDelete | ReadOnly),
840 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoUnicodeGetterPrivateName(), regExpProtoUnicodeGetterObject, DontEnum | DontDelete | ReadOnly),
842 // RegExp.prototype helpers.
843 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpBuiltinExecPrivateName(), builtinRegExpExec, DontEnum | DontDelete | ReadOnly),
844 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpCreatePrivateName(), JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
845 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpMatchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast), DontEnum | DontDelete | ReadOnly),
846 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSearchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), DontEnum | DontDelete | ReadOnly),
847 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
848 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpPrototypeSymbolReplacePrivateName(), m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol), DontEnum | DontDelete | ReadOnly),
849 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpTestFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic), DontEnum | DontDelete | ReadOnly),
851 // String.prototype helpers.
852 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringIncludesInternalPrivateName(), JSFunction::create(vm, this, 1, String(), builtinStringIncludesInternal), DontEnum | DontDelete | ReadOnly),
853 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
854 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSubstrInternalPrivateName(), JSFunction::create(vm, this, 2, String(), builtinStringSubstrInternal), DontEnum | DontDelete | ReadOnly),
856 // Function prototype helpers.
857 GlobalPropertyInfo(vm.propertyNames->builtinNames().makeBoundFunctionPrivateName(), JSFunction::create(vm, this, 5, String(), makeBoundFunction), DontEnum | DontDelete | ReadOnly),
858 GlobalPropertyInfo(vm.propertyNames->builtinNames().hasOwnLengthPropertyPrivateName(), JSFunction::create(vm, this, 1, String(), hasOwnLengthProperty), DontEnum | DontDelete | ReadOnly),
860 addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
862 m_specialPointers[Special::CallFunction] = m_callFunction.get();
863 m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
864 m_specialPointers[Special::ObjectConstructor] = objectConstructor;
865 m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
867 m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::ThrowTypeErrorFunction)] = m_throwTypeErrorFunction.get();
869 if (UNLIKELY(Options::useDollarVM())) {
870 JSDollarVMPrototype* dollarVMPrototype = JSDollarVMPrototype::create(vm, this, JSDollarVMPrototype::createStructure(vm, this, m_objectPrototype.get()));
871 m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, dollarVMPrototype));
872 JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
874 GlobalPropertyInfo extraStaticGlobals[] = {
875 GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, DontEnum | DontDelete | ReadOnly),
877 addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
879 putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, DontEnum);
882 #if ENABLE(WEBASSEMBLY)
883 if (Options::useWebAssembly()) {
884 auto* webAssemblyPrototype = WebAssemblyPrototype::create(vm, this, WebAssemblyPrototype::createStructure(vm, this, m_objectPrototype.get()));
885 m_webAssemblyStructure.set(vm, this, JSWebAssembly::createStructure(vm, this, webAssemblyPrototype));
886 m_webAssemblyModuleRecordStructure.set(vm, this, WebAssemblyModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
887 m_webAssemblyFunctionStructure.set(vm, this, WebAssemblyFunction::createStructure(vm, this, m_objectPrototype.get()));
888 auto* webAssembly = JSWebAssembly::create(vm, this, m_webAssemblyStructure.get());
889 putDirectWithoutTransition(vm, Identifier::fromString(exec, "WebAssembly"), webAssembly, DontEnum);
891 #define CREATE_WEBASSEMBLY_CONSTRUCTOR(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
892 typedef capitalName ## Prototype Prototype; \
893 typedef capitalName ## Constructor Constructor; \
894 typedef JS ## capitalName JSObj; \
895 auto* base = m_ ## prototypeBase ## Prototype.get(); \
896 auto* prototype = Prototype::create(vm, this, Prototype::createStructure(vm, this, base)); \
897 auto* structure = JSObj::createStructure(vm, this, prototype); \
898 auto* constructor = Constructor::create(vm, Constructor::createStructure(vm, this, this->functionPrototype()), prototype); \
899 prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, constructor, DontEnum); \
900 m_ ## lowerName ## Prototype.set(vm, this, prototype); \
901 m_ ## properName ## Structure.set(vm, this, structure); \
902 webAssembly->putDirectWithoutTransition(vm, Identifier::fromString(this->globalExec(), #jsName), constructor, DontEnum); \
905 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(CREATE_WEBASSEMBLY_CONSTRUCTOR)
907 #undef CREATE_WEBASSEMBLY_CONSTRUCTOR
909 #endif // ENABLE(WEBASSEMBLY)
912 ExecState* exec = globalExec();
914 auto setupAdaptiveWatchpoint = [&] (JSObject* base, const Identifier& ident) -> ObjectPropertyCondition {
915 // Performing these gets should not throw.
916 PropertySlot slot(base, PropertySlot::InternalMethodType::Get);
917 bool result = base->getOwnPropertySlot(base, exec, ident, slot);
918 ASSERT_UNUSED(result, result);
919 ASSERT(!catchScope.exception());
920 RELEASE_ASSERT(slot.isCacheableValue());
921 JSValue functionValue = slot.getValue(exec, ident);
922 ASSERT(!catchScope.exception());
923 ASSERT(jsDynamicCast<JSFunction*>(functionValue));
925 ObjectPropertyCondition condition = generateConditionForSelfEquivalence(m_vm, nullptr, base, ident.impl());
926 RELEASE_ASSERT(condition.requiredValue() == functionValue);
928 bool isWatchable = condition.isWatchable(PropertyCondition::EnsureWatchability);
929 RELEASE_ASSERT(isWatchable); // We allow this to install the necessary watchpoints.
935 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(arrayIteratorPrototype, m_vm.propertyNames->next);
936 m_arrayIteratorPrototypeNext = std::make_unique<ArrayIteratorAdaptiveWatchpoint>(condition, this);
937 m_arrayIteratorPrototypeNext->install();
941 ArrayPrototype* arrayPrototype = this->arrayPrototype();
942 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(arrayPrototype, m_vm.propertyNames->iteratorSymbol);
943 m_arrayPrototypeSymbolIteratorWatchpoint = std::make_unique<ArrayIteratorAdaptiveWatchpoint>(condition, this);
944 m_arrayPrototypeSymbolIteratorWatchpoint->install();
948 resetPrototype(vm, getPrototypeDirect());
951 bool JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
954 auto scope = DECLARE_THROW_SCOPE(vm);
955 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
956 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
958 if (UNLIKELY(isThisValueAltered(slot, thisObject))) {
960 return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
963 bool shouldThrowReadOnlyError = slot.isStrictMode();
964 bool ignoreReadOnlyErrors = false;
965 bool putResult = false;
966 bool done = symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
967 ASSERT((!!scope.exception() == (done && !putResult)) || !shouldThrowReadOnlyError);
971 return Base::put(thisObject, exec, propertyName, value, slot);
974 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
976 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
977 PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry);
978 // silently ignore attempts to add accessors aliasing vars.
979 if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
981 return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
984 void JSGlobalObject::addGlobalVar(const Identifier& ident)
986 ConcurrentJSLocker locker(symbolTable()->m_lock);
987 SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
991 ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
992 SymbolTableEntry newEntry(VarOffset(offset), 0);
993 newEntry.prepareToWatch();
994 symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
996 ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
997 RELEASE_ASSERT(offsetForAssert == offset);
1000 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
1002 VM& vm = exec->vm();
1003 VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
1004 methodTable(vm)->deleteProperty(this, exec, propertyName);
1005 addGlobalVar(propertyName);
1008 void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
1010 m_globalScopeExtension.set(vm(), this, scope);
1013 void JSGlobalObject::clearGlobalScopeExtension()
1015 m_globalScopeExtension.clear();
1018 static inline JSObject* lastInPrototypeChain(JSObject* object)
1020 JSObject* o = object;
1021 while (o->getPrototypeDirect().isObject())
1022 o = asObject(o->getPrototypeDirect());
1026 // Private namespace for helpers for JSGlobalObject::haveABadTime()
1029 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
1031 ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
1032 IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1035 void visit(JSCell*);
1037 MarkedArgumentBuffer& m_foundObjects;
1038 JSGlobalObject* m_globalObject;
1041 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
1042 MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
1043 : m_foundObjects(foundObjects)
1044 , m_globalObject(globalObject)
1048 inline bool hasBrokenIndexing(JSObject* object)
1050 // This will change if we have more indexing types.
1051 IndexingType type = object->indexingType();
1052 // This could be made obviously more efficient, but isn't made so right now, because
1053 // we expect this to be an unlikely slow path anyway.
1054 return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type);
1057 inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell)
1059 if (!cell->isObject())
1062 JSObject* object = asObject(cell);
1064 // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
1065 if (!hasBrokenIndexing(object))
1068 // We only want to have a bad time in the affected global object, not in the entire
1069 // VM. But we have to be careful, since there may be objects that claim to belong to
1070 // a different global object that have prototypes from our global object.
1071 bool foundGlobalObject = false;
1072 for (JSObject* current = object; ;) {
1073 if (current->globalObject() == m_globalObject) {
1074 foundGlobalObject = true;
1078 JSValue prototypeValue = current->getPrototypeDirect();
1079 if (prototypeValue.isNull())
1081 current = asObject(prototypeValue);
1083 if (!foundGlobalObject)
1086 m_foundObjects.append(object);
1089 IterationStatus ObjectsWithBrokenIndexingFinder::operator()(HeapCell* cell, HeapCell::Kind kind) const
1091 if (kind == HeapCell::JSCell) {
1092 // FIXME: This const_cast exists because this isn't a C++ lambda.
1093 // https://bugs.webkit.org/show_bug.cgi?id=159644
1094 const_cast<ObjectsWithBrokenIndexingFinder*>(this)->visit(static_cast<JSCell*>(cell));
1096 return IterationStatus::Continue;
1099 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
1101 void JSGlobalObject::haveABadTime(VM& vm)
1103 ASSERT(&vm == &this->vm());
1105 if (isHavingABadTime())
1108 // Make sure that all allocations or indexed storage transitions that are inlining
1109 // the assumption that it's safe to transition to a non-SlowPut array storage don't
1111 m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
1112 ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
1114 // Make sure that all JSArray allocations that load the appropriate structure from
1115 // this object now load a structure that uses SlowPut.
1116 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1117 m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
1119 // Same for any special array structures.
1120 Structure* slowPutStructure;
1121 slowPutStructure = createRegExpMatchesArraySlowPutStructure(vm, this);
1122 m_regExpMatchesArrayStructure.set(vm, this, slowPutStructure);
1123 slowPutStructure = ClonedArguments::createSlowPutStructure(vm, this, m_objectPrototype.get());
1124 m_clonedArgumentsStructure.set(vm, this, slowPutStructure);
1126 // Make sure that all objects that have indexed storage switch to the slow kind of
1128 MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
1129 ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
1131 HeapIterationScope iterationScope(vm.heap);
1132 vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
1134 while (!foundObjects.isEmpty()) {
1135 JSObject* object = asObject(foundObjects.last());
1136 foundObjects.removeLast();
1137 ASSERT(hasBrokenIndexing(object));
1138 object->switchToSlowPutArrayStorage(vm);
1142 // Set prototype, and also insert the object prototype at the end of the chain.
1143 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1145 setPrototypeDirect(vm, prototype);
1147 JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
1148 JSObject* objectPrototype = m_objectPrototype.get();
1149 if (oldLastInPrototypeChain != objectPrototype)
1150 oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1152 // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1153 setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1156 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1158 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1159 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1160 Base::visitChildren(thisObject, visitor);
1162 visitor.append(&thisObject->m_globalThis);
1164 visitor.append(&thisObject->m_globalLexicalEnvironment);
1165 visitor.append(&thisObject->m_globalScopeExtension);
1166 visitor.append(&thisObject->m_globalCallee);
1167 visitor.append(&thisObject->m_regExpConstructor);
1168 visitor.append(&thisObject->m_errorConstructor);
1169 visitor.append(&thisObject->m_nativeErrorPrototypeStructure);
1170 visitor.append(&thisObject->m_nativeErrorStructure);
1171 thisObject->m_evalErrorConstructor.visit(visitor);
1172 visitor.append(&thisObject->m_rangeErrorConstructor);
1173 thisObject->m_referenceErrorConstructor.visit(visitor);
1174 thisObject->m_syntaxErrorConstructor.visit(visitor);
1175 visitor.append(&thisObject->m_typeErrorConstructor);
1176 thisObject->m_URIErrorConstructor.visit(visitor);
1177 visitor.append(&thisObject->m_objectConstructor);
1178 visitor.append(&thisObject->m_promiseConstructor);
1180 visitor.append(&thisObject->m_nullGetterFunction);
1181 visitor.append(&thisObject->m_nullSetterFunction);
1183 visitor.append(&thisObject->m_parseIntFunction);
1184 visitor.append(&thisObject->m_evalFunction);
1185 visitor.append(&thisObject->m_callFunction);
1186 visitor.append(&thisObject->m_applyFunction);
1187 visitor.append(&thisObject->m_throwTypeErrorFunction);
1188 thisObject->m_arrayProtoToStringFunction.visit(visitor);
1189 thisObject->m_arrayProtoValuesFunction.visit(visitor);
1190 thisObject->m_initializePromiseFunction.visit(visitor);
1191 thisObject->m_iteratorProtocolFunction.visit(visitor);
1192 visitor.append(&thisObject->m_newPromiseCapabilityFunction);
1193 visitor.append(&thisObject->m_functionProtoHasInstanceSymbolFunction);
1194 thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1195 visitor.append(&thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
1196 visitor.append(&thisObject->m_moduleLoader);
1198 visitor.append(&thisObject->m_objectPrototype);
1199 visitor.append(&thisObject->m_functionPrototype);
1200 visitor.append(&thisObject->m_arrayPrototype);
1201 visitor.append(&thisObject->m_errorPrototype);
1202 visitor.append(&thisObject->m_iteratorPrototype);
1203 visitor.append(&thisObject->m_generatorFunctionPrototype);
1204 visitor.append(&thisObject->m_generatorPrototype);
1205 visitor.append(&thisObject->m_asyncFunctionPrototype);
1206 visitor.append(&thisObject->m_moduleLoaderPrototype);
1208 thisObject->m_debuggerScopeStructure.visit(visitor);
1209 thisObject->m_withScopeStructure.visit(visitor);
1210 visitor.append(&thisObject->m_strictEvalActivationStructure);
1211 visitor.append(&thisObject->m_lexicalEnvironmentStructure);
1212 thisObject->m_moduleEnvironmentStructure.visit(visitor);
1213 visitor.append(&thisObject->m_directArgumentsStructure);
1214 visitor.append(&thisObject->m_scopedArgumentsStructure);
1215 visitor.append(&thisObject->m_clonedArgumentsStructure);
1216 visitor.append(&thisObject->m_objectStructureForObjectConstructor);
1217 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1218 visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
1219 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1220 visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1221 thisObject->m_callbackConstructorStructure.visit(visitor);
1222 thisObject->m_callbackFunctionStructure.visit(visitor);
1223 thisObject->m_callbackObjectStructure.visit(visitor);
1224 visitor.append(&thisObject->m_propertyNameIteratorStructure);
1225 #if JSC_OBJC_API_ENABLED
1226 thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1227 thisObject->m_objcWrapperObjectStructure.visit(visitor);
1229 thisObject->m_nullPrototypeObjectStructure.visit(visitor);
1230 visitor.append(&thisObject->m_errorStructure);
1231 visitor.append(&thisObject->m_calleeStructure);
1232 visitor.append(&thisObject->m_functionStructure);
1233 thisObject->m_customGetterSetterFunctionStructure.visit(visitor);
1234 thisObject->m_boundFunctionStructure.visit(visitor);
1235 visitor.append(&thisObject->m_getterSetterStructure);
1236 thisObject->m_nativeStdFunctionStructure.visit(visitor);
1237 thisObject->m_namedFunctionStructure.visit(visitor);
1238 visitor.append(&thisObject->m_symbolObjectStructure);
1239 visitor.append(&thisObject->m_regExpStructure);
1240 visitor.append(&thisObject->m_generatorFunctionStructure);
1241 visitor.append(&thisObject->m_asyncFunctionStructure);
1242 visitor.append(&thisObject->m_iteratorResultObjectStructure);
1243 visitor.append(&thisObject->m_regExpMatchesArrayStructure);
1244 visitor.append(&thisObject->m_moduleRecordStructure);
1245 visitor.append(&thisObject->m_moduleNamespaceObjectStructure);
1246 visitor.append(&thisObject->m_dollarVMStructure);
1247 visitor.append(&thisObject->m_proxyObjectStructure);
1248 visitor.append(&thisObject->m_callableProxyObjectStructure);
1249 visitor.append(&thisObject->m_proxyRevokeStructure);
1250 visitor.append(&thisObject->m_moduleLoaderStructure);
1252 visitor.append(&thisObject->m_arrayBufferPrototype);
1253 visitor.append(&thisObject->m_arrayBufferStructure);
1254 visitor.append(&thisObject->m_sharedArrayBufferPrototype);
1255 visitor.append(&thisObject->m_sharedArrayBufferStructure);
1257 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1258 visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
1259 visitor.append(&thisObject->m_ ## properName ## Structure); \
1261 FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1263 #if ENABLE(WEBASSEMBLY)
1264 visitor.append(&thisObject->m_webAssemblyStructure);
1265 visitor.append(&thisObject->m_webAssemblyModuleRecordStructure);
1266 visitor.append(&thisObject->m_webAssemblyFunctionStructure);
1267 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(VISIT_SIMPLE_TYPE)
1268 #endif // ENABLE(WEBASSEMBLY)
1270 #undef VISIT_SIMPLE_TYPE
1272 #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1273 thisObject->m_ ## properName ## Structure.visit(visitor);
1275 FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1276 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_LAZY_TYPE)
1278 #undef VISIT_LAZY_TYPE
1280 for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;)
1281 thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1283 visitor.append(&thisObject->m_speciesGetterSetter);
1284 thisObject->m_typedArrayProto.visit(visitor);
1285 thisObject->m_typedArraySuperConstructor.visit(visitor);
1288 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
1290 if (ecmaMode == StrictMode)
1291 return jsUndefined();
1292 return exec->globalThisValue();
1295 ExecState* JSGlobalObject::globalExec()
1297 return CallFrame::create(m_globalCallFrame);
1300 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1302 ScopeOffset startOffset = addVariables(count, jsUndefined());
1304 for (int i = 0; i < count; ++i) {
1305 GlobalPropertyInfo& global = globals[i];
1306 ASSERT(global.attributes & DontDelete);
1308 WatchpointSet* watchpointSet = nullptr;
1309 WriteBarrierBase<Unknown>* variable = nullptr;
1311 ConcurrentJSLocker locker(symbolTable()->m_lock);
1312 ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1313 RELEASE_ASSERT(offset = startOffset + i);
1314 SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1315 newEntry.prepareToWatch();
1316 watchpointSet = newEntry.watchpointSet();
1317 symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1318 variable = &variableAt(offset);
1320 symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1324 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1326 if (Base::getOwnPropertySlot(object, exec, propertyName, slot))
1328 return symbolTableGet(jsCast<JSGlobalObject*>(object), propertyName, slot);
1331 void JSGlobalObject::clearRareData(JSCell* cell)
1333 jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1336 void slowValidateCell(JSGlobalObject* globalObject)
1338 RELEASE_ASSERT(globalObject->isGlobalObject());
1339 ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1342 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1344 #if ENABLE(REMOTE_INSPECTOR)
1345 m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1347 UNUSED_PARAM(enabled);
1351 bool JSGlobalObject::remoteDebuggingEnabled() const
1353 #if ENABLE(REMOTE_INSPECTOR)
1354 return m_inspectorDebuggable->remoteDebuggingAllowed();
1360 #if ENABLE(WEB_REPLAY)
1361 void JSGlobalObject::setInputCursor(PassRefPtr<InputCursor> prpCursor)
1363 m_inputCursor = prpCursor;
1364 ASSERT(m_inputCursor);
1366 InputCursor& cursor = inputCursor();
1367 // Save or set the random seed. This performed here rather than the constructor
1368 // to avoid threading the input cursor through all the abstraction layers.
1369 if (cursor.isCapturing())
1370 cursor.appendInput<SetRandomSeed>(m_weakRandom.seed());
1371 else if (cursor.isReplaying()) {
1372 if (SetRandomSeed* input = cursor.fetchInput<SetRandomSeed>())
1373 m_weakRandom.setSeed(static_cast<unsigned>(input->randomSeed()));
1378 void JSGlobalObject::setName(const String& name)
1382 #if ENABLE(REMOTE_INSPECTOR)
1383 m_inspectorDebuggable->update();
1388 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1390 if (m_intlCollatorAvailableLocales.isEmpty()) {
1391 int32_t count = ucol_countAvailable();
1392 for (int32_t i = 0; i < count; ++i) {
1393 String locale(ucol_getAvailable(i));
1394 convertICULocaleToBCP47LanguageTag(locale);
1395 m_intlCollatorAvailableLocales.add(locale);
1398 return m_intlCollatorAvailableLocales;
1401 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1403 if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1404 int32_t count = udat_countAvailable();
1405 for (int32_t i = 0; i < count; ++i) {
1406 String locale(udat_getAvailable(i));
1407 convertICULocaleToBCP47LanguageTag(locale);
1408 m_intlDateTimeFormatAvailableLocales.add(locale);
1411 return m_intlDateTimeFormatAvailableLocales;
1414 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1416 if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1417 int32_t count = unum_countAvailable();
1418 for (int32_t i = 0; i < count; ++i) {
1419 String locale(unum_getAvailable(i));
1420 convertICULocaleToBCP47LanguageTag(locale);
1421 m_intlNumberFormatAvailableLocales.add(locale);
1424 return m_intlNumberFormatAvailableLocales;
1426 #endif // ENABLE(INTL)
1428 void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
1430 if (globalObjectMethodTable()->queueTaskToEventLoop) {
1431 globalObjectMethodTable()->queueTaskToEventLoop(this, WTFMove(task));
1435 vm().queueMicrotask(this, WTFMove(task));
1438 bool JSGlobalObject::hasDebugger() const
1443 bool JSGlobalObject::hasInteractiveDebugger() const
1445 return m_debugger && m_debugger->isInteractivelyDebugging();