Copy hclass when SetIsPrototype

issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8WH57

Signed-off-by: dov1s <maojunwei1@huawei.com>
Change-Id: I24cee9682c95d909ecfa56bfeb43320fb3324db9
This commit is contained in:
dov1s 2024-01-16 10:27:13 +08:00
parent e3eb979704
commit dd9c248cb9
9 changed files with 183 additions and 67 deletions

View File

@ -375,7 +375,7 @@ void Builtins::Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool
// Object = new Function() // Object = new Function()
JSHandle<JSObject> objectFunction( JSHandle<JSObject> objectFunction(
NewBuiltinConstructor(env, objFuncPrototype, Object::ObjectConstructor, "Object", FunctionLength::ONE)); NewBuiltinConstructor(env, objFuncPrototype, Object::ObjectConstructor, "Object", FunctionLength::ONE));
objectFunction.GetObject<JSFunction>()->SetFunctionPrototype(thread_, objFuncClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, JSHandle<JSFunction>(objectFunction), objFuncClass.GetTaggedValue());
// initialize object method. // initialize object method.
env->SetObjectFunction(thread_, objectFunction); env->SetObjectFunction(thread_, objectFunction);
env->SetObjectFunctionPrototype(thread_, objFuncPrototype); env->SetObjectFunctionPrototype(thread_, objFuncPrototype);
@ -615,7 +615,7 @@ void Builtins::InitializeFunction(const JSHandle<GlobalEnv> &env, const JSHandle
auto funcFuncPrototypeObj = JSHandle<JSObject>(funcFuncPrototype); auto funcFuncPrototypeObj = JSHandle<JSObject>(funcFuncPrototype);
InitializeCtor(env, funcFuncPrototypeObj, funcFunc, "Function", FunctionLength::ONE); InitializeCtor(env, funcFuncPrototypeObj, funcFunc, "Function", FunctionLength::ONE);
funcFunc->SetFunctionPrototype(thread_, funcFuncIntanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, funcFunc, funcFuncIntanceHClass.GetTaggedValue());
env->SetFunctionFunction(thread_, funcFunc); env->SetFunctionFunction(thread_, funcFunc);
env->SetFunctionPrototype(thread_, funcFuncPrototype); env->SetFunctionPrototype(thread_, funcFuncPrototype);
@ -685,7 +685,8 @@ void Builtins::InitializeSymbol(const JSHandle<GlobalEnv> &env, const JSHandle<J
// Symbol = new Function() // Symbol = new Function()
JSHandle<JSObject> symbolFunction( JSHandle<JSObject> symbolFunction(
NewBuiltinConstructor(env, symbolFuncPrototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); NewBuiltinConstructor(env, symbolFuncPrototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO));
JSHandle<JSFunction>(symbolFunction)->SetFunctionPrototype(thread_, symbolFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(symbolFunction), symbolFuncInstanceHClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -806,7 +807,8 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle<GlobalEnv> &realm,
// Symbol = new Function() // Symbol = new Function()
JSHandle<JSObject> symbolFunction( JSHandle<JSObject> symbolFunction(
NewBuiltinConstructor(realm, symbolFuncPrototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); NewBuiltinConstructor(realm, symbolFuncPrototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO));
JSHandle<JSFunction>(symbolFunction)->SetFunctionPrototype(thread_, symbolFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(symbolFunction), symbolFuncInstanceHClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = thread_->GlobalConstants()->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = thread_->GlobalConstants()->GetHandledConstructorString();
@ -875,7 +877,8 @@ void Builtins::InitializeNumber(const JSHandle<GlobalEnv> &env, const JSHandle<J
JSHandle<JSObject> numFunction( JSHandle<JSObject> numFunction(
NewBuiltinConstructor(env, numFuncPrototype, Number::NumberConstructor, "Number", FunctionLength::ONE, NewBuiltinConstructor(env, numFuncPrototype, Number::NumberConstructor, "Number", FunctionLength::ONE,
BUILTINS_STUB_ID(NumberConstructor))); BUILTINS_STUB_ID(NumberConstructor)));
numFunction.GetObject<JSFunction>()->SetFunctionPrototype(thread_, numFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(numFunction), numFuncInstanceHClass.GetTaggedValue());
// Number.prototype method // Number.prototype method
for (const base::BuiltinFunctionEntry &entry: Number::GetNumberPrototypeFunctions()) { for (const base::BuiltinFunctionEntry &entry: Number::GetNumberPrototypeFunctions()) {
@ -925,7 +928,8 @@ void Builtins::InitializeBigInt(const JSHandle<GlobalEnv> &env, const JSHandle<J
JSHandle<JSObject> bigIntFunction( JSHandle<JSObject> bigIntFunction(
NewBuiltinConstructor(env, bigIntFuncPrototype, NewBuiltinConstructor(env, bigIntFuncPrototype,
BuiltinsBigInt::BigIntConstructor, "BigInt", FunctionLength::ONE)); BuiltinsBigInt::BigIntConstructor, "BigInt", FunctionLength::ONE));
JSHandle<JSFunction>(bigIntFunction)->SetFunctionPrototype(thread_, bigIntFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(bigIntFunction), bigIntFuncInstanceHClass.GetTaggedValue());
// BigInt.prototype method // BigInt.prototype method
SetFunction(env, bigIntFuncPrototype, "toLocaleString", BuiltinsBigInt::ToLocaleString, FunctionLength::ZERO); SetFunction(env, bigIntFuncPrototype, "toLocaleString", BuiltinsBigInt::ToLocaleString, FunctionLength::ZERO);
@ -958,7 +962,8 @@ void Builtins::InitializeDate(const JSHandle<GlobalEnv> &env, JSHandle<JSTaggedV
JSHandle<JSObject> dateFunction( JSHandle<JSObject> dateFunction(
NewBuiltinConstructor(env, dateFuncPrototype, Date::DateConstructor, "Date", FunctionLength::ONE, NewBuiltinConstructor(env, dateFuncPrototype, Date::DateConstructor, "Date", FunctionLength::ONE,
BUILTINS_STUB_ID(DateConstructor))); BUILTINS_STUB_ID(DateConstructor)));
JSHandle<JSFunction>(dateFunction)->SetFunctionPrototype(thread_, dateFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(dateFunction), dateFuncInstanceHClass.GetTaggedValue());
// Date.prototype method // Date.prototype method
for (const base::BuiltinFunctionEntry &entry: Date::GetDatePrototypeFunctions()) { for (const base::BuiltinFunctionEntry &entry: Date::GetDatePrototypeFunctions()) {
@ -1010,7 +1015,7 @@ void Builtins::InitializeBoolean(const JSHandle<GlobalEnv> &env, const JSHandle<
// new Boolean Function() // new Boolean Function()
JSHandle<JSFunction> booleanFunction = NewBuiltinConstructor(env, booleanFuncPrototype, Boolean::BooleanConstructor, JSHandle<JSFunction> booleanFunction = NewBuiltinConstructor(env, booleanFuncPrototype, Boolean::BooleanConstructor,
"Boolean", FunctionLength::ONE, BUILTINS_STUB_ID(BooleanConstructor)); "Boolean", FunctionLength::ONE, BUILTINS_STUB_ID(BooleanConstructor));
booleanFunction->SetFunctionPrototype(thread_, booleanFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, booleanFunction, booleanFuncInstanceHClass.GetTaggedValue());
// Boolean.prototype method // Boolean.prototype method
SetFunction(env, booleanFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), SetFunction(env, booleanFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(),
@ -1086,7 +1091,7 @@ void Builtins::InitializeAllTypeError(const JSHandle<GlobalEnv> &env, const JSHa
// Error() = new Function() // Error() = new Function()
JSHandle<JSFunction> errorFunction( JSHandle<JSFunction> errorFunction(
NewBuiltinConstructor(env, errorFuncPrototype, Error::ErrorConstructor, "Error", FunctionLength::ONE)); NewBuiltinConstructor(env, errorFuncPrototype, Error::ErrorConstructor, "Error", FunctionLength::ONE));
errorFunction->SetFunctionPrototype(thread_, errorFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, errorFunction, errorFuncInstanceHClass.GetTaggedValue());
// Error.prototype method // Error.prototype method
SetFunction(env, errorFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Error::ToString, SetFunction(env, errorFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Error::ToString,
@ -1266,7 +1271,7 @@ void Builtins::InitializeError(const JSHandle<GlobalEnv> &env, const JSHandle<JS
InitializeCtor(env, nativeErrorFuncPrototype, nativeErrorFunction, errorParameter.nativePropertyName, InitializeCtor(env, nativeErrorFuncPrototype, nativeErrorFunction, errorParameter.nativePropertyName,
functionLength); functionLength);
nativeErrorFunction->SetFunctionPrototype(thread_, nativeErrorFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, nativeErrorFunction, nativeErrorFuncInstanceHClass.GetTaggedValue());
// NativeError.prototype method // NativeError.prototype method
SetFunction(env, nativeErrorFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), SetFunction(env, nativeErrorFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(),
@ -1315,7 +1320,7 @@ void Builtins::InitializeCtor(const JSHandle<GlobalEnv> &env, const JSHandle<JSO
JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1); JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1);
/* set "prototype" in constructor */ /* set "prototype" in constructor */
ctor->SetFunctionPrototype(thread_, prototype.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, ctor, prototype.GetTaggedValue());
if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) {
JSHandle<JSObject> globalObject(thread_, env->GetGlobalObject()); JSHandle<JSObject> globalObject(thread_, env->GetGlobalObject());
@ -1339,7 +1344,8 @@ void Builtins::InitializeSet(const JSHandle<GlobalEnv> &env, JSHandle<JSTaggedVa
// Set() = new Function() // Set() = new Function()
JSHandle<JSTaggedValue> setFunction( JSHandle<JSTaggedValue> setFunction(
NewBuiltinConstructor(env, setFuncPrototype, BuiltinsSet::SetConstructor, "Set", FunctionLength::ZERO)); NewBuiltinConstructor(env, setFuncPrototype, BuiltinsSet::SetConstructor, "Set", FunctionLength::ZERO));
JSHandle<JSFunction>(setFunction)->SetFunctionPrototype(thread_, setFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(setFunction), setFuncInstanceHClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -1413,8 +1419,8 @@ void Builtins::InitializeMap(const JSHandle<GlobalEnv> &env, JSHandle<JSTaggedVa
JSHandle<JSTaggedValue> mapFunction( JSHandle<JSTaggedValue> mapFunction(
NewBuiltinConstructor(env, mapFuncPrototype, BuiltinsMap::MapConstructor, "Map", FunctionLength::ZERO)); NewBuiltinConstructor(env, mapFuncPrototype, BuiltinsMap::MapConstructor, "Map", FunctionLength::ZERO));
// Map().prototype = Map.Prototype & Map.prototype.constructor = Map() // Map().prototype = Map.Prototype & Map.prototype.constructor = Map()
JSFunction::Cast(mapFunction->GetTaggedObject()) JSFunction::SetFunctionPrototype(thread_,
->SetFunctionPrototype(thread_, mapFuncInstanceHClass.GetTaggedValue()); JSHandle<JSFunction>(mapFunction), mapFuncInstanceHClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -1723,7 +1729,8 @@ void Builtins::InitializeString(const JSHandle<GlobalEnv> &env, JSHandle<JSTagge
// String = new Function() // String = new Function()
JSHandle<JSObject> stringFunction(NewBuiltinConstructor(env, stringFuncPrototype, BuiltinsString::StringConstructor, JSHandle<JSObject> stringFunction(NewBuiltinConstructor(env, stringFuncPrototype, BuiltinsString::StringConstructor,
"String", FunctionLength::ONE)); "String", FunctionLength::ONE));
stringFunction.GetObject<JSFunction>()->SetFunctionPrototype(thread_, stringFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(stringFunction), stringFuncInstanceHClass.GetTaggedValue());
// String.prototype method // String.prototype method
for (const base::BuiltinFunctionEntry &entry: BuiltinsString::GetStringPrototypeFunctions()) { for (const base::BuiltinFunctionEntry &entry: BuiltinsString::GetStringPrototypeFunctions()) {
@ -1764,7 +1771,7 @@ void Builtins::InitializeStringIterator(const JSHandle<GlobalEnv> &env,
JSHandle<JSFunction> strIterFunction( JSHandle<JSFunction> strIterFunction(
factory_->NewJSFunction(env, static_cast<void *>(nullptr), FunctionKind::BASE_CONSTRUCTOR)); factory_->NewJSFunction(env, static_cast<void *>(nullptr), FunctionKind::BASE_CONSTRUCTOR));
strIterFunction->SetFunctionPrototype(thread_, strIterFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, strIterFunction, strIterFuncInstanceHClass.GetTaggedValue());
SetFunction(env, strIterPrototype, "next", StringIterator::Next, FunctionLength::ZERO, SetFunction(env, strIterPrototype, "next", StringIterator::Next, FunctionLength::ZERO,
BUILTINS_STUB_ID(STRING_ITERATOR_PROTO_NEXT)); BUILTINS_STUB_ID(STRING_ITERATOR_PROTO_NEXT));
@ -1788,7 +1795,7 @@ void Builtins::InitializeAsyncFromSyncIterator(const JSHandle<GlobalEnv> &env,
JSHandle<JSTaggedValue>(asyncItPrototype)); JSHandle<JSTaggedValue>(asyncItPrototype));
JSHandle<JSFunction> iterFunction( JSHandle<JSFunction> iterFunction(
factory_->NewJSFunction(env, static_cast<void *>(nullptr), FunctionKind::BASE_CONSTRUCTOR)); factory_->NewJSFunction(env, static_cast<void *>(nullptr), FunctionKind::BASE_CONSTRUCTOR));
iterFunction->SetFunctionPrototype(thread_, hclass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, iterFunction, hclass.GetTaggedValue());
env->SetAsyncFromSyncIterator(thread_, iterFunction); env->SetAsyncFromSyncIterator(thread_, iterFunction);
env->SetAsyncFromSyncIteratorPrototype(thread_, asyncItPrototype); env->SetAsyncFromSyncIteratorPrototype(thread_, asyncItPrototype);
@ -1956,7 +1963,8 @@ void Builtins::InitializeRegExp(const JSHandle<GlobalEnv> &env)
// initialize RegExp.$1 .. $9 static and read-only attributes // initialize RegExp.$1 .. $9 static and read-only attributes
InitializeGlobalRegExp(regexpFunction); InitializeGlobalRegExp(regexpFunction);
JSHandle<JSFunction>(regexpFunction)->SetFunctionPrototype(thread_, regexpFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(regexpFunction), regexpFuncInstanceHClass.GetTaggedValue());
const GlobalEnvConstants *globalConstants = thread_->GlobalConstants(); const GlobalEnvConstants *globalConstants = thread_->GlobalConstants();
// RegExp.prototype method // RegExp.prototype method
@ -2084,7 +2092,7 @@ void Builtins::InitializeArray(const JSHandle<GlobalEnv> &env, const JSHandle<JS
lexicalEnv->SetParentEnv(thread_, env.GetTaggedValue()); lexicalEnv->SetParentEnv(thread_, env.GetTaggedValue());
arrayFuncFunction->SetLexicalEnv(thread_, lexicalEnv.GetTaggedValue()); arrayFuncFunction->SetLexicalEnv(thread_, lexicalEnv.GetTaggedValue());
arrayFuncFunction->SetFunctionPrototype(thread_, arrFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, arrayFuncFunction, arrFuncInstanceHClass.GetTaggedValue());
// Array.prototype methods (excluding constructor and '@@' internal properties) // Array.prototype methods (excluding constructor and '@@' internal properties)
for (const base::BuiltinFunctionEntry &entry: BuiltinsArray::GetArrayPrototypeFunctions()) { for (const base::BuiltinFunctionEntry &entry: BuiltinsArray::GetArrayPrototypeFunctions()) {
@ -2303,8 +2311,8 @@ void Builtins::InitializeArrayBuffer(const JSHandle<GlobalEnv> &env, const JSHan
JSHandle<JSObject> arrayBufferFunction(NewBuiltinConstructor( JSHandle<JSObject> arrayBufferFunction(NewBuiltinConstructor(
env, arrayBufferFuncPrototype, ArrayBuffer::ArrayBufferConstructor, "ArrayBuffer", FunctionLength::ONE)); env, arrayBufferFuncPrototype, ArrayBuffer::ArrayBufferConstructor, "ArrayBuffer", FunctionLength::ONE));
JSHandle<JSFunction>(arrayBufferFunction) JSFunction::SetFunctionPrototype(thread_,
->SetFunctionPrototype(thread_, arrayBufferFuncInstanceHClass.GetTaggedValue()); JSHandle<JSFunction>(arrayBufferFunction), arrayBufferFuncInstanceHClass.GetTaggedValue());
// ArrayBuffer prototype method // ArrayBuffer prototype method
SetFunction(env, arrayBufferFuncPrototype, "slice", ArrayBuffer::Slice, FunctionLength::TWO); SetFunction(env, arrayBufferFuncPrototype, "slice", ArrayBuffer::Slice, FunctionLength::TWO);
@ -2383,8 +2391,8 @@ void Builtins::InitializeSharedArrayBuffer(const JSHandle<GlobalEnv> &env,
JSHandle<JSObject> SharedArrayBufferFunction(NewBuiltinConstructor(env, sharedArrayBufferFuncPrototype, JSHandle<JSObject> SharedArrayBufferFunction(NewBuiltinConstructor(env, sharedArrayBufferFuncPrototype,
SharedArrayBuffer::SharedArrayBufferConstructor, "SharedArrayBuffer", FunctionLength::ONE)); SharedArrayBuffer::SharedArrayBufferConstructor, "SharedArrayBuffer", FunctionLength::ONE));
JSHandle<JSFunction>(SharedArrayBufferFunction) JSFunction::SetFunctionPrototype(thread_,
->SetFunctionPrototype(thread_, sharedArrayBufferFuncInstanceHClass.GetTaggedValue()); JSHandle<JSFunction>(SharedArrayBufferFunction), sharedArrayBufferFuncInstanceHClass.GetTaggedValue());
// SharedArrayBuffer prototype method // SharedArrayBuffer prototype method
SetFunction(env, sharedArrayBufferFuncPrototype, "slice", SharedArrayBuffer::Slice, FunctionLength::TWO); SetFunction(env, sharedArrayBufferFuncPrototype, "slice", SharedArrayBuffer::Slice, FunctionLength::TWO);
@ -2434,7 +2442,8 @@ void Builtins::InitializePromise(const JSHandle<GlobalEnv> &env, const JSHandle<
// Promise() = new Function() // Promise() = new Function()
JSHandle<JSObject> promiseFunction( JSHandle<JSObject> promiseFunction(
NewBuiltinConstructor(env, promiseFuncPrototype, Promise::PromiseConstructor, "Promise", FunctionLength::ONE)); NewBuiltinConstructor(env, promiseFuncPrototype, Promise::PromiseConstructor, "Promise", FunctionLength::ONE));
JSHandle<JSFunction>(promiseFunction)->SetFunctionPrototype(thread_, promiseFuncInstanceHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(promiseFunction), promiseFuncInstanceHClass.GetTaggedValue());
// Promise method // Promise method
for (const base::BuiltinFunctionEntry &entry: Promise::GetPromiseFunctions()) { for (const base::BuiltinFunctionEntry &entry: Promise::GetPromiseFunctions()) {
@ -3096,7 +3105,7 @@ void Builtins::InitializeIntlCtor(const JSHandle<GlobalEnv> &env, const JSHandle
JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1); JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1);
// set "prototype" in constructor. // set "prototype" in constructor.
ctor->SetFunctionPrototype(thread_, prototype.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, ctor, prototype.GetTaggedValue());
if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) {
JSHandle<JSObject> intlObject(thread_, env->GetIntlFunction().GetTaggedValue()); JSHandle<JSObject> intlObject(thread_, env->GetIntlFunction().GetTaggedValue());
@ -3143,7 +3152,8 @@ void Builtins::InitializeDateTimeFormat(const JSHandle<GlobalEnv> &env)
// 13.4.1 Intl.DateTimeFormat.prototype.constructor // 13.4.1 Intl.DateTimeFormat.prototype.constructor
JSHandle<JSObject> dtfFunction(NewIntlConstructor(env, dtfPrototype, DateTimeFormat::DateTimeFormatConstructor, JSHandle<JSObject> dtfFunction(NewIntlConstructor(env, dtfPrototype, DateTimeFormat::DateTimeFormatConstructor,
"DateTimeFormat", FunctionLength::ZERO)); "DateTimeFormat", FunctionLength::ZERO));
JSHandle<JSFunction>(dtfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*dtfFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(dtfFunction), JSTaggedValue(*dtfFuncInstanceHClass));
// 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ) // 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] )
SetFunction(env, dtfFunction, "supportedLocalesOf", DateTimeFormat::SupportedLocalesOf, FunctionLength::ONE); SetFunction(env, dtfFunction, "supportedLocalesOf", DateTimeFormat::SupportedLocalesOf, FunctionLength::ONE);
@ -3186,7 +3196,8 @@ void Builtins::InitializeRelativeTimeFormat(const JSHandle<GlobalEnv> &env)
JSHandle<JSObject> rtfFunction(NewIntlConstructor(env, rtfPrototype, JSHandle<JSObject> rtfFunction(NewIntlConstructor(env, rtfPrototype,
RelativeTimeFormat::RelativeTimeFormatConstructor, RelativeTimeFormat::RelativeTimeFormatConstructor,
"RelativeTimeFormat", FunctionLength::ZERO)); "RelativeTimeFormat", FunctionLength::ZERO));
JSHandle<JSFunction>(rtfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*rtfFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(rtfFunction), JSTaggedValue(*rtfFuncInstanceHClass));
// 14.3.2 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] ) // 14.3.2 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] )
SetFunction(env, rtfFunction, "supportedLocalesOf", RelativeTimeFormat::SupportedLocalesOf, FunctionLength::ONE); SetFunction(env, rtfFunction, "supportedLocalesOf", RelativeTimeFormat::SupportedLocalesOf, FunctionLength::ONE);
@ -3222,7 +3233,8 @@ void Builtins::InitializeNumberFormat(const JSHandle<GlobalEnv> &env)
// 12.4.1 Intl.NumberFormat.prototype.constructor // 12.4.1 Intl.NumberFormat.prototype.constructor
JSHandle<JSObject> nfFunction(NewIntlConstructor(env, nfPrototype, NumberFormat::NumberFormatConstructor, JSHandle<JSObject> nfFunction(NewIntlConstructor(env, nfPrototype, NumberFormat::NumberFormatConstructor,
"NumberFormat", FunctionLength::ZERO)); "NumberFormat", FunctionLength::ZERO));
JSHandle<JSFunction>(nfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*nfFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(nfFunction), JSTaggedValue(*nfFuncInstanceHClass));
// 12.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] ) // 12.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] )
SetFunction(env, nfFunction, "supportedLocalesOf", NumberFormat::SupportedLocalesOf, FunctionLength::ONE); SetFunction(env, nfFunction, "supportedLocalesOf", NumberFormat::SupportedLocalesOf, FunctionLength::ONE);
@ -3259,7 +3271,8 @@ void Builtins::InitializeLocale(const JSHandle<GlobalEnv> &env)
// Locale = new Function() // Locale = new Function()
JSHandle<JSObject> localeFunction( JSHandle<JSObject> localeFunction(
NewIntlConstructor(env, localePrototype, Locale::LocaleConstructor, "Locale", FunctionLength::ONE)); NewIntlConstructor(env, localePrototype, Locale::LocaleConstructor, "Locale", FunctionLength::ONE));
JSHandle<JSFunction>(localeFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*localeFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(localeFunction), JSTaggedValue(*localeFuncInstanceHClass));
// Locale.prototype method // Locale.prototype method
SetFunction(env, localePrototype, "maximize", Locale::Maximize, FunctionLength::ZERO); SetFunction(env, localePrototype, "maximize", Locale::Maximize, FunctionLength::ZERO);
@ -3321,7 +3334,8 @@ void Builtins::InitializeCollator(const JSHandle<GlobalEnv> &env)
// 11.1.2 Intl.Collator.prototype.constructor // 11.1.2 Intl.Collator.prototype.constructor
JSHandle<JSObject> collatorFunction( JSHandle<JSObject> collatorFunction(
NewIntlConstructor(env, collatorPrototype, Collator::CollatorConstructor, "Collator", FunctionLength::ZERO)); NewIntlConstructor(env, collatorPrototype, Collator::CollatorConstructor, "Collator", FunctionLength::ZERO));
JSHandle<JSFunction>(collatorFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*collatorFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(collatorFunction), JSTaggedValue(*collatorFuncInstanceHClass));
// 11.2.2 Intl.Collator.supportedLocalesOf ( locales [ , options ] ) // 11.2.2 Intl.Collator.supportedLocalesOf ( locales [ , options ] )
SetFunction(env, collatorFunction, "supportedLocalesOf", Collator::SupportedLocalesOf, FunctionLength::ONE); SetFunction(env, collatorFunction, "supportedLocalesOf", Collator::SupportedLocalesOf, FunctionLength::ONE);
@ -3356,7 +3370,8 @@ void Builtins::InitializePluralRules(const JSHandle<GlobalEnv> &env)
// 15.2.1 Intl.PluralRules.prototype.constructor // 15.2.1 Intl.PluralRules.prototype.constructor
JSHandle<JSObject> prFunction( JSHandle<JSObject> prFunction(
NewIntlConstructor(env, prPrototype, PluralRules::PluralRulesConstructor, "PluralRules", FunctionLength::ZERO)); NewIntlConstructor(env, prPrototype, PluralRules::PluralRulesConstructor, "PluralRules", FunctionLength::ZERO));
JSHandle<JSFunction>(prFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*prFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(prFunction), JSTaggedValue(*prFuncInstanceHClass));
// 15.3.2 Intl.PluralRules.supportedLocalesOf ( locales [ , options ] ) // 15.3.2 Intl.PluralRules.supportedLocalesOf ( locales [ , options ] )
SetFunction(env, prFunction, "supportedLocalesOf", PluralRules::SupportedLocalesOf, FunctionLength::ONE); SetFunction(env, prFunction, "supportedLocalesOf", PluralRules::SupportedLocalesOf, FunctionLength::ONE);
@ -3389,7 +3404,8 @@ void Builtins::InitializeDisplayNames(const JSHandle<GlobalEnv> &env)
// 12.4.1 Intl.DisplayNames.prototype.constructor // 12.4.1 Intl.DisplayNames.prototype.constructor
JSHandle<JSObject> dnFunction(NewIntlConstructor(env, dnPrototype, DisplayNames::DisplayNamesConstructor, JSHandle<JSObject> dnFunction(NewIntlConstructor(env, dnPrototype, DisplayNames::DisplayNamesConstructor,
"DisplayNames", FunctionLength::TWO)); "DisplayNames", FunctionLength::TWO));
JSHandle<JSFunction>(dnFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*dnFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(dnFunction), JSTaggedValue(*dnFuncInstanceHClass));
// 12.3.2 Intl.DisplayNames.supportedLocalesOf ( locales [ , options ] ) // 12.3.2 Intl.DisplayNames.supportedLocalesOf ( locales [ , options ] )
SetFunction(env, dnFunction, "supportedLocalesOf", DisplayNames::SupportedLocalesOf, FunctionLength::ONE); SetFunction(env, dnFunction, "supportedLocalesOf", DisplayNames::SupportedLocalesOf, FunctionLength::ONE);
@ -3422,7 +3438,8 @@ void Builtins::InitializeListFormat(const JSHandle<GlobalEnv> &env)
// 13.4.1 Intl.ListFormat.prototype.constructor // 13.4.1 Intl.ListFormat.prototype.constructor
JSHandle<JSObject> lfFunction(NewIntlConstructor(env, lfPrototype, ListFormat::ListFormatConstructor, JSHandle<JSObject> lfFunction(NewIntlConstructor(env, lfPrototype, ListFormat::ListFormatConstructor,
"ListFormat", FunctionLength::ZERO)); "ListFormat", FunctionLength::ZERO));
JSHandle<JSFunction>(lfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*lfFuncInstanceHClass)); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(lfFunction), JSTaggedValue(*lfFuncInstanceHClass));
// 13.3.2 Intl.ListFormat.supportedLocalesOf ( locales [ , options ] ) // 13.3.2 Intl.ListFormat.supportedLocalesOf ( locales [ , options ] )
SetFunction(env, lfFunction, "supportedLocalesOf", ListFormat::SupportedLocalesOf, FunctionLength::ONE); SetFunction(env, lfFunction, "supportedLocalesOf", ListFormat::SupportedLocalesOf, FunctionLength::ONE);
@ -3571,7 +3588,8 @@ void Builtins::InitializeCjsModule(const JSHandle<GlobalEnv> &env) const
NewBuiltinCjsCtor(env, cjsModulePrototype, BuiltinsCjsModule::CjsModuleConstructor, "Module", NewBuiltinCjsCtor(env, cjsModulePrototype, BuiltinsCjsModule::CjsModuleConstructor, "Module",
FunctionLength::TWO)); FunctionLength::TWO));
JSHandle<JSFunction>(cjsModuleFunction)->SetFunctionPrototype(thread_, cjsModuleHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(cjsModuleFunction), cjsModuleHClass.GetTaggedValue());
// CjsModule method // CjsModule method
SetFunction(env, cjsModuleFunction, "_load", BuiltinsCjsModule::Load, FunctionLength::ONE); SetFunction(env, cjsModuleFunction, "_load", BuiltinsCjsModule::Load, FunctionLength::ONE);
@ -3626,7 +3644,8 @@ void Builtins::InitializeCjsExports(const JSHandle<GlobalEnv> &env) const
NewBuiltinCjsCtor(env, cjsExportsPrototype, BuiltinsCjsExports::CjsExportsConstructor, "Exports", NewBuiltinCjsCtor(env, cjsExportsPrototype, BuiltinsCjsExports::CjsExportsConstructor, "Exports",
FunctionLength::TWO)); FunctionLength::TWO));
JSHandle<JSFunction>(cjsExportsFunction)->SetFunctionPrototype(thread_, cjsExportsHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(cjsExportsFunction), cjsExportsHClass.GetTaggedValue());
env->SetCjsExportsFunction(thread_, cjsExportsFunction); env->SetCjsExportsFunction(thread_, cjsExportsFunction);
} }
@ -3647,7 +3666,8 @@ void Builtins::InitializeCjsRequire(const JSHandle<GlobalEnv> &env) const
JSHandle<JSFunction> cjsRequireFunction = JSHandle<JSFunction> cjsRequireFunction =
NewBuiltinCjsCtor(env, cjsRequirePrototype, BuiltinsCjsRequire::CjsRequireConstructor, "require", NewBuiltinCjsCtor(env, cjsRequirePrototype, BuiltinsCjsRequire::CjsRequireConstructor, "require",
FunctionLength::ONE); FunctionLength::ONE);
JSHandle<JSFunction>(cjsRequireFunction)->SetFunctionPrototype(thread_, cjsRequireHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_,
JSHandle<JSFunction>(cjsRequireFunction), cjsRequireHClass.GetTaggedValue());
// CjsModule.prototype method // CjsModule.prototype method
SetFunction(env, cjsRequirePrototype, "Main", BuiltinsCjsRequire::Main, FunctionLength::ONE); SetFunction(env, cjsRequirePrototype, "Main", BuiltinsCjsRequire::Main, FunctionLength::ONE);
@ -3706,7 +3726,7 @@ void Builtins::InitializeSCtor(const JSHandle<JSHClass> &protoHClass, const JSHa
JSHandle<JSObject> prototype(thread_, protoHClass->GetProto()); JSHandle<JSObject> prototype(thread_, protoHClass->GetProto());
JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor, SCheckMode::SKIP); JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor, SCheckMode::SKIP);
ctor->SetFunctionPrototype(thread_, protoHClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread_, ctor, protoHClass.GetTaggedValue());
} }
JSHandle<JSFunction> Builtins::NewSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<JSTaggedValue> &key, JSHandle<JSFunction> Builtins::NewSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<JSTaggedValue> &key,

View File

@ -184,7 +184,7 @@ JSHandle<JSFunction> ContainersPrivate::NewContainerConstructor(JSThread *thread
JSObject::DefineOwnProperty(thread, prototype, constructorKey, descriptor1); JSObject::DefineOwnProperty(thread, prototype, constructorKey, descriptor1);
/* set "prototype" in constructor */ /* set "prototype" in constructor */
ctor->SetFunctionPrototype(thread, prototype.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread, ctor, prototype.GetTaggedValue());
return ctor; return ctor;
} }
@ -283,8 +283,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeArrayList(JSThread *thread)
// ArrayList() = new Function() // ArrayList() = new Function()
JSHandle<JSTaggedValue> arrayListFunction(NewContainerConstructor( JSHandle<JSTaggedValue> arrayListFunction(NewContainerConstructor(
thread, prototype, ContainersArrayList::ArrayListConstructor, "ArrayList", FuncLength::ZERO)); thread, prototype, ContainersArrayList::ArrayListConstructor, "ArrayList", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(arrayListFunction)->SetFunctionPrototype(thread, JSFunction::SetFunctionPrototype(thread,
arrayListInstanceClass.GetTaggedValue()); JSHandle<JSFunction>::Cast(arrayListFunction), arrayListInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -357,8 +357,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeLightWeightMap(JSThread *th
JSHandle<JSTaggedValue> lightWeightMapFunction(NewContainerConstructor( JSHandle<JSTaggedValue> lightWeightMapFunction(NewContainerConstructor(
thread, funcPrototype, ContainersLightWeightMap::LightWeightMapConstructor, "LightWeightMap", thread, funcPrototype, ContainersLightWeightMap::LightWeightMapConstructor, "LightWeightMap",
FuncLength::ZERO)); FuncLength::ZERO));
JSHandle<JSFunction>::Cast(lightWeightMapFunction)-> JSFunction::SetFunctionPrototype(thread,
SetFunctionPrototype(thread, lightWeightMapInstanceClass.GetTaggedValue()); JSHandle<JSFunction>::Cast(lightWeightMapFunction), lightWeightMapInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -431,8 +431,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeLightWeightSet(JSThread *th
JSHandle<JSTaggedValue> lightweightSetFunction( JSHandle<JSTaggedValue> lightweightSetFunction(
NewContainerConstructor(thread, funcPrototype, ContainersLightWeightSet::LightWeightSetConstructor, NewContainerConstructor(thread, funcPrototype, ContainersLightWeightSet::LightWeightSetConstructor,
"LightWeightSet", FuncLength::ZERO)); "LightWeightSet", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(lightweightSetFunction)->SetFunctionPrototype(thread, lightweightSetInstanceClass. JSFunction::SetFunctionPrototype(thread,
GetTaggedValue()); JSHandle<JSFunction>::Cast(lightweightSetFunction), lightweightSetInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(funcPrototype), constructorKey, lightweightSetFunction); JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(funcPrototype), constructorKey, lightweightSetFunction);
@ -496,7 +496,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeTreeMap(JSThread *thread)
// TreeMap() = new Function() // TreeMap() = new Function()
JSHandle<JSTaggedValue> mapFunction(NewContainerConstructor( JSHandle<JSTaggedValue> mapFunction(NewContainerConstructor(
thread, mapFuncPrototype, ContainersTreeMap::TreeMapConstructor, "TreeMap", FuncLength::ZERO)); thread, mapFuncPrototype, ContainersTreeMap::TreeMapConstructor, "TreeMap", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(mapFunction)->SetFunctionPrototype(thread, mapInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(mapFunction), mapInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -572,7 +573,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeTreeSet(JSThread *thread)
// TreeSet() = new Function() // TreeSet() = new Function()
JSHandle<JSTaggedValue> setFunction(NewContainerConstructor( JSHandle<JSTaggedValue> setFunction(NewContainerConstructor(
thread, setFuncPrototype, ContainersTreeSet::TreeSetConstructor, "TreeSet", FuncLength::ZERO)); thread, setFuncPrototype, ContainersTreeSet::TreeSetConstructor, "TreeSet", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(setFunction)->SetFunctionPrototype(thread, setInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(setFunction), setInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -645,8 +647,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializePlainArray(JSThread *thread
JSHandle<JSTaggedValue> plainArrayFunction( JSHandle<JSTaggedValue> plainArrayFunction(
NewContainerConstructor(thread, plainArrayFuncPrototype, ContainersPlainArray::PlainArrayConstructor, NewContainerConstructor(thread, plainArrayFuncPrototype, ContainersPlainArray::PlainArrayConstructor,
"PlainArray", FuncLength::ZERO)); "PlainArray", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(plainArrayFunction)->SetFunctionPrototype(thread, JSFunction::SetFunctionPrototype(thread,
plainArrayInstanceClass.GetTaggedValue()); JSHandle<JSFunction>::Cast(plainArrayFunction), plainArrayInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -719,7 +721,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeStack(JSThread *thread)
// Stack() = new Function() // Stack() = new Function()
JSHandle<JSTaggedValue> stackFunction(NewContainerConstructor( JSHandle<JSTaggedValue> stackFunction(NewContainerConstructor(
thread, stackFuncPrototype, ContainersStack::StackConstructor, "Stack", FuncLength::ZERO)); thread, stackFuncPrototype, ContainersStack::StackConstructor, "Stack", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(stackFunction)->SetFunctionPrototype(thread, stackInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(stackFunction), stackInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -777,7 +780,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeVector(JSThread *thread)
// Vector() = new Function() // Vector() = new Function()
JSHandle<JSTaggedValue> vectorFunction(NewContainerConstructor( JSHandle<JSTaggedValue> vectorFunction(NewContainerConstructor(
thread, prototype, ContainersVector::VectorConstructor, "Vector", FuncLength::ZERO)); thread, prototype, ContainersVector::VectorConstructor, "Vector", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(vectorFunction)->SetFunctionPrototype(thread, vectorInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(vectorFunction), vectorInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -858,7 +862,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeQueue(JSThread *thread)
// Queue() = new Function() // Queue() = new Function()
JSHandle<JSTaggedValue> queueFunction(NewContainerConstructor( JSHandle<JSTaggedValue> queueFunction(NewContainerConstructor(
thread, queueFuncPrototype, ContainersQueue::QueueConstructor, "Queue", FuncLength::ZERO)); thread, queueFuncPrototype, ContainersQueue::QueueConstructor, "Queue", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(queueFunction)->SetFunctionPrototype(thread, queueInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(queueFunction), queueInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -912,7 +917,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeDeque(JSThread *thread)
// Deque() = new Function() // Deque() = new Function()
JSHandle<JSTaggedValue> dequeFunction(NewContainerConstructor( JSHandle<JSTaggedValue> dequeFunction(NewContainerConstructor(
thread, dequeFuncPrototype, ContainersDeque::DequeConstructor, "Deque", FuncLength::ZERO)); thread, dequeFuncPrototype, ContainersDeque::DequeConstructor, "Deque", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(dequeFunction)->SetFunctionPrototype(thread, dequeInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(dequeFunction), dequeInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -965,7 +971,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeList(JSThread *thread)
factory->NewEcmaHClass(JSAPIList::SIZE, JSType::JS_API_LIST, listFuncPrototypeValue); factory->NewEcmaHClass(JSAPIList::SIZE, JSType::JS_API_LIST, listFuncPrototypeValue);
JSHandle<JSTaggedValue> listFunction(NewContainerConstructor( JSHandle<JSTaggedValue> listFunction(NewContainerConstructor(
thread, listFuncPrototype, ContainersList::ListConstructor, "List", FuncLength::ZERO)); thread, listFuncPrototype, ContainersList::ListConstructor, "List", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(listFunction)->SetFunctionPrototype(thread, listInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(listFunction), listInstanceClass.GetTaggedValue());
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(listFuncPrototype), constructorKey, listFunction); JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(listFuncPrototype), constructorKey, listFunction);
@ -1015,8 +1022,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeLinkedList(JSThread *thread
factory->NewEcmaHClass(JSAPILinkedList::SIZE, JSType::JS_API_LINKED_LIST, linkedListFuncPrototypeValue); factory->NewEcmaHClass(JSAPILinkedList::SIZE, JSType::JS_API_LINKED_LIST, linkedListFuncPrototypeValue);
JSHandle<JSTaggedValue> linkedListFunction(NewContainerConstructor( JSHandle<JSTaggedValue> linkedListFunction(NewContainerConstructor(
thread, linkedListFuncPrototype, ContainersLinkedList::LinkedListConstructor, "LinkedList", FuncLength::ZERO)); thread, linkedListFuncPrototype, ContainersLinkedList::LinkedListConstructor, "LinkedList", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(linkedListFunction)->SetFunctionPrototype(thread, JSFunction::SetFunctionPrototype(thread,
linkedListInstanceClass.GetTaggedValue()); JSHandle<JSFunction>::Cast(linkedListFunction), linkedListInstanceClass.GetTaggedValue());
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(linkedListFuncPrototype), constructorKey, linkedListFunction); JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(linkedListFuncPrototype), constructorKey, linkedListFunction);
@ -1101,7 +1108,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeHashMap(JSThread *thread)
JSHandle<JSTaggedValue> hashMapFunction(NewContainerConstructor( JSHandle<JSTaggedValue> hashMapFunction(NewContainerConstructor(
thread, hashMapFuncPrototype, ContainersHashMap::HashMapConstructor, "HashMap", FuncLength::ZERO)); thread, hashMapFuncPrototype, ContainersHashMap::HashMapConstructor, "HashMap", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(hashMapFunction)->SetFunctionPrototype(thread, hashMapInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(hashMapFunction), hashMapInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -1183,7 +1191,8 @@ JSHandle<JSTaggedValue> ContainersPrivate::InitializeHashSet(JSThread *thread)
JSHandle<JSTaggedValue> hashSetFunction(NewContainerConstructor( JSHandle<JSTaggedValue> hashSetFunction(NewContainerConstructor(
thread, hashSetFuncPrototype, ContainersHashSet::HashSetConstructor, "HashSet", FuncLength::ZERO)); thread, hashSetFuncPrototype, ContainersHashSet::HashSetConstructor, "HashSet", FuncLength::ZERO));
JSHandle<JSFunction>::Cast(hashSetFunction)->SetFunctionPrototype(thread, hashSetInstanceClass.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread,
JSHandle<JSFunction>::Cast(hashSetFunction), hashSetInstanceClass.GetTaggedValue());
// "constructor" property on the prototype // "constructor" property on the prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();

View File

@ -89,7 +89,7 @@ JSHandle<JSObject> JSFunction::NewJSFunctionPrototype(JSThread *thread, const JS
const GlobalEnvConstants *globalConst = thread->GlobalConstants(); const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<JSFunction> objFun(env->GetObjectFunction()); JSHandle<JSFunction> objFun(env->GetObjectFunction());
JSHandle<JSObject> funPro = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(objFun); JSHandle<JSObject> funPro = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(objFun);
func->SetFunctionPrototype(thread, funPro.GetTaggedValue()); SetFunctionPrototype(thread, func, funPro.GetTaggedValue());
// set "constructor" in prototype // set "constructor" in prototype
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
@ -153,7 +153,7 @@ bool JSFunction::PrototypeSetter(JSThread *thread, const JSHandle<JSObject> &sel
} }
func->SetProtoOrHClass(thread, newClass); func->SetProtoOrHClass(thread, newClass);
} else { } else {
func->SetFunctionPrototype(thread, value.GetTaggedValue()); SetFunctionPrototype(thread, func, value.GetTaggedValue());
} }
return true; return true;
} }
@ -342,7 +342,7 @@ bool JSFunction::MakeConstructor(JSThread *thread, const JSHandle<JSFunction> &f
// func.prototype = proto // func.prototype = proto
// Let status be DefinePropertyOrThrow(F, "prototype", PropertyDescriptor{[[Value]]: // Let status be DefinePropertyOrThrow(F, "prototype", PropertyDescriptor{[[Value]]:
// prototype, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false}). // prototype, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false}).
func->SetFunctionPrototype(thread, proto.GetTaggedValue()); SetFunctionPrototype(thread, func, proto.GetTaggedValue());
ASSERT_PRINT(status, "DefineProperty proto_type failed"); ASSERT_PRINT(status, "DefineProperty proto_type failed");
return status; return status;

View File

@ -136,14 +136,19 @@ public:
return protoOrHClass; return protoOrHClass;
} }
inline void SetFunctionPrototype(const JSThread *thread, JSTaggedValue proto) static void SetFunctionPrototype(const JSThread *thread, const JSHandle<JSFunction> &fun, JSTaggedValue proto)
{ {
SetProtoOrHClass(thread, proto); JSHandle<JSTaggedValue> protoHandle(thread, proto);
if (proto.IsJSHClass()) { fun->SetProtoOrHClass(thread, protoHandle.GetTaggedValue());
proto = JSHClass::Cast(proto.GetTaggedObject())->GetPrototype(); if (protoHandle->IsJSHClass()) {
protoHandle = JSHandle<JSTaggedValue>(thread,
JSHClass::Cast(protoHandle->GetTaggedObject())->GetPrototype());
} }
if (proto.IsECMAObject()) { if (protoHandle->IsECMAObject()) {
proto.GetTaggedObject()->GetClass()->SetIsPrototype(true); auto hclass = JSHandle<JSHClass>(thread, protoHandle->GetTaggedObject()->GetClass());
JSHandle<JSHClass> newJSHClass = JSHClass::Clone(thread, hclass);
newJSHClass->SetIsPrototype(true);
protoHandle->GetTaggedObject()->SynchronizedSetClass(*newJSHClass);
} }
} }

View File

@ -818,7 +818,7 @@ JSTaggedValue RuntimeStubs::RuntimeCloneClassFromTemplate(JSThread *thread, cons
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// After clone both, reset "constructor" and "prototype" properties. // After clone both, reset "constructor" and "prototype" properties.
cloneClass->SetFunctionPrototype(thread, cloneClassPrototype.GetTaggedValue()); JSFunction::SetFunctionPrototype(thread, cloneClass, cloneClassPrototype.GetTaggedValue());
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
PropertyDescriptor ctorDesc(thread, JSHandle<JSTaggedValue>(cloneClass), true, false, true); PropertyDescriptor ctorDesc(thread, JSHandle<JSTaggedValue>(cloneClass), true, false, true);

View File

@ -49,6 +49,7 @@ group("ark_js_moduletest") {
"builtins", "builtins",
"callframe", "callframe",
"calltype", "calltype",
"changelistener",
"class", "class",
"compareobjecthclass", "compareobjecthclass",
"concurrent", "concurrent",
@ -228,6 +229,7 @@ group("ark_asm_test") {
"builtins", "builtins",
"callframe", "callframe",
"calltype", "calltype",
"changelistener",
"class", "class",
"compareobjecthclass", "compareobjecthclass",
"concurrent", "concurrent",
@ -378,6 +380,7 @@ group("ark_asm_single_step_test") {
"bitwiseop", "bitwiseop",
"callframe", "callframe",
"calltype", "calltype",
"changelistener",
"class", "class",
"compareobjecthclass", "compareobjecthclass",
"concurrent", "concurrent",

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("changelistener") {
deps = []
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @tc.name:changelistener
* @tc.desc:test changelistener function
* @tc.type: FUNC
*/
for (var a = 0; a < 100; a++) {
}
function f7(a8) {
return a8;
}
class C9 extends f7{}
for (let v15 = 0; v15 < 5; v15++)
{
const o16 = {};
const v18 = new Uint16Array();
const t30 = v18.__proto__;
print("222");
t30.__proto__ = o16;
print("111");
o16.c += NaN;
}

View File

@ -0,0 +1,23 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
222
111
222
111
222
111
222
111
222
111