Descriptor: delete FunctionKind in JSFunction

Details: delete FunctionKind in JSFunction

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I5LPNL

Signed-off-by: wengchangcheng <wengchangcheng@huawei.com>
Change-Id: Idc21112643211e691d5a0b6ae11831ad4bb7acd6
This commit is contained in:
wengchangcheng 2022-09-08 23:22:35 +08:00
parent 4ad9947c09
commit ff85273bc9
26 changed files with 171 additions and 171 deletions

View File

@ -137,6 +137,7 @@ if (defined(ark_standalone_build)) {
deps += [
"//arkcompiler/ets_runtime/test/aottest:ark_aot_js_test",
"//arkcompiler/ets_runtime/test/aottest:ark_aot_test",
#"//arkcompiler/ets_runtime/test/moduletest:ark_asm_single_step_test",
"//arkcompiler/ets_runtime/test/moduletest:ark_asm_test",
"//arkcompiler/ets_runtime/test/typeinfer:ark_typeinfer_test",

View File

@ -999,8 +999,7 @@ JSTaggedValue BuiltinsObject::FromEntries(EcmaRuntimeCallInfo *argv)
// 6. Let adder be ! CreateBuiltinFunction(stepsDefine, lengthDefine, "", « »).
JSHandle<Method> method(thread,
thread->GetEcmaVM()->GetMethodByIndex(MethodIndex::BUILTINS_OBJECT_CREATE_DATA_PROPERTY_ON_OBJECT_FUNCTIONS));
JSHandle<JSFunction> addrFunc =
factory->NewJSFunction(env, method, FunctionKind::NORMAL_FUNCTION);
JSHandle<JSFunction> addrFunc = factory->NewJSFunction(env, method);
JSHandle<JSTaggedValue> adder(thread, addrFunc.GetTaggedValue());

View File

@ -457,12 +457,6 @@ GateRef CircuitBuilder::GetGlobalObject(GateRef glue)
return Load(VariableType::JS_ANY(), glue, offset);
}
GateRef CircuitBuilder::GetFunctionBitFieldFromJSFunction(GateRef function)
{
GateRef offset = IntPtr(JSFunction::BIT_FIELD_OFFSET);
return Load(VariableType::INT32(), function, offset);
}
GateRef CircuitBuilder::GetMethodFromFunction(GateRef function)
{
GateRef offset = IntPtr(JSFunctionBase::METHOD_OFFSET);

View File

@ -394,7 +394,6 @@ public:
inline GateRef LogicOr(GateRef x, GateRef y);
inline GateRef BothAreString(GateRef x, GateRef y);
GateRef GetGlobalObject(GateRef glue);
GateRef GetFunctionBitFieldFromJSFunction(GateRef function);
GateRef GetMethodFromFunction(GateRef function);
GateRef GetModuleFromFunction(GateRef function);
GateRef FunctionIsResolved(GateRef function);

View File

@ -1015,12 +1015,13 @@ inline GateRef StubBuilder::IsConstructor(GateRef object)
inline GateRef StubBuilder::IsBase(GateRef func)
{
GateRef bitfieldOffset = IntPtr(JSFunction::BIT_FIELD_OFFSET);
GateRef bitfield = Load(VariableType::INT32(), func, bitfieldOffset);
GateRef method = GetMethodFromJSFunction(func);
GateRef extraLiteralInfoOffset = IntPtr(Method::EXTRA_LITERAL_INFO_OFFSET);
GateRef bitfield = Load(VariableType::INT32(), method, extraLiteralInfoOffset);
// decode
return Int32LessThanOrEqual(
Int32And(Int32LSR(bitfield, Int32(JSFunction::FunctionKindBits::START_BIT)),
Int32((1LU << JSFunction::FunctionKindBits::SIZE) - 1)),
Int32And(Int32LSR(bitfield, Int32(MethodLiteral::FunctionKindBits::START_BIT)),
Int32((1LU << MethodLiteral::FunctionKindBits::SIZE) - 1)),
Int32(static_cast<int32_t>(FunctionKind::CLASS_CONSTRUCTOR)));
}
@ -1738,12 +1739,6 @@ inline void StubBuilder::SetPropertiesToLexicalEnv(GateRef glue, GateRef object,
SetValueToTaggedArray(VariableType::JS_ANY(), glue, object, valueIndex, value);
}
inline GateRef StubBuilder::GetFunctionBitFieldFromJSFunction(GateRef object)
{
GateRef offset = IntPtr(JSFunction::BIT_FIELD_OFFSET);
return Load(VariableType::INT32(), object, offset);
}
inline GateRef StubBuilder::GetHomeObjectFromJSFunction(GateRef object)
{
GateRef offset = IntPtr(JSFunction::HOME_OBJECT_OFFSET);

View File

@ -406,7 +406,6 @@ public:
GateRef GetParentEnv(GateRef object);
GateRef GetPropertiesFromLexicalEnv(GateRef object, GateRef index);
void SetPropertiesToLexicalEnv(GateRef glue, GateRef object, GateRef index, GateRef value);
GateRef GetFunctionBitFieldFromJSFunction(GateRef object);
GateRef GetHomeObjectFromJSFunction(GateRef object);
GateRef GetCallFieldFromMethod(GateRef method);
inline GateRef GetBuiltinId(GateRef method);

View File

@ -95,7 +95,7 @@ public:
method->SetNativeBit(false);
method->SetNumArgsWithCallField(numArgs);
method->SetCodeEntry(reinterpret_cast<uintptr_t>(codeEntry));
JSHandle<JSFunction> jsfunc = factory->NewJSFunction(env, method, FunctionKind::NORMAL_FUNCTION);
JSHandle<JSFunction> jsfunc = factory->NewJSFunction(env, method);
return jsfunc.GetTaggedValue();
}

View File

@ -714,10 +714,11 @@ void AsmInterpreterCall::ResumeRspAndDispatch(ExtendedAssembler *assembler)
- static_cast<int64_t>(AsmInterpretedFrame::GetSize(false));
ASSERT(constructorOffset < 0);
__ Ldur(temp, MemoryOperand(sp, constructorOffset)); // load constructor
__ Ldr(temp, MemoryOperand(temp, JSFunction::BIT_FIELD_OFFSET));
__ Lsr(temp.W(), temp.W(), JSFunction::FunctionKindBits::START_BIT);
__ Ldr(temp, MemoryOperand(temp, JSFunctionBase::METHOD_OFFSET));
__ Ldr(temp, MemoryOperand(temp, Method::EXTRA_LITERAL_INFO_OFFSET));
__ Lsr(temp.W(), temp.W(), MethodLiteral::FunctionKindBits::START_BIT);
__ And(temp.W(), temp.W(),
LogicalImmediate::Create((1LU << JSFunction::FunctionKindBits::SIZE) - 1, RegWSize));
LogicalImmediate::Create((1LU << MethodLiteral::FunctionKindBits::SIZE) - 1, RegWSize));
__ Cmp(temp.W(), Immediate(static_cast<int64_t>(FunctionKind::CLASS_CONSTRUCTOR)));
__ B(Condition::LS, &getHiddenThis); // constructor is base
// exception branch

View File

@ -997,9 +997,10 @@ void AsmInterpreterCall::ResumeRspAndDispatch(ExtendedAssembler *assembler)
{
// load constructor
__ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetFunctionOffset(false)), temp);
__ Movl(Operand(temp, JSFunction::BIT_FIELD_OFFSET), temp);
__ Shr(JSFunction::FunctionKindBits::START_BIT, temp);
__ Andl((1LU << JSFunction::FunctionKindBits::SIZE) - 1, temp);
__ Movq(Operand(temp, JSFunctionBase::METHOD_OFFSET), temp);
__ Movq(Operand(temp, Method::EXTRA_LITERAL_INFO_OFFSET), temp);
__ Shr(MethodLiteral::FunctionKindBits::START_BIT, temp);
__ Andl((1LU << MethodLiteral::FunctionKindBits::SIZE) - 1, temp);
__ Cmpl(static_cast<int32_t>(FunctionKind::CLASS_CONSTRUCTOR), temp);
__ Jbe(&getHiddenThis); // constructor is base
// fall through

View File

@ -329,7 +329,7 @@ void CpuProfiler::GetNativeStack(FrameHandler &frameHandler, char *functionName,
std::stringstream stream;
JSFunction* function = JSFunction::Cast(frameHandler.GetFunction().GetTaggedObject());
// napi method
if (function->GetCallNative()) {
if (function->IsCallNative()) {
JSNativePointer *extraInfo = JSNativePointer::Cast(function->GetFunctionExtraInfo().GetTaggedObject());
auto cb = vm_->GetNativePtrGetter();
if (cb != nullptr && extraInfo != nullptr) {

View File

@ -1353,9 +1353,6 @@ void JSFunction::Dump(std::ostream &os) const
os << " - HomeObject: ";
GetHomeObject().Dump(os);
os << "\n";
os << " - FunctionKind: " << static_cast<int>(GetFunctionKind());
os << "\n";
os << " - FunctionExtraInfo: ";
GetFunctionExtraInfo().Dump(os);
os << "\n";
@ -3363,6 +3360,8 @@ void Method::Dump(std::ostream &os) const
os << " - ConstantPool: ";
GetConstantPool().Dump(os);
os << "\n";
os << " - FunctionKind: " << static_cast<int>(GetFunctionKind());
os << "\n";
os << " - CodeEntry: " << std::hex << GetCodeEntry() << "\n";
os << "\n";
}

View File

@ -830,6 +830,7 @@ void EcmaVM::GenerateInternalNativeMethods()
method->SetNativePointer(InternalMethodTable[i]);
method->SetNativeBit(true);
method->SetNumArgsWithCallField(numArgs);
method->SetFunctionKind(FunctionKind::NORMAL_FUNCTION);
internalNativeMethods_.emplace_back(method.GetTaggedValue());
}
}

View File

@ -39,8 +39,6 @@ void JSFunction::InitializeJSFunction(JSThread *thread, const JSHandle<JSFunctio
func->SetModule(thread, JSTaggedValue::Undefined(), SKIP_BARRIER);
func->SetProfileTypeInfo(thread, JSTaggedValue::Undefined(), SKIP_BARRIER);
func->SetMethod(thread, JSTaggedValue::Undefined(), SKIP_BARRIER);
func->SetFunctionKind(kind);
func->SetCallNative(false);
auto globalConst = thread->GlobalConstants();
if (HasPrototype(kind)) {
@ -50,15 +48,20 @@ void JSFunction::InitializeJSFunction(JSThread *thread, const JSHandle<JSFunctio
func->SetPropertyInlinedProps(thread, PROTOTYPE_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue());
accessor = globalConst->GetHandledFunctionNameAccessor();
func->SetPropertyInlinedProps(thread, NAME_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue());
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
if (kind == FunctionKind::ASYNC_GENERATOR_FUNCTION) {
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> objFun(env->GetObjectFunction());
JSHandle<JSObject> initialGeneratorFuncPrototype =
factory->NewJSObjectByConstructor(objFun);
JSHandle<JSObject> initialGeneratorFuncPrototype = factory->NewJSObjectByConstructor(objFun);
JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetAsyncGeneratorPrototype());
func->SetProtoOrHClass(thread, initialGeneratorFuncPrototype);
}
if (kind == FunctionKind::GENERATOR_FUNCTION) {
JSHandle<JSFunction> objFun(env->GetObjectFunction());
JSHandle<JSObject> initialGeneratorFuncPrototype = factory->NewJSObjectByConstructor(objFun);
JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
func->SetProtoOrHClass(thread, initialGeneratorFuncPrototype);
}
} else if (!JSFunction::IsClassConstructor(kind)) { // class ctor do nothing
PropertyDescriptor desc(thread, accessor, kind != FunctionKind::BUILTIN_CONSTRUCTOR, false, false);
[[maybe_unused]] bool success = JSObject::DefineOwnProperty(thread, JSHandle<JSObject>(func),

View File

@ -39,6 +39,24 @@ public:
const JSHandle<JSTaggedValue> &name, const JSHandle<JSTaggedValue> &prefix);
static JSHandle<JSTaggedValue> GetFunctionName(JSThread *thread, const JSHandle<JSFunctionBase> &func);
void SetCallNative(bool isCallNative)
{
JSTaggedValue method = GetMethod();
Method::Cast(method.GetTaggedObject())->SetCallNative(isCallNative);
}
bool IsCallNative() const
{
JSTaggedValue method = GetMethod();
return Method::ConstCast(method.GetTaggedObject())->IsCallNative();
}
FunctionKind GetFunctionKind() const
{
JSTaggedValue method = GetMethod();
return Method::ConstCast(method.GetTaggedObject())->GetFunctionKind();
}
static constexpr size_t METHOD_OFFSET = JSObject::SIZE;
ACCESSORS(Method, METHOD_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);
@ -204,17 +222,10 @@ public:
ACCESSORS(LexicalEnv, LEXICAL_ENV_OFFSET, HOME_OBJECT_OFFSET)
ACCESSORS(HomeObject, HOME_OBJECT_OFFSET, PROFILE_TYPE_INFO_OFFSET)
ACCESSORS(ProfileTypeInfo, PROFILE_TYPE_INFO_OFFSET, ECMA_MODULE_OFFSET)
ACCESSORS(Module, ECMA_MODULE_OFFSET, BIT_FIELD_OFFSET)
ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
ACCESSORS(Module, ECMA_MODULE_OFFSET, LAST_OFFSET)
DEFINE_ALIGN_SIZE(LAST_OFFSET);
// define BitField
static constexpr uint32_t FUNCTION_KIND_BITS = 4;
static constexpr uint32_t CALL_NATIVE_BITS = 1;
FIRST_BIT_FIELD(BitField, FunctionKind, FunctionKind, FUNCTION_KIND_BITS)
NEXT_BIT_FIELD(BitField, CallNative, bool, CALL_NATIVE_BITS, FunctionKind)
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunctionBase, PROTO_OR_DYNCLASS_OFFSET, BIT_FIELD_OFFSET)
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunctionBase, PROTO_OR_DYNCLASS_OFFSET, SIZE)
DECL_DUMP()
private:

View File

@ -291,7 +291,7 @@ JSHandle<JSFunction> ClassHelper::DefineClassFromExtractor(JSThread *thread, JSH
JSHandle<Method> method(thread, Method::Cast(extractor->GetConstructorMethod().GetTaggedObject()));
JSHandle<JSFunction> constructor = factory->NewJSFunctionByHClass(method,
constructorHClass, FunctionKind::CLASS_CONSTRUCTOR, MemSpaceType::OLD_SPACE);
constructorHClass, MemSpaceType::OLD_SPACE);
// non-static
nonStaticProperties->Set(thread, 0, constructor);

View File

@ -93,6 +93,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil
uint16_t length = std::get<uint16_t>(value);
auto methodLiteral = jsPandaFile->FindMethodLiteral(methodId);
ASSERT(methodLiteral != nullptr);
methodLiteral->SetFunctionKind(kind);
JSHandle<Method> method = factory->NewMethod(methodLiteral);
method->SetConstantPool(thread, constpool.GetTaggedValue());
@ -243,14 +244,8 @@ JSHandle<JSFunction> LiteralDataExtractor::DefineMethodInLiteral(JSThread *threa
functionClass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
}
JSHandle<JSFunction> jsFunc =
factory->NewJSFunctionByHClass(method, functionClass, kind, MemSpaceType::OLD_SPACE);
factory->NewJSFunctionByHClass(method, functionClass, MemSpaceType::OLD_SPACE);
if (kind == FunctionKind::GENERATOR_FUNCTION) {
JSHandle<JSFunction> objFun(env->GetObjectFunction());
JSHandle<JSObject> initialGeneratorFuncPrototype = factory->NewJSObjectByConstructor(objFun);
JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
jsFunc->SetProtoOrHClass(thread, initialGeneratorFuncPrototype);
}
jsFunc->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length));
CString moduleName = jsPandaFile->GetJSPandaFileDesc();
CString entry = JSPandaFile::ENTRY_FUNCTION_NAME;

View File

@ -65,6 +65,7 @@ struct PUBLIC_API MethodLiteral : public base::AlignedStruct<sizeof(uint64_t),
using IsNativeBit = NumArgsBits::NextFlag; // offset 60
using IsAotCodeBit = IsNativeBit::NextFlag; // offset 61
using IsFastBuiltinBit = IsAotCodeBit::NextFlag; // offset 62
using IsCallNativeBit = IsFastBuiltinBit::NextFlag; // offset 63
uint64_t GetCallField() const
{
@ -85,37 +86,37 @@ struct PUBLIC_API MethodLiteral : public base::AlignedStruct<sizeof(uint64_t),
bool HaveThisWithCallField() const
{
return HaveThisBit::Decode(callField_);
return HaveThisWithCallField(callField_);
}
bool HaveNewTargetWithCallField() const
{
return HaveNewTargetBit::Decode(callField_);
return HaveNewTargetWithCallField(callField_);
}
bool HaveExtraWithCallField() const
{
return HaveExtraBit::Decode(callField_);
return HaveExtraWithCallField(callField_);
}
bool HaveFuncWithCallField() const
{
return HaveFuncBit::Decode(callField_);
return HaveFuncWithCallField(callField_);
}
bool IsNativeWithCallField() const
{
return IsNativeBit::Decode(callField_);
return IsNativeWithCallField(callField_);
}
bool IsAotWithCallField() const
{
return IsAotCodeBit::Decode(callField_);
return IsAotWithCallField(callField_);
}
uint32_t GetNumArgsWithCallField() const
{
return NumArgsBits::Decode(callField_);
return GetNumArgsWithCallField(callField_);
}
uint32_t GetNumArgs() const
@ -194,6 +195,16 @@ struct PUBLIC_API MethodLiteral : public base::AlignedStruct<sizeof(uint64_t),
return NumArgsBits::Decode(callField);
}
static uint64_t SetCallNative(uint64_t callField, bool isCallNative)
{
return IsCallNativeBit::Update(callField, isCallNative);
}
static bool IsCallNative(uint64_t callField)
{
return IsCallNativeBit::Decode(callField);
}
static constexpr size_t METHOD_ARGS_NUM_BITS = 16;
static constexpr size_t METHOD_ARGS_METHODID_BITS = 32;
static constexpr size_t METHOD_SLOT_SIZE_BITS = 16;
@ -261,6 +272,11 @@ struct PUBLIC_API MethodLiteral : public base::AlignedStruct<sizeof(uint64_t),
return HotnessCounterBits::Update(literalInfo, counter);
}
static uint64_t SetFunctionKind(uint64_t extraLiteralInfo, FunctionKind kind)
{
return FunctionKindBits::Update(extraLiteralInfo, kind);
}
static FunctionKind GetFunctionKind(uint64_t extraLiteralInfo)
{
return static_cast<FunctionKind>(FunctionKindBits::Decode(extraLiteralInfo));

View File

@ -210,8 +210,7 @@ JSHandle<Program> PandaFileTranslator::GenerateProgram(EcmaVM *vm, const JSPanda
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
JSHandle<Method> method = factory->NewMethod(methodLiteral);
JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithProto());
JSHandle<JSFunction> mainFunc =
factory->NewJSFunctionByHClass(method, hclass, FunctionKind::BASE_CONSTRUCTOR);
JSHandle<JSFunction> mainFunc = factory->NewJSFunctionByHClass(method, hclass);
program->SetMainFunction(thread, mainFunc.GetTaggedValue());
method->SetConstantPool(thread, constpool);
@ -309,14 +308,15 @@ JSHandle<ConstantPool> PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSP
} else if (value.GetConstpoolType() == ConstPoolType::CLASS_FUNCTION) {
MethodLiteral *methodLiteral = jsPandaFile->FindMethodLiteral(it.first);
ASSERT(methodLiteral != nullptr);
methodLiteral->SetFunctionKind(FunctionKind::CLASS_CONSTRUCTOR);
JSHandle<Method> method = factory->NewMethod(methodLiteral);
method->SetConstantPool(thread, constpool.GetTaggedValue());
constpool->SetObjectToCache(thread, value.GetConstpoolIndex(), method.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::METHOD) {
MethodLiteral *methodLiteral = jsPandaFile->FindMethodLiteral(it.first);
methodLiteral->SetFunctionKind(FunctionKind::NORMAL_FUNCTION);
ASSERT(methodLiteral != nullptr);
methodLiteral->SetFunctionKind(FunctionKind::NORMAL_FUNCTION);
JSHandle<Method> method = factory->NewMethod(methodLiteral);
if (isLoadedAOT) {
fileLoader->SetAOTFuncEntry(jsPandaFile, *method);
@ -422,8 +422,7 @@ JSHandle<Program> PandaFileTranslator::GenerateProgramWithMerge(EcmaVM *vm, cons
} else {
JSHandle<Method> method = factory->NewMethod(methodLiteral);
JSHandle<JSHClass> dynclass = JSHandle<JSHClass>::Cast(vm->GetGlobalEnv()->GetFunctionClassWithProto());
JSHandle<JSFunction> mainFunc =
factory->NewJSFunctionByHClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR);
JSHandle<JSFunction> mainFunc = factory->NewJSFunctionByHClass(method, dynclass);
program->SetMainFunction(thread, mainFunc.GetTaggedValue());
method->SetConstantPool(thread, constpool);
@ -514,6 +513,7 @@ void PandaFileTranslator::ParseConstPoolWithMerge(EcmaVM *vm, const JSPandaFile
} else if (value.GetConstpoolType() == ConstPoolType::CLASS_FUNCTION) {
MethodLiteral *methodLiteral = jsPandaFile->FindMethodLiteral(it.first);
ASSERT(methodLiteral != nullptr);
methodLiteral->SetFunctionKind(FunctionKind::CLASS_CONSTRUCTOR);
JSHandle<Method> method = factory->NewMethod(methodLiteral);
method->SetConstantPool(thread, constpool.GetTaggedValue());

View File

@ -151,6 +151,13 @@ public:
return MethodLiteral::GetSlotSize(literalInfo);
}
void SetFunctionKind(FunctionKind kind)
{
uint64_t extraLiteralInfo = GetExtraLiteralInfo();
uint64_t newValue = MethodLiteral::SetFunctionKind(extraLiteralInfo, kind);
SetExtraLiteralInfo(newValue);
}
FunctionKind GetFunctionKind() const
{
uint64_t extraLiteralInfo = GetExtraLiteralInfo();
@ -163,6 +170,19 @@ public:
return MethodLiteral::GetBuiltinId(extraLiteralInfo);
}
void SetCallNative(bool isCallNative)
{
uint64_t callField = GetCallField();
uint64_t newValue = MethodLiteral::SetCallNative(callField, isCallNative);
SetCallField(newValue);
}
bool IsCallNative() const
{
uint64_t callField = GetCallField();
return MethodLiteral::IsCallNative(callField);
}
void SetBuiltinId(uint8_t id)
{
uint64_t extraLiteralInfo = GetExtraLiteralInfo();

View File

@ -869,7 +869,7 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_004)
factory->NewEcmaHClass(JSFunction::SIZE, JSType::JS_FUNCTION, funcFuncPrototypeValue);
// new with NewJSFunctionByHClass::function Class
JSHandle<JSFunction> protoFunc =
factory->NewJSFunctionByHClass(ctor, funcFuncProtoIntanceClass, FunctionKind::BUILTIN_CONSTRUCTOR);
factory->NewJSFunctionByHClass(ctor, funcFuncProtoIntanceClass);
EXPECT_TRUE(*protoFunc != nullptr);
// add method in funcnction
PropertyDescriptor desc1 = PropertyDescriptor(thread_, addMethod);
@ -886,7 +886,7 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_004)
factory->NewEcmaHClass(JSFunction::SIZE, JSType::JS_FUNCTION, funcFuncNoProtoPrototypeValue);
// new with NewJSFunctionByHClass::function Class
JSHandle<JSFunction> noProtoFunc = factory->NewJSFunctionByHClass(ctor,
funcFuncNoProtoProtoIntanceClass, FunctionKind::BUILTIN_CONSTRUCTOR);
funcFuncNoProtoProtoIntanceClass);
EXPECT_TRUE(*noProtoFunc != nullptr);
// set property that has same key with fater type
PropertyDescriptor desc2 = PropertyDescriptor(thread_, defaultString);

View File

@ -139,7 +139,7 @@ using ErrorHelper = base::ErrorHelper;
ObjectFactory::ObjectFactory(JSThread *thread, Heap *heap)
: thread_(thread), vm_(thread->GetEcmaVM()), heap_(heap) {}
JSHandle<Method> ObjectFactory::NewMethodForNativeFunction(const void *func, uint8_t builtinId)
JSHandle<Method> ObjectFactory::NewMethodForNativeFunction(const void *func, FunctionKind kind, uint8_t builtinId)
{
uint32_t numArgs = 2; // function object and this
auto method = NewMethod(nullptr);
@ -150,6 +150,7 @@ JSHandle<Method> ObjectFactory::NewMethodForNativeFunction(const void *func, uin
method->SetBuiltinId(builtinId);
}
method->SetNumArgsWithCallField(numArgs);
method->SetFunctionKind(kind);
return method;
}
@ -464,7 +465,7 @@ JSHandle<TaggedArray> ObjectFactory::CloneProperties(const JSHandle<TaggedArray>
newArray->Set(thread_, i, value);
} else {
JSHandle<JSFunction> valueHandle(thread_, value);
JSHandle<JSFunction> newFunc = CloneJSFuction(valueHandle, valueHandle->GetFunctionKind());
JSHandle<JSFunction> newFunc = CloneJSFuction(valueHandle);
newFunc->SetLexicalEnv(thread_, env);
newFunc->SetHomeObject(thread_, obj);
newArray->Set(thread_, i, newFunc);
@ -499,7 +500,7 @@ JSHandle<JSObject> ObjectFactory::CloneObjectLiteral(JSHandle<JSObject> object,
cloneObject->SetPropertyInlinedProps(thread_, i, value);
} else {
JSHandle<JSFunction> valueHandle(thread_, value);
JSHandle<JSFunction> newFunc = CloneJSFuction(valueHandle, valueHandle->GetFunctionKind());
JSHandle<JSFunction> newFunc = CloneJSFuction(valueHandle);
newFunc->SetLexicalEnv(thread_, env);
newFunc->SetHomeObject(thread_, cloneObject);
cloneObject->SetPropertyInlinedProps(thread_, i, newFunc.GetTaggedValue());
@ -508,22 +509,15 @@ JSHandle<JSObject> ObjectFactory::CloneObjectLiteral(JSHandle<JSObject> object,
return cloneObject;
}
JSHandle<JSFunction> ObjectFactory::CloneJSFuction(JSHandle<JSFunction> obj, FunctionKind kind)
JSHandle<JSFunction> ObjectFactory::CloneJSFuction(JSHandle<JSFunction> func)
{
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
JSHandle<JSHClass> jshclass(thread_, obj->GetJSHClass());
JSHandle<Method> method(thread_, obj->GetMethod());
JSHandle<JSFunction> cloneFunc = NewJSFunctionByHClass(method, jshclass, kind);
if (kind == FunctionKind::GENERATOR_FUNCTION) {
JSHandle<JSFunction> objFun(env->GetObjectFunction());
JSHandle<JSObject> initialGeneratorFuncPrototype = NewJSObjectByConstructor(objFun);
JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
cloneFunc->SetProtoOrHClass(thread_, initialGeneratorFuncPrototype);
}
JSHandle<JSHClass> jshclass(thread_, func->GetJSHClass());
JSHandle<Method> method(thread_, func->GetMethod());
JSHandle<JSFunction> cloneFunc = NewJSFunctionByHClass(method, jshclass);
JSTaggedValue length = obj->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX);
JSTaggedValue length = func->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX);
cloneFunc->SetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, length);
cloneFunc->SetModule(thread_, obj->GetModule());
cloneFunc->SetModule(thread_, func->GetModule());
return cloneFunc;
}
@ -537,12 +531,11 @@ JSHandle<JSFunction> ObjectFactory::CloneClassCtor(JSHandle<JSFunction> ctor, co
hclass = JSHClass::Clone(thread_, hclass);
}
FunctionKind kind = ctor->GetFunctionKind();
ASSERT_PRINT(kind == FunctionKind::CLASS_CONSTRUCTOR || kind == FunctionKind::DERIVED_CONSTRUCTOR,
"cloned function is not class");
JSHandle<Method> method(thread_, ctor->GetMethod());
JSHandle<JSFunction> cloneCtor = NewJSFunctionByHClass(method, hclass, kind);
ASSERT_PRINT(method->GetFunctionKind() == FunctionKind::CLASS_CONSTRUCTOR ||
method->GetFunctionKind() == FunctionKind::DERIVED_CONSTRUCTOR,
"cloned function is not class");
JSHandle<JSFunction> cloneCtor = NewJSFunctionByHClass(method, hclass);
for (uint32_t i = 0; i < hclass->GetInlinedProperties(); i++) {
JSTaggedValue value = ctor->GetPropertyInlinedProps(i);
@ -550,7 +543,7 @@ JSHandle<JSFunction> ObjectFactory::CloneClassCtor(JSHandle<JSFunction> ctor, co
cloneCtor->SetPropertyInlinedProps(thread_, i, value);
} else {
JSHandle<JSFunction> valueHandle(thread_, value);
JSHandle<JSFunction> newFunc = CloneJSFuction(valueHandle, valueHandle->GetFunctionKind());
JSHandle<JSFunction> newFunc = CloneJSFuction(valueHandle);
newFunc->SetLexicalEnv(thread_, lexenv);
newFunc->SetHomeObject(thread_, cloneCtor);
cloneCtor->SetPropertyInlinedProps(thread_, i, newFunc.GetTaggedValue());
@ -1142,31 +1135,31 @@ void ObjectFactory::InitializeJSObject(const JSHandle<JSObject> &obj, const JSHa
break;
case JSType::JS_FUNCTION:
case JSType::JS_GENERATOR_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
break;
case JSType::JS_ASYNC_GENERATOR_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
break;
case JSType::JS_PROXY_REVOC_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSProxyRevocFunction::Cast(*obj)->SetRevocableProxy(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_REACTIONS_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSPromiseReactionsFunction::Cast(*obj)->SetPromise(thread_, JSTaggedValue::Undefined());
JSPromiseReactionsFunction::Cast(*obj)->SetAlreadyResolved(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_EXECUTOR_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSPromiseExecutorFunction::Cast(*obj)->SetCapability(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_ASYNC_GENERATOR_RESUME_NEXT_RETURN_PROCESSOR_RST_FTN:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSAsyncGeneratorResNextRetProRstFtn::Cast(*obj)->SetAsyncGeneratorObject(thread_,
JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSPromiseAllResolveElementFunction::Cast(*obj)->SetIndex(thread_, JSTaggedValue::Undefined());
JSPromiseAllResolveElementFunction::Cast(*obj)->SetValues(thread_, JSTaggedValue::Undefined());
JSPromiseAllResolveElementFunction::Cast(*obj)->SetCapabilities(thread_, JSTaggedValue::Undefined());
@ -1174,7 +1167,7 @@ void ObjectFactory::InitializeJSObject(const JSHandle<JSObject> &obj, const JSHa
JSPromiseAllResolveElementFunction::Cast(*obj)->SetAlreadyCalled(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSPromiseAnyRejectElementFunction::Cast(*obj)->SetIndex(0);
JSPromiseAnyRejectElementFunction::Cast(*obj)->SetErrors(thread_, JSTaggedValue::Undefined());
JSPromiseAnyRejectElementFunction::Cast(*obj)->SetCapability(thread_, JSTaggedValue::Undefined());
@ -1182,7 +1175,7 @@ void ObjectFactory::InitializeJSObject(const JSHandle<JSObject> &obj, const JSHa
JSPromiseAnyRejectElementFunction::Cast(*obj)->SetAlreadyCalled(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSPromiseAllSettledElementFunction::Cast(*obj)->SetIndex(0);
JSPromiseAllSettledElementFunction::Cast(*obj)->SetValues(thread_, JSTaggedValue::Undefined());
JSPromiseAllSettledElementFunction::Cast(*obj)->SetCapability(thread_, JSTaggedValue::Undefined());
@ -1190,16 +1183,16 @@ void ObjectFactory::InitializeJSObject(const JSHandle<JSObject> &obj, const JSHa
JSPromiseAllSettledElementFunction::Cast(*obj)->SetAlreadyCalled(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_FINALLY_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSPromiseFinallyFunction::Cast(*obj)->SetOnFinally(thread_, JSTaggedValue::Undefined());
JSPromiseFinallyFunction::Cast(*obj)->SetConstructor(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSPromiseValueThunkOrThrowerFunction::Cast(*obj)->SetResult(thread_, JSTaggedValue::Undefined());
break;
case JSType::JS_INTL_BOUND_FUNCTION:
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj), FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>(obj));
JSIntlBoundFunction::Cast(*obj)->SetNumberFormat(thread_, JSTaggedValue::Undefined());
JSIntlBoundFunction::Cast(*obj)->SetDateTimeFormat(thread_, JSTaggedValue::Undefined());
JSIntlBoundFunction::Cast(*obj)->SetCollator(thread_, JSTaggedValue::Undefined());
@ -1329,13 +1322,14 @@ JSHandle<JSObject> ObjectFactory::OrdinaryNewJSObjectCreate(const JSHandle<JSTag
JSHandle<JSFunction> ObjectFactory::NewJSFunction(const JSHandle<GlobalEnv> &env, const void *nativeFunc,
FunctionKind kind, uint8_t builtinId)
{
JSHandle<Method> target = NewMethodForNativeFunction(nativeFunc, builtinId);
return NewJSFunction(env, target, kind);
JSHandle<Method> target = NewMethodForNativeFunction(nativeFunc, kind, builtinId);
return NewJSFunction(env, target);
}
JSHandle<JSFunction> ObjectFactory::NewJSFunction(const JSHandle<GlobalEnv> &env,
const JSHandle<Method> &method, FunctionKind kind)
const JSHandle<Method> &method)
{
FunctionKind kind = method->GetFunctionKind();
JSHandle<JSHClass> hclass;
if (kind == FunctionKind::BASE_CONSTRUCTOR) {
hclass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithProto());
@ -1345,7 +1339,7 @@ JSHandle<JSFunction> ObjectFactory::NewJSFunction(const JSHandle<GlobalEnv> &env
hclass = JSHandle<JSHClass>::Cast(env->GetNormalFunctionClass());
}
return NewJSFunctionByHClass(method, hclass, kind);
return NewJSFunctionByHClass(method, hclass);
}
JSHandle<JSHClass> ObjectFactory::CreateFunctionClass(FunctionKind kind, uint32_t size, JSType type,
@ -1413,7 +1407,7 @@ JSHandle<JSHClass> ObjectFactory::CreateFunctionClass(FunctionKind kind, uint32_
JSHandle<JSFunction> ObjectFactory::NewJSFunctionByHClass(const JSHandle<Method> &method,
const JSHandle<JSHClass> &clazz,
FunctionKind kind, MemSpaceType type)
MemSpaceType type)
{
JSHandle<JSFunction> function;
switch (type) {
@ -1431,15 +1425,15 @@ JSHandle<JSFunction> ObjectFactory::NewJSFunctionByHClass(const JSHandle<Method>
}
clazz->SetCallable(true);
clazz->SetExtensible(true);
JSFunction::InitializeJSFunction(thread_, function, kind);
JSFunction::InitializeJSFunction(thread_, function, method->GetFunctionKind());
function->SetMethod(thread_, method);
return function;
}
JSHandle<JSFunction> ObjectFactory::NewJSFunctionByHClass(const void *func, const JSHandle<JSHClass> &clazz,
FunctionKind kind)
FunctionKind kind)
{
JSHandle<Method> method = NewMethodForNativeFunction(func);
JSHandle<Method> method = NewMethodForNativeFunction(func, kind);
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(NewJSObject(clazz));
clazz->SetCallable(true);
clazz->SetExtensible(true);
@ -1473,17 +1467,17 @@ JSHandle<Method> ObjectFactory::NewMethod(const MethodLiteral *methodLiteral)
JSHandle<JSFunction> ObjectFactory::NewJSNativeErrorFunction(const JSHandle<GlobalEnv> &env, const void *nativeFunc)
{
JSHandle<Method> target = NewMethodForNativeFunction(nativeFunc);
JSHandle<Method> target = NewMethodForNativeFunction(nativeFunc, FunctionKind::BUILTIN_CONSTRUCTOR);
JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetNativeErrorFunctionClass());
return NewJSFunctionByHClass(target, hclass, FunctionKind::BUILTIN_CONSTRUCTOR);
return NewJSFunctionByHClass(target, hclass);
}
JSHandle<JSFunction> ObjectFactory::NewSpecificTypedArrayFunction(const JSHandle<GlobalEnv> &env,
const void *nativeFunc)
{
JSHandle<Method> target = NewMethodForNativeFunction(nativeFunc);
JSHandle<Method> target = NewMethodForNativeFunction(nativeFunc, FunctionKind::BUILTIN_CONSTRUCTOR);
JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetSpecificTypedArrayFunctionClass());
return NewJSFunctionByHClass(target, hclass, FunctionKind::BUILTIN_CONSTRUCTOR);
return NewJSFunctionByHClass(target, hclass);
}
JSHandle<JSFunction> ObjectFactory::NewAotFunction(uint32_t numArgs, uintptr_t codeEntry)
@ -1494,7 +1488,7 @@ JSHandle<JSFunction> ObjectFactory::NewAotFunction(uint32_t numArgs, uintptr_t c
method->SetNativeBit(false);
method->SetNumArgsWithCallField(numArgs);
method->SetCodeEntry(codeEntry);
JSHandle<JSFunction> jsfunc = NewJSFunction(env, method, FunctionKind::NORMAL_FUNCTION);
JSHandle<JSFunction> jsfunc = NewJSFunction(env, method);
return jsfunc;
}
@ -1528,7 +1522,7 @@ JSHandle<JSIntlBoundFunction> ObjectFactory::NewJSIntlBoundFunction(MethodIndex
intlBoundFunc->SetDateTimeFormat(thread_, JSTaggedValue::Undefined());
intlBoundFunc->SetCollator(thread_, JSTaggedValue::Undefined());
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(intlBoundFunc);
JSFunction::InitializeJSFunction(thread_, function, FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, function);
function->SetMethod(thread_, vm_->GetMethodByIndex(idx));
JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(functionLength));
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
@ -1549,7 +1543,7 @@ JSHandle<JSProxyRevocFunction> ObjectFactory::NewJSProxyRevocFunction(const JSHa
revocFunction->SetRevocableProxy(thread_, JSTaggedValue::Undefined());
revocFunction->SetRevocableProxy(thread_, proxy);
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(revocFunction);
JSFunction::InitializeJSFunction(thread_, function, FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, function);
function->SetMethod(thread_, vm_->GetMethodByIndex(MethodIndex::BUILTINS_PROXY_INVALIDATE_PROXY_FUNCTION));
JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(0));
JSHandle<JSTaggedValue> emptyString = globalConst->GetHandledEmptyString();
@ -1572,17 +1566,6 @@ JSHandle<JSAsyncAwaitStatusFunction> ObjectFactory::NewJSAsyncAwaitStatusFunctio
return awaitFunction;
}
JSHandle<JSFunction> ObjectFactory::NewJSGeneratorFunction(const JSHandle<Method> &method)
{
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
JSHandle<JSFunction> generatorFunc = JSHandle<JSFunction>::Cast(NewJSObject(hclass));
JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION);
generatorFunc->SetMethod(thread_, method);
return generatorFunc;
}
JSHandle<JSGeneratorObject> ObjectFactory::NewJSGeneratorObject(JSHandle<JSTaggedValue> generatorFunction)
{
JSHandle<JSTaggedValue> proto(thread_, JSHandle<JSFunction>::Cast(generatorFunction)->GetProtoOrHClass());
@ -1611,16 +1594,6 @@ JSHandle<JSAsyncGeneratorObject> ObjectFactory::NewJSAsyncGeneratorObject(JSHand
return generatorObject;
}
JSHandle<JSAsyncFunction> ObjectFactory::NewAsyncFunction(const JSHandle<Method> &method)
{
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetAsyncFunctionClass());
JSHandle<JSAsyncFunction> asyncFunction = JSHandle<JSAsyncFunction>::Cast(NewJSObject(hclass));
JSFunction::InitializeJSFunction(thread_, JSHandle<JSFunction>::Cast(asyncFunction));
asyncFunction->SetMethod(thread_, method);
return asyncFunction;
}
JSHandle<JSAsyncFuncObject> ObjectFactory::NewJSAsyncFuncObject()
{
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
@ -2564,7 +2537,7 @@ JSHandle<JSPromiseExecutorFunction> ObjectFactory::CreateJSPromiseExecutorFuncti
executorFunction->SetCapability(thread_, JSTaggedValue::Hole());
executorFunction->SetCapability(thread_, JSTaggedValue::Undefined());
JSHandle<JSFunction> function = JSHandle<JSFunction>::Cast(executorFunction);
JSFunction::InitializeJSFunction(thread_, function, FunctionKind::NORMAL_FUNCTION);
JSFunction::InitializeJSFunction(thread_, function);
executorFunction->SetMethod(
thread_, vm_->GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_EXECUTOR));
JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(FunctionLength::TWO));

View File

@ -180,7 +180,8 @@ class ObjectFactory {
public:
ObjectFactory(JSThread *thread, Heap *heap);
~ObjectFactory() = default;
JSHandle<Method> NewMethodForNativeFunction(const void *func, uint8_t builtinId = INVALID_BUILTINS_ID);
JSHandle<Method> NewMethodForNativeFunction(const void *func, FunctionKind kind = FunctionKind::NORMAL_FUNCTION,
uint8_t builtinId = INVALID_BUILTINS_ID);
JSHandle<ProfileTypeInfo> NewProfileTypeInfo(uint32_t length);
JSHandle<ConstantPool> NewConstantPool(uint32_t capacity);
@ -205,8 +206,7 @@ public:
FunctionKind kind = FunctionKind::NORMAL_FUNCTION,
uint8_t builtinId = INVALID_BUILTINS_ID);
// use for method
JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<Method> &method,
FunctionKind kind = FunctionKind::NORMAL_FUNCTION);
JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<Method> &method);
JSHandle<JSFunction> NewJSNativeErrorFunction(const JSHandle<GlobalEnv> &env, const void *nativeFunc = nullptr);
@ -228,9 +228,6 @@ public:
JSHandle<JSProxyRevocFunction> NewJSProxyRevocFunction(const JSHandle<JSProxy> &proxy);
JSHandle<JSAsyncAwaitStatusFunction> NewJSAsyncAwaitStatusFunction(MethodIndex idx);
JSHandle<JSFunction> NewJSGeneratorFunction(const JSHandle<Method> &method);
JSHandle<JSAsyncFunction> NewAsyncFunction(const JSHandle<Method> &method);
JSHandle<JSGeneratorObject> NewJSGeneratorObject(JSHandle<JSTaggedValue> generatorFunction);
@ -389,7 +386,7 @@ public:
bool canShareHClass = true);
JSHandle<JSObject> CloneObjectLiteral(JSHandle<JSObject> object);
JSHandle<JSArray> CloneArrayLiteral(JSHandle<JSArray> object);
JSHandle<JSFunction> CloneJSFuction(JSHandle<JSFunction> obj, FunctionKind kind);
JSHandle<JSFunction> CloneJSFuction(JSHandle<JSFunction> func);
JSHandle<JSFunction> CloneClassCtor(JSHandle<JSFunction> ctor, const JSHandle<JSTaggedValue> &lexenv,
bool canShareHClass);
@ -426,10 +423,9 @@ public:
JSHandle<JSHClass> GetObjectLiteralHClass(const JSHandle<TaggedArray> &properties, size_t length);
// only use for creating Function.prototype and Function
JSHandle<JSFunction> NewJSFunctionByHClass(const JSHandle<Method> &method, const JSHandle<JSHClass> &clazz,
FunctionKind kind = FunctionKind::NORMAL_FUNCTION,
MemSpaceType type = MemSpaceType::SEMI_SPACE);
MemSpaceType type = MemSpaceType::SEMI_SPACE);
JSHandle<JSFunction> NewJSFunctionByHClass(const void *func, const JSHandle<JSHClass> &clazz,
FunctionKind kind = FunctionKind::NORMAL_FUNCTION);
FunctionKind kind = FunctionKind::NORMAL_FUNCTION);
JSHandle<Method> NewMethod(const MethodLiteral *methodLiteral);
// used for creating jsobject by constructor

View File

@ -776,18 +776,19 @@ JSTaggedValue RuntimeStubs::RuntimeSetClassInheritanceRelationship(JSThread *thr
JSHandle<JSTaggedValue> parentPrototype;
// hole means parent is not present
Method *method = Method::Cast(JSHandle<JSFunction>::Cast(ctor)->GetMethod().GetTaggedObject());
if (parent->IsHole()) {
JSHandle<JSFunction>::Cast(ctor)->SetFunctionKind(FunctionKind::CLASS_CONSTRUCTOR);
method->SetFunctionKind(FunctionKind::CLASS_CONSTRUCTOR);
parentPrototype = env->GetObjectFunctionPrototype();
parent.Update(env->GetFunctionPrototype().GetTaggedValue());
} else if (parent->IsNull()) {
JSHandle<JSFunction>::Cast(ctor)->SetFunctionKind(FunctionKind::DERIVED_CONSTRUCTOR);
method->SetFunctionKind(FunctionKind::DERIVED_CONSTRUCTOR);
parentPrototype = JSHandle<JSTaggedValue>(thread, JSTaggedValue::Null());
parent.Update(env->GetFunctionPrototype().GetTaggedValue());
} else if (!parent->IsConstructor()) {
return RuntimeThrowTypeError(thread, "parent class is not constructor");
} else {
JSHandle<JSFunction>::Cast(ctor)->SetFunctionKind(FunctionKind::DERIVED_CONSTRUCTOR);
method->SetFunctionKind(FunctionKind::DERIVED_CONSTRUCTOR);
parentPrototype = JSTaggedValue::GetProperty(thread, parent,
globalConst->GetHandledPrototypeString()).GetValue();
if (!parentPrototype->IsECMAObject() && !parentPrototype->IsNull()) {
@ -1673,42 +1674,35 @@ JSTaggedValue RuntimeStubs::RuntimeDefinefunc(JSThread *thread, const JSHandle<M
case FunctionKind::NORMAL_FUNCTION:
case FunctionKind::BASE_CONSTRUCTOR: {
auto hclass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithProto());
jsFunc = factory->NewJSFunctionByHClass(methodHandle, hclass, kind, MemSpaceType::OLD_SPACE);
jsFunc = factory->NewJSFunctionByHClass(methodHandle, hclass, MemSpaceType::OLD_SPACE);
break;
}
case FunctionKind::ARROW_FUNCTION: {
auto normalClass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithoutProto());
jsFunc = factory->NewJSFunctionByHClass(methodHandle, normalClass, kind, MemSpaceType::OLD_SPACE);
jsFunc = factory->NewJSFunctionByHClass(methodHandle, normalClass, MemSpaceType::OLD_SPACE);
break;
}
case FunctionKind::GENERATOR_FUNCTION: {
auto generatorClass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
jsFunc = factory->NewJSFunctionByHClass(methodHandle, generatorClass, kind, MemSpaceType::OLD_SPACE);
// 26.3.4.3 prototype
// Whenever a GeneratorFunction instance is created another ordinary object is also created and
// is the initial value of the generator function's "prototype" property.
JSHandle<JSFunction> objFun(env->GetObjectFunction());
JSHandle<JSObject> initialGeneratorFuncPrototype = factory->NewJSObjectByConstructor(objFun);
JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
jsFunc->SetProtoOrHClass(thread, initialGeneratorFuncPrototype);
jsFunc = factory->NewJSFunctionByHClass(methodHandle, generatorClass, MemSpaceType::OLD_SPACE);
break;
}
case FunctionKind::ASYNC_FUNCTION: {
auto asyncClass = JSHandle<JSHClass>::Cast(env->GetAsyncFunctionClass());
jsFunc = factory->NewJSFunctionByHClass(methodHandle, asyncClass, kind, MemSpaceType::OLD_SPACE);
jsFunc = factory->NewJSFunctionByHClass(methodHandle, asyncClass, MemSpaceType::OLD_SPACE);
break;
}
case FunctionKind::ASYNC_GENERATOR_FUNCTION: {
auto asyncGeneratorClass = JSHandle<JSHClass>::Cast(env->GetAsyncGeneratorFunctionClass());
jsFunc = factory->NewJSFunctionByHClass(methodHandle, asyncGeneratorClass,
kind, MemSpaceType::OLD_SPACE);
MemSpaceType::OLD_SPACE);
break;
}
case FunctionKind::ASYNC_ARROW_FUNCTION: {
// Add hclass for async arrow function
auto asyncClass = JSHandle<JSHClass>::Cast(env->GetAsyncFunctionClass());
jsFunc = factory->NewJSFunctionByHClass(methodHandle, asyncClass,
kind, MemSpaceType::OLD_SPACE);
MemSpaceType::OLD_SPACE);
break;
}
default:
@ -1809,7 +1803,7 @@ JSTaggedValue RuntimeStubs::RuntimeDefineMethod(JSThread *thread, const JSHandle
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithoutProto());
JSHandle<JSFunction> jsFunc = factory->NewJSFunctionByHClass(methodHandle, hclass, FunctionKind::NORMAL_FUNCTION);
JSHandle<JSFunction> jsFunc = factory->NewJSFunctionByHClass(methodHandle, hclass);
jsFunc->SetHomeObject(thread, homeObject);
ASSERT_NO_ABRUPT_COMPLETION(thread);
return jsFunc.GetTaggedValue();
@ -1873,11 +1867,13 @@ JSTaggedValue RuntimeStubs::RuntimeDefineGetterSetterByValue(JSThread *thread, c
!(obj.GetTaggedValue().IsClassPrototype() || obj.GetTaggedValue().IsClassConstructor());
PropertyDescriptor desc(thread, true, enumerable, true);
if (!getter->IsUndefined()) {
JSHandle<JSFunction>::Cast(getter)->SetFunctionKind(FunctionKind::GETTER_FUNCTION);
Method *method = Method::Cast(JSHandle<JSFunction>::Cast(getter)->GetMethod().GetTaggedObject());
method->SetFunctionKind(FunctionKind::GETTER_FUNCTION);
desc.SetGetter(getter);
}
if (!setter->IsUndefined()) {
JSHandle<JSFunction>::Cast(setter)->SetFunctionKind(FunctionKind::SETTER_FUNCTION);
Method *method = Method::Cast(JSHandle<JSFunction>::Cast(setter)->GetMethod().GetTaggedObject());
method->SetFunctionKind(FunctionKind::SETTER_FUNCTION);
desc.SetSetter(setter);
}
JSObject::DefineOwnProperty(thread, obj, propKey, desc);

View File

@ -70,7 +70,7 @@ DEF_RUNTIME_STUBS(DefineAotFunc)
method->SetNativeBit(false);
method->SetNumArgsWithCallField(numArgs.GetInt());
method->SetCodeEntry(reinterpret_cast<uintptr_t>(codeEntry));
JSHandle<JSFunction> jsfunc = factory->NewJSFunction(env, method, FunctionKind::NORMAL_FUNCTION);
JSHandle<JSFunction> jsfunc = factory->NewJSFunction(env, method);
return jsfunc.GetTaggedValue().GetRawData();
}

View File

@ -176,8 +176,9 @@ HWTEST_F_L0(AccessorDataTest, CallInternalSet)
// Construct objects and specify specific prototypes.
JSFunction *func1 = globalEnv->GetObjectFunction().GetObject<JSFunction>();
Method::Cast(func1->GetMethod().GetTaggedObject())->SetFunctionKind(FunctionKind::BASE_CONSTRUCTOR);
JSHandle<JSFunction> funcTagVal1 =
factory->CloneJSFuction(JSHandle<JSFunction>(thread, func1), FunctionKind::BASE_CONSTRUCTOR);
factory->CloneJSFuction(JSHandle<JSFunction>(thread, func1));
// Call the CallInternalGet method to inspect prototype.
JSHandle<JSTaggedValue> nullPrototypeHandle(thread, JSTaggedValue::Null());

View File

@ -443,7 +443,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
break;
}
case JSType::JS_FUNCTION: {
CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 6U);
CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 5U);
JSHandle<JSTaggedValue> jsFunc = globalEnv->GetFunctionFunction();
DUMP_FOR_HANDLE(jsFunc)
break;