Commit 08f11892 by Michael Mifsud

Merge pull request #1309 from saper/less-red-tape-throw

Less V8 bureaucracy for Nan::ThrowTypeError
parents 7128b45e cc1810b3
...@@ -54,12 +54,12 @@ namespace SassTypes ...@@ -54,12 +54,12 @@ namespace SassTypes
if (info.IsConstructCall()) { if (info.IsConstructCall()) {
if (constructor_locked) { if (constructor_locked) {
return Nan::ThrowTypeError(Nan::New("Cannot instantiate SassBoolean").ToLocalChecked()); return Nan::ThrowTypeError("Cannot instantiate SassBoolean");
} }
} }
else { else {
if (info.Length() != 1 || !info[0]->IsBoolean()) { 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()); info.GetReturnValue().Set(get_singleton(Nan::To<bool>(info[0]).FromJust()).get_js_object());
......
...@@ -79,11 +79,11 @@ namespace SassTypes ...@@ -79,11 +79,11 @@ namespace SassTypes
NAN_METHOD(Color::SetR) { NAN_METHOD(Color::SetR) {
if (info.Length() != 1) { 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()) { 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()); sass_color_set_r(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
...@@ -91,11 +91,11 @@ namespace SassTypes ...@@ -91,11 +91,11 @@ namespace SassTypes
NAN_METHOD(Color::SetG) { NAN_METHOD(Color::SetG) {
if (info.Length() != 1) { 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()) { 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()); sass_color_set_g(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
...@@ -103,11 +103,11 @@ namespace SassTypes ...@@ -103,11 +103,11 @@ namespace SassTypes
NAN_METHOD(Color::SetB) { NAN_METHOD(Color::SetB) {
if (info.Length() != 1) { 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()) { 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()); sass_color_set_b(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
...@@ -115,11 +115,11 @@ namespace SassTypes ...@@ -115,11 +115,11 @@ namespace SassTypes
NAN_METHOD(Color::SetA) { NAN_METHOD(Color::SetA) {
if (info.Length() != 1) { 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()) { 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()); sass_color_set_a(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
......
...@@ -40,7 +40,7 @@ namespace SassTypes ...@@ -40,7 +40,7 @@ namespace SassTypes
default: default:
const char *msg = "Unknown type encountered."; const char *msg = "Unknown type encountered.";
Nan::ThrowTypeError(Nan::New<v8::String>(msg).ToLocalChecked()); Nan::ThrowTypeError(msg);
return new Error(sass_make_error(msg)); return new Error(sass_make_error(msg));
} }
} }
......
...@@ -39,11 +39,11 @@ namespace SassTypes ...@@ -39,11 +39,11 @@ namespace SassTypes
NAN_METHOD(List::GetValue) { NAN_METHOD(List::GetValue) {
if (info.Length() != 1) { 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()) { 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; Sass_Value* list = unwrap(info.This())->value;
...@@ -59,22 +59,22 @@ namespace SassTypes ...@@ -59,22 +59,22 @@ namespace SassTypes
NAN_METHOD(List::SetValue) { NAN_METHOD(List::SetValue) {
if (info.Length() != 2) { if (info.Length() != 2) {
return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked()); return Nan::ThrowTypeError("Expected two arguments");
} }
if (!info[0]->IsNumber()) { 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()) { 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]); Value* sass_value = Factory::unwrap(info[1]);
if (sass_value) { if (sass_value) {
sass_list_set_value(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value()); sass_list_set_value(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value());
} else { } 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");
} }
} }
...@@ -84,11 +84,11 @@ namespace SassTypes ...@@ -84,11 +84,11 @@ namespace SassTypes
NAN_METHOD(List::SetSeparator) { NAN_METHOD(List::SetSeparator) {
if (info.Length() != 1) { 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()) { 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); sass_list_set_separator(unwrap(info.This())->value, Nan::To<bool>(info[0]).FromJust() ? SASS_COMMA : SASS_SPACE);
......
...@@ -30,11 +30,11 @@ namespace SassTypes ...@@ -30,11 +30,11 @@ namespace SassTypes
NAN_METHOD(Map::GetValue) { NAN_METHOD(Map::GetValue) {
if (info.Length() != 1) { 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()) { 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; Sass_Value* map = unwrap(info.This())->value;
...@@ -50,33 +50,33 @@ namespace SassTypes ...@@ -50,33 +50,33 @@ namespace SassTypes
NAN_METHOD(Map::SetValue) { NAN_METHOD(Map::SetValue) {
if (info.Length() != 2) { if (info.Length() != 2) {
return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked()); return Nan::ThrowTypeError("Expected two arguments");
} }
if (!info[0]->IsNumber()) { 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()) { 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]); Value* sass_value = Factory::unwrap(info[1]);
if (sass_value) { if (sass_value) {
sass_map_set_value(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value()); sass_map_set_value(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value());
} else { } 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) { NAN_METHOD(Map::GetKey) {
if (info.Length() != 1) { 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()) { 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; Sass_Value* map = unwrap(info.This())->value;
...@@ -92,22 +92,22 @@ namespace SassTypes ...@@ -92,22 +92,22 @@ namespace SassTypes
NAN_METHOD(Map::SetKey) { NAN_METHOD(Map::SetKey) {
if (info.Length() != 2) { if (info.Length() != 2) {
return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked()); return Nan::ThrowTypeError("Expected two arguments");
} }
if (!info[0]->IsNumber()) { 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()) { 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]); Value* sass_value = Factory::unwrap(info[1]);
if (sass_value) { if (sass_value) {
sass_map_set_key(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value()); sass_map_set_key(unwrap(info.This())->value, Nan::To<uint32_t>(info[0]).FromJust(), sass_value->get_sass_value());
} else { } 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");
} }
} }
......
...@@ -49,7 +49,7 @@ namespace SassTypes ...@@ -49,7 +49,7 @@ namespace SassTypes
if (info.IsConstructCall()) { if (info.IsConstructCall()) {
if (constructor_locked) { if (constructor_locked) {
return Nan::ThrowTypeError(Nan::New("Cannot instantiate SassNull").ToLocalChecked()); return Nan::ThrowTypeError("Cannot instantiate SassNull");
} }
} }
else { else {
......
...@@ -47,11 +47,11 @@ namespace SassTypes ...@@ -47,11 +47,11 @@ namespace SassTypes
NAN_METHOD(Number::SetValue) { NAN_METHOD(Number::SetValue) {
if (info.Length() != 1) { 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()) { 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()); sass_number_set_value(unwrap(info.This())->value, Nan::To<double>(info[0]).FromJust());
...@@ -59,11 +59,11 @@ namespace SassTypes ...@@ -59,11 +59,11 @@ namespace SassTypes
NAN_METHOD(Number::SetUnit) { NAN_METHOD(Number::SetUnit) {
if (info.Length() != 1) { 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()) { 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])); sass_number_set_unit(unwrap(info.This())->value, create_string(info[0]));
......
...@@ -31,11 +31,11 @@ namespace SassTypes ...@@ -31,11 +31,11 @@ namespace SassTypes
NAN_METHOD(String::SetValue) { NAN_METHOD(String::SetValue) {
if (info.Length() != 1) { 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()) { 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])); sass_string_set_value(unwrap(info.This())->value, create_string(info[0]));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment