finish Array to List rename

This commit is contained in:
Ari Lazier 2015-10-13 15:56:43 -07:00
parent f6e0d34022
commit 7db001c3da
3 changed files with 29 additions and 29 deletions

View File

@ -24,24 +24,24 @@
using RJSAccessor = realm::NativeAccessor<JSValueRef, JSContextRef>; using RJSAccessor = realm::NativeAccessor<JSValueRef, JSContextRef>;
using namespace realm; using namespace realm;
static inline List * RJSVerifiedArray(JSObjectRef object) { static inline List * RJSVerifiedList(JSObjectRef object) {
List *list = RJSGetInternal<List *>(object); List *list = RJSGetInternal<List *>(object);
list->verify_attached(); list->verify_attached();
return list; return list;
} }
static inline List * RJSVerifiedMutableArray(JSObjectRef object) { static inline List * RJSVerifiedMutableList(JSObjectRef object) {
List *list = RJSVerifiedArray(object); List *list = RJSVerifiedList(object);
if (!list->realm->is_in_transaction()) { if (!list->realm->is_in_transaction()) {
throw std::runtime_error("Can only mutate lists within a transaction."); throw std::runtime_error("Can only mutate lists within a transaction.");
} }
return list; return list;
} }
JSValueRef ArrayGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) { JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) {
try { try {
// index subscripting // index subscripting
List *list = RJSVerifiedArray(object); List *list = RJSVerifiedList(object);
size_t size = list->size(); size_t size = list->size();
std::string indexStr = RJSStringForJSString(propertyName); std::string indexStr = RJSStringForJSString(propertyName);
@ -67,9 +67,9 @@ JSValueRef ArrayGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef pr
} }
} }
bool ArraySetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* jsException) { bool ListSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* jsException) {
try { try {
List *list = RJSVerifiedMutableArray(object); List *list = RJSVerifiedMutableList(object);
std::string indexStr = RJSStringForJSString(propertyName); std::string indexStr = RJSStringForJSString(propertyName);
if (indexStr == "length") { if (indexStr == "length") {
throw std::runtime_error("The 'length' property is readonly."); throw std::runtime_error("The 'length' property is readonly.");
@ -90,8 +90,8 @@ bool ArraySetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef property
} }
} }
void ArrayPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames) { void ListPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames) {
List *list = RJSVerifiedArray(object); List *list = RJSVerifiedList(object);
size_t size = list->size(); size_t size = list->size();
char str[32]; char str[32];
@ -103,9 +103,9 @@ void ArrayPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccu
} }
} }
JSValueRef ArrayPush(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) { JSValueRef ListPush(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
try { try {
List *array = RJSVerifiedMutableArray(thisObject); List *array = RJSVerifiedMutableList(thisObject);
RJSValidateArgumentCountIsAtLeast(argumentCount, 1); RJSValidateArgumentCountIsAtLeast(argumentCount, 1);
for (size_t i = 0; i < argumentCount; i++) { for (size_t i = 0; i < argumentCount; i++) {
array->link_view->add(RJSAccessor::to_object_index(ctx, array->realm, const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false)); array->link_view->add(RJSAccessor::to_object_index(ctx, array->realm, const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false));
@ -120,9 +120,9 @@ JSValueRef ArrayPush(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj
return NULL; return NULL;
} }
JSValueRef ArrayPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) { JSValueRef ListPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
try { try {
List *list = RJSVerifiedMutableArray(thisObject); List *list = RJSVerifiedMutableList(thisObject);
RJSValidateArgumentCount(argumentCount, 0); RJSValidateArgumentCount(argumentCount, 0);
size_t size = list->size(); size_t size = list->size();
@ -142,9 +142,9 @@ JSValueRef ArrayPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObje
return NULL; return NULL;
} }
JSValueRef ArrayUnshift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) { JSValueRef ListUnshift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
try { try {
List *array = RJSVerifiedMutableArray(thisObject); List *array = RJSVerifiedMutableList(thisObject);
RJSValidateArgumentCountIsAtLeast(argumentCount, 1); RJSValidateArgumentCountIsAtLeast(argumentCount, 1);
for (size_t i = 0; i < argumentCount; i++) { for (size_t i = 0; i < argumentCount; i++) {
array->link_view->insert(i, RJSAccessor::to_object_index(ctx, array->realm, const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false)); array->link_view->insert(i, RJSAccessor::to_object_index(ctx, array->realm, const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false));
@ -159,9 +159,9 @@ JSValueRef ArrayUnshift(JSContextRef ctx, JSObjectRef function, JSObjectRef this
return NULL; return NULL;
} }
JSValueRef ArrayShift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) { JSValueRef ListShift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
try { try {
List *list = RJSVerifiedMutableArray(thisObject); List *list = RJSVerifiedMutableList(thisObject);
RJSValidateArgumentCount(argumentCount, 0); RJSValidateArgumentCount(argumentCount, 0);
if (list->size() == 0) { if (list->size() == 0) {
return JSValueMakeUndefined(ctx); return JSValueMakeUndefined(ctx);
@ -178,9 +178,9 @@ JSValueRef ArrayShift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisOb
return NULL; return NULL;
} }
JSValueRef ArraySplice(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) { JSValueRef ListSplice(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
try { try {
List *list = RJSVerifiedMutableArray(thisObject); List *list = RJSVerifiedMutableList(thisObject);
size_t size = list->size(); size_t size = list->size();
RJSValidateArgumentCountIsAtLeast(argumentCount, 2); RJSValidateArgumentCountIsAtLeast(argumentCount, 2);
@ -215,15 +215,15 @@ JSObjectRef RJSListCreate(JSContextRef ctx, realm::List &list) {
} }
const JSStaticFunction RJSListFuncs[] = { const JSStaticFunction RJSListFuncs[] = {
{"push", ArrayPush, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"push", ListPush, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"pop", ArrayPop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"pop", ListPop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"shift", ArrayShift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"shift", ListShift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"unshift", ArrayUnshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"unshift", ListUnshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"splice", ArraySplice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"splice", ListSplice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL}, {NULL, NULL},
}; };
JSClassRef RJSListClass() { JSClassRef RJSListClass() {
static JSClassRef s_arrayClass = RJSCreateWrapperClass<Object>("RealmList", ArrayGetProperty, ArraySetProperty, RJSListFuncs, NULL, ArrayPropertyNames); static JSClassRef s_listClass = RJSCreateWrapperClass<Object>("RealmList", ListGetProperty, ListSetProperty, RJSListFuncs, NULL, ListPropertyNames);
return s_arrayClass; return s_listClass;
} }

View File

@ -24,4 +24,4 @@ extern const JSStaticFunction RJSListFuncs[];
JSClassRef RJSListClass(); JSClassRef RJSListClass();
JSObjectRef RJSListCreate(JSContextRef ctx, realm::List &list); JSObjectRef RJSListCreate(JSContextRef ctx, realm::List &list);
JSValueRef ArrayGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException); JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException);

View File

@ -140,7 +140,7 @@ using RPCRequest = std::function<NSDictionary *(NSDictionary *dictionary)>;
JSValueRef exception = NULL; JSValueRef exception = NULL;
static JSStringRef lengthPropertyName = JSStringCreateWithUTF8CString("length"); static JSStringRef lengthPropertyName = JSStringCreateWithUTF8CString("length");
JSValueRef lengthValue = ArrayGetProperty(_context, _objects[listId], lengthPropertyName, &exception); JSValueRef lengthValue = ListGetProperty(_context, _objects[listId], lengthPropertyName, &exception);
size_t length = JSValueToNumber(_context, lengthValue, &exception); size_t length = JSValueToNumber(_context, lengthValue, &exception);
if (exception) { if (exception) {
@ -154,7 +154,7 @@ using RPCRequest = std::function<NSDictionary *(NSDictionary *dictionary)>;
JSValueRef exception = NULL; JSValueRef exception = NULL;
JSStringRef indexPropertyName = JSStringCreateWithUTF8CString(std::to_string(index).c_str()); JSStringRef indexPropertyName = JSStringCreateWithUTF8CString(std::to_string(index).c_str());
JSValueRef objectValue = ArrayGetProperty(_context, _objects[listId], indexPropertyName, &exception); JSValueRef objectValue = ListGetProperty(_context, _objects[listId], indexPropertyName, &exception);
JSStringRelease(indexPropertyName); JSStringRelease(indexPropertyName);
if (exception) { if (exception) {