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

Commit

Permalink
Merge pull request #1309 from saper/less-red-tape-throw
Browse files Browse the repository at this point in the history
Less V8 bureaucracy for Nan::ThrowTypeError
  • Loading branch information
xzyfer committed Dec 27, 2015
2 parents 7128b45 + cc1810b commit 08f1189
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
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
2 changes: 1 addition & 1 deletion src/sass_types/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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));
}
}
Expand Down
16 changes: 8 additions & 8 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 @@ -59,22 +59,22 @@ namespace SassTypes

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]->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 +84,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

0 comments on commit 08f1189

Please sign in to comment.