Skip to content

Commit

Permalink
Expose clearKeptObjects function, kriszyp/weak-lru-cache#4
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jan 24, 2022
1 parent 39af8fa commit 82fac02
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion external.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export let Env, Compression, Cursor, getAddress, getAddressShared, setGlobalBuffer,
export let Env, Compression, Cursor, getAddress, clearKeptObjects, setGlobalBuffer,
require, arch, fs, lmdbError, path, EventEmitter, orderedBinary, MsgpackrEncoder, WeakLRUCache;
export function setNativeFunctions(externals) {
Env = externals.Env;
Compression = externals.Compression;
getAddress = externals.getAddress;
clearKeptObjects = externals.clearKeptObjects;
setGlobalBuffer = externals.setGlobalBuffer;
Cursor = externals.Cursor;
lmdbError = externals.lmdbError;
Expand Down
1 change: 1 addition & 0 deletions node-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ setExternals({
export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
export { ABORT, IF_EXISTS, asBinary } from './write.js';
export { levelup } from './level.js';
export { clearKeptObjects } from './external.js';
export { open, getLastVersion, getLastEntrySize, setLastVersion, allDbs } from './open.js';
import { toBufferKey as keyValueToBuffer, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
import { open, getLastVersion } from './open.js';
Expand Down
1 change: 1 addition & 0 deletions src/lmdb-js.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ NAN_METHOD(lmdbError);
//NAN_METHOD(getBufferForAddress);
NAN_METHOD(getViewAddress);
NAN_METHOD(getAddress);
NAN_METHOD(clearKeptObjects);
NAN_METHOD(lmdbNativeFunctions);

#ifndef thread_local
Expand Down
5 changes: 5 additions & 0 deletions src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void setupExportMisc(Local<Object> exports) {
Nan::SetMethod(exports, "lmdbError", lmdbError);
//Nan::SetMethod(exports, "getBufferForAddress", getBufferForAddress);
Nan::SetMethod(exports, "getAddress", getViewAddress);
Nan::SetMethod(exports, "clearKeptObjects", clearKeptObjects);
// this is set solely for the purpose of giving a good name to the set of native functions for the profiler since V8
// often just uses the name of the last exported native function:
Nan::SetMethod(exports, "lmdbNativeFunctions", lmdbNativeFunctions);
Expand Down Expand Up @@ -201,6 +202,10 @@ NAN_METHOD(getViewAddress) {
void* address = length > 0 ? node::Buffer::Data(info[0]) : nullptr;
info.GetReturnValue().Set(Nan::New<Number>((size_t) address));
}
NAN_METHOD(clearKeptObjects) {
Isolate::GetCurrent()->ClearKeptObjects();
}

NAN_METHOD(lmdbNativeFunctions) {
// no-op, just doing this to give a label to the native functions
}
Expand Down

0 comments on commit 82fac02

Please sign in to comment.