| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ExceptionContext& context, ExceptionState& es) | 229 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ExceptionContext& context, ExceptionState& es) |
| 230 { | 230 { |
| 231 if (!raw.get(propertyName, array) || !array) { | 231 if (!raw.get(propertyName, array) || !array) { |
| 232 es.throwTypeError(context.toString(propertyName, "Missing or not a Uint8
Array")); | 232 es.throwTypeError(context.toString(propertyName, "Missing or not a Uint8
Array")); |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 return true; | 235 return true; |
| 236 } | 236 } |
| 237 | 237 |
| 238 bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
double minValue, double maxValue, const ExceptionContext& context, ExceptionStat
e& es) | 238 // Gets an integer according to WebIDL's [EnforceRange]. |
| 239 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ExceptionCont
ext& context, ExceptionState& es) |
| 239 { | 240 { |
| 240 double number; | 241 double number; |
| 241 if (!raw.get(propertyName, number)) { | 242 bool ok = raw.get(propertyName, number, hasProperty); |
| 242 es.throwTypeError(context.toString(propertyName, "Missing or not a numbe
r")); | |
| 243 return false; | |
| 244 } | |
| 245 | 243 |
| 246 // Convert to an integer according to WebIDL's [EnforceRange]. | 244 if (!hasProperty) |
| 247 if (std::isinf(number) || std::isnan(number)) { | 245 return true; |
| 248 es.throwTypeError(context.toString(propertyName, "Outside of numeric ran
ge")); | 246 |
| 247 if (!ok || std::isnan(number)) { |
| 248 es.throwTypeError(context.toString(propertyName, "Is not a number")); |
| 249 return false; | 249 return false; |
| 250 } | 250 } |
| 251 | 251 |
| 252 number = trunc(number); | 252 number = trunc(number); |
| 253 | 253 |
| 254 if (number < minValue || number > maxValue) { | 254 if (std::isinf(number) || number < minValue || number > maxValue) { |
| 255 es.throwTypeError(context.toString(propertyName, "Outside of numeric ran
ge")); | 255 es.throwTypeError(context.toString(propertyName, "Outside of numeric ran
ge")); |
| 256 return false; | 256 return false; |
| 257 } | 257 } |
| 258 | 258 |
| 259 value = number; | 259 value = number; |
| 260 return true; | 260 return true; |
| 261 } | 261 } |
| 262 | 262 |
| 263 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asValue, double& value, double minValue, double maxValue, const ExceptionContext
& context, ExceptionState& es) | 263 bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
double minValue, double maxValue, const ExceptionContext& context, ExceptionStat
e& es) |
| 264 { | 264 { |
| 265 double number; | 265 bool hasProperty; |
| 266 if (!raw.get(propertyName, number)) { | 266 if (!getOptionalInteger(raw, propertyName, hasProperty, value, minValue, max
Value, context, es)) |
| 267 // FIXME: If the property exists but is NOT a number, should fail. | 267 return false; |
| 268 hasValue = false; | 268 |
| 269 return true; | 269 if (!hasProperty) { |
| 270 es.throwTypeError(context.toString(propertyName, "Missing required prope
rty")); |
| 271 return false; |
| 270 } | 272 } |
| 271 | 273 |
| 272 hasValue = true; | 274 return true; |
| 273 return getInteger(raw, propertyName, value, minValue, maxValue, context, es)
; | |
| 274 } | 275 } |
| 275 | 276 |
| 276 bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value,
const ExceptionContext& context, ExceptionState& es) | 277 bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value,
const ExceptionContext& context, ExceptionState& es) |
| 277 { | 278 { |
| 278 double number; | 279 double number; |
| 279 if (!getInteger(raw, propertyName, number, 0, 0xFFFFFFFF, context, es)) | 280 if (!getInteger(raw, propertyName, number, 0, 0xFFFFFFFF, context, es)) |
| 280 return false; | 281 return false; |
| 281 value = number; | 282 value = number; |
| 282 return true; | 283 return true; |
| 283 } | 284 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 return true; | 351 return true; |
| 351 } | 352 } |
| 352 | 353 |
| 353 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithm
Params>& params, const ExceptionContext& context, ExceptionState& es) | 354 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithm
Params>& params, const ExceptionContext& context, ExceptionState& es) |
| 354 { | 355 { |
| 355 WebKit::WebCryptoAlgorithm hash; | 356 WebKit::WebCryptoAlgorithm hash; |
| 356 if (!parseHash(raw, hash, context, es)) | 357 if (!parseHash(raw, hash, context, es)) |
| 357 return false; | 358 return false; |
| 358 | 359 |
| 359 bool hasLength; | 360 bool hasLength; |
| 360 uint32_t length; | 361 uint32_t length = 0; |
| 361 if (!getOptionalUint32(raw, "length", hasLength, length, context, es)) | 362 if (!getOptionalUint32(raw, "length", hasLength, length, context, es)) |
| 362 return false; | 363 return false; |
| 363 | 364 |
| 364 params = adoptPtr(new WebKit::WebCryptoHmacKeyParams(hash, hasLength, length
)); | 365 params = adoptPtr(new WebKit::WebCryptoHmacKeyParams(hash, hasLength, length
)); |
| 365 return true; | 366 return true; |
| 366 } | 367 } |
| 367 | 368 |
| 368 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) | 369 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) |
| 369 { | 370 { |
| 370 WebKit::WebCryptoAlgorithm hash; | 371 WebKit::WebCryptoAlgorithm hash; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 467 } |
| 467 | 468 |
| 468 } // namespace | 469 } // namespace |
| 469 | 470 |
| 470 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionState& es) | 471 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionState& es) |
| 471 { | 472 { |
| 472 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); | 473 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); |
| 473 } | 474 } |
| 474 | 475 |
| 475 } // namespace WebCore | 476 } // namespace WebCore |
| OLD | NEW |