Make throwing exception when parsing args easier
This commit is contained in:
parent
12f4e9b7ea
commit
c5b39126ee
2 changed files with 14 additions and 5 deletions
|
@ -32,17 +32,25 @@ v8::Handle<v8::Value> Arguments::PeekNext() const {
|
||||||
return (*info_)[next_];
|
return (*info_)[next_];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Arguments::ThrowError() const {
|
v8::Handle<v8::Value> Arguments::ThrowError() const {
|
||||||
if (insufficient_arguments_)
|
if (insufficient_arguments_)
|
||||||
return ThrowTypeError("Insufficient number of arguments.");
|
return ThrowTypeError("Insufficient number of arguments.");
|
||||||
|
|
||||||
ThrowTypeError(base::StringPrintf(
|
return ThrowTypeError(base::StringPrintf(
|
||||||
"Error processing argument %d.", next_ - 1));
|
"Error processing argument %d.", next_ - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Arguments::ThrowTypeError(const std::string& message) const {
|
v8::Handle<v8::Value> Arguments::ThrowError(const std::string& message) const {
|
||||||
|
MATE_THROW_EXCEPTION(isolate_, v8::Exception::Error(
|
||||||
|
StringToV8(isolate_, message)));
|
||||||
|
return MATE_UNDEFINED(isolate_);
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::Handle<v8::Value> Arguments::ThrowTypeError(
|
||||||
|
const std::string& message) const {
|
||||||
MATE_THROW_EXCEPTION(isolate_, v8::Exception::TypeError(
|
MATE_THROW_EXCEPTION(isolate_, v8::Exception::TypeError(
|
||||||
StringToV8(isolate_, message)));
|
StringToV8(isolate_, message)));
|
||||||
|
return MATE_UNDEFINED(isolate_);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
|
@ -73,8 +73,9 @@ class Arguments {
|
||||||
|
|
||||||
v8::Handle<v8::Value> PeekNext() const;
|
v8::Handle<v8::Value> PeekNext() const;
|
||||||
|
|
||||||
void ThrowError() const;
|
v8::Handle<v8::Value> ThrowError() const;
|
||||||
void ThrowTypeError(const std::string& message) const;
|
v8::Handle<v8::Value> ThrowError(const std::string& message) const;
|
||||||
|
v8::Handle<v8::Value> ThrowTypeError(const std::string& message) const;
|
||||||
|
|
||||||
v8::Isolate* isolate() const { return isolate_; }
|
v8::Isolate* isolate() const { return isolate_; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue