Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,27 +301,27 @@ module.exports.render = function(options, cb) {
if (Array.isArray(importer)) {
importer.forEach(function(subject, index) {
options.importer[index] = function(file, prev, bridge) {
function done(data) {
bridge.success(data);
function done(result) {
bridge.success(result === module.exports.NULL ? null : result);
}

var result = subject.call(options.context, file, prev, done);

if (result) {
done(result === module.exports.NULL ? null : result);
if (result !== undefined) {
done(result);
}
};
});
} else {
options.importer = function(file, prev, bridge) {
function done(data) {
bridge.success(data);
function done(result) {
bridge.success(result === module.exports.NULL ? null : result);
}

var result = importer.call(options.context, file, prev, done);

if (result) {
done(result === module.exports.NULL ? null : result);
if (result !== undefined) {
done(result);
}
};
}
Expand Down
16 changes: 14 additions & 2 deletions src/custom_function_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
#include "sass_types/factory.h"
#include "sass_types/value.h"

#include <stdio.h>

Sass_Value* CustomFunctionBridge::post_process_return_value(v8::Local<v8::Value> val) const {
SassTypes::Value *v_;
if ((v_ = SassTypes::Factory::unwrap(val))) {
if (val->IsNull()) {
return sass_make_null();
} else if ((v_ = SassTypes::Factory::unwrap(val))) {
return v_->get_sass_value();
} else {
return sass_make_error("A SassValue object was expected.");
Expand All @@ -17,7 +21,15 @@ 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) {
argv.push_back(SassTypes::Factory::create(static_cast<Sass_Value*>(value))->get_js_object());
Sass_Value *vptr = static_cast<Sass_Value*>(value);
v8::Local<v8::Value> item;

if (sass_value_is_null(vptr)) {
item = Nan::Null();
} else {
item = SassTypes::Factory::create(vptr)->get_js_object();
}
argv.push_back(item);
}

return argv;
Expand Down
4 changes: 2 additions & 2 deletions src/sass_types/boolean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ namespace SassTypes

if (info.IsConstructCall()) {
if (constructor_locked) {
return Nan::ThrowTypeError(Nan::New("Cannot instantiate SassBoolean").ToLocalChecked());
return Nan::ThrowTypeError("Cannot instantiate SassBoolean");
}
}
else {
if (info.Length() != 1 || !info[0]->IsBoolean()) {
return Nan::ThrowTypeError(Nan::New("Expected one boolean argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected one boolean argument");
}

info.GetReturnValue().Set(get_singleton(Nan::To<bool>(info[0]).FromJust()).get_js_object());
Expand Down
16 changes: 8 additions & 8 deletions src/sass_types/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,47 +79,47 @@ namespace SassTypes

NAN_METHOD(Color::SetR) {
if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a number");
}

sass_color_set_r(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
}

NAN_METHOD(Color::SetG) {
if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a number");
}

sass_color_set_g(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
}

NAN_METHOD(Color::SetB) {
if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a number");
}

sass_color_set_b(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
}

NAN_METHOD(Color::SetA) {
if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a number");
}

sass_color_set_a(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
Expand Down
7 changes: 5 additions & 2 deletions src/sass_types/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ namespace SassTypes

default:
const char *msg = "Unknown type encountered.";
Nan::ThrowTypeError(Nan::New<v8::String>(msg).ToLocalChecked());
Nan::ThrowTypeError(msg);
return new Error(sass_make_error(msg));
}
}

NAN_MODULE_INIT(Factory::initExports) {
Nan::HandleScope scope;
v8::Local<v8::Object> fake_null = Nan::New<v8::Object>();
Nan::Set(fake_null, Nan::New("NULL").ToLocalChecked(), Nan::Null());

v8::Local<v8::Object> types = Nan::New<v8::Object>();

Nan::Set(types, Nan::New("Number").ToLocalChecked(), Number::get_constructor());
Expand All @@ -55,7 +58,7 @@ namespace SassTypes
Nan::Set(types, Nan::New("Boolean").ToLocalChecked(), Boolean::get_constructor());
Nan::Set(types, Nan::New("List").ToLocalChecked(), List::get_constructor());
Nan::Set(types, Nan::New("Map").ToLocalChecked(), Map::get_constructor());
Nan::Set(types, Nan::New("Null").ToLocalChecked(), Null::get_constructor());
Nan::Set(types, Nan::New("Null").ToLocalChecked(), fake_null);
Nan::Set(types, Nan::New("Error").ToLocalChecked(), Error::get_constructor());
Nan::Set(target, Nan::New<v8::String>("types").ToLocalChecked(), types);
}
Expand Down
27 changes: 18 additions & 9 deletions src/sass_types/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ namespace SassTypes
NAN_METHOD(List::GetValue) {

if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
return Nan::ThrowTypeError("Supplied index should be an integer");
}

Sass_Value* list = unwrap(info.This())->value;
Expand All @@ -54,27 +54,36 @@ namespace SassTypes
return Nan::ThrowRangeError(Nan::New("Out of bound index").ToLocalChecked());
}

info.GetReturnValue().Set(Factory::create(sass_list_get_value(list, Nan::To<uint32_t>(info[0]).FromJust()))->get_js_object());
Sass_Value *item = sass_list_get_value(list, Nan::To<uint32_t>(info[0]).FromJust());
if (sass_value_is_null(item)) {
info.GetReturnValue().Set(Nan::Null());
} else {
info.GetReturnValue().Set(Factory::create(item)->get_js_object());
}
}

NAN_METHOD(List::SetValue) {
if (info.Length() != 2) {
return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked());
return Nan::ThrowTypeError("Expected two arguments");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
return Nan::ThrowTypeError("Supplied index should be an integer");
}

if (info[1]->IsNull()) {
sass_list_set_value(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_make_null());
return;
}
if (!info[1]->IsObject()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a SassValue object");
}

Value* sass_value = Factory::unwrap(info[1]);
if (sass_value) {
sass_list_set_value(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value());
} else {
Nan::ThrowTypeError(Nan::New<v8::String>("A SassValue is expected as the list item").ToLocalChecked());
Nan::ThrowTypeError("A SassValue is expected as the list item");
}
}

Expand All @@ -84,11 +93,11 @@ namespace SassTypes

NAN_METHOD(List::SetSeparator) {
if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsBoolean()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a boolean").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a boolean");
}

sass_list_set_separator(unwrap(info.This())->value, Nan::To<bool>(info[0]).FromJust() ? SASS_COMMA : SASS_SPACE);
Expand Down
24 changes: 12 additions & 12 deletions src/sass_types/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ namespace SassTypes
NAN_METHOD(Map::GetValue) {

if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
return Nan::ThrowTypeError("Supplied index should be an integer");
}

Sass_Value* map = unwrap(info.This())->value;
Expand All @@ -50,33 +50,33 @@ namespace SassTypes

NAN_METHOD(Map::SetValue) {
if (info.Length() != 2) {
return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked());
return Nan::ThrowTypeError("Expected two arguments");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
return Nan::ThrowTypeError("Supplied index should be an integer");
}

if (!info[1]->IsObject()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a SassValue object");
}

Value* sass_value = Factory::unwrap(info[1]);
if (sass_value) {
sass_map_set_value(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value());
} else {
Nan::ThrowTypeError(Nan::New<v8::String>("A SassValue is expected as a map value").ToLocalChecked());
Nan::ThrowTypeError("A SassValue is expected as a map value");
}
}

NAN_METHOD(Map::GetKey) {

if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
return Nan::ThrowTypeError("Supplied index should be an integer");
}

Sass_Value* map = unwrap(info.This())->value;
Expand All @@ -92,22 +92,22 @@ namespace SassTypes

NAN_METHOD(Map::SetKey) {
if (info.Length() != 2) {
return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked());
return Nan::ThrowTypeError("Expected two arguments");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
return Nan::ThrowTypeError("Supplied index should be an integer");
}

if (!info[1]->IsObject()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a SassValue object");
}

Value* sass_value = Factory::unwrap(info[1]);
if (sass_value) {
sass_map_set_key(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value());
} else {
Nan::ThrowTypeError(Nan::New<v8::String>("A SassValue is expected as a map key").ToLocalChecked());
Nan::ThrowTypeError("A SassValue is expected as a map key");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sass_types/null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace SassTypes

if (info.IsConstructCall()) {
if (constructor_locked) {
return Nan::ThrowTypeError(Nan::New("Cannot instantiate SassNull").ToLocalChecked());
return Nan::ThrowTypeError("Cannot instantiate SassNull");
}
}
else {
Expand Down
8 changes: 4 additions & 4 deletions src/sass_types/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ namespace SassTypes
NAN_METHOD(Number::SetValue) {

if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsNumber()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a number");
}

sass_number_set_value(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
}

NAN_METHOD(Number::SetUnit) {
if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsString()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a string").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a string");
}

sass_number_set_unit(unwrap(info.This())->value, create_string(info[0]));
Expand Down
4 changes: 2 additions & 2 deletions src/sass_types/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ namespace SassTypes

NAN_METHOD(String::SetValue) {
if (info.Length() != 1) {
return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
return Nan::ThrowTypeError("Expected just one argument");
}

if (!info[0]->IsString()) {
return Nan::ThrowTypeError(Nan::New("Supplied value should be a string").ToLocalChecked());
return Nan::ThrowTypeError("Supplied value should be a string");
}

sass_string_set_value(unwrap(info.This())->value, create_string(info[0]));
Expand Down
Loading