reason:performance optimization

description:optimize taggedvalue encode
issue:https://gitee.com/openharmony/ark_js_runtime/issues/I55ZVP?from=project-issue

Signed-off-by: wupengyong <wupengyong@huawei.com>
Change-Id: I747a60f5ea7348d3b0cfc041a3b010c52b1517c0
This commit is contained in:
wupengyong
2022-05-20 17:32:34 +08:00
parent 0bd7febe37
commit 7c650ba015
13 changed files with 430 additions and 344 deletions
+47 -46
View File
@@ -415,7 +415,7 @@ void Builtins::InitializeFunction(const JSHandle<GlobalEnv> &env, const JSHandle
JSHandle<JSHClass> funcFuncIntanceDynclass =
factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, funcFuncPrototypeValue);
funcFuncIntanceDynclass->SetConstructor(true);
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(factory_->NewJSObject(funcFuncIntanceDynclass));
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(factory_->NewJSObjectWithInit(funcFuncIntanceDynclass));
function->SetBuiltinsCtorMode();
// Function = new Function() (forbidden use NewBuiltinConstructor)
@@ -443,7 +443,7 @@ void Builtins::InitializeFunction(const JSHandle<GlobalEnv> &env, const JSHandle
factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetFunctionPrototype());
constructorFunctionClass->SetConstructor(true);
JSHandle<JSFunction> functionConstructor =
JSHandle<JSFunction>::Cast(factory_->NewJSObject(constructorFunctionClass));
JSHandle<JSFunction>::Cast(factory_->NewJSObjectWithInit(constructorFunctionClass));
functionConstructor->SetBuiltinsCtorMode();
env->SetConstructorFunctionClass(thread_, constructorFunctionClass);
@@ -535,7 +535,7 @@ void Builtins::InitializeSymbol(const JSHandle<GlobalEnv> &env, const JSHandle<J
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
// Symbol.prototype
JSHandle<JSObject> symbolFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> symbolFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> symbolFuncPrototypeValue(symbolFuncPrototype);
// Symbol.prototype_or_dynclass
@@ -631,7 +631,7 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle<GlobalEnv> &realm,
[[maybe_unused]] EcmaHandleScope scope(thread_);
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
// Symbol.prototype
JSHandle<JSObject> symbolFuncPrototype = factory_->NewJSObject(objFuncInstanceDynclass);
JSHandle<JSObject> symbolFuncPrototype = factory_->NewJSObjectWithInit(objFuncInstanceDynclass);
JSHandle<JSTaggedValue> symbolFuncPrototypeValue(symbolFuncPrototype);
// Symbol.prototype_or_dynclass
@@ -769,7 +769,7 @@ void Builtins::InitializeBigInt(const JSHandle<GlobalEnv> &env, const JSHandle<J
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// BigInt.prototype
JSHandle<JSObject> bigIntFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> bigIntFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> bigIntFuncPrototypeValue(bigIntFuncPrototype);
// BigInt.prototype_or_dynclass
@@ -800,7 +800,7 @@ void Builtins::InitializeDate(const JSHandle<GlobalEnv> &env, const JSHandle<JSH
[[maybe_unused]] EcmaHandleScope scope(thread_);
const int utcLength = 7;
// Date.prototype
JSHandle<JSObject> dateFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> dateFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> dateFuncPrototypeValue(dateFuncPrototype);
// Date.prototype_or_dynclass
@@ -933,7 +933,7 @@ void Builtins::InitializeAsyncFunction(const JSHandle<GlobalEnv> &env, const JSH
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
// AsyncFunction.prototype
JSHandle<JSObject> asyncFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> asyncFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSObject::SetPrototype(thread_, asyncFuncPrototype, env->GetFunctionPrototype());
JSHandle<JSTaggedValue> async_func_prototype_value(asyncFuncPrototype);
@@ -959,7 +959,7 @@ void Builtins::InitializeAsyncFunction(const JSHandle<GlobalEnv> &env, const JSH
void Builtins::InitializeAllTypeError(const JSHandle<GlobalEnv> &env, const JSHandle<JSHClass> &objFuncDynclass) const
{
// Error.prototype
JSHandle<JSObject> errorFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> errorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> errorFuncPrototypeValue(errorFuncPrototype);
// Error.prototype_or_dynclass
JSHandle<JSHClass> errorFuncInstanceDynclass =
@@ -981,7 +981,7 @@ void Builtins::InitializeAllTypeError(const JSHandle<GlobalEnv> &env, const JSHa
JSHandle<JSHClass> nativeErrorFuncClass =
factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetErrorFunction());
nativeErrorFuncClass->SetConstructor(true);
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(factory_->NewJSObject(nativeErrorFuncClass));
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(factory_->NewJSObjectWithInit(nativeErrorFuncClass));
function->SetBuiltinsCtorMode();
env->SetNativeErrorFunctionClass(thread_, nativeErrorFuncClass);
@@ -1068,7 +1068,7 @@ void Builtins::InitializeError(const JSHandle<GlobalEnv> &env, const JSHandle<JS
const JSType &errorTag) const
{
// NativeError.prototype
JSHandle<JSObject> nativeErrorFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> nativeErrorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> nativeErrorFuncPrototypeValue(nativeErrorFuncPrototype);
ErrorParameter errorParameter{RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError",
@@ -1169,7 +1169,7 @@ void Builtins::InitializeSet(const JSHandle<GlobalEnv> &env, const JSHandle<JSHC
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
// Set.prototype
JSHandle<JSObject> setFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> setFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> setFuncPrototypeValue(setFuncPrototype);
// Set.prototype_or_dynclass
JSHandle<JSHClass> setFuncInstanceDynclass =
@@ -1230,7 +1230,7 @@ void Builtins::InitializeMap(const JSHandle<GlobalEnv> &env, const JSHandle<JSHC
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
// Map.prototype
JSHandle<JSObject> mapFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> mapFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> mapFuncPrototypeValue(mapFuncPrototype);
// Map.prototype_or_dynclass
JSHandle<JSHClass> mapFuncInstanceDynclass =
@@ -1295,7 +1295,7 @@ void Builtins::InitializeWeakMap(const JSHandle<GlobalEnv> &env, const JSHandle<
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
// WeakMap.prototype
JSHandle<JSObject> weakMapFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> weakMapFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> weakMapFuncPrototypeValue(weakMapFuncPrototype);
// WeakMap.prototype_or_dynclass
JSHandle<JSHClass> weakMapFuncInstanceDynclass =
@@ -1331,7 +1331,7 @@ void Builtins::InitializeWeakSet(const JSHandle<GlobalEnv> &env, const JSHandle<
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
// Set.prototype
JSHandle<JSObject> weakSetFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> weakSetFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> weakSetFuncPrototypeValue(weakSetFuncPrototype);
// Set.prototype_or_dynclass
JSHandle<JSHClass> weakSetFuncInstanceDynclass =
@@ -1361,7 +1361,7 @@ void Builtins::InitializeMath(const JSHandle<GlobalEnv> &env, const JSHandle<JST
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
JSHandle<JSHClass> mathDynclass = factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, objFuncPrototypeVal);
JSHandle<JSObject> mathObject = factory_->NewJSObject(mathDynclass);
JSHandle<JSObject> 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<GlobalEnv> &env, const JSHandle<JST
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
JSHandle<JSHClass> jsonDynclass = factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, objFuncPrototypeVal);
JSHandle<JSObject> jsonObject = factory_->NewJSObject(jsonDynclass);
JSHandle<JSObject> 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<GlobalEnv> &env,
const JSHandle<JSHClass> &iteratorFuncDynclass) const
{
// StringIterator.prototype
JSHandle<JSObject> strIterPrototype(factory_->NewJSObject(iteratorFuncDynclass));
JSHandle<JSObject> strIterPrototype(factory_->NewJSObjectWithInit(iteratorFuncDynclass));
// StringIterator.prototype_or_dynclass
JSHandle<JSHClass> strIterFuncInstanceDynclass = factory_->NewEcmaDynClass(
@@ -1522,7 +1522,7 @@ void Builtins::InitializeIterator(const JSHandle<GlobalEnv> &env, const JSHandle
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Iterator.prototype
JSHandle<JSObject> iteratorPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> 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<GlobalEnv> &env,
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Iterator.prototype
JSHandle<JSObject> forinIteratorPrototype = factory_->NewJSObject(iteratorFuncDynclass);
JSHandle<JSObject> forinIteratorPrototype = factory_->NewJSObjectWithInit(iteratorFuncDynclass);
JSHandle<JSHClass> dynclass = factory_->NewEcmaDynClass(JSForInIterator::SIZE, JSType::JS_FORIN_ITERATOR,
JSHandle<JSTaggedValue>(forinIteratorPrototype));
@@ -1568,7 +1568,7 @@ void Builtins::InitializeSetIterator(const JSHandle<GlobalEnv> &env,
const JSHandle<JSHClass> &iteratorFuncDynclass) const
{
// SetIterator.prototype
JSHandle<JSObject> setIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass));
JSHandle<JSObject> 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<GlobalEnv> &env,
const JSHandle<JSHClass> &iteratorFuncDynclass) const
{
// MapIterator.prototype
JSHandle<JSObject> mapIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass));
JSHandle<JSObject> 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<GlobalEnv> &env,
const JSHandle<JSHClass> &iteratorFuncDynclass) const
{
// ArrayIterator.prototype
JSHandle<JSObject> arrayIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass));
JSHandle<JSObject> 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<GlobalEnv> &env, const JSHandle<JS
JSHandle<JSHClass> arrBaseFuncInstanceDynclass = factory_->CreateJSArrayInstanceClass(objFuncPrototypeVal);
// Array.prototype
JSHandle<JSObject> arrFuncPrototype = factory_->NewJSObject(arrBaseFuncInstanceDynclass);
JSHandle<JSObject> arrFuncPrototype = factory_->NewJSObjectWithInit(arrBaseFuncInstanceDynclass);
JSHandle<JSArray>::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<GlobalEnv> &env, const JSHand
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// TypedArray.prototype
JSHandle<JSObject> typedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> typedArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> typedArrFuncPrototypeValue(typedArrFuncPrototype);
// TypedArray.prototype_or_dynclass
@@ -1896,7 +1896,8 @@ void Builtins::InitializeTypedArray(const JSHandle<GlobalEnv> &env, const JSHand
JSHandle<JSHClass> specificTypedArrayFuncClass =
factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetTypedArrayFunction());
specificTypedArrayFuncClass->SetConstructor(true);
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(factory_->NewJSObject(specificTypedArrayFuncClass));
JSHandle<JSFunction> function =
JSHandle<JSFunction>::Cast(factory_->NewJSObjectWithInit(specificTypedArrayFuncClass));
function->SetBuiltinsCtorMode();
env->SetSpecificTypedArrayFunctionClass(thread_, specificTypedArrayFuncClass);
@@ -1917,7 +1918,7 @@ void Builtins::InitializeInt8Array(const JSHandle<GlobalEnv> &env, const JSHandl
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Int8Array.prototype
JSHandle<JSObject> int8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> int8ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> int8ArrFuncPrototypeValue(int8ArrFuncPrototype);
// Int8Array.prototype_or_dynclass
@@ -1941,7 +1942,7 @@ void Builtins::InitializeUint8Array(const JSHandle<GlobalEnv> &env, const JSHand
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Uint8Array.prototype
JSHandle<JSObject> uint8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> uint8ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> uint8ArrFuncPrototypeValue(uint8ArrFuncPrototype);
// Uint8Array.prototype_or_dynclass
@@ -1966,7 +1967,7 @@ void Builtins::InitializeUint8ClampedArray(const JSHandle<GlobalEnv> &env,
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Uint8ClampedArray.prototype
JSHandle<JSObject> uint8ClampedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> uint8ClampedArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> uint8ClampedArrFuncPrototypeValue(uint8ClampedArrFuncPrototype);
// Uint8ClampedArray.prototype_or_dynclass
@@ -1992,7 +1993,7 @@ void Builtins::InitializeInt16Array(const JSHandle<GlobalEnv> &env, const JSHand
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Int16Array.prototype
JSHandle<JSObject> int16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> int16ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> int16ArrFuncPrototypeValue(int16ArrFuncPrototype);
// Int16Array.prototype_or_dynclass
@@ -2016,7 +2017,7 @@ void Builtins::InitializeUint16Array(const JSHandle<GlobalEnv> &env, const JSHan
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Uint16Array.prototype
JSHandle<JSObject> uint16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> uint16ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> uint16ArrFuncPrototypeValue(uint16ArrFuncPrototype);
// Uint16Array.prototype_or_dynclass
@@ -2040,7 +2041,7 @@ void Builtins::InitializeInt32Array(const JSHandle<GlobalEnv> &env, const JSHand
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Int32Array.prototype
JSHandle<JSObject> int32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> int32ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> int32ArrFuncPrototypeValue(int32ArrFuncPrototype);
// Int32Array.prototype_or_dynclass
@@ -2064,7 +2065,7 @@ void Builtins::InitializeUint32Array(const JSHandle<GlobalEnv> &env, const JSHan
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Uint32Array.prototype
JSHandle<JSObject> uint32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> uint32ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> uint32ArrFuncPrototypeValue(uint32ArrFuncPrototype);
// Uint32Array.prototype_or_dynclass
@@ -2088,7 +2089,7 @@ void Builtins::InitializeFloat32Array(const JSHandle<GlobalEnv> &env, const JSHa
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Float32Array.prototype
JSHandle<JSObject> float32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> float32ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> float32ArrFuncPrototypeValue(float32ArrFuncPrototype);
// Float32Array.prototype_or_dynclass
@@ -2112,7 +2113,7 @@ void Builtins::InitializeFloat64Array(const JSHandle<GlobalEnv> &env, const JSHa
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Float64Array.prototype
JSHandle<JSObject> float64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> float64ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> float64ArrFuncPrototypeValue(float64ArrFuncPrototype);
// Float64Array.prototype_or_dynclass
@@ -2136,7 +2137,7 @@ void Builtins::InitializeBigInt64Array(const JSHandle<GlobalEnv> &env, const JSH
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// BigInt64Array.prototype
JSHandle<JSObject> bigInt64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> bigInt64ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> bigInt64ArrFuncPrototypeValue(bigInt64ArrFuncPrototype);
// BigInt64Array.prototype_or_dynclass
@@ -2160,7 +2161,7 @@ void Builtins::InitializeBigUint64Array(const JSHandle<GlobalEnv> &env, const JS
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// BigUint64Array.prototype
JSHandle<JSObject> bigUint64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> bigUint64ArrFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> bigUint64ArrFuncPrototypeValue(bigUint64ArrFuncPrototype);
// BigUint64Array.prototype_or_dynclass
@@ -2184,7 +2185,7 @@ void Builtins::InitializeArrayBuffer(const JSHandle<GlobalEnv> &env, const JSHan
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// ArrayBuffer.prototype
JSHandle<JSObject> arrayBufferFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> arrayBufferFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> arrayBufferFuncPrototypeValue(arrayBufferFuncPrototype);
// ArrayBuffer.prototype_or_dynclass
@@ -2228,7 +2229,7 @@ void Builtins::InitializeReflect(const JSHandle<GlobalEnv> &env,
[[maybe_unused]] EcmaHandleScope scope(thread_);
JSHandle<JSHClass> reflectDynclass =
factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, objFuncPrototypeVal);
JSHandle<JSObject> reflectObject = factory_->NewJSObject(reflectDynclass);
JSHandle<JSObject> 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<GlobalEnv> &env,
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// SharedArrayBuffer.prototype
JSHandle<JSObject> sharedArrayBufferFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> sharedArrayBufferFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> sharedArrayBufferFuncPrototypeValue(sharedArrayBufferFuncPrototype);
// SharedArrayBuffer.prototype_or_dynclass
@@ -2305,7 +2306,7 @@ void Builtins::InitializePromise(const JSHandle<GlobalEnv> &env, const JSHandle<
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// Promise.prototype
JSHandle<JSObject> promiseFuncPrototype = factory_->NewJSObject(promiseFuncDynclass);
JSHandle<JSObject> promiseFuncPrototype = factory_->NewJSObjectWithInit(promiseFuncDynclass);
JSHandle<JSTaggedValue> promiseFuncPrototypeValue(promiseFuncPrototype);
// Promise.prototype_or_dynclass
JSHandle<JSHClass> promiseFuncInstanceDynclass =
@@ -2350,7 +2351,7 @@ void Builtins::InitializeDataView(const JSHandle<GlobalEnv> &env, const JSHandle
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// ArrayBuffer.prototype
JSHandle<JSObject> dataViewFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> dataViewFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> dataViewFuncPrototypeValue(dataViewFuncPrototype);
// ArrayBuffer.prototype_or_dynclass
@@ -2575,7 +2576,7 @@ void Builtins::InitializeGeneratorFunction(const JSHandle<GlobalEnv> &env,
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSObject> generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> generatorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> generatorFuncPrototypeValue(generatorFuncPrototype);
// 26.3.3.1 GeneratorFunction.prototype.constructor
@@ -2621,7 +2622,7 @@ void Builtins::InitializeGenerator(const JSHandle<GlobalEnv> &env, const JSHandl
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
JSHandle<JSObject> generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> generatorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
// GeneratorObject.prototype method
// 26.5.1.2 Generator.prototype.next(value)
@@ -2641,7 +2642,7 @@ void Builtins::InitializeGenerator(const JSHandle<GlobalEnv> &env, const JSHandl
JSObject::SetPrototype(thread_, generatorFuncPrototype, env->GetIteratorPrototype());
// Generator {}
JSHandle<JSObject> initialGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> initialGeneratorFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, JSHandle<JSTaggedValue>(generatorFuncPrototype));
env->SetInitialGenerator(thread_, initialGeneratorFuncPrototype);
}
@@ -2715,7 +2716,7 @@ void Builtins::InitializeIntl(const JSHandle<GlobalEnv> &env, const JSHandle<JST
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
JSHandle<JSHClass> intlDynclass = factory_->NewEcmaDynClass(JSObject::SIZE, JSType::JS_INTL, objFuncPrototypeValue);
JSHandle<JSObject> intlObject = factory_->NewJSObject(intlDynclass);
JSHandle<JSObject> intlObject = factory_->NewJSObjectWithInit(intlDynclass);
JSHandle<JSTaggedValue> initIntlSymbol(factory_->NewPublicSymbolWithChar("Symbol.IntlLegacyConstructedSymbol"));
SetNoneAttributeProperty(intlObject, "fallbackSymbol", initIntlSymbol);
@@ -3087,7 +3088,7 @@ void Builtins::InitializeModuleNamespace(const JSHandle<GlobalEnv> &env,
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// ModuleNamespace.prototype
JSHandle<JSObject> moduleNamespacePrototype = factory_->NewJSObject(objFuncDynclass);
JSHandle<JSObject> moduleNamespacePrototype = factory_->NewJSObjectWithInit(objFuncDynclass);
JSHandle<JSTaggedValue> moduleNamespacePrototypeValue(moduleNamespacePrototype);
// ModuleNamespace.prototype_or_dynclass
@@ -2305,7 +2305,7 @@ void BytecodeCircuitBuilder::NewReturn(BytecodeRegion &bb, const uint8_t *pc, Ga
} else if (static_cast<EcmaOpcode>(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,
+8 -15
View File
@@ -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)
+1 -1
View File
@@ -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)
@@ -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))) {
+1 -1
View File
@@ -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
+17 -13
View File
@@ -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<JSTaggedType>(false);
static constexpr JSTaggedType VALUE_TRUE =
TAG_OBJECT | TAG_BOOLEAN | TAG_SPECIAL_VALUE | static_cast<JSTaggedType>(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
+1 -1
View File
@@ -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)
+322 -246
View File
@@ -352,7 +352,7 @@ JSHandle<TaggedArray> ObjectFactory::CloneProperties(const JSHandle<TaggedArray>
auto header = heap_->AllocateYoungOrHugeObject(klass, size);
JSHandle<TaggedArray> 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<TaggedArray> ObjectFactory::CloneProperties(const JSHandle<TaggedArray>
size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength);
auto header = heap_->AllocateYoungOrHugeObject(klass, size);
JSHandle<TaggedArray> newArray(thread_, header);
newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength);
newArray->SetLength(newLength);
for (uint32_t i = 0; i < newLength; i++) {
@@ -535,6 +536,7 @@ JSHandle<JSObject> ObjectFactory::NewNonMovableJSObject(const JSHandle<JSHClass>
{
JSHandle<JSObject> 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<JSObject> ObjectFactory::NewJSObjectByConstructor(const JSHandle<JSFunc
}
// Check this exception elsewhere
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread_);
return NewJSObjectWithInit(jshclass);
}
JSHandle<JSObject> ObjectFactory::NewJSObjectWithInit(const JSHandle<JSHClass> &jshclass)
{
JSHandle<JSObject> 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<JSObject> &obj, const JSHandle<JSHClass> &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<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
break;
case JSType::JS_PROXY_REVOC_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSProxyRevocFunction::Cast(*obj)->SetRevocableProxy(JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_REACTIONS_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(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<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSPromiseExecutorFunction::Cast(*obj)->SetCapability(JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(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<JSFunction>(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<JSIntlBoundFunction> ObjectFactory::NewJSIntlBoundFunction(const void *
JSHandle<JSHClass> dynclass = JSHandle<JSHClass>::Cast(env->GetJSIntlBoundFunctionClass());
JSHandle<JSIntlBoundFunction> intlBoundFunc = JSHandle<JSIntlBoundFunction>::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<JSFunction> function = JSHandle<JSFunction>::Cast(intlBoundFunc);
@@ -1260,6 +1316,7 @@ JSHandle<JSProxyRevocFunction> ObjectFactory::NewJSProxyRevocFunction(const JSHa
JSHandle<JSHClass> dynclass = JSHandle<JSHClass>::Cast(env->GetProxyRevocFunctionClass());
JSHandle<JSProxyRevocFunction> revocFunction = JSHandle<JSProxyRevocFunction>::Cast(NewJSObject(dynclass));
revocFunction->SetRevocableProxy(JSTaggedValue::Undefined());
revocFunction->SetRevocableProxy(thread_, proxy);
JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc);
@@ -1281,7 +1338,7 @@ JSHandle<JSAsyncAwaitStatusFunction> ObjectFactory::NewJSAsyncAwaitStatusFunctio
JSHandle<JSAsyncAwaitStatusFunction> awaitFunction =
JSHandle<JSAsyncAwaitStatusFunction>::Cast(NewJSObject(dynclass));
awaitFunction->SetAsyncContext(JSTaggedValue::Undefined());
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>::Cast(awaitFunction));
JSMethod *target = vm_->GetMethodForNativeFunction(nativeFunc);
awaitFunction->SetCallTarget(thread_, target);
@@ -1308,6 +1365,8 @@ JSHandle<JSGeneratorObject> ObjectFactory::NewJSGeneratorObject(JSHandle<JSTagge
}
JSHandle<JSHClass> dynclass = NewEcmaDynClass(JSGeneratorObject::SIZE, JSType::JS_GENERATOR_OBJECT, proto);
JSHandle<JSGeneratorObject> generatorObject = JSHandle<JSGeneratorObject>::Cast(NewJSObject(dynclass));
generatorObject->SetGeneratorContext(JSTaggedValue::Undefined());
generatorObject->SetResumeResult(JSTaggedValue::Undefined());
return generatorObject;
}
@@ -1326,7 +1385,7 @@ JSHandle<JSAsyncFuncObject> ObjectFactory::NewJSAsyncFuncObject()
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
JSHandle<JSTaggedValue> proto = env->GetInitialGenerator();
JSHandle<JSHClass> dynclass = NewEcmaDynClass(JSAsyncFuncObject::SIZE, JSType::JS_ASYNC_FUNC_OBJECT, proto);
JSHandle<JSAsyncFuncObject> asyncFuncObject = JSHandle<JSAsyncFuncObject>::Cast(NewJSObject(dynclass));
JSHandle<JSAsyncFuncObject> asyncFuncObject = JSHandle<JSAsyncFuncObject>::Cast(NewJSObjectWithInit(dynclass));
return asyncFuncObject;
}
@@ -1551,6 +1610,8 @@ JSHandle<AccessorData> ObjectFactory::NewInternalAccessor(void *setter, void *ge
TaggedObject *header = heap_->AllocateNonMovableOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetInternalAccessorClass().GetTaggedObject()));
JSHandle<AccessorData> obj(thread_, AccessorData::Cast(header));
obj->SetGetter(thread_, JSTaggedValue::Undefined());
obj->SetSetter(thread_, JSTaggedValue::Undefined());
if (setter != nullptr) {
JSHandle<JSNativePointer> setFunc = NewJSNativePointer(setter, nullptr, nullptr, true);
obj->SetSetter(thread_, setFunc.GetTaggedValue());
@@ -1670,6 +1731,7 @@ JSHandle<JSRealm> ObjectFactory::NewJSRealm()
JSHandle<JSHClass> dynHandle = NewEcmaDynClass(JSRealm::SIZE, JSType::JS_REALM, protoValue);
JSHandle<JSRealm> realm(NewJSObject(dynHandle));
realm->SetGlobalEnv(thread_, realmEnvHandle.GetTaggedValue());
realm->SetValue(JSTaggedValue::Undefined());
JSHandle<JSTaggedValue> realmObj = realmEnvHandle->GetJSGlobalObject();
JSHandle<JSTaggedValue> realmkey(thread_->GlobalConstants()->GetHandledGlobalString());
@@ -1797,6 +1859,7 @@ JSHandle<TaggedArray> ObjectFactory::CopyPartArray(const JSHandle<TaggedArray> &
auto header = heap_->AllocateYoungOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size);
JSHandle<TaggedArray> newArray(thread_, header);
newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength);
newArray->SetLength(newLength);
for (uint32_t i = 0; i < newLength; i++) {
@@ -1825,6 +1888,7 @@ JSHandle<TaggedArray> ObjectFactory::CopyArray(const JSHandle<TaggedArray> &old,
auto header = heap_->AllocateYoungOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size);
JSHandle<TaggedArray> newArray(thread_, header);
newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength);
newArray->SetLength(newLength);
for (uint32_t i = 0; i < newLength; i++) {
@@ -2163,6 +2227,11 @@ JSHandle<JSPromiseAllResolveElementFunction> ObjectFactory::NewJSPromiseAllResol
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>::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<JSFunction>::Cast(function), JSTaggedValue(1));
return function;
}
@@ -2184,6 +2253,8 @@ JSHandle<TransitionHandler> ObjectFactory::NewTransitionHandler()
TransitionHandler *handler =
TransitionHandler::Cast(heap_->AllocateYoungOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetTransitionHandlerClass().GetTaggedObject())));
handler->SetHandlerInfo(JSTaggedValue::Undefined());
handler->SetTransitionHClass(JSTaggedValue::Undefined());
return JSHandle<TransitionHandler>(thread_, handler);
}
@@ -2312,7 +2383,7 @@ JSHandle<JSHClass> ObjectFactory::GetObjectLiteralHClass(const JSHandle<TaggedAr
JSHandle<JSObject> ObjectFactory::GetObjectLiteralByHClass(const JSHandle<TaggedArray> &properties, size_t length)
{
JSHandle<JSHClass> dynclass = GetObjectLiteralHClass(properties, length);
JSHandle<JSObject> obj = NewJSObject(dynclass);
JSHandle<JSObject> obj = NewJSObjectWithInit(dynclass);
return obj;
}
@@ -2383,14 +2454,12 @@ JSHandle<TSObjectType> ObjectFactory::NewTSObjectType(uint32_t numOfKeys)
TaggedObject *header = heap_->AllocateYoungOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetTSObjectTypeClass().GetTaggedObject()));
JSHandle<TSObjectType> objectType(thread_, header);
objectType->SetHClass(thread_, JSTaggedValue::Undefined());
objectType->SetObjLayoutInfo(thread_, JSTaggedValue::Undefined());
objectType->SetGTRef(GlobalTSTypeRef::Default());
JSHandle<TSObjLayoutInfo> tsPropInfo = CreateTSObjLayoutInfo(numOfKeys);
objectType->SetObjLayoutInfo(thread_, tsPropInfo);
objectType->SetHClass(thread_, JSTaggedValue::Undefined());
return objectType;
}
@@ -2438,6 +2507,7 @@ JSHandle<TSUnionType> ObjectFactory::NewTSUnionType(uint32_t length)
JSHandle<TSUnionType> unionType(thread_, header);
unionType->SetGTRef(GlobalTSTypeRef::Default());
unionType->SetComponentTypes(thread_, JSTaggedValue::Undefined());
JSHandle<TaggedArray> componentTypes = NewTaggedArray(length, JSTaggedValue::Undefined());
unionType->SetComponentTypes(thread_, componentTypes);
@@ -2480,6 +2550,7 @@ JSHandle<TSFunctionType> ObjectFactory::NewTSFunctionType(uint32_t length)
TaggedObject *header = heap_->AllocateYoungOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetTSFunctionTypeClass().GetTaggedObject()));
JSHandle<TSFunctionType> functionType(thread_, header);
functionType->SetParameterTypes(thread_, JSTaggedValue::Undefined());
JSHandle<TaggedArray> parameterTypes = NewTaggedArray(length + TSFunctionType::DEFAULT_LENGTH,
JSTaggedValue::Undefined());
@@ -2711,6 +2782,7 @@ JSHandle<TaggedArray> ObjectFactory::CopyDeque(const JSHandle<TaggedArray> &old,
auto header = heap_->AllocateYoungOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size);
JSHandle<TaggedArray> 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<TaggedArray> ObjectFactory::CopyQueue(const JSHandle<TaggedArray> &old,
auto header = heap_->AllocateYoungOrHugeObject(
JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), size);
JSHandle<TaggedArray> newArray(thread_, header);
newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength);
newArray->SetLength(newLength);
for (uint32_t i = 0; i < oldLength; i++) {
@@ -2786,6 +2859,7 @@ JSHandle<JSAPITreeMapIterator> ObjectFactory::NewJSAPITreeMapIterator(const JSHa
iter->GetJSHClass()->SetExtensible(true);
iter->SetIteratedMap(thread_, map);
iter->SetNextIndex(0);
iter->SetEntries(JSTaggedValue::Undefined());
iter->SetIterationKind(kind);
JSHandle<TaggedTreeMap> tmap(thread_, map->GetTreeMap());
JSHandle<TaggedArray> entries = TaggedTreeMap::GetArrayFromMap(thread_, tmap);
@@ -2805,6 +2879,7 @@ JSHandle<JSAPITreeSetIterator> ObjectFactory::NewJSAPITreeSetIterator(const JSHa
iter->GetJSHClass()->SetExtensible(true);
iter->SetIteratedSet(thread_, set);
iter->SetNextIndex(0);
iter->SetEntries(JSTaggedValue::Undefined());
iter->SetIterationKind(kind);
JSHandle<TaggedTreeSet> tset(thread_, set->GetTreeSet());
JSHandle<TaggedArray> entries = TaggedTreeSet::GetArrayFromSet(thread_, tset);
@@ -2863,6 +2938,7 @@ JSHandle<SourceTextModule> 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);
+2 -1
View File
@@ -363,7 +363,8 @@ public:
// used for creating jsobject by constructor
JSHandle<JSObject> NewJSObjectByConstructor(const JSHandle<JSFunction> &constructor,
const JSHandle<JSTaggedValue> &newTarget);
void InitializeJSObject(const JSHandle<JSObject> &obj, const JSHandle<JSHClass> &jshclass);
JSHandle<JSObject> NewJSObjectWithInit(const JSHandle<JSHClass> &jshclass);
uintptr_t NewSpaceBySnapshotAllocator(size_t size);
JSHandle<MachineCode> NewMachineCodeObject(size_t length, const uint8_t *data);
JSHandle<ClassInfoExtractor> NewClassInfoExtractor(JSMethod *ctorMethod);
+7
View File
@@ -63,6 +63,8 @@ HWTEST_F_L0(AccessorDataTest, AccessorData_Cast)
JSHandle<JSHClass> 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<JSHClass> 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<JSHClass> internalAccDynClass =
@@ -140,6 +144,7 @@ HWTEST_F_L0(AccessorDataTest, HasSetter)
JSHandle<JSHClass> 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<JSHClass> accDynclass1 =
factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, nullPrototypeHandle);
JSHandle<AccessorData> accObject1(thread, factory->NewDynObject(accDynclass1));
accObject1->SetGetter(thread, JSTaggedValue::Undefined());
accObject1->SetSetter(thread, JSTaggedValue::Undefined());
JSHandle<JSNativePointer> prototypeGetterFuncNativePtrHandle =
factory->NewJSNativePointer(reinterpret_cast<void *>(JSFunction::PrototypeGetter), nullptr, nullptr, true);
accObject1->SetGetter(thread, prototypeGetterFuncNativePtrHandle);
+19 -17
View File
@@ -151,7 +151,7 @@ HWTEST_F_L0(EcmaDumpTest, Dump)
static JSHandle<JSMap> NewJSMap(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
{
JSHandle<JSHClass> mapClass = factory->NewEcmaDynClass(JSMap::SIZE, JSType::JS_MAP, proto);
JSHandle<JSMap> jsMap = JSHandle<JSMap>::Cast(factory->NewJSObject(mapClass));
JSHandle<JSMap> jsMap = JSHandle<JSMap>::Cast(factory->NewJSObjectWithInit(mapClass));
JSHandle<LinkedHashMap> linkedMap(LinkedHashMap::Create(thread));
jsMap->SetLinkedMap(thread, linkedMap);
return jsMap;
@@ -160,7 +160,7 @@ static JSHandle<JSMap> NewJSMap(JSThread *thread, ObjectFactory *factory, JSHand
static JSHandle<JSSet> NewJSSet(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
{
JSHandle<JSHClass> setClass = factory->NewEcmaDynClass(JSSet::SIZE, JSType::JS_SET, proto);
JSHandle<JSSet> jsSet = JSHandle<JSSet>::Cast(factory->NewJSObject(setClass));
JSHandle<JSSet> jsSet = JSHandle<JSSet>::Cast(factory->NewJSObjectWithInit(setClass));
JSHandle<LinkedHashSet> linkedSet(LinkedHashSet::Create(thread));
jsSet->SetLinkedSet(thread, linkedSet);
return jsSet;
@@ -171,7 +171,7 @@ static JSHandle<JSAPITreeMap> NewJSAPITreeMap(JSThread *thread, ObjectFactory *f
auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
JSHandle<JSHClass> mapClass = factory->NewEcmaDynClass(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto);
JSHandle<JSAPITreeMap> jsTreeMap = JSHandle<JSAPITreeMap>::Cast(factory->NewJSObject(mapClass));
JSHandle<JSAPITreeMap> jsTreeMap = JSHandle<JSAPITreeMap>::Cast(factory->NewJSObjectWithInit(mapClass));
JSHandle<TaggedTreeMap> treeMap(thread, TaggedTreeMap::Create(thread));
jsTreeMap->SetTreeMap(thread, treeMap);
return jsTreeMap;
@@ -182,7 +182,7 @@ static JSHandle<JSAPITreeSet> NewJSAPITreeSet(JSThread *thread, ObjectFactory *f
auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
JSHandle<JSHClass> setClass = factory->NewEcmaDynClass(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto);
JSHandle<JSAPITreeSet> jsTreeSet = JSHandle<JSAPITreeSet>::Cast(factory->NewJSObject(setClass));
JSHandle<JSAPITreeSet> jsTreeSet = JSHandle<JSAPITreeSet>::Cast(factory->NewJSObjectWithInit(setClass));
JSHandle<TaggedTreeSet> treeSet(thread, TaggedTreeSet::Create(thread));
jsTreeSet->SetTreeSet(thread, treeSet);
return jsTreeSet;
@@ -193,7 +193,7 @@ static JSHandle<JSAPIPlainArray> NewJSAPIPlainArray(JSThread *thread, ObjectFact
auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
JSHandle<JSHClass> mapClass = factory->NewEcmaDynClass(JSAPIPlainArray::SIZE, JSType::JS_API_PLAIN_ARRAY, proto);
JSHandle<JSAPIPlainArray> jSAPIPlainArray = JSHandle<JSAPIPlainArray>::Cast(factory->NewJSObject(mapClass));
JSHandle<JSAPIPlainArray> jSAPIPlainArray = JSHandle<JSAPIPlainArray>::Cast(factory->NewJSObjectWithInit(mapClass));
JSHandle<TaggedArray> keys =
JSAPIPlainArray::CreateSlot(thread, JSAPIPlainArray::DEFAULT_CAPACITY_LENGTH);
JSHandle<TaggedArray> values =
@@ -217,7 +217,7 @@ static JSHandle<JSAPIArrayList> NewJSAPIArrayList(JSThread *thread, ObjectFactor
{
JSHandle<JSHClass> arrayListClass =
factory->NewEcmaDynClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto);
JSHandle<JSAPIArrayList> jsArrayList = JSHandle<JSAPIArrayList>::Cast(factory->NewJSObject(arrayListClass));
JSHandle<JSAPIArrayList> jsArrayList = JSHandle<JSAPIArrayList>::Cast(factory->NewJSObjectWithInit(arrayListClass));
jsArrayList->SetLength(thread, JSTaggedValue(0));
return jsArrayList;
}
@@ -225,7 +225,7 @@ static JSHandle<JSAPIArrayList> NewJSAPIArrayList(JSThread *thread, ObjectFactor
static JSHandle<JSAPIStack> NewJSAPIStack(ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
{
JSHandle<JSHClass> stackClass = factory->NewEcmaDynClass(JSAPIStack::SIZE, JSType::JS_API_STACK, proto);
JSHandle<JSAPIStack> jsStack = JSHandle<JSAPIStack>::Cast(factory->NewJSObject(stackClass));
JSHandle<JSAPIStack> jsStack = JSHandle<JSAPIStack>::Cast(factory->NewJSObjectWithInit(stackClass));
jsStack->SetTop(0);
return jsStack;
}
@@ -245,7 +245,7 @@ static JSHandle<JSRegExp> NewJSRegExp(JSThread *thread, ObjectFactory *factory,
static JSHandle<JSAPIQueue> NewJSAPIQueue(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
{
JSHandle<JSHClass> queueClass = factory->NewEcmaDynClass(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto);
JSHandle<JSAPIQueue> jsQueue = JSHandle<JSAPIQueue>::Cast(factory->NewJSObject(queueClass));
JSHandle<JSAPIQueue> jsQueue = JSHandle<JSAPIQueue>::Cast(factory->NewJSObjectWithInit(queueClass));
JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIQueue::DEFAULT_CAPACITY_LENGTH);
jsQueue->SetLength(thread, JSTaggedValue(0));
jsQueue->SetFront(0);
@@ -257,7 +257,7 @@ static JSHandle<JSAPIQueue> NewJSAPIQueue(JSThread *thread, ObjectFactory *facto
static JSHandle<JSAPIDeque> NewJSAPIDeque(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
{
JSHandle<JSHClass> dequeClass = factory->NewEcmaDynClass(JSAPIDeque::SIZE, JSType::JS_API_DEQUE, proto);
JSHandle<JSAPIDeque> jsDeque = JSHandle<JSAPIDeque>::Cast(factory->NewJSObject(dequeClass));
JSHandle<JSAPIDeque> jsDeque = JSHandle<JSAPIDeque>::Cast(factory->NewJSObjectWithInit(dequeClass));
JSHandle<TaggedArray> 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<JSHClass> class##ClassName = \
factory->NewEcmaDynClass(ClassName::SIZE, JSType::TypeName, proto); \
JSHandle<JSObject> object##ClassName = factory->NewJSObject(class##ClassName); \
JSHandle<JSObject> 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<JSHClass> proxyRevocClass =
JSHandle<JSHClass>::Cast(globalEnv->GetProxyRevocFunctionClass());
JSHandle<JSObject> proxyRevocFunc = factory->NewJSObject(proxyRevocClass);
JSHandle<JSObject> 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<JSHClass> promiseReactClass =
JSHandle<JSHClass>::Cast(globalEnv->GetPromiseReactionFunctionClass());
JSHandle<JSObject> promiseReactFunc = factory->NewJSObject(promiseReactClass);
JSHandle<JSObject> 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<JSHClass> promiseExeClass =
JSHandle<JSHClass>::Cast(globalEnv->GetPromiseExecutorFunctionClass());
JSHandle<JSObject> promiseExeFunc = factory->NewJSObject(promiseExeClass);
JSHandle<JSObject> 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<JSHClass> promiseAllClass =
JSHandle<JSHClass>::Cast(globalEnv->GetPromiseAllResolveElementFunctionClass());
JSHandle<JSObject> promiseAllFunc = factory->NewJSObject(promiseAllClass);
JSHandle<JSObject> 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<JSHClass> weakMapClass = factory->NewEcmaDynClass(JSWeakMap::SIZE, JSType::JS_WEAK_MAP, proto);
JSHandle<JSWeakMap> jsWeakMap = JSHandle<JSWeakMap>::Cast(factory->NewJSObject(weakMapClass));
JSHandle<JSWeakMap> jsWeakMap = JSHandle<JSWeakMap>::Cast(factory->NewJSObjectWithInit(weakMapClass));
JSHandle<LinkedHashMap> 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<JSHClass> weakSetClass = factory->NewEcmaDynClass(JSWeakSet::SIZE, JSType::JS_WEAK_SET, proto);
JSHandle<JSWeakSet> jsWeakSet = JSHandle<JSWeakSet>::Cast(factory->NewJSObject(weakSetClass));
JSHandle<JSWeakSet> jsWeakSet = JSHandle<JSWeakSet>::Cast(factory->NewJSObjectWithInit(weakSetClass));
JSHandle<LinkedHashSet> 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<JSHClass> dateClass = factory->NewEcmaDynClass(JSDate::SIZE, JSType::JS_DATE, proto);
JSHandle<JSDate> date = JSHandle<JSDate>::Cast(factory->NewJSObject(dateClass));
JSHandle<JSDate> date = JSHandle<JSDate>::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<JSHClass> pendingClass(thread,
JSHClass::Cast(globalConst->GetPendingJobClass().GetTaggedObject()));
JSHandle<TaggedObject> 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;
}
+3 -1
View File
@@ -51,7 +51,9 @@ public:
JSTaggedType *sp = const_cast<JSTaggedType *>(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<EcmaRuntimeCallInfo>(thread, numActualArgs - NUM_MANDATORY_JSFUNC_ARGS, newSp);
callInfo->SetNewTarget(newTgt);
return callInfo;