diff --git a/ecmascript/builtins.cpp b/ecmascript/builtins.cpp index 83d612dc..a93f2f17 100644 --- a/ecmascript/builtins.cpp +++ b/ecmascript/builtins.cpp @@ -415,7 +415,7 @@ void Builtins::InitializeFunction(const JSHandle &env, const JSHandle JSHandle funcFuncIntanceDynclass = factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, funcFuncPrototypeValue); funcFuncIntanceDynclass->SetConstructor(true); - JSHandle function = JSHandle::Cast(factory_->NewJSObject(funcFuncIntanceDynclass)); + JSHandle function = JSHandle::Cast(factory_->NewJSObjectWithInit(funcFuncIntanceDynclass)); function->SetBuiltinsCtorMode(); // Function = new Function() (forbidden use NewBuiltinConstructor) @@ -443,7 +443,7 @@ void Builtins::InitializeFunction(const JSHandle &env, const JSHandle factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetFunctionPrototype()); constructorFunctionClass->SetConstructor(true); JSHandle functionConstructor = - JSHandle::Cast(factory_->NewJSObject(constructorFunctionClass)); + JSHandle::Cast(factory_->NewJSObjectWithInit(constructorFunctionClass)); functionConstructor->SetBuiltinsCtorMode(); env->SetConstructorFunctionClass(thread_, constructorFunctionClass); @@ -535,7 +535,7 @@ void Builtins::InitializeSymbol(const JSHandle &env, const JSHandleGlobalConstants(); // Symbol.prototype - JSHandle symbolFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle symbolFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle symbolFuncPrototypeValue(symbolFuncPrototype); // Symbol.prototype_or_dynclass @@ -631,7 +631,7 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, [[maybe_unused]] EcmaHandleScope scope(thread_); JSHandle env = vm_->GetGlobalEnv(); // Symbol.prototype - JSHandle symbolFuncPrototype = factory_->NewJSObject(objFuncInstanceDynclass); + JSHandle symbolFuncPrototype = factory_->NewJSObjectWithInit(objFuncInstanceDynclass); JSHandle symbolFuncPrototypeValue(symbolFuncPrototype); // Symbol.prototype_or_dynclass @@ -769,7 +769,7 @@ void Builtins::InitializeBigInt(const JSHandle &env, const JSHandle bigIntFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle bigIntFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle bigIntFuncPrototypeValue(bigIntFuncPrototype); // BigInt.prototype_or_dynclass @@ -800,7 +800,7 @@ void Builtins::InitializeDate(const JSHandle &env, const JSHandle dateFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle dateFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle dateFuncPrototypeValue(dateFuncPrototype); // Date.prototype_or_dynclass @@ -933,7 +933,7 @@ void Builtins::InitializeAsyncFunction(const JSHandle &env, const JSH [[maybe_unused]] EcmaHandleScope scope(thread_); const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // AsyncFunction.prototype - JSHandle asyncFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle asyncFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSObject::SetPrototype(thread_, asyncFuncPrototype, env->GetFunctionPrototype()); JSHandle async_func_prototype_value(asyncFuncPrototype); @@ -959,7 +959,7 @@ void Builtins::InitializeAsyncFunction(const JSHandle &env, const JSH void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHandle &objFuncDynclass) const { // Error.prototype - JSHandle errorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle errorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle errorFuncPrototypeValue(errorFuncPrototype); // Error.prototype_or_dynclass JSHandle errorFuncInstanceDynclass = @@ -981,7 +981,7 @@ void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHa JSHandle nativeErrorFuncClass = factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetErrorFunction()); nativeErrorFuncClass->SetConstructor(true); - JSHandle function = JSHandle::Cast(factory_->NewJSObject(nativeErrorFuncClass)); + JSHandle function = JSHandle::Cast(factory_->NewJSObjectWithInit(nativeErrorFuncClass)); function->SetBuiltinsCtorMode(); env->SetNativeErrorFunctionClass(thread_, nativeErrorFuncClass); @@ -1068,7 +1068,7 @@ void Builtins::InitializeError(const JSHandle &env, const JSHandle nativeErrorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle nativeErrorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle nativeErrorFuncPrototypeValue(nativeErrorFuncPrototype); ErrorParameter errorParameter{RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError", @@ -1169,7 +1169,7 @@ void Builtins::InitializeSet(const JSHandle &env, const JSHandleGlobalConstants(); // Set.prototype - JSHandle setFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle setFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle setFuncPrototypeValue(setFuncPrototype); // Set.prototype_or_dynclass JSHandle setFuncInstanceDynclass = @@ -1230,7 +1230,7 @@ void Builtins::InitializeMap(const JSHandle &env, const JSHandleGlobalConstants(); // Map.prototype - JSHandle mapFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle mapFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle mapFuncPrototypeValue(mapFuncPrototype); // Map.prototype_or_dynclass JSHandle mapFuncInstanceDynclass = @@ -1295,7 +1295,7 @@ void Builtins::InitializeWeakMap(const JSHandle &env, const JSHandle< [[maybe_unused]] EcmaHandleScope scope(thread_); const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // WeakMap.prototype - JSHandle weakMapFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle weakMapFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle weakMapFuncPrototypeValue(weakMapFuncPrototype); // WeakMap.prototype_or_dynclass JSHandle weakMapFuncInstanceDynclass = @@ -1331,7 +1331,7 @@ void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle< [[maybe_unused]] EcmaHandleScope scope(thread_); const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); // Set.prototype - JSHandle weakSetFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle weakSetFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle weakSetFuncPrototypeValue(weakSetFuncPrototype); // Set.prototype_or_dynclass JSHandle weakSetFuncInstanceDynclass = @@ -1361,7 +1361,7 @@ void Builtins::InitializeMath(const JSHandle &env, const JSHandle mathDynclass = factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, objFuncPrototypeVal); - JSHandle mathObject = factory_->NewJSObject(mathDynclass); + JSHandle mathObject = factory_->NewJSObjectWithInit(mathDynclass); SetFunction(env, mathObject, "abs", Math::Abs, FunctionLength::ONE); SetFunction(env, mathObject, "acos", Math::Acos, FunctionLength::ONE); SetFunction(env, mathObject, "acosh", Math::Acosh, FunctionLength::ONE); @@ -1420,7 +1420,7 @@ void Builtins::InitializeJson(const JSHandle &env, const JSHandle jsonDynclass = factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, objFuncPrototypeVal); - JSHandle jsonObject = factory_->NewJSObject(jsonDynclass); + JSHandle jsonObject = factory_->NewJSObjectWithInit(jsonDynclass); SetFunction(env, jsonObject, "parse", Json::Parse, FunctionLength::TWO); SetFunction(env, jsonObject, "stringify", Json::Stringify, FunctionLength::THREE); @@ -1501,7 +1501,7 @@ void Builtins::InitializeStringIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const { // StringIterator.prototype - JSHandle strIterPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle strIterPrototype(factory_->NewJSObjectWithInit(iteratorFuncDynclass)); // StringIterator.prototype_or_dynclass JSHandle strIterFuncInstanceDynclass = factory_->NewEcmaDynClass( @@ -1522,7 +1522,7 @@ void Builtins::InitializeIterator(const JSHandle &env, const JSHandle { [[maybe_unused]] EcmaHandleScope scope(thread_); // Iterator.prototype - JSHandle iteratorPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle iteratorPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); // Iterator.prototype.next() SetFunction(env, iteratorPrototype, "next", BuiltinsIterator::Next, FunctionLength::ONE); // Iterator.prototype.return() @@ -1554,7 +1554,7 @@ void Builtins::InitializeForinIterator(const JSHandle &env, { [[maybe_unused]] EcmaHandleScope scope(thread_); // Iterator.prototype - JSHandle forinIteratorPrototype = factory_->NewJSObject(iteratorFuncDynclass); + JSHandle forinIteratorPrototype = factory_->NewJSObjectWithInit(iteratorFuncDynclass); JSHandle dynclass = factory_->NewEcmaDynClass(JSForInIterator::SIZE, JSType::JS_FORIN_ITERATOR, JSHandle(forinIteratorPrototype)); @@ -1568,7 +1568,7 @@ void Builtins::InitializeSetIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const { // SetIterator.prototype - JSHandle setIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle setIteratorPrototype(factory_->NewJSObjectWithInit(iteratorFuncDynclass)); // Iterator.prototype.next() SetFunction(env, setIteratorPrototype, "next", JSSetIterator::Next, FunctionLength::ZERO); SetStringTagSymbol(env, setIteratorPrototype, "Set Iterator"); @@ -1579,7 +1579,7 @@ void Builtins::InitializeMapIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const { // MapIterator.prototype - JSHandle mapIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle mapIteratorPrototype(factory_->NewJSObjectWithInit(iteratorFuncDynclass)); // Iterator.prototype.next() SetFunction(env, mapIteratorPrototype, "next", JSMapIterator::Next, FunctionLength::ZERO); SetStringTagSymbol(env, mapIteratorPrototype, "Map Iterator"); @@ -1589,7 +1589,7 @@ void Builtins::InitializeArrayIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const { // ArrayIterator.prototype - JSHandle arrayIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle arrayIteratorPrototype(factory_->NewJSObjectWithInit(iteratorFuncDynclass)); // Iterator.prototype.next() SetFunction(env, arrayIteratorPrototype, "next", JSArrayIterator::Next, FunctionLength::ZERO); SetStringTagSymbol(env, arrayIteratorPrototype, "Array Iterator"); @@ -1697,7 +1697,7 @@ void Builtins::InitializeArray(const JSHandle &env, const JSHandle arrBaseFuncInstanceDynclass = factory_->CreateJSArrayInstanceClass(objFuncPrototypeVal); // Array.prototype - JSHandle arrFuncPrototype = factory_->NewJSObject(arrBaseFuncInstanceDynclass); + JSHandle arrFuncPrototype = factory_->NewJSObjectWithInit(arrBaseFuncInstanceDynclass); JSHandle::Cast(arrFuncPrototype)->SetLength(thread_, JSTaggedValue(FunctionLength::ZERO)); auto accessor = thread_->GlobalConstants()->GetArrayLengthAccessor(); JSArray::Cast(*arrFuncPrototype)->SetPropertyInlinedProps(thread_, JSArray::LENGTH_INLINE_PROPERTY_INDEX, accessor); @@ -1797,7 +1797,7 @@ void Builtins::InitializeTypedArray(const JSHandle &env, const JSHand { [[maybe_unused]] EcmaHandleScope scope(thread_); // TypedArray.prototype - JSHandle typedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle typedArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle typedArrFuncPrototypeValue(typedArrFuncPrototype); // TypedArray.prototype_or_dynclass @@ -1896,7 +1896,8 @@ void Builtins::InitializeTypedArray(const JSHandle &env, const JSHand JSHandle specificTypedArrayFuncClass = factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetTypedArrayFunction()); specificTypedArrayFuncClass->SetConstructor(true); - JSHandle function = JSHandle::Cast(factory_->NewJSObject(specificTypedArrayFuncClass)); + JSHandle function = + JSHandle::Cast(factory_->NewJSObjectWithInit(specificTypedArrayFuncClass)); function->SetBuiltinsCtorMode(); env->SetSpecificTypedArrayFunctionClass(thread_, specificTypedArrayFuncClass); @@ -1917,7 +1918,7 @@ void Builtins::InitializeInt8Array(const JSHandle &env, const JSHandl { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int8Array.prototype - JSHandle int8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle int8ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle int8ArrFuncPrototypeValue(int8ArrFuncPrototype); // Int8Array.prototype_or_dynclass @@ -1941,7 +1942,7 @@ void Builtins::InitializeUint8Array(const JSHandle &env, const JSHand { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint8Array.prototype - JSHandle uint8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint8ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle uint8ArrFuncPrototypeValue(uint8ArrFuncPrototype); // Uint8Array.prototype_or_dynclass @@ -1966,7 +1967,7 @@ void Builtins::InitializeUint8ClampedArray(const JSHandle &env, { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint8ClampedArray.prototype - JSHandle uint8ClampedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint8ClampedArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle uint8ClampedArrFuncPrototypeValue(uint8ClampedArrFuncPrototype); // Uint8ClampedArray.prototype_or_dynclass @@ -1992,7 +1993,7 @@ void Builtins::InitializeInt16Array(const JSHandle &env, const JSHand { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int16Array.prototype - JSHandle int16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle int16ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle int16ArrFuncPrototypeValue(int16ArrFuncPrototype); // Int16Array.prototype_or_dynclass @@ -2016,7 +2017,7 @@ void Builtins::InitializeUint16Array(const JSHandle &env, const JSHan { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint16Array.prototype - JSHandle uint16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint16ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle uint16ArrFuncPrototypeValue(uint16ArrFuncPrototype); // Uint16Array.prototype_or_dynclass @@ -2040,7 +2041,7 @@ void Builtins::InitializeInt32Array(const JSHandle &env, const JSHand { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int32Array.prototype - JSHandle int32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle int32ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle int32ArrFuncPrototypeValue(int32ArrFuncPrototype); // Int32Array.prototype_or_dynclass @@ -2064,7 +2065,7 @@ void Builtins::InitializeUint32Array(const JSHandle &env, const JSHan { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint32Array.prototype - JSHandle uint32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle uint32ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle uint32ArrFuncPrototypeValue(uint32ArrFuncPrototype); // Uint32Array.prototype_or_dynclass @@ -2088,7 +2089,7 @@ void Builtins::InitializeFloat32Array(const JSHandle &env, const JSHa { [[maybe_unused]] EcmaHandleScope scope(thread_); // Float32Array.prototype - JSHandle float32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle float32ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle float32ArrFuncPrototypeValue(float32ArrFuncPrototype); // Float32Array.prototype_or_dynclass @@ -2112,7 +2113,7 @@ void Builtins::InitializeFloat64Array(const JSHandle &env, const JSHa { [[maybe_unused]] EcmaHandleScope scope(thread_); // Float64Array.prototype - JSHandle float64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle float64ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle float64ArrFuncPrototypeValue(float64ArrFuncPrototype); // Float64Array.prototype_or_dynclass @@ -2136,7 +2137,7 @@ void Builtins::InitializeBigInt64Array(const JSHandle &env, const JSH { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigInt64Array.prototype - JSHandle bigInt64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle bigInt64ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle bigInt64ArrFuncPrototypeValue(bigInt64ArrFuncPrototype); // BigInt64Array.prototype_or_dynclass @@ -2160,7 +2161,7 @@ void Builtins::InitializeBigUint64Array(const JSHandle &env, const JS { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigUint64Array.prototype - JSHandle bigUint64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle bigUint64ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle bigUint64ArrFuncPrototypeValue(bigUint64ArrFuncPrototype); // BigUint64Array.prototype_or_dynclass @@ -2184,7 +2185,7 @@ void Builtins::InitializeArrayBuffer(const JSHandle &env, const JSHan { [[maybe_unused]] EcmaHandleScope scope(thread_); // ArrayBuffer.prototype - JSHandle arrayBufferFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle arrayBufferFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle arrayBufferFuncPrototypeValue(arrayBufferFuncPrototype); // ArrayBuffer.prototype_or_dynclass @@ -2228,7 +2229,7 @@ void Builtins::InitializeReflect(const JSHandle &env, [[maybe_unused]] EcmaHandleScope scope(thread_); JSHandle reflectDynclass = factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, objFuncPrototypeVal); - JSHandle reflectObject = factory_->NewJSObject(reflectDynclass); + JSHandle reflectObject = factory_->NewJSObjectWithInit(reflectDynclass); SetFunction(env, reflectObject, "apply", Reflect::ReflectApply, FunctionLength::THREE); SetFunction(env, reflectObject, "construct", Reflect::ReflectConstruct, FunctionLength::TWO); @@ -2261,7 +2262,7 @@ void Builtins::InitializeSharedArrayBuffer(const JSHandle &env, { [[maybe_unused]] EcmaHandleScope scope(thread_); // SharedArrayBuffer.prototype - JSHandle sharedArrayBufferFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle sharedArrayBufferFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle sharedArrayBufferFuncPrototypeValue(sharedArrayBufferFuncPrototype); // SharedArrayBuffer.prototype_or_dynclass @@ -2305,7 +2306,7 @@ void Builtins::InitializePromise(const JSHandle &env, const JSHandle< { [[maybe_unused]] EcmaHandleScope scope(thread_); // Promise.prototype - JSHandle promiseFuncPrototype = factory_->NewJSObject(promiseFuncDynclass); + JSHandle promiseFuncPrototype = factory_->NewJSObjectWithInit(promiseFuncDynclass); JSHandle promiseFuncPrototypeValue(promiseFuncPrototype); // Promise.prototype_or_dynclass JSHandle promiseFuncInstanceDynclass = @@ -2350,7 +2351,7 @@ void Builtins::InitializeDataView(const JSHandle &env, const JSHandle { [[maybe_unused]] EcmaHandleScope scope(thread_); // ArrayBuffer.prototype - JSHandle dataViewFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle dataViewFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle dataViewFuncPrototypeValue(dataViewFuncPrototype); // ArrayBuffer.prototype_or_dynclass @@ -2575,7 +2576,7 @@ void Builtins::InitializeGeneratorFunction(const JSHandle &env, { [[maybe_unused]] EcmaHandleScope scope(thread_); const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); - JSHandle generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle generatorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle generatorFuncPrototypeValue(generatorFuncPrototype); // 26.3.3.1 GeneratorFunction.prototype.constructor @@ -2621,7 +2622,7 @@ void Builtins::InitializeGenerator(const JSHandle &env, const JSHandl { [[maybe_unused]] EcmaHandleScope scope(thread_); const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); - JSHandle generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle generatorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); // GeneratorObject.prototype method // 26.5.1.2 Generator.prototype.next(value) @@ -2641,7 +2642,7 @@ void Builtins::InitializeGenerator(const JSHandle &env, const JSHandl JSObject::SetPrototype(thread_, generatorFuncPrototype, env->GetIteratorPrototype()); // Generator {} - JSHandle initialGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle initialGeneratorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, JSHandle(generatorFuncPrototype)); env->SetInitialGenerator(thread_, initialGeneratorFuncPrototype); } @@ -2715,7 +2716,7 @@ void Builtins::InitializeIntl(const JSHandle &env, const JSHandle intlDynclass = factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_INTL, objFuncPrototypeValue); - JSHandle intlObject = factory_->NewJSObject(intlDynclass); + JSHandle intlObject = factory_->NewJSObjectWithInit(intlDynclass); JSHandle initIntlSymbol(factory_->NewPublicSymbolWithChar("Symbol.IntlLegacyConstructedSymbol")); SetNoneAttributeProperty(intlObject, "fallbackSymbol", initIntlSymbol); @@ -3087,7 +3088,7 @@ void Builtins::InitializeModuleNamespace(const JSHandle &env, { [[maybe_unused]] EcmaHandleScope scope(thread_); // ModuleNamespace.prototype - JSHandle moduleNamespacePrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle moduleNamespacePrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle moduleNamespacePrototypeValue(moduleNamespacePrototype); // ModuleNamespace.prototype_or_dynclass diff --git a/ecmascript/compiler/bytecode_circuit_builder.cpp b/ecmascript/compiler/bytecode_circuit_builder.cpp index fb51f488..a09786dc 100644 --- a/ecmascript/compiler/bytecode_circuit_builder.cpp +++ b/ecmascript/compiler/bytecode_circuit_builder.cpp @@ -2305,7 +2305,7 @@ void BytecodeCircuitBuilder::NewReturn(BytecodeRegion &bb, const uint8_t *pc, Ga } else if (static_cast(bytecodeInfo.opcode) == EcmaOpcode::RETURNUNDEFINED_PREF) { // handle returnundefined bytecode auto constant = circuit_.NewGate(OpCode(OpCode::CONSTANT), MachineType::I64, - coretypes::TaggedValue::VALUE_UNDEFINED, + JSTaggedValue::VALUE_UNDEFINED, { Circuit::GetCircuitRoot(OpCode(OpCode::CONSTANT_LIST)) }, GateType::JS_ANY); auto gate = circuit_.NewGate(OpCode(OpCode::RETURN), 0, diff --git a/ecmascript/compiler/stub-inl.h b/ecmascript/compiler/stub-inl.h index b5bb8c67..55e8cc0d 100644 --- a/ecmascript/compiler/stub-inl.h +++ b/ecmascript/compiler/stub-inl.h @@ -604,19 +604,13 @@ inline GateRef Stub::TaggedIsException(GateRef x) inline GateRef Stub::TaggedIsSpecial(GateRef x) { - return TruncInt32ToInt1(Int32And( - SExtInt1ToInt32( - Int64Equal(Int64And(x, Int64(~JSTaggedValue::TAG_SPECIAL_MASK)), Int64(0))), - Int32Or(SExtInt1ToInt32( - Int64NotEqual(Int64And(x, Int64(JSTaggedValue::TAG_SPECIAL_VALUE)), Int64(0))), - SExtInt1ToInt32(TaggedIsHole(x))))); + return BoolOr(Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_SPECIAL_MARK)), + Int64(JSTaggedValue::TAG_SPECIAL_VALUE)), TaggedIsHole(x)); } inline GateRef Stub::TaggedIsHeapObject(GateRef x) { - return TruncInt32ToInt1( - Int32And(SExtInt1ToInt32(TaggedIsObject(x)), - SExtInt1ToInt32(Int32Equal(SExtInt1ToInt32(TaggedIsSpecial(x)), Int32(0))))); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_BOOLEAN)), Int64(0)); } inline GateRef Stub::TaggedIsGeneratorObject(GateRef x) @@ -638,10 +632,7 @@ inline GateRef Stub::TaggedIsPropertyBox(GateRef x) inline GateRef Stub::TaggedIsWeak(GateRef x) { - return TruncInt32ToInt1( - Int32And(SExtInt1ToInt32(TaggedIsHeapObject(x)), SExtInt1ToInt32( - Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_WEAK_MASK)), - Int64(1))))); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_WEAK)), Int64(1)); } inline GateRef Stub::TaggedIsPrototypeHandler(GateRef x) @@ -686,7 +677,8 @@ inline GateRef Stub::TaggedIsNull(GateRef x) inline GateRef Stub::TaggedIsUndefinedOrNull(GateRef x) { - return TruncInt32ToInt1(Int32Or(SExtInt1ToInt32(TaggedIsUndefined(x)), SExtInt1ToInt32(TaggedIsNull(x)))); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_BOOLEAN)), + Int64(JSTaggedValue::TAG_SPECIAL_VALUE)); } inline GateRef Stub::TaggedIsTrue(GateRef x) @@ -701,7 +693,8 @@ inline GateRef Stub::TaggedIsFalse(GateRef x) inline GateRef Stub::TaggedIsBoolean(GateRef x) { - return TruncInt32ToInt1(Int32Or(SExtInt1ToInt32(TaggedIsTrue(x)), SExtInt1ToInt32(TaggedIsFalse(x)))); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_BOOLEAN)), + Int64(JSTaggedValue::TAG_BOOLEAN_MASK)); } inline GateRef Stub::TaggedGetInt(GateRef x) diff --git a/ecmascript/compiler/tests/stub_tests.cpp b/ecmascript/compiler/tests/stub_tests.cpp index 3db39c8b..8cf5d0c2 100644 --- a/ecmascript/compiler/tests/stub_tests.cpp +++ b/ecmascript/compiler/tests/stub_tests.cpp @@ -1082,7 +1082,7 @@ HWTEST_F_L0(StubTest, GetPropertyByValueStub) double key = 4.29497e+09; resVal = getPropertyByValuePtr(thread->GetGlueAddr(), strHello.GetTaggedValue().GetRawData(), JSTaggedValue(key).GetRawData()); - EXPECT_EQ(resVal.GetRawData(), 0ULL); + EXPECT_EQ(resVal.GetRawData(), JSTaggedValue::Hole().GetRawData()); } HWTEST_F_L0(StubTest, FastTypeOfTest) diff --git a/ecmascript/interpreter/fast_runtime_stub-inl.h b/ecmascript/interpreter/fast_runtime_stub-inl.h index 6b334f05..12b1f9f1 100644 --- a/ecmascript/interpreter/fast_runtime_stub-inl.h +++ b/ecmascript/interpreter/fast_runtime_stub-inl.h @@ -1180,7 +1180,7 @@ bool FastRuntimeStub::FastSetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue FastRuntimeStub::FastGetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) { INTERPRETER_TRACE(thread, FastGetProperty); - JSTaggedValue result; + JSTaggedValue result = JSTaggedValue::Hole(); if (receiver.IsJSObject() && !receiver.IsTypedArray() && (key.IsStringOrSymbol())) { uint32_t index = 0; if (UNLIKELY(JSTaggedValue::ToElementIndex(key, &index))) { diff --git a/ecmascript/js_tagged_value-inl.h b/ecmascript/js_tagged_value-inl.h index 636bd863..3f6fbc86 100644 --- a/ecmascript/js_tagged_value-inl.h +++ b/ecmascript/js_tagged_value-inl.h @@ -491,7 +491,7 @@ inline bool JSTaggedValue::IsJSProxy() const inline bool JSTaggedValue::IsBoolean() const { - return IsTrue() || IsFalse(); + return ((value_ & TAG_HEAPOBJECT_BOOLEAN) == TAG_BOOLEAN_MASK); } inline bool JSTaggedValue::IsJSObject() const diff --git a/ecmascript/js_tagged_value.h b/ecmascript/js_tagged_value.h index eb408d89..6dfdd903 100644 --- a/ecmascript/js_tagged_value.h +++ b/ecmascript/js_tagged_value.h @@ -48,7 +48,7 @@ enum class ComparisonResult { using JSTaggedType = uint64_t; -static const JSTaggedType NULL_POINTER = 0; +static const JSTaggedType NULL_POINTER = 0x05ULL; static inline JSTaggedType ReinterpretDoubleToTaggedType(double value) { @@ -76,9 +76,9 @@ static inline double ReinterpretTaggedTypeToDouble(JSTaggedType value) // There are some special markers of Object: // False: [56 bits 0] | 0x06 // 0110 // True: [56 bits 0] | 0x07 // 0111 -// Undefined: [56 bits 0] | 0x0a // 1010 -// Null: [56 bits 0] | 0x02 // 0010 -// Hole: [56 bits 0] | 0x00 // 0000 +// Undefined: [56 bits 0] | 0x02 // 0010 +// Null: [56 bits 0] | 0x03 // 0011 +// Hole: [56 bits 0] | 0x05 // 0101 class JSTaggedValue { public: @@ -90,20 +90,24 @@ public: static constexpr JSTaggedType TAG_OBJECT = 0x0000ULL << TAG_BITS_SHIFT; static constexpr JSTaggedType TAG_SPECIAL_MASK = 0xFFULL; + static constexpr TaggedType TAG_HEAPOBJECT_BOOLEAN = TAG_INT | 0x06ULL; + static constexpr TaggedType TAG_WEAK = TAG_INT | 0x07ULL; + static constexpr TaggedType TAG_SPECIAL_MARK = TAG_INT | 0x02ULL; static constexpr JSTaggedType TAG_SPECIAL_VALUE = 0x02ULL; static constexpr JSTaggedType TAG_BOOLEAN = 0x04ULL; - static constexpr JSTaggedType TAG_UNDEFINED = 0x08ULL; - static constexpr JSTaggedType TAG_EXCEPTION = 0x10ULL; + static constexpr JSTaggedType TAG_BOOLEAN_MASK = 0x06ULL; + static constexpr TaggedType TAG_NULL = 0x01ULL; + static constexpr TaggedType TAG_EXCEPTION = 0x08ULL; static constexpr JSTaggedType TAG_WEAK_FILTER = 0x03ULL; - static constexpr JSTaggedType VALUE_HOLE = TAG_OBJECT | 0x00ULL; + static constexpr JSTaggedType VALUE_HOLE = TAG_OBJECT | 0x05ULL; static constexpr JSTaggedType TAG_WEAK_MASK = TAG_OBJECT | 0x01ULL; - static constexpr JSTaggedType VALUE_NULL = TAG_OBJECT | TAG_SPECIAL_VALUE; + static constexpr JSTaggedType VALUE_NULL = TAG_OBJECT | TAG_SPECIAL_VALUE | TAG_NULL; static constexpr JSTaggedType VALUE_FALSE = TAG_OBJECT | TAG_BOOLEAN | TAG_SPECIAL_VALUE | static_cast(false); static constexpr JSTaggedType VALUE_TRUE = TAG_OBJECT | TAG_BOOLEAN | TAG_SPECIAL_VALUE | static_cast(true); static constexpr JSTaggedType VALUE_ZERO = TAG_INT | 0x00ULL; - static constexpr JSTaggedType VALUE_UNDEFINED = TAG_OBJECT | TAG_SPECIAL_VALUE | TAG_UNDEFINED; + static constexpr JSTaggedType VALUE_UNDEFINED = TAG_OBJECT | TAG_SPECIAL_VALUE; static constexpr JSTaggedType VALUE_EXCEPTION = TAG_OBJECT | TAG_SPECIAL_VALUE | TAG_EXCEPTION; static constexpr size_t DOUBLE_ENCODE_OFFSET_BIT = 48; @@ -191,7 +195,7 @@ public: inline bool IsWeak() const { - return IsHeapObject() && ((value_ & TAG_WEAK_MASK) == 1U); + return ((value_ & TAG_WEAK) == 0x01ULL);; } inline bool IsDouble() const @@ -206,7 +210,7 @@ public: inline bool IsSpecial() const { - return ((value_ & (~TAG_SPECIAL_MASK)) == 0U) && (((value_ & TAG_SPECIAL_VALUE) != 0U) || IsHole()); + return ((value_ & TAG_SPECIAL_MARK) == TAG_SPECIAL_VALUE) || IsHole(); } inline bool IsObject() const @@ -221,7 +225,7 @@ public: inline bool IsHeapObject() const { - return IsObject() && !IsSpecial(); + return ((value_ & TAG_HEAPOBJECT_BOOLEAN) == 0U); } inline double GetDouble() const @@ -289,7 +293,7 @@ public: inline bool IsUndefinedOrNull() const { - return IsNull() || IsUndefined(); + return ((value_ & TAG_HEAPOBJECT_BOOLEAN) == TAG_SPECIAL_VALUE); } inline bool IsHole() const diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index b748f378..dad56e24 100644 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -507,7 +507,7 @@ LocalScope::~LocalScope() } // ----------------------------------- EscapeLocalScope ------------------------------ -EscapeLocalScope::EscapeLocalScope(const EcmaVM *vm) : LocalScope(vm, 0U) +EscapeLocalScope::EscapeLocalScope(const EcmaVM *vm) : LocalScope(vm, JSTaggedValue::Undefined().GetRawData()) { auto thread = vm->GetJSThread(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index a913c711..d29b01f1 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -352,7 +352,7 @@ JSHandle ObjectFactory::CloneProperties(const JSHandle auto header = heap_->AllocateYoungOrHugeObject(klass, size); JSHandle newArray(thread_, header); newArray->SetLength(newLength); - + newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength); for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i); newArray->Set(thread_, i, value); @@ -416,6 +416,7 @@ JSHandle ObjectFactory::CloneProperties(const JSHandle size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength); auto header = heap_->AllocateYoungOrHugeObject(klass, size); JSHandle newArray(thread_, header); + newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength); newArray->SetLength(newLength); for (uint32_t i = 0; i < newLength; i++) { @@ -535,6 +536,7 @@ JSHandle ObjectFactory::NewNonMovableJSObject(const JSHandle { JSHandle obj(thread_, JSObject::Cast(NewNonMovableDynObject(jshclass, jshclass->GetInlinedProperties()))); + obj->InitializeHash(); obj->SetElements(thread_, EmptyArray(), SKIP_BARRIER); obj->SetProperties(thread_, EmptyArray(), SKIP_BARRIER); return obj; @@ -768,249 +770,300 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandle ObjectFactory::NewJSObjectWithInit(const JSHandle &jshclass) +{ JSHandle obj = NewJSObject(jshclass); - { - JSType type = jshclass->GetObjectType(); - switch (type) { - case JSType::JS_OBJECT: - case JSType::JS_ERROR: - case JSType::JS_EVAL_ERROR: - case JSType::JS_RANGE_ERROR: - case JSType::JS_REFERENCE_ERROR: - case JSType::JS_TYPE_ERROR: - case JSType::JS_URI_ERROR: - case JSType::JS_SYNTAX_ERROR: - case JSType::JS_ITERATOR: { - break; - } - case JSType::JS_INTL: { - JSIntl::Cast(*obj)->SetFallbackSymbol(thread_, JSTaggedValue::Undefined()); - break; - } - case JSType::JS_LOCALE: { - JSLocale::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); - break; - } - case JSType::JS_DATE_TIME_FORMAT: { - JSDateTimeFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetCalendar(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetNumberingSystem(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetTimeZone(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetLocaleIcu(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetSimpleDateTimeFormatIcu(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetIso8601(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetBoundFormat(thread_, JSTaggedValue::Undefined()); - JSDateTimeFormat::Cast(*obj)->SetHourCycle(HourCycleOption::EXCEPTION); - JSDateTimeFormat::Cast(*obj)->SetDateStyle(DateTimeStyleOption::EXCEPTION); - JSDateTimeFormat::Cast(*obj)->SetTimeStyle(DateTimeStyleOption::EXCEPTION); - break; - } - case JSType::JS_NUMBER_FORMAT: { - JSNumberFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetNumberingSystem(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetCurrency(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetUnit(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetMinimumIntegerDigits(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetMinimumFractionDigits(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetMaximumFractionDigits(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetMinimumSignificantDigits(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetMaximumSignificantDigits(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetUseGrouping(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetBoundFormat(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); - JSNumberFormat::Cast(*obj)->SetStyle(StyleOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetCurrencySign(CurrencySignOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetCurrencyDisplay(CurrencyDisplayOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetUnitDisplay(UnitDisplayOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetSignDisplay(SignDisplayOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetCompactDisplay(CompactDisplayOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetNotation(NotationOption::EXCEPTION); - JSNumberFormat::Cast(*obj)->SetRoundingType(RoundingType::EXCEPTION); - break; - } - case JSType::JS_RELATIVE_TIME_FORMAT: { - JSRelativeTimeFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); - JSRelativeTimeFormat::Cast(*obj)->SetInitializedRelativeTimeFormat(thread_, JSTaggedValue::Undefined()); - JSRelativeTimeFormat::Cast(*obj)->SetNumberingSystem(thread_, JSTaggedValue::Undefined()); - JSRelativeTimeFormat::Cast(*obj)->SetAvailableLocales(thread_, JSTaggedValue::Undefined()); - JSRelativeTimeFormat::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); - JSRelativeTimeFormat::Cast(*obj)->SetStyle(RelativeStyleOption::EXCEPTION); - JSRelativeTimeFormat::Cast(*obj)->SetNumeric(NumericOption::EXCEPTION); - break; - } - case JSType::JS_COLLATOR: { - JSCollator::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); - JSCollator::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); - JSCollator::Cast(*obj)->SetCollation(thread_, JSTaggedValue::Undefined()); - JSCollator::Cast(*obj)->SetBoundCompare(thread_, JSTaggedValue::Undefined()); - JSCollator::Cast(*obj)->SetUsage(UsageOption::EXCEPTION); - JSCollator::Cast(*obj)->SetCaseFirst(CaseFirstOption::EXCEPTION); - JSCollator::Cast(*obj)->SetSensitivity(SensitivityOption::EXCEPTION); - JSCollator::Cast(*obj)->SetIgnorePunctuation(false); - JSCollator::Cast(*obj)->SetNumeric(false); - break; - } - case JSType::JS_PLURAL_RULES: { - JSPluralRules::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetInitializedPluralRules(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetMinimumIntegerDigits(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetMinimumFractionDigits(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetMaximumFractionDigits(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetMinimumSignificantDigits(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetMaximumSignificantDigits(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetIcuPR(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetIcuNF(thread_, JSTaggedValue::Undefined()); - JSPluralRules::Cast(*obj)->SetRoundingType(RoundingType::EXCEPTION); - JSPluralRules::Cast(*obj)->SetType(TypeOption::EXCEPTION); - break; - } - case JSType::JS_DISPLAYNAMES: { - JSDisplayNames::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); - JSDisplayNames::Cast(*obj)->SetType(TypednsOption::EXCEPTION); - JSDisplayNames::Cast(*obj)->SetStyle(StyOption::EXCEPTION); - JSDisplayNames::Cast(*obj)->SetFallback(FallbackOption::EXCEPTION); - JSDisplayNames::Cast(*obj)->SetIcuLDN(thread_, JSTaggedValue::Undefined()); - break; - } - case JSType::JS_LIST_FORMAT: { - JSListFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); - JSListFormat::Cast(*obj)->SetType(ListTypeOption::EXCEPTION); - JSListFormat::Cast(*obj)->SetStyle(ListStyleOption::EXCEPTION); - JSListFormat::Cast(*obj)->SetIcuLF(thread_, JSTaggedValue::Undefined()); - break; - } - case JSType::JS_ARRAY: { - JSArray::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); - auto accessor = thread_->GlobalConstants()->GetArrayLengthAccessor(); - JSArray::Cast(*obj)->SetPropertyInlinedProps(thread_, JSArray::LENGTH_INLINE_PROPERTY_INDEX, accessor); - break; - } - case JSType::JS_DATE: - JSDate::Cast(*obj)->SetTimeValue(thread_, JSTaggedValue(0.0)); - JSDate::Cast(*obj)->SetLocalOffset(thread_, JSTaggedValue(JSDate::MAX_DOUBLE)); - break; - case JSType::JS_INT8_ARRAY: - case JSType::JS_UINT8_ARRAY: - case JSType::JS_UINT8_CLAMPED_ARRAY: - case JSType::JS_INT16_ARRAY: - case JSType::JS_UINT16_ARRAY: - case JSType::JS_INT32_ARRAY: - case JSType::JS_UINT32_ARRAY: - case JSType::JS_FLOAT32_ARRAY: - case JSType::JS_FLOAT64_ARRAY: - case JSType::JS_BIGINT64_ARRAY: - case JSType::JS_BIGUINT64_ARRAY: - JSTypedArray::Cast(*obj)->SetViewedArrayBuffer(thread_, JSTaggedValue::Undefined()); - JSTypedArray::Cast(*obj)->SetTypedArrayName(thread_, JSTaggedValue::Undefined()); - JSTypedArray::Cast(*obj)->SetByteLength(thread_, JSTaggedValue(0)); - JSTypedArray::Cast(*obj)->SetByteOffset(thread_, JSTaggedValue(0)); - JSTypedArray::Cast(*obj)->SetArrayLength(thread_, JSTaggedValue(0)); - JSTypedArray::Cast(*obj)->SetContentType(ContentType::None); - break; - case JSType::JS_REG_EXP: - JSRegExp::Cast(*obj)->SetByteCodeBuffer(thread_, JSTaggedValue::Undefined()); - JSRegExp::Cast(*obj)->SetOriginalSource(thread_, JSTaggedValue::Undefined()); - JSRegExp::Cast(*obj)->SetOriginalFlags(thread_, JSTaggedValue(0)); - JSRegExp::Cast(*obj)->SetLength(0); - break; - case JSType::JS_PRIMITIVE_REF: - JSPrimitiveRef::Cast(*obj)->SetValue(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_SET: - JSSet::Cast(*obj)->SetLinkedSet(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_MAP: - JSMap::Cast(*obj)->SetLinkedMap(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_WEAK_MAP: - JSWeakMap::Cast(*obj)->SetLinkedMap(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_WEAK_SET: - JSWeakSet::Cast(*obj)->SetLinkedSet(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_GENERATOR_OBJECT: - JSGeneratorObject::Cast(*obj)->SetGeneratorContext(thread_, JSTaggedValue::Undefined()); - JSGeneratorObject::Cast(*obj)->SetResumeResult(thread_, JSTaggedValue::Undefined()); - JSGeneratorObject::Cast(*obj)->SetGeneratorState(JSGeneratorState::UNDEFINED); - JSGeneratorObject::Cast(*obj)->SetResumeMode(GeneratorResumeMode::UNDEFINED); - break; - case JSType::JS_STRING_ITERATOR: - JSStringIterator::Cast(*obj)->SetStringIteratorNextIndex(0); - JSStringIterator::Cast(*obj)->SetIteratedString(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_ARRAY_BUFFER: - JSArrayBuffer::Cast(*obj)->SetArrayBufferData(thread_, JSTaggedValue::Undefined()); - JSArrayBuffer::Cast(*obj)->SetArrayBufferByteLength(0); - JSArrayBuffer::Cast(*obj)->ClearBitField(); - break; - case JSType::JS_SHARED_ARRAY_BUFFER: - JSArrayBuffer::Cast(*obj)->SetArrayBufferData(thread_, JSTaggedValue::Undefined()); - JSArrayBuffer::Cast(*obj)->SetArrayBufferByteLength(0); - JSArrayBuffer::Cast(*obj)->SetShared(true); - break; - case JSType::JS_PROMISE: - JSPromise::Cast(*obj)->SetPromiseState(PromiseState::PENDING); - JSPromise::Cast(*obj)->SetPromiseResult(thread_, JSTaggedValue::Undefined()); - JSPromise::Cast(*obj)->SetPromiseRejectReactions(thread_, GetEmptyTaggedQueue().GetTaggedValue()); - JSPromise::Cast(*obj)->SetPromiseFulfillReactions(thread_, GetEmptyTaggedQueue().GetTaggedValue()); - - JSPromise::Cast(*obj)->SetPromiseIsHandled(false); - break; - case JSType::JS_DATA_VIEW: - JSDataView::Cast(*obj)->SetDataView(thread_, JSTaggedValue(false)); - JSDataView::Cast(*obj)->SetViewedArrayBuffer(thread_, JSTaggedValue::Undefined()); - JSDataView::Cast(*obj)->SetByteLength(0); - JSDataView::Cast(*obj)->SetByteOffset(0); - break; - // non ECMA standard jsapi container - case JSType::JS_API_ARRAY_LIST: - JSAPIArrayList::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); - break; - case JSType::JS_API_TREE_MAP: - JSAPITreeMap::Cast(*obj)->SetTreeMap(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_API_TREE_SET: - JSAPITreeSet::Cast(*obj)->SetTreeSet(thread_, JSTaggedValue::Undefined()); - break; - case JSType::JS_API_QUEUE: - JSAPIQueue::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); - JSAPIQueue::Cast(*obj)->SetFront(0); - JSAPIQueue::Cast(*obj)->SetTail(0); - break; - case JSType::JS_API_PLAIN_ARRAY: - JSAPIPlainArray::Cast(*obj)->SetLength(0); - JSAPIPlainArray::Cast(*obj)->SetValues(thread_, JSTaggedValue(0)); - JSAPIPlainArray::Cast(*obj)->SetKeys(thread_, JSTaggedValue(0)); - break; - case JSType::JS_API_STACK: - JSAPIStack::Cast(*obj)->SetTop(0); - break; - case JSType::JS_API_DEQUE: - JSAPIDeque::Cast(*obj)->SetFirst(0); - JSAPIDeque::Cast(*obj)->SetLast(0); - break; - case JSType::JS_FUNCTION: - case JSType::JS_GENERATOR_FUNCTION: - case JSType::JS_FORIN_ITERATOR: - case JSType::JS_MAP_ITERATOR: - case JSType::JS_SET_ITERATOR: - case JSType::JS_REG_EXP_ITERATOR: - case JSType::JS_API_ARRAYLIST_ITERATOR: - case JSType::JS_API_TREEMAP_ITERATOR: - case JSType::JS_API_TREESET_ITERATOR: - case JSType::JS_API_QUEUE_ITERATOR: - case JSType::JS_API_DEQUE_ITERATOR: - case JSType::JS_API_STACK_ITERATOR: - case JSType::JS_ARRAY_ITERATOR: - case JSType::JS_API_PLAIN_ARRAY_ITERATOR: - default: - UNREACHABLE(); - } - } + InitializeJSObject(obj, jshclass); return obj; } +void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHandle &jshclass) +{ + JSType type = jshclass->GetObjectType(); + switch (type) { + case JSType::JS_OBJECT: + case JSType::JS_ERROR: + case JSType::JS_EVAL_ERROR: + case JSType::JS_RANGE_ERROR: + case JSType::JS_REFERENCE_ERROR: + case JSType::JS_TYPE_ERROR: + case JSType::JS_URI_ERROR: + case JSType::JS_SYNTAX_ERROR: + case JSType::JS_ITERATOR: { + break; + } + case JSType::JS_INTL: { + JSIntl::Cast(*obj)->SetFallbackSymbol(thread_, JSTaggedValue::Undefined()); + break; + } + case JSType::JS_LOCALE: { + JSLocale::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); + break; + } + case JSType::JS_DATE_TIME_FORMAT: { + JSDateTimeFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetCalendar(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetNumberingSystem(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetTimeZone(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetLocaleIcu(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetSimpleDateTimeFormatIcu(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetIso8601(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetBoundFormat(thread_, JSTaggedValue::Undefined()); + JSDateTimeFormat::Cast(*obj)->SetHourCycle(HourCycleOption::EXCEPTION); + JSDateTimeFormat::Cast(*obj)->SetDateStyle(DateTimeStyleOption::EXCEPTION); + JSDateTimeFormat::Cast(*obj)->SetTimeStyle(DateTimeStyleOption::EXCEPTION); + break; + } + case JSType::JS_NUMBER_FORMAT: { + JSNumberFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetNumberingSystem(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetCurrency(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetUnit(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetMinimumIntegerDigits(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetMinimumFractionDigits(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetMaximumFractionDigits(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetMinimumSignificantDigits(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetMaximumSignificantDigits(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetUseGrouping(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetBoundFormat(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); + JSNumberFormat::Cast(*obj)->SetStyle(StyleOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetCurrencySign(CurrencySignOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetCurrencyDisplay(CurrencyDisplayOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetUnitDisplay(UnitDisplayOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetSignDisplay(SignDisplayOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetCompactDisplay(CompactDisplayOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetNotation(NotationOption::EXCEPTION); + JSNumberFormat::Cast(*obj)->SetRoundingType(RoundingType::EXCEPTION); + break; + } + case JSType::JS_RELATIVE_TIME_FORMAT: { + JSRelativeTimeFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); + JSRelativeTimeFormat::Cast(*obj)->SetInitializedRelativeTimeFormat(thread_, JSTaggedValue::Undefined()); + JSRelativeTimeFormat::Cast(*obj)->SetNumberingSystem(thread_, JSTaggedValue::Undefined()); + JSRelativeTimeFormat::Cast(*obj)->SetAvailableLocales(thread_, JSTaggedValue::Undefined()); + JSRelativeTimeFormat::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); + JSRelativeTimeFormat::Cast(*obj)->SetStyle(RelativeStyleOption::EXCEPTION); + JSRelativeTimeFormat::Cast(*obj)->SetNumeric(NumericOption::EXCEPTION); + break; + } + case JSType::JS_COLLATOR: { + JSCollator::Cast(*obj)->SetIcuField(thread_, JSTaggedValue::Undefined()); + JSCollator::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); + JSCollator::Cast(*obj)->SetCollation(thread_, JSTaggedValue::Undefined()); + JSCollator::Cast(*obj)->SetBoundCompare(thread_, JSTaggedValue::Undefined()); + JSCollator::Cast(*obj)->SetUsage(UsageOption::EXCEPTION); + JSCollator::Cast(*obj)->SetCaseFirst(CaseFirstOption::EXCEPTION); + JSCollator::Cast(*obj)->SetSensitivity(SensitivityOption::EXCEPTION); + JSCollator::Cast(*obj)->SetIgnorePunctuation(false); + JSCollator::Cast(*obj)->SetNumeric(false); + break; + } + case JSType::JS_PLURAL_RULES: { + JSPluralRules::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetInitializedPluralRules(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetMinimumIntegerDigits(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetMinimumFractionDigits(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetMaximumFractionDigits(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetMinimumSignificantDigits(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetMaximumSignificantDigits(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetIcuPR(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetIcuNF(thread_, JSTaggedValue::Undefined()); + JSPluralRules::Cast(*obj)->SetRoundingType(RoundingType::EXCEPTION); + JSPluralRules::Cast(*obj)->SetType(TypeOption::EXCEPTION); + break; + } + case JSType::JS_DISPLAYNAMES: { + JSDisplayNames::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); + JSDisplayNames::Cast(*obj)->SetType(TypednsOption::EXCEPTION); + JSDisplayNames::Cast(*obj)->SetStyle(StyOption::EXCEPTION); + JSDisplayNames::Cast(*obj)->SetFallback(FallbackOption::EXCEPTION); + JSDisplayNames::Cast(*obj)->SetIcuLDN(thread_, JSTaggedValue::Undefined()); + break; + } + case JSType::JS_LIST_FORMAT: { + JSListFormat::Cast(*obj)->SetLocale(thread_, JSTaggedValue::Undefined()); + JSListFormat::Cast(*obj)->SetType(ListTypeOption::EXCEPTION); + JSListFormat::Cast(*obj)->SetStyle(ListStyleOption::EXCEPTION); + JSListFormat::Cast(*obj)->SetIcuLF(thread_, JSTaggedValue::Undefined()); + break; + } + case JSType::JS_ARRAY: { + JSArray::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); + auto accessor = thread_->GlobalConstants()->GetArrayLengthAccessor(); + JSArray::Cast(*obj)->SetPropertyInlinedProps(thread_, JSArray::LENGTH_INLINE_PROPERTY_INDEX, accessor); + break; + } + case JSType::JS_DATE: + JSDate::Cast(*obj)->SetTimeValue(thread_, JSTaggedValue(0.0)); + JSDate::Cast(*obj)->SetLocalOffset(thread_, JSTaggedValue(JSDate::MAX_DOUBLE)); + break; + case JSType::JS_TYPED_ARRAY: + case JSType::JS_INT8_ARRAY: + case JSType::JS_UINT8_ARRAY: + case JSType::JS_UINT8_CLAMPED_ARRAY: + case JSType::JS_INT16_ARRAY: + case JSType::JS_UINT16_ARRAY: + case JSType::JS_INT32_ARRAY: + case JSType::JS_UINT32_ARRAY: + case JSType::JS_FLOAT32_ARRAY: + case JSType::JS_FLOAT64_ARRAY: + case JSType::JS_BIGINT64_ARRAY: + case JSType::JS_BIGUINT64_ARRAY: + JSTypedArray::Cast(*obj)->SetViewedArrayBuffer(thread_, JSTaggedValue::Undefined()); + JSTypedArray::Cast(*obj)->SetTypedArrayName(thread_, JSTaggedValue::Undefined()); + JSTypedArray::Cast(*obj)->SetByteLength(thread_, JSTaggedValue(0)); + JSTypedArray::Cast(*obj)->SetByteOffset(thread_, JSTaggedValue(0)); + JSTypedArray::Cast(*obj)->SetArrayLength(thread_, JSTaggedValue(0)); + JSTypedArray::Cast(*obj)->SetContentType(ContentType::None); + break; + case JSType::JS_REG_EXP: + JSRegExp::Cast(*obj)->SetByteCodeBuffer(thread_, JSTaggedValue::Undefined()); + JSRegExp::Cast(*obj)->SetOriginalSource(thread_, JSTaggedValue::Undefined()); + JSRegExp::Cast(*obj)->SetOriginalFlags(thread_, JSTaggedValue(0)); + JSRegExp::Cast(*obj)->SetLength(0); + break; + case JSType::JS_PRIMITIVE_REF: + JSPrimitiveRef::Cast(*obj)->SetValue(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_SET: + JSSet::Cast(*obj)->SetLinkedSet(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_MAP: + JSMap::Cast(*obj)->SetLinkedMap(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_WEAK_MAP: + JSWeakMap::Cast(*obj)->SetLinkedMap(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_WEAK_SET: + JSWeakSet::Cast(*obj)->SetLinkedSet(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_GENERATOR_OBJECT: + JSGeneratorObject::Cast(*obj)->SetGeneratorContext(thread_, JSTaggedValue::Undefined()); + JSGeneratorObject::Cast(*obj)->SetResumeResult(thread_, JSTaggedValue::Undefined()); + JSGeneratorObject::Cast(*obj)->SetGeneratorState(JSGeneratorState::UNDEFINED); + JSGeneratorObject::Cast(*obj)->SetResumeMode(GeneratorResumeMode::UNDEFINED); + break; + case JSType::JS_STRING_ITERATOR: + JSStringIterator::Cast(*obj)->SetStringIteratorNextIndex(0); + JSStringIterator::Cast(*obj)->SetIteratedString(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_ARRAY_BUFFER: + JSArrayBuffer::Cast(*obj)->SetArrayBufferData(thread_, JSTaggedValue::Undefined()); + JSArrayBuffer::Cast(*obj)->SetArrayBufferByteLength(0); + JSArrayBuffer::Cast(*obj)->ClearBitField(); + break; + case JSType::JS_SHARED_ARRAY_BUFFER: + JSArrayBuffer::Cast(*obj)->SetArrayBufferData(thread_, JSTaggedValue::Undefined()); + JSArrayBuffer::Cast(*obj)->SetArrayBufferByteLength(0); + JSArrayBuffer::Cast(*obj)->SetShared(true); + break; + case JSType::JS_PROMISE: + JSPromise::Cast(*obj)->SetPromiseState(PromiseState::PENDING); + JSPromise::Cast(*obj)->SetPromiseResult(thread_, JSTaggedValue::Undefined()); + JSPromise::Cast(*obj)->SetPromiseRejectReactions(thread_, GetEmptyTaggedQueue().GetTaggedValue()); + JSPromise::Cast(*obj)->SetPromiseFulfillReactions(thread_, GetEmptyTaggedQueue().GetTaggedValue()); + + JSPromise::Cast(*obj)->SetPromiseIsHandled(false); + break; + case JSType::JS_DATA_VIEW: + JSDataView::Cast(*obj)->SetDataView(thread_, JSTaggedValue(false)); + JSDataView::Cast(*obj)->SetViewedArrayBuffer(thread_, JSTaggedValue::Undefined()); + JSDataView::Cast(*obj)->SetByteLength(0); + JSDataView::Cast(*obj)->SetByteOffset(0); + break; + // non ECMA standard jsapi container + case JSType::JS_API_ARRAY_LIST: + JSAPIArrayList::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); + break; + case JSType::JS_API_TREE_MAP: + JSAPITreeMap::Cast(*obj)->SetTreeMap(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_API_TREE_SET: + JSAPITreeSet::Cast(*obj)->SetTreeSet(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_API_QUEUE: + JSAPIQueue::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); + JSAPIQueue::Cast(*obj)->SetFront(0); + JSAPIQueue::Cast(*obj)->SetTail(0); + break; + case JSType::JS_API_PLAIN_ARRAY: + JSAPIPlainArray::Cast(*obj)->SetLength(0); + JSAPIPlainArray::Cast(*obj)->SetValues(thread_, JSTaggedValue(0)); + JSAPIPlainArray::Cast(*obj)->SetKeys(thread_, JSTaggedValue(0)); + break; + case JSType::JS_API_STACK: + JSAPIStack::Cast(*obj)->SetTop(0); + break; + case JSType::JS_API_DEQUE: + JSAPIDeque::Cast(*obj)->SetFirst(0); + JSAPIDeque::Cast(*obj)->SetLast(0); + break; + case JSType::JS_ASYNC_FUNC_OBJECT: + JSAsyncFuncObject::Cast(*obj)->SetGeneratorContext(thread_, JSTaggedValue::Undefined()); + JSAsyncFuncObject::Cast(*obj)->SetResumeResult(thread_, JSTaggedValue::Undefined()); + JSAsyncFuncObject::Cast(*obj)->SetPromise(JSTaggedValue::Undefined()); + break; + case JSType::JS_FUNCTION: + case JSType::JS_GENERATOR_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + break; + case JSType::JS_PROXY_REVOC_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSProxyRevocFunction::Cast(*obj)->SetRevocableProxy(JSTaggedValue::Undefined()); + break; + case JSType::JS_PROMISE_REACTIONS_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSPromiseReactionsFunction::Cast(*obj)->SetPromise(JSTaggedValue::Undefined()); + JSPromiseReactionsFunction::Cast(*obj)->SetAlreadyResolved(JSTaggedValue::Undefined()); + break; + case JSType::JS_PROMISE_EXECUTOR_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSPromiseExecutorFunction::Cast(*obj)->SetCapability(JSTaggedValue::Undefined()); + break; + case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSPromiseAllResolveElementFunction::Cast(*obj)->SetIndex(JSTaggedValue::Undefined()); + JSPromiseAllResolveElementFunction::Cast(*obj)->SetValues(JSTaggedValue::Undefined()); + JSPromiseAllResolveElementFunction::Cast(*obj)->SetCapabilities(JSTaggedValue::Undefined()); + JSPromiseAllResolveElementFunction::Cast(*obj)->SetRemainingElements(JSTaggedValue::Undefined()); + JSPromiseAllResolveElementFunction::Cast(*obj)->SetAlreadyCalled(JSTaggedValue::Undefined()); + break; + case JSType::JS_INTL_BOUND_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSIntlBoundFunction::Cast(*obj)->SetNumberFormat(JSTaggedValue::Undefined()); + JSIntlBoundFunction::Cast(*obj)->SetDateTimeFormat(JSTaggedValue::Undefined()); + JSIntlBoundFunction::Cast(*obj)->SetCollator(JSTaggedValue::Undefined()); + break; + case JSType::JS_BOUND_FUNCTION: + JSBoundFunction::Cast(*obj)->SetBoundTarget(JSTaggedValue::Undefined()); + JSBoundFunction::Cast(*obj)->SetBoundThis(JSTaggedValue::Undefined()); + JSBoundFunction::Cast(*obj)->SetBoundArguments(JSTaggedValue::Undefined()); + break; + case JSType::JS_ARGUMENTS: + JSArguments::Cast(*obj)->SetParameterMap(JSTaggedValue::Undefined()); + break; + case JSType::JS_FORIN_ITERATOR: + case JSType::JS_MAP_ITERATOR: + case JSType::JS_SET_ITERATOR: + case JSType::JS_REG_EXP_ITERATOR: + case JSType::JS_API_ARRAYLIST_ITERATOR: + case JSType::JS_API_TREEMAP_ITERATOR: + case JSType::JS_API_TREESET_ITERATOR: + case JSType::JS_API_QUEUE_ITERATOR: + case JSType::JS_API_DEQUE_ITERATOR: + case JSType::JS_API_STACK_ITERATOR: + case JSType::JS_ARRAY_ITERATOR: + case JSType::JS_API_PLAIN_ARRAY_ITERATOR: + break; + default: + UNREACHABLE(); + } +} + FreeObject *ObjectFactory::FillFreeObject(uintptr_t address, size_t size, RemoveSlots removeSlots) { FreeObject *object = nullptr; @@ -1239,6 +1292,9 @@ JSHandle ObjectFactory::NewJSIntlBoundFunction(const void * JSHandle dynclass = JSHandle::Cast(env->GetJSIntlBoundFunctionClass()); JSHandle intlBoundFunc = JSHandle::Cast(NewJSObject(dynclass)); + intlBoundFunc->SetNumberFormat(JSTaggedValue::Undefined()); + intlBoundFunc->SetDateTimeFormat(JSTaggedValue::Undefined()); + intlBoundFunc->SetCollator(JSTaggedValue::Undefined()); JSMethod *method = vm_->GetMethodForNativeFunction(nativeFunc); intlBoundFunc->SetCallTarget(thread_, method); JSHandle function = JSHandle::Cast(intlBoundFunc); @@ -1260,6 +1316,7 @@ JSHandle ObjectFactory::NewJSProxyRevocFunction(const JSHa JSHandle dynclass = JSHandle::Cast(env->GetProxyRevocFunctionClass()); JSHandle revocFunction = JSHandle::Cast(NewJSObject(dynclass)); + revocFunction->SetRevocableProxy(JSTaggedValue::Undefined()); revocFunction->SetRevocableProxy(thread_, proxy); JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); @@ -1281,7 +1338,7 @@ JSHandle ObjectFactory::NewJSAsyncAwaitStatusFunctio JSHandle awaitFunction = JSHandle::Cast(NewJSObject(dynclass)); - + awaitFunction->SetAsyncContext(JSTaggedValue::Undefined()); JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(awaitFunction)); JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc); awaitFunction->SetCallTarget(thread_, target); @@ -1308,6 +1365,8 @@ JSHandle ObjectFactory::NewJSGeneratorObject(JSHandle dynclass = NewEcmaDynClass(JSGeneratorObject::SIZE, JSType::JS_GENERATOR_OBJECT, proto); JSHandle generatorObject = JSHandle::Cast(NewJSObject(dynclass)); + generatorObject->SetGeneratorContext(JSTaggedValue::Undefined()); + generatorObject->SetResumeResult(JSTaggedValue::Undefined()); return generatorObject; } @@ -1326,7 +1385,7 @@ JSHandle ObjectFactory::NewJSAsyncFuncObject() JSHandle env = vm_->GetGlobalEnv(); JSHandle proto = env->GetInitialGenerator(); JSHandle dynclass = NewEcmaDynClass(JSAsyncFuncObject::SIZE, JSType::JS_ASYNC_FUNC_OBJECT, proto); - JSHandle asyncFuncObject = JSHandle::Cast(NewJSObject(dynclass)); + JSHandle asyncFuncObject = JSHandle::Cast(NewJSObjectWithInit(dynclass)); return asyncFuncObject; } @@ -1551,6 +1610,8 @@ JSHandle ObjectFactory::NewInternalAccessor(void *setter, void *ge TaggedObject *header = heap_->AllocateNonMovableOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetInternalAccessorClass().GetTaggedObject())); JSHandle obj(thread_, AccessorData::Cast(header)); + obj->SetGetter(thread_, JSTaggedValue::Undefined()); + obj->SetSetter(thread_, JSTaggedValue::Undefined()); if (setter != nullptr) { JSHandle setFunc = NewJSNativePointer(setter, nullptr, nullptr, true); obj->SetSetter(thread_, setFunc.GetTaggedValue()); @@ -1670,6 +1731,7 @@ JSHandle ObjectFactory::NewJSRealm() JSHandle dynHandle = NewEcmaDynClass(JSRealm::SIZE, JSType::JS_REALM, protoValue); JSHandle realm(NewJSObject(dynHandle)); realm->SetGlobalEnv(thread_, realmEnvHandle.GetTaggedValue()); + realm->SetValue(JSTaggedValue::Undefined()); JSHandle realmObj = realmEnvHandle->GetJSGlobalObject(); JSHandle realmkey(thread_->GlobalConstants()->GetHandledGlobalString()); @@ -1797,6 +1859,7 @@ JSHandle ObjectFactory::CopyPartArray(const JSHandle & auto header = heap_->AllocateYoungOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size); JSHandle newArray(thread_, header); + newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength); newArray->SetLength(newLength); for (uint32_t i = 0; i < newLength; i++) { @@ -1825,6 +1888,7 @@ JSHandle ObjectFactory::CopyArray(const JSHandle &old, auto header = heap_->AllocateYoungOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size); JSHandle newArray(thread_, header); + newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength); newArray->SetLength(newLength); for (uint32_t i = 0; i < newLength; i++) { @@ -2163,6 +2227,11 @@ JSHandle ObjectFactory::NewJSPromiseAllResol JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); JSMethod *method = vm_->GetMethodForNativeFunction(nativeFunc); function->SetCallTarget(thread_, method); + function->SetIndex(JSTaggedValue::Undefined()); + function->SetValues(JSTaggedValue::Undefined()); + function->SetCapabilities(JSTaggedValue::Undefined()); + function->SetRemainingElements(JSTaggedValue::Undefined()); + function->SetAlreadyCalled(JSTaggedValue::Undefined()); JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(1)); return function; } @@ -2184,6 +2253,8 @@ JSHandle ObjectFactory::NewTransitionHandler() TransitionHandler *handler = TransitionHandler::Cast(heap_->AllocateYoungOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetTransitionHandlerClass().GetTaggedObject()))); + handler->SetHandlerInfo(JSTaggedValue::Undefined()); + handler->SetTransitionHClass(JSTaggedValue::Undefined()); return JSHandle(thread_, handler); } @@ -2312,7 +2383,7 @@ JSHandle ObjectFactory::GetObjectLiteralHClass(const JSHandle ObjectFactory::GetObjectLiteralByHClass(const JSHandle &properties, size_t length) { JSHandle dynclass = GetObjectLiteralHClass(properties, length); - JSHandle obj = NewJSObject(dynclass); + JSHandle obj = NewJSObjectWithInit(dynclass); return obj; } @@ -2383,14 +2454,12 @@ JSHandle ObjectFactory::NewTSObjectType(uint32_t numOfKeys) TaggedObject *header = heap_->AllocateYoungOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetTSObjectTypeClass().GetTaggedObject())); JSHandle objectType(thread_, header); - + objectType->SetHClass(thread_, JSTaggedValue::Undefined()); + objectType->SetObjLayoutInfo(thread_, JSTaggedValue::Undefined()); objectType->SetGTRef(GlobalTSTypeRef::Default()); JSHandle tsPropInfo = CreateTSObjLayoutInfo(numOfKeys); objectType->SetObjLayoutInfo(thread_, tsPropInfo); - - objectType->SetHClass(thread_, JSTaggedValue::Undefined()); - return objectType; } @@ -2438,6 +2507,7 @@ JSHandle ObjectFactory::NewTSUnionType(uint32_t length) JSHandle unionType(thread_, header); unionType->SetGTRef(GlobalTSTypeRef::Default()); + unionType->SetComponentTypes(thread_, JSTaggedValue::Undefined()); JSHandle componentTypes = NewTaggedArray(length, JSTaggedValue::Undefined()); unionType->SetComponentTypes(thread_, componentTypes); @@ -2480,6 +2550,7 @@ JSHandle ObjectFactory::NewTSFunctionType(uint32_t length) TaggedObject *header = heap_->AllocateYoungOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetTSFunctionTypeClass().GetTaggedObject())); JSHandle functionType(thread_, header); + functionType->SetParameterTypes(thread_, JSTaggedValue::Undefined()); JSHandle parameterTypes = NewTaggedArray(length + TSFunctionType::DEFAULT_LENGTH, JSTaggedValue::Undefined()); @@ -2711,6 +2782,7 @@ JSHandle ObjectFactory::CopyDeque(const JSHandle &old, auto header = heap_->AllocateYoungOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size); JSHandle newArray(thread_, header); + newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength); uint32_t curIndex = first; // newIndex use in new TaggedArray, 0 : New TaggedArray index @@ -2750,6 +2822,7 @@ JSHandle ObjectFactory::CopyQueue(const JSHandle &old, auto header = heap_->AllocateYoungOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size); JSHandle newArray(thread_, header); + newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength); newArray->SetLength(newLength); for (uint32_t i = 0; i < oldLength; i++) { @@ -2786,6 +2859,7 @@ JSHandle ObjectFactory::NewJSAPITreeMapIterator(const JSHa iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedMap(thread_, map); iter->SetNextIndex(0); + iter->SetEntries(JSTaggedValue::Undefined()); iter->SetIterationKind(kind); JSHandle tmap(thread_, map->GetTreeMap()); JSHandle entries = TaggedTreeMap::GetArrayFromMap(thread_, tmap); @@ -2805,6 +2879,7 @@ JSHandle ObjectFactory::NewJSAPITreeSetIterator(const JSHa iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedSet(thread_, set); iter->SetNextIndex(0); + iter->SetEntries(JSTaggedValue::Undefined()); iter->SetIterationKind(kind); JSHandle tset(thread_, set->GetTreeSet()); JSHandle entries = TaggedTreeSet::GetArrayFromSet(thread_, tset); @@ -2863,6 +2938,7 @@ JSHandle ObjectFactory::NewSourceTextModule() JSTaggedValue undefinedValue = thread_->GlobalConstants()->GetUndefined(); obj->SetEnvironment(thread_, undefinedValue); obj->SetNamespace(thread_, undefinedValue); + obj->SetEcmaModuleFilename(thread_, undefinedValue); obj->SetRequestedModules(thread_, undefinedValue); obj->SetImportEntries(thread_, undefinedValue); obj->SetLocalExportEntries(thread_, undefinedValue); diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index 608d7edb..7384e30f 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -363,7 +363,8 @@ public: // used for creating jsobject by constructor JSHandle NewJSObjectByConstructor(const JSHandle &constructor, const JSHandle &newTarget); - + void InitializeJSObject(const JSHandle &obj, const JSHandle &jshclass); + JSHandle NewJSObjectWithInit(const JSHandle &jshclass); uintptr_t NewSpaceBySnapshotAllocator(size_t size); JSHandle NewMachineCodeObject(size_t length, const uint8_t *data); JSHandle NewClassInfoExtractor(JSMethod *ctorMethod); diff --git a/ecmascript/tests/accessor_data_test.cpp b/ecmascript/tests/accessor_data_test.cpp index 8f1710e7..df8cfb90 100644 --- a/ecmascript/tests/accessor_data_test.cpp +++ b/ecmascript/tests/accessor_data_test.cpp @@ -63,6 +63,8 @@ HWTEST_F_L0(AccessorDataTest, AccessorData_Cast) JSHandle accDynclassHandle = factory->NewEcmaDynClass(JSObject::SIZE, JSType::ACCESSOR_DATA, nullHandle); ObjectHeader *accObject = factory->NewDynObject(accDynclassHandle); + AccessorData::Cast(accObject)->SetGetter(thread, JSTaggedValue::Undefined()); + AccessorData::Cast(accObject)->SetSetter(thread, JSTaggedValue::Undefined()); EXPECT_TRUE(JSTaggedValue(accObject).IsAccessorData()); AccessorData *acc = AccessorData::Cast(accObject); EXPECT_TRUE(JSTaggedValue(acc).IsAccessorData()); @@ -96,6 +98,8 @@ HWTEST_F_L0(AccessorDataTest, IsInternal) JSHandle accDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::ACCESSOR_DATA, nullHandle); ObjectHeader *accObject = factory->NewDynObject(accDynclass); AccessorData *acc = AccessorData::Cast(accObject); + acc->SetGetter(thread, JSTaggedValue::Undefined()); + acc->SetSetter(thread, JSTaggedValue::Undefined()); EXPECT_EQ(acc->IsInternal(), false); JSHandle internalAccDynClass = @@ -140,6 +144,7 @@ HWTEST_F_L0(AccessorDataTest, HasSetter) JSHandle accDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::ACCESSOR_DATA, nullHandle); ObjectHeader *accObject = factory->NewDynObject(accDynclass); AccessorData *acc = AccessorData::Cast(accObject); + acc->SetGetter(thread, JSTaggedValue::Undefined()); EXPECT_EQ(acc->HasSetter(), true); acc->SetSetter(thread, JSTaggedValue::Undefined()); EXPECT_EQ(acc->HasSetter(), false); @@ -179,6 +184,8 @@ HWTEST_F_L0(AccessorDataTest, CallInternalSet) JSHandle accDynclass1 = factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, nullPrototypeHandle); JSHandle accObject1(thread, factory->NewDynObject(accDynclass1)); + accObject1->SetGetter(thread, JSTaggedValue::Undefined()); + accObject1->SetSetter(thread, JSTaggedValue::Undefined()); JSHandle prototypeGetterFuncNativePtrHandle = factory->NewJSNativePointer(reinterpret_cast(JSFunction::PrototypeGetter), nullptr, nullptr, true); accObject1->SetGetter(thread, prototypeGetterFuncNativePtrHandle); diff --git a/ecmascript/tests/dump_test.cpp b/ecmascript/tests/dump_test.cpp index 479e9029..a1bb10cd 100644 --- a/ecmascript/tests/dump_test.cpp +++ b/ecmascript/tests/dump_test.cpp @@ -151,7 +151,7 @@ HWTEST_F_L0(EcmaDumpTest, Dump) static JSHandle NewJSMap(JSThread *thread, ObjectFactory *factory, JSHandle proto) { JSHandle mapClass = factory->NewEcmaDynClass(JSMap::SIZE, JSType::JS_MAP, proto); - JSHandle jsMap = JSHandle::Cast(factory->NewJSObject(mapClass)); + JSHandle jsMap = JSHandle::Cast(factory->NewJSObjectWithInit(mapClass)); JSHandle linkedMap(LinkedHashMap::Create(thread)); jsMap->SetLinkedMap(thread, linkedMap); return jsMap; @@ -160,7 +160,7 @@ static JSHandle NewJSMap(JSThread *thread, ObjectFactory *factory, JSHand static JSHandle NewJSSet(JSThread *thread, ObjectFactory *factory, JSHandle proto) { JSHandle setClass = factory->NewEcmaDynClass(JSSet::SIZE, JSType::JS_SET, proto); - JSHandle jsSet = JSHandle::Cast(factory->NewJSObject(setClass)); + JSHandle jsSet = JSHandle::Cast(factory->NewJSObjectWithInit(setClass)); JSHandle linkedSet(LinkedHashSet::Create(thread)); jsSet->SetLinkedSet(thread, linkedSet); return jsSet; @@ -171,7 +171,7 @@ static JSHandle NewJSAPITreeMap(JSThread *thread, ObjectFactory *f auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle mapClass = factory->NewEcmaDynClass(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto); - JSHandle jsTreeMap = JSHandle::Cast(factory->NewJSObject(mapClass)); + JSHandle jsTreeMap = JSHandle::Cast(factory->NewJSObjectWithInit(mapClass)); JSHandle treeMap(thread, TaggedTreeMap::Create(thread)); jsTreeMap->SetTreeMap(thread, treeMap); return jsTreeMap; @@ -182,7 +182,7 @@ static JSHandle NewJSAPITreeSet(JSThread *thread, ObjectFactory *f auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle setClass = factory->NewEcmaDynClass(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto); - JSHandle jsTreeSet = JSHandle::Cast(factory->NewJSObject(setClass)); + JSHandle jsTreeSet = JSHandle::Cast(factory->NewJSObjectWithInit(setClass)); JSHandle treeSet(thread, TaggedTreeSet::Create(thread)); jsTreeSet->SetTreeSet(thread, treeSet); return jsTreeSet; @@ -193,7 +193,7 @@ static JSHandle NewJSAPIPlainArray(JSThread *thread, ObjectFact auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle mapClass = factory->NewEcmaDynClass(JSAPIPlainArray::SIZE, JSType::JS_API_PLAIN_ARRAY, proto); - JSHandle jSAPIPlainArray = JSHandle::Cast(factory->NewJSObject(mapClass)); + JSHandle jSAPIPlainArray = JSHandle::Cast(factory->NewJSObjectWithInit(mapClass)); JSHandle keys = JSAPIPlainArray::CreateSlot(thread, JSAPIPlainArray::DEFAULT_CAPACITY_LENGTH); JSHandle values = @@ -217,7 +217,7 @@ static JSHandle NewJSAPIArrayList(JSThread *thread, ObjectFactor { JSHandle arrayListClass = factory->NewEcmaDynClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto); - JSHandle jsArrayList = JSHandle::Cast(factory->NewJSObject(arrayListClass)); + JSHandle jsArrayList = JSHandle::Cast(factory->NewJSObjectWithInit(arrayListClass)); jsArrayList->SetLength(thread, JSTaggedValue(0)); return jsArrayList; } @@ -225,7 +225,7 @@ static JSHandle NewJSAPIArrayList(JSThread *thread, ObjectFactor static JSHandle NewJSAPIStack(ObjectFactory *factory, JSHandle proto) { JSHandle stackClass = factory->NewEcmaDynClass(JSAPIStack::SIZE, JSType::JS_API_STACK, proto); - JSHandle jsStack = JSHandle::Cast(factory->NewJSObject(stackClass)); + JSHandle jsStack = JSHandle::Cast(factory->NewJSObjectWithInit(stackClass)); jsStack->SetTop(0); return jsStack; } @@ -245,7 +245,7 @@ static JSHandle NewJSRegExp(JSThread *thread, ObjectFactory *factory, static JSHandle NewJSAPIQueue(JSThread *thread, ObjectFactory *factory, JSHandle proto) { JSHandle queueClass = factory->NewEcmaDynClass(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto); - JSHandle jsQueue = JSHandle::Cast(factory->NewJSObject(queueClass)); + JSHandle jsQueue = JSHandle::Cast(factory->NewJSObjectWithInit(queueClass)); JSHandle newElements = factory->NewTaggedArray(JSAPIQueue::DEFAULT_CAPACITY_LENGTH); jsQueue->SetLength(thread, JSTaggedValue(0)); jsQueue->SetFront(0); @@ -257,7 +257,7 @@ static JSHandle NewJSAPIQueue(JSThread *thread, ObjectFactory *facto static JSHandle NewJSAPIDeque(JSThread *thread, ObjectFactory *factory, JSHandle proto) { JSHandle dequeClass = factory->NewEcmaDynClass(JSAPIDeque::SIZE, JSType::JS_API_DEQUE, proto); - JSHandle jsDeque = JSHandle::Cast(factory->NewJSObject(dequeClass)); + JSHandle jsDeque = JSHandle::Cast(factory->NewJSObjectWithInit(dequeClass)); JSHandle newElements = factory->NewTaggedArray(JSAPIDeque::DEFAULT_CAPACITY_LENGTH); jsDeque->SetFirst(0); jsDeque->SetLast(0); @@ -282,7 +282,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) #define NEW_OBJECT_AND_DUMP(ClassName, TypeName) \ JSHandle class##ClassName = \ factory->NewEcmaDynClass(ClassName::SIZE, JSType::TypeName, proto); \ - JSHandle object##ClassName = factory->NewJSObject(class##ClassName); \ + JSHandle object##ClassName = factory->NewJSObjectWithInit(class##ClassName); \ object##ClassName.GetTaggedValue().Dump(os); \ object##ClassName.GetTaggedValue().DumpForSnapshot(snapshotVector); @@ -325,7 +325,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) CHECK_DUMP_FIELDS(JSFunction::SIZE, JSProxyRevocFunction::SIZE, 1U) JSHandle proxyRevocClass = JSHandle::Cast(globalEnv->GetProxyRevocFunctionClass()); - JSHandle proxyRevocFunc = factory->NewJSObject(proxyRevocClass); + JSHandle proxyRevocFunc = factory->NewJSObjectWithInit(proxyRevocClass); DUMP_FOR_HANDLE(proxyRevocFunc) break; } @@ -333,7 +333,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseReactionsFunction::SIZE, 2U) JSHandle promiseReactClass = JSHandle::Cast(globalEnv->GetPromiseReactionFunctionClass()); - JSHandle promiseReactFunc = factory->NewJSObject(promiseReactClass); + JSHandle promiseReactFunc = factory->NewJSObjectWithInit(promiseReactClass); DUMP_FOR_HANDLE(promiseReactFunc) break; } @@ -341,7 +341,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseExecutorFunction::SIZE, 1U) JSHandle promiseExeClass = JSHandle::Cast(globalEnv->GetPromiseExecutorFunctionClass()); - JSHandle promiseExeFunc = factory->NewJSObject(promiseExeClass); + JSHandle promiseExeFunc = factory->NewJSObjectWithInit(promiseExeClass); DUMP_FOR_HANDLE(promiseExeFunc) break; } @@ -349,7 +349,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAllResolveElementFunction::SIZE, 5U) JSHandle promiseAllClass = JSHandle::Cast(globalEnv->GetPromiseAllResolveElementFunctionClass()); - JSHandle promiseAllFunc = factory->NewJSObject(promiseAllClass); + JSHandle promiseAllFunc = factory->NewJSObjectWithInit(promiseAllClass); DUMP_FOR_HANDLE(promiseAllFunc) break; } @@ -398,7 +398,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) case JSType::JS_WEAK_MAP: { CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakMap::SIZE, 1U) JSHandle weakMapClass = factory->NewEcmaDynClass(JSWeakMap::SIZE, JSType::JS_WEAK_MAP, proto); - JSHandle jsWeakMap = JSHandle::Cast(factory->NewJSObject(weakMapClass)); + JSHandle jsWeakMap = JSHandle::Cast(factory->NewJSObjectWithInit(weakMapClass)); JSHandle weakLinkedMap(LinkedHashMap::Create(thread)); jsWeakMap->SetLinkedMap(thread, weakLinkedMap); DUMP_FOR_HANDLE(jsWeakMap) @@ -407,7 +407,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) case JSType::JS_WEAK_SET: { CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakSet::SIZE, 1U) JSHandle weakSetClass = factory->NewEcmaDynClass(JSWeakSet::SIZE, JSType::JS_WEAK_SET, proto); - JSHandle jsWeakSet = JSHandle::Cast(factory->NewJSObject(weakSetClass)); + JSHandle jsWeakSet = JSHandle::Cast(factory->NewJSObjectWithInit(weakSetClass)); JSHandle weakLinkedSet(LinkedHashSet::Create(thread)); jsWeakSet->SetLinkedSet(thread, weakLinkedSet); DUMP_FOR_HANDLE(jsWeakSet) @@ -416,7 +416,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) case JSType::JS_DATE: { CHECK_DUMP_FIELDS(JSObject::SIZE, JSDate::SIZE, 2U) JSHandle dateClass = factory->NewEcmaDynClass(JSDate::SIZE, JSType::JS_DATE, proto); - JSHandle date = JSHandle::Cast(factory->NewJSObject(dateClass)); + JSHandle date = JSHandle::Cast(factory->NewJSObjectWithInit(dateClass)); date->SetTimeValue(thread, JSTaggedValue(0.0)); date->SetLocalOffset(thread, JSTaggedValue(0.0)); DUMP_FOR_HANDLE(date) @@ -724,6 +724,8 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) JSHandle pendingClass(thread, JSHClass::Cast(globalConst->GetPendingJobClass().GetTaggedObject())); JSHandle pendingJob(thread, factory->NewDynObject(pendingClass)); + ecmascript::job::PendingJob::Cast(*pendingJob)->SetJob(JSTaggedValue::Undefined()); + ecmascript::job::PendingJob::Cast(*pendingJob)->SetArguments(JSTaggedValue::Undefined()); DUMP_FOR_HANDLE(pendingJob) break; } diff --git a/ecmascript/tests/test_helper.h b/ecmascript/tests/test_helper.h index f42f079d..6e6647ec 100644 --- a/ecmascript/tests/test_helper.h +++ b/ecmascript/tests/test_helper.h @@ -51,7 +51,9 @@ public: JSTaggedType *sp = const_cast(thread->GetCurrentSPFrame()); size_t frameSize = ecmascript::INTERPRETER_FRAME_STATE_SIZE + numActualArgs; JSTaggedType *newSp = sp - frameSize; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - + for (int i = numActualArgs; i > 0; i--) { + newSp[i - 1] = JSTaggedValue::Undefined().GetRawData(); + } auto callInfo = std::make_unique(thread, numActualArgs - NUM_MANDATORY_JSFUNC_ARGS, newSp); callInfo->SetNewTarget(newTgt); return callInfo;