mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-18 17:47:32 +00:00
Make realm instances pass instanceof check
This commit is contained in:
parent
97e6166597
commit
154422a3d1
@ -217,16 +217,22 @@ JSObjectRef RealmConstructor(JSContextRef ctx, JSObjectRef constructor, size_t a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RealmHasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef value, JSValueRef* exception) {
|
||||||
|
return JSValueIsObjectOfClass(ctx, value, RJSRealmClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
static const JSStaticValue RealmStaticProperties[] = {
|
||||||
|
{"defaultPath", GetDefaultPath, SetDefaultPath, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
JSClassRef RJSRealmConstructorClass() {
|
JSClassRef RJSRealmConstructorClass() {
|
||||||
JSClassDefinition realmConstructorDefinition = kJSClassDefinitionEmpty;
|
JSClassDefinition realmConstructorDefinition = kJSClassDefinitionEmpty;
|
||||||
realmConstructorDefinition.className = "Realm";
|
realmConstructorDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
|
||||||
|
realmConstructorDefinition.className = "RealmConstructor";
|
||||||
realmConstructorDefinition.callAsConstructor = RealmConstructor;
|
realmConstructorDefinition.callAsConstructor = RealmConstructor;
|
||||||
|
realmConstructorDefinition.hasInstance = RealmHasInstance;
|
||||||
JSStaticValue realmStaticProperties[] = {
|
realmConstructorDefinition.staticValues = RealmStaticProperties;
|
||||||
{"defaultPath", GetDefaultPath, SetDefaultPath, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
|
||||||
{NULL, NULL}
|
|
||||||
};
|
|
||||||
realmConstructorDefinition.staticValues = realmStaticProperties;
|
|
||||||
return JSClassCreate(&realmConstructorDefinition);
|
return JSClassCreate(&realmConstructorDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,11 @@ var schemas = require('./schemas');
|
|||||||
var util = require('./util');
|
var util = require('./util');
|
||||||
|
|
||||||
module.exports = BaseTest.extend({
|
module.exports = BaseTest.extend({
|
||||||
|
testRealmConstructor: function() {
|
||||||
|
var realm = new Realm({schema: []});
|
||||||
|
TestCase.assertTrue(realm instanceof Realm);
|
||||||
|
},
|
||||||
|
|
||||||
testRealmConstructorPath: function() {
|
testRealmConstructorPath: function() {
|
||||||
TestCase.assertThrows(function() {
|
TestCase.assertThrows(function() {
|
||||||
new Realm('/invalidpath');
|
new Realm('/invalidpath');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user