Make realm instances pass instanceof check

This commit is contained in:
Scott Kyle 2016-02-26 12:11:35 -08:00
parent 97e6166597
commit 154422a3d1
2 changed files with 18 additions and 7 deletions

View File

@ -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() {
JSClassDefinition realmConstructorDefinition = kJSClassDefinitionEmpty;
realmConstructorDefinition.className = "Realm";
realmConstructorDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
realmConstructorDefinition.className = "RealmConstructor";
realmConstructorDefinition.callAsConstructor = RealmConstructor;
JSStaticValue realmStaticProperties[] = {
{"defaultPath", GetDefaultPath, SetDefaultPath, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL}
};
realmConstructorDefinition.staticValues = realmStaticProperties;
realmConstructorDefinition.hasInstance = RealmHasInstance;
realmConstructorDefinition.staticValues = RealmStaticProperties;
return JSClassCreate(&realmConstructorDefinition);
}

View File

@ -25,6 +25,11 @@ var schemas = require('./schemas');
var util = require('./util');
module.exports = BaseTest.extend({
testRealmConstructor: function() {
var realm = new Realm({schema: []});
TestCase.assertTrue(realm instanceof Realm);
},
testRealmConstructorPath: function() {
TestCase.assertThrows(function() {
new Realm('/invalidpath');