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

Commit

Permalink
Trace in/out values for custom functions
Browse files Browse the repository at this point in the history
Introduce one true way to print contents
of the SassValue union.
  • Loading branch information
saper committed Apr 30, 2016
1 parent 6affb04 commit 8d48713
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/custom_function_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include "custom_function_bridge.h"
#include "sass_types/factory.h"
#include "sass_types/value.h"
#include "debug.h"

Sass_Value* CustomFunctionBridge::post_process_return_value(v8::Local<v8::Value> val) const {
SassTypes::Value *v_;
if ((v_ = SassTypes::Factory::unwrap(val))) {
TRACEINST(&val) << " CustomFunctionBridge: unwrapping custom function return value...";
return v_->get_sass_value();
} else {
return sass_make_error("A SassValue object was expected.");
Expand All @@ -17,6 +19,7 @@ std::vector<v8::Local<v8::Value>> CustomFunctionBridge::pre_process_args(std::ve
std::vector<v8::Local<v8::Value>> argv = std::vector<v8::Local<v8::Value>>();

for (void* value : in) {
TRACEINST(&value) << " CustomFunctionBridge: wrapping custom function parameters...";
argv.push_back(SassTypes::Factory::create(static_cast<Sass_Value*>(value))->get_js_object());
}

Expand Down
63 changes: 62 additions & 1 deletion src/sass_types/sass_value_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdexcept>
#include <vector>
#include <nan.h>
#include "../debug.h"
#include "value.h"
#include "factory.h"

Expand All @@ -27,6 +28,59 @@ namespace SassTypes
static NAN_METHOD(New);
static Sass_Value *fail(const char *, Sass_Value **);

static void print_value(Sass_Value *v) {
if (v) {
if (sass_value_is_null(v)) {
TRACEINST(v) << "#null";
} else if (sass_value_is_number(v)) {
TRACEINST(v) << "#number "
<< sass_number_get_value(v)
<< " unit=<" << sass_number_get_unit(v) << ">";
} else if (sass_value_is_string(v)) {
TRACEINST(v) << "#string "
<< '"' << sass_string_get_value(v) << '"'
<< ", quoted=" << (sass_string_is_quoted(v) ? 'Y' : 'N');
} else if (sass_value_is_boolean(v)) {
TRACEINST(v) << "#boolean " << sass_boolean_get_value(v);
} else if (sass_value_is_color(v)) {
TRACEINST(v) << "#color RGBA: <"
<< sass_color_get_r(v) << ","
<< sass_color_get_g(v) << ","
<< sass_color_get_b(v) << ","
<< sass_color_get_a(v) << ">";
} else if (sass_value_is_list(v)) {
enum Sass_Separator sep = sass_list_get_separator(v);
size_t len = sass_list_get_length(v);
TRACEINST(v) << "#list "
<< "separator=<" << (sep == SASS_COMMA ? ',' : ' ') << ">"
<< "length=" << len;
for(size_t i = 0; i < len; i ++) {
TRACEINST(v) << "item(" << i << ")";
print_value(sass_list_get_value(v, i));
}
TRACEINST(v) << "#list end";
} else if (sass_value_is_map(v)) {
size_t len = sass_map_get_length(v);
TRACEINST(v) << "#map length=" << len;
for(size_t i = 0; i < len; i ++) {
TRACEINST(v) << "key(" << i << ")";
print_value(sass_map_get_key(v, i));
TRACEINST(v) << "value(" << i << ")";
print_value(sass_map_get_value(v, i));
}
TRACEINST(v) << "#map end";
} else if (sass_value_is_error(v)) {
TRACEINST(v) << "#error " << sass_error_get_message(v);
} else if (sass_value_is_warning(v)) {
TRACEINST(v) << "#warn " << sass_warning_get_message(v);
} else {
TRACEINST(v) << "#unknown";
}
} else {
TRACE() << "(null value)";
}
}

protected:
Sass_Value* value;
static T* unwrap(v8::Local<v8::Object>);
Expand All @@ -42,6 +96,9 @@ namespace SassTypes
template <class T>
SassValueWrapper<T>::SassValueWrapper(Sass_Value* v) {
this->value = sass_clone_value(v);
TRACEINST(this) << "ctor " << (void *)this->value << " := " << (void *)v;
print_value(v);
TRACEINST(this) << "done";
}

template <class T>
Expand All @@ -52,7 +109,11 @@ namespace SassTypes

template <class T>
Sass_Value* SassValueWrapper<T>::get_sass_value() {
return sass_clone_value(this->value);
Sass_Value *nv = sass_clone_value(this->value);
TRACEINST(this) << (void *)nv << " := " << (void *)this->value;
print_value(this->value);
TRACEINST(this) << "done";
return nv;
}

template <class T>
Expand Down

0 comments on commit 8d48713

Please sign in to comment.