Commit 60e0b255 by Marcin Cieslak

Replace smart pointers with a dumb ones

Remove C++11 feature in order to be
able to compile against libstdc++.so.6.0.9
on MacOSX.
parent ef58b6f1
...@@ -123,11 +123,12 @@ int ExtractOptions(v8::Local<v8::Object> options, void* cptr, sass_context_wrapp ...@@ -123,11 +123,12 @@ int ExtractOptions(v8::Local<v8::Object> options, void* cptr, sass_context_wrapp
if (importer_callback->IsFunction()) { if (importer_callback->IsFunction()) {
v8::Local<v8::Function> importer = importer_callback.As<v8::Function>(); v8::Local<v8::Function> importer = importer_callback.As<v8::Function>();
auto bridge = std::make_shared<CustomImporterBridge>(new Nan::Callback(importer), ctx_w->is_sync);
CustomImporterBridge *bridge = new CustomImporterBridge(importer, ctx_w->is_sync);
ctx_w->importer_bridges.push_back(bridge); ctx_w->importer_bridges.push_back(bridge);
Sass_Importer_List c_importers = sass_make_importer_list(1); Sass_Importer_List c_importers = sass_make_importer_list(1);
c_importers[0] = sass_make_importer(sass_importer, 0, bridge.get()); c_importers[0] = sass_make_importer(sass_importer, 0, bridge);
sass_option_set_c_importers(sass_options, c_importers); sass_option_set_c_importers(sass_options, c_importers);
} }
...@@ -138,10 +139,10 @@ int ExtractOptions(v8::Local<v8::Object> options, void* cptr, sass_context_wrapp ...@@ -138,10 +139,10 @@ int ExtractOptions(v8::Local<v8::Object> options, void* cptr, sass_context_wrapp
for (size_t i = 0; i < importers->Length(); ++i) { for (size_t i = 0; i < importers->Length(); ++i) {
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(Nan::Get(importers, static_cast<uint32_t>(i)).ToLocalChecked()); v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(Nan::Get(importers, static_cast<uint32_t>(i)).ToLocalChecked());
auto bridge = std::make_shared<CustomImporterBridge>(new Nan::Callback(callback), ctx_w->is_sync); CustomImporterBridge *bridge = new CustomImporterBridge(callback, ctx_w->is_sync);
ctx_w->importer_bridges.push_back(bridge); ctx_w->importer_bridges.push_back(bridge);
c_importers[i] = sass_make_importer(sass_importer, importers->Length() - i - 1, bridge.get()); c_importers[i] = sass_make_importer(sass_importer, importers->Length() - i - 1, bridge);
} }
sass_option_set_c_importers(sass_options, c_importers); sass_option_set_c_importers(sass_options, c_importers);
...@@ -159,10 +160,10 @@ int ExtractOptions(v8::Local<v8::Object> options, void* cptr, sass_context_wrapp ...@@ -159,10 +160,10 @@ int ExtractOptions(v8::Local<v8::Object> options, void* cptr, sass_context_wrapp
v8::Local<v8::String> signature = v8::Local<v8::String>::Cast(Nan::Get(signatures, Nan::New(i)).ToLocalChecked()); v8::Local<v8::String> signature = v8::Local<v8::String>::Cast(Nan::Get(signatures, Nan::New(i)).ToLocalChecked());
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(Nan::Get(functions, signature).ToLocalChecked()); v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(Nan::Get(functions, signature).ToLocalChecked());
auto bridge = std::make_shared<CustomFunctionBridge>(new Nan::Callback(callback), ctx_w->is_sync); CustomFunctionBridge *bridge = new CustomFunctionBridge(callback, ctx_w->is_sync);
ctx_w->function_bridges.push_back(bridge); ctx_w->function_bridges.push_back(bridge);
Sass_Function_Entry fn = sass_make_function(create_string(signature), sass_custom_function, bridge.get()); Sass_Function_Entry fn = sass_make_function(create_string(signature), sass_custom_function, bridge);
sass_function_set_list_entry(fn_list, i, fn); sass_function_set_list_entry(fn_list, i, fn);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
template <typename T, typename L = void*> template <typename T, typename L = void*>
class CallbackBridge { class CallbackBridge {
public: public:
CallbackBridge(Nan::Callback*, bool); CallbackBridge(v8::Local<v8::Function>, bool);
virtual ~CallbackBridge(); virtual ~CallbackBridge();
// Executes the callback // Executes the callback
...@@ -54,7 +54,7 @@ template <typename T, typename L> ...@@ -54,7 +54,7 @@ template <typename T, typename L>
Nan::Persistent<v8::Function> CallbackBridge<T, L>::wrapper_constructor; Nan::Persistent<v8::Function> CallbackBridge<T, L>::wrapper_constructor;
template <typename T, typename L> template <typename T, typename L>
CallbackBridge<T, L>::CallbackBridge(Nan::Callback* callback, bool is_sync) : callback(callback), is_sync(is_sync) { CallbackBridge<T, L>::CallbackBridge(v8::Local<v8::Function> callback, bool is_sync) : callback(new Nan::Callback(callback)), is_sync(is_sync) {
/* /*
* This is invoked from the main JavaScript thread. * This is invoked from the main JavaScript thread.
* V8 context is available. * V8 context is available.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class CustomFunctionBridge : public CallbackBridge<Sass_Value*> { class CustomFunctionBridge : public CallbackBridge<Sass_Value*> {
public: public:
CustomFunctionBridge(Nan::Callback* cb, bool is_sync) : CallbackBridge<Sass_Value*>(cb, is_sync) {} CustomFunctionBridge(v8::Local<v8::Function> cb, bool is_sync) : CallbackBridge<Sass_Value*>(cb, is_sync) {}
private: private:
Sass_Value* post_process_return_value(v8::Local<v8::Value>) const; Sass_Value* post_process_return_value(v8::Local<v8::Value>) const;
......
...@@ -9,7 +9,7 @@ typedef Sass_Import_List SassImportList; ...@@ -9,7 +9,7 @@ typedef Sass_Import_List SassImportList;
class CustomImporterBridge : public CallbackBridge<SassImportList> { class CustomImporterBridge : public CallbackBridge<SassImportList> {
public: public:
CustomImporterBridge(Nan::Callback* cb, bool is_sync) : CallbackBridge<SassImportList>(cb, is_sync) {} CustomImporterBridge(v8::Local<v8::Function> cb, bool is_sync) : CallbackBridge<SassImportList>(cb, is_sync) {}
private: private:
SassImportList post_process_return_value(v8::Local<v8::Value>) const; SassImportList post_process_return_value(v8::Local<v8::Value>) const;
......
...@@ -46,8 +46,18 @@ extern "C" { ...@@ -46,8 +46,18 @@ extern "C" {
free(ctx_w->source_map_root); free(ctx_w->source_map_root);
free(ctx_w->indent); free(ctx_w->indent);
ctx_w->importer_bridges.resize(0); std::vector<CustomImporterBridge *>::iterator imp_it = ctx_w->importer_bridges.begin();
ctx_w->function_bridges.resize(0); while (imp_it != ctx_w->importer_bridges.end()) {
CustomImporterBridge* p = *imp_it;
imp_it = ctx_w->importer_bridges.erase(imp_it);
delete p;
}
std::vector<CustomFunctionBridge *>::iterator func_it = ctx_w->function_bridges.begin();
while (func_it != ctx_w->function_bridges.end()) {
CustomFunctionBridge* p = *func_it;
func_it = ctx_w->function_bridges.erase(func_it);
delete p;
}
free(ctx_w); free(ctx_w);
} }
......
...@@ -42,8 +42,8 @@ extern "C" { ...@@ -42,8 +42,8 @@ extern "C" {
Nan::Callback* error_callback; Nan::Callback* error_callback;
Nan::Callback* success_callback; Nan::Callback* success_callback;
std::vector<std::shared_ptr<CustomFunctionBridge>> function_bridges; std::vector<CustomFunctionBridge *> function_bridges;
std::vector<std::shared_ptr<CustomImporterBridge>> importer_bridges; std::vector<CustomImporterBridge *> importer_bridges;
}; };
struct sass_context_wrapper* sass_make_context_wrapper(void); struct sass_context_wrapper* sass_make_context_wrapper(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment