Files
MapLibreParticleLab/platform/node/src/node_map.hpp
John Firebaugh c4c3a19d85 [node] Allow GC in spite of reference loops through the request method
The following produces a reference cycle:

var map = new mbgl.Map({
    request: function () { ... }
});

map has a reference to the request function, which has a reference to
its closure, which has a reference to map.

Storing a the map options in an internal field, rather than a Persistent,
allows V8 to collect the reference cycle when none of its members have
other references.
2015-11-20 16:33:46 -08:00

63 lines
1.5 KiB
C++

#pragma once
#include <mbgl/map/map.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wnested-anon-types"
#include <nan.h>
#pragma GCC diagnostic pop
#include <queue>
namespace node_mbgl {
class NodeMap : public Nan::ObjectWrap,
public mbgl::FileSource {
public:
struct RenderOptions;
class RenderWorker;
static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);
static NAN_METHOD(Load);
static NAN_METHOD(Render);
static NAN_METHOD(Release);
static NAN_METHOD(DumpDebugLogs);
void startRender(std::unique_ptr<NodeMap::RenderOptions> options);
void renderFinished();
void release();
inline bool isLoaded() { return loaded; }
inline bool isValid() { return valid; }
static std::unique_ptr<NodeMap::RenderOptions> ParseOptions(v8::Local<v8::Object>);
static Nan::Persistent<v8::Function> constructor;
NodeMap(v8::Local<v8::Object>);
~NodeMap();
std::unique_ptr<mbgl::FileRequest> request(const mbgl::Resource&, Callback);
mbgl::HeadlessView view;
std::unique_ptr<mbgl::Map> map;
std::exception_ptr error;
std::unique_ptr<const mbgl::StillImage> image;
std::unique_ptr<Nan::Callback> callback;
// Async for delivering the notifications of render completion.
uv_async_t *async;
bool loaded = false;
bool valid = true;
};
}