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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 struct IntTypeLimits<uint16_t> { | 170 struct IntTypeLimits<uint16_t> { |
171 static const unsigned short maxValue = 65535; | 171 static const unsigned short maxValue = 65535; |
172 static const unsigned numberOfValues = 65536; // 2^16 | 172 static const unsigned numberOfValues = 65536; // 2^16 |
173 }; | 173 }; |
174 | 174 |
175 template <typename T> | 175 template <typename T> |
176 static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi guration configuration, const char* typeName, ExceptionState& exceptionState) | 176 static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi guration configuration, const char* typeName, ExceptionState& exceptionState) |
177 { | 177 { |
178 typedef IntTypeLimits<T> LimitsTrait; | 178 typedef IntTypeLimits<T> LimitsTrait; |
179 | 179 |
180 v8::Isolate* isolate = exceptionState.isolate(); | |
181 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
180 // Fast case. The value is already a 32-bit integer in the right range. | 182 // Fast case. The value is already a 32-bit integer in the right range. |
181 if (value->IsInt32()) { | 183 if (value->IsInt32()) { |
182 int32_t result = value->Int32Value(); | 184 int32_t result; |
bashi
2015/03/11 10:30:37
As seen below, there are some code which look almo
| |
185 if (!getValueFromMaybe(value->Int32Value(context), result)) { | |
186 exceptionState.throwTypeError("Cannot convert to a 32 bit integer.") ; | |
187 return 0; | |
188 } | |
183 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) | 189 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) |
184 return static_cast<T>(result); | 190 return static_cast<T>(result); |
185 if (configuration == EnforceRange) { | 191 if (configuration == EnforceRange) { |
186 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); | 192 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); |
187 return 0; | 193 return 0; |
188 } | 194 } |
189 if (configuration == Clamp) | 195 if (configuration == Clamp) |
190 return clampTo<T>(result); | 196 return clampTo<T>(result); |
191 result %= LimitsTrait::numberOfValues; | 197 result %= LimitsTrait::numberOfValues; |
192 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); | 198 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); |
193 } | 199 } |
194 | 200 |
195 v8::Local<v8::Number> numberObject; | 201 v8::Local<v8::Number> numberObject; |
196 if (value->IsNumber()) { | 202 if (value->IsNumber()) { |
197 numberObject = value.As<v8::Number>(); | 203 numberObject = value.As<v8::Number>(); |
198 } else { | 204 } else { |
199 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
200 // Can the value be converted to a number? | 205 // Can the value be converted to a number? |
201 v8::TryCatch block(isolate); | 206 v8::TryCatch block(isolate); |
202 numberObject = value->ToNumber(isolate); | 207 if (!value->ToNumber(context).ToLocal(&numberObject)) { |
Yuki
2015/03/11 13:11:53
It looks to me that either of ToNumber or ToLocal
| |
203 if (block.HasCaught()) { | 208 if (block.HasCaught()) |
204 exceptionState.rethrowV8Exception(block.Exception()); | 209 exceptionState.rethrowV8Exception(block.Exception()); |
210 else | |
211 exceptionState.throwTypeError("Cannot convert to a number."); | |
205 return 0; | 212 return 0; |
206 } | 213 } |
207 } | 214 } |
208 ASSERT(!numberObject.IsEmpty()); | 215 ASSERT(!numberObject.IsEmpty()); |
209 | 216 |
210 if (configuration == EnforceRange) | 217 if (configuration == EnforceRange) |
211 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState); | 218 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState); |
212 | 219 |
213 double numberValue = numberObject->Value(); | 220 double numberValue = numberObject->Value(); |
214 if (std::isnan(numberValue) || !numberValue) | 221 if (std::isnan(numberValue) || !numberValue) |
215 return 0; | 222 return 0; |
216 | 223 |
217 if (configuration == Clamp) | 224 if (configuration == Clamp) |
218 return clampTo<T>(numberValue); | 225 return clampTo<T>(numberValue); |
219 | 226 |
220 if (std::isinf(numberValue)) | 227 if (std::isinf(numberValue)) |
221 return 0; | 228 return 0; |
222 | 229 |
223 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue)); | 230 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue)); |
224 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); | 231 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); |
225 | 232 |
226 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue); | 233 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue); |
227 } | 234 } |
228 | 235 |
229 template <typename T> | 236 template <typename T> |
230 static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf iguration configuration, const char* typeName, ExceptionState& exceptionState) | 237 static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf iguration configuration, const char* typeName, ExceptionState& exceptionState) |
231 { | 238 { |
232 typedef IntTypeLimits<T> LimitsTrait; | 239 typedef IntTypeLimits<T> LimitsTrait; |
233 | 240 |
241 v8::Isolate* isolate = exceptionState.isolate(); | |
242 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
234 // Fast case. The value is a 32-bit signed integer - possibly positive? | 243 // Fast case. The value is a 32-bit signed integer - possibly positive? |
235 if (value->IsInt32()) { | 244 if (value->IsInt32()) { |
236 int32_t result = value->Int32Value(); | 245 int32_t result = value->Int32Value(); |
246 if (!getValueFromMaybe(value->Int32Value(context), result)) { | |
247 exceptionState.throwTypeError("Cannot convert to a 32 bit integer.") ; | |
248 return 0; | |
249 } | |
237 if (result >= 0 && result <= LimitsTrait::maxValue) | 250 if (result >= 0 && result <= LimitsTrait::maxValue) |
238 return static_cast<T>(result); | 251 return static_cast<T>(result); |
239 if (configuration == EnforceRange) { | 252 if (configuration == EnforceRange) { |
240 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); | 253 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); |
241 return 0; | 254 return 0; |
242 } | 255 } |
243 if (configuration == Clamp) | 256 if (configuration == Clamp) |
244 return clampTo<T>(result); | 257 return clampTo<T>(result); |
245 return static_cast<T>(result); | 258 return static_cast<T>(result); |
246 } | 259 } |
247 | 260 |
248 v8::Local<v8::Number> numberObject; | 261 v8::Local<v8::Number> numberObject; |
249 if (value->IsNumber()) { | 262 if (value->IsNumber()) { |
250 numberObject = value.As<v8::Number>(); | 263 numberObject = value.As<v8::Number>(); |
251 } else { | 264 } else { |
252 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
253 // Can the value be converted to a number? | 265 // Can the value be converted to a number? |
254 v8::TryCatch block(isolate); | 266 v8::TryCatch block(isolate); |
255 numberObject = value->ToNumber(isolate); | 267 if (!value->ToNumber(context).ToLocal(&numberObject)) { |
256 if (block.HasCaught()) { | 268 if (block.HasCaught()) |
257 exceptionState.rethrowV8Exception(block.Exception()); | 269 exceptionState.rethrowV8Exception(block.Exception()); |
270 else | |
271 exceptionState.throwTypeError("Cannot convert to a number."); | |
258 return 0; | 272 return 0; |
259 } | 273 } |
260 } | 274 } |
261 ASSERT(!numberObject.IsEmpty()); | 275 ASSERT(!numberObject.IsEmpty()); |
262 | 276 |
263 if (configuration == EnforceRange) | 277 if (configuration == EnforceRange) |
264 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); | 278 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); |
265 | 279 |
266 double numberValue = numberObject->Value(); | 280 double numberValue = numberObject->Value(); |
267 | 281 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 } | 331 } |
318 | 332 |
319 uint16_t toUInt16(v8::Handle<v8::Value> value) | 333 uint16_t toUInt16(v8::Handle<v8::Value> value) |
320 { | 334 { |
321 NonThrowableExceptionState exceptionState; | 335 NonThrowableExceptionState exceptionState; |
322 return toUInt16(value, NormalConversion, exceptionState); | 336 return toUInt16(value, NormalConversion, exceptionState); |
323 } | 337 } |
324 | 338 |
325 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) | 339 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) |
326 { | 340 { |
341 v8::Isolate* isolate = exceptionState.isolate(); | |
342 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
327 // Fast case. The value is already a 32-bit integer. | 343 // Fast case. The value is already a 32-bit integer. |
328 if (value->IsInt32()) | 344 if (value->IsInt32()) { |
329 return value->Int32Value(); | 345 int32_t result; |
346 if (!getValueFromMaybe(value->Int32Value(context), result)) { | |
347 exceptionState.throwTypeError("Cannot convert to a 32 bit integer.") ; | |
348 return 0; | |
349 } | |
350 return result; | |
351 } | |
330 | 352 |
331 v8::Local<v8::Number> numberObject; | 353 v8::Local<v8::Number> numberObject; |
332 if (value->IsNumber()) { | 354 if (value->IsNumber()) { |
333 numberObject = value.As<v8::Number>(); | 355 numberObject = value.As<v8::Number>(); |
334 } else { | 356 } else { |
335 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
336 // Can the value be converted to a number? | 357 // Can the value be converted to a number? |
337 v8::TryCatch block(isolate); | 358 v8::TryCatch block(isolate); |
338 numberObject = value->ToNumber(isolate); | 359 if (!value->ToNumber(context).ToLocal(&numberObject)) { |
339 if (block.HasCaught()) { | 360 if (block.HasCaught()) |
340 exceptionState.rethrowV8Exception(block.Exception()); | 361 exceptionState.rethrowV8Exception(block.Exception()); |
362 else | |
363 exceptionState.throwTypeError("Cannot convert to a number."); | |
341 return 0; | 364 return 0; |
342 } | 365 } |
343 } | 366 } |
344 ASSERT(!numberObject.IsEmpty()); | 367 ASSERT(!numberObject.IsEmpty()); |
345 | 368 |
346 if (configuration == EnforceRange) | 369 if (configuration == EnforceRange) |
347 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState); | 370 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState); |
348 | 371 |
349 double numberValue = numberObject->Value(); | 372 double numberValue = numberObject->Value(); |
350 | 373 |
351 if (std::isnan(numberValue)) | 374 if (std::isnan(numberValue)) |
352 return 0; | 375 return 0; |
353 | 376 |
354 if (configuration == Clamp) | 377 if (configuration == Clamp) |
355 return clampTo<int32_t>(numberValue); | 378 return clampTo<int32_t>(numberValue); |
356 | 379 |
357 if (std::isinf(numberValue)) | 380 if (std::isinf(numberValue)) |
358 return 0; | 381 return 0; |
359 | 382 |
360 return numberObject->Int32Value(); | 383 int32_t result; |
384 if (!getValueFromMaybe(numberObject->Int32Value(context), result)) { | |
385 exceptionState.throwTypeError("Cannot convert to a 32 bit integer."); | |
386 return 0; | |
387 } | |
388 return result; | |
361 } | 389 } |
362 | 390 |
363 int32_t toInt32(v8::Handle<v8::Value> value) | 391 int32_t toInt32(v8::Handle<v8::Value> value) |
364 { | 392 { |
365 NonThrowableExceptionState exceptionState; | 393 NonThrowableExceptionState exceptionState; |
366 return toInt32(value, NormalConversion, exceptionState); | 394 return toInt32(value, NormalConversion, exceptionState); |
367 } | 395 } |
368 | 396 |
369 uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio n configuration, ExceptionState& exceptionState) | 397 uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio n configuration, ExceptionState& exceptionState) |
370 { | 398 { |
371 ASSERT(!value->IsUint32()); | 399 ASSERT(!value->IsUint32()); |
400 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
401 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
372 if (value->IsInt32()) { | 402 if (value->IsInt32()) { |
373 ASSERT(configuration != NormalConversion); | 403 ASSERT(configuration != NormalConversion); |
374 int32_t result = value->Int32Value(); | 404 int32_t result; |
405 if (!getValueFromMaybe(value->Int32Value(context), result)) { | |
406 exceptionState.throwTypeError("Cannot convert to a 32 bit integer.") ; | |
407 return 0; | |
408 } | |
375 if (result >= 0) | 409 if (result >= 0) |
376 return result; | 410 return result; |
377 if (configuration == EnforceRange) { | 411 if (configuration == EnforceRange) { |
378 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); | 412 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); |
379 return 0; | 413 return 0; |
380 } | 414 } |
381 ASSERT(configuration == Clamp); | 415 ASSERT(configuration == Clamp); |
382 return clampTo<uint32_t>(result); | 416 return clampTo<uint32_t>(result); |
383 } | 417 } |
384 | 418 |
385 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
386 // Can the value be converted to a number? | 419 // Can the value be converted to a number? |
387 v8::TryCatch block(isolate); | 420 v8::TryCatch block(isolate); |
388 v8::Local<v8::Number> numberObject = value->ToNumber(isolate); | 421 v8::Local<v8::Number> numberObject; |
389 if (block.HasCaught()) { | 422 if (!value->ToNumber(context).ToLocal(&numberObject)) { |
390 exceptionState.rethrowV8Exception(block.Exception()); | 423 if (block.HasCaught()) |
424 exceptionState.rethrowV8Exception(block.Exception()); | |
425 else | |
426 exceptionState.throwTypeError("Cannot convert to a number."); | |
391 return 0; | 427 return 0; |
392 } | 428 } |
393 ASSERT(!numberObject.IsEmpty()); | 429 ASSERT(!numberObject.IsEmpty()); |
394 | 430 |
395 if (configuration == EnforceRange) | 431 if (configuration == EnforceRange) |
396 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); | 432 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); |
397 | 433 |
398 double numberValue = numberObject->Value(); | 434 double numberValue = numberObject->Value(); |
399 | 435 |
400 if (std::isnan(numberValue)) | 436 if (std::isnan(numberValue)) |
401 return 0; | 437 return 0; |
402 | 438 |
403 if (configuration == Clamp) | 439 if (configuration == Clamp) |
404 return clampTo<uint32_t>(numberValue); | 440 return clampTo<uint32_t>(numberValue); |
405 | 441 |
406 if (std::isinf(numberValue)) | 442 if (std::isinf(numberValue)) |
407 return 0; | 443 return 0; |
408 | 444 |
409 return numberObject->Uint32Value(); | 445 uint32_t result; |
446 if (!getValueFromMaybe(numberObject->Uint32Value(context), result)) { | |
447 exceptionState.throwTypeError("Cannot convert to a 32 bit unsigned integ er."); | |
448 return 0; | |
449 } | |
450 return result; | |
410 } | 451 } |
411 | 452 |
412 uint32_t toUInt32(v8::Handle<v8::Value> value) | 453 uint32_t toUInt32(v8::Handle<v8::Value> value) |
413 { | 454 { |
414 NonThrowableExceptionState exceptionState; | 455 NonThrowableExceptionState exceptionState; |
415 return toUInt32(value, NormalConversion, exceptionState); | 456 return toUInt32(value, NormalConversion, exceptionState); |
416 } | 457 } |
417 | 458 |
418 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) | 459 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) |
419 { | 460 { |
420 // Clamping not supported for int64_t/long long int. See Source/wtf/MathExtr as.h. | 461 // Clamping not supported for int64_t/long long int. See Source/wtf/MathExtr as.h. |
421 ASSERT(configuration != Clamp); | 462 ASSERT(configuration != Clamp); |
422 | 463 |
464 v8::Isolate* isolate = exceptionState.isolate(); | |
465 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
423 // Fast case. The value is a 32-bit integer. | 466 // Fast case. The value is a 32-bit integer. |
424 if (value->IsInt32()) | 467 if (value->IsInt32()) { |
425 return value->Int32Value(); | 468 int32_t result; |
469 if (!getValueFromMaybe(value->Int32Value(context), result)) { | |
470 exceptionState.throwTypeError("Cannot convert to a 32 bit integer.") ; | |
471 return 0; | |
472 } | |
473 return result; | |
474 } | |
426 | 475 |
427 v8::Local<v8::Number> numberObject; | 476 v8::Local<v8::Number> numberObject; |
428 if (value->IsNumber()) { | 477 if (value->IsNumber()) { |
429 numberObject = value.As<v8::Number>(); | 478 numberObject = value.As<v8::Number>(); |
430 } else { | 479 } else { |
431 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
432 // Can the value be converted to a number? | 480 // Can the value be converted to a number? |
433 v8::TryCatch block(isolate); | 481 v8::TryCatch block(isolate); |
434 numberObject = value->ToNumber(isolate); | 482 if (!value->ToNumber(context).ToLocal(&numberObject)) { |
435 if (block.HasCaught()) { | 483 if (block.HasCaught()) |
436 exceptionState.rethrowV8Exception(block.Exception()); | 484 exceptionState.rethrowV8Exception(block.Exception()); |
485 else | |
486 exceptionState.throwTypeError("Cannot convert to a number."); | |
437 return 0; | 487 return 0; |
438 } | 488 } |
439 } | 489 } |
440 ASSERT(!numberObject.IsEmpty()); | 490 ASSERT(!numberObject.IsEmpty()); |
441 | 491 |
442 double numberValue = numberObject->Value(); | 492 double numberValue = numberObject->Value(); |
443 | 493 |
444 if (configuration == EnforceRange) | 494 if (configuration == EnforceRange) |
445 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo ng", exceptionState); | 495 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo ng", exceptionState); |
446 | 496 |
447 if (std::isnan(numberValue) || std::isinf(numberValue)) | 497 if (std::isnan(numberValue) || std::isinf(numberValue)) |
448 return 0; | 498 return 0; |
449 | 499 |
450 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 500 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
451 unsigned long long integer; | 501 unsigned long long integer; |
452 doubleToInteger(numberValue, integer); | 502 doubleToInteger(numberValue, integer); |
453 return integer; | 503 return integer; |
454 } | 504 } |
455 | 505 |
456 int64_t toInt64(v8::Handle<v8::Value> value) | 506 int64_t toInt64(v8::Handle<v8::Value> value) |
457 { | 507 { |
458 NonThrowableExceptionState exceptionState; | 508 NonThrowableExceptionState exceptionState; |
459 return toInt64(value, NormalConversion, exceptionState); | 509 return toInt64(value, NormalConversion, exceptionState); |
460 } | 510 } |
461 | 511 |
462 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) | 512 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) |
463 { | 513 { |
514 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
515 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
516 | |
464 // Fast case. The value is a 32-bit unsigned integer. | 517 // Fast case. The value is a 32-bit unsigned integer. |
465 if (value->IsUint32()) | 518 if (value->IsUint32()) { |
466 return value->Uint32Value(); | 519 uint32_t result; |
520 if (!getValueFromMaybe(value->Uint32Value(context), result)) { | |
521 exceptionState.throwTypeError("Cannot convert to a 32 bit unsigned i nteger."); | |
522 return 0; | |
523 } | |
524 return result; | |
525 } | |
467 | 526 |
468 // Fast case. The value is a 32-bit integer. | 527 // Fast case. The value is a 32-bit integer. |
469 if (value->IsInt32()) { | 528 if (value->IsInt32()) { |
470 int32_t result = value->Int32Value(); | 529 int32_t result; |
530 if (!getValueFromMaybe(value->Int32Value(context), result)) { | |
531 exceptionState.throwTypeError("Cannot convert to a 32 bit integer.") ; | |
532 return 0; | |
533 } | |
471 if (result >= 0) | 534 if (result >= 0) |
472 return result; | 535 return result; |
473 if (configuration == EnforceRange) { | 536 if (configuration == EnforceRange) { |
474 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); | 537 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); |
475 return 0; | 538 return 0; |
476 } | 539 } |
477 if (configuration == Clamp) | 540 if (configuration == Clamp) |
478 return clampTo<uint64_t>(result); | 541 return clampTo<uint64_t>(result); |
479 return result; | 542 return result; |
480 } | 543 } |
481 | 544 |
482 v8::Local<v8::Number> numberObject; | 545 v8::Local<v8::Number> numberObject; |
483 if (value->IsNumber()) { | 546 if (value->IsNumber()) { |
484 numberObject = value.As<v8::Number>(); | 547 numberObject = value.As<v8::Number>(); |
485 } else { | 548 } else { |
486 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
487 // Can the value be converted to a number? | 549 // Can the value be converted to a number? |
488 v8::TryCatch block(isolate); | 550 v8::TryCatch block(isolate); |
489 numberObject = value->ToNumber(isolate); | 551 if (!value->ToNumber(context).ToLocal(&numberObject)) { |
490 if (block.HasCaught()) { | 552 if (block.HasCaught()) |
491 exceptionState.rethrowV8Exception(block.Exception()); | 553 exceptionState.rethrowV8Exception(block.Exception()); |
554 else | |
555 exceptionState.throwTypeError("Cannot convert to a number."); | |
492 return 0; | 556 return 0; |
493 } | 557 } |
494 } | 558 } |
495 ASSERT(!numberObject.IsEmpty()); | 559 ASSERT(!numberObject.IsEmpty()); |
496 | 560 |
497 double numberValue = numberObject->Value(); | 561 double numberValue = numberObject->Value(); |
498 | 562 |
499 if (configuration == EnforceRange) | 563 if (configuration == EnforceRange) |
500 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long", exceptionState); | 564 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long", exceptionState); |
501 | 565 |
(...skipping 26 matching lines...) Expand all Loading... | |
528 if (!std::isfinite(numberValue)) { | 592 if (!std::isfinite(numberValue)) { |
529 exceptionState.throwTypeError("The provided float value is non-finite.") ; | 593 exceptionState.throwTypeError("The provided float value is non-finite.") ; |
530 return 0; | 594 return 0; |
531 } | 595 } |
532 return numberValue; | 596 return numberValue; |
533 } | 597 } |
534 | 598 |
535 double toDoubleSlow(v8::Handle<v8::Value> value, ExceptionState& exceptionState) | 599 double toDoubleSlow(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
536 { | 600 { |
537 ASSERT(!value->IsNumber()); | 601 ASSERT(!value->IsNumber()); |
538 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 602 v8::Isolate* isolate = exceptionState.isolate(); |
539 v8::TryCatch block(isolate); | 603 v8::TryCatch block(isolate); |
540 double doubleValue = value->NumberValue(); | 604 double doubleValue; |
541 if (block.HasCaught()) { | 605 if (!getValueFromMaybe(value->NumberValue(isolate->GetCurrentContext()), dou bleValue)) { |
542 exceptionState.rethrowV8Exception(block.Exception()); | 606 if (block.HasCaught()) |
607 exceptionState.rethrowV8Exception(block.Exception()); | |
608 else | |
609 exceptionState.throwTypeError("Cannot convert to a number."); | |
543 return 0; | 610 return 0; |
544 } | 611 } |
545 return doubleValue; | 612 return doubleValue; |
546 } | 613 } |
547 | 614 |
548 double toRestrictedDouble(v8::Handle<v8::Value> value, ExceptionState& exception State) | 615 double toRestrictedDouble(v8::Handle<v8::Value> value, ExceptionState& exception State) |
549 { | 616 { |
550 double numberValue = toDouble(value, exceptionState); | 617 double numberValue = toDouble(value, exceptionState); |
551 if (exceptionState.hadException()) | 618 if (exceptionState.hadException()) |
552 return 0; | 619 return 0; |
(...skipping 12 matching lines...) Expand all Loading... | |
565 | 632 |
566 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString | 633 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString |
567 if (value.IsEmpty()) | 634 if (value.IsEmpty()) |
568 return String(); | 635 return String(); |
569 | 636 |
570 // 1. Let x be ToString(v) | 637 // 1. Let x be ToString(v) |
571 v8::Local<v8::String> stringObject; | 638 v8::Local<v8::String> stringObject; |
572 if (value->IsString()) { | 639 if (value->IsString()) { |
573 stringObject = value.As<v8::String>(); | 640 stringObject = value.As<v8::String>(); |
574 } else { | 641 } else { |
575 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 642 v8::Isolate* isolate = exceptionState.isolate(); |
576 v8::TryCatch block(isolate); | 643 v8::TryCatch block(isolate); |
577 stringObject = value->ToString(isolate); | 644 stringObject = value->ToString(isolate); |
578 if (block.HasCaught()) { | 645 if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&stringObject )) { |
579 exceptionState.rethrowV8Exception(block.Exception()); | 646 if (block.HasCaught()) |
647 exceptionState.rethrowV8Exception(block.Exception()); | |
648 else | |
649 exceptionState.throwTypeError("Cannot convert to a string."); | |
580 return String(); | 650 return String(); |
581 } | 651 } |
582 } | 652 } |
583 | 653 |
584 String x = toCoreString(stringObject); | 654 String x = toCoreString(stringObject); |
585 | 655 |
586 // 2. If the value of any element of x is greater than 255, then throw a Typ eError. | 656 // 2. If the value of any element of x is greater than 255, then throw a Typ eError. |
587 if (!x.containsOnlyLatin1()) { | 657 if (!x.containsOnlyLatin1()) { |
588 exceptionState.throwTypeError("Value is not a valid ByteString."); | 658 exceptionState.throwTypeError("Value is not a valid ByteString."); |
589 return String(); | 659 return String(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 String toUSVString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) | 771 String toUSVString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
702 { | 772 { |
703 // http://heycam.github.io/webidl/#es-USVString | 773 // http://heycam.github.io/webidl/#es-USVString |
704 if (value.IsEmpty()) | 774 if (value.IsEmpty()) |
705 return String(); | 775 return String(); |
706 | 776 |
707 v8::Local<v8::String> stringObject; | 777 v8::Local<v8::String> stringObject; |
708 if (value->IsString()) { | 778 if (value->IsString()) { |
709 stringObject = value.As<v8::String>(); | 779 stringObject = value.As<v8::String>(); |
710 } else { | 780 } else { |
711 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 781 v8::Isolate* isolate = exceptionState.isolate(); |
712 v8::TryCatch block(isolate); | 782 v8::TryCatch block(isolate); |
713 stringObject = value->ToString(isolate); | 783 stringObject = value->ToString(isolate); |
784 if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&stringObject )) { | |
785 exceptionState.throwTypeError("Cannot convert to a string."); | |
786 return String(); | |
787 } | |
714 if (block.HasCaught()) { | 788 if (block.HasCaught()) { |
715 exceptionState.rethrowV8Exception(block.Exception()); | 789 exceptionState.rethrowV8Exception(block.Exception()); |
716 return String(); | 790 return String(); |
717 } | 791 } |
718 } | 792 } |
719 | 793 |
720 // USVString is identical to DOMString except that "convert a | 794 // USVString is identical to DOMString except that "convert a |
721 // DOMString to a sequence of Unicode characters" is used subsequently | 795 // DOMString to a sequence of Unicode characters" is used subsequently |
722 // when converting to an IDL value | 796 // when converting to an IDL value |
723 String x = toCoreString(stringObject); | 797 String x = toCoreString(stringObject); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 { | 1133 { |
1060 v8ConstructorAttributeGetter(info); | 1134 v8ConstructorAttributeGetter(info); |
1061 } | 1135 } |
1062 | 1136 |
1063 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V alue>& info) | 1137 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V alue>& info) |
1064 { | 1138 { |
1065 v8ConstructorAttributeGetter(info); | 1139 v8ConstructorAttributeGetter(info); |
1066 } | 1140 } |
1067 | 1141 |
1068 } // namespace blink | 1142 } // namespace blink |
OLD | NEW |