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() {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue