2 * Copyright (C) 2007-2017 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 "JSFunction.h"
84 #include "JSGeneratorFunction.h"
85 #include "JSGenericTypedArrayViewConstructorInlines.h"
86 #include "JSGenericTypedArrayViewInlines.h"
87 #include "JSGenericTypedArrayViewPrototypeInlines.h"
88 #include "JSGlobalObjectFunctions.h"
89 #include "JSInternalPromise.h"
90 #include "JSInternalPromiseConstructor.h"
91 #include "JSInternalPromisePrototype.h"
93 #include "JSLexicalEnvironment.h"
96 #include "JSMapIterator.h"
97 #include "JSModuleEnvironment.h"
98 #include "JSModuleLoader.h"
99 #include "JSModuleNamespaceObject.h"
100 #include "JSModuleRecord.h"
101 #include "JSNativeStdFunction.h"
102 #include "JSONObject.h"
103 #include "JSPromise.h"
104 #include "JSPromiseConstructor.h"
105 #include "JSPromisePrototype.h"
106 #include "JSPropertyNameIterator.h"
108 #include "JSSetIterator.h"
109 #include "JSStringIterator.h"
110 #include "JSTemplateRegistryKey.h"
111 #include "JSTypedArrayConstructors.h"
112 #include "JSTypedArrayPrototypes.h"
113 #include "JSTypedArrayViewConstructor.h"
114 #include "JSTypedArrayViewPrototype.h"
115 #include "JSTypedArrays.h"
116 #include "JSWeakMap.h"
117 #include "JSWeakSet.h"
118 #include "JSWebAssembly.h"
119 #include "JSWithScope.h"
120 #include "LazyClassStructureInlines.h"
121 #include "LazyPropertyInlines.h"
123 #include "MapConstructor.h"
124 #include "MapIteratorPrototype.h"
125 #include "MapPrototype.h"
126 #include "MarkedSpaceInlines.h"
127 #include "MathObject.h"
128 #include "Microtask.h"
129 #include "ModuleLoaderPrototype.h"
130 #include "NativeErrorConstructor.h"
131 #include "NativeErrorPrototype.h"
132 #include "NullGetterFunction.h"
133 #include "NullSetterFunction.h"
134 #include "NumberConstructor.h"
135 #include "NumberPrototype.h"
136 #include "ObjCCallbackFunction.h"
137 #include "ObjectConstructor.h"
138 #include "ObjectPropertyConditionSet.h"
139 #include "ObjectPrototype.h"
140 #include "ParserError.h"
141 #include "ProxyConstructor.h"
142 #include "ProxyObject.h"
143 #include "ProxyRevoke.h"
144 #include "ReflectObject.h"
145 #include "RegExpConstructor.h"
146 #include "RegExpMatchesArray.h"
147 #include "RegExpObject.h"
148 #include "RegExpPrototype.h"
149 #include "ScopedArguments.h"
150 #include "SetConstructor.h"
151 #include "SetIteratorPrototype.h"
152 #include "SetPrototype.h"
153 #include "StrictEvalActivation.h"
154 #include "StringConstructor.h"
155 #include "StringIteratorPrototype.h"
156 #include "StringPrototype.h"
158 #include "SymbolConstructor.h"
159 #include "SymbolPrototype.h"
160 #include "VariableWriteFireDetail.h"
161 #include "WeakGCMapInlines.h"
162 #include "WeakMapConstructor.h"
163 #include "WeakMapPrototype.h"
164 #include "WeakSetConstructor.h"
165 #include "WeakSetPrototype.h"
166 #include <wtf/RandomNumber.h>
169 #include "IntlObject.h"
170 #include <unicode/ucol.h>
171 #include <unicode/udat.h>
172 #include <unicode/unum.h>
173 #endif // ENABLE(INTL)
175 #if ENABLE(REMOTE_INSPECTOR)
176 #include "JSGlobalObjectDebuggable.h"
177 #include "JSGlobalObjectInspectorController.h"
180 #if ENABLE(WEB_REPLAY)
181 #include "EmptyInputCursor.h"
182 #include "JSReplayInputs.h"
187 static JSValue createProxyProperty(VM& vm, JSObject* object)
189 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
190 return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
193 static JSValue createJSONProperty(VM& vm, JSObject* object)
195 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
196 return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
199 static JSValue createMathProperty(VM& vm, JSObject* object)
201 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
202 return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
205 static JSValue createConsoleProperty(VM& vm, JSObject* object)
207 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
208 return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global->globalExec())));
211 static JSValue createAtomicsProperty(VM& vm, JSObject* object)
213 JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
214 return AtomicsObject::create(vm, global, AtomicsObject::createStructure(vm, global, global->objectPrototype()));
217 static EncodedJSValue JSC_HOST_CALL makeBoundFunction(ExecState* exec)
220 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
222 JSObject* target = asObject(exec->uncheckedArgument(0));
223 JSValue boundThis = exec->uncheckedArgument(1);
224 JSValue boundArgs = exec->uncheckedArgument(2);
225 JSValue length = exec->uncheckedArgument(3);
226 JSString* name = asString(exec->uncheckedArgument(4));
228 return JSValue::encode(JSBoundFunction::create(
229 vm, exec, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSArray*>(boundArgs) : nullptr, length.asInt32(), name->value(exec)));
232 static EncodedJSValue JSC_HOST_CALL hasOwnLengthProperty(ExecState* exec)
235 JSObject* target = asObject(exec->uncheckedArgument(0));
236 return JSValue::encode(jsBoolean(target->hasOwnProperty(exec, vm.propertyNames->length)));
241 #include "JSGlobalObject.lut.h"
245 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
247 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
248 &supportsRichSourceInfo,
249 &shouldInterruptScript,
250 &javaScriptRuntimeFlags,
252 &shouldInterruptScriptBeforeTimeout,
261 /* Source for JSGlobalObject.lut.h
262 @begin globalObjectTable
263 parseFloat globalFuncParseFloat DontEnum|Function 1
264 isNaN JSBuiltin DontEnum|Function 1
265 isFinite JSBuiltin DontEnum|Function 1
266 escape globalFuncEscape DontEnum|Function 1
267 unescape globalFuncUnescape DontEnum|Function 1
268 decodeURI globalFuncDecodeURI DontEnum|Function 1
269 decodeURIComponent globalFuncDecodeURIComponent DontEnum|Function 1
270 encodeURI globalFuncEncodeURI DontEnum|Function 1
271 encodeURIComponent globalFuncEncodeURIComponent DontEnum|Function 1
272 EvalError JSGlobalObject::m_evalErrorConstructor DontEnum|CellProperty
273 ReferenceError JSGlobalObject::m_referenceErrorConstructor DontEnum|CellProperty
274 SyntaxError JSGlobalObject::m_syntaxErrorConstructor DontEnum|CellProperty
275 URIError JSGlobalObject::m_URIErrorConstructor DontEnum|CellProperty
276 Proxy createProxyProperty DontEnum|PropertyCallback
277 JSON createJSONProperty DontEnum|PropertyCallback
278 Math createMathProperty DontEnum|PropertyCallback
279 Atomics createAtomicsProperty DontEnum|PropertyCallback
280 console createConsoleProperty DontEnum|PropertyCallback
281 Int8Array JSGlobalObject::m_typedArrayInt8 DontEnum|ClassStructure
282 Int16Array JSGlobalObject::m_typedArrayInt16 DontEnum|ClassStructure
283 Int32Array JSGlobalObject::m_typedArrayInt32 DontEnum|ClassStructure
284 Uint8Array JSGlobalObject::m_typedArrayUint8 DontEnum|ClassStructure
285 Uint8ClampedArray JSGlobalObject::m_typedArrayUint8Clamped DontEnum|ClassStructure
286 Uint16Array JSGlobalObject::m_typedArrayUint16 DontEnum|ClassStructure
287 Uint32Array JSGlobalObject::m_typedArrayUint32 DontEnum|ClassStructure
288 Float32Array JSGlobalObject::m_typedArrayFloat32 DontEnum|ClassStructure
289 Float64Array JSGlobalObject::m_typedArrayFloat64 DontEnum|ClassStructure
290 DataView JSGlobalObject::m_typedArrayDataView DontEnum|ClassStructure
291 Set JSGlobalObject::m_setStructure DontEnum|ClassStructure
292 Date JSGlobalObject::m_dateStructure DontEnum|ClassStructure
293 Boolean JSGlobalObject::m_booleanObjectStructure DontEnum|ClassStructure
294 Number JSGlobalObject::m_numberObjectStructure DontEnum|ClassStructure
295 WeakMap JSGlobalObject::m_weakMapStructure DontEnum|ClassStructure
296 WeakSet JSGlobalObject::m_weakSetStructure DontEnum|ClassStructure
300 static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
303 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
305 JSValue job = exec->argument(0);
306 JSValue arguments = exec->argument(1);
307 ASSERT(arguments.inherits(vm, JSArray::info()));
309 globalObject->queueMicrotask(createJSJob(vm, job, jsCast<JSArray*>(arguments)));
311 return JSValue::encode(jsUndefined());
314 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
315 : Base(vm, structure, 0)
317 #if ENABLE(WEB_REPLAY)
318 , m_inputCursor(EmptyInputCursor::create())
320 , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
321 , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
322 , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
323 , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
324 , m_arrayIteratorProtocolWatchpoint(IsWatched)
325 , m_arraySpeciesWatchpoint(ClearWatchpoint)
326 , m_templateRegistry(vm)
327 , m_evalEnabled(true)
329 , m_consoleClient(nullptr)
330 , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
334 JSGlobalObject::~JSGlobalObject()
336 #if ENABLE(REMOTE_INSPECTOR)
337 m_inspectorController->globalObjectDestroyed();
341 m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
344 void JSGlobalObject::destroy(JSCell* cell)
346 static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
349 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
351 m_globalThis.set(vm, this, globalThis);
354 static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier& ident)
356 JSValue baseValue = JSValue(base);
357 PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry);
358 baseValue.getPropertySlot(exec, ident, slot);
359 return slot.getPureResult().toObject(exec);
362 void JSGlobalObject::init(VM& vm)
364 ASSERT(vm.currentThreadIsHoldingAPILock());
365 auto catchScope = DECLARE_CATCH_SCOPE(vm);
367 Base::setStructure(vm, Structure::toCacheableDictionaryTransition(vm, structure()));
371 #if ENABLE(REMOTE_INSPECTOR)
372 m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
373 m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
374 m_inspectorDebuggable->init();
375 m_consoleClient = m_inspectorController->consoleClient();
378 m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
379 m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
381 m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
382 // Need to create the callee structure (above) before creating the callee.
383 JSCallee* globalCallee = JSCallee::create(vm, this, globalScope());
384 m_globalCallee.set(vm, this, globalCallee);
386 ExecState::initGlobalExec(JSGlobalObject::globalExec(), globalCallee);
387 ExecState* exec = JSGlobalObject::globalExec();
389 m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
390 m_customGetterSetterFunctionStructure.initLater(
391 [] (const Initializer<Structure>& init) {
392 init.set(JSCustomGetterSetterFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
394 m_boundFunctionStructure.initLater(
395 [] (const Initializer<Structure>& init) {
396 init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
398 m_getterSetterStructure.set(vm, this, GetterSetter::createStructure(vm, this, jsNull()));
399 m_nativeStdFunctionStructure.initLater(
400 [] (const Initializer<Structure>& init) {
401 init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
403 m_namedFunctionStructure.initLater(
404 [] (const Initializer<Structure>& init) {
405 init.set(Structure::addPropertyTransition(init.vm, init.owner->m_functionStructure.get(), init.vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, init.owner->m_functionNameOffset));
407 JSFunction* callFunction = 0;
408 JSFunction* applyFunction = 0;
409 JSFunction* hasInstanceSymbolFunction = 0;
410 m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
411 m_callFunction.set(vm, this, callFunction);
412 m_applyFunction.set(vm, this, applyFunction);
413 m_arrayProtoToStringFunction.initLater(
414 [] (const Initializer<JSFunction>& init) {
415 init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
417 m_arrayProtoValuesFunction.initLater(
418 [] (const Initializer<JSFunction>& init) {
419 init.set(JSFunction::createBuiltinFunction(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
421 m_initializePromiseFunction.initLater(
422 [] (const Initializer<JSFunction>& init) {
423 init.set(JSFunction::createBuiltinFunction(init.vm, promiseOperationsInitializePromiseCodeGenerator(init.vm), init.owner));
426 m_iteratorProtocolFunction.initLater(
427 [] (const Initializer<JSFunction>& init) {
428 init.set(JSFunction::createBuiltinFunction(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
431 m_newPromiseCapabilityFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
432 m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
433 m_throwTypeErrorGetterSetter.initLater(
434 [] (const Initializer<GetterSetter>& init) {
435 JSFunction* thrower = init.owner->throwTypeErrorFunction();
436 GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner);
437 getterSetter->setGetter(init.vm, init.owner, thrower);
438 getterSetter->setSetter(init.vm, init.owner, thrower);
439 init.set(getterSetter);
442 m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
443 m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
444 m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
445 GetterSetter* protoAccessor = GetterSetter::create(vm, this);
446 protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter));
447 protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
448 m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
449 m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
450 m_objectStructureForObjectConstructor.set(vm, this, vm.prototypeMap.emptyObjectStructureForPrototype(this, m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
451 m_objectProtoValueOfFunction.set(vm, this, jsCast<JSFunction*>(objectPrototype()->getDirect(vm, vm.propertyNames->valueOf)));
453 JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeErrorArgumentsCalleeAndCaller);
454 GetterSetter* getterSetter = GetterSetter::create(vm, this);
455 getterSetter->setGetter(vm, this, thrower);
456 getterSetter->setSetter(vm, this, thrower);
457 m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.set(vm, this, getterSetter);
459 m_functionPrototype->initRestrictedProperties(exec, this);
461 m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this));
462 m_speciesGetterSetter->setGetter(vm, this, JSFunction::createBuiltinFunction(vm, globalOperationsSpeciesGetterCodeGenerator(vm), this, "get [Symbol.species]"));
464 m_typedArrayProto.initLater(
465 [] (const Initializer<JSTypedArrayViewPrototype>& init) {
466 init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
468 // Make sure that the constructor gets initialized, too.
469 init.owner->m_typedArraySuperConstructor.get(init.owner);
471 m_typedArraySuperConstructor.initLater(
472 [] (const Initializer<JSTypedArrayViewConstructor>& init) {
473 JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
474 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());
475 prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, DontEnum);
476 init.set(constructor);
479 #define INIT_TYPED_ARRAY_LATER(type) \
480 m_typedArray ## type.initLater( \
481 [] (LazyClassStructure::Initializer& init) { \
482 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)))); \
483 init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
484 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))); \
485 init.global->putDirectWithoutTransition(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, DontEnum); \
487 FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
488 #undef INIT_TYPED_ARRAY_LATER
490 m_typedArrayDataView.initLater(
491 [] (LazyClassStructure::Initializer& init) {
492 init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
493 init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
494 init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, ASCIILiteral("DataView"), nullptr));
497 m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
498 m_moduleEnvironmentStructure.initLater(
499 [] (const Initializer<Structure>& init) {
500 init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
502 m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
503 m_debuggerScopeStructure.initLater(
504 [] (const Initializer<Structure>& init) {
505 init.set(DebuggerScope::createStructure(init.vm, init.owner));
507 m_withScopeStructure.initLater(
508 [] (const Initializer<Structure>& init) {
509 init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
512 m_nullPrototypeObjectStructure.initLater(
513 [] (const Initializer<Structure>& init) {
514 init.set(JSFinalObject::createStructure(init.vm, init.owner, jsNull(), JSFinalObject::defaultInlineCapacity()));
517 m_callbackFunctionStructure.initLater(
518 [] (const Initializer<Structure>& init) {
519 init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
521 m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
522 m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
523 m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
524 m_callbackConstructorStructure.initLater(
525 [] (const Initializer<Structure>& init) {
526 init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
528 m_callbackObjectStructure.initLater(
529 [] (const Initializer<Structure>& init) {
530 init.set(JSCallbackObject<JSDestructibleObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
533 #if JSC_OBJC_API_ENABLED
534 m_objcCallbackFunctionStructure.initLater(
535 [] (const Initializer<Structure>& init) {
536 init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
538 m_objcWrapperObjectStructure.initLater(
539 [] (const Initializer<Structure>& init) {
540 init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
544 m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
546 m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
547 m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
548 m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
549 m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
550 m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
551 m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
552 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
553 m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
555 m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
556 m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
557 m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
559 m_moduleRecordStructure.set(vm, this, JSModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
560 m_moduleNamespaceObjectStructure.set(vm, this, JSModuleNamespaceObject::createStructure(vm, this, jsNull()));
562 bool isCallable = false;
563 m_proxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
565 m_callableProxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
567 m_proxyRevokeStructure.set(vm, this, ProxyRevoke::createStructure(vm, this, m_functionPrototype.get()));
569 m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, ParseIntIntrinsic));
570 putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), DontEnum);
572 m_arrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Default));
573 m_arrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_arrayBufferPrototype.get()));
574 m_sharedArrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Shared));
575 m_sharedArrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_sharedArrayBufferPrototype.get()));
577 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
578 m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_ ## prototypeBase ## Prototype.get()))); \
579 m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
581 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
583 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
585 #define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
586 m_ ## properName ## Structure.initLater(\
587 [] (LazyClassStructure::Initializer& init) { \
588 init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_ ## prototypeBase ## Prototype.get()))); \
589 init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
590 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())); \
593 FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
595 #undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
597 m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
599 #define CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
600 m_ ## lowerName ## Structure.initLater( \
601 [] (const Initializer<Structure>& init) { \
602 JSObject* prototype = capitalName ## Prototype::create(init.vm, init.owner, capitalName ## Prototype::createStructure(init.vm, init.owner, init.owner->m_iteratorPrototype.get())); \
603 init.set(instanceType::createStructure(init.vm, init.owner, prototype)); \
605 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE)
606 #undef CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE
608 m_propertyNameIteratorStructure.set(vm, this, JSPropertyNameIterator::createStructure(vm, this, m_iteratorPrototype.get()));
609 m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
610 m_moduleLoaderPrototype.set(vm, this, ModuleLoaderPrototype::create(vm, this, ModuleLoaderPrototype::createStructure(vm, this, m_objectPrototype.get())));
614 ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
615 m_objectConstructor.set(vm, this, objectConstructor);
617 JSFunction* throwTypeErrorFunction = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
618 m_throwTypeErrorFunction.set(vm, this, throwTypeErrorFunction);
620 JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
622 ArrayConstructor* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
623 m_arrayConstructor.set(vm, this, arrayConstructor);
625 m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get()));
627 JSArrayBufferConstructor* arrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayBufferPrototype.get(), m_speciesGetterSetter.get(), ArrayBufferSharingMode::Default);
628 m_arrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayBufferConstructor, DontEnum);
629 JSArrayBufferConstructor* sharedArrayBufferConstructor = nullptr;
630 sharedArrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_sharedArrayBufferPrototype.get(), m_speciesGetterSetter.get(), ArrayBufferSharingMode::Shared);
631 m_sharedArrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, sharedArrayBufferConstructor, DontEnum);
633 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
634 capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()); \
635 m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \
637 FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
639 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
641 m_errorConstructor.set(vm, this, errorConstructor);
642 m_promiseConstructor.set(vm, this, promiseConstructor);
643 m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
645 m_nativeErrorPrototypeStructure.set(vm, this, NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get()));
646 m_nativeErrorStructure.set(vm, this, NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get()));
647 m_evalErrorConstructor.initLater(
648 [] (const Initializer<NativeErrorConstructor>& init) {
649 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("EvalError")));
651 m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("RangeError")));
652 m_referenceErrorConstructor.initLater(
653 [] (const Initializer<NativeErrorConstructor>& init) {
654 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("ReferenceError")));
656 m_syntaxErrorConstructor.initLater(
657 [] (const Initializer<NativeErrorConstructor>& init) {
658 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("SyntaxError")));
660 m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("TypeError")));
661 m_URIErrorConstructor.initLater(
662 [] (const Initializer<NativeErrorConstructor>& init) {
663 init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("URIError")));
666 m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
667 GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
668 m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, DontEnum | ReadOnly);
669 m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
671 m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), DontEnum | ReadOnly);
672 m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), DontEnum | ReadOnly);
674 m_asyncFunctionPrototype.set(vm, this, AsyncFunctionPrototype::create(vm, AsyncFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
675 AsyncFunctionConstructor* asyncFunctionConstructor = AsyncFunctionConstructor::create(vm, AsyncFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncFunctionPrototype.get());
676 m_asyncFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncFunctionConstructor, DontEnum | ReadOnly);
677 m_asyncFunctionStructure.set(vm, this, JSAsyncFunction::createStructure(vm, this, m_asyncFunctionPrototype.get()));
679 m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum);
680 m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum);
681 m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, DontEnum);
682 m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum);
684 putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum);
685 putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum);
686 putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum);
687 putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum);
688 putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum);
689 putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum);
691 putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ObjectPrivateName(), objectConstructor, DontEnum | DontDelete | ReadOnly);
692 putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ArrayPrivateName(), arrayConstructor, DontEnum | DontDelete | ReadOnly);
694 putDirectWithoutTransition(vm, vm.propertyNames->ArrayBuffer, arrayBufferConstructor, DontEnum);
695 putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, sharedArrayBufferConstructor, DontEnum);
697 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
698 putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \
700 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
702 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
703 m_iteratorResultObjectStructure.set(vm, this, createIteratorResultObjectStructure(vm, *this));
705 m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
706 putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
709 IntlObject* intl = IntlObject::create(vm, this, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
710 putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, DontEnum);
711 #endif // ENABLE(INTL)
712 ReflectObject* reflectObject = ReflectObject::create(vm, this, ReflectObject::createStructure(vm, this, m_objectPrototype.get()));
713 putDirectWithoutTransition(vm, vm.propertyNames->Reflect, reflectObject, DontEnum);
715 m_moduleLoaderStructure.set(vm, this, JSModuleLoader::createStructure(vm, this, m_moduleLoaderPrototype.get()));
716 m_moduleLoader.set(vm, this, JSModuleLoader::create(globalExec(), vm, this, m_moduleLoaderStructure.get()));
717 if (Options::exposeInternalModuleLoader())
718 putDirectWithoutTransition(vm, vm.propertyNames->Loader, m_moduleLoader.get(), DontEnum);
720 JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
722 JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic);
723 JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
724 JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
726 JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule);
727 JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
728 JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
729 JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
730 JSFunction* privateFuncIsTypedArrayView = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncIsTypedArrayView, IsTypedArrayViewIntrinsic);
731 JSFunction* privateFuncTypedArraySubarrayCreate = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSubarrayCreate);
732 JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
733 JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
734 JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
735 JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
736 JSFunction* privateFuncThisNumberValue = JSFunction::create(vm, this, 0, String(), numberProtoFuncValueOf);
737 JSFunction* privateFuncIsArrayConstructor = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArrayConstructor);
738 JSFunction* privateFuncIsArraySlow = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArraySlow);
739 JSFunction* privateFuncConcatMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncConcatMemcpy);
740 JSFunction* privateFuncAppendMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncAppendMemcpy);
741 JSFunction* privateFuncConcatSlowPath = JSFunction::createBuiltinFunction(vm, arrayPrototypeConcatSlowPathCodeGenerator(vm), this);
743 JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
744 ASSERT_UNUSED(catchScope, !catchScope.exception());
745 JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
746 ASSERT(!catchScope.exception());
747 m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
748 JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
749 ASSERT(!catchScope.exception());
750 JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
751 ASSERT(!catchScope.exception());
752 JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
753 ASSERT(!catchScope.exception());
754 JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
755 ASSERT(!catchScope.exception());
756 JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
757 ASSERT(!catchScope.exception());
758 m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
759 JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
760 m_regExpProtoExec.set(vm, this, builtinRegExpExec);
761 JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
762 m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
764 #define CREATE_PRIVATE_GLOBAL_FUNCTION(name, code) JSFunction* name ## PrivateFunction = JSFunction::createBuiltinFunction(vm, code ## CodeGenerator(vm), this);
765 JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(CREATE_PRIVATE_GLOBAL_FUNCTION)
766 #undef CREATE_PRIVATE_GLOBAL_FUNCTION
768 JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
769 createArrayIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
771 GlobalPropertyInfo staticGlobals[] = {
772 #define INIT_PRIVATE_GLOBAL(name, code) GlobalPropertyInfo(vm.propertyNames->builtinNames().name ## PrivateName(), name ## PrivateFunction, DontEnum | DontDelete | ReadOnly),
773 JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
774 #undef INIT_PRIVATE_GLOBAL
775 GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
776 GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
777 GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
778 GlobalPropertyInfo(vm.propertyNames->builtinNames().ownEnumerablePropertyKeysPrivateName(), JSFunction::create(vm, this, 0, String(), ownEnumerablePropertyKeys), DontEnum | DontDelete | ReadOnly),
779 GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, DontEnum | DontDelete | ReadOnly),
780 GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),
781 GlobalPropertyInfo(vm.propertyNames->builtinNames().ErrorPrivateName(), m_errorConstructor.get(), DontEnum | DontDelete | ReadOnly),
782 GlobalPropertyInfo(vm.propertyNames->builtinNames().RangeErrorPrivateName(), m_rangeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
783 GlobalPropertyInfo(vm.propertyNames->builtinNames().TypeErrorPrivateName(), m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
784 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayLengthPrivateName(), privateFuncTypedArrayLength, DontEnum | DontDelete | ReadOnly),
785 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayGetOriginalConstructorPrivateName(), privateFuncTypedArrayGetOriginalConstructor, DontEnum | DontDelete | ReadOnly),
786 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySortPrivateName(), privateFuncTypedArraySort, DontEnum | DontDelete | ReadOnly),
787 GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, DontEnum | DontDelete | ReadOnly),
788 GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySubarrayCreatePrivateName(), privateFuncTypedArraySubarrayCreate, DontEnum | DontDelete | ReadOnly),
789 GlobalPropertyInfo(vm.propertyNames->builtinNames().isBoundFunctionPrivateName(), privateFuncIsBoundFunction, DontEnum | DontDelete | ReadOnly),
790 GlobalPropertyInfo(vm.propertyNames->builtinNames().hasInstanceBoundFunctionPrivateName(), privateFuncHasInstanceBoundFunction, DontEnum | DontDelete | ReadOnly),
791 GlobalPropertyInfo(vm.propertyNames->builtinNames().instanceOfPrivateName(), privateFuncInstanceOf, DontEnum | DontDelete | ReadOnly),
792 GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinLogPrivateName(), builtinLog, DontEnum | DontDelete | ReadOnly),
793 GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberPrivateName(), numberConstructor, DontEnum | DontDelete | ReadOnly),
794 GlobalPropertyInfo(vm.propertyNames->builtinNames().RegExpPrivateName(), m_regExpConstructor.get(), DontEnum | DontDelete | ReadOnly),
795 GlobalPropertyInfo(vm.propertyNames->builtinNames().StringPrivateName(), stringConstructor, DontEnum | DontDelete | ReadOnly),
796 GlobalPropertyInfo(vm.propertyNames->builtinNames().absPrivateName(), privateFuncAbs, DontEnum | DontDelete | ReadOnly),
797 GlobalPropertyInfo(vm.propertyNames->builtinNames().floorPrivateName(), privateFuncFloor, DontEnum | DontDelete | ReadOnly),
798 GlobalPropertyInfo(vm.propertyNames->builtinNames().truncPrivateName(), privateFuncTrunc, DontEnum | DontDelete | ReadOnly),
799 GlobalPropertyInfo(vm.propertyNames->builtinNames().PromisePrivateName(), promiseConstructor, DontEnum | DontDelete | ReadOnly),
800 GlobalPropertyInfo(vm.propertyNames->builtinNames().ReflectPrivateName(), reflectObject, DontEnum | DontDelete | ReadOnly),
801 GlobalPropertyInfo(vm.propertyNames->builtinNames().InternalPromisePrivateName(), internalPromiseConstructor, DontEnum | DontDelete | ReadOnly),
803 GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharacterPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), DontEnum | DontDelete | ReadOnly),
804 GlobalPropertyInfo(vm.propertyNames->builtinNames().SetIteratorPrivateName(), JSFunction::create(vm, this, 1, String(), privateFuncSetIterator), DontEnum | DontDelete | ReadOnly),
805 GlobalPropertyInfo(vm.propertyNames->builtinNames().setIteratorNextPrivateName(), JSFunction::create(vm, this, 0, String(), privateFuncSetIteratorNext), DontEnum | DontDelete | ReadOnly),
806 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayPrivateName(), arrayConstructor->getDirect(vm, vm.propertyNames->isArray), DontEnum | DontDelete | ReadOnly),
807 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArraySlowPrivateName(), privateFuncIsArraySlow, DontEnum | DontDelete | ReadOnly),
808 GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayConstructorPrivateName(), privateFuncIsArrayConstructor, DontEnum | DontDelete | ReadOnly),
809 GlobalPropertyInfo(vm.propertyNames->builtinNames().concatMemcpyPrivateName(), privateFuncConcatMemcpy, DontEnum | DontDelete | ReadOnly),
810 GlobalPropertyInfo(vm.propertyNames->builtinNames().appendMemcpyPrivateName(), privateFuncAppendMemcpy, DontEnum | DontDelete | ReadOnly),
811 GlobalPropertyInfo(vm.propertyNames->builtinNames().concatSlowPathPrivateName(), privateFuncConcatSlowPath, DontEnum | DontDelete | ReadOnly),
812 GlobalPropertyInfo(vm.propertyNames->builtinNames().MapIteratorPrivateName(), JSFunction::create(vm, this, 1, String(), privateFuncMapIterator), DontEnum | DontDelete | ReadOnly),
813 GlobalPropertyInfo(vm.propertyNames->builtinNames().mapIteratorNextPrivateName(), JSFunction::create(vm, this, 0, String(), privateFuncMapIteratorNext), DontEnum | DontDelete | ReadOnly),
815 GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum | DontDelete | ReadOnly),
816 GlobalPropertyInfo(vm.propertyNames->builtinNames().MapPrivateName(), mapConstructor, DontEnum | DontDelete | ReadOnly),
817 GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, DontEnum | DontDelete | ReadOnly),
818 GlobalPropertyInfo(vm.propertyNames->builtinNames().thisNumberValuePrivateName(), privateFuncThisNumberValue, DontEnum | DontDelete | ReadOnly),
820 GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), DontEnum | DontDelete | ReadOnly),
821 GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), DontEnum | DontDelete | ReadOnly),
822 GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), DontEnum | DontDelete | ReadOnly),
823 #endif // ENABLE(INTL)
825 GlobalPropertyInfo(vm.propertyNames->builtinNames().isConstructorPrivateName(), JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
827 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoFlagsGetterPrivateName(), regExpProtoFlagsGetterObject, DontEnum | DontDelete | ReadOnly),
828 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoGlobalGetterPrivateName(), regExpProtoGlobalGetterObject, DontEnum | DontDelete | ReadOnly),
829 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoIgnoreCaseGetterPrivateName(), regExpProtoIgnoreCaseGetterObject, DontEnum | DontDelete | ReadOnly),
830 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoMultilineGetterPrivateName(), regExpProtoMultilineGetterObject, DontEnum | DontDelete | ReadOnly),
831 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoSourceGetterPrivateName(), regExpProtoSourceGetterObject, DontEnum | DontDelete | ReadOnly),
832 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoStickyGetterPrivateName(), regExpProtoStickyGetterObject, DontEnum | DontDelete | ReadOnly),
833 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoUnicodeGetterPrivateName(), regExpProtoUnicodeGetterObject, DontEnum | DontDelete | ReadOnly),
835 // RegExp.prototype helpers.
836 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpBuiltinExecPrivateName(), builtinRegExpExec, DontEnum | DontDelete | ReadOnly),
837 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpCreatePrivateName(), JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
838 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpMatchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast), DontEnum | DontDelete | ReadOnly),
839 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSearchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), DontEnum | DontDelete | ReadOnly),
840 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
841 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpPrototypeSymbolReplacePrivateName(), m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol), DontEnum | DontDelete | ReadOnly),
842 GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpTestFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic), DontEnum | DontDelete | ReadOnly),
844 // String.prototype helpers.
845 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringIncludesInternalPrivateName(), JSFunction::create(vm, this, 1, String(), builtinStringIncludesInternal), DontEnum | DontDelete | ReadOnly),
846 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
847 GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSubstrInternalPrivateName(), JSFunction::create(vm, this, 2, String(), builtinStringSubstrInternal), DontEnum | DontDelete | ReadOnly),
849 // Function prototype helpers.
850 GlobalPropertyInfo(vm.propertyNames->builtinNames().makeBoundFunctionPrivateName(), JSFunction::create(vm, this, 5, String(), makeBoundFunction), DontEnum | DontDelete | ReadOnly),
851 GlobalPropertyInfo(vm.propertyNames->builtinNames().hasOwnLengthPropertyPrivateName(), JSFunction::create(vm, this, 1, String(), hasOwnLengthProperty), DontEnum | DontDelete | ReadOnly),
853 addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
855 m_specialPointers[Special::CallFunction] = m_callFunction.get();
856 m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
857 m_specialPointers[Special::ObjectConstructor] = objectConstructor;
858 m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
860 m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::ThrowTypeErrorFunction)] = m_throwTypeErrorFunction.get();
862 if (UNLIKELY(Options::useDollarVM())) {
863 JSDollarVMPrototype* dollarVMPrototype = JSDollarVMPrototype::create(vm, this, JSDollarVMPrototype::createStructure(vm, this, m_objectPrototype.get()));
864 m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, dollarVMPrototype));
865 JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
867 GlobalPropertyInfo extraStaticGlobals[] = {
868 GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, DontEnum | DontDelete | ReadOnly),
870 addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
872 putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, DontEnum);
875 #if ENABLE(WEBASSEMBLY)
876 if (Options::useWebAssembly()) {
877 auto* webAssemblyPrototype = WebAssemblyPrototype::create(vm, this, WebAssemblyPrototype::createStructure(vm, this, m_objectPrototype.get()));
878 m_webAssemblyStructure.set(vm, this, JSWebAssembly::createStructure(vm, this, webAssemblyPrototype));
879 m_webAssemblyModuleRecordStructure.set(vm, this, WebAssemblyModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
880 m_webAssemblyFunctionStructure.set(vm, this, WebAssemblyFunction::createStructure(vm, this, m_functionPrototype.get()));
881 m_webAssemblyWrapperFunctionStructure.set(vm, this, WebAssemblyWrapperFunction::createStructure(vm, this, m_functionPrototype.get()));
882 auto* webAssembly = JSWebAssembly::create(vm, this, m_webAssemblyStructure.get());
883 putDirectWithoutTransition(vm, Identifier::fromString(exec, "WebAssembly"), webAssembly, DontEnum);
885 #define CREATE_WEBASSEMBLY_CONSTRUCTOR(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
886 typedef capitalName ## Prototype Prototype; \
887 typedef capitalName ## Constructor Constructor; \
888 typedef JS ## capitalName JSObj; \
889 auto* base = m_ ## prototypeBase ## Prototype.get(); \
890 auto* prototype = Prototype::create(vm, this, Prototype::createStructure(vm, this, base)); \
891 auto* structure = JSObj::createStructure(vm, this, prototype); \
892 auto* constructor = Constructor::create(vm, Constructor::createStructure(vm, this, this->functionPrototype()), prototype); \
893 prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, constructor, DontEnum); \
894 m_ ## lowerName ## Prototype.set(vm, this, prototype); \
895 m_ ## properName ## Structure.set(vm, this, structure); \
896 webAssembly->putDirectWithoutTransition(vm, Identifier::fromString(this->globalExec(), #jsName), constructor, DontEnum); \
899 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(CREATE_WEBASSEMBLY_CONSTRUCTOR)
901 #undef CREATE_WEBASSEMBLY_CONSTRUCTOR
903 #endif // ENABLE(WEBASSEMBLY)
906 ExecState* exec = globalExec();
908 auto setupAdaptiveWatchpoint = [&] (JSObject* base, const Identifier& ident) -> ObjectPropertyCondition {
909 // Performing these gets should not throw.
910 PropertySlot slot(base, PropertySlot::InternalMethodType::Get);
911 bool result = base->getOwnPropertySlot(base, exec, ident, slot);
912 ASSERT_UNUSED(result, result);
913 ASSERT(!catchScope.exception());
914 RELEASE_ASSERT(slot.isCacheableValue());
915 JSValue functionValue = slot.getValue(exec, ident);
916 ASSERT(!catchScope.exception());
917 ASSERT(jsDynamicCast<JSFunction*>(vm, functionValue));
919 ObjectPropertyCondition condition = generateConditionForSelfEquivalence(m_vm, nullptr, base, ident.impl());
920 RELEASE_ASSERT(condition.requiredValue() == functionValue);
922 bool isWatchable = condition.isWatchable(PropertyCondition::EnsureWatchability);
923 RELEASE_ASSERT(isWatchable); // We allow this to install the necessary watchpoints.
929 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(arrayIteratorPrototype, m_vm.propertyNames->next);
930 m_arrayIteratorPrototypeNext = std::make_unique<ArrayIteratorAdaptiveWatchpoint>(condition, this);
931 m_arrayIteratorPrototypeNext->install();
935 ArrayPrototype* arrayPrototype = this->arrayPrototype();
936 ObjectPropertyCondition condition = setupAdaptiveWatchpoint(arrayPrototype, m_vm.propertyNames->iteratorSymbol);
937 m_arrayPrototypeSymbolIteratorWatchpoint = std::make_unique<ArrayIteratorAdaptiveWatchpoint>(condition, this);
938 m_arrayPrototypeSymbolIteratorWatchpoint->install();
942 resetPrototype(vm, getPrototypeDirect());
945 bool JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
948 auto scope = DECLARE_THROW_SCOPE(vm);
949 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
950 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
952 if (UNLIKELY(isThisValueAltered(slot, thisObject))) {
954 return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
957 bool shouldThrowReadOnlyError = slot.isStrictMode();
958 bool ignoreReadOnlyErrors = false;
959 bool putResult = false;
960 bool done = symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
961 ASSERT((!!scope.exception() == (done && !putResult)) || !shouldThrowReadOnlyError);
965 return Base::put(thisObject, exec, propertyName, value, slot);
968 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
970 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
971 PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry);
972 // silently ignore attempts to add accessors aliasing vars.
973 if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
975 return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
978 void JSGlobalObject::addGlobalVar(const Identifier& ident)
980 ConcurrentJSLocker locker(symbolTable()->m_lock);
981 SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
985 ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
986 SymbolTableEntry newEntry(VarOffset(offset), 0);
987 newEntry.prepareToWatch();
988 symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
990 ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
991 RELEASE_ASSERT(offsetForAssert == offset);
994 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
997 VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
998 methodTable(vm)->deleteProperty(this, exec, propertyName);
999 addGlobalVar(propertyName);
1002 void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
1004 m_globalScopeExtension.set(vm(), this, scope);
1007 void JSGlobalObject::clearGlobalScopeExtension()
1009 m_globalScopeExtension.clear();
1012 static inline JSObject* lastInPrototypeChain(JSObject* object)
1014 JSObject* o = object;
1015 while (o->getPrototypeDirect().isObject())
1016 o = asObject(o->getPrototypeDirect());
1020 // Private namespace for helpers for JSGlobalObject::haveABadTime()
1023 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
1025 ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
1026 IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1029 void visit(JSCell*);
1031 MarkedArgumentBuffer& m_foundObjects;
1032 JSGlobalObject* m_globalObject;
1035 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
1036 MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
1037 : m_foundObjects(foundObjects)
1038 , m_globalObject(globalObject)
1042 inline bool hasBrokenIndexing(JSObject* object)
1044 // This will change if we have more indexing types.
1045 IndexingType type = object->indexingType();
1046 // This could be made obviously more efficient, but isn't made so right now, because
1047 // we expect this to be an unlikely slow path anyway.
1048 return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type);
1051 inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell)
1053 if (!cell->isObject())
1056 JSObject* object = asObject(cell);
1058 // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
1059 if (!hasBrokenIndexing(object))
1062 // We only want to have a bad time in the affected global object, not in the entire
1063 // VM. But we have to be careful, since there may be objects that claim to belong to
1064 // a different global object that have prototypes from our global object.
1065 bool foundGlobalObject = false;
1066 for (JSObject* current = object; ;) {
1067 if (current->globalObject() == m_globalObject) {
1068 foundGlobalObject = true;
1072 JSValue prototypeValue = current->getPrototypeDirect();
1073 if (prototypeValue.isNull())
1075 current = asObject(prototypeValue);
1077 if (!foundGlobalObject)
1080 m_foundObjects.append(object);
1083 IterationStatus ObjectsWithBrokenIndexingFinder::operator()(HeapCell* cell, HeapCell::Kind kind) const
1085 if (kind == HeapCell::JSCell) {
1086 // FIXME: This const_cast exists because this isn't a C++ lambda.
1087 // https://bugs.webkit.org/show_bug.cgi?id=159644
1088 const_cast<ObjectsWithBrokenIndexingFinder*>(this)->visit(static_cast<JSCell*>(cell));
1090 return IterationStatus::Continue;
1093 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
1095 void JSGlobalObject::haveABadTime(VM& vm)
1097 ASSERT(&vm == &this->vm());
1099 if (isHavingABadTime())
1102 // Make sure that all allocations or indexed storage transitions that are inlining
1103 // the assumption that it's safe to transition to a non-SlowPut array storage don't
1105 m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
1106 ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
1108 // Make sure that all JSArray allocations that load the appropriate structure from
1109 // this object now load a structure that uses SlowPut.
1110 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1111 m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
1113 // Same for any special array structures.
1114 Structure* slowPutStructure;
1115 slowPutStructure = createRegExpMatchesArraySlowPutStructure(vm, this);
1116 m_regExpMatchesArrayStructure.set(vm, this, slowPutStructure);
1117 slowPutStructure = ClonedArguments::createSlowPutStructure(vm, this, m_objectPrototype.get());
1118 m_clonedArgumentsStructure.set(vm, this, slowPutStructure);
1120 // Make sure that all objects that have indexed storage switch to the slow kind of
1122 MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
1123 ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
1125 HeapIterationScope iterationScope(vm.heap);
1126 vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
1128 while (!foundObjects.isEmpty()) {
1129 JSObject* object = asObject(foundObjects.last());
1130 foundObjects.removeLast();
1131 ASSERT(hasBrokenIndexing(object));
1132 object->switchToSlowPutArrayStorage(vm);
1136 // Set prototype, and also insert the object prototype at the end of the chain.
1137 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1139 setPrototypeDirect(vm, prototype);
1141 JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
1142 JSObject* objectPrototype = m_objectPrototype.get();
1143 if (oldLastInPrototypeChain != objectPrototype)
1144 oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1146 // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1147 setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1150 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1152 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1153 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1154 Base::visitChildren(thisObject, visitor);
1156 visitor.append(thisObject->m_globalThis);
1158 visitor.append(thisObject->m_globalLexicalEnvironment);
1159 visitor.append(thisObject->m_globalScopeExtension);
1160 visitor.append(thisObject->m_globalCallee);
1161 visitor.append(thisObject->m_regExpConstructor);
1162 visitor.append(thisObject->m_errorConstructor);
1163 visitor.append(thisObject->m_nativeErrorPrototypeStructure);
1164 visitor.append(thisObject->m_nativeErrorStructure);
1165 thisObject->m_evalErrorConstructor.visit(visitor);
1166 visitor.append(thisObject->m_rangeErrorConstructor);
1167 thisObject->m_referenceErrorConstructor.visit(visitor);
1168 thisObject->m_syntaxErrorConstructor.visit(visitor);
1169 visitor.append(thisObject->m_typeErrorConstructor);
1170 thisObject->m_URIErrorConstructor.visit(visitor);
1171 visitor.append(thisObject->m_objectConstructor);
1172 visitor.append(thisObject->m_promiseConstructor);
1174 visitor.append(thisObject->m_nullGetterFunction);
1175 visitor.append(thisObject->m_nullSetterFunction);
1177 visitor.append(thisObject->m_parseIntFunction);
1178 visitor.append(thisObject->m_evalFunction);
1179 visitor.append(thisObject->m_callFunction);
1180 visitor.append(thisObject->m_applyFunction);
1181 visitor.append(thisObject->m_throwTypeErrorFunction);
1182 thisObject->m_arrayProtoToStringFunction.visit(visitor);
1183 thisObject->m_arrayProtoValuesFunction.visit(visitor);
1184 thisObject->m_initializePromiseFunction.visit(visitor);
1185 thisObject->m_iteratorProtocolFunction.visit(visitor);
1186 visitor.append(thisObject->m_objectProtoValueOfFunction);
1187 visitor.append(thisObject->m_newPromiseCapabilityFunction);
1188 visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
1189 thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1190 visitor.append(thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
1191 visitor.append(thisObject->m_moduleLoader);
1193 visitor.append(thisObject->m_objectPrototype);
1194 visitor.append(thisObject->m_functionPrototype);
1195 visitor.append(thisObject->m_arrayPrototype);
1196 visitor.append(thisObject->m_errorPrototype);
1197 visitor.append(thisObject->m_iteratorPrototype);
1198 visitor.append(thisObject->m_generatorFunctionPrototype);
1199 visitor.append(thisObject->m_generatorPrototype);
1200 visitor.append(thisObject->m_asyncFunctionPrototype);
1201 visitor.append(thisObject->m_moduleLoaderPrototype);
1203 thisObject->m_debuggerScopeStructure.visit(visitor);
1204 thisObject->m_withScopeStructure.visit(visitor);
1205 visitor.append(thisObject->m_strictEvalActivationStructure);
1206 visitor.append(thisObject->m_lexicalEnvironmentStructure);
1207 thisObject->m_moduleEnvironmentStructure.visit(visitor);
1208 visitor.append(thisObject->m_directArgumentsStructure);
1209 visitor.append(thisObject->m_scopedArgumentsStructure);
1210 visitor.append(thisObject->m_clonedArgumentsStructure);
1211 visitor.append(thisObject->m_objectStructureForObjectConstructor);
1212 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1213 visitor.append(thisObject->m_originalArrayStructureForIndexingShape[i]);
1214 for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1215 visitor.append(thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1216 thisObject->m_callbackConstructorStructure.visit(visitor);
1217 thisObject->m_callbackFunctionStructure.visit(visitor);
1218 thisObject->m_callbackObjectStructure.visit(visitor);
1219 visitor.append(thisObject->m_propertyNameIteratorStructure);
1220 #if JSC_OBJC_API_ENABLED
1221 thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1222 thisObject->m_objcWrapperObjectStructure.visit(visitor);
1224 thisObject->m_nullPrototypeObjectStructure.visit(visitor);
1225 visitor.append(thisObject->m_errorStructure);
1226 visitor.append(thisObject->m_calleeStructure);
1227 visitor.append(thisObject->m_functionStructure);
1228 thisObject->m_customGetterSetterFunctionStructure.visit(visitor);
1229 thisObject->m_boundFunctionStructure.visit(visitor);
1230 visitor.append(thisObject->m_getterSetterStructure);
1231 thisObject->m_nativeStdFunctionStructure.visit(visitor);
1232 thisObject->m_namedFunctionStructure.visit(visitor);
1233 visitor.append(thisObject->m_symbolObjectStructure);
1234 visitor.append(thisObject->m_regExpStructure);
1235 visitor.append(thisObject->m_generatorFunctionStructure);
1236 visitor.append(thisObject->m_asyncFunctionStructure);
1237 visitor.append(thisObject->m_iteratorResultObjectStructure);
1238 visitor.append(thisObject->m_regExpMatchesArrayStructure);
1239 visitor.append(thisObject->m_moduleRecordStructure);
1240 visitor.append(thisObject->m_moduleNamespaceObjectStructure);
1241 visitor.append(thisObject->m_dollarVMStructure);
1242 visitor.append(thisObject->m_proxyObjectStructure);
1243 visitor.append(thisObject->m_callableProxyObjectStructure);
1244 visitor.append(thisObject->m_proxyRevokeStructure);
1245 visitor.append(thisObject->m_moduleLoaderStructure);
1247 visitor.append(thisObject->m_arrayBufferPrototype);
1248 visitor.append(thisObject->m_arrayBufferStructure);
1249 visitor.append(thisObject->m_sharedArrayBufferPrototype);
1250 visitor.append(thisObject->m_sharedArrayBufferStructure);
1252 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1253 visitor.append(thisObject->m_ ## lowerName ## Prototype); \
1254 visitor.append(thisObject->m_ ## properName ## Structure); \
1256 FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1258 #if ENABLE(WEBASSEMBLY)
1259 visitor.append(thisObject->m_webAssemblyStructure);
1260 visitor.append(thisObject->m_webAssemblyModuleRecordStructure);
1261 visitor.append(thisObject->m_webAssemblyFunctionStructure);
1262 visitor.append(thisObject->m_webAssemblyWrapperFunctionStructure);
1263 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(VISIT_SIMPLE_TYPE)
1264 #endif // ENABLE(WEBASSEMBLY)
1266 #undef VISIT_SIMPLE_TYPE
1268 #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1269 thisObject->m_ ## properName ## Structure.visit(visitor);
1271 FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1272 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_LAZY_TYPE)
1274 #undef VISIT_LAZY_TYPE
1276 for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;)
1277 thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1279 visitor.append(thisObject->m_speciesGetterSetter);
1280 thisObject->m_typedArrayProto.visit(visitor);
1281 thisObject->m_typedArraySuperConstructor.visit(visitor);
1284 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
1286 if (ecmaMode == StrictMode)
1287 return jsUndefined();
1288 return exec->globalThisValue();
1291 ExecState* JSGlobalObject::globalExec()
1293 return CallFrame::create(m_globalCallFrame);
1296 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1298 ScopeOffset startOffset = addVariables(count, jsUndefined());
1300 for (int i = 0; i < count; ++i) {
1301 GlobalPropertyInfo& global = globals[i];
1302 ASSERT(global.attributes & DontDelete);
1304 WatchpointSet* watchpointSet = nullptr;
1305 WriteBarrierBase<Unknown>* variable = nullptr;
1307 ConcurrentJSLocker locker(symbolTable()->m_lock);
1308 ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1309 RELEASE_ASSERT(offset == startOffset + i);
1310 SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1311 newEntry.prepareToWatch();
1312 watchpointSet = newEntry.watchpointSet();
1313 symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1314 variable = &variableAt(offset);
1316 symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1320 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1322 if (Base::getOwnPropertySlot(object, exec, propertyName, slot))
1324 return symbolTableGet(jsCast<JSGlobalObject*>(object), propertyName, slot);
1327 void JSGlobalObject::clearRareData(JSCell* cell)
1329 jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1332 void slowValidateCell(JSGlobalObject* globalObject)
1334 RELEASE_ASSERT(globalObject->isGlobalObject());
1335 ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1338 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1340 #if ENABLE(REMOTE_INSPECTOR)
1341 m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1343 UNUSED_PARAM(enabled);
1347 bool JSGlobalObject::remoteDebuggingEnabled() const
1349 #if ENABLE(REMOTE_INSPECTOR)
1350 return m_inspectorDebuggable->remoteDebuggingAllowed();
1356 #if ENABLE(WEB_REPLAY)
1357 void JSGlobalObject::setInputCursor(Ref<InputCursor>&& cursor)
1359 m_inputCursor = WTFMove(cursor);
1360 // Save or set the random seed. This performed here rather than the constructor
1361 // to avoid threading the input cursor through all the abstraction layers.
1362 if (m_inputCursor->isCapturing())
1363 m_inputCursor->appendInput<SetRandomSeed>(m_weakRandom.seed());
1364 else if (m_inputCursor->isReplaying()) {
1365 if (SetRandomSeed* input = m_inputCursor->fetchInput<SetRandomSeed>())
1366 m_weakRandom.setSeed(static_cast<unsigned>(input->randomSeed()));
1371 void JSGlobalObject::setName(const String& name)
1375 #if ENABLE(REMOTE_INSPECTOR)
1376 m_inspectorDebuggable->update();
1381 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1383 if (m_intlCollatorAvailableLocales.isEmpty()) {
1384 int32_t count = ucol_countAvailable();
1385 for (int32_t i = 0; i < count; ++i) {
1386 String locale(ucol_getAvailable(i));
1387 convertICULocaleToBCP47LanguageTag(locale);
1388 m_intlCollatorAvailableLocales.add(locale);
1391 return m_intlCollatorAvailableLocales;
1394 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1396 if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1397 int32_t count = udat_countAvailable();
1398 for (int32_t i = 0; i < count; ++i) {
1399 String locale(udat_getAvailable(i));
1400 convertICULocaleToBCP47LanguageTag(locale);
1401 m_intlDateTimeFormatAvailableLocales.add(locale);
1404 return m_intlDateTimeFormatAvailableLocales;
1407 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1409 if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1410 int32_t count = unum_countAvailable();
1411 for (int32_t i = 0; i < count; ++i) {
1412 String locale(unum_getAvailable(i));
1413 convertICULocaleToBCP47LanguageTag(locale);
1414 m_intlNumberFormatAvailableLocales.add(locale);
1417 return m_intlNumberFormatAvailableLocales;
1419 #endif // ENABLE(INTL)
1421 void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
1423 if (globalObjectMethodTable()->queueTaskToEventLoop) {
1424 globalObjectMethodTable()->queueTaskToEventLoop(this, WTFMove(task));
1428 vm().queueMicrotask(this, WTFMove(task));
1431 bool JSGlobalObject::hasDebugger() const
1436 bool JSGlobalObject::hasInteractiveDebugger() const
1438 return m_debugger && m_debugger->isInteractivelyDebugging();
1441 JSGlobalObject* JSGlobalObject::create(VM& vm, Structure* structure)
1443 JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
1444 globalObject->finishCreation(vm);
1445 return globalObject;
1448 void JSGlobalObject::finishCreation(VM& vm)
1450 Base::finishCreation(vm);
1451 structure()->setGlobalObject(vm, this);
1452 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1454 setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, getPrototypeDirect(), PureForwardingProxyType), this));
1457 void JSGlobalObject::finishCreation(VM& vm, JSObject* thisValue)
1459 Base::finishCreation(vm);
1460 structure()->setGlobalObject(vm, this);
1461 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1463 setGlobalThis(vm, thisValue);