Check option.

This commit is contained in:
Miao Jiang 2013-02-19 21:09:39 +08:00
parent decb16d790
commit 7c776b81a5
2 changed files with 9 additions and 4 deletions

View file

@ -12,9 +12,9 @@
return this.options[option_id] = value;
};
Curl.prototype.setopt = function(ooption, value) {
Curl.prototype.setopt = function(option_name, value) {
var option, option_id;
option = ooption.toUpperCase();
option = option_name.toUpperCase();
if ((option_id = Curl.user_options[option]) != null) {
this.setopt_user_(option_id, value);
} else if ((option_id = Curl.slist_options[option]) != null) {
@ -22,6 +22,9 @@
} else if ((option_id = Curl.integer_options[option]) != null) {
this.setopt_int_(option_id, value >> 0);
} else if ((option_id = Curl.string_options[option]) != null) {
if (value == null) {
throw new Error("Cannot set option " + option_name + " to " + value + ".");
}
this.setopt_str_(option_id, value.toString());
} else {
throw new Error("unsupported option " + option);

View file

@ -6,8 +6,8 @@ catch e
Curl::setopt_user_ = (option_id, value) ->
@options[option_id] = value
Curl::setopt = (ooption, value) ->
option = ooption.toUpperCase()
Curl::setopt = (option_name, value) ->
option = option_name.toUpperCase()
# slist must be at the top of condition
# the option exists in string_options too
@ -18,6 +18,8 @@ Curl::setopt = (ooption, value) ->
else if (option_id = Curl.integer_options[option])?
@setopt_int_ option_id, value >> 0
else if (option_id = Curl.string_options[option])?
if !value?
throw new Error("Cannot set option #{option_name} to #{value}.")
@setopt_str_ option_id, value.toString()
else
throw new Error("unsupported option #{option}")