1 | /* |
2 | * Copyright (C) 2007 Eric Seidel <[email protected]> |
3 | * Copyright (C) 2007-2019 Apple Inc. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | * |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include "ArrayAllocationProfile.h" |
25 | #include "ArrayBufferSharingMode.h" |
26 | #include "BigIntPrototype.h" |
27 | #include "BooleanPrototype.h" |
28 | #include "ErrorType.h" |
29 | #include "ExceptionHelpers.h" |
30 | #include "InternalFunction.h" |
31 | #include "JSArray.h" |
32 | #include "JSArrayBufferPrototype.h" |
33 | #include "JSClassRef.h" |
34 | #include "JSGlobalLexicalEnvironment.h" |
35 | #include "JSPromiseDeferred.h" |
36 | #include "JSSegmentedVariableObject.h" |
37 | #include "JSWeakObjectMapRefInternal.h" |
38 | #include "LazyProperty.h" |
39 | #include "LazyClassStructure.h" |
40 | #include "NumberPrototype.h" |
41 | #include "ParserModes.h" |
42 | #include "RegExpGlobalData.h" |
43 | #include "RuntimeFlags.h" |
44 | #include "SpecialPointer.h" |
45 | #include "StringPrototype.h" |
46 | #include "SymbolPrototype.h" |
47 | #include "VM.h" |
48 | #include "Watchpoint.h" |
49 | #include <JavaScriptCore/JSBase.h> |
50 | #include <array> |
51 | #include <wtf/HashSet.h> |
52 | #include <wtf/RetainPtr.h> |
53 | |
54 | struct OpaqueJSClass; |
55 | struct OpaqueJSClassContextData; |
56 | OBJC_CLASS JSWrapperMap; |
57 | |
58 | namespace Inspector { |
59 | class JSGlobalObjectInspectorController; |
60 | } |
61 | |
62 | namespace JSC { |
63 | class ArrayConstructor; |
64 | class ArrayPrototype; |
65 | class AsyncIteratorPrototype; |
66 | class AsyncFunctionPrototype; |
67 | class AsyncGeneratorPrototype; |
68 | class AsyncGeneratorFunctionPrototype; |
69 | class BooleanPrototype; |
70 | class ConsoleClient; |
71 | class Debugger; |
72 | class ErrorConstructor; |
73 | class ErrorPrototype; |
74 | class EvalCodeBlock; |
75 | class EvalExecutable; |
76 | class FunctionConstructor; |
77 | class FunctionPrototype; |
78 | class GeneratorPrototype; |
79 | class GeneratorFunctionPrototype; |
80 | class GetterSetter; |
81 | class GlobalCodeBlock; |
82 | class IndirectEvalExecutable; |
83 | class InputCursor; |
84 | class IntlObject; |
85 | class IntlCollator; |
86 | class JSArrayBuffer; |
87 | class JSArrayBufferPrototype; |
88 | class JSCallee; |
89 | class JSGlobalObjectDebuggable; |
90 | class JSInternalPromise; |
91 | class JSModuleLoader; |
92 | class JSModuleRecord; |
93 | class JSPromise; |
94 | class JSPromiseConstructor; |
95 | class JSPromisePrototype; |
96 | class JSSharedArrayBuffer; |
97 | class JSSharedArrayBufferPrototype; |
98 | class JSTypedArrayViewConstructor; |
99 | class JSTypedArrayViewPrototype; |
100 | class DirectEvalExecutable; |
101 | class ; |
102 | class MapPrototype; |
103 | class Microtask; |
104 | class ModuleLoader; |
105 | class ModuleProgramExecutable; |
106 | class NativeErrorConstructorBase; |
107 | class NullGetterFunction; |
108 | class NullSetterFunction; |
109 | class ObjectConstructor; |
110 | class ProgramCodeBlock; |
111 | class ProgramExecutable; |
112 | class RegExpConstructor; |
113 | class RegExpPrototype; |
114 | class SetPrototype; |
115 | class SourceCode; |
116 | class SourceOrigin; |
117 | class UnlinkedModuleProgramCodeBlock; |
118 | class VariableEnvironment; |
119 | struct ActivationStackNode; |
120 | struct HashTable; |
121 | |
122 | #ifdef JSC_GLIB_API_ENABLED |
123 | class WrapperMap; |
124 | #endif |
125 | |
126 | template<typename Watchpoint> class ObjectPropertyChangeAdaptiveWatchpoint; |
127 | |
128 | #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName, object) |
129 | |
130 | #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \ |
131 | macro(String, string, stringObject, StringObject, String, object) \ |
132 | macro(Map, map, map, JSMap, Map, object) \ |
133 | macro(Set, set, set, JSSet, Set, object) \ |
134 | macro(JSPromise, promise, promise, JSPromise, Promise, object) |
135 | |
136 | #define FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \ |
137 | macro(BigInt, bigInt, bigIntObject, BigIntObject, BigInt, object) |
138 | |
139 | #define FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \ |
140 | macro(StringIterator, stringIterator, stringIterator, JSStringIterator, StringIterator, iterator) \ |
141 | |
142 | #define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \ |
143 | FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \ |
144 | macro(JSInternalPromise, internalPromise, internalPromise, JSInternalPromise, InternalPromise, object) \ |
145 | |
146 | #define FOR_EACH_LAZY_BUILTIN_TYPE_WITH_DECLARATION(macro) \ |
147 | macro(Boolean, boolean, booleanObject, BooleanObject, Boolean, object) \ |
148 | macro(Date, date, date, DateInstance, Date, object) \ |
149 | macro(Error, error, error, ErrorInstance, Error, object) \ |
150 | macro(Number, number, numberObject, NumberObject, Number, object) \ |
151 | macro(Symbol, symbol, symbolObject, SymbolObject, Symbol, object) \ |
152 | macro(WeakObjectRef, weakObjectRef, weakObjectRef, JSWeakObjectRef, WeakRef, object) \ |
153 | DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \ |
154 | DEFINE_STANDARD_BUILTIN(macro, WeakSet, weakSet) \ |
155 | |
156 | #define FOR_EACH_LAZY_BUILTIN_TYPE(macro) \ |
157 | FOR_EACH_LAZY_BUILTIN_TYPE_WITH_DECLARATION(macro) \ |
158 | macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer, object) \ |
159 | |
160 | #if ENABLE(WEBASSEMBLY) |
161 | #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro) \ |
162 | macro(WebAssemblyCompileError, webAssemblyCompileError, webAssemblyCompileError, JSWebAssemblyCompileError, CompileError, error) \ |
163 | macro(WebAssemblyInstance, webAssemblyInstance, webAssemblyInstance, JSWebAssemblyInstance, Instance, object) \ |
164 | macro(WebAssemblyLinkError, webAssemblyLinkError, webAssemblyLinkError, JSWebAssemblyLinkError, LinkError, error) \ |
165 | macro(WebAssemblyMemory, webAssemblyMemory, webAssemblyMemory, JSWebAssemblyMemory, Memory, object) \ |
166 | macro(WebAssemblyModule, webAssemblyModule, webAssemblyModule, JSWebAssemblyModule, Module, object) \ |
167 | macro(WebAssemblyRuntimeError, webAssemblyRuntimeError, webAssemblyRuntimeError, JSWebAssemblyRuntimeError, RuntimeError, error) \ |
168 | macro(WebAssemblyTable, webAssemblyTable, webAssemblyTable, JSWebAssemblyTable, Table, object) |
169 | #else |
170 | #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro) |
171 | #endif // ENABLE(WEBASSEMBLY) |
172 | |
173 | #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \ |
174 | class JS ## capitalName; \ |
175 | class capitalName ## Prototype; \ |
176 | class capitalName ## Constructor; |
177 | |
178 | class IteratorPrototype; |
179 | FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE) |
180 | FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DECLARE_SIMPLE_BUILTIN_TYPE) |
181 | FOR_EACH_LAZY_BUILTIN_TYPE_WITH_DECLARATION(DECLARE_SIMPLE_BUILTIN_TYPE) |
182 | FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE) |
183 | FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE) |
184 | |
185 | #undef DECLARE_SIMPLE_BUILTIN_TYPE |
186 | |
187 | enum class JSPromiseRejectionOperation : unsigned { |
188 | Reject, // When a promise is rejected without any handlers. |
189 | Handle, // When a handler is added to a rejected promise for the first time. |
190 | }; |
191 | |
192 | struct GlobalObjectMethodTable { |
193 | typedef bool (*SupportsRichSourceInfoFunctionPtr)(const JSGlobalObject*); |
194 | SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo; |
195 | |
196 | typedef bool (*ShouldInterruptScriptFunctionPtr)(const JSGlobalObject*); |
197 | ShouldInterruptScriptFunctionPtr shouldInterruptScript; |
198 | |
199 | typedef RuntimeFlags (*JavaScriptRuntimeFlagsFunctionPtr)(const JSGlobalObject*); |
200 | JavaScriptRuntimeFlagsFunctionPtr javaScriptRuntimeFlags; |
201 | |
202 | typedef void (*QueueTaskToEventLoopFunctionPtr)(JSGlobalObject&, Ref<Microtask>&&); |
203 | QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop; |
204 | |
205 | typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr)(const JSGlobalObject*); |
206 | ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout; |
207 | |
208 | typedef JSInternalPromise* (*ModuleLoaderImportModulePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, JSValue, const SourceOrigin&); |
209 | ModuleLoaderImportModulePtr moduleLoaderImportModule; |
210 | |
211 | typedef Identifier (*ModuleLoaderResolvePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue); |
212 | ModuleLoaderResolvePtr moduleLoaderResolve; |
213 | |
214 | typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue); |
215 | ModuleLoaderFetchPtr moduleLoaderFetch; |
216 | |
217 | typedef JSObject* (*ModuleLoaderCreateImportMetaPropertiesPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue); |
218 | ModuleLoaderCreateImportMetaPropertiesPtr moduleLoaderCreateImportMetaProperties; |
219 | |
220 | typedef JSValue (*ModuleLoaderEvaluatePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue); |
221 | ModuleLoaderEvaluatePtr moduleLoaderEvaluate; |
222 | |
223 | typedef void (*PromiseRejectionTrackerPtr)(JSGlobalObject*, ExecState*, JSPromise*, JSPromiseRejectionOperation); |
224 | PromiseRejectionTrackerPtr promiseRejectionTracker; |
225 | |
226 | typedef String (*DefaultLanguageFunctionPtr)(); |
227 | DefaultLanguageFunctionPtr defaultLanguage; |
228 | |
229 | typedef void (*CompileStreamingPtr)(JSGlobalObject*, ExecState*, JSPromiseDeferred*, JSValue); |
230 | CompileStreamingPtr compileStreaming; |
231 | |
232 | typedef void (*InstantiateStreamingPtr)(JSGlobalObject*, ExecState*, JSPromiseDeferred*, JSValue, JSObject*); |
233 | InstantiateStreamingPtr instantiateStreaming; |
234 | }; |
235 | |
236 | class JSGlobalObject : public JSSegmentedVariableObject { |
237 | private: |
238 | typedef HashSet<RefPtr<OpaqueJSWeakObjectMap>> WeakMapSet; |
239 | typedef HashMap<OpaqueJSClass*, std::unique_ptr<OpaqueJSClassContextData>> OpaqueJSClassDataMap; |
240 | |
241 | struct JSGlobalObjectRareData { |
242 | WTF_MAKE_FAST_ALLOCATED; |
243 | public: |
244 | JSGlobalObjectRareData() |
245 | : profileGroup(0) |
246 | { |
247 | } |
248 | |
249 | WeakMapSet weakMaps; |
250 | unsigned profileGroup; |
251 | |
252 | OpaqueJSClassDataMap opaqueJSClassData; |
253 | }; |
254 | |
255 | // Our hashtable code-generator tries to access these properties, so we make them public. |
256 | // However, we'd like it better if they could be protected. |
257 | public: |
258 | template<typename T> using Initializer = typename LazyProperty<JSGlobalObject, T>::Initializer; |
259 | |
260 | Register m_globalCallFrame[CallFrame::headerSizeInRegisters]; |
261 | |
262 | WriteBarrier<JSObject> m_globalThis; |
263 | |
264 | WriteBarrier<JSGlobalLexicalEnvironment> m_globalLexicalEnvironment; |
265 | WriteBarrier<JSScope> m_globalScopeExtension; |
266 | WriteBarrier<JSCallee> m_globalCallee; |
267 | WriteBarrier<JSCallee> m_stackOverflowFrameCallee; |
268 | |
269 | LazyClassStructure m_evalErrorStructure; |
270 | LazyClassStructure m_rangeErrorStructure; |
271 | LazyClassStructure m_referenceErrorStructure; |
272 | LazyClassStructure m_syntaxErrorStructure; |
273 | LazyClassStructure m_typeErrorStructure; |
274 | LazyClassStructure m_URIErrorStructure; |
275 | |
276 | WriteBarrier<ObjectConstructor> m_objectConstructor; |
277 | WriteBarrier<ArrayConstructor> m_arrayConstructor; |
278 | WriteBarrier<JSPromiseConstructor> m_promiseConstructor; |
279 | WriteBarrier<JSInternalPromiseConstructor> m_internalPromiseConstructor; |
280 | |
281 | #if ENABLE(INTL) |
282 | WriteBarrier<IntlCollator> m_defaultCollator; |
283 | LazyProperty<JSGlobalObject, Structure> m_collatorStructure; |
284 | LazyProperty<JSGlobalObject, Structure> m_numberFormatStructure; |
285 | LazyProperty<JSGlobalObject, Structure> m_dateTimeFormatStructure; |
286 | LazyProperty<JSGlobalObject, Structure> m_pluralRulesStructure; |
287 | #endif |
288 | WriteBarrier<NullGetterFunction> m_nullGetterFunction; |
289 | WriteBarrier<NullSetterFunction> m_nullSetterFunction; |
290 | |
291 | LazyProperty<JSGlobalObject, JSFunction> m_parseIntFunction; |
292 | LazyProperty<JSGlobalObject, JSFunction> m_parseFloatFunction; |
293 | |
294 | WriteBarrier<JSFunction> m_callFunction; |
295 | WriteBarrier<JSFunction> m_applyFunction; |
296 | WriteBarrier<JSFunction> m_throwTypeErrorFunction; |
297 | LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoToStringFunction; |
298 | LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoValuesFunction; |
299 | LazyProperty<JSGlobalObject, JSFunction> m_evalFunction; |
300 | LazyProperty<JSGlobalObject, JSFunction> m_initializePromiseFunction; |
301 | LazyProperty<JSGlobalObject, JSFunction> m_iteratorProtocolFunction; |
302 | LazyProperty<JSGlobalObject, JSFunction> m_promiseResolveFunction; |
303 | WriteBarrier<JSFunction> m_objectProtoValueOfFunction; |
304 | WriteBarrier<JSFunction> m_numberProtoToStringFunction; |
305 | WriteBarrier<JSFunction> m_newPromiseCapabilityFunction; |
306 | WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction; |
307 | LazyProperty<JSGlobalObject, GetterSetter> m_throwTypeErrorGetterSetter; |
308 | WriteBarrier<JSObject> m_regExpProtoExec; |
309 | WriteBarrier<JSObject> m_regExpProtoSymbolReplace; |
310 | WriteBarrier<JSObject> m_regExpProtoGlobalGetter; |
311 | WriteBarrier<JSObject> m_regExpProtoUnicodeGetter; |
312 | WriteBarrier<GetterSetter> m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter; |
313 | |
314 | LazyProperty<JSGlobalObject, JSModuleLoader> m_moduleLoader; |
315 | |
316 | WriteBarrier<ObjectPrototype> m_objectPrototype; |
317 | WriteBarrier<FunctionPrototype> m_functionPrototype; |
318 | WriteBarrier<ArrayPrototype> m_arrayPrototype; |
319 | WriteBarrier<RegExpPrototype> m_regExpPrototype; |
320 | WriteBarrier<IteratorPrototype> m_iteratorPrototype; |
321 | WriteBarrier<AsyncIteratorPrototype> m_asyncIteratorPrototype; |
322 | WriteBarrier<GeneratorFunctionPrototype> m_generatorFunctionPrototype; |
323 | WriteBarrier<GeneratorPrototype> m_generatorPrototype; |
324 | WriteBarrier<AsyncGeneratorPrototype> m_asyncGeneratorPrototype; |
325 | |
326 | LazyProperty<JSGlobalObject, Structure> m_debuggerScopeStructure; |
327 | LazyProperty<JSGlobalObject, Structure> m_withScopeStructure; |
328 | LazyProperty<JSGlobalObject, Structure> m_strictEvalActivationStructure; |
329 | WriteBarrier<Structure> m_lexicalEnvironmentStructure; |
330 | LazyProperty<JSGlobalObject, Structure> m_moduleEnvironmentStructure; |
331 | WriteBarrier<Structure> m_directArgumentsStructure; |
332 | WriteBarrier<Structure> m_scopedArgumentsStructure; |
333 | WriteBarrier<Structure> m_clonedArgumentsStructure; |
334 | |
335 | WriteBarrier<Structure> m_objectStructureForObjectConstructor; |
336 | |
337 | // Lists the actual structures used for having these particular indexing shapes. |
338 | WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfArrayIndexingModes]; |
339 | // Lists the structures we should use during allocation for these particular indexing shapes. |
340 | // These structures will differ from the originals list above when we are having a bad time. |
341 | WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfArrayIndexingModes]; |
342 | |
343 | LazyProperty<JSGlobalObject, Structure> m_callbackConstructorStructure; |
344 | LazyProperty<JSGlobalObject, Structure> m_callbackFunctionStructure; |
345 | LazyProperty<JSGlobalObject, Structure> m_callbackObjectStructure; |
346 | #if JSC_OBJC_API_ENABLED |
347 | LazyProperty<JSGlobalObject, Structure> m_objcCallbackFunctionStructure; |
348 | LazyProperty<JSGlobalObject, Structure> m_objcWrapperObjectStructure; |
349 | #endif |
350 | #ifdef JSC_GLIB_API_ENABLED |
351 | LazyProperty<JSGlobalObject, Structure> m_glibCallbackFunctionStructure; |
352 | LazyProperty<JSGlobalObject, Structure> m_glibWrapperObjectStructure; |
353 | #endif |
354 | WriteBarrier<Structure> m_nullPrototypeObjectStructure; |
355 | WriteBarrier<Structure> m_calleeStructure; |
356 | |
357 | WriteBarrier<Structure> m_hostFunctionStructure; |
358 | |
359 | struct FunctionStructures { |
360 | WriteBarrier<Structure> arrowFunctionStructure; |
361 | WriteBarrier<Structure> sloppyFunctionStructure; |
362 | WriteBarrier<Structure> strictFunctionStructure; |
363 | }; |
364 | FunctionStructures m_builtinFunctions; |
365 | FunctionStructures m_ordinaryFunctions; |
366 | |
367 | LazyProperty<JSGlobalObject, Structure> m_boundFunctionStructure; |
368 | LazyProperty<JSGlobalObject, Structure> m_customGetterSetterFunctionStructure; |
369 | WriteBarrier<Structure> m_getterSetterStructure; |
370 | LazyProperty<JSGlobalObject, Structure> m_nativeStdFunctionStructure; |
371 | PropertyOffset m_functionNameOffset; |
372 | WriteBarrier<Structure> m_regExpStructure; |
373 | WriteBarrier<AsyncFunctionPrototype> m_asyncFunctionPrototype; |
374 | WriteBarrier<AsyncGeneratorFunctionPrototype> m_asyncGeneratorFunctionPrototype; |
375 | WriteBarrier<Structure> m_asyncFunctionStructure; |
376 | WriteBarrier<Structure> m_asyncGeneratorFunctionStructure; |
377 | WriteBarrier<Structure> m_generatorFunctionStructure; |
378 | LazyProperty<JSGlobalObject, Structure> m_iteratorResultObjectStructure; |
379 | WriteBarrier<Structure> m_regExpMatchesArrayStructure; |
380 | WriteBarrier<Structure> m_regExpMatchesArrayWithGroupsStructure; |
381 | LazyProperty<JSGlobalObject, Structure> m_moduleRecordStructure; |
382 | LazyProperty<JSGlobalObject, Structure> m_moduleNamespaceObjectStructure; |
383 | LazyProperty<JSGlobalObject, Structure> m_proxyObjectStructure; |
384 | LazyProperty<JSGlobalObject, Structure> m_callableProxyObjectStructure; |
385 | LazyProperty<JSGlobalObject, Structure> m_proxyRevokeStructure; |
386 | #if ENABLE(SHARED_ARRAY_BUFFER) |
387 | WriteBarrier<JSArrayBufferPrototype> m_sharedArrayBufferPrototype; |
388 | WriteBarrier<Structure> m_sharedArrayBufferStructure; |
389 | #endif |
390 | |
391 | #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \ |
392 | WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \ |
393 | WriteBarrier<Structure> m_ ## properName ## Structure; |
394 | |
395 | #define DEFINE_STORAGE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \ |
396 | LazyClassStructure m_ ## properName ## Structure; |
397 | |
398 | FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE) |
399 | FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_STORAGE_FOR_SIMPLE_TYPE) |
400 | FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE) |
401 | |
402 | #if ENABLE(WEBASSEMBLY) |
403 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyModuleRecordStructure; |
404 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyFunctionStructure; |
405 | LazyProperty<JSGlobalObject, Structure> m_jsToWasmICCalleeStructure; |
406 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyWrapperFunctionStructure; |
407 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyToJSCalleeStructure; |
408 | FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE) |
409 | #endif // ENABLE(WEBASSEMBLY) |
410 | |
411 | FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE) |
412 | |
413 | #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE |
414 | #undef DEFINE_STORAGE_FOR_LAZY_TYPE |
415 | |
416 | WriteBarrier<GetterSetter> m_speciesGetterSetter; |
417 | |
418 | LazyProperty<JSGlobalObject, JSTypedArrayViewPrototype> m_typedArrayProto; |
419 | LazyProperty<JSGlobalObject, JSTypedArrayViewConstructor> m_typedArraySuperConstructor; |
420 | |
421 | #define DECLARE_TYPED_ARRAY_TYPE_STRUCTURE(name) LazyClassStructure m_typedArray ## name; |
422 | FOR_EACH_TYPED_ARRAY_TYPE(DECLARE_TYPED_ARRAY_TYPE_STRUCTURE) |
423 | #undef DECLARE_TYPED_ARRAY_TYPE_STRUCTURE |
424 | |
425 | JSCell* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT. |
426 | JSCell* m_linkTimeConstants[LinkTimeConstantCount]; |
427 | |
428 | String m_name; |
429 | |
430 | Debugger* m_debugger; |
431 | |
432 | VM& m_vm; |
433 | |
434 | #if ENABLE(REMOTE_INSPECTOR) |
435 | std::unique_ptr<Inspector::JSGlobalObjectInspectorController> m_inspectorController; |
436 | std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable; |
437 | #endif |
438 | |
439 | #if ENABLE(INTL) |
440 | HashSet<String> m_intlCollatorAvailableLocales; |
441 | HashSet<String> m_intlDateTimeFormatAvailableLocales; |
442 | HashSet<String> m_intlNumberFormatAvailableLocales; |
443 | HashSet<String> m_intlPluralRulesAvailableLocales; |
444 | #endif // ENABLE(INTL) |
445 | |
446 | RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint; |
447 | RefPtr<WatchpointSet> m_havingABadTimeWatchpoint; |
448 | RefPtr<WatchpointSet> m_varInjectionWatchpoint; |
449 | |
450 | std::unique_ptr<JSGlobalObjectRareData> m_rareData; |
451 | |
452 | WeakRandom m_weakRandom; |
453 | RegExpGlobalData m_regExpGlobalData; |
454 | |
455 | JSCallee* stackOverflowFrameCallee() const { return m_stackOverflowFrameCallee.get(); } |
456 | |
457 | InlineWatchpointSet& arrayIteratorProtocolWatchpoint() { return m_arrayIteratorProtocolWatchpoint; } |
458 | InlineWatchpointSet& mapIteratorProtocolWatchpoint() { return m_mapIteratorProtocolWatchpoint; } |
459 | InlineWatchpointSet& setIteratorProtocolWatchpoint() { return m_setIteratorProtocolWatchpoint; } |
460 | InlineWatchpointSet& stringIteratorProtocolWatchpoint() { return m_stringIteratorProtocolWatchpoint; } |
461 | InlineWatchpointSet& mapSetWatchpoint() { return m_mapSetWatchpoint; } |
462 | InlineWatchpointSet& setAddWatchpoint() { return m_setAddWatchpoint; } |
463 | InlineWatchpointSet& arraySpeciesWatchpoint() { return m_arraySpeciesWatchpoint; } |
464 | InlineWatchpointSet& numberToStringWatchpoint() |
465 | { |
466 | RELEASE_ASSERT(VM::canUseJIT()); |
467 | return m_numberToStringWatchpoint; |
468 | } |
469 | // If this hasn't been invalidated, it means the array iterator protocol |
470 | // is not observable to user code yet. |
471 | InlineWatchpointSet m_arrayIteratorProtocolWatchpoint; |
472 | InlineWatchpointSet m_mapIteratorProtocolWatchpoint; |
473 | InlineWatchpointSet m_setIteratorProtocolWatchpoint; |
474 | InlineWatchpointSet m_stringIteratorProtocolWatchpoint; |
475 | InlineWatchpointSet m_mapSetWatchpoint; |
476 | InlineWatchpointSet m_setAddWatchpoint; |
477 | InlineWatchpointSet m_arraySpeciesWatchpoint; |
478 | InlineWatchpointSet m_numberToStringWatchpoint; |
479 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayConstructorSpeciesWatchpoint; |
480 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeConstructorWatchpoint; |
481 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeSymbolIteratorWatchpoint; |
482 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayIteratorPrototypeNext; |
483 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSymbolIteratorWatchpoint; |
484 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapIteratorPrototypeNextWatchpoint; |
485 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeSymbolIteratorWatchpoint; |
486 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setIteratorPrototypeNextWatchpoint; |
487 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringPrototypeSymbolIteratorWatchpoint; |
488 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringIteratorPrototypeNextWatchpoint; |
489 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSetWatchpoint; |
490 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeAddWatchpoint; |
491 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_numberPrototypeToStringWatchpoint; |
492 | |
493 | bool isArrayPrototypeIteratorProtocolFastAndNonObservable(); |
494 | bool isMapPrototypeIteratorProtocolFastAndNonObservable(); |
495 | bool isSetPrototypeIteratorProtocolFastAndNonObservable(); |
496 | bool isStringPrototypeIteratorProtocolFastAndNonObservable(); |
497 | bool isMapPrototypeSetFastAndNonObservable(); |
498 | bool isSetPrototypeAddFastAndNonObservable(); |
499 | |
500 | #if ENABLE(DFG_JIT) |
501 | using ReferencedGlobalPropertyWatchpointSets = HashMap<RefPtr<UniquedStringImpl>, Ref<WatchpointSet>, IdentifierRepHash>; |
502 | ReferencedGlobalPropertyWatchpointSets m_referencedGlobalPropertyWatchpointSets; |
503 | ConcurrentJSLock m_referencedGlobalPropertyWatchpointSetsLock; |
504 | #endif |
505 | |
506 | bool m_evalEnabled { true }; |
507 | bool m_webAssemblyEnabled { true }; |
508 | unsigned m_globalLexicalBindingEpoch { 1 }; |
509 | String m_evalDisabledErrorMessage; |
510 | String m_webAssemblyDisabledErrorMessage; |
511 | RuntimeFlags m_runtimeFlags; |
512 | ConsoleClient* m_consoleClient { nullptr }; |
513 | Optional<unsigned> m_stackTraceLimit; |
514 | |
515 | #if !ASSERT_DISABLED |
516 | const ExecState* m_callFrameAtDebuggerEntry { nullptr }; |
517 | #endif |
518 | |
519 | static JS_EXPORT_PRIVATE const GlobalObjectMethodTable s_globalObjectMethodTable; |
520 | const GlobalObjectMethodTable* m_globalObjectMethodTable; |
521 | |
522 | void createRareDataIfNeeded() |
523 | { |
524 | if (m_rareData) |
525 | return; |
526 | m_rareData = std::make_unique<JSGlobalObjectRareData>(); |
527 | } |
528 | |
529 | public: |
530 | typedef JSSegmentedVariableObject Base; |
531 | static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable | OverridesGetOwnPropertySlot | OverridesGetPropertyNames | IsImmutablePrototypeExoticObject; |
532 | |
533 | JS_EXPORT_PRIVATE static JSGlobalObject* create(VM&, Structure*); |
534 | |
535 | DECLARE_EXPORT_INFO; |
536 | |
537 | bool hasDebugger() const; |
538 | bool hasInteractiveDebugger() const; |
539 | const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; } |
540 | |
541 | #if ENABLE(DFG_JIT) |
542 | WatchpointSet* getReferencedPropertyWatchpointSet(UniquedStringImpl*); |
543 | WatchpointSet& ensureReferencedPropertyWatchpointSet(UniquedStringImpl*); |
544 | #endif |
545 | |
546 | Optional<unsigned> stackTraceLimit() const { return m_stackTraceLimit; } |
547 | void setStackTraceLimit(Optional<unsigned> value) { m_stackTraceLimit = value; } |
548 | |
549 | protected: |
550 | JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = nullptr); |
551 | |
552 | JS_EXPORT_PRIVATE void finishCreation(VM&); |
553 | |
554 | JS_EXPORT_PRIVATE void finishCreation(VM&, JSObject*); |
555 | |
556 | void addGlobalVar(const Identifier&); |
557 | |
558 | public: |
559 | JS_EXPORT_PRIVATE ~JSGlobalObject(); |
560 | JS_EXPORT_PRIVATE static void destroy(JSCell*); |
561 | |
562 | JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&); |
563 | |
564 | JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&); |
565 | JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&); |
566 | |
567 | JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes); |
568 | JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes); |
569 | JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow); |
570 | |
571 | void addVar(ExecState* exec, const Identifier& propertyName) |
572 | { |
573 | if (!hasOwnProperty(exec, propertyName)) |
574 | addGlobalVar(propertyName); |
575 | } |
576 | void addFunction(ExecState*, const Identifier&); |
577 | |
578 | JSScope* globalScope() { return m_globalLexicalEnvironment.get(); } |
579 | JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); } |
580 | |
581 | JSScope* globalScopeExtension() { return m_globalScopeExtension.get(); } |
582 | void setGlobalScopeExtension(JSScope*); |
583 | void clearGlobalScopeExtension(); |
584 | |
585 | // The following accessors return pristine values, even if a script |
586 | // replaces the global object's associated property. |
587 | |
588 | GetterSetter* speciesGetterSetter() const { return m_speciesGetterSetter.get(); } |
589 | |
590 | ArrayConstructor* arrayConstructor() const { return m_arrayConstructor.get(); } |
591 | ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); } |
592 | JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); } |
593 | JSInternalPromiseConstructor* internalPromiseConstructor() const { return m_internalPromiseConstructor.get(); } |
594 | |
595 | #if ENABLE(INTL) |
596 | IntlCollator* defaultCollator(ExecState*); |
597 | #endif |
598 | |
599 | NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); } |
600 | NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); } |
601 | |
602 | JSFunction* parseIntFunction() const { return m_parseIntFunction.get(this); } |
603 | JSFunction* parseFloatFunction() const { return m_parseFloatFunction.get(this); } |
604 | |
605 | JSFunction* evalFunction() const { return m_evalFunction.get(this); } |
606 | JSFunction* callFunction() const { return m_callFunction.get(); } |
607 | JSFunction* applyFunction() const { return m_applyFunction.get(); } |
608 | JSFunction* throwTypeErrorFunction() const { return m_throwTypeErrorFunction.get(); } |
609 | JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); } |
610 | JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); } |
611 | JSFunction* initializePromiseFunction() const { return m_initializePromiseFunction.get(this); } |
612 | JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); } |
613 | JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); } |
614 | JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); } |
615 | JSFunction* numberProtoToStringFunction() const { return m_numberProtoToStringFunction.get(); } |
616 | JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); } |
617 | JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); } |
618 | JSObject* regExpProtoExecFunction() const { return m_regExpProtoExec.get(); } |
619 | JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); } |
620 | JSObject* regExpProtoGlobalGetter() const { return m_regExpProtoGlobalGetter.get(); } |
621 | JSObject* regExpProtoUnicodeGetter() const { return m_regExpProtoUnicodeGetter.get(); } |
622 | GetterSetter* throwTypeErrorArgumentsCalleeAndCallerGetterSetter() |
623 | { |
624 | return m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.get(); |
625 | } |
626 | |
627 | JSModuleLoader* moduleLoader() const { return m_moduleLoader.get(this); } |
628 | |
629 | ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); } |
630 | FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); } |
631 | ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); } |
632 | JSObject* booleanPrototype() const { return m_booleanObjectStructure.prototypeInitializedOnMainThread(this); } |
633 | StringPrototype* stringPrototype() const { return m_stringPrototype.get(); } |
634 | JSObject* numberPrototype() const { return m_numberObjectStructure.prototypeInitializedOnMainThread(this); } |
635 | BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); } |
636 | JSObject* datePrototype() const { return m_dateStructure.prototype(this); } |
637 | JSObject* symbolPrototype() const { return m_symbolObjectStructure.prototypeInitializedOnMainThread(this); } |
638 | RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); } |
639 | JSObject* errorPrototype() const { return m_errorStructure.prototype(this); } |
640 | IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); } |
641 | AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); } |
642 | GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); } |
643 | GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); } |
644 | AsyncFunctionPrototype* asyncFunctionPrototype() const { return m_asyncFunctionPrototype.get(); } |
645 | MapPrototype* mapPrototype() const { return m_mapPrototype.get(); } |
646 | // Workaround for the name conflict between JSCell::setPrototype. |
647 | SetPrototype* jsSetPrototype() const { return m_setPrototype.get(); } |
648 | JSPromisePrototype* promisePrototype() const { return m_promisePrototype.get(); } |
649 | AsyncGeneratorPrototype* asyncGeneratorPrototype() const { return m_asyncGeneratorPrototype.get(); } |
650 | AsyncGeneratorFunctionPrototype* asyncGeneratorFunctionPrototype() const { return m_asyncGeneratorFunctionPrototype.get(); } |
651 | |
652 | Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(this); } |
653 | Structure* withScopeStructure() const { return m_withScopeStructure.get(this); } |
654 | Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(this); } |
655 | Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); } |
656 | Structure* moduleEnvironmentStructure() const { return m_moduleEnvironmentStructure.get(this); } |
657 | Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); } |
658 | Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); } |
659 | Structure* clonedArgumentsStructure() const { return m_clonedArgumentsStructure.get(); } |
660 | Structure* objectStructureForObjectConstructor() const { return m_objectStructureForObjectConstructor.get(); } |
661 | Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const |
662 | { |
663 | ASSERT(indexingType & IsArray); |
664 | return m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(indexingType)].get(); |
665 | } |
666 | Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const |
667 | { |
668 | ASSERT(indexingType & IsArray); |
669 | return m_arrayStructureForIndexingShapeDuringAllocation[arrayIndexFromIndexingType(indexingType)].get(); |
670 | } |
671 | Structure* arrayStructureForIndexingTypeDuringAllocation(ExecState* exec, IndexingType indexingType, JSValue newTarget) const |
672 | { |
673 | return InternalFunction::createSubclassStructure(exec, newTarget, arrayStructureForIndexingTypeDuringAllocation(indexingType)); |
674 | } |
675 | Structure* arrayStructureForProfileDuringAllocation(ExecState* exec, ArrayAllocationProfile* profile, JSValue newTarget) const |
676 | { |
677 | return arrayStructureForIndexingTypeDuringAllocation(exec, ArrayAllocationProfile::selectIndexingTypeFor(profile), newTarget); |
678 | } |
679 | |
680 | bool isOriginalArrayStructure(Structure* structure) |
681 | { |
682 | return originalArrayStructureForIndexingType(structure->indexingMode() | IsArray) == structure; |
683 | } |
684 | |
685 | Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(this); } |
686 | Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(this); } |
687 | Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(this); } |
688 | Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(this); } |
689 | #if JSC_OBJC_API_ENABLED |
690 | Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(this); } |
691 | Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(this); } |
692 | #endif |
693 | #ifdef JSC_GLIB_API_ENABLED |
694 | Structure* glibCallbackFunctionStructure() const { return m_glibCallbackFunctionStructure.get(this); } |
695 | Structure* glibWrapperObjectStructure() const { return m_glibWrapperObjectStructure.get(this); } |
696 | #endif |
697 | Structure* dateStructure() const { return m_dateStructure.get(this); } |
698 | Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(this); } |
699 | Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); } |
700 | Structure* errorStructure() const { return m_errorStructure.get(this); } |
701 | Structure* errorStructure(ErrorType errorType) const |
702 | { |
703 | switch (errorType) { |
704 | case ErrorType::Error: |
705 | return errorStructure(); |
706 | case ErrorType::EvalError: |
707 | return m_evalErrorStructure.get(this); |
708 | case ErrorType::RangeError: |
709 | return m_rangeErrorStructure.get(this); |
710 | case ErrorType::ReferenceError: |
711 | return m_referenceErrorStructure.get(this); |
712 | case ErrorType::SyntaxError: |
713 | return m_syntaxErrorStructure.get(this); |
714 | case ErrorType::TypeError: |
715 | return m_typeErrorStructure.get(this); |
716 | case ErrorType::URIError: |
717 | return m_URIErrorStructure.get(this); |
718 | } |
719 | ASSERT_NOT_REACHED(); |
720 | return nullptr; |
721 | } |
722 | Structure* calleeStructure() const { return m_calleeStructure.get(); } |
723 | Structure* hostFunctionStructure() const { return m_hostFunctionStructure.get(); } |
724 | |
725 | Structure* arrowFunctionStructure(bool isBuiltin) const |
726 | { |
727 | if (isBuiltin) |
728 | return m_builtinFunctions.arrowFunctionStructure.get(); |
729 | return m_ordinaryFunctions.arrowFunctionStructure.get(); |
730 | } |
731 | Structure* sloppyFunctionStructure(bool isBuiltin) const |
732 | { |
733 | if (isBuiltin) |
734 | return m_builtinFunctions.sloppyFunctionStructure.get(); |
735 | return m_ordinaryFunctions.sloppyFunctionStructure.get(); |
736 | } |
737 | Structure* strictFunctionStructure(bool isBuiltin) const |
738 | { |
739 | if (isBuiltin) |
740 | return m_builtinFunctions.strictFunctionStructure.get(); |
741 | return m_ordinaryFunctions.strictFunctionStructure.get(); |
742 | } |
743 | |
744 | Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(this); } |
745 | Structure* customGetterSetterFunctionStructure() const { return m_customGetterSetterFunctionStructure.get(this); } |
746 | Structure* getterSetterStructure() const { return m_getterSetterStructure.get(); } |
747 | Structure* nativeStdFunctionStructure() const { return m_nativeStdFunctionStructure.get(this); } |
748 | PropertyOffset functionNameOffset() const { return m_functionNameOffset; } |
749 | Structure* numberObjectStructure() const { return m_numberObjectStructure.get(this); } |
750 | Structure* mapStructure() const { return m_mapStructure.get(); } |
751 | Structure* regExpStructure() const { return m_regExpStructure.get(); } |
752 | Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); } |
753 | Structure* asyncFunctionStructure() const { return m_asyncFunctionStructure.get(); } |
754 | Structure* asyncGeneratorFunctionStructure() const { return m_asyncGeneratorFunctionStructure.get(); } |
755 | Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); } |
756 | Structure* bigIntObjectStructure() const { return m_bigIntObjectStructure.get(); } |
757 | Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(this); } |
758 | Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); } |
759 | Structure* regExpMatchesArrayWithGroupsStructure() const { return m_regExpMatchesArrayWithGroupsStructure.get(); } |
760 | Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(this); } |
761 | Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(this); } |
762 | Structure* proxyObjectStructure() const { return m_proxyObjectStructure.get(this); } |
763 | Structure* callableProxyObjectStructure() const { return m_callableProxyObjectStructure.get(this); } |
764 | Structure* proxyRevokeStructure() const { return m_proxyRevokeStructure.get(this); } |
765 | Structure* restParameterStructure() const { return arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); } |
766 | Structure* originalRestParameterStructure() const { return originalArrayStructureForIndexingType(ArrayWithContiguous); } |
767 | #if ENABLE(WEBASSEMBLY) |
768 | Structure* webAssemblyModuleRecordStructure() const { return m_webAssemblyModuleRecordStructure.get(this); } |
769 | Structure* webAssemblyFunctionStructure() const { return m_webAssemblyFunctionStructure.get(this); } |
770 | Structure* jsToWasmICCalleeStructure() const { return m_jsToWasmICCalleeStructure.get(this); } |
771 | Structure* webAssemblyWrapperFunctionStructure() const { return m_webAssemblyWrapperFunctionStructure.get(this); } |
772 | Structure* webAssemblyToJSCalleeStructure() const { return m_webAssemblyToJSCalleeStructure.get(this); } |
773 | #endif // ENABLE(WEBASSEMBLY) |
774 | #if ENABLE(INTL) |
775 | Structure* collatorStructure() { return m_collatorStructure.get(this); } |
776 | Structure* numberFormatStructure() { return m_numberFormatStructure.get(this); } |
777 | Structure* dateTimeFormatStructure() { return m_dateTimeFormatStructure.get(this); } |
778 | Structure* pluralRulesStructure() { return m_pluralRulesStructure.get(this); } |
779 | #endif // ENABLE(INTL) |
780 | |
781 | JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool); |
782 | JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const; |
783 | |
784 | RegExpGlobalData& regExpGlobalData() { return m_regExpGlobalData; } |
785 | static ptrdiff_t regExpGlobalDataOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_regExpGlobalData); } |
786 | |
787 | #if ENABLE(REMOTE_INSPECTOR) |
788 | Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); } |
789 | JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); } |
790 | #endif |
791 | |
792 | #if ENABLE(INTL) |
793 | const HashSet<String>& intlCollatorAvailableLocales(); |
794 | const HashSet<String>& intlDateTimeFormatAvailableLocales(); |
795 | const HashSet<String>& intlNumberFormatAvailableLocales(); |
796 | const HashSet<String>& intlPluralRulesAvailableLocales(); |
797 | #endif // ENABLE(INTL) |
798 | |
799 | void bumpGlobalLexicalBindingEpoch(VM&); |
800 | unsigned globalLexicalBindingEpoch() const { return m_globalLexicalBindingEpoch; } |
801 | static ptrdiff_t globalLexicalBindingEpochOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_globalLexicalBindingEpoch); } |
802 | unsigned* addressOfGlobalLexicalBindingEpoch() { return &m_globalLexicalBindingEpoch; } |
803 | |
804 | void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; } |
805 | ConsoleClient* consoleClient() const { return m_consoleClient; } |
806 | |
807 | void setName(const String&); |
808 | const String& name() const { return m_name; } |
809 | |
810 | JSObject* arrayBufferConstructor() const { return m_arrayBufferStructure.constructor(this); } |
811 | |
812 | JSObject* arrayBufferPrototype(ArrayBufferSharingMode sharingMode) const |
813 | { |
814 | switch (sharingMode) { |
815 | case ArrayBufferSharingMode::Default: |
816 | return m_arrayBufferStructure.prototype(this); |
817 | #if ENABLE(SHARED_ARRAY_BUFFER) |
818 | case ArrayBufferSharingMode::Shared: |
819 | return m_sharedArrayBufferPrototype.get(); |
820 | #else |
821 | default: |
822 | return m_arrayBufferStructure.prototype(this); |
823 | #endif |
824 | } |
825 | } |
826 | Structure* arrayBufferStructure(ArrayBufferSharingMode sharingMode) const |
827 | { |
828 | switch (sharingMode) { |
829 | case ArrayBufferSharingMode::Default: |
830 | return m_arrayBufferStructure.get(this); |
831 | #if ENABLE(SHARED_ARRAY_BUFFER) |
832 | case ArrayBufferSharingMode::Shared: |
833 | return m_sharedArrayBufferStructure.get(); |
834 | #else |
835 | default: |
836 | return m_arrayBufferStructure.get(this); |
837 | #endif |
838 | } |
839 | RELEASE_ASSERT_NOT_REACHED(); |
840 | return nullptr; |
841 | } |
842 | |
843 | #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \ |
844 | Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); } |
845 | |
846 | FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE) |
847 | FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE) |
848 | FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE) |
849 | |
850 | #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE |
851 | |
852 | #define DEFINE_ACCESSORS_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \ |
853 | Structure* properName ## Structure() { return m_ ## properName ## Structure.get(this); } \ |
854 | JSObject* properName ## Constructor() { return m_ ## properName ## Structure.constructor(this); } |
855 | |
856 | FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE) |
857 | FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE) |
858 | |
859 | #undef DEFINE_ACCESSORS_FOR_LAZY_TYPE |
860 | |
861 | LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) |
862 | { |
863 | switch (type) { |
864 | case NotTypedArray: |
865 | RELEASE_ASSERT_NOT_REACHED(); |
866 | return m_typedArrayInt8; |
867 | #define TYPED_ARRAY_TYPE_CASE(name) case Type ## name: return m_typedArray ## name; |
868 | FOR_EACH_TYPED_ARRAY_TYPE(TYPED_ARRAY_TYPE_CASE) |
869 | #undef TYPED_ARRAY_TYPE_CASE |
870 | } |
871 | RELEASE_ASSERT_NOT_REACHED(); |
872 | return m_typedArrayInt8; |
873 | } |
874 | const LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) const |
875 | { |
876 | return const_cast<const LazyClassStructure&>(const_cast<JSGlobalObject*>(this)->lazyTypedArrayStructure(type)); |
877 | } |
878 | |
879 | Structure* typedArrayStructure(TypedArrayType type) const |
880 | { |
881 | return lazyTypedArrayStructure(type).get(this); |
882 | } |
883 | Structure* typedArrayStructureConcurrently(TypedArrayType type) const |
884 | { |
885 | return lazyTypedArrayStructure(type).getConcurrently(); |
886 | } |
887 | bool isOriginalTypedArrayStructure(Structure* structure) |
888 | { |
889 | TypedArrayType type = structure->classInfo()->typedArrayStorageType; |
890 | if (type == NotTypedArray) |
891 | return false; |
892 | return typedArrayStructureConcurrently(type) == structure; |
893 | } |
894 | |
895 | JSObject* typedArrayConstructor(TypedArrayType type) const |
896 | { |
897 | return lazyTypedArrayStructure(type).constructor(this); |
898 | } |
899 | |
900 | JSCell* actualPointerFor(Special::Pointer pointer) |
901 | { |
902 | ASSERT(pointer < Special::TableSize); |
903 | return m_specialPointers[pointer]; |
904 | } |
905 | JSCell* jsCellForLinkTimeConstant(LinkTimeConstant type) |
906 | { |
907 | unsigned index = static_cast<unsigned>(type); |
908 | ASSERT(index < LinkTimeConstantCount); |
909 | return m_linkTimeConstants[index]; |
910 | } |
911 | |
912 | WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); } |
913 | WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); } |
914 | WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); } |
915 | |
916 | bool isHavingABadTime() const |
917 | { |
918 | return m_havingABadTimeWatchpoint->hasBeenInvalidated(); |
919 | } |
920 | |
921 | void haveABadTime(VM&); |
922 | |
923 | bool objectPrototypeIsSane(); |
924 | bool arrayPrototypeChainIsSane(); |
925 | bool stringPrototypeChainIsSane(); |
926 | |
927 | void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; } |
928 | unsigned profileGroup() const |
929 | { |
930 | if (!m_rareData) |
931 | return 0; |
932 | return m_rareData->profileGroup; |
933 | } |
934 | |
935 | Debugger* debugger() const { return m_debugger; } |
936 | void setDebugger(Debugger*); |
937 | |
938 | const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; } |
939 | |
940 | static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; } |
941 | |
942 | JS_EXPORT_PRIVATE ExecState* globalExec(); |
943 | |
944 | static bool shouldInterruptScript(const JSGlobalObject*) { return true; } |
945 | static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; } |
946 | static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); } |
947 | |
948 | JS_EXPORT_PRIVATE void queueMicrotask(Ref<Microtask>&&); |
949 | |
950 | bool evalEnabled() const { return m_evalEnabled; } |
951 | bool webAssemblyEnabled() const { return m_webAssemblyEnabled; } |
952 | const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; } |
953 | const String& webAssemblyDisabledErrorMessage() const { return m_webAssemblyDisabledErrorMessage; } |
954 | void setEvalEnabled(bool enabled, const String& errorMessage = String()) |
955 | { |
956 | m_evalEnabled = enabled; |
957 | m_evalDisabledErrorMessage = errorMessage; |
958 | } |
959 | void setWebAssemblyEnabled(bool enabled, const String& errorMessage = String()) |
960 | { |
961 | m_webAssemblyEnabled = enabled; |
962 | m_webAssemblyDisabledErrorMessage = errorMessage; |
963 | } |
964 | |
965 | #if !ASSERT_DISABLED |
966 | const ExecState* callFrameAtDebuggerEntry() const { return m_callFrameAtDebuggerEntry; } |
967 | void setCallFrameAtDebuggerEntry(const ExecState* callFrame) { m_callFrameAtDebuggerEntry = callFrame; } |
968 | #endif |
969 | |
970 | void resetPrototype(VM&, JSValue prototype); |
971 | |
972 | VM& vm() const { return m_vm; } |
973 | JSObject* globalThis() const; |
974 | WriteBarrier<JSObject>* addressOfGlobalThis() { return &m_globalThis; } |
975 | OptionSet<CodeGenerationMode> defaultCodeGenerationMode() const; |
976 | |
977 | static Structure* createStructure(VM& vm, JSValue prototype) |
978 | { |
979 | Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info()); |
980 | result->setTransitionWatchpointIsLikelyToBeFired(true); |
981 | return result; |
982 | } |
983 | |
984 | void registerWeakMap(OpaqueJSWeakObjectMap* map) |
985 | { |
986 | createRareDataIfNeeded(); |
987 | m_rareData->weakMaps.add(map); |
988 | } |
989 | |
990 | void unregisterWeakMap(OpaqueJSWeakObjectMap* map) |
991 | { |
992 | if (m_rareData) |
993 | m_rareData->weakMaps.remove(map); |
994 | } |
995 | |
996 | OpaqueJSClassDataMap& opaqueJSClassData() |
997 | { |
998 | createRareDataIfNeeded(); |
999 | return m_rareData->opaqueJSClassData; |
1000 | } |
1001 | |
1002 | static ptrdiff_t weakRandomOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_weakRandom); } |
1003 | double weakRandomNumber() { return m_weakRandom.get(); } |
1004 | unsigned weakRandomInteger() { return m_weakRandom.getUint32(); } |
1005 | WeakRandom& weakRandom() { return m_weakRandom; } |
1006 | |
1007 | bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; } |
1008 | JS_EXPORT_PRIVATE void exposeDollarVM(VM&); |
1009 | |
1010 | #if JSC_OBJC_API_ENABLED |
1011 | JSWrapperMap* wrapperMap() const { return m_wrapperMap.get(); } |
1012 | void setWrapperMap(JSWrapperMap* map) { m_wrapperMap = map; } |
1013 | void setAPIWrapper(void* apiWrapper) { m_apiWrapper = apiWrapper; } |
1014 | void* apiWrapper() const { return m_apiWrapper; } |
1015 | #endif |
1016 | #ifdef JSC_GLIB_API_ENABLED |
1017 | WrapperMap* wrapperMap() const { return m_wrapperMap.get(); } |
1018 | void setWrapperMap(std::unique_ptr<WrapperMap>&&); |
1019 | #endif |
1020 | |
1021 | void tryInstallArraySpeciesWatchpoint(ExecState*); |
1022 | |
1023 | protected: |
1024 | struct GlobalPropertyInfo { |
1025 | GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a) |
1026 | : identifier(i) |
1027 | , value(v) |
1028 | , attributes(a) |
1029 | { |
1030 | } |
1031 | |
1032 | const Identifier identifier; |
1033 | JSValue value; |
1034 | unsigned attributes; |
1035 | }; |
1036 | JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count); |
1037 | |
1038 | void setNeedsSiteSpecificQuirks(bool needQuirks) { m_needsSiteSpecificQuirks = needQuirks; } |
1039 | |
1040 | private: |
1041 | friend class LLIntOffsetsExtractor; |
1042 | |
1043 | void fireWatchpointAndMakeAllArrayStructuresSlowPut(VM&); |
1044 | void setGlobalThis(VM&, JSObject* globalThis); |
1045 | |
1046 | template<ErrorType errorType> |
1047 | void initializeErrorConstructor(LazyClassStructure::Initializer&); |
1048 | |
1049 | JS_EXPORT_PRIVATE void init(VM&); |
1050 | void fixupPrototypeChainWithObjectPrototype(VM&); |
1051 | |
1052 | JS_EXPORT_PRIVATE static void clearRareData(JSCell*); |
1053 | |
1054 | bool m_needsSiteSpecificQuirks { false }; |
1055 | #if JSC_OBJC_API_ENABLED |
1056 | RetainPtr<JSWrapperMap> m_wrapperMap; |
1057 | void* m_apiWrapper { nullptr }; |
1058 | #endif |
1059 | #ifdef JSC_GLIB_API_ENABLED |
1060 | std::unique_ptr<WrapperMap> m_wrapperMap; |
1061 | #endif |
1062 | }; |
1063 | |
1064 | inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0, JSValue newTarget = JSValue()) |
1065 | { |
1066 | VM& vm = globalObject->vm(); |
1067 | auto scope = DECLARE_THROW_SCOPE(vm); |
1068 | Structure* structure; |
1069 | if (initialLength >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH) |
1070 | structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(exec, ArrayWithArrayStorage, newTarget); |
1071 | else |
1072 | structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget); |
1073 | RETURN_IF_EXCEPTION(scope, nullptr); |
1074 | |
1075 | JSArray* result = JSArray::tryCreate(vm, structure, initialLength); |
1076 | if (UNLIKELY(!result)) { |
1077 | throwOutOfMemoryError(exec, scope); |
1078 | return nullptr; |
1079 | } |
1080 | return ArrayAllocationProfile::updateLastAllocationFor(profile, result); |
1081 | } |
1082 | |
1083 | inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0, JSValue newTarget = JSValue()) |
1084 | { |
1085 | return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength, newTarget); |
1086 | } |
1087 | |
1088 | inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values, JSValue newTarget = JSValue()) |
1089 | { |
1090 | VM& vm = globalObject->vm(); |
1091 | auto scope = DECLARE_THROW_SCOPE(vm); |
1092 | Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget); |
1093 | RETURN_IF_EXCEPTION(scope, nullptr); |
1094 | return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values)); |
1095 | } |
1096 | |
1097 | inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values, JSValue newTarget = JSValue()) |
1098 | { |
1099 | return constructArray(exec, profile, exec->lexicalGlobalObject(), values, newTarget); |
1100 | } |
1101 | |
1102 | inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue()) |
1103 | { |
1104 | VM& vm = globalObject->vm(); |
1105 | auto scope = DECLARE_THROW_SCOPE(vm); |
1106 | Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget); |
1107 | RETURN_IF_EXCEPTION(scope, nullptr); |
1108 | return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values, length)); |
1109 | } |
1110 | |
1111 | inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue()) |
1112 | { |
1113 | return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget); |
1114 | } |
1115 | |
1116 | inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue()) |
1117 | { |
1118 | VM& vm = globalObject->vm(); |
1119 | auto scope = DECLARE_THROW_SCOPE(vm); |
1120 | Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget); |
1121 | RETURN_IF_EXCEPTION(scope, nullptr); |
1122 | return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(exec, structure, values, length)); |
1123 | } |
1124 | |
1125 | inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue()) |
1126 | { |
1127 | return constructArrayNegativeIndexed(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget); |
1128 | } |
1129 | |
1130 | inline JSObject* ExecState::globalThisValue() const |
1131 | { |
1132 | return lexicalGlobalObject()->globalThis(); |
1133 | } |
1134 | |
1135 | inline JSObject* JSScope::globalThis() |
1136 | { |
1137 | return globalObject()->globalThis(); |
1138 | } |
1139 | |
1140 | inline JSObject* JSGlobalObject::globalThis() const |
1141 | { |
1142 | return m_globalThis.get(); |
1143 | } |
1144 | |
1145 | inline OptionSet<CodeGenerationMode> JSGlobalObject::defaultCodeGenerationMode() const |
1146 | { |
1147 | OptionSet<CodeGenerationMode> codeGenerationMode; |
1148 | if (hasInteractiveDebugger() || Options::forceDebuggerBytecodeGeneration()) |
1149 | codeGenerationMode.add(CodeGenerationMode::Debugger); |
1150 | if (m_vm.typeProfiler()) |
1151 | codeGenerationMode.add(CodeGenerationMode::TypeProfiler); |
1152 | if (m_vm.controlFlowProfiler()) |
1153 | codeGenerationMode.add(CodeGenerationMode::ControlFlowProfiler); |
1154 | return codeGenerationMode; |
1155 | } |
1156 | |
1157 | } // namespace JSC |
1158 | |