make 'cancel' function in FileSource optional

update README
This commit is contained in:
Mike Morris
2015-08-04 14:50:04 -04:00
parent 84a1e6d1c3
commit d3104756af
7 changed files with 93 additions and 107 deletions

View File

@@ -61,17 +61,17 @@ NAN_METHOD(NodeMap::New) {
}
if (args.Length() < 1 || !args[0]->IsObject()) {
return NanThrowTypeError("Requires FileSource options as first argument");
return NanThrowTypeError("Requires an options object as first argument");
}
auto options = args[0]->ToObject();
// Check that request() and cancel() are defined.
if (!options->Has(NanNew("request")) || !options->Get(NanNew("request"))->IsFunction()) {
return NanThrowError("FileSource options must have a request member function");
return NanThrowError("Options object must have a 'request' method");
}
if (!options->Has(NanNew("cancel")) || !options->Get(NanNew("cancel"))->IsFunction()) {
return NanThrowError("FileSource options must have a cancel member function");
if (options->Has(NanNew("cancel")) && !options->Get(NanNew("cancel"))->IsFunction()) {
return NanThrowError("Options object 'cancel' property must be a function");
}
try {