void List<T>::shift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); auto list = get_internal<T, ListClass<T>>(this_object); if (list->size() == 0) { list->verify_in_transaction(); return_value.set_undefined(); } else { auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(0)); return_value.set(RealmObject<T>::create_instance(ctx, realm_object)); list->remove(0); } }
void ListClass<T>::pop(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); auto list = get_internal<T, ListClass<T>>(this_object); size_t size = list->size(); if (size == 0) { list->verify_in_transaction(); return_value.set_undefined(); } else { size_t index = size - 1; auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index)); return_value.set(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object))); list->remove(index); } }