Permalink
Browse files

LruCache, bugfix: data error when update element in updater function.

  • Loading branch information...
xicilion committed Sep 18, 2017
1 parent f169bb0 commit d27eb0099a6e89fefcbb09777dd2ae227f22b79e
Showing with 17 additions and 11 deletions.
  1. +8 −5 fibjs/src/util/LruCache.cpp
  2. +9 −6 test/util_test.js
@@ -118,11 +118,14 @@ result_t LruCache::get(exlib::string name, v8::Local<v8::Function> updater,
return CALL_E_JAVASCRIPT;
if (!IsEmpty(v)) {
find = m_datas.insert(std::pair<exlib::string, _linkedNode>(sname, newNode)).first;
insert(find);
find->second.insert.now();
SetPrivate(name, v);
find = m_datas.find(sname);
if (find == m_datas.end()) {
find = m_datas.insert(std::pair<exlib::string, _linkedNode>(sname, newNode)).first;
insert(find);
find->second.insert.now();
SetPrivate(name, v);
}
}
retVal = v;
View
@@ -228,15 +228,15 @@ describe('util', () => {
});
it('isAsyncFunction', () => {
assert.isTrue(util.isAsyncFunction(async () => {}));
assert.isTrue(util.isAsyncFunction(async function() {}));
assert.isTrue(util.isAsyncFunction(async() => {}));
assert.isTrue(util.isAsyncFunction(async function () {}));
assert.isTrue(util.isAsyncFunction(async function demo() {}));
assert.isFalse(util.isAsyncFunction(() => {}));
assert.isFalse(util.isAsyncFunction(function() {}));
assert.isFalse(util.isAsyncFunction(function () {}));
assert.isFalse(util.isAsyncFunction(function demo() {}));
assert.isFalse(util.isAsyncFunction(function*() {}));
assert.isFalse(util.isAsyncFunction(function* () {}));
assert.isFalse(util.isAsyncFunction(function* demo() {}));
});
@@ -1272,6 +1272,11 @@ describe('util', () => {
})
});
assert.equal(c.get("c1", (k) => {
c.set("c1", 200);
return 100;
}), 100);
assert.equal(c.get("c1"), 200);
});
it("Garbage Collection", () => {
@@ -1290,8 +1295,6 @@ describe('util', () => {
GC();
assert.equal(no1, os.memoryUsage().nativeObjects.objects);
});
});
});

0 comments on commit d27eb00

Please sign in to comment.