use string wrapper, finish realm constructor conversion
This commit is contained in:
parent
29213f1d87
commit
61685dee83
|
@ -188,6 +188,7 @@ public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Realm<T>::Constructor(ContextType ctx, ObjectType constructor, size_t argumentCount, const ValueType arguments[], ObjectType &returnObject) {
|
void Realm<T>::Constructor(ContextType ctx, ObjectType constructor, size_t argumentCount, const ValueType arguments[], ObjectType &returnObject) {
|
||||||
using RJSAccessor = realm::NativeAccessor<ValueType, ContextType>;
|
using RJSAccessor = realm::NativeAccessor<ValueType, ContextType>;
|
||||||
|
using StringType = typename T::String;
|
||||||
|
|
||||||
realm::Realm::Config config;
|
realm::Realm::Config config;
|
||||||
std::map<std::string, ObjectDefaults> defaults;
|
std::map<std::string, ObjectDefaults> defaults;
|
||||||
|
@ -201,10 +202,10 @@ void Realm<T>::Constructor(ContextType ctx, ObjectType constructor, size_t argum
|
||||||
config.path = RJSValidatedStringForValue(ctx, value, "path");
|
config.path = RJSValidatedStringForValue(ctx, value, "path");
|
||||||
}
|
}
|
||||||
else if (ValueIsObject(ctx, value)) {
|
else if (ValueIsObject(ctx, value)) {
|
||||||
JSObjectRef object = RJSValidatedValueToObject(ctx, value);
|
ObjectType object = RJSValidatedValueToObject(ctx, value);
|
||||||
|
|
||||||
static JSStringRef pathString = JSStringCreateWithUTF8CString("path");
|
StringType pathString("path");
|
||||||
JSValueRef pathValue = RJSValidatedPropertyValue(ctx, object, pathString);
|
ValueType pathValue = RJSValidatedPropertyValue(ctx, object, pathString);
|
||||||
if (!JSValueIsUndefined(ctx, pathValue)) {
|
if (!JSValueIsUndefined(ctx, pathValue)) {
|
||||||
config.path = RJSValidatedStringForValue(ctx, pathValue, "path");
|
config.path = RJSValidatedStringForValue(ctx, pathValue, "path");
|
||||||
}
|
}
|
||||||
|
@ -212,14 +213,14 @@ void Realm<T>::Constructor(ContextType ctx, ObjectType constructor, size_t argum
|
||||||
config.path = js::default_path();
|
config.path = js::default_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSStringRef schemaString = JSStringCreateWithUTF8CString("schema");
|
StringType schemaString("schema");
|
||||||
JSValueRef schemaValue = RJSValidatedPropertyValue(ctx, object, schemaString);
|
ValueType schemaValue = RJSValidatedPropertyValue(ctx, object, schemaString);
|
||||||
if (!JSValueIsUndefined(ctx, schemaValue)) {
|
if (!JSValueIsUndefined(ctx, schemaValue)) {
|
||||||
config.schema.reset(new Schema(RJSParseSchema(ctx, RJSValidatedValueToObject(ctx, schemaValue), defaults, constructors)));
|
config.schema.reset(new Schema(RJSParseSchema(ctx, RJSValidatedValueToObject(ctx, schemaValue), defaults, constructors)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSStringRef schemaVersionString = JSStringCreateWithUTF8CString("schemaVersion");
|
StringType schemaVersionString("schemaVersion");
|
||||||
JSValueRef versionValue = RJSValidatedPropertyValue(ctx, object, schemaVersionString);
|
ValueType versionValue = RJSValidatedPropertyValue(ctx, object, schemaVersionString);
|
||||||
if (JSValueIsNumber(ctx, versionValue)) {
|
if (JSValueIsNumber(ctx, versionValue)) {
|
||||||
config.schema_version = RJSValidatedValueToNumber(ctx, versionValue);
|
config.schema_version = RJSValidatedValueToNumber(ctx, versionValue);
|
||||||
}
|
}
|
||||||
|
@ -227,8 +228,8 @@ void Realm<T>::Constructor(ContextType ctx, ObjectType constructor, size_t argum
|
||||||
config.schema_version = 0;
|
config.schema_version = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSStringRef encryptionKeyString = JSStringCreateWithUTF8CString("encryptionKey");
|
StringType encryptionKeyString("encryptionKey");
|
||||||
JSValueRef encryptionKeyValue = RJSValidatedPropertyValue(ctx, object, encryptionKeyString);
|
ValueType encryptionKeyValue = RJSValidatedPropertyValue(ctx, object, encryptionKeyString);
|
||||||
if (!JSValueIsUndefined(ctx, encryptionKeyValue)) {
|
if (!JSValueIsUndefined(ctx, encryptionKeyValue)) {
|
||||||
std::string encryptionKey = RJSAccessor::to_binary(ctx, encryptionKeyValue);
|
std::string encryptionKey = RJSAccessor::to_binary(ctx, encryptionKeyValue);
|
||||||
config.encryption_key = std::vector<char>(encryptionKey.begin(), encryptionKey.end());;
|
config.encryption_key = std::vector<char>(encryptionKey.begin(), encryptionKey.end());;
|
||||||
|
@ -254,7 +255,7 @@ void Realm<T>::Constructor(ContextType ctx, ObjectType constructor, size_t argum
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Realm<T>::SchemaVersion(ContextType ctx, ObjectType thisObject, size_t argumentCount, const ValueType arguments[], ReturnType &returnObject) {
|
void Realm<T>::SchemaVersion(ContextType ctx, ObjectType thisObject, size_t argumentCount, const ValueType arguments[], ReturnType &returnObject) {
|
||||||
using RJSAccessor = realm::NativeAccessor<JSValueRef, JSContextRef>;
|
using RJSAccessor = realm::NativeAccessor<ValueType, ContextType>;
|
||||||
|
|
||||||
RJSValidateArgumentRange(argumentCount, 1, 2);
|
RJSValidateArgumentRange(argumentCount, 1, 2);
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,23 @@
|
||||||
namespace realm {
|
namespace realm {
|
||||||
namespace jsc {
|
namespace jsc {
|
||||||
|
|
||||||
|
class String {
|
||||||
|
public:
|
||||||
|
String(const char * str) : m_str(JSStringCreateWithUTF8CString(str)) {}
|
||||||
|
~String() { JSStringRelease(m_str); }
|
||||||
|
operator JSStringRef() const { return m_str; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
JSStringRef m_str;
|
||||||
|
};
|
||||||
|
|
||||||
struct Types {
|
struct Types {
|
||||||
using Context = JSContextRef;
|
using Context = JSContextRef;
|
||||||
using GlobalContext = JSGlobalContextRef;
|
using GlobalContext = JSGlobalContextRef;
|
||||||
using ObjectClass = JSClassRef;
|
using ObjectClass = JSClassRef;
|
||||||
using Value = JSValueRef;
|
using Value = JSValueRef;
|
||||||
using Object = JSObjectRef;
|
using Object = JSObjectRef;
|
||||||
using String = JSStringRef;
|
using String = jsc::String;
|
||||||
using Function = JSObjectRef;
|
using Function = JSObjectRef;
|
||||||
using Return = JSValueRef;
|
using Return = JSValueRef;
|
||||||
using Exception = JSValueRef;
|
using Exception = JSValueRef;
|
||||||
|
|
Loading…
Reference in New Issue