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 "GetVM.h" |
31 | #include "InternalFunction.h" |
32 | #include "JSArray.h" |
33 | #include "JSArrayBufferPrototype.h" |
34 | #include "JSClassRef.h" |
35 | #include "JSGlobalLexicalEnvironment.h" |
36 | #include "JSPromise.h" |
37 | #include "JSSegmentedVariableObject.h" |
38 | #include "JSWeakObjectMapRefInternal.h" |
39 | #include "LazyProperty.h" |
40 | #include "LazyClassStructure.h" |
41 | #include "NumberPrototype.h" |
42 | #include "ParserModes.h" |
43 | #include "RegExpGlobalData.h" |
44 | #include "RuntimeFlags.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 | enum class LinkTimeConstant : int32_t; |
122 | |
123 | #ifdef JSC_GLIB_API_ENABLED |
124 | class WrapperMap; |
125 | #endif |
126 | |
127 | template<typename Watchpoint> class ObjectPropertyChangeAdaptiveWatchpoint; |
128 | |
129 | constexpr bool typeExposedByDefault = true; |
130 | |
131 | #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName, object, typeExposedByDefault) |
132 | |
133 | #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \ |
134 | macro(String, string, stringObject, StringObject, String, object, typeExposedByDefault) \ |
135 | macro(JSPromise, promise, promise, JSPromise, Promise, object, typeExposedByDefault) \ |
136 | macro(BigInt, bigInt, bigIntObject, BigIntObject, BigInt, object, Options::useBigInt()) \ |
137 | macro(WeakObjectRef, weakObjectRef, weakObjectRef, JSWeakObjectRef, WeakRef, object, Options::useWeakRefs()) \ |
138 | |
139 | #define FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \ |
140 | macro(StringIterator, stringIterator, stringIterator, JSStringIterator, StringIterator, iterator, typeExposedByDefault) \ |
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, typeExposedByDefault) \ |
145 | |
146 | #define FOR_EACH_LAZY_BUILTIN_TYPE_WITH_DECLARATION(macro) \ |
147 | macro(Boolean, boolean, booleanObject, BooleanObject, Boolean, object, typeExposedByDefault) \ |
148 | macro(Date, date, date, DateInstance, Date, object, typeExposedByDefault) \ |
149 | macro(Error, error, error, ErrorInstance, Error, object, typeExposedByDefault) \ |
150 | macro(Map, map, map, JSMap, Map, object, typeExposedByDefault) \ |
151 | macro(Number, number, numberObject, NumberObject, Number, object, typeExposedByDefault) \ |
152 | macro(Set, set, set, JSSet, Set, object, typeExposedByDefault) \ |
153 | macro(Symbol, symbol, symbolObject, SymbolObject, Symbol, object, typeExposedByDefault) \ |
154 | DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \ |
155 | DEFINE_STANDARD_BUILTIN(macro, WeakSet, weakSet) \ |
156 | |
157 | #define FOR_EACH_LAZY_BUILTIN_TYPE(macro) \ |
158 | FOR_EACH_LAZY_BUILTIN_TYPE_WITH_DECLARATION(macro) \ |
159 | macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer, object, typeExposedByDefault) \ |
160 | |
161 | #if ENABLE(WEBASSEMBLY) |
162 | #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro) \ |
163 | macro(WebAssemblyCompileError, webAssemblyCompileError, webAssemblyCompileError, JSWebAssemblyCompileError, CompileError, error, typeExposedByDefault) \ |
164 | macro(WebAssemblyInstance, webAssemblyInstance, webAssemblyInstance, JSWebAssemblyInstance, Instance, object, typeExposedByDefault) \ |
165 | macro(WebAssemblyLinkError, webAssemblyLinkError, webAssemblyLinkError, JSWebAssemblyLinkError, LinkError, error, typeExposedByDefault) \ |
166 | macro(WebAssemblyMemory, webAssemblyMemory, webAssemblyMemory, JSWebAssemblyMemory, Memory, object, typeExposedByDefault) \ |
167 | macro(WebAssemblyModule, webAssemblyModule, webAssemblyModule, JSWebAssemblyModule, Module, object, typeExposedByDefault) \ |
168 | macro(WebAssemblyRuntimeError, webAssemblyRuntimeError, webAssemblyRuntimeError, JSWebAssemblyRuntimeError, RuntimeError, error, typeExposedByDefault) \ |
169 | macro(WebAssemblyTable, webAssemblyTable, webAssemblyTable, JSWebAssemblyTable, Table, object, typeExposedByDefault) |
170 | #else |
171 | #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro) |
172 | #endif // ENABLE(WEBASSEMBLY) |
173 | |
174 | #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \ |
175 | class JS ## capitalName; \ |
176 | class capitalName ## Prototype; \ |
177 | class capitalName ## Constructor; |
178 | |
179 | class IteratorPrototype; |
180 | FOR_EACH_SIMPLE_BUILTIN_TYPE(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*, JSModuleLoader*, JSString*, JSValue, const SourceOrigin&); |
209 | ModuleLoaderImportModulePtr moduleLoaderImportModule; |
210 | |
211 | typedef Identifier (*ModuleLoaderResolvePtr)(JSGlobalObject*, JSModuleLoader*, JSValue, JSValue, JSValue); |
212 | ModuleLoaderResolvePtr moduleLoaderResolve; |
213 | |
214 | typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, JSModuleLoader*, JSValue, JSValue, JSValue); |
215 | ModuleLoaderFetchPtr moduleLoaderFetch; |
216 | |
217 | typedef JSObject* (*ModuleLoaderCreateImportMetaPropertiesPtr)(JSGlobalObject*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue); |
218 | ModuleLoaderCreateImportMetaPropertiesPtr moduleLoaderCreateImportMetaProperties; |
219 | |
220 | typedef JSValue (*ModuleLoaderEvaluatePtr)(JSGlobalObject*, JSModuleLoader*, JSValue, JSValue, JSValue); |
221 | ModuleLoaderEvaluatePtr moduleLoaderEvaluate; |
222 | |
223 | typedef void (*PromiseRejectionTrackerPtr)(JSGlobalObject*, JSPromise*, JSPromiseRejectionOperation); |
224 | PromiseRejectionTrackerPtr promiseRejectionTracker; |
225 | |
226 | typedef String (*DefaultLanguageFunctionPtr)(); |
227 | DefaultLanguageFunctionPtr defaultLanguage; |
228 | |
229 | typedef void (*CompileStreamingPtr)(JSGlobalObject*, JSPromise*, JSValue); |
230 | CompileStreamingPtr compileStreaming; |
231 | |
232 | typedef void (*InstantiateStreamingPtr)(JSGlobalObject*, JSPromise*, 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 | // m_vm must be a pointer (instead of a reference) because the JSCLLIntOffsetsExtractor |
256 | // cannot handle it being a reference. |
257 | VM* m_vm; |
258 | |
259 | // Our hashtable code-generator tries to access these properties, so we make them public. |
260 | // However, we'd like it better if they could be protected. |
261 | public: |
262 | template<typename T> using Initializer = typename LazyProperty<JSGlobalObject, T>::Initializer; |
263 | |
264 | Register m_deprecatedCallFrameForDebugger[CallFrame::headerSizeInRegisters]; |
265 | |
266 | WriteBarrier<JSObject> m_globalThis; |
267 | |
268 | WriteBarrier<JSGlobalLexicalEnvironment> m_globalLexicalEnvironment; |
269 | WriteBarrier<JSScope> m_globalScopeExtension; |
270 | WriteBarrier<JSCallee> m_globalCallee; |
271 | WriteBarrier<JSCallee> m_stackOverflowFrameCallee; |
272 | |
273 | LazyClassStructure m_evalErrorStructure; |
274 | LazyClassStructure m_rangeErrorStructure; |
275 | LazyClassStructure m_referenceErrorStructure; |
276 | LazyClassStructure m_syntaxErrorStructure; |
277 | LazyClassStructure m_typeErrorStructure; |
278 | LazyClassStructure m_URIErrorStructure; |
279 | |
280 | WriteBarrier<ObjectConstructor> m_objectConstructor; |
281 | WriteBarrier<ArrayConstructor> m_arrayConstructor; |
282 | WriteBarrier<RegExpConstructor> m_regExpConstructor; |
283 | WriteBarrier<FunctionConstructor> m_functionConstructor; |
284 | WriteBarrier<JSPromiseConstructor> m_promiseConstructor; |
285 | WriteBarrier<JSInternalPromiseConstructor> m_internalPromiseConstructor; |
286 | |
287 | #if ENABLE(INTL) |
288 | LazyProperty<JSGlobalObject, IntlCollator> m_defaultCollator; |
289 | LazyProperty<JSGlobalObject, Structure> m_collatorStructure; |
290 | LazyProperty<JSGlobalObject, Structure> m_numberFormatStructure; |
291 | LazyProperty<JSGlobalObject, Structure> m_dateTimeFormatStructure; |
292 | LazyProperty<JSGlobalObject, Structure> m_pluralRulesStructure; |
293 | #endif |
294 | WriteBarrier<NullGetterFunction> m_nullGetterFunction; |
295 | WriteBarrier<NullSetterFunction> m_nullSetterFunction; |
296 | |
297 | LazyProperty<JSGlobalObject, JSFunction> m_parseIntFunction; |
298 | LazyProperty<JSGlobalObject, JSFunction> m_parseFloatFunction; |
299 | |
300 | LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoToStringFunction; |
301 | LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoValuesFunction; |
302 | LazyProperty<JSGlobalObject, JSFunction> m_evalFunction; |
303 | LazyProperty<JSGlobalObject, JSFunction> m_iteratorProtocolFunction; |
304 | LazyProperty<JSGlobalObject, JSFunction> m_promiseResolveFunction; |
305 | LazyProperty<JSGlobalObject, JSFunction> m_numberProtoToStringFunction; |
306 | WriteBarrier<JSFunction> m_objectProtoValueOfFunction; |
307 | WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction; |
308 | LazyProperty<JSGlobalObject, GetterSetter> m_throwTypeErrorGetterSetter; |
309 | WriteBarrier<JSObject> m_regExpProtoSymbolReplace; |
310 | WriteBarrier<GetterSetter> m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter; |
311 | |
312 | LazyProperty<JSGlobalObject, JSModuleLoader> m_moduleLoader; |
313 | |
314 | WriteBarrier<ObjectPrototype> m_objectPrototype; |
315 | WriteBarrier<FunctionPrototype> m_functionPrototype; |
316 | WriteBarrier<ArrayPrototype> m_arrayPrototype; |
317 | WriteBarrier<RegExpPrototype> m_regExpPrototype; |
318 | WriteBarrier<IteratorPrototype> m_iteratorPrototype; |
319 | WriteBarrier<AsyncIteratorPrototype> m_asyncIteratorPrototype; |
320 | WriteBarrier<GeneratorFunctionPrototype> m_generatorFunctionPrototype; |
321 | WriteBarrier<GeneratorPrototype> m_generatorPrototype; |
322 | WriteBarrier<AsyncGeneratorPrototype> m_asyncGeneratorPrototype; |
323 | |
324 | LazyProperty<JSGlobalObject, Structure> m_debuggerScopeStructure; |
325 | LazyProperty<JSGlobalObject, Structure> m_withScopeStructure; |
326 | LazyProperty<JSGlobalObject, Structure> m_strictEvalActivationStructure; |
327 | WriteBarrier<Structure> m_lexicalEnvironmentStructure; |
328 | LazyProperty<JSGlobalObject, Structure> m_moduleEnvironmentStructure; |
329 | WriteBarrier<Structure> m_directArgumentsStructure; |
330 | WriteBarrier<Structure> m_scopedArgumentsStructure; |
331 | WriteBarrier<Structure> m_clonedArgumentsStructure; |
332 | |
333 | WriteBarrier<Structure> m_objectStructureForObjectConstructor; |
334 | |
335 | // Lists the actual structures used for having these particular indexing shapes. |
336 | WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfArrayIndexingModes]; |
337 | // Lists the structures we should use during allocation for these particular indexing shapes. |
338 | // These structures will differ from the originals list above when we are having a bad time. |
339 | WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfArrayIndexingModes]; |
340 | |
341 | LazyProperty<JSGlobalObject, Structure> m_callbackConstructorStructure; |
342 | LazyProperty<JSGlobalObject, Structure> m_callbackFunctionStructure; |
343 | LazyProperty<JSGlobalObject, Structure> m_callbackObjectStructure; |
344 | #if JSC_OBJC_API_ENABLED |
345 | LazyProperty<JSGlobalObject, Structure> m_objcCallbackFunctionStructure; |
346 | LazyProperty<JSGlobalObject, Structure> m_objcWrapperObjectStructure; |
347 | #endif |
348 | #ifdef JSC_GLIB_API_ENABLED |
349 | LazyProperty<JSGlobalObject, Structure> m_glibCallbackFunctionStructure; |
350 | LazyProperty<JSGlobalObject, Structure> m_glibWrapperObjectStructure; |
351 | #endif |
352 | WriteBarrier<Structure> m_nullPrototypeObjectStructure; |
353 | WriteBarrier<Structure> m_calleeStructure; |
354 | |
355 | WriteBarrier<Structure> m_hostFunctionStructure; |
356 | |
357 | struct FunctionStructures { |
358 | WriteBarrier<Structure> arrowFunctionStructure; |
359 | WriteBarrier<Structure> sloppyFunctionStructure; |
360 | WriteBarrier<Structure> strictFunctionStructure; |
361 | }; |
362 | FunctionStructures m_builtinFunctions; |
363 | FunctionStructures m_ordinaryFunctions; |
364 | |
365 | LazyProperty<JSGlobalObject, Structure> m_boundFunctionStructure; |
366 | LazyProperty<JSGlobalObject, Structure> m_customGetterSetterFunctionStructure; |
367 | LazyProperty<JSGlobalObject, Structure> m_nativeStdFunctionStructure; |
368 | PropertyOffset m_functionNameOffset; |
369 | WriteBarrier<Structure> m_regExpStructure; |
370 | WriteBarrier<AsyncFunctionPrototype> m_asyncFunctionPrototype; |
371 | WriteBarrier<AsyncGeneratorFunctionPrototype> m_asyncGeneratorFunctionPrototype; |
372 | WriteBarrier<Structure> m_asyncFunctionStructure; |
373 | WriteBarrier<Structure> m_asyncGeneratorFunctionStructure; |
374 | WriteBarrier<Structure> m_generatorFunctionStructure; |
375 | WriteBarrier<Structure> m_generatorStructure; |
376 | WriteBarrier<Structure> m_asyncGeneratorStructure; |
377 | LazyProperty<JSGlobalObject, Structure> m_iteratorResultObjectStructure; |
378 | WriteBarrier<Structure> m_regExpMatchesArrayStructure; |
379 | LazyProperty<JSGlobalObject, Structure> m_moduleRecordStructure; |
380 | LazyProperty<JSGlobalObject, Structure> m_moduleNamespaceObjectStructure; |
381 | LazyProperty<JSGlobalObject, Structure> m_proxyObjectStructure; |
382 | LazyProperty<JSGlobalObject, Structure> m_callableProxyObjectStructure; |
383 | LazyProperty<JSGlobalObject, Structure> m_proxyRevokeStructure; |
384 | #if ENABLE(SHARED_ARRAY_BUFFER) |
385 | WriteBarrier<JSArrayBufferPrototype> m_sharedArrayBufferPrototype; |
386 | WriteBarrier<Structure> m_sharedArrayBufferStructure; |
387 | #endif |
388 | |
389 | #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \ |
390 | WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \ |
391 | WriteBarrier<Structure> m_ ## properName ## Structure; |
392 | |
393 | #define DEFINE_STORAGE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \ |
394 | LazyClassStructure m_ ## properName ## Structure; |
395 | |
396 | FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE) |
397 | FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE) |
398 | |
399 | #if ENABLE(WEBASSEMBLY) |
400 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyModuleRecordStructure; |
401 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyFunctionStructure; |
402 | LazyProperty<JSGlobalObject, Structure> m_jsToWasmICCalleeStructure; |
403 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyWrapperFunctionStructure; |
404 | LazyProperty<JSGlobalObject, Structure> m_webAssemblyToJSCalleeStructure; |
405 | FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE) |
406 | #endif // ENABLE(WEBASSEMBLY) |
407 | |
408 | FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE) |
409 | |
410 | #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE |
411 | #undef DEFINE_STORAGE_FOR_LAZY_TYPE |
412 | |
413 | WriteBarrier<GetterSetter> m_speciesGetterSetter; |
414 | |
415 | LazyProperty<JSGlobalObject, JSTypedArrayViewPrototype> m_typedArrayProto; |
416 | LazyProperty<JSGlobalObject, JSTypedArrayViewConstructor> m_typedArraySuperConstructor; |
417 | |
418 | #define DECLARE_TYPED_ARRAY_TYPE_STRUCTURE(name) LazyClassStructure m_typedArray ## name; |
419 | FOR_EACH_TYPED_ARRAY_TYPE(DECLARE_TYPED_ARRAY_TYPE_STRUCTURE) |
420 | #undef DECLARE_TYPED_ARRAY_TYPE_STRUCTURE |
421 | |
422 | Vector<LazyProperty<JSGlobalObject, JSCell>> m_linkTimeConstants; |
423 | |
424 | String m_name; |
425 | |
426 | Strong<JSObject> m_unhandledRejectionCallback; |
427 | |
428 | Debugger* m_debugger; |
429 | |
430 | #if ENABLE(REMOTE_INSPECTOR) |
431 | std::unique_ptr<Inspector::JSGlobalObjectInspectorController> m_inspectorController; |
432 | std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable; |
433 | #endif |
434 | |
435 | #if ENABLE(INTL) |
436 | HashSet<String> m_intlCollatorAvailableLocales; |
437 | HashSet<String> m_intlDateTimeFormatAvailableLocales; |
438 | HashSet<String> m_intlNumberFormatAvailableLocales; |
439 | HashSet<String> m_intlPluralRulesAvailableLocales; |
440 | #endif // ENABLE(INTL) |
441 | |
442 | RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint; |
443 | RefPtr<WatchpointSet> m_havingABadTimeWatchpoint; |
444 | RefPtr<WatchpointSet> m_varInjectionWatchpoint; |
445 | |
446 | std::unique_ptr<JSGlobalObjectRareData> m_rareData; |
447 | |
448 | WeakRandom m_weakRandom; |
449 | RegExpGlobalData m_regExpGlobalData; |
450 | |
451 | JSCallee* stackOverflowFrameCallee() const { return m_stackOverflowFrameCallee.get(); } |
452 | |
453 | InlineWatchpointSet& arrayIteratorProtocolWatchpointSet() { return m_arrayIteratorProtocolWatchpointSet; } |
454 | InlineWatchpointSet& mapIteratorProtocolWatchpointSet() { return m_mapIteratorProtocolWatchpointSet; } |
455 | InlineWatchpointSet& setIteratorProtocolWatchpointSet() { return m_setIteratorProtocolWatchpointSet; } |
456 | InlineWatchpointSet& stringIteratorProtocolWatchpointSet() { return m_stringIteratorProtocolWatchpointSet; } |
457 | InlineWatchpointSet& mapSetWatchpointSet() { return m_mapSetWatchpointSet; } |
458 | InlineWatchpointSet& setAddWatchpointSet() { return m_setAddWatchpointSet; } |
459 | InlineWatchpointSet& arraySpeciesWatchpointSet() { return m_arraySpeciesWatchpointSet; } |
460 | InlineWatchpointSet& arrayJoinWatchpointSet() { return m_arrayJoinWatchpointSet; } |
461 | InlineWatchpointSet& numberToStringWatchpointSet() |
462 | { |
463 | RELEASE_ASSERT(VM::canUseJIT()); |
464 | return m_numberToStringWatchpointSet; |
465 | } |
466 | // If this hasn't been invalidated, it means the array iterator protocol |
467 | // is not observable to user code yet. |
468 | InlineWatchpointSet m_arrayIteratorProtocolWatchpointSet; |
469 | InlineWatchpointSet m_mapIteratorProtocolWatchpointSet; |
470 | InlineWatchpointSet m_setIteratorProtocolWatchpointSet; |
471 | InlineWatchpointSet m_stringIteratorProtocolWatchpointSet; |
472 | InlineWatchpointSet m_mapSetWatchpointSet; |
473 | InlineWatchpointSet m_setAddWatchpointSet; |
474 | InlineWatchpointSet m_arraySpeciesWatchpointSet; |
475 | InlineWatchpointSet m_arrayJoinWatchpointSet; |
476 | InlineWatchpointSet m_numberToStringWatchpointSet; |
477 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayConstructorSpeciesWatchpoint; |
478 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeConstructorWatchpoint; |
479 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeSymbolIteratorWatchpoint; |
480 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeJoinWatchpoint; |
481 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayIteratorPrototypeNext; |
482 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSymbolIteratorWatchpoint; |
483 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapIteratorPrototypeNextWatchpoint; |
484 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeSymbolIteratorWatchpoint; |
485 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setIteratorPrototypeNextWatchpoint; |
486 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringPrototypeSymbolIteratorWatchpoint; |
487 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringIteratorPrototypeNextWatchpoint; |
488 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSetWatchpoint; |
489 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeAddWatchpoint; |
490 | std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_numberPrototypeToStringWatchpoint; |
491 | |
492 | bool isArrayPrototypeIteratorProtocolFastAndNonObservable(); |
493 | bool isMapPrototypeIteratorProtocolFastAndNonObservable(); |
494 | bool isSetPrototypeIteratorProtocolFastAndNonObservable(); |
495 | bool isStringPrototypeIteratorProtocolFastAndNonObservable(); |
496 | bool isMapPrototypeSetFastAndNonObservable(); |
497 | bool isSetPrototypeAddFastAndNonObservable(); |
498 | |
499 | #if ENABLE(DFG_JIT) |
500 | using ReferencedGlobalPropertyWatchpointSets = HashMap<RefPtr<UniquedStringImpl>, Ref<WatchpointSet>, IdentifierRepHash>; |
501 | ReferencedGlobalPropertyWatchpointSets m_referencedGlobalPropertyWatchpointSets; |
502 | ConcurrentJSLock m_referencedGlobalPropertyWatchpointSetsLock; |
503 | #endif |
504 | |
505 | bool m_evalEnabled { true }; |
506 | bool m_webAssemblyEnabled { true }; |
507 | unsigned m_globalLexicalBindingEpoch { 1 }; |
508 | String m_evalDisabledErrorMessage; |
509 | String m_webAssemblyDisabledErrorMessage; |
510 | RuntimeFlags m_runtimeFlags; |
511 | ConsoleClient* m_consoleClient { nullptr }; |
512 | Optional<unsigned> m_stackTraceLimit; |
513 | |
514 | #if !ASSERT_DISABLED |
515 | const JSGlobalObject* m_globalObjectAtDebuggerEntry { nullptr }; |
516 | #endif |
517 | |
518 | static JS_EXPORT_PRIVATE const GlobalObjectMethodTable s_globalObjectMethodTable; |
519 | const GlobalObjectMethodTable* m_globalObjectMethodTable; |
520 | |
521 | void createRareDataIfNeeded() |
522 | { |
523 | if (m_rareData) |
524 | return; |
525 | m_rareData = makeUnique<JSGlobalObjectRareData>(); |
526 | } |
527 | |
528 | public: |
529 | typedef JSSegmentedVariableObject Base; |
530 | static constexpr unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable | OverridesGetOwnPropertySlot | OverridesGetPropertyNames | IsImmutablePrototypeExoticObject; |
531 | |
532 | JS_EXPORT_PRIVATE static JSGlobalObject* create(VM&, Structure*); |
533 | |
534 | DECLARE_EXPORT_INFO; |
535 | |
536 | bool hasDebugger() const; |
537 | bool hasInteractiveDebugger() const; |
538 | const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; } |
539 | |
540 | #if ENABLE(DFG_JIT) |
541 | WatchpointSet* getReferencedPropertyWatchpointSet(UniquedStringImpl*); |
542 | WatchpointSet& ensureReferencedPropertyWatchpointSet(UniquedStringImpl*); |
543 | #endif |
544 | |
545 | Optional<unsigned> stackTraceLimit() const { return m_stackTraceLimit; } |
546 | void setStackTraceLimit(Optional<unsigned> value) { m_stackTraceLimit = value; } |
547 | |
548 | protected: |
549 | JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = nullptr); |
550 | |
551 | JS_EXPORT_PRIVATE void finishCreation(VM&); |
552 | |
553 | JS_EXPORT_PRIVATE void finishCreation(VM&, JSObject*); |
554 | |
555 | void addGlobalVar(const Identifier&); |
556 | |
557 | public: |
558 | JS_EXPORT_PRIVATE ~JSGlobalObject(); |
559 | JS_EXPORT_PRIVATE static void destroy(JSCell*); |
560 | |
561 | JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&); |
562 | |
563 | JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, JSGlobalObject*, PropertyName, PropertySlot&); |
564 | JS_EXPORT_PRIVATE static bool put(JSCell*, JSGlobalObject*, PropertyName, JSValue, PutPropertySlot&); |
565 | |
566 | JS_EXPORT_PRIVATE static void defineGetter(JSObject*, JSGlobalObject*, PropertyName, JSObject* getterFunc, unsigned attributes); |
567 | JS_EXPORT_PRIVATE static void defineSetter(JSObject*, JSGlobalObject*, PropertyName, JSObject* setterFunc, unsigned attributes); |
568 | JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool shouldThrow); |
569 | |
570 | void addVar(JSGlobalObject* globalObject, const Identifier& propertyName) |
571 | { |
572 | if (!hasOwnProperty(globalObject, propertyName)) |
573 | addGlobalVar(propertyName); |
574 | } |
575 | void addFunction(JSGlobalObject*, const Identifier&); |
576 | |
577 | JSScope* globalScope() { return m_globalLexicalEnvironment.get(); } |
578 | JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); } |
579 | |
580 | JSScope* globalScopeExtension() { return m_globalScopeExtension.get(); } |
581 | void setGlobalScopeExtension(JSScope*); |
582 | void clearGlobalScopeExtension(); |
583 | |
584 | // The following accessors return pristine values, even if a script |
585 | // replaces the global object's associated property. |
586 | |
587 | GetterSetter* speciesGetterSetter() const { return m_speciesGetterSetter.get(); } |
588 | |
589 | ArrayConstructor* arrayConstructor() const { return m_arrayConstructor.get(); } |
590 | RegExpConstructor* regExpConstructor() const { return m_regExpConstructor.get(); } |
591 | ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); } |
592 | FunctionConstructor* functionConstructor() const { return m_functionConstructor.get(); } |
593 | JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); } |
594 | JSInternalPromiseConstructor* internalPromiseConstructor() const { return m_internalPromiseConstructor.get(); } |
595 | |
596 | #if ENABLE(INTL) |
597 | IntlCollator* defaultCollator() const { return m_defaultCollator.get(this); } |
598 | #endif |
599 | |
600 | NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); } |
601 | NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); } |
602 | |
603 | JSFunction* parseIntFunction() const { return m_parseIntFunction.get(this); } |
604 | JSFunction* parseFloatFunction() const { return m_parseFloatFunction.get(this); } |
605 | |
606 | JSFunction* evalFunction() const { return m_evalFunction.get(this); } |
607 | JSFunction* throwTypeErrorFunction() const; |
608 | JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); } |
609 | JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); } |
610 | JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); } |
611 | JSFunction* newPromiseCapabilityFunction() const; |
612 | JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); } |
613 | JSFunction* resolvePromiseFunction() const; |
614 | JSFunction* rejectPromiseFunction() const; |
615 | JSFunction* promiseProtoThenFunction() const; |
616 | JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); } |
617 | JSFunction* numberProtoToStringFunction() const { return m_numberProtoToStringFunction.getInitializedOnMainThread(this); } |
618 | JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); } |
619 | JSFunction* regExpProtoExecFunction() const; |
620 | JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); } |
621 | GetterSetter* regExpProtoGlobalGetter() const; |
622 | GetterSetter* regExpProtoUnicodeGetter() const; |
623 | GetterSetter* throwTypeErrorArgumentsCalleeAndCallerGetterSetter() |
624 | { |
625 | return m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.get(); |
626 | } |
627 | |
628 | JSModuleLoader* moduleLoader() const { return m_moduleLoader.get(this); } |
629 | |
630 | ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); } |
631 | FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); } |
632 | ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); } |
633 | JSObject* booleanPrototype() const { return m_booleanObjectStructure.prototypeInitializedOnMainThread(this); } |
634 | StringPrototype* stringPrototype() const { return m_stringPrototype.get(); } |
635 | JSObject* numberPrototype() const { return m_numberObjectStructure.prototypeInitializedOnMainThread(this); } |
636 | BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); } |
637 | JSObject* datePrototype() const { return m_dateStructure.prototype(this); } |
638 | JSObject* symbolPrototype() const { return m_symbolObjectStructure.prototypeInitializedOnMainThread(this); } |
639 | RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); } |
640 | JSObject* errorPrototype() const { return m_errorStructure.prototype(this); } |
641 | IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); } |
642 | AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); } |
643 | GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); } |
644 | GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); } |
645 | AsyncFunctionPrototype* asyncFunctionPrototype() const { return m_asyncFunctionPrototype.get(); } |
646 | JSObject* mapPrototype() const { return m_mapStructure.prototype(this); } |
647 | // Workaround for the name conflict between JSCell::setPrototype. |
648 | JSObject* jsSetPrototype() const { return m_setStructure.prototype(this); } |
649 | JSPromisePrototype* promisePrototype() const { return m_promisePrototype.get(); } |
650 | AsyncGeneratorPrototype* asyncGeneratorPrototype() const { return m_asyncGeneratorPrototype.get(); } |
651 | AsyncGeneratorFunctionPrototype* asyncGeneratorFunctionPrototype() const { return m_asyncGeneratorFunctionPrototype.get(); } |
652 | |
653 | Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(this); } |
654 | Structure* withScopeStructure() const { return m_withScopeStructure.get(this); } |
655 | Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(this); } |
656 | Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); } |
657 | Structure* moduleEnvironmentStructure() const { return m_moduleEnvironmentStructure.get(this); } |
658 | Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); } |
659 | Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); } |
660 | Structure* clonedArgumentsStructure() const { return m_clonedArgumentsStructure.get(); } |
661 | Structure* objectStructureForObjectConstructor() const { return m_objectStructureForObjectConstructor.get(); } |
662 | Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const |
663 | { |
664 | ASSERT(indexingType & IsArray); |
665 | return m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(indexingType)].get(); |
666 | } |
667 | Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const |
668 | { |
669 | ASSERT(indexingType & IsArray); |
670 | return m_arrayStructureForIndexingShapeDuringAllocation[arrayIndexFromIndexingType(indexingType)].get(); |
671 | } |
672 | Structure* arrayStructureForIndexingTypeDuringAllocation(JSGlobalObject* globalObject, IndexingType indexingType, JSValue newTarget) const; |
673 | Structure* arrayStructureForProfileDuringAllocation(JSGlobalObject* globalObject, ArrayAllocationProfile* profile, JSValue newTarget) const |
674 | { |
675 | return arrayStructureForIndexingTypeDuringAllocation(globalObject, ArrayAllocationProfile::selectIndexingTypeFor(profile), newTarget); |
676 | } |
677 | |
678 | bool isOriginalArrayStructure(Structure* structure) |
679 | { |
680 | return originalArrayStructureForIndexingType(structure->indexingMode() | IsArray) == structure; |
681 | } |
682 | |
683 | Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(this); } |
684 | Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(this); } |
685 | Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(this); } |
686 | Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(this); } |
687 | #if JSC_OBJC_API_ENABLED |
688 | Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(this); } |
689 | Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(this); } |
690 | #endif |
691 | #ifdef JSC_GLIB_API_ENABLED |
692 | Structure* glibCallbackFunctionStructure() const { return m_glibCallbackFunctionStructure.get(this); } |
693 | Structure* glibWrapperObjectStructure() const { return m_glibWrapperObjectStructure.get(this); } |
694 | #endif |
695 | Structure* dateStructure() const { return m_dateStructure.get(this); } |
696 | Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(this); } |
697 | Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); } |
698 | Structure* errorStructure() const { return m_errorStructure.get(this); } |
699 | Structure* errorStructure(ErrorType errorType) const |
700 | { |
701 | switch (errorType) { |
702 | case ErrorType::Error: |
703 | return errorStructure(); |
704 | case ErrorType::EvalError: |
705 | return m_evalErrorStructure.get(this); |
706 | case ErrorType::RangeError: |
707 | return m_rangeErrorStructure.get(this); |
708 | case ErrorType::ReferenceError: |
709 | return m_referenceErrorStructure.get(this); |
710 | case ErrorType::SyntaxError: |
711 | return m_syntaxErrorStructure.get(this); |
712 | case ErrorType::TypeError: |
713 | return m_typeErrorStructure.get(this); |
714 | case ErrorType::URIError: |
715 | return m_URIErrorStructure.get(this); |
716 | } |
717 | ASSERT_NOT_REACHED(); |
718 | return nullptr; |
719 | } |
720 | Structure* calleeStructure() const { return m_calleeStructure.get(); } |
721 | Structure* hostFunctionStructure() const { return m_hostFunctionStructure.get(); } |
722 | |
723 | Structure* arrowFunctionStructure(bool isBuiltin) const |
724 | { |
725 | if (isBuiltin) |
726 | return m_builtinFunctions.arrowFunctionStructure.get(); |
727 | return m_ordinaryFunctions.arrowFunctionStructure.get(); |
728 | } |
729 | Structure* sloppyFunctionStructure(bool isBuiltin) const |
730 | { |
731 | if (isBuiltin) |
732 | return m_builtinFunctions.sloppyFunctionStructure.get(); |
733 | return m_ordinaryFunctions.sloppyFunctionStructure.get(); |
734 | } |
735 | Structure* strictFunctionStructure(bool isBuiltin) const |
736 | { |
737 | if (isBuiltin) |
738 | return m_builtinFunctions.strictFunctionStructure.get(); |
739 | return m_ordinaryFunctions.strictFunctionStructure.get(); |
740 | } |
741 | |
742 | Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(this); } |
743 | Structure* customGetterSetterFunctionStructure() const { return m_customGetterSetterFunctionStructure.get(this); } |
744 | Structure* nativeStdFunctionStructure() const { return m_nativeStdFunctionStructure.get(this); } |
745 | PropertyOffset functionNameOffset() const { return m_functionNameOffset; } |
746 | Structure* numberObjectStructure() const { return m_numberObjectStructure.get(this); } |
747 | Structure* regExpStructure() const { return m_regExpStructure.get(); } |
748 | Structure* generatorStructure() const { return m_generatorStructure.get(); } |
749 | Structure* asyncGeneratorStructure() const { return m_asyncGeneratorStructure.get(); } |
750 | Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); } |
751 | Structure* asyncFunctionStructure() const { return m_asyncFunctionStructure.get(); } |
752 | Structure* asyncGeneratorFunctionStructure() const { return m_asyncGeneratorFunctionStructure.get(); } |
753 | Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); } |
754 | Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(this); } |
755 | Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); } |
756 | Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(this); } |
757 | Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(this); } |
758 | Structure* proxyObjectStructure() const { return m_proxyObjectStructure.get(this); } |
759 | Structure* callableProxyObjectStructure() const { return m_callableProxyObjectStructure.get(this); } |
760 | Structure* proxyRevokeStructure() const { return m_proxyRevokeStructure.get(this); } |
761 | Structure* restParameterStructure() const { return arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); } |
762 | Structure* originalRestParameterStructure() const { return originalArrayStructureForIndexingType(ArrayWithContiguous); } |
763 | #if ENABLE(WEBASSEMBLY) |
764 | Structure* webAssemblyModuleRecordStructure() const { return m_webAssemblyModuleRecordStructure.get(this); } |
765 | Structure* webAssemblyFunctionStructure() const { return m_webAssemblyFunctionStructure.get(this); } |
766 | Structure* jsToWasmICCalleeStructure() const { return m_jsToWasmICCalleeStructure.get(this); } |
767 | Structure* webAssemblyWrapperFunctionStructure() const { return m_webAssemblyWrapperFunctionStructure.get(this); } |
768 | Structure* webAssemblyToJSCalleeStructure() const { return m_webAssemblyToJSCalleeStructure.get(this); } |
769 | #endif // ENABLE(WEBASSEMBLY) |
770 | #if ENABLE(INTL) |
771 | Structure* collatorStructure() { return m_collatorStructure.get(this); } |
772 | Structure* numberFormatStructure() { return m_numberFormatStructure.get(this); } |
773 | Structure* dateTimeFormatStructure() { return m_dateTimeFormatStructure.get(this); } |
774 | Structure* pluralRulesStructure() { return m_pluralRulesStructure.get(this); } |
775 | #endif // ENABLE(INTL) |
776 | |
777 | JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool); |
778 | JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const; |
779 | |
780 | RegExpGlobalData& regExpGlobalData() { return m_regExpGlobalData; } |
781 | static ptrdiff_t regExpGlobalDataOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_regExpGlobalData); } |
782 | |
783 | #if ENABLE(REMOTE_INSPECTOR) |
784 | Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); } |
785 | JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); } |
786 | #endif |
787 | |
788 | #if ENABLE(INTL) |
789 | const HashSet<String>& intlCollatorAvailableLocales(); |
790 | const HashSet<String>& intlDateTimeFormatAvailableLocales(); |
791 | const HashSet<String>& intlNumberFormatAvailableLocales(); |
792 | const HashSet<String>& intlPluralRulesAvailableLocales(); |
793 | #endif // ENABLE(INTL) |
794 | |
795 | void bumpGlobalLexicalBindingEpoch(VM&); |
796 | unsigned globalLexicalBindingEpoch() const { return m_globalLexicalBindingEpoch; } |
797 | static ptrdiff_t globalLexicalBindingEpochOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_globalLexicalBindingEpoch); } |
798 | unsigned* addressOfGlobalLexicalBindingEpoch() { return &m_globalLexicalBindingEpoch; } |
799 | |
800 | void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; } |
801 | ConsoleClient* consoleClient() const { return m_consoleClient; } |
802 | |
803 | void setName(const String&); |
804 | const String& name() const { return m_name; } |
805 | |
806 | void setUnhandledRejectionCallback(VM& vm, JSObject* function) { m_unhandledRejectionCallback.set(vm, function); } |
807 | JSObject* unhandledRejectionCallback() const { return m_unhandledRejectionCallback.get(); } |
808 | |
809 | JSObject* arrayBufferConstructor() const { return m_arrayBufferStructure.constructor(this); } |
810 | |
811 | JSObject* arrayBufferPrototype(ArrayBufferSharingMode sharingMode) const |
812 | { |
813 | switch (sharingMode) { |
814 | case ArrayBufferSharingMode::Default: |
815 | return m_arrayBufferStructure.prototype(this); |
816 | #if ENABLE(SHARED_ARRAY_BUFFER) |
817 | case ArrayBufferSharingMode::Shared: |
818 | return m_sharedArrayBufferPrototype.get(); |
819 | #else |
820 | default: |
821 | return m_arrayBufferStructure.prototype(this); |
822 | #endif |
823 | } |
824 | } |
825 | Structure* arrayBufferStructure(ArrayBufferSharingMode sharingMode) const |
826 | { |
827 | switch (sharingMode) { |
828 | case ArrayBufferSharingMode::Default: |
829 | return m_arrayBufferStructure.get(this); |
830 | #if ENABLE(SHARED_ARRAY_BUFFER) |
831 | case ArrayBufferSharingMode::Shared: |
832 | return m_sharedArrayBufferStructure.get(); |
833 | #else |
834 | default: |
835 | return m_arrayBufferStructure.get(this); |
836 | #endif |
837 | } |
838 | RELEASE_ASSERT_NOT_REACHED(); |
839 | return nullptr; |
840 | } |
841 | |
842 | #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \ |
843 | Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); } |
844 | |
845 | FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE) |
846 | FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE) |
847 | |
848 | #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE |
849 | |
850 | #define DEFINE_ACCESSORS_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \ |
851 | Structure* properName ## Structure() { return m_ ## properName ## Structure.get(this); } \ |
852 | JSObject* properName ## Constructor() { return m_ ## properName ## Structure.constructor(this); } |
853 | |
854 | FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE) |
855 | FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE) |
856 | |
857 | #undef DEFINE_ACCESSORS_FOR_LAZY_TYPE |
858 | |
859 | LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) |
860 | { |
861 | switch (type) { |
862 | case NotTypedArray: |
863 | RELEASE_ASSERT_NOT_REACHED(); |
864 | return m_typedArrayInt8; |
865 | #define TYPED_ARRAY_TYPE_CASE(name) case Type ## name: return m_typedArray ## name; |
866 | FOR_EACH_TYPED_ARRAY_TYPE(TYPED_ARRAY_TYPE_CASE) |
867 | #undef TYPED_ARRAY_TYPE_CASE |
868 | } |
869 | RELEASE_ASSERT_NOT_REACHED(); |
870 | return m_typedArrayInt8; |
871 | } |
872 | const LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) const |
873 | { |
874 | return const_cast<const LazyClassStructure&>(const_cast<JSGlobalObject*>(this)->lazyTypedArrayStructure(type)); |
875 | } |
876 | |
877 | Structure* typedArrayStructure(TypedArrayType type) const |
878 | { |
879 | return lazyTypedArrayStructure(type).get(this); |
880 | } |
881 | Structure* typedArrayStructureConcurrently(TypedArrayType type) const |
882 | { |
883 | return lazyTypedArrayStructure(type).getConcurrently(); |
884 | } |
885 | bool isOriginalTypedArrayStructure(Structure* structure) |
886 | { |
887 | TypedArrayType type = structure->classInfo()->typedArrayStorageType; |
888 | if (type == NotTypedArray) |
889 | return false; |
890 | return typedArrayStructureConcurrently(type) == structure; |
891 | } |
892 | |
893 | JSObject* typedArrayConstructor(TypedArrayType type) const |
894 | { |
895 | return lazyTypedArrayStructure(type).constructor(this); |
896 | } |
897 | |
898 | JSCell* linkTimeConstant(LinkTimeConstant value) const |
899 | { |
900 | JSCell* result = m_linkTimeConstants[static_cast<unsigned>(value)].getInitializedOnMainThread(this); |
901 | ASSERT(result); |
902 | return result; |
903 | } |
904 | |
905 | WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); } |
906 | WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); } |
907 | WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); } |
908 | |
909 | bool isHavingABadTime() const |
910 | { |
911 | return m_havingABadTimeWatchpoint->hasBeenInvalidated(); |
912 | } |
913 | |
914 | void haveABadTime(VM&); |
915 | |
916 | bool objectPrototypeIsSane(); |
917 | bool arrayPrototypeChainIsSane(); |
918 | bool stringPrototypeChainIsSane(); |
919 | |
920 | void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; } |
921 | unsigned profileGroup() const |
922 | { |
923 | if (!m_rareData) |
924 | return 0; |
925 | return m_rareData->profileGroup; |
926 | } |
927 | |
928 | Debugger* debugger() const { return m_debugger; } |
929 | void setDebugger(Debugger*); |
930 | |
931 | const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; } |
932 | |
933 | JS_EXPORT_PRIVATE CallFrame* deprecatedCallFrameForDebugger(); |
934 | |
935 | static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; } |
936 | |
937 | static bool shouldInterruptScript(const JSGlobalObject*) { return true; } |
938 | static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; } |
939 | static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); } |
940 | |
941 | JS_EXPORT_PRIVATE void queueMicrotask(Ref<Microtask>&&); |
942 | |
943 | bool evalEnabled() const { return m_evalEnabled; } |
944 | bool webAssemblyEnabled() const { return m_webAssemblyEnabled; } |
945 | const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; } |
946 | const String& webAssemblyDisabledErrorMessage() const { return m_webAssemblyDisabledErrorMessage; } |
947 | void setEvalEnabled(bool enabled, const String& errorMessage = String()) |
948 | { |
949 | m_evalEnabled = enabled; |
950 | m_evalDisabledErrorMessage = errorMessage; |
951 | } |
952 | void setWebAssemblyEnabled(bool enabled, const String& errorMessage = String()) |
953 | { |
954 | m_webAssemblyEnabled = enabled; |
955 | m_webAssemblyDisabledErrorMessage = errorMessage; |
956 | } |
957 | |
958 | #if !ASSERT_DISABLED |
959 | const JSGlobalObject* globalObjectAtDebuggerEntry() const { return m_globalObjectAtDebuggerEntry; } |
960 | void setGlobalObjectAtDebuggerEntry(const JSGlobalObject* globalObject) { m_globalObjectAtDebuggerEntry = globalObject; } |
961 | #endif |
962 | |
963 | void resetPrototype(VM&, JSValue prototype); |
964 | |
965 | VM& vm() const { return *m_vm; } |
966 | JSObject* globalThis() const; |
967 | WriteBarrier<JSObject>* addressOfGlobalThis() { return &m_globalThis; } |
968 | OptionSet<CodeGenerationMode> defaultCodeGenerationMode() const; |
969 | |
970 | static Structure* createStructure(VM& vm, JSValue prototype) |
971 | { |
972 | Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info()); |
973 | result->setTransitionWatchpointIsLikelyToBeFired(true); |
974 | return result; |
975 | } |
976 | |
977 | void registerWeakMap(OpaqueJSWeakObjectMap* map) |
978 | { |
979 | createRareDataIfNeeded(); |
980 | m_rareData->weakMaps.add(map); |
981 | } |
982 | |
983 | void unregisterWeakMap(OpaqueJSWeakObjectMap* map) |
984 | { |
985 | if (m_rareData) |
986 | m_rareData->weakMaps.remove(map); |
987 | } |
988 | |
989 | OpaqueJSClassDataMap& opaqueJSClassData() |
990 | { |
991 | createRareDataIfNeeded(); |
992 | return m_rareData->opaqueJSClassData; |
993 | } |
994 | |
995 | static ptrdiff_t weakRandomOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_weakRandom); } |
996 | double weakRandomNumber() { return m_weakRandom.get(); } |
997 | unsigned weakRandomInteger() { return m_weakRandom.getUint32(); } |
998 | WeakRandom& weakRandom() { return m_weakRandom; } |
999 | |
1000 | bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; } |
1001 | JS_EXPORT_PRIVATE void exposeDollarVM(VM&); |
1002 | |
1003 | #if JSC_OBJC_API_ENABLED |
1004 | JSWrapperMap* wrapperMap() const { return m_wrapperMap.get(); } |
1005 | void setWrapperMap(JSWrapperMap* map) { m_wrapperMap = map; } |
1006 | #endif |
1007 | #ifdef JSC_GLIB_API_ENABLED |
1008 | WrapperMap* wrapperMap() const { return m_wrapperMap.get(); } |
1009 | void setWrapperMap(std::unique_ptr<WrapperMap>&&); |
1010 | #endif |
1011 | |
1012 | void tryInstallArraySpeciesWatchpoint(); |
1013 | void installNumberPrototypeWatchpoint(NumberPrototype*); |
1014 | void installMapPrototypeWatchpoint(MapPrototype*); |
1015 | void installSetPrototypeWatchpoint(SetPrototype*); |
1016 | |
1017 | protected: |
1018 | struct GlobalPropertyInfo { |
1019 | GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a) |
1020 | : identifier(i) |
1021 | , value(v) |
1022 | , attributes(a) |
1023 | { |
1024 | } |
1025 | |
1026 | const Identifier identifier; |
1027 | JSValue value; |
1028 | unsigned attributes; |
1029 | }; |
1030 | JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count); |
1031 | |
1032 | void setNeedsSiteSpecificQuirks(bool needQuirks) { m_needsSiteSpecificQuirks = needQuirks; } |
1033 | |
1034 | private: |
1035 | friend class LLIntOffsetsExtractor; |
1036 | |
1037 | void fireWatchpointAndMakeAllArrayStructuresSlowPut(VM&); |
1038 | void setGlobalThis(VM&, JSObject* globalThis); |
1039 | |
1040 | template<ErrorType errorType> |
1041 | void initializeErrorConstructor(LazyClassStructure::Initializer&); |
1042 | |
1043 | JS_EXPORT_PRIVATE void init(VM&); |
1044 | void fixupPrototypeChainWithObjectPrototype(VM&); |
1045 | |
1046 | JS_EXPORT_PRIVATE static void clearRareData(JSCell*); |
1047 | |
1048 | bool m_needsSiteSpecificQuirks { false }; |
1049 | #if JSC_OBJC_API_ENABLED |
1050 | RetainPtr<JSWrapperMap> m_wrapperMap; |
1051 | #endif |
1052 | #ifdef JSC_GLIB_API_ENABLED |
1053 | std::unique_ptr<WrapperMap> m_wrapperMap; |
1054 | #endif |
1055 | }; |
1056 | |
1057 | inline JSArray* constructEmptyArray(JSGlobalObject* globalObject, ArrayAllocationProfile* profile, unsigned initialLength = 0, JSValue newTarget = JSValue()) |
1058 | { |
1059 | VM& vm = getVM(globalObject); |
1060 | auto scope = DECLARE_THROW_SCOPE(vm); |
1061 | Structure* structure; |
1062 | if (initialLength >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH) |
1063 | structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(globalObject, ArrayWithArrayStorage, newTarget); |
1064 | else |
1065 | structure = globalObject->arrayStructureForProfileDuringAllocation(globalObject, profile, newTarget); |
1066 | RETURN_IF_EXCEPTION(scope, nullptr); |
1067 | |
1068 | JSArray* result = JSArray::tryCreate(vm, structure, initialLength); |
1069 | if (UNLIKELY(!result)) { |
1070 | throwOutOfMemoryError(globalObject, scope); |
1071 | return nullptr; |
1072 | } |
1073 | return ArrayAllocationProfile::updateLastAllocationFor(profile, result); |
1074 | } |
1075 | |
1076 | inline JSArray* constructArray(JSGlobalObject* globalObject, ArrayAllocationProfile* profile, const ArgList& values, JSValue newTarget = JSValue()) |
1077 | { |
1078 | VM& vm = getVM(globalObject); |
1079 | auto scope = DECLARE_THROW_SCOPE(vm); |
1080 | Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(globalObject, profile, newTarget); |
1081 | RETURN_IF_EXCEPTION(scope, nullptr); |
1082 | return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(globalObject, structure, values)); |
1083 | } |
1084 | |
1085 | inline JSArray* constructArray(JSGlobalObject* globalObject, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue()) |
1086 | { |
1087 | VM& vm = getVM(globalObject); |
1088 | auto scope = DECLARE_THROW_SCOPE(vm); |
1089 | Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(globalObject, profile, newTarget); |
1090 | RETURN_IF_EXCEPTION(scope, nullptr); |
1091 | return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(globalObject, structure, values, length)); |
1092 | } |
1093 | |
1094 | inline JSArray* constructArrayNegativeIndexed(JSGlobalObject* globalObject, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue()) |
1095 | { |
1096 | VM& vm = getVM(globalObject); |
1097 | auto scope = DECLARE_THROW_SCOPE(vm); |
1098 | Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(globalObject, profile, newTarget); |
1099 | RETURN_IF_EXCEPTION(scope, nullptr); |
1100 | return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(globalObject, structure, values, length)); |
1101 | } |
1102 | |
1103 | inline JSObject* JSScope::globalThis() |
1104 | { |
1105 | return globalObject()->globalThis(); |
1106 | } |
1107 | |
1108 | inline JSObject* JSGlobalObject::globalThis() const |
1109 | { |
1110 | return m_globalThis.get(); |
1111 | } |
1112 | |
1113 | inline OptionSet<CodeGenerationMode> JSGlobalObject::defaultCodeGenerationMode() const |
1114 | { |
1115 | OptionSet<CodeGenerationMode> codeGenerationMode; |
1116 | if (hasInteractiveDebugger() || Options::forceDebuggerBytecodeGeneration()) |
1117 | codeGenerationMode.add(CodeGenerationMode::Debugger); |
1118 | if (vm().typeProfiler()) |
1119 | codeGenerationMode.add(CodeGenerationMode::TypeProfiler); |
1120 | if (vm().controlFlowProfiler()) |
1121 | codeGenerationMode.add(CodeGenerationMode::ControlFlowProfiler); |
1122 | return codeGenerationMode; |
1123 | } |
1124 | |
1125 | } // namespace JSC |
1126 | |