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

Commit 8d48713

Browse files
committed
Trace in/out values for custom functions
Introduce one true way to print contents of the SassValue union.
1 parent 6affb04 commit 8d48713

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/custom_function_bridge.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
#include "custom_function_bridge.h"
44
#include "sass_types/factory.h"
55
#include "sass_types/value.h"
6+
#include "debug.h"
67

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

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

src/sass_types/sass_value_wrapper.h

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdexcept>
55
#include <vector>
66
#include <nan.h>
7+
#include "../debug.h"
78
#include "value.h"
89
#include "factory.h"
910

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

31+
static void print_value(Sass_Value *v) {
32+
if (v) {
33+
if (sass_value_is_null(v)) {
34+
TRACEINST(v) << "#null";
35+
} else if (sass_value_is_number(v)) {
36+
TRACEINST(v) << "#number "
37+
<< sass_number_get_value(v)
38+
<< " unit=<" << sass_number_get_unit(v) << ">";
39+
} else if (sass_value_is_string(v)) {
40+
TRACEINST(v) << "#string "
41+
<< '"' << sass_string_get_value(v) << '"'
42+
<< ", quoted=" << (sass_string_is_quoted(v) ? 'Y' : 'N');
43+
} else if (sass_value_is_boolean(v)) {
44+
TRACEINST(v) << "#boolean " << sass_boolean_get_value(v);
45+
} else if (sass_value_is_color(v)) {
46+
TRACEINST(v) << "#color RGBA: <"
47+
<< sass_color_get_r(v) << ","
48+
<< sass_color_get_g(v) << ","
49+
<< sass_color_get_b(v) << ","
50+
<< sass_color_get_a(v) << ">";
51+
} else if (sass_value_is_list(v)) {
52+
enum Sass_Separator sep = sass_list_get_separator(v);
53+
size_t len = sass_list_get_length(v);
54+
TRACEINST(v) << "#list "
55+
<< "separator=<" << (sep == SASS_COMMA ? ',' : ' ') << ">"
56+
<< "length=" << len;
57+
for(size_t i = 0; i < len; i ++) {
58+
TRACEINST(v) << "item(" << i << ")";
59+
print_value(sass_list_get_value(v, i));
60+
}
61+
TRACEINST(v) << "#list end";
62+
} else if (sass_value_is_map(v)) {
63+
size_t len = sass_map_get_length(v);
64+
TRACEINST(v) << "#map length=" << len;
65+
for(size_t i = 0; i < len; i ++) {
66+
TRACEINST(v) << "key(" << i << ")";
67+
print_value(sass_map_get_key(v, i));
68+
TRACEINST(v) << "value(" << i << ")";
69+
print_value(sass_map_get_value(v, i));
70+
}
71+
TRACEINST(v) << "#map end";
72+
} else if (sass_value_is_error(v)) {
73+
TRACEINST(v) << "#error " << sass_error_get_message(v);
74+
} else if (sass_value_is_warning(v)) {
75+
TRACEINST(v) << "#warn " << sass_warning_get_message(v);
76+
} else {
77+
TRACEINST(v) << "#unknown";
78+
}
79+
} else {
80+
TRACE() << "(null value)";
81+
}
82+
}
83+
3084
protected:
3185
Sass_Value* value;
3286
static T* unwrap(v8::Local<v8::Object>);
@@ -42,6 +96,9 @@ namespace SassTypes
4296
template <class T>
4397
SassValueWrapper<T>::SassValueWrapper(Sass_Value* v) {
4498
this->value = sass_clone_value(v);
99+
TRACEINST(this) << "ctor " << (void *)this->value << " := " << (void *)v;
100+
print_value(v);
101+
TRACEINST(this) << "done";
45102
}
46103

47104
template <class T>
@@ -52,7 +109,11 @@ namespace SassTypes
52109

53110
template <class T>
54111
Sass_Value* SassValueWrapper<T>::get_sass_value() {
55-
return sass_clone_value(this->value);
112+
Sass_Value *nv = sass_clone_value(this->value);
113+
TRACEINST(this) << (void *)nv << " := " << (void *)this->value;
114+
print_value(this->value);
115+
TRACEINST(this) << "done";
116+
return nv;
56117
}
57118

58119
template <class T>

0 commit comments

Comments
 (0)