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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 | 344 |
345 return numberObject->Int32Value(); | 345 return numberObject->Int32Value(); |
346 } | 346 } |
347 | 347 |
348 int32_t toInt32(v8::Handle<v8::Value> value) | 348 int32_t toInt32(v8::Handle<v8::Value> value) |
349 { | 349 { |
350 NonThrowableExceptionState exceptionState; | 350 NonThrowableExceptionState exceptionState; |
351 return toInt32(value, NormalConversion, exceptionState); | 351 return toInt32(value, NormalConversion, exceptionState); |
352 } | 352 } |
353 | 353 |
354 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) | 354 uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio n configuration, ExceptionState& exceptionState) |
355 { | 355 { |
356 // Fast case. The value is already a 32-bit unsigned integer. | 356 ASSERT(!value->IsUint32()); |
357 if (value->IsUint32()) | |
358 return value->Uint32Value(); | |
359 | |
360 // Fast case. The value is a 32-bit signed integer - possibly positive? | |
361 if (value->IsInt32()) { | 357 if (value->IsInt32()) { |
358 ASSERT(configuration != NormalConversion); | |
362 int32_t result = value->Int32Value(); | 359 int32_t result = value->Int32Value(); |
363 if (result >= 0) | 360 if (result >= 0) |
364 return result; | 361 return result; |
365 if (configuration == EnforceRange) { | 362 if (configuration == EnforceRange) { |
366 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); | 363 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); |
367 return 0; | 364 return 0; |
365 } else { | |
Jens Widell
2015/02/24 07:43:09
No need for an else branch here since the if-state
| |
366 ASSERT(configuration == Clamp); | |
367 return clampTo<uint32_t>(result); | |
368 } | 368 } |
369 if (configuration == Clamp) | |
370 return clampTo<uint32_t>(result); | |
371 return result; | |
372 } | 369 } |
373 | 370 |
374 v8::Local<v8::Number> numberObject; | 371 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
375 if (value->IsNumber()) { | 372 // Can the value be converted to a number? |
376 numberObject = value.As<v8::Number>(); | 373 v8::TryCatch block(isolate); |
377 } else { | 374 v8::Local<v8::Number> numberObject = value->ToNumber(isolate); |
378 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 375 if (block.HasCaught()) { |
379 // Can the value be converted to a number? | 376 exceptionState.rethrowV8Exception(block.Exception()); |
380 v8::TryCatch block(isolate); | 377 return 0; |
381 numberObject = value->ToNumber(isolate); | |
382 if (block.HasCaught()) { | |
383 exceptionState.rethrowV8Exception(block.Exception()); | |
384 return 0; | |
385 } | |
386 } | 378 } |
387 ASSERT(!numberObject.IsEmpty()); | 379 ASSERT(!numberObject.IsEmpty()); |
388 | 380 |
389 if (configuration == EnforceRange) | 381 if (configuration == EnforceRange) |
390 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); | 382 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); |
391 | 383 |
392 double numberValue = numberObject->Value(); | 384 double numberValue = numberObject->Value(); |
393 | 385 |
394 if (std::isnan(numberValue)) | 386 if (std::isnan(numberValue)) |
395 return 0; | 387 return 0; |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 attributes->append(value); | 1078 attributes->append(value); |
1087 } | 1079 } |
1088 | 1080 |
1089 AttributesWithSideEffectOnGet::AttributeSet* AttributesWithSideEffectOnGet::attr ibutesWithSideEffectOnGet() | 1081 AttributesWithSideEffectOnGet::AttributeSet* AttributesWithSideEffectOnGet::attr ibutesWithSideEffectOnGet() |
1090 { | 1082 { |
1091 DEFINE_STATIC_LOCAL(AttributeSet, attributes, ()); | 1083 DEFINE_STATIC_LOCAL(AttributeSet, attributes, ()); |
1092 return &attributes; | 1084 return &attributes; |
1093 } | 1085 } |
1094 | 1086 |
1095 } // namespace blink | 1087 } // namespace blink |
OLD | NEW |