diff --git a/src/js_realm.cpp b/src/js_realm.cpp index 2e80f099..a21ab798 100644 --- a/src/js_realm.cpp +++ b/src/js_realm.cpp @@ -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); } diff --git a/tests/lib/realm-tests.js b/tests/lib/realm-tests.js index 476219f4..8555d05b 100644 --- a/tests/lib/realm-tests.js +++ b/tests/lib/realm-tests.js @@ -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');