From a7662af484a10a05ce072787c26592962b5e07a1 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 29 Sep 2015 14:50:55 -0700 Subject: [PATCH 1/3] RealmType -> Realm.Type --- .../ReactExample.xcodeproj/project.pbxproj | 1 + examples/ReactExample/index.ios.js | 6 +- src/RJSUtil.hpp | 2 +- src/RJSUtil.mm | 3 +- src/RealmJS.mm | 8 ++- tests/ObjectTests.js | 4 +- tests/TestObjects.js | 62 +++++++++---------- 7 files changed, 46 insertions(+), 40 deletions(-) diff --git a/examples/ReactExample/ReactExample.xcodeproj/project.pbxproj b/examples/ReactExample/ReactExample.xcodeproj/project.pbxproj index cad2d7ac..bc3996a6 100644 --- a/examples/ReactExample/ReactExample.xcodeproj/project.pbxproj +++ b/examples/ReactExample/ReactExample.xcodeproj/project.pbxproj @@ -797,6 +797,7 @@ 0277984E1BBB2F1000C96559 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactExample" */ = { isa = XCConfigurationList; diff --git a/examples/ReactExample/index.ios.js b/examples/ReactExample/index.ios.js index 160aeca7..7b45e870 100644 --- a/examples/ReactExample/index.ios.js +++ b/examples/ReactExample/index.ios.js @@ -21,14 +21,14 @@ var { var TodoItemSchema = { name: 'Todo', properties: [ - {name: 'text', type: RealmType.String}, + {name: 'text', type: Realm.Type.String}, ] }; var TodoListSchmea = { name: 'TodoList', properties: [ - {name: 'name', type: RealmType.String}, - {name: 'items', type: RealmType.Array, objectType: 'Todo'} + {name: 'name', type: Realm.Type.String}, + {name: 'items', type: Realm.Type.Array, objectType: 'Todo'} ] }; diff --git a/src/RJSUtil.hpp b/src/RJSUtil.hpp index 025a76ac..dc97963a 100644 --- a/src/RJSUtil.hpp +++ b/src/RJSUtil.hpp @@ -53,7 +53,7 @@ JSClassRef RJSCreateWrapperClass(const char * name, JSObjectGetPropertyCallback return JSClassCreate(&classDefinition); } -void RJSRegisterGlobalClass(JSContextRef ctx, JSObjectRef globalObject, JSClassRef classRef, const char * name, JSValueRef *exception); +JSObjectRef RJSRegisterGlobalClass(JSContextRef ctx, JSObjectRef globalObject, JSClassRef classRef, const char * name, JSValueRef *exception); std::string RJSStringForJSString(JSStringRef jsString); std::string RJSValidatedStringForValue(JSContextRef ctx, JSValueRef value, const char * name = nullptr); diff --git a/src/RJSUtil.mm b/src/RJSUtil.mm index 4ee353a4..76c5cc18 100644 --- a/src/RJSUtil.mm +++ b/src/RJSUtil.mm @@ -18,11 +18,12 @@ #import "RJSUtil.hpp" -void RJSRegisterGlobalClass(JSContextRef ctx, JSObjectRef globalObject, JSClassRef classRef, const char * name, JSValueRef *exception) { +JSObjectRef RJSRegisterGlobalClass(JSContextRef ctx, JSObjectRef globalObject, JSClassRef classRef, const char * name, JSValueRef *exception) { JSObjectRef classObject = JSObjectMake(ctx, classRef, NULL); JSStringRef nameString = JSStringCreateWithUTF8CString(name); JSObjectSetProperty(ctx, globalObject, nameString, classObject, kJSPropertyAttributeNone, exception); JSStringRelease(nameString); + return classObject; } JSValueRef RJSMakeError(JSContextRef ctx, RJSException &exp) { diff --git a/src/RealmJS.mm b/src/RealmJS.mm index 3697980d..3be39fe3 100644 --- a/src/RealmJS.mm +++ b/src/RealmJS.mm @@ -49,9 +49,13 @@ JSClassRef RJSRealmTypeClass() { JSValueRef exception = NULL; JSObjectRef globalObject = JSContextGetGlobalObject(ctx); - RJSRegisterGlobalClass(ctx, globalObject, RJSRealmConstructorClass(), "Realm", &exception); + JSObjectRef globalRealmObject = RJSRegisterGlobalClass(ctx, globalObject, RJSRealmConstructorClass(), "Realm", &exception); + JSObjectRef typesObject = JSObjectMake(ctx, RJSRealmTypeClass(), NULL); + JSStringRef typeString = JSStringCreateWithUTF8CString("Type"); + JSObjectSetProperty(ctx, globalRealmObject, typeString, typesObject, kJSPropertyAttributeNone, &exception); + JSStringRelease(typeString); + RJSRegisterGlobalClass(ctx, globalObject, RJSObjectClass(), "RealmObject", &exception); - RJSRegisterGlobalClass(ctx, globalObject, RJSRealmTypeClass(), "RealmType", &exception); assert(!exception); } diff --git a/tests/ObjectTests.js b/tests/ObjectTests.js index e4f65525..2cc99ad6 100644 --- a/tests/ObjectTests.js +++ b/tests/ObjectTests.js @@ -29,10 +29,10 @@ var ObjectTests = { for (var i = 0; i < BasicTypesObjectSchema.properties.length; i++) { var prop = BasicTypesObjectSchema.properties[i]; - if (prop.type == RealmType.Float) { + if (prop.type == Realm.Type.Float) { TestCase.assertEqualWithTolerance(object[prop.name], basicTypesValues[i], 0.000001); } - else if (prop.type == RealmType.Date) { + else if (prop.type == Realm.Type.Date) { TestCase.assertEqual(object[prop.name].getTime(), basicTypesValues[i].getTime()); } else { diff --git a/tests/TestObjects.js b/tests/TestObjects.js index 8d2e7ba1..7633bbb0 100644 --- a/tests/TestObjects.js +++ b/tests/TestObjects.js @@ -21,7 +21,7 @@ var TestObjectSchema = { name: 'TestObject', properties: [ - {name: 'doubleCol', type: RealmType.Double}, + {name: 'doubleCol', type: Realm.Type.Double}, ] }; @@ -29,8 +29,8 @@ function PersonObject() {} PersonObject.prototype.schema = { name: 'PersonObject', properties: [ - {name: 'name', type: RealmType.String}, - {name: 'age', type: RealmType.Double}, + {name: 'name', type: Realm.Type.String}, + {name: 'age', type: Realm.Type.Double}, ] }; PersonObject.prototype.description = function() { @@ -40,13 +40,13 @@ PersonObject.prototype.description = function() { var BasicTypesObjectSchema = { name: 'BasicTypesObject', properties: [ - {name: 'boolCol', type: RealmType.Bool}, - {name: 'intCol', type: RealmType.Int}, - {name: 'floatCol', type: RealmType.Float}, - {name: 'doubleCol', type: RealmType.Double}, - {name: 'stringCol', type: RealmType.String}, - {name: 'dateCol', type: RealmType.Date}, - {name: 'dataCol', type: RealmType.Data}, + {name: 'boolCol', type: Realm.Type.Bool}, + {name: 'intCol', type: Realm.Type.Int}, + {name: 'floatCol', type: Realm.Type.Float}, + {name: 'doubleCol', type: Realm.Type.Double}, + {name: 'stringCol', type: Realm.Type.String}, + {name: 'dateCol', type: Realm.Type.Date}, + {name: 'dataCol', type: Realm.Type.Data}, ] }; @@ -54,8 +54,8 @@ var LinkTypesObjectSchema = { name: 'LinkTypesObject', properties: [ {name: 'objectCol', type: 'TestObject'}, - {name: 'objectCol1', type: RealmType.Object, objectType: 'TestObject'}, - {name: 'arrayCol', type: RealmType.Array, objectType: 'TestObject'}, + {name: 'objectCol1', type: Realm.Type.Object, objectType: 'TestObject'}, + {name: 'arrayCol', type: Realm.Type.Array, objectType: 'TestObject'}, ] }; @@ -63,8 +63,8 @@ var IntPrimaryObjectSchema = { name: 'IntPrimaryObject', primaryKey: 'primaryCol', properties: [ - {name: 'primaryCol', type: RealmType.Int}, - {name: 'valueCol', type: RealmType.String}, + {name: 'primaryCol', type: Realm.Type.Int}, + {name: 'valueCol', type: Realm.Type.String}, ] }; @@ -72,32 +72,32 @@ var AllTypesObjectSchema = { name: 'AllTypesObject', primaryKey: 'primaryCol', properties: [ - {name: 'primaryCol',type: RealmType.String}, - {name: 'boolCol', type: RealmType.Bool}, - {name: 'intCol', type: RealmType.Int}, - {name: 'floatCol', type: RealmType.Float}, - {name: 'doubleCol', type: RealmType.Double}, - {name: 'stringCol', type: RealmType.String}, - {name: 'dateCol', type: RealmType.Date}, - {name: 'dataCol', type: RealmType.Data}, + {name: 'primaryCol',type: Realm.Type.String}, + {name: 'boolCol', type: Realm.Type.Bool}, + {name: 'intCol', type: Realm.Type.Int}, + {name: 'floatCol', type: Realm.Type.Float}, + {name: 'doubleCol', type: Realm.Type.Double}, + {name: 'stringCol', type: Realm.Type.String}, + {name: 'dateCol', type: Realm.Type.Date}, + {name: 'dataCol', type: Realm.Type.Data}, {name: 'objectCol', type: 'TestObject'}, - {name: 'arrayCol', type: RealmType.Array, objectType: 'TestObject'}, + {name: 'arrayCol', type: Realm.Type.Array, objectType: 'TestObject'}, ] }; var DefaultValuesObjectSchema = { name: 'DefaultValuesObject', properties: [ - {name: 'boolCol', type: RealmType.Bool, default: true}, - {name: 'intCol', type: RealmType.Int, default: -1}, - {name: 'floatCol', type: RealmType.Float, default: -1.1}, - {name: 'doubleCol', type: RealmType.Double, default: -1.11}, - {name: 'stringCol', type: RealmType.String, default: 'defaultString'}, - {name: 'dateCol', type: RealmType.Date, default: new Date(1.111)}, - {name: 'dataCol', type: RealmType.Data, default: 'defaultData'}, + {name: 'boolCol', type: Realm.Type.Bool, default: true}, + {name: 'intCol', type: Realm.Type.Int, default: -1}, + {name: 'floatCol', type: Realm.Type.Float, default: -1.1}, + {name: 'doubleCol', type: Realm.Type.Double, default: -1.11}, + {name: 'stringCol', type: Realm.Type.String, default: 'defaultString'}, + {name: 'dateCol', type: Realm.Type.Date, default: new Date(1.111)}, + {name: 'dataCol', type: Realm.Type.Data, default: 'defaultData'}, {name: 'objectCol', type: 'TestObject', default: [1]}, {name: 'nullObjectCol', type: 'TestObject', default: null}, - {name: 'arrayCol', type: RealmType.Array, objectType: 'TestObject', default: [[2]]}, + {name: 'arrayCol', type: Realm.Type.Array, objectType: 'TestObject', default: [[2]]}, ] }; From 8f466d47b184ae219e29d864406e379518aae25a Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 29 Sep 2015 15:14:39 -0700 Subject: [PATCH 2/3] Type -> Types --- examples/ReactExample/index.ios.js | 6 +-- src/RealmJS.mm | 4 +- tests/ObjectTests.js | 4 +- tests/TestObjects.js | 62 +++++++++++++++--------------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/examples/ReactExample/index.ios.js b/examples/ReactExample/index.ios.js index 7b45e870..4e608975 100644 --- a/examples/ReactExample/index.ios.js +++ b/examples/ReactExample/index.ios.js @@ -21,14 +21,14 @@ var { var TodoItemSchema = { name: 'Todo', properties: [ - {name: 'text', type: Realm.Type.String}, + {name: 'text', type: Realm.Types.String}, ] }; var TodoListSchmea = { name: 'TodoList', properties: [ - {name: 'name', type: Realm.Type.String}, - {name: 'items', type: Realm.Type.Array, objectType: 'Todo'} + {name: 'name', type: Realm.Types.String}, + {name: 'items', type: Realm.Types.Array, objectType: 'Todo'} ] }; diff --git a/src/RealmJS.mm b/src/RealmJS.mm index 3be39fe3..808f988b 100644 --- a/src/RealmJS.mm +++ b/src/RealmJS.mm @@ -26,7 +26,7 @@ JSValueRef RJSTypeGet(JSContextRef ctx, JSObjectRef object, JSStringRef property JSClassRef RJSRealmTypeClass() { JSClassDefinition realmTypesDefinition = kJSClassDefinitionEmpty; - realmTypesDefinition.className = "RealmType"; + realmTypesDefinition.className = "RealmTypes"; JSStaticValue types[] = { { "Bool", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, { "Int", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, @@ -51,7 +51,7 @@ JSClassRef RJSRealmTypeClass() { JSObjectRef globalRealmObject = RJSRegisterGlobalClass(ctx, globalObject, RJSRealmConstructorClass(), "Realm", &exception); JSObjectRef typesObject = JSObjectMake(ctx, RJSRealmTypeClass(), NULL); - JSStringRef typeString = JSStringCreateWithUTF8CString("Type"); + JSStringRef typeString = JSStringCreateWithUTF8CString("Types"); JSObjectSetProperty(ctx, globalRealmObject, typeString, typesObject, kJSPropertyAttributeNone, &exception); JSStringRelease(typeString); diff --git a/tests/ObjectTests.js b/tests/ObjectTests.js index 2cc99ad6..cb3c1dbd 100644 --- a/tests/ObjectTests.js +++ b/tests/ObjectTests.js @@ -29,10 +29,10 @@ var ObjectTests = { for (var i = 0; i < BasicTypesObjectSchema.properties.length; i++) { var prop = BasicTypesObjectSchema.properties[i]; - if (prop.type == Realm.Type.Float) { + if (prop.type == Realm.Types.Float) { TestCase.assertEqualWithTolerance(object[prop.name], basicTypesValues[i], 0.000001); } - else if (prop.type == Realm.Type.Date) { + else if (prop.type == Realm.Types.Date) { TestCase.assertEqual(object[prop.name].getTime(), basicTypesValues[i].getTime()); } else { diff --git a/tests/TestObjects.js b/tests/TestObjects.js index 7633bbb0..1e2fdde5 100644 --- a/tests/TestObjects.js +++ b/tests/TestObjects.js @@ -21,7 +21,7 @@ var TestObjectSchema = { name: 'TestObject', properties: [ - {name: 'doubleCol', type: Realm.Type.Double}, + {name: 'doubleCol', type: Realm.Types.Double}, ] }; @@ -29,8 +29,8 @@ function PersonObject() {} PersonObject.prototype.schema = { name: 'PersonObject', properties: [ - {name: 'name', type: Realm.Type.String}, - {name: 'age', type: Realm.Type.Double}, + {name: 'name', type: Realm.Types.String}, + {name: 'age', type: Realm.Types.Double}, ] }; PersonObject.prototype.description = function() { @@ -40,13 +40,13 @@ PersonObject.prototype.description = function() { var BasicTypesObjectSchema = { name: 'BasicTypesObject', properties: [ - {name: 'boolCol', type: Realm.Type.Bool}, - {name: 'intCol', type: Realm.Type.Int}, - {name: 'floatCol', type: Realm.Type.Float}, - {name: 'doubleCol', type: Realm.Type.Double}, - {name: 'stringCol', type: Realm.Type.String}, - {name: 'dateCol', type: Realm.Type.Date}, - {name: 'dataCol', type: Realm.Type.Data}, + {name: 'boolCol', type: Realm.Types.Bool}, + {name: 'intCol', type: Realm.Types.Int}, + {name: 'floatCol', type: Realm.Types.Float}, + {name: 'doubleCol', type: Realm.Types.Double}, + {name: 'stringCol', type: Realm.Types.String}, + {name: 'dateCol', type: Realm.Types.Date}, + {name: 'dataCol', type: Realm.Types.Data}, ] }; @@ -54,8 +54,8 @@ var LinkTypesObjectSchema = { name: 'LinkTypesObject', properties: [ {name: 'objectCol', type: 'TestObject'}, - {name: 'objectCol1', type: Realm.Type.Object, objectType: 'TestObject'}, - {name: 'arrayCol', type: Realm.Type.Array, objectType: 'TestObject'}, + {name: 'objectCol1', type: Realm.Types.Object, objectType: 'TestObject'}, + {name: 'arrayCol', type: Realm.Types.Array, objectType: 'TestObject'}, ] }; @@ -63,8 +63,8 @@ var IntPrimaryObjectSchema = { name: 'IntPrimaryObject', primaryKey: 'primaryCol', properties: [ - {name: 'primaryCol', type: Realm.Type.Int}, - {name: 'valueCol', type: Realm.Type.String}, + {name: 'primaryCol', type: Realm.Types.Int}, + {name: 'valueCol', type: Realm.Types.String}, ] }; @@ -72,32 +72,32 @@ var AllTypesObjectSchema = { name: 'AllTypesObject', primaryKey: 'primaryCol', properties: [ - {name: 'primaryCol',type: Realm.Type.String}, - {name: 'boolCol', type: Realm.Type.Bool}, - {name: 'intCol', type: Realm.Type.Int}, - {name: 'floatCol', type: Realm.Type.Float}, - {name: 'doubleCol', type: Realm.Type.Double}, - {name: 'stringCol', type: Realm.Type.String}, - {name: 'dateCol', type: Realm.Type.Date}, - {name: 'dataCol', type: Realm.Type.Data}, + {name: 'primaryCol',type: Realm.Types.String}, + {name: 'boolCol', type: Realm.Types.Bool}, + {name: 'intCol', type: Realm.Types.Int}, + {name: 'floatCol', type: Realm.Types.Float}, + {name: 'doubleCol', type: Realm.Types.Double}, + {name: 'stringCol', type: Realm.Types.String}, + {name: 'dateCol', type: Realm.Types.Date}, + {name: 'dataCol', type: Realm.Types.Data}, {name: 'objectCol', type: 'TestObject'}, - {name: 'arrayCol', type: Realm.Type.Array, objectType: 'TestObject'}, + {name: 'arrayCol', type: Realm.Types.Array, objectType: 'TestObject'}, ] }; var DefaultValuesObjectSchema = { name: 'DefaultValuesObject', properties: [ - {name: 'boolCol', type: Realm.Type.Bool, default: true}, - {name: 'intCol', type: Realm.Type.Int, default: -1}, - {name: 'floatCol', type: Realm.Type.Float, default: -1.1}, - {name: 'doubleCol', type: Realm.Type.Double, default: -1.11}, - {name: 'stringCol', type: Realm.Type.String, default: 'defaultString'}, - {name: 'dateCol', type: Realm.Type.Date, default: new Date(1.111)}, - {name: 'dataCol', type: Realm.Type.Data, default: 'defaultData'}, + {name: 'boolCol', type: Realm.Types.Bool, default: true}, + {name: 'intCol', type: Realm.Types.Int, default: -1}, + {name: 'floatCol', type: Realm.Types.Float, default: -1.1}, + {name: 'doubleCol', type: Realm.Types.Double, default: -1.11}, + {name: 'stringCol', type: Realm.Types.String, default: 'defaultString'}, + {name: 'dateCol', type: Realm.Types.Date, default: new Date(1.111)}, + {name: 'dataCol', type: Realm.Types.Data, default: 'defaultData'}, {name: 'objectCol', type: 'TestObject', default: [1]}, {name: 'nullObjectCol', type: 'TestObject', default: null}, - {name: 'arrayCol', type: Realm.Type.Array, objectType: 'TestObject', default: [[2]]}, + {name: 'arrayCol', type: Realm.Types.Array, objectType: 'TestObject', default: [[2]]}, ] }; From aa78436f536eef6083bd29c973d13daa41ff1ce0 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 30 Sep 2015 10:41:47 -0700 Subject: [PATCH 3/3] use capitalized names for enums/constants --- examples/ReactExample/index.ios.js | 6 +-- src/RJSSchema.mm | 18 ++++----- src/RJSUtil.mm | 4 +- src/RealmJS.mm | 24 ++++++------ tests/ObjectTests.js | 4 +- tests/TestObjects.js | 62 +++++++++++++++--------------- 6 files changed, 58 insertions(+), 60 deletions(-) diff --git a/examples/ReactExample/index.ios.js b/examples/ReactExample/index.ios.js index 4e608975..f6f1d2be 100644 --- a/examples/ReactExample/index.ios.js +++ b/examples/ReactExample/index.ios.js @@ -21,14 +21,14 @@ var { var TodoItemSchema = { name: 'Todo', properties: [ - {name: 'text', type: Realm.Types.String}, + {name: 'text', type: Realm.Types.STRING}, ] }; var TodoListSchmea = { name: 'TodoList', properties: [ - {name: 'name', type: Realm.Types.String}, - {name: 'items', type: Realm.Types.Array, objectType: 'Todo'} + {name: 'name', type: Realm.Types.STRING}, + {name: 'items', type: Realm.Types.ARRAY, objectType: 'Todo'} ] }; diff --git a/src/RJSSchema.mm b/src/RJSSchema.mm index cc77c80c..f4d42a79 100644 --- a/src/RJSSchema.mm +++ b/src/RJSSchema.mm @@ -64,33 +64,33 @@ static inline Property RJSParseProperty(JSContextRef ctx, JSObjectRef propertyOb prop.name = RJSValidatedStringProperty(ctx, propertyObject, nameString); std::string type = RJSValidatedStringProperty(ctx, propertyObject, typeString); - if (type == "RealmTypeBool") { + if (type == "PropTypesBOOL") { prop.type = PropertyTypeBool; } - else if (type == "RealmTypeInt") { + else if (type == "PropTypesINT") { prop.type = PropertyTypeInt; } - else if (type == "RealmTypeFloat") { + else if (type == "PropTypesFLOAT") { prop.type = PropertyTypeFloat; } - else if (type == "RealmTypeDouble") { + else if (type == "PropTypesDOUBLE") { prop.type = PropertyTypeDouble; } - else if (type == "RealmTypeString") { + else if (type == "PropTypesSTRING") { prop.type = PropertyTypeString; } - else if (type == "RealmTypeDate") { + else if (type == "PropTypesDATE") { prop.type = PropertyTypeDate; } - else if (type == "RealmTypeData") { + else if (type == "PropTypesDATA") { prop.type = PropertyTypeData; } - else if (type == "RealmTypeObject") { + else if (type == "PropTypesOBJECT") { prop.type = PropertyTypeObject; prop.object_type = RJSValidatedStringProperty(ctx, propertyObject, objectTypeString); prop.is_nullable = true; } - else if (type == "RealmTypeArray") { + else if (type == "PropTypesARRAY") { prop.type = PropertyTypeArray; prop.object_type = RJSValidatedStringProperty(ctx, propertyObject, objectTypeString); } diff --git a/src/RJSUtil.mm b/src/RJSUtil.mm index 76c5cc18..e78dd7db 100644 --- a/src/RJSUtil.mm +++ b/src/RJSUtil.mm @@ -54,10 +54,10 @@ std::string RJSStringForJSString(JSStringRef jsString) { std::string RJSValidatedStringForValue(JSContextRef ctx, JSValueRef value, const char * name) { if (!JSValueIsString(ctx, value)) { if (name) { - throw std::invalid_argument((std::string)"'" + name + "' must be of type 'string'"); + throw std::invalid_argument((std::string)"'" + name + "' must be of type 'STRING'"); } else { - throw std::invalid_argument("JSValue must be of type 'string'"); + throw std::invalid_argument("JSValue must be of type 'STRING'"); } } diff --git a/src/RealmJS.mm b/src/RealmJS.mm index 808f988b..dcbb331f 100644 --- a/src/RealmJS.mm +++ b/src/RealmJS.mm @@ -21,22 +21,22 @@ #import "RJSObject.hpp" JSValueRef RJSTypeGet(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { - return RJSValueForString(ctx, "RealmType" + RJSStringForJSString(propertyName)); + return RJSValueForString(ctx, "PropTypes" + RJSStringForJSString(propertyName)); } JSClassRef RJSRealmTypeClass() { JSClassDefinition realmTypesDefinition = kJSClassDefinitionEmpty; - realmTypesDefinition.className = "RealmTypes"; + realmTypesDefinition.className = "PropTypes"; JSStaticValue types[] = { - { "Bool", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "Int", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "Float", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "Double", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "String", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "Date", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "Data", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "Object", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "Array", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "BOOL", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "INT", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "FLOAT", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "DOUBLE", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "STRING", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "DATE", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "DATA", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "OBJECT", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "ARRAY", RJSTypeGet, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, { NULL, NULL, NULL, 0 } }; realmTypesDefinition.staticValues = types; @@ -55,8 +55,6 @@ JSClassRef RJSRealmTypeClass() { JSObjectSetProperty(ctx, globalRealmObject, typeString, typesObject, kJSPropertyAttributeNone, &exception); JSStringRelease(typeString); - RJSRegisterGlobalClass(ctx, globalObject, RJSObjectClass(), "RealmObject", &exception); - assert(!exception); } diff --git a/tests/ObjectTests.js b/tests/ObjectTests.js index cb3c1dbd..4e847ab3 100644 --- a/tests/ObjectTests.js +++ b/tests/ObjectTests.js @@ -29,10 +29,10 @@ var ObjectTests = { for (var i = 0; i < BasicTypesObjectSchema.properties.length; i++) { var prop = BasicTypesObjectSchema.properties[i]; - if (prop.type == Realm.Types.Float) { + if (prop.type == Realm.Types.FLOAT) { TestCase.assertEqualWithTolerance(object[prop.name], basicTypesValues[i], 0.000001); } - else if (prop.type == Realm.Types.Date) { + else if (prop.type == Realm.Types.DATE) { TestCase.assertEqual(object[prop.name].getTime(), basicTypesValues[i].getTime()); } else { diff --git a/tests/TestObjects.js b/tests/TestObjects.js index 1e2fdde5..830caae8 100644 --- a/tests/TestObjects.js +++ b/tests/TestObjects.js @@ -21,7 +21,7 @@ var TestObjectSchema = { name: 'TestObject', properties: [ - {name: 'doubleCol', type: Realm.Types.Double}, + {name: 'doubleCol', type: Realm.Types.DOUBLE}, ] }; @@ -29,8 +29,8 @@ function PersonObject() {} PersonObject.prototype.schema = { name: 'PersonObject', properties: [ - {name: 'name', type: Realm.Types.String}, - {name: 'age', type: Realm.Types.Double}, + {name: 'name', type: Realm.Types.STRING}, + {name: 'age', type: Realm.Types.DOUBLE}, ] }; PersonObject.prototype.description = function() { @@ -40,13 +40,13 @@ PersonObject.prototype.description = function() { var BasicTypesObjectSchema = { name: 'BasicTypesObject', properties: [ - {name: 'boolCol', type: Realm.Types.Bool}, - {name: 'intCol', type: Realm.Types.Int}, - {name: 'floatCol', type: Realm.Types.Float}, - {name: 'doubleCol', type: Realm.Types.Double}, - {name: 'stringCol', type: Realm.Types.String}, - {name: 'dateCol', type: Realm.Types.Date}, - {name: 'dataCol', type: Realm.Types.Data}, + {name: 'boolCol', type: Realm.Types.BOOL}, + {name: 'intCol', type: Realm.Types.INT}, + {name: 'floatCol', type: Realm.Types.FLOAT}, + {name: 'doubleCol', type: Realm.Types.DOUBLE}, + {name: 'stringCol', type: Realm.Types.STRING}, + {name: 'dateCol', type: Realm.Types.DATE}, + {name: 'dataCol', type: Realm.Types.DATA}, ] }; @@ -54,8 +54,8 @@ var LinkTypesObjectSchema = { name: 'LinkTypesObject', properties: [ {name: 'objectCol', type: 'TestObject'}, - {name: 'objectCol1', type: Realm.Types.Object, objectType: 'TestObject'}, - {name: 'arrayCol', type: Realm.Types.Array, objectType: 'TestObject'}, + {name: 'objectCol1', type: Realm.Types.OBJECT, objectType: 'TestObject'}, + {name: 'arrayCol', type: Realm.Types.ARRAY, objectType: 'TestObject'}, ] }; @@ -63,8 +63,8 @@ var IntPrimaryObjectSchema = { name: 'IntPrimaryObject', primaryKey: 'primaryCol', properties: [ - {name: 'primaryCol', type: Realm.Types.Int}, - {name: 'valueCol', type: Realm.Types.String}, + {name: 'primaryCol', type: Realm.Types.INT}, + {name: 'valueCol', type: Realm.Types.STRING}, ] }; @@ -72,32 +72,32 @@ var AllTypesObjectSchema = { name: 'AllTypesObject', primaryKey: 'primaryCol', properties: [ - {name: 'primaryCol',type: Realm.Types.String}, - {name: 'boolCol', type: Realm.Types.Bool}, - {name: 'intCol', type: Realm.Types.Int}, - {name: 'floatCol', type: Realm.Types.Float}, - {name: 'doubleCol', type: Realm.Types.Double}, - {name: 'stringCol', type: Realm.Types.String}, - {name: 'dateCol', type: Realm.Types.Date}, - {name: 'dataCol', type: Realm.Types.Data}, + {name: 'primaryCol',type: Realm.Types.STRING}, + {name: 'boolCol', type: Realm.Types.BOOL}, + {name: 'intCol', type: Realm.Types.INT}, + {name: 'floatCol', type: Realm.Types.FLOAT}, + {name: 'doubleCol', type: Realm.Types.DOUBLE}, + {name: 'stringCol', type: Realm.Types.STRING}, + {name: 'dateCol', type: Realm.Types.DATE}, + {name: 'dataCol', type: Realm.Types.DATA}, {name: 'objectCol', type: 'TestObject'}, - {name: 'arrayCol', type: Realm.Types.Array, objectType: 'TestObject'}, + {name: 'arrayCol', type: Realm.Types.ARRAY, objectType: 'TestObject'}, ] }; var DefaultValuesObjectSchema = { name: 'DefaultValuesObject', properties: [ - {name: 'boolCol', type: Realm.Types.Bool, default: true}, - {name: 'intCol', type: Realm.Types.Int, default: -1}, - {name: 'floatCol', type: Realm.Types.Float, default: -1.1}, - {name: 'doubleCol', type: Realm.Types.Double, default: -1.11}, - {name: 'stringCol', type: Realm.Types.String, default: 'defaultString'}, - {name: 'dateCol', type: Realm.Types.Date, default: new Date(1.111)}, - {name: 'dataCol', type: Realm.Types.Data, default: 'defaultData'}, + {name: 'boolCol', type: Realm.Types.BOOL, default: true}, + {name: 'intCol', type: Realm.Types.INT, default: -1}, + {name: 'floatCol', type: Realm.Types.FLOAT, default: -1.1}, + {name: 'doubleCol', type: Realm.Types.DOUBLE, default: -1.11}, + {name: 'stringCol', type: Realm.Types.STRING, default: 'defaultString'}, + {name: 'dateCol', type: Realm.Types.DATE, default: new Date(1.111)}, + {name: 'dataCol', type: Realm.Types.DATA, default: 'defaultData'}, {name: 'objectCol', type: 'TestObject', default: [1]}, {name: 'nullObjectCol', type: 'TestObject', default: null}, - {name: 'arrayCol', type: Realm.Types.Array, objectType: 'TestObject', default: [[2]]}, + {name: 'arrayCol', type: Realm.Types.ARRAY, objectType: 'TestObject', default: [[2]]}, ] };