| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 if (configuration == EnforceRange) | 252 if (configuration == EnforceRange) |
| 253 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, ok)
; | 253 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, ok)
; |
| 254 | 254 |
| 255 // Does the value convert to nan or to an infinity? | 255 // Does the value convert to nan or to an infinity? |
| 256 double numberValue = numberObject->Value(); | 256 double numberValue = numberObject->Value(); |
| 257 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) | 257 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) |
| 258 return 0; | 258 return 0; |
| 259 | 259 |
| 260 if (configuration == Clamp) |
| 261 return clampTo<T>(numberObject->Value()); |
| 262 |
| 260 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); | 263 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); |
| 261 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); | 264 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); |
| 262 } | 265 } |
| 263 | 266 |
| 264 int8_t toInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration config
uration, bool& ok) | 267 int8_t toInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration config
uration, bool& ok) |
| 265 { | 268 { |
| 266 return toSmallerInt<int8_t>(value, configuration, ok); | 269 return toSmallerInt<int8_t>(value, configuration, ok); |
| 267 } | 270 } |
| 268 | 271 |
| 269 uint8_t toUInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) | 272 uint8_t toUInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 283 | 286 |
| 284 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) | 287 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) |
| 285 { | 288 { |
| 286 ok = true; | 289 ok = true; |
| 287 | 290 |
| 288 // Fast case. The value is already a 32-bit integer. | 291 // Fast case. The value is already a 32-bit integer. |
| 289 if (value->IsInt32()) | 292 if (value->IsInt32()) |
| 290 return value->Int32Value(); | 293 return value->Int32Value(); |
| 291 | 294 |
| 292 // Can the value be converted to a number? | 295 // Can the value be converted to a number? |
| 293 v8::Local<v8::Number> numberObject = value->ToNumber(); | 296 ok = false; |
| 297 V8TRYCATCH_RETURN(v8::Local<v8::Number>, numberObject, value->ToNumber(), 0)
; |
| 294 if (numberObject.IsEmpty()) { | 298 if (numberObject.IsEmpty()) { |
| 295 ok = false; | |
| 296 return 0; | 299 return 0; |
| 297 } | 300 } |
| 301 ok = true; |
| 298 | 302 |
| 299 if (configuration == EnforceRange) | 303 if (configuration == EnforceRange) |
| 300 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, ok); | 304 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, ok); |
| 301 | 305 |
| 302 // Does the value convert to nan or to an infinity? | 306 // Does the value convert to nan or to an infinity? |
| 303 double numberValue = numberObject->Value(); | 307 double numberValue = numberObject->Value(); |
| 304 if (std::isnan(numberValue) || std::isinf(numberValue)) | 308 if (std::isnan(numberValue) || std::isinf(numberValue)) |
| 305 return 0; | 309 return 0; |
| 306 return numberObject->Int32Value(); | 310 |
| 311 if (configuration == Clamp) |
| 312 return clampTo<int32_t>(numberObject->Value()); |
| 313 |
| 314 V8TRYCATCH_RETURN(int32_t, result, numberObject->Int32Value(), 0); |
| 315 return result; |
| 307 } | 316 } |
| 308 | 317 |
| 309 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, bool& ok) | 318 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, bool& ok) |
| 310 { | 319 { |
| 311 ok = true; | 320 ok = true; |
| 312 | 321 |
| 313 // Fast case. The value is already a 32-bit unsigned integer. | 322 // Fast case. The value is already a 32-bit unsigned integer. |
| 314 if (value->IsUint32()) | 323 if (value->IsUint32()) |
| 315 return value->Uint32Value(); | 324 return value->Uint32Value(); |
| 316 | 325 |
| 317 // Fast case. The value is a 32-bit signed integer - possibly positive? | 326 // Fast case. The value is a 32-bit signed integer - possibly positive? |
| 318 if (value->IsInt32()) { | 327 if (value->IsInt32()) { |
| 319 int32_t result = value->Int32Value(); | 328 int32_t result = value->Int32Value(); |
| 320 if (result >= 0) | 329 if (result >= 0) |
| 321 return result; | 330 return result; |
| 322 if (configuration == EnforceRange) { | 331 if (configuration == EnforceRange) { |
| 323 ok = false; | 332 ok = false; |
| 324 return 0; | 333 return 0; |
| 325 } | 334 } |
| 326 return result; | 335 return result; |
| 327 } | 336 } |
| 328 | 337 |
| 329 // Can the value be converted to a number? | 338 // Can the value be converted to a number? |
| 330 v8::Local<v8::Number> numberObject = value->ToNumber(); | 339 ok = false; |
| 340 V8TRYCATCH_RETURN(v8::Local<v8::Number>, numberObject, value->ToNumber(), 0)
; |
| 331 if (numberObject.IsEmpty()) { | 341 if (numberObject.IsEmpty()) { |
| 332 ok = false; | |
| 333 return 0; | 342 return 0; |
| 334 } | 343 } |
| 344 ok = true; |
| 335 | 345 |
| 336 if (configuration == EnforceRange) | 346 if (configuration == EnforceRange) |
| 337 return enforceRange(numberObject->Value(), 0, kMaxUInt32, ok); | 347 return enforceRange(numberObject->Value(), 0, kMaxUInt32, ok); |
| 338 | 348 |
| 339 // Does the value convert to nan or to an infinity? | 349 // Does the value convert to nan or to an infinity? |
| 340 double numberValue = numberObject->Value(); | 350 double numberValue = numberObject->Value(); |
| 341 if (std::isnan(numberValue) || std::isinf(numberValue)) | 351 if (std::isnan(numberValue) || std::isinf(numberValue)) |
| 342 return 0; | 352 return 0; |
| 343 return numberObject->Uint32Value(); | 353 |
| 354 if (configuration == Clamp) |
| 355 return clampTo<uint32_t>(numberObject->Value()); |
| 356 |
| 357 V8TRYCATCH_RETURN(uint32_t, result, numberObject->Uint32Value(), 0); |
| 358 return result; |
| 344 } | 359 } |
| 345 | 360 |
| 346 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) | 361 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) |
| 347 { | 362 { |
| 348 ok = true; | 363 ok = true; |
| 349 | 364 |
| 350 // Fast case. The value is a 32-bit integer. | 365 // Fast case. The value is a 32-bit integer. |
| 351 if (value->IsInt32()) | 366 if (value->IsInt32()) |
| 352 return value->Int32Value(); | 367 return value->Int32Value(); |
| 353 | 368 |
| 354 // Can the value be converted to a number? | 369 // Can the value be converted to a number? |
| 355 v8::Local<v8::Number> numberObject = value->ToNumber(); | 370 v8::Local<v8::Number> numberObject = value->ToNumber(); |
| 356 if (numberObject.IsEmpty()) { | 371 if (numberObject.IsEmpty()) { |
| 357 ok = false; | 372 ok = false; |
| 358 return 0; | 373 return 0; |
| 359 } | 374 } |
| 360 | 375 |
| 361 double x = numberObject->Value(); | 376 double x = numberObject->Value(); |
| 362 | 377 |
| 363 if (configuration == EnforceRange) | 378 if (configuration == EnforceRange) |
| 364 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, ok); | 379 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, ok); |
| 365 | 380 |
| 381 // Does the value convert to nan or to an infinity? |
| 382 if (std::isnan(x) || std::isinf(x)) |
| 383 return 0; |
| 384 |
| 366 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 385 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
| 367 unsigned long long integer; | 386 unsigned long long integer; |
| 368 doubleToInteger(x, integer); | 387 doubleToInteger(x, integer); |
| 369 return integer; | 388 return integer; |
| 370 } | 389 } |
| 371 | 390 |
| 372 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, bool& ok) | 391 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, bool& ok) |
| 373 { | 392 { |
| 374 ok = true; | 393 ok = true; |
| 375 | 394 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 394 if (numberObject.IsEmpty()) { | 413 if (numberObject.IsEmpty()) { |
| 395 ok = false; | 414 ok = false; |
| 396 return 0; | 415 return 0; |
| 397 } | 416 } |
| 398 | 417 |
| 399 double x = numberObject->Value(); | 418 double x = numberObject->Value(); |
| 400 | 419 |
| 401 if (configuration == EnforceRange) | 420 if (configuration == EnforceRange) |
| 402 return enforceRange(x, 0, kJSMaxInteger, ok); | 421 return enforceRange(x, 0, kJSMaxInteger, ok); |
| 403 | 422 |
| 423 // Does the value convert to nan or to an infinity? |
| 424 if (std::isnan(x) || std::isinf(x)) |
| 425 return 0; |
| 426 |
| 404 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 427 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
| 405 unsigned long long integer; | 428 unsigned long long integer; |
| 406 doubleToInteger(x, integer); | 429 doubleToInteger(x, integer); |
| 407 return integer; | 430 return integer; |
| 408 } | 431 } |
| 409 | 432 |
| 410 v8::Handle<v8::FunctionTemplate> createRawTemplate(v8::Isolate* isolate) | 433 v8::Handle<v8::FunctionTemplate> createRawTemplate(v8::Isolate* isolate) |
| 411 { | 434 { |
| 412 v8::HandleScope scope(isolate); | 435 v8::HandleScope scope(isolate); |
| 413 v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8ObjectC
onstructor::isValidConstructorMode); | 436 v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8ObjectC
onstructor::isValidConstructorMode); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 return mainThreadIsolate(); | 633 return mainThreadIsolate(); |
| 611 return v8::Isolate::GetCurrent(); | 634 return v8::Isolate::GetCurrent(); |
| 612 } | 635 } |
| 613 | 636 |
| 614 v8::Isolate* toIsolate(Frame* frame) | 637 v8::Isolate* toIsolate(Frame* frame) |
| 615 { | 638 { |
| 616 return frame->script().isolate(); | 639 return frame->script().isolate(); |
| 617 } | 640 } |
| 618 | 641 |
| 619 } // namespace WebCore | 642 } // namespace WebCore |
| OLD | NEW |