sass_context_wrapper.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "sass_context_wrapper.h"
  2. extern "C" {
  3. using namespace std;
  4. void compile_it(uv_work_t* req) {
  5. sass_context_wrapper* ctx_w = (sass_context_wrapper*)req->data;
  6. if (ctx_w->dctx) {
  7. compile_data(ctx_w->dctx);
  8. }
  9. else if (ctx_w->fctx) {
  10. compile_file(ctx_w->fctx);
  11. }
  12. }
  13. void compile_data(struct Sass_Data_Context* dctx) {
  14. sass_compile_data_context(dctx);
  15. }
  16. void compile_file(struct Sass_File_Context* fctx) {
  17. sass_compile_file_context(fctx);
  18. }
  19. sass_context_wrapper* sass_make_context_wrapper() {
  20. return (sass_context_wrapper*)calloc(1, sizeof(sass_context_wrapper));
  21. }
  22. void sass_free_context_wrapper(sass_context_wrapper* ctx_w) {
  23. if (ctx_w->dctx) {
  24. sass_delete_data_context(ctx_w->dctx);
  25. }
  26. else if (ctx_w->fctx) {
  27. sass_delete_file_context(ctx_w->fctx);
  28. }
  29. if (ctx_w->async_resource) {
  30. delete ctx_w->async_resource;
  31. }
  32. delete ctx_w->error_callback;
  33. delete ctx_w->success_callback;
  34. ctx_w->result.Reset();
  35. free(ctx_w->include_path);
  36. free(ctx_w->linefeed);
  37. free(ctx_w->out_file);
  38. free(ctx_w->source_map);
  39. free(ctx_w->source_map_root);
  40. free(ctx_w->indent);
  41. std::vector<CustomImporterBridge *>::iterator imp_it = ctx_w->importer_bridges.begin();
  42. while (imp_it != ctx_w->importer_bridges.end()) {
  43. CustomImporterBridge* p = *imp_it;
  44. imp_it = ctx_w->importer_bridges.erase(imp_it);
  45. delete p;
  46. }
  47. std::vector<CustomFunctionBridge *>::iterator func_it = ctx_w->function_bridges.begin();
  48. while (func_it != ctx_w->function_bridges.end()) {
  49. CustomFunctionBridge* p = *func_it;
  50. func_it = ctx_w->function_bridges.erase(func_it);
  51. delete p;
  52. }
  53. free(ctx_w);
  54. }
  55. }