Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Replace smart pointers with a dumb ones
Browse files Browse the repository at this point in the history
Remove C++11 feature in order to be
able to compile against libstdc++.so.6.0.9
on MacOSX.
  • Loading branch information
saper committed Aug 27, 2015
1 parent ef58b6f commit 60e0b25
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
13 changes: 7 additions & 6 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ int ExtractOptions(v8::Local<v8::Object> options, void* cptr, sass_context_wrapp

if (importer_callback->IsFunction()) {
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);

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);
}
Expand All @@ -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) {
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);

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);
Expand All @@ -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::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);

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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/callback_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
template <typename T, typename L = void*>
class CallbackBridge {
public:
CallbackBridge(Nan::Callback*, bool);
CallbackBridge(v8::Local<v8::Function>, bool);
virtual ~CallbackBridge();

// Executes the callback
Expand Down Expand Up @@ -54,7 +54,7 @@ template <typename T, typename L>
Nan::Persistent<v8::Function> CallbackBridge<T, L>::wrapper_constructor;

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.
* V8 context is available.
Expand Down
2 changes: 1 addition & 1 deletion src/custom_function_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CustomFunctionBridge : public CallbackBridge<Sass_Value*> {
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:
Sass_Value* post_process_return_value(v8::Local<v8::Value>) const;
Expand Down
2 changes: 1 addition & 1 deletion src/custom_importer_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typedef Sass_Import_List SassImportList;

class CustomImporterBridge : public CallbackBridge<SassImportList> {
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:
SassImportList post_process_return_value(v8::Local<v8::Value>) const;
Expand Down
14 changes: 12 additions & 2 deletions src/sass_context_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ extern "C" {
free(ctx_w->source_map_root);
free(ctx_w->indent);

ctx_w->importer_bridges.resize(0);
ctx_w->function_bridges.resize(0);
std::vector<CustomImporterBridge *>::iterator imp_it = ctx_w->importer_bridges.begin();
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/sass_context_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ extern "C" {
Nan::Callback* error_callback;
Nan::Callback* success_callback;

std::vector<std::shared_ptr<CustomFunctionBridge>> function_bridges;
std::vector<std::shared_ptr<CustomImporterBridge>> importer_bridges;
std::vector<CustomFunctionBridge *> function_bridges;
std::vector<CustomImporterBridge *> importer_bridges;
};

struct sass_context_wrapper* sass_make_context_wrapper(void);
Expand Down

0 comments on commit 60e0b25

Please sign in to comment.