| 1027 | |
| 1028 | |
| 1029 | Object *Object::DefineMembers(Object *obj, LPTSTR aClassName, ObjectMember aMember[], int aMemberCount) |
| 1030 | { |
| 1031 | if (aMemberCount) |
| 1032 | obj->mFlags |= NativeClassPrototype; |
| 1033 | |
| 1034 | TCHAR full_name[MAX_VAR_NAME_LENGTH + 1]; |
| 1035 | TCHAR *name = full_name + _stprintf(full_name, _T("%s.Prototype."), aClassName); |
| 1036 | |
| 1037 | for (int i = 0; i < aMemberCount; ++i) |
| 1038 | { |
| 1039 | const auto &member = aMember[i]; |
| 1040 | _tcscpy(name, member.name); |
| 1041 | if (member.invokeType == IT_CALL) |
| 1042 | { |
| 1043 | auto func = new BuiltInMethod(SimpleHeap::Alloc(full_name)); |
| 1044 | func->mBIM = member.method; |
| 1045 | func->mMID = member.id; |
| 1046 | func->mMIT = IT_CALL; |
| 1047 | func->mMinParams = member.minParams + 1; // Includes `this`. |
| 1048 | func->mIsVariadic = member.maxParams == MAXP_VARIADIC; |
| 1049 | func->mParamCount = func->mIsVariadic ? func->mMinParams : member.maxParams + 1; |
| 1050 | func->mClass = obj; // AddRef not needed since neither mClass nor our caller's reference to obj is ever Released. |
| 1051 | obj->DefineMethod(member.name, func); |
| 1052 | func->Release(); |
| 1053 | } |
| 1054 | else |
| 1055 | { |
| 1056 | auto prop = obj->DefineProperty(name); |
| 1057 | prop->MinParams = member.minParams; |
| 1058 | prop->MaxParams = member.maxParams; |
| 1059 | |
| 1060 | auto op_name = _tcschr(name, '\0'); |
| 1061 | |
| 1062 | _tcscpy(op_name, _T(".Get")); |
| 1063 | auto func = new BuiltInMethod(SimpleHeap::Alloc(full_name)); |
| 1064 | func->mBIM = member.method; |
| 1065 | func->mMID = member.id; |
| 1066 | func->mMIT = IT_GET; |
| 1067 | func->mMinParams = member.minParams + 1; // Includes `this`. |
| 1068 | func->mParamCount = member.maxParams + 1; |
| 1069 | func->mIsVariadic = member.maxParams == MAXP_VARIADIC; |
| 1070 | func->mClass = obj; |
| 1071 | prop->SetGetter(func); |
| 1072 | func->Release(); |
| 1073 | |
| 1074 | if (member.invokeType == IT_SET) |
| 1075 | { |
| 1076 | _tcscpy(op_name, _T(".Set")); |
| 1077 | func = new BuiltInMethod(SimpleHeap::Alloc(full_name)); |
| 1078 | func->mBIM = member.method; |
| 1079 | func->mMID = member.id; |
| 1080 | func->mMIT = IT_SET; |
| 1081 | func->mMinParams = member.minParams + 2; // Includes `this` and `value`. |
| 1082 | func->mParamCount = member.maxParams + 2; |
| 1083 | func->mIsVariadic = member.maxParams == MAXP_VARIADIC; |
| 1084 | func->mClass = obj; |
| 1085 | prop->SetSetter(func); |
| 1086 | func->Release(); |
nothing calls this directly
no test coverage detected