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

Commit cb37972

Browse files
committed
Trace in/out values for custom functions
Introduce one true way to print contents of the SassValue union.
1 parent 3d62138 commit cb37972

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
@@ -1,9 +1,11 @@
11
#include <nan.h>
22
#include "custom_function_bridge.h"
33
#include "sass_types/factory.h"
4+
#include "debug.h"
45

56
Sass_Value* CustomFunctionBridge::post_process_return_value(Handle<Value> val) const {
67
try {
8+
TRACEINST(&val) << " CustomFunctionBridge: unwrapping custom function return value...";
79
return SassTypes::Factory::unwrap(val)->get_sass_value();
810
}
911
catch (const std::invalid_argument& e) {
@@ -15,6 +17,7 @@ std::vector<Handle<Value>> CustomFunctionBridge::pre_process_args(std::vector<vo
1517
std::vector<Handle<Value>> argv = std::vector<Handle<Value>>();
1618

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

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

@@ -28,6 +29,59 @@ namespace SassTypes
2829
static Local<FunctionTemplate> get_constructor_template();
2930
static NAN_METHOD(New);
3031

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

48105
template <class T>
@@ -53,7 +110,11 @@ namespace SassTypes
53110

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

59120
template <class T>

0 commit comments

Comments
 (0)