Commit 06042232 by Marcin Cieslak

Throw more specific exceptions

Use TypeError whenever argument count
or type do not match and RangeError
if the index is out of bounds.
parent c9494525
...@@ -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::ThrowError(Nan::New("Cannot instantiate SassBoolean").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Cannot instantiate SassBoolean").ToLocalChecked());
} }
} }
else { else {
if (info.Length() != 1 || !info[0]->IsBoolean()) { if (info.Length() != 1 || !info[0]->IsBoolean()) {
return Nan::ThrowError(Nan::New("Expected one boolean argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected one boolean argument").ToLocalChecked());
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied value should be a number").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied value should be a number").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied value should be a number").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied value should be a number").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
} }
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());
......
...@@ -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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied index should be an integer").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
} }
Sass_Value* list = unwrap(info.This())->value; Sass_Value* list = unwrap(info.This())->value;
...@@ -51,7 +51,7 @@ namespace SassTypes ...@@ -51,7 +51,7 @@ namespace SassTypes
if (index >= sass_list_get_length(list)) { if (index >= sass_list_get_length(list)) {
return Nan::ThrowError(Nan::New("Out of bound index").ToLocalChecked()); 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()); info.GetReturnValue().Set(Factory::create(sass_list_get_value(list, Nan::To<uint32_t>(info[0]).FromJust()))->get_js_object());
...@@ -59,15 +59,15 @@ namespace SassTypes ...@@ -59,15 +59,15 @@ namespace SassTypes
NAN_METHOD(List::SetValue) { NAN_METHOD(List::SetValue) {
if (info.Length() != 2) { if (info.Length() != 2) {
return Nan::ThrowError(Nan::New("Expected two arguments").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied index should be an integer").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
} }
if (!info[1]->IsObject()) { if (!info[1]->IsObject()) {
return Nan::ThrowError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked());
} }
Value* sass_value = Factory::unwrap(info[1]); Value* sass_value = Factory::unwrap(info[1]);
...@@ -80,11 +80,11 @@ namespace SassTypes ...@@ -80,11 +80,11 @@ namespace SassTypes
NAN_METHOD(List::SetSeparator) { NAN_METHOD(List::SetSeparator) {
if (info.Length() != 1) { if (info.Length() != 1) {
return Nan::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsBoolean()) { if (!info[0]->IsBoolean()) {
return Nan::ThrowError(Nan::New("Supplied value should be a boolean").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a boolean").ToLocalChecked());
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied index should be an integer").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
} }
Sass_Value* map = unwrap(info.This())->value; Sass_Value* map = unwrap(info.This())->value;
...@@ -42,7 +42,7 @@ namespace SassTypes ...@@ -42,7 +42,7 @@ namespace SassTypes
if (index >= sass_map_get_length(map)) { if (index >= sass_map_get_length(map)) {
return Nan::ThrowError(Nan::New("Out of bound index").ToLocalChecked()); return Nan::ThrowRangeError(Nan::New("Out of bound index").ToLocalChecked());
} }
info.GetReturnValue().Set(Factory::create(sass_map_get_value(map, Nan::To<uint32_t>(info[0]).FromJust()))->get_js_object()); info.GetReturnValue().Set(Factory::create(sass_map_get_value(map, Nan::To<uint32_t>(info[0]).FromJust()))->get_js_object());
...@@ -50,15 +50,15 @@ namespace SassTypes ...@@ -50,15 +50,15 @@ namespace SassTypes
NAN_METHOD(Map::SetValue) { NAN_METHOD(Map::SetValue) {
if (info.Length() != 2) { if (info.Length() != 2) {
return Nan::ThrowError(Nan::New("Expected two arguments").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied index should be an integer").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
} }
if (!info[1]->IsObject()) { if (!info[1]->IsObject()) {
return Nan::ThrowError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked());
} }
Value* sass_value = Factory::unwrap(info[1]); Value* sass_value = Factory::unwrap(info[1]);
...@@ -68,11 +68,11 @@ namespace SassTypes ...@@ -68,11 +68,11 @@ namespace SassTypes
NAN_METHOD(Map::GetKey) { NAN_METHOD(Map::GetKey) {
if (info.Length() != 1) { if (info.Length() != 1) {
return Nan::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied index should be an integer").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
} }
Sass_Value* map = unwrap(info.This())->value; Sass_Value* map = unwrap(info.This())->value;
...@@ -80,7 +80,7 @@ namespace SassTypes ...@@ -80,7 +80,7 @@ namespace SassTypes
if (index >= sass_map_get_length(map)) { if (index >= sass_map_get_length(map)) {
return Nan::ThrowError(Nan::New("Out of bound index").ToLocalChecked()); return Nan::ThrowRangeError(Nan::New("Out of bound index").ToLocalChecked());
} }
info.GetReturnValue().Set(Factory::create(sass_map_get_key(map, Nan::To<uint32_t>(info[0]).FromJust()))->get_js_object()); info.GetReturnValue().Set(Factory::create(sass_map_get_key(map, Nan::To<uint32_t>(info[0]).FromJust()))->get_js_object());
...@@ -88,15 +88,15 @@ namespace SassTypes ...@@ -88,15 +88,15 @@ namespace SassTypes
NAN_METHOD(Map::SetKey) { NAN_METHOD(Map::SetKey) {
if (info.Length() != 2) { if (info.Length() != 2) {
return Nan::ThrowError(Nan::New("Expected two arguments").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected two arguments").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied index should be an integer").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied index should be an integer").ToLocalChecked());
} }
if (!info[1]->IsObject()) { if (!info[1]->IsObject()) {
return Nan::ThrowError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a SassValue object").ToLocalChecked());
} }
Value* sass_value = Factory::unwrap(info[1]); Value* sass_value = Factory::unwrap(info[1]);
......
...@@ -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::ThrowError(Nan::New("Cannot instantiate SassNull").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Cannot instantiate SassNull").ToLocalChecked());
} }
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsNumber()) { if (!info[0]->IsNumber()) {
return Nan::ThrowError(Nan::New("Supplied value should be a number").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a number").ToLocalChecked());
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsString()) { if (!info[0]->IsString()) {
return Nan::ThrowError(Nan::New("Supplied value should be a string").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a string").ToLocalChecked());
} }
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::ThrowError(Nan::New("Expected just one argument").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Expected just one argument").ToLocalChecked());
} }
if (!info[0]->IsString()) { if (!info[0]->IsString()) {
return Nan::ThrowError(Nan::New("Supplied value should be a string").ToLocalChecked()); return Nan::ThrowTypeError(Nan::New("Supplied value should be a string").ToLocalChecked());
} }
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