mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-10 22:36:01 +00:00
pr fixes
This commit is contained in:
parent
6f41c3cf68
commit
a1c4cd5702
14
lib/realm.js
14
lib/realm.js
@ -8,7 +8,7 @@ const rpc = require('./rpc');
|
||||
const util = require('./util');
|
||||
|
||||
const {keys, propTypes, objectTypes} = constants;
|
||||
const notificationsKey = Symbol();
|
||||
const listenersKey = Symbol();
|
||||
const resultsKey = Symbol();
|
||||
|
||||
// TODO: DATA
|
||||
@ -39,7 +39,7 @@ class Realm {
|
||||
this[keys.id] = realmId;
|
||||
this[keys.realm] = realmId;
|
||||
this[keys.type] = objectTypes.REALM;
|
||||
this[notificationsKey] = [];
|
||||
this[listenersKey] = [];
|
||||
this[resultsKey] = [];
|
||||
|
||||
[
|
||||
@ -57,7 +57,7 @@ class Realm {
|
||||
if (name != 'change') {
|
||||
throw new Error("Only 'change' notification is supported.");
|
||||
}
|
||||
this[notificationsKey].push(callback);
|
||||
this[listenersKey].push(callback);
|
||||
}
|
||||
|
||||
|
||||
@ -69,8 +69,8 @@ class Realm {
|
||||
throw new Error("Only 'change' notification is supported.");
|
||||
}
|
||||
var index = 0;
|
||||
while((index = this[notificationsKey].indexOf(callback, index)) != -1) {
|
||||
this[notificationsKey].splice(index, 1);
|
||||
while((index = this[listenersKey].indexOf(callback, index)) != -1) {
|
||||
this[listenersKey].splice(index, 1);
|
||||
};
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ class Realm {
|
||||
if (name != undefined && name != 'change') {
|
||||
throw new Error("Only 'change' notification is supported.");
|
||||
}
|
||||
this[notificationsKey] = [];
|
||||
this[listenersKey] = [];
|
||||
}
|
||||
|
||||
objects() {
|
||||
@ -114,7 +114,7 @@ class Realm {
|
||||
results[keys.resize]();
|
||||
}
|
||||
|
||||
for (let callback of this[notificationsKey]) {
|
||||
for (let callback of this[listenersKey]) {
|
||||
callback(this, 'change');
|
||||
}
|
||||
}
|
||||
|
@ -86,16 +86,16 @@ public:
|
||||
WeakRealm m_realm;
|
||||
|
||||
void notify(const char *notification_name) {
|
||||
for (auto callback : m_notifications) {
|
||||
JSValueRef arguments[2];
|
||||
SharedRealm realm = m_realm.lock();
|
||||
if (!realm) {
|
||||
throw std::runtime_error("Realm no longer exists");
|
||||
}
|
||||
JSObjectRef realm_object = RJSWrapObject<SharedRealm *>(m_context, RJSRealmClass(), new SharedRealm(realm));
|
||||
arguments[0] = realm_object;
|
||||
arguments[1] = RJSValueForString(m_context, notification_name);
|
||||
JSValueRef arguments[2];
|
||||
SharedRealm realm = m_realm.lock();
|
||||
if (!realm) {
|
||||
throw std::runtime_error("Realm no longer exists");
|
||||
}
|
||||
JSObjectRef realm_object = RJSWrapObject<SharedRealm *>(m_context, RJSRealmClass(), new SharedRealm(realm));
|
||||
arguments[0] = realm_object;
|
||||
arguments[1] = RJSValueForString(m_context, notification_name);
|
||||
|
||||
for (auto callback : m_notifications) {
|
||||
JSValueRef ex = NULL;
|
||||
JSObjectCallAsFunction(m_context, callback, realm_object, 2, arguments, &ex);
|
||||
if (ex) {
|
||||
@ -486,8 +486,6 @@ JSValueRef RealmRemoveAllListeners(JSContextRef ctx, JSObjectRef function, JSObj
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
JSValueRef RealmClose(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
|
||||
try {
|
||||
RJSValidateArgumentCount(argumentCount, 0);
|
||||
@ -521,5 +519,3 @@ JSClassRef RJSRealmClass() {
|
||||
static JSClassRef s_realmClass = RJSCreateWrapperClass<SharedRealm *>("Realm", RealmGetProperty, NULL, RJSRealmFuncs);
|
||||
return s_realmClass;
|
||||
}
|
||||
|
||||
|
||||
|
@ -311,5 +311,17 @@ module.exports = BaseTest.extend({
|
||||
realm.write(function() {});
|
||||
TestCase.assertEqual(notificationCount, 3);
|
||||
TestCase.assertEqual(secondNotificationCount, 1);
|
||||
|
||||
TestCase.assertThrows(function() {
|
||||
realm.addListener('invalid', function() {});
|
||||
});
|
||||
|
||||
realm.addListener('change', function() {
|
||||
throw new Error('error');
|
||||
});
|
||||
|
||||
TestCase.assertThrows(function() {
|
||||
realm.write(function() {});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user