OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 return static_cast<T>(result); | 195 return static_cast<T>(result); |
196 if (configuration == EnforceRange) { | 196 if (configuration == EnforceRange) { |
197 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); | 197 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); |
198 return 0; | 198 return 0; |
199 } | 199 } |
200 result %= LimitsTrait::numberOfValues; | 200 result %= LimitsTrait::numberOfValues; |
201 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); | 201 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); |
202 } | 202 } |
203 | 203 |
204 // Can the value be converted to a number? | 204 // Can the value be converted to a number? |
205 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); | 205 v8::TryCatch block; |
206 v8::Local<v8::Number> numberObject(value->ToNumber()); | |
207 if (block.HasCaught()) { | |
208 exceptionState.rethrowV8Exception(block.Exception()); | |
209 return 0; | |
210 } | |
211 | |
206 if (numberObject.IsEmpty()) { | 212 if (numberObject.IsEmpty()) { |
Jens Widell
2014/09/09 15:06:38
Question: Can this be true? It would be if value->
haraken
2014/09/10 01:09:23
You're right. This should be ASSERT(!numberObject.
Jens Widell
2014/09/10 05:33:57
Done.
| |
207 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'."); | 213 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'."); |
haraken
2014/09/10 01:09:23
Do we want to put this message into the exceptionS
Jens Widell
2014/09/10 04:42:27
Don't know if I understand what you mean. Elaborat
haraken
2014/09/10 04:49:49
Sorry for not being clear.
There are two ways to
| |
208 return 0; | 214 return 0; |
209 } | 215 } |
210 | 216 |
211 if (configuration == EnforceRange) | 217 if (configuration == EnforceRange) |
212 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState); | 218 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState); |
213 | 219 |
214 double numberValue = numberObject->Value(); | 220 double numberValue = numberObject->Value(); |
215 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) | 221 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) |
216 return 0; | 222 return 0; |
217 | 223 |
(...skipping 14 matching lines...) Expand all Loading... | |
232 if (result >= 0 && result <= LimitsTrait::maxValue) | 238 if (result >= 0 && result <= LimitsTrait::maxValue) |
233 return static_cast<T>(result); | 239 return static_cast<T>(result); |
234 if (configuration == EnforceRange) { | 240 if (configuration == EnforceRange) { |
235 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); | 241 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); |
236 return 0; | 242 return 0; |
237 } | 243 } |
238 return static_cast<T>(result); | 244 return static_cast<T>(result); |
239 } | 245 } |
240 | 246 |
241 // Can the value be converted to a number? | 247 // Can the value be converted to a number? |
242 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); | 248 v8::TryCatch block; |
249 v8::Local<v8::Number> numberObject(value->ToNumber()); | |
250 if (block.HasCaught()) { | |
251 exceptionState.rethrowV8Exception(block.Exception()); | |
252 return 0; | |
253 } | |
254 | |
243 if (numberObject.IsEmpty()) { | 255 if (numberObject.IsEmpty()) { |
244 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'."); | 256 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'."); |
245 return 0; | 257 return 0; |
246 } | 258 } |
247 | 259 |
248 if (configuration == EnforceRange) | 260 if (configuration == EnforceRange) |
249 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); | 261 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); |
250 | 262 |
251 // Does the value convert to nan or to an infinity? | 263 // Does the value convert to nan or to an infinity? |
252 double numberValue = numberObject->Value(); | 264 double numberValue = numberObject->Value(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 return toUInt16(value, NormalConversion, exceptionState); | 316 return toUInt16(value, NormalConversion, exceptionState); |
305 } | 317 } |
306 | 318 |
307 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) | 319 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) |
308 { | 320 { |
309 // Fast case. The value is already a 32-bit integer. | 321 // Fast case. The value is already a 32-bit integer. |
310 if (value->IsInt32()) | 322 if (value->IsInt32()) |
311 return value->Int32Value(); | 323 return value->Int32Value(); |
312 | 324 |
313 // Can the value be converted to a number? | 325 // Can the value be converted to a number? |
314 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); | 326 v8::TryCatch block; |
327 v8::Local<v8::Number> numberObject(value->ToNumber()); | |
328 if (block.HasCaught()) { | |
329 exceptionState.rethrowV8Exception(block.Exception()); | |
330 return 0; | |
331 } | |
332 | |
315 if (numberObject.IsEmpty()) { | 333 if (numberObject.IsEmpty()) { |
316 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long'.)"); | 334 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long'.)"); |
317 return 0; | 335 return 0; |
318 } | 336 } |
319 | 337 |
320 if (configuration == EnforceRange) | 338 if (configuration == EnforceRange) |
321 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState); | 339 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState); |
322 | 340 |
323 // Does the value convert to nan or to an infinity? | 341 // Does the value convert to nan or to an infinity? |
324 double numberValue = numberObject->Value(); | 342 double numberValue = numberObject->Value(); |
325 if (std::isnan(numberValue) || std::isinf(numberValue)) | 343 if (std::isnan(numberValue) || std::isinf(numberValue)) |
326 return 0; | 344 return 0; |
327 | 345 |
328 if (configuration == Clamp) | 346 if (configuration == Clamp) |
329 return clampTo<int32_t>(numberObject->Value()); | 347 return clampTo<int32_t>(numberObject->Value()); |
330 | 348 |
331 TONATIVE_DEFAULT_EXCEPTIONSTATE(int32_t, result, numberObject->Int32Value(), exceptionState, 0); | 349 return numberObject->Int32Value(); |
Jens Widell
2014/09/09 15:06:38
I assumed here that since numberObject is a number
| |
332 return result; | |
333 } | 350 } |
334 | 351 |
335 int32_t toInt32(v8::Handle<v8::Value> value) | 352 int32_t toInt32(v8::Handle<v8::Value> value) |
336 { | 353 { |
337 NonThrowableExceptionState exceptionState; | 354 NonThrowableExceptionState exceptionState; |
338 return toInt32(value, NormalConversion, exceptionState); | 355 return toInt32(value, NormalConversion, exceptionState); |
339 } | 356 } |
340 | 357 |
341 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) | 358 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) |
342 { | 359 { |
343 // Fast case. The value is already a 32-bit unsigned integer. | 360 // Fast case. The value is already a 32-bit unsigned integer. |
344 if (value->IsUint32()) | 361 if (value->IsUint32()) |
345 return value->Uint32Value(); | 362 return value->Uint32Value(); |
346 | 363 |
347 // Fast case. The value is a 32-bit signed integer - possibly positive? | 364 // Fast case. The value is a 32-bit signed integer - possibly positive? |
348 if (value->IsInt32()) { | 365 if (value->IsInt32()) { |
349 int32_t result = value->Int32Value(); | 366 int32_t result = value->Int32Value(); |
350 if (result >= 0) | 367 if (result >= 0) |
351 return result; | 368 return result; |
352 if (configuration == EnforceRange) { | 369 if (configuration == EnforceRange) { |
353 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); | 370 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); |
354 return 0; | 371 return 0; |
355 } | 372 } |
356 return result; | 373 return result; |
357 } | 374 } |
358 | 375 |
359 // Can the value be converted to a number? | 376 // Can the value be converted to a number? |
360 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); | 377 v8::TryCatch block; |
378 v8::Local<v8::Number> numberObject(value->ToNumber()); | |
379 if (block.HasCaught()) { | |
380 exceptionState.rethrowV8Exception(block.Exception()); | |
381 return 0; | |
382 } | |
383 | |
361 if (numberObject.IsEmpty()) { | 384 if (numberObject.IsEmpty()) { |
362 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long'.)"); | 385 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long'.)"); |
363 return 0; | 386 return 0; |
364 } | 387 } |
365 | 388 |
366 if (configuration == EnforceRange) | 389 if (configuration == EnforceRange) |
367 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); | 390 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); |
368 | 391 |
369 // Does the value convert to nan or to an infinity? | 392 // Does the value convert to nan or to an infinity? |
370 double numberValue = numberObject->Value(); | 393 double numberValue = numberObject->Value(); |
371 if (std::isnan(numberValue) || std::isinf(numberValue)) | 394 if (std::isnan(numberValue) || std::isinf(numberValue)) |
372 return 0; | 395 return 0; |
373 | 396 |
374 if (configuration == Clamp) | 397 if (configuration == Clamp) |
375 return clampTo<uint32_t>(numberObject->Value()); | 398 return clampTo<uint32_t>(numberObject->Value()); |
376 | 399 |
377 TONATIVE_DEFAULT(uint32_t, result, numberObject->Uint32Value(), 0); | 400 return numberObject->Uint32Value(); |
378 return result; | |
379 } | 401 } |
380 | 402 |
381 uint32_t toUInt32(v8::Handle<v8::Value> value) | 403 uint32_t toUInt32(v8::Handle<v8::Value> value) |
382 { | 404 { |
383 NonThrowableExceptionState exceptionState; | 405 NonThrowableExceptionState exceptionState; |
384 return toUInt32(value, NormalConversion, exceptionState); | 406 return toUInt32(value, NormalConversion, exceptionState); |
385 } | 407 } |
386 | 408 |
387 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) | 409 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) |
388 { | 410 { |
389 // Fast case. The value is a 32-bit integer. | 411 // Fast case. The value is a 32-bit integer. |
390 if (value->IsInt32()) | 412 if (value->IsInt32()) |
391 return value->Int32Value(); | 413 return value->Int32Value(); |
392 | 414 |
393 // Can the value be converted to a number? | 415 // Can the value be converted to a number? |
394 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); | 416 v8::TryCatch block; |
417 v8::Local<v8::Number> numberObject(value->ToNumber()); | |
418 if (block.HasCaught()) { | |
419 exceptionState.rethrowV8Exception(block.Exception()); | |
420 return 0; | |
421 } | |
422 | |
395 if (numberObject.IsEmpty()) { | 423 if (numberObject.IsEmpty()) { |
396 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long long'.)"); | 424 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long long'.)"); |
397 return 0; | 425 return 0; |
398 } | 426 } |
399 | 427 |
400 double x = numberObject->Value(); | 428 double x = numberObject->Value(); |
401 | 429 |
402 if (configuration == EnforceRange) | 430 if (configuration == EnforceRange) |
403 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, "long long", excep tionState); | 431 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, "long long", excep tionState); |
404 | 432 |
(...skipping 25 matching lines...) Expand all Loading... | |
430 if (result >= 0) | 458 if (result >= 0) |
431 return result; | 459 return result; |
432 if (configuration == EnforceRange) { | 460 if (configuration == EnforceRange) { |
433 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); | 461 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); |
434 return 0; | 462 return 0; |
435 } | 463 } |
436 return result; | 464 return result; |
437 } | 465 } |
438 | 466 |
439 // Can the value be converted to a number? | 467 // Can the value be converted to a number? |
440 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); | 468 v8::TryCatch block; |
469 v8::Local<v8::Number> numberObject(value->ToNumber()); | |
470 if (block.HasCaught()) { | |
471 exceptionState.rethrowV8Exception(block.Exception()); | |
472 return 0; | |
473 } | |
474 | |
441 if (numberObject.IsEmpty()) { | 475 if (numberObject.IsEmpty()) { |
442 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long long'.)"); | 476 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long long'.)"); |
443 return 0; | 477 return 0; |
444 } | 478 } |
445 | 479 |
446 double x = numberObject->Value(); | 480 double x = numberObject->Value(); |
447 | 481 |
448 if (configuration == EnforceRange) | 482 if (configuration == EnforceRange) |
449 return enforceRange(x, 0, kJSMaxInteger, "unsigned long long", exception State); | 483 return enforceRange(x, 0, kJSMaxInteger, "unsigned long long", exception State); |
450 | 484 |
451 // Does the value convert to nan or to an infinity? | 485 // Does the value convert to nan or to an infinity? |
452 if (std::isnan(x) || std::isinf(x)) | 486 if (std::isnan(x) || std::isinf(x)) |
453 return 0; | 487 return 0; |
454 | 488 |
455 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 489 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
456 unsigned long long integer; | 490 unsigned long long integer; |
457 doubleToInteger(x, integer); | 491 doubleToInteger(x, integer); |
458 return integer; | 492 return integer; |
459 } | 493 } |
460 | 494 |
461 uint64_t toUInt64(v8::Handle<v8::Value> value) | 495 uint64_t toUInt64(v8::Handle<v8::Value> value) |
462 { | 496 { |
463 NonThrowableExceptionState exceptionState; | 497 NonThrowableExceptionState exceptionState; |
464 return toUInt64(value, NormalConversion, exceptionState); | 498 return toUInt64(value, NormalConversion, exceptionState); |
465 } | 499 } |
466 | 500 |
467 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState) | 501 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
468 { | 502 { |
469 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); | 503 v8::TryCatch block; |
504 v8::Local<v8::Number> numberObject(value->ToNumber()); | |
505 if (block.HasCaught()) { | |
506 exceptionState.rethrowV8Exception(block.Exception()); | |
507 return 0; | |
508 } | |
470 return numberObject->NumberValue(); | 509 return numberObject->NumberValue(); |
471 } | 510 } |
472 | 511 |
473 String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) | 512 String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
474 { | 513 { |
475 // Handle null default value. | 514 // Handle null default value. |
476 if (value.IsEmpty()) | 515 if (value.IsEmpty()) |
477 return String(); | 516 return String(); |
478 | 517 |
479 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString | 518 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString |
480 if (value.IsEmpty()) | 519 if (value.IsEmpty()) |
481 return String(); | 520 return String(); |
482 | 521 |
483 // 1. Let x be ToString(v) | 522 // 1. Let x be ToString(v) |
484 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value-> ToString(), exceptionState, String()); | 523 v8::TryCatch block; |
524 v8::Local<v8::String> stringObject(value->ToString()); | |
525 if (block.HasCaught()) { | |
526 exceptionState.rethrowV8Exception(block.Exception()); | |
527 return String(); | |
528 } | |
529 | |
485 String x = toCoreString(stringObject); | 530 String x = toCoreString(stringObject); |
486 | 531 |
487 // 2. If the value of any element of x is greater than 255, then throw a Typ eError. | 532 // 2. If the value of any element of x is greater than 255, then throw a Typ eError. |
488 if (!x.containsOnlyLatin1()) { | 533 if (!x.containsOnlyLatin1()) { |
489 exceptionState.throwTypeError("Value is not a valid ByteString."); | 534 exceptionState.throwTypeError("Value is not a valid ByteString."); |
490 return String(); | 535 return String(); |
491 } | 536 } |
492 | 537 |
493 // 3. Return an IDL ByteString value whose length is the length of x, and wh ere the | 538 // 3. Return an IDL ByteString value whose length is the length of x, and wh ere the |
494 // value of each element is the value of the corresponding element of x. | 539 // value of each element is the value of the corresponding element of x. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 ASSERT(u.length() == string.length()); | 643 ASSERT(u.length() == string.length()); |
599 return u.toString(); | 644 return u.toString(); |
600 } | 645 } |
601 | 646 |
602 String toScalarValueString(v8::Handle<v8::Value> value, ExceptionState& exceptio nState) | 647 String toScalarValueString(v8::Handle<v8::Value> value, ExceptionState& exceptio nState) |
603 { | 648 { |
604 // From the Encoding standard (with a TODO to move to Web IDL): | 649 // From the Encoding standard (with a TODO to move to Web IDL): |
605 // http://encoding.spec.whatwg.org/#type-scalarvaluestring | 650 // http://encoding.spec.whatwg.org/#type-scalarvaluestring |
606 if (value.IsEmpty()) | 651 if (value.IsEmpty()) |
607 return String(); | 652 return String(); |
608 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value-> ToString(), exceptionState, String()); | 653 |
654 v8::TryCatch block; | |
655 v8::Local<v8::String> stringObject(value->ToString()); | |
656 if (block.HasCaught()) { | |
657 exceptionState.rethrowV8Exception(block.Exception()); | |
658 return String(); | |
659 } | |
609 | 660 |
610 // ScalarValueString is identical to DOMString except that "convert a | 661 // ScalarValueString is identical to DOMString except that "convert a |
611 // DOMString to a sequence of Unicode characters" is used subsequently | 662 // DOMString to a sequence of Unicode characters" is used subsequently |
612 // when converting to an IDL value | 663 // when converting to an IDL value |
613 String x = toCoreString(stringObject); | 664 String x = toCoreString(stringObject); |
614 return replaceUnmatchedSurrogates(x); | 665 return replaceUnmatchedSurrogates(x); |
615 } | 666 } |
616 | 667 |
617 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 668 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
618 { | 669 { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 | 971 |
921 v8::Local<v8::Value> v8IteratorResult(v8::Isolate* isolate, v8::Handle<v8::Value > value) | 972 v8::Local<v8::Value> v8IteratorResult(v8::Isolate* isolate, v8::Handle<v8::Value > value) |
922 { | 973 { |
923 v8::Local<v8::Object> result = v8::Object::New(isolate); | 974 v8::Local<v8::Object> result = v8::Object::New(isolate); |
924 result->Set(v8String(isolate, "value"), value); | 975 result->Set(v8String(isolate, "value"), value); |
925 result->Set(v8String(isolate, "done"), v8Boolean(false, isolate)); | 976 result->Set(v8String(isolate, "done"), v8Boolean(false, isolate)); |
926 return result; | 977 return result; |
927 } | 978 } |
928 | 979 |
929 } // namespace blink | 980 } // namespace blink |
OLD | NEW |