1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_GLOBAL_ENV_H 17 #define ECMASCRIPT_GLOBAL_ENV_H 18 19 #include "ecmascript/js_global_object.h" 20 #include "ecmascript/js_function.h" 21 #include "ecmascript/lexical_env.h" 22 #include "ecmascript/js_handle.h" 23 #include "ecmascript/global_env_constants-inl.h" 24 25 namespace panda::ecmascript { 26 class JSThread; 27 28 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 29 #define GLOBAL_ENV_FIELDS(V) \ 30 /* Function */ \ 31 V(JSTaggedValue, ObjectFunction, OBJECT_FUNCTION_INDEX) \ 32 V(JSTaggedValue, ObjectFunctionClass, OBJECT_FUNCTION_CLASS_INDEX) \ 33 V(JSTaggedValue, ObjectFunctionPrototype, OBJECT_FUNCTION_PROTOTYPE_INDEX) \ 34 V(JSTaggedValue, ObjectFunctionPrototypeClass, OBJECT_FUNCTION_PROTOTYPE_CLASS_INDEX) \ 35 V(JSTaggedValue, FunctionFunction, FUNCTION_FUNCTION_INDEX) \ 36 V(JSTaggedValue, FunctionPrototype, FUNCTION_PROTOTYPE_INDEX) \ 37 V(JSTaggedValue, NumberFunction, NUMBER_FUNCTION_INDEX) \ 38 V(JSTaggedValue, BigIntFunction, BIGINT_FUNCTION_INDEX) \ 39 V(JSTaggedValue, DateFunction, DATE_FUNCTION_INDEX) \ 40 V(JSTaggedValue, BooleanFunction, BOOLEAN_FUNCTION_INDEX) \ 41 V(JSTaggedValue, ErrorFunction, ERROR_FUNCTION_INDEX) \ 42 V(JSTaggedValue, ArrayFunction, ARRAY_FUNCTION_INDEX) \ 43 V(JSTaggedValue, ArrayPrototype, ARRAY_PROTOTYPE_INDEX) \ 44 V(JSTaggedValue, TypedArrayFunction, TYPED_ARRAY_FUNCTION_INDEX) \ 45 V(JSTaggedValue, TypedArrayPrototype, TYPED_ARRAY_PROTOTYPE_INDEX) \ 46 V(JSTaggedValue, Int8ArrayFunction, INT8_ARRAY_FUNCTION_INDEX) \ 47 V(JSTaggedValue, Uint8ArrayFunction, UINT8_ARRAY_FUNCTION_INDEX) \ 48 V(JSTaggedValue, Uint8ClampedArrayFunction, UINT8_CLAMPED_ARRAY_FUNCTION_INDEX) \ 49 V(JSTaggedValue, Int16ArrayFunction, INT16_ARRAY_FUNCTION_INDEX) \ 50 V(JSTaggedValue, Uint16ArrayFunction, UINT16_ARRAY_FUNCTION_INDEX) \ 51 V(JSTaggedValue, Int32ArrayFunction, INT32_ARRAY_FUNCTION_INDEX) \ 52 V(JSTaggedValue, Uint32ArrayFunction, UINT32_ARRAY_FUNCTION_INDEX) \ 53 V(JSTaggedValue, Float32ArrayFunction, FLOAT32_ARRAY_FUNCTION_INDEX) \ 54 V(JSTaggedValue, Float64ArrayFunction, FLOAT64_ARRAY_FUNCTION_INDEX) \ 55 V(JSTaggedValue, BigInt64ArrayFunction, BIGINT64_ARRAY_FUNCTION_INDEX) \ 56 V(JSTaggedValue, BigUint64ArrayFunction, BIGUINT64_ARRAY_FUNCTION_INDEX) \ 57 V(JSTaggedValue, ArrayBufferFunction, ARRAY_BUFFER_FUNCTION_INDEX) \ 58 V(JSTaggedValue, SharedArrayBufferFunction, SHAREDARRAY_BUFFER_FUNCTION_INDEX) \ 59 V(JSTaggedValue, ArrayProtoValuesFunction, ARRAY_PROTO_VALUES_FUNCTION_INDEX) \ 60 V(JSTaggedValue, DataViewFunction, DATA_VIEW_FUNCTION_INDEX) \ 61 V(JSTaggedValue, SymbolFunction, SYMBOL_FUNCTION_INDEX) \ 62 V(JSTaggedValue, RangeErrorFunction, RANGE_ERROR_FUNCTION_INDEX) \ 63 V(JSTaggedValue, ReferenceErrorFunction, REFERENCE_ERROR_FUNCTION_INDEX) \ 64 V(JSTaggedValue, TypeErrorFunction, TYPE_ERROR_FUNCTION_INDEX) \ 65 V(JSTaggedValue, AggregateErrorFunction, AGGREGATE_ERROR_FUNCTION_INDEX) \ 66 V(JSTaggedValue, URIErrorFunction, URI_ERROR_FUNCTION_INDEX) \ 67 V(JSTaggedValue, SyntaxErrorFunction, SYNTAX_ERROR_FUNCTION_INDEX) \ 68 V(JSTaggedValue, EvalErrorFunction, EVAL_ERROR_FUNCTION_INDEX) \ 69 V(JSTaggedValue, OOMErrorFunction, OOM_ERROR_FUNCTION_INDEX) \ 70 V(JSTaggedValue, IntlFunction, INTL_FUNCTION_INDEX) \ 71 V(JSTaggedValue, LocaleFunction, LOCALE_FUNCTION_INDEX) \ 72 V(JSTaggedValue, DateTimeFormatFunction, DATE_TIME_FORMAT_FUNCTION_INDEX) \ 73 V(JSTaggedValue, RelativeTimeFormatFunction, RELATIVE_TIME_FORMAT_FUNCTION_INDEX) \ 74 V(JSTaggedValue, NumberFormatFunction, NUMBER_FORMAT_FUNCTION_INDEX) \ 75 V(JSTaggedValue, CollatorFunction, COLLATOR_FUNCTION_INDEX) \ 76 V(JSTaggedValue, PluralRulesFunction, PLURAL_RULES_FUNCTION_INDEX) \ 77 V(JSTaggedValue, DisplayNamesFunction, DISPLAY_NAMES_FUNCTION_INDEX) \ 78 V(JSTaggedValue, ListFormatFunction, LIST_FORMAT_FUNCTION_INDEX) \ 79 V(JSTaggedValue, RegExpFunction, REGEXP_FUNCTION_INDEX) \ 80 V(JSTaggedValue, BuiltinsSetFunction, BUILTINS_SET_FUNCTION_INDEX) \ 81 V(JSTaggedValue, SetPrototype, SET_PROTOTYPE_INDEX) \ 82 V(JSTaggedValue, BuiltinsMapFunction, BUILTINS_MAP_FUNCTION_INDEX) \ 83 V(JSTaggedValue, BuiltinsWeakMapFunction, BUILTINS_WEAK_MAP_FUNCTION_INDEX) \ 84 V(JSTaggedValue, BuiltinsWeakSetFunction, BUILTINS_WEAK_SET_FUNCTION_INDEX) \ 85 V(JSTaggedValue, BuiltinsWeakRefFunction, BUILTINS_WEAK_REF_FUNCTION_INDEX) \ 86 V(JSTaggedValue, BuiltinsFinalizationRegistryFunction, \ 87 BUILTINS_FINALIZATION_REGISTRY_FUNCTION_INDEX) \ 88 V(JSTaggedValue, MapPrototype, MAP_PROTOTYPE_INDEX) \ 89 V(JSTaggedValue, MathFunction, MATH_FUNCTION_INDEX) \ 90 V(JSTaggedValue, AtomicsFunction, ATOMICS_FUNCTION_INDEX) \ 91 V(JSTaggedValue, JsonFunction, JSON_FUNCTION_INDEX) \ 92 V(JSTaggedValue, StringFunction, STRING_FUNCTION_INDEX) \ 93 V(JSTaggedValue, ProxyFunction, PROXY_FUNCTION_INDEX) \ 94 V(JSTaggedValue, GeneratorFunctionFunction, GENERATOR_FUNCTION_OFFSET) \ 95 V(JSTaggedValue, GeneratorFunctionPrototype, GENERATOR_FUNCTION_PROTOTYPE_OFFSET) \ 96 V(JSTaggedValue, AsyncGeneratorFunctionFunction, ASYNC_GENERATOR_FUNCTION_OFFSET) \ 97 V(JSTaggedValue, AsyncGeneratorFunctionPrototype, ASYNC_GENERATOR_FUNCTION_PROTOTYPE_OFFSET) \ 98 V(JSTaggedValue, InitialGenerator, INITIAL_GENERATOR_OFFSET) \ 99 V(JSTaggedValue, InitialAsyncGenerator, INITIAL_ASYNC_GENERATOR_OFFSET) \ 100 V(JSTaggedValue, GeneratorPrototype, GENERATOR_PROTOTYPE_OFFSET) \ 101 V(JSTaggedValue, AsyncGeneratorPrototype, ASYNC_GENERATOR_PROTOTYPE_OFFSET) \ 102 V(JSTaggedValue, ReflectFunction, REFLECT_FUNCTION_INDEX) \ 103 V(JSTaggedValue, AsyncFunction, ASYNC_FUNCTION_INDEX) \ 104 V(JSTaggedValue, AsyncFunctionPrototype, ASYNC_FUNCTION_PROTOTYPE_INDEX) \ 105 V(JSTaggedValue, JSGlobalObject, JS_GLOBAL_OBJECT_INDEX) \ 106 V(JSTaggedValue, HasInstanceSymbol, HASINSTANCE_SYMBOL_INDEX) \ 107 V(JSTaggedValue, HasInstanceFunction, HASINSTANCE_FUNCTION_INDEX) \ 108 V(JSTaggedValue, IsConcatSpreadableSymbol, ISCONCAT_SYMBOL_INDEX) \ 109 V(JSTaggedValue, ToStringTagSymbol, TOSTRINGTAG_SYMBOL_INDEX) \ 110 V(JSTaggedValue, IteratorSymbol, ITERATOR_SYMBOL_INDEX) \ 111 V(JSTaggedValue, AsyncIteratorSymbol, ASYNC_ITERATOR_SYMBOL_INDEX) \ 112 V(JSTaggedValue, MatchSymbol, MATCH_SYMBOL_INDEX) \ 113 V(JSTaggedValue, MatchAllSymbol, MATCH_All_SYMBOL_INDEX) \ 114 V(JSTaggedValue, ReplaceSymbol, REPLACE_SYMBOL_INDEX) \ 115 V(JSTaggedValue, SearchSymbol, SEARCH_SYMBOL_INDEX) \ 116 V(JSTaggedValue, SpeciesSymbol, SPECIES_SYMBOL_INDEX) \ 117 V(JSTaggedValue, SplitSymbol, SPLIT_SYMBOL_INDEX) \ 118 V(JSTaggedValue, ToPrimitiveSymbol, TOPRIMITIVE_SYMBOL_INDEX) \ 119 V(JSTaggedValue, UnscopablesSymbol, UNSCOPABLES_SYMBOL_INDEX) \ 120 V(JSTaggedValue, HoleySymbol, HOLEY_SYMBOL_OFFSET) \ 121 V(JSTaggedValue, ElementICSymbol, ELEMENT_IC_SYMBOL_OFFSET) \ 122 V(JSTaggedValue, IteratorPrototype, ITERATOR_PROTOTYPE_INDEX) \ 123 V(JSTaggedValue, AsyncIteratorPrototype, ASYNC_ITERATOR_PROTOTYPE_INDEX) \ 124 V(JSTaggedValue, ForinIteratorPrototype, FORIN_ITERATOR_PROTOTYPE_INDEX) \ 125 V(JSTaggedValue, ForinIteratorClass, FOR_IN_ITERATOR_CLASS_INDEX) \ 126 V(JSTaggedValue, StringIterator, STRING_ITERATOR_INDEX) \ 127 V(JSTaggedValue, AsyncFromSyncIterator, ASYNC_FROM_SYNC_ITERATOR_INDEX) \ 128 V(JSTaggedValue, MapIteratorPrototype, MAP_ITERATOR_PROTOTYPE_INDEX) \ 129 V(JSTaggedValue, SetIteratorPrototype, SET_ITERATOR_PROTOTYPE_INDEX) \ 130 V(JSTaggedValue, RegExpIteratorPrototype, REGEXP_ITERATOR_PROTOTYPE_INDEX) \ 131 V(JSTaggedValue, ArrayIteratorPrototype, ARRAY_ITERATOR_PROTOTYPE_INDEX) \ 132 V(JSTaggedValue, StringIteratorPrototype, STRING_ITERATOR_PROTOTYPE_INDEX) \ 133 V(JSTaggedValue, AsyncFromSyncIteratorPrototype, ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_INDEX) \ 134 /* SymbolTable *RegisterSymbols */ \ 135 V(JSTaggedValue, RegisterSymbols, SYMBOLS_INDEX) \ 136 V(JSTaggedValue, ThrowTypeError, THROW_TYPE_ERROR_INDEX) \ 137 V(JSTaggedValue, PromiseFunction, PROMISE_FUNCTION_INDEX) \ 138 V(JSTaggedValue, PromiseReactionJob, PROMISE_REACTION_JOB_INDEX) \ 139 V(JSTaggedValue, PromiseResolveThenableJob, PROMISE_REACTION_THENABLE_JOB_INDEX) \ 140 V(JSTaggedValue, DynamicImportJob, DYNAMIC_IMPORT_JOB_INDEX) \ 141 V(JSTaggedValue, TemplateMap, TEMPLATE_MAP_INDEX) \ 142 V(JSTaggedValue, FunctionClassWithProto, FUNCTION_CLASS_WITH_PROTO) \ 143 V(JSTaggedValue, FunctionClassWithProtoOptimized, FUNCTION_CLASS_WITH_PROTO_OPTIMIZED) \ 144 V(JSTaggedValue, FunctionClassWithProtoOptimizedWithFastCall, \ 145 FUNCTION_CLASS_WITH_PROTO_OPTIMIZED_WITH_FAST_CALL) \ 146 V(JSTaggedValue, FunctionClassWithoutProto, FUNCTION_CLASS_WITHOUT_PROTO) \ 147 V(JSTaggedValue, FunctionClassWithoutProtoOptimized, FUNCTION_CLASS_WITHOUT_PROTO_OPTIMIZED) \ 148 V(JSTaggedValue, FunctionClassWithoutProtoOptimizedWithFastCall, \ 149 FUNCTION_CLASS_WITHOUT_PROTO_OPTIMIZED_WITH_FAST_CALL) \ 150 V(JSTaggedValue, FunctionClassWithoutName, FUNCTION_CLASS_WITHOUT_NAME) \ 151 V(JSTaggedValue, ArgumentsClass, ARGUMENTS_CLASS) \ 152 V(JSTaggedValue, ArgumentsCallerAccessor, ARGUMENTS_CALLER_ACCESSOR) \ 153 V(JSTaggedValue, ArgumentsCalleeAccessor, ARGUMENTS_CALLEE_ACCESSOR) \ 154 V(JSTaggedValue, AsyncFunctionClass, ASYNC_FUNCTION_CLASS) \ 155 V(JSTaggedValue, AsyncFunctionClassOptimized, ASYNC_FUNCTION_CLASS_OPTIMIZED) \ 156 V(JSTaggedValue, AsyncFunctionClassOptimizedWithFastCall, \ 157 ASYNC_FUNCTION_CLASS_OPTIMIZED_WITH_FAST_CALL) \ 158 V(JSTaggedValue, AsyncAwaitStatusFunctionClass, ASYNC_AWAIT_STATUS_FUNCTION_CLASS) \ 159 V(JSTaggedValue, PromiseReactionFunctionClass, PROMISE_REACTION_FUNCTION_CLASS) \ 160 V(JSTaggedValue, PromiseExecutorFunctionClass, PROMISE_EXECUTOR_FUNCTION_CLASS) \ 161 V(JSTaggedValue, GeneratorFunctionClass, GENERATOR_FUNCTION_CLASS) \ 162 V(JSTaggedValue, GeneratorFunctionClassOptimized, GENERATOR_FUNCTION_CLASS_OPTIMIZED) \ 163 V(JSTaggedValue, GeneratorFunctionClassOptimizedWithFastCall, \ 164 GENERATOR_FUNCTION_CLASS_OPTIMIZED_WITH_FAST_CALL) \ 165 V(JSTaggedValue, AsyncGeneratorFunctionClass, ASYNC_GENERATOR_FUNCTION_CLASS) \ 166 V(JSTaggedValue, AsyncGeneratorFunctionClassOptimized, \ 167 ASYNC_GENERATOR_FUNCTION_CLASS_OPTIMIZED) \ 168 V(JSTaggedValue, AsyncGeneratorFunctionClassOptimizedWithFastCall, \ 169 ASYNC_GENERATOR_FUNCTION_CLASS_FUNCTION_CLASS_OPTIMIZED_WITH_FAST_CALL) \ 170 V(JSTaggedValue, PromiseAllResolveElementFunctionClass, PROMISE_ALL_RESOLVE_ELEMENT_FUNC_CLASS) \ 171 V(JSTaggedValue, PromiseAnyRejectElementFunctionClass, PROMISE_ANY_REJECT_ELEMENT_FUNC_CLASS) \ 172 V(JSTaggedValue, PromiseAllSettledElementFunctionClass, PROMISE_ALL_SETTLED_ELEMENT_FUNC_CLASS) \ 173 V(JSTaggedValue, PromiseFinallyFunctionClass, PROMISE_FINALLY_FUNC_CLASS) \ 174 V(JSTaggedValue, PromiseValueThunkOrThrowerFunctionClass, \ 175 PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION_CLASS) \ 176 V(JSTaggedValue, AsyncGeneratorResNextRetProRstFtnClass, \ 177 ASYNC_GENERATOR_RESUME_NEXT_RETURN_PROCESSOR_RST_FTN_CLASS) \ 178 V(JSTaggedValue, AsyncFromSyncIterUnwarpClass, ASYNC_FROM_SYNC_ITER_UNWARP_CLASS) \ 179 V(JSTaggedValue, ProxyRevocFunctionClass, PROXY_REVOC_FUNCTION_CLASS) \ 180 V(JSTaggedValue, NativeErrorFunctionClass, NATIVE_ERROR_FUNCTION_CLASS) \ 181 V(JSTaggedValue, SpecificTypedArrayFunctionClass, SPERCIFIC_TYPED_ARRAY_FUNCTION_CLASS) \ 182 V(JSTaggedValue, ConstructorFunctionClass, CONSTRUCTOR_FUNCTION_CLASS) \ 183 V(JSTaggedValue, NormalFunctionClass, NORMAL_FUNCTION_CLASS) \ 184 V(JSTaggedValue, JSIntlBoundFunctionClass, JS_INTL_BOUND_FUNCTION_CLASS) \ 185 V(JSTaggedValue, NumberFormatLocales, NUMBER_FORMAT_LOCALES_INDEX) \ 186 V(JSTaggedValue, DateTimeFormatLocales, DATE_TIMEFORMAT_LOCALES_INDEX) \ 187 V(JSTaggedValue, ListFormatLocales, LIST_FORMAT_LOCALES_INDEX) \ 188 V(JSTaggedValue, GlobalRecord, GLOBAL_RECORD) \ 189 V(JSTaggedValue, ModuleNamespaceClass, MODULENAMESPACE_CLASS) \ 190 V(JSTaggedValue, ObjectLiteralHClassCache, OBJECT_LITERAL_HCLASS_CACHE) \ 191 V(JSTaggedValue, WeakRefKeepObjects, WEAK_REF_KEEP_OBJECTS) \ 192 V(JSTaggedValue, FinRegLists, FIN_REG_LISTS) \ 193 V(JSTaggedValue, AttachSymbol, ATTACH_SYMBOL_INDEX) \ 194 V(JSTaggedValue, DetachSymbol, DETACH_SYMBOL_INDEX) \ 195 V(JSTaggedValue, CjsModuleFunction, CJS_MODULE_FUNCTION_INDEX) \ 196 V(JSTaggedValue, CjsExportsFunction, CJS_EXPORTS_FUNCTION_INDEX) \ 197 V(JSTaggedValue, CjsRequireFunction, CJS_REQUIRE_FUNCTION_INDEX) \ 198 V(JSTaggedValue, GlobalPatch, GLOBAL_PATCH) \ 199 V(JSTaggedValue, ExportOfScript, DEFAULT_EXPORT_OF_SCRIPT) 200 201 class GlobalEnv : public TaggedObject { 202 public: GetGlobalObject()203 JSTaggedValue GetGlobalObject() const 204 { 205 return GetJSGlobalObject().GetTaggedValue(); 206 } 207 ComputeObjectAddress(size_t index)208 uintptr_t ComputeObjectAddress(size_t index) const 209 { 210 return reinterpret_cast<uintptr_t>(this) + HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); 211 } 212 GetGlobalEnvObjectByIndex(size_t index)213 JSHandle<JSTaggedValue> GetGlobalEnvObjectByIndex(size_t index) const 214 { 215 ASSERT(index < FINAL_INDEX); 216 uintptr_t address = ComputeObjectAddress(index); 217 JSHandle<JSTaggedValue> result(address); 218 return result; 219 } 220 GetGlobalEnvFieldSize()221 size_t GetGlobalEnvFieldSize() const 222 { 223 return FINAL_INDEX; 224 } 225 226 void Init(JSThread *thread); 227 Cast(TaggedObject * object)228 static GlobalEnv *Cast(TaggedObject *object) 229 { 230 ASSERT(JSTaggedValue(object).IsJSGlobalEnv()); 231 return reinterpret_cast<GlobalEnv *>(object); 232 } 233 234 JSHandle<JSTaggedValue> GetSymbol(JSThread *thread, const JSHandle<JSTaggedValue> &string); 235 JSHandle<JSTaggedValue> GetStringFunctionByName(JSThread *thread, const char *name); 236 JSHandle<JSTaggedValue> GetStringPrototypeFunctionByName(JSThread *thread, const char *name); 237 238 enum Field { 239 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 240 #define GLOBAL_ENV_SLOT(type, name, index) index, 241 GLOBAL_ENV_FIELDS(GLOBAL_ENV_SLOT) 242 #undef GLOBAL_ENV_SLOT 243 FINAL_INDEX 244 }; 245 246 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 247 #define GLOBAL_ENV_FIELD_ACCESSORS(type, name, index) \ 248 inline JSHandle<type> Get##name() const \ 249 { \ 250 const uintptr_t address = \ 251 reinterpret_cast<uintptr_t>(this) + HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ 252 JSHandle<type> result(address); \ 253 if (result.GetTaggedValue().IsInternalAccessor()) { \ 254 JSThread *thread = GetJSThread(); \ 255 AccessorData *accessor = AccessorData::Cast(result.GetTaggedValue().GetTaggedObject()); \ 256 accessor->CallInternalGet(thread, JSHandle<JSObject>::Cast(GetJSGlobalObject())); \ 257 } \ 258 return result; \ 259 } \ 260 inline JSTaggedValue GetTagged##name() const \ 261 { \ 262 uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ 263 JSTaggedValue result(Barriers::GetValue<JSTaggedType>(this, offset)); \ 264 if (result.IsInternalAccessor()) { \ 265 JSThread *thread = GetJSThread(); \ 266 AccessorData *accessor = AccessorData::Cast(result.GetTaggedObject()); \ 267 accessor->CallInternalGet(thread, JSHandle<JSObject>::Cast(GetJSGlobalObject())); \ 268 } \ 269 return result; \ 270 } \ 271 template<typename T> \ 272 inline void Set##name(const JSThread *thread, JSHandle<T> value, BarrierMode mode = WRITE_BARRIER) \ 273 { \ 274 uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ 275 if (mode == WRITE_BARRIER && value.GetTaggedValue().IsHeapObject()) { \ 276 Barriers::SetObject<true>(thread, this, offset, value.GetTaggedValue().GetRawData()); \ 277 } else { \ 278 Barriers::SetPrimitive<JSTaggedType>(this, offset, value.GetTaggedValue().GetRawData()); \ 279 } \ 280 } \ 281 inline void Set##name(const JSThread *thread, type value, BarrierMode mode = WRITE_BARRIER) \ 282 { \ 283 uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ 284 if (mode == WRITE_BARRIER && value.IsHeapObject()) { \ 285 Barriers::SetObject<true>(thread, this, offset, value.GetRawData()); \ 286 } else { \ 287 Barriers::SetPrimitive<JSTaggedType>(this, offset, value.GetRawData()); \ 288 } \ 289 } 290 GLOBAL_ENV_FIELDS(GLOBAL_ENV_FIELD_ACCESSORS) 291 #undef GLOBAL_ENV_FIELD_ACCESSORS 292 293 static constexpr size_t HEADER_SIZE = TaggedObjectSize(); 294 static constexpr size_t SIZE = HEADER_SIZE + FINAL_INDEX * JSTaggedValue::TaggedTypeSize(); 295 296 DECL_VISIT_OBJECT(HEADER_SIZE, SIZE); 297 298 DECL_DUMP() 299 }; 300 } // namespace panda::ecmascript 301 302 #endif // ECMASCRIPT_GLOBAL_ENV_H 303