Chromium Code Reviews| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 NodeFilterCondition* condition = V8NodeFilterCondition::Create( | 90 NodeFilterCondition* condition = V8NodeFilterCondition::Create( |
| 91 callback, filter_wrapper.As<v8::Object>(), script_state); | 91 callback, filter_wrapper.As<v8::Object>(), script_state); |
| 92 filter->SetCondition(condition); | 92 filter->SetCondition(condition); |
| 93 | 93 |
| 94 return filter; | 94 return filter; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool ToBooleanSlow(v8::Isolate* isolate, | 97 bool ToBooleanSlow(v8::Isolate* isolate, |
| 98 v8::Local<v8::Value> value, | 98 v8::Local<v8::Value> value, |
| 99 ExceptionState& exception_state) { | 99 ExceptionState& exception_state) { |
| 100 ASSERT(!value->IsBoolean()); | 100 DCHECK(!value->IsBoolean()); |
| 101 v8::TryCatch block(isolate); | 101 v8::TryCatch block(isolate); |
| 102 bool result = false; | 102 bool result = false; |
| 103 if (!V8Call(value->BooleanValue(isolate->GetCurrentContext()), result, block)) | 103 if (!V8Call(value->BooleanValue(isolate->GetCurrentContext()), result, block)) |
| 104 exception_state.RethrowV8Exception(block.Exception()); | 104 exception_state.RethrowV8Exception(block.Exception()); |
| 105 return result; | 105 return result; |
| 106 } | 106 } |
| 107 | 107 |
| 108 const int32_t kMaxInt32 = 0x7fffffff; | 108 const int32_t kMaxInt32 = 0x7fffffff; |
| 109 const int32_t kMinInt32 = -kMaxInt32 - 1; | 109 const int32_t kMinInt32 = -kMaxInt32 - 1; |
| 110 const uint32_t kMaxUInt32 = 0xffffffff; | 110 const uint32_t kMaxUInt32 = 0xffffffff; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 number_object = value.As<v8::Number>(); | 192 number_object = value.As<v8::Number>(); |
| 193 } else { | 193 } else { |
| 194 // Can the value be converted to a number? | 194 // Can the value be converted to a number? |
| 195 v8::TryCatch block(isolate); | 195 v8::TryCatch block(isolate); |
| 196 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, | 196 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, |
| 197 block)) { | 197 block)) { |
| 198 exception_state.RethrowV8Exception(block.Exception()); | 198 exception_state.RethrowV8Exception(block.Exception()); |
| 199 return 0; | 199 return 0; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 ASSERT(!number_object.IsEmpty()); | 202 DCHECK(!number_object.IsEmpty()); |
| 203 | 203 |
| 204 if (configuration == kEnforceRange) | 204 if (configuration == kEnforceRange) |
| 205 return EnforceRange(number_object->Value(), LimitsTrait::kMinValue, | 205 return EnforceRange(number_object->Value(), LimitsTrait::kMinValue, |
| 206 LimitsTrait::kMaxValue, type_name, exception_state); | 206 LimitsTrait::kMaxValue, type_name, exception_state); |
| 207 | 207 |
| 208 double number_value = number_object->Value(); | 208 double number_value = number_object->Value(); |
| 209 if (std::isnan(number_value) || !number_value) | 209 if (std::isnan(number_value) || !number_value) |
| 210 return 0; | 210 return 0; |
| 211 | 211 |
| 212 if (configuration == kClamp) | 212 if (configuration == kClamp) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 number_object = value.As<v8::Number>(); | 252 number_object = value.As<v8::Number>(); |
| 253 } else { | 253 } else { |
| 254 // Can the value be converted to a number? | 254 // Can the value be converted to a number? |
| 255 v8::TryCatch block(isolate); | 255 v8::TryCatch block(isolate); |
| 256 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, | 256 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, |
| 257 block)) { | 257 block)) { |
| 258 exception_state.RethrowV8Exception(block.Exception()); | 258 exception_state.RethrowV8Exception(block.Exception()); |
| 259 return 0; | 259 return 0; |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 ASSERT(!number_object.IsEmpty()); | 262 DCHECK(!number_object.IsEmpty()); |
| 263 | 263 |
| 264 if (configuration == kEnforceRange) | 264 if (configuration == kEnforceRange) |
| 265 return EnforceRange(number_object->Value(), 0, LimitsTrait::kMaxValue, | 265 return EnforceRange(number_object->Value(), 0, LimitsTrait::kMaxValue, |
| 266 type_name, exception_state); | 266 type_name, exception_state); |
| 267 | 267 |
| 268 double number_value = number_object->Value(); | 268 double number_value = number_object->Value(); |
| 269 | 269 |
| 270 if (std::isnan(number_value) || !number_value) | 270 if (std::isnan(number_value) || !number_value) |
| 271 return 0; | 271 return 0; |
| 272 | 272 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 IntegerConversionConfiguration configuration, | 310 IntegerConversionConfiguration configuration, |
| 311 ExceptionState& exception_state) { | 311 ExceptionState& exception_state) { |
| 312 return ToSmallerUInt<uint16_t>(isolate, value, configuration, | 312 return ToSmallerUInt<uint16_t>(isolate, value, configuration, |
| 313 "unsigned short", exception_state); | 313 "unsigned short", exception_state); |
| 314 } | 314 } |
| 315 | 315 |
| 316 int32_t ToInt32Slow(v8::Isolate* isolate, | 316 int32_t ToInt32Slow(v8::Isolate* isolate, |
| 317 v8::Local<v8::Value> value, | 317 v8::Local<v8::Value> value, |
| 318 IntegerConversionConfiguration configuration, | 318 IntegerConversionConfiguration configuration, |
| 319 ExceptionState& exception_state) { | 319 ExceptionState& exception_state) { |
| 320 ASSERT(!value->IsInt32()); | 320 DCHECK(!value->IsInt32()); |
| 321 // Can the value be converted to a number? | 321 // Can the value be converted to a number? |
| 322 v8::TryCatch block(isolate); | 322 v8::TryCatch block(isolate); |
| 323 v8::Local<v8::Number> number_object; | 323 v8::Local<v8::Number> number_object; |
| 324 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, | 324 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, |
| 325 block)) { | 325 block)) { |
| 326 exception_state.RethrowV8Exception(block.Exception()); | 326 exception_state.RethrowV8Exception(block.Exception()); |
| 327 return 0; | 327 return 0; |
| 328 } | 328 } |
| 329 | 329 |
| 330 ASSERT(!number_object.IsEmpty()); | 330 DCHECK(!number_object.IsEmpty()); |
| 331 | 331 |
| 332 double number_value = number_object->Value(); | 332 double number_value = number_object->Value(); |
| 333 if (configuration == kEnforceRange) | 333 if (configuration == kEnforceRange) |
| 334 return EnforceRange(number_value, kMinInt32, kMaxInt32, "long", | 334 return EnforceRange(number_value, kMinInt32, kMaxInt32, "long", |
| 335 exception_state); | 335 exception_state); |
| 336 | 336 |
| 337 if (std::isnan(number_value)) | 337 if (std::isnan(number_value)) |
| 338 return 0; | 338 return 0; |
| 339 | 339 |
| 340 if (configuration == kClamp) | 340 if (configuration == kClamp) |
| 341 return clampTo<int32_t>(number_value); | 341 return clampTo<int32_t>(number_value); |
| 342 | 342 |
| 343 if (std::isinf(number_value)) | 343 if (std::isinf(number_value)) |
| 344 return 0; | 344 return 0; |
| 345 | 345 |
| 346 int32_t result; | 346 int32_t result; |
| 347 if (!V8Call(number_object->Int32Value(isolate->GetCurrentContext()), result, | 347 if (!V8Call(number_object->Int32Value(isolate->GetCurrentContext()), result, |
| 348 block)) { | 348 block)) { |
| 349 exception_state.RethrowV8Exception(block.Exception()); | 349 exception_state.RethrowV8Exception(block.Exception()); |
| 350 return 0; | 350 return 0; |
| 351 } | 351 } |
| 352 return result; | 352 return result; |
| 353 } | 353 } |
| 354 | 354 |
| 355 uint32_t ToUInt32Slow(v8::Isolate* isolate, | 355 uint32_t ToUInt32Slow(v8::Isolate* isolate, |
| 356 v8::Local<v8::Value> value, | 356 v8::Local<v8::Value> value, |
| 357 IntegerConversionConfiguration configuration, | 357 IntegerConversionConfiguration configuration, |
| 358 ExceptionState& exception_state) { | 358 ExceptionState& exception_state) { |
| 359 ASSERT(!value->IsUint32()); | 359 DCHECK(!value->IsUint32()); |
| 360 if (value->IsInt32()) { | 360 if (value->IsInt32()) { |
| 361 ASSERT(configuration != kNormalConversion); | 361 DCHECK_NE(configuration, kNormalConversion); |
| 362 int32_t result = value.As<v8::Int32>()->Value(); | 362 int32_t result = value.As<v8::Int32>()->Value(); |
| 363 if (result >= 0) | 363 if (result >= 0) |
| 364 return result; | 364 return result; |
| 365 if (configuration == kEnforceRange) { | 365 if (configuration == kEnforceRange) { |
| 366 exception_state.ThrowTypeError( | 366 exception_state.ThrowTypeError( |
| 367 "Value is outside the 'unsigned long' value range."); | 367 "Value is outside the 'unsigned long' value range."); |
| 368 return 0; | 368 return 0; |
| 369 } | 369 } |
| 370 ASSERT(configuration == kClamp); | 370 DCHECK_EQ(configuration, kClamp); |
| 371 return clampTo<uint32_t>(result); | 371 return clampTo<uint32_t>(result); |
| 372 } | 372 } |
| 373 | 373 |
| 374 // Can the value be converted to a number? | 374 // Can the value be converted to a number? |
| 375 v8::TryCatch block(isolate); | 375 v8::TryCatch block(isolate); |
| 376 v8::Local<v8::Number> number_object; | 376 v8::Local<v8::Number> number_object; |
| 377 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, | 377 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, |
| 378 block)) { | 378 block)) { |
| 379 exception_state.RethrowV8Exception(block.Exception()); | 379 exception_state.RethrowV8Exception(block.Exception()); |
| 380 return 0; | 380 return 0; |
| 381 } | 381 } |
| 382 ASSERT(!number_object.IsEmpty()); | 382 DCHECK(!number_object.IsEmpty()); |
| 383 | 383 |
| 384 if (configuration == kEnforceRange) | 384 if (configuration == kEnforceRange) |
| 385 return EnforceRange(number_object->Value(), 0, kMaxUInt32, "unsigned long", | 385 return EnforceRange(number_object->Value(), 0, kMaxUInt32, "unsigned long", |
| 386 exception_state); | 386 exception_state); |
| 387 | 387 |
| 388 double number_value = number_object->Value(); | 388 double number_value = number_object->Value(); |
| 389 | 389 |
| 390 if (std::isnan(number_value)) | 390 if (std::isnan(number_value)) |
| 391 return 0; | 391 return 0; |
| 392 | 392 |
| 393 if (configuration == kClamp) | 393 if (configuration == kClamp) |
| 394 return clampTo<uint32_t>(number_value); | 394 return clampTo<uint32_t>(number_value); |
| 395 | 395 |
| 396 if (std::isinf(number_value)) | 396 if (std::isinf(number_value)) |
| 397 return 0; | 397 return 0; |
| 398 | 398 |
| 399 uint32_t result; | 399 uint32_t result; |
| 400 if (!V8Call(number_object->Uint32Value(isolate->GetCurrentContext()), result, | 400 if (!V8Call(number_object->Uint32Value(isolate->GetCurrentContext()), result, |
| 401 block)) { | 401 block)) { |
| 402 exception_state.RethrowV8Exception(block.Exception()); | 402 exception_state.RethrowV8Exception(block.Exception()); |
| 403 return 0; | 403 return 0; |
| 404 } | 404 } |
| 405 return result; | 405 return result; |
| 406 } | 406 } |
| 407 | 407 |
| 408 int64_t ToInt64Slow(v8::Isolate* isolate, | 408 int64_t ToInt64Slow(v8::Isolate* isolate, |
| 409 v8::Local<v8::Value> value, | 409 v8::Local<v8::Value> value, |
| 410 IntegerConversionConfiguration configuration, | 410 IntegerConversionConfiguration configuration, |
| 411 ExceptionState& exception_state) { | 411 ExceptionState& exception_state) { |
| 412 ASSERT(!value->IsInt32()); | 412 DCHECK(!value->IsInt32()); |
| 413 | 413 |
| 414 v8::Local<v8::Number> number_object; | 414 v8::Local<v8::Number> number_object; |
| 415 // Can the value be converted to a number? | 415 // Can the value be converted to a number? |
| 416 v8::TryCatch block(isolate); | 416 v8::TryCatch block(isolate); |
| 417 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, | 417 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, |
| 418 block)) { | 418 block)) { |
| 419 exception_state.RethrowV8Exception(block.Exception()); | 419 exception_state.RethrowV8Exception(block.Exception()); |
| 420 return 0; | 420 return 0; |
| 421 } | 421 } |
| 422 ASSERT(!number_object.IsEmpty()); | 422 DCHECK(!number_object.IsEmpty()); |
| 423 | 423 |
| 424 double number_value = number_object->Value(); | 424 double number_value = number_object->Value(); |
| 425 | 425 |
| 426 if (configuration == kEnforceRange) | 426 if (configuration == kEnforceRange) |
| 427 return EnforceRange(number_value, -kJSMaxInteger, kJSMaxInteger, | 427 return EnforceRange(number_value, -kJSMaxInteger, kJSMaxInteger, |
| 428 "long long", exception_state); | 428 "long long", exception_state); |
| 429 | 429 |
| 430 if (std::isnan(number_value) || std::isinf(number_value)) | 430 if (std::isnan(number_value) || std::isinf(number_value)) |
| 431 return 0; | 431 return 0; |
| 432 | 432 |
| 433 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 433 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
| 434 unsigned long long integer; | 434 unsigned long long integer; |
| 435 doubleToInteger(number_value, integer); | 435 doubleToInteger(number_value, integer); |
| 436 return integer; | 436 return integer; |
| 437 } | 437 } |
| 438 | 438 |
| 439 uint64_t ToUInt64Slow(v8::Isolate* isolate, | 439 uint64_t ToUInt64Slow(v8::Isolate* isolate, |
| 440 v8::Local<v8::Value> value, | 440 v8::Local<v8::Value> value, |
| 441 IntegerConversionConfiguration configuration, | 441 IntegerConversionConfiguration configuration, |
| 442 ExceptionState& exception_state) { | 442 ExceptionState& exception_state) { |
| 443 ASSERT(!value->IsUint32()); | 443 DCHECK(!value->IsUint32()); |
| 444 if (value->IsInt32()) { | 444 if (value->IsInt32()) { |
| 445 ASSERT(configuration != kNormalConversion); | 445 ASSERT(configuration != kNormalConversion); |
| 446 int32_t result = value.As<v8::Int32>()->Value(); | 446 int32_t result = value.As<v8::Int32>()->Value(); |
| 447 if (result >= 0) | 447 if (result >= 0) |
| 448 return result; | 448 return result; |
| 449 if (configuration == kEnforceRange) { | 449 if (configuration == kEnforceRange) { |
| 450 exception_state.ThrowTypeError( | 450 exception_state.ThrowTypeError( |
| 451 "Value is outside the 'unsigned long long' value range."); | 451 "Value is outside the 'unsigned long long' value range."); |
| 452 return 0; | 452 return 0; |
| 453 } | 453 } |
| 454 ASSERT(configuration == kClamp); | 454 DCHECK_EQ(configuration, kClamp); |
| 455 return clampTo<uint64_t>(result); | 455 return clampTo<uint64_t>(result); |
| 456 } | 456 } |
| 457 | 457 |
| 458 v8::Local<v8::Number> number_object; | 458 v8::Local<v8::Number> number_object; |
| 459 // Can the value be converted to a number? | 459 // Can the value be converted to a number? |
| 460 v8::TryCatch block(isolate); | 460 v8::TryCatch block(isolate); |
| 461 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, | 461 if (!V8Call(value->ToNumber(isolate->GetCurrentContext()), number_object, |
| 462 block)) { | 462 block)) { |
| 463 exception_state.RethrowV8Exception(block.Exception()); | 463 exception_state.RethrowV8Exception(block.Exception()); |
| 464 return 0; | 464 return 0; |
| 465 } | 465 } |
| 466 ASSERT(!number_object.IsEmpty()); | 466 DCHECK(!number_object.IsEmpty()); |
| 467 | 467 |
| 468 double number_value = number_object->Value(); | 468 double number_value = number_object->Value(); |
| 469 | 469 |
| 470 if (configuration == kEnforceRange) | 470 if (configuration == kEnforceRange) |
| 471 return EnforceRange(number_value, 0, kJSMaxInteger, "unsigned long long", | 471 return EnforceRange(number_value, 0, kJSMaxInteger, "unsigned long long", |
| 472 exception_state); | 472 exception_state); |
| 473 | 473 |
| 474 if (std::isnan(number_value)) | 474 if (std::isnan(number_value)) |
| 475 return 0; | 475 return 0; |
| 476 | 476 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 495 if (!std::isfinite(number_value)) { | 495 if (!std::isfinite(number_value)) { |
| 496 exception_state.ThrowTypeError("The provided float value is non-finite."); | 496 exception_state.ThrowTypeError("The provided float value is non-finite."); |
| 497 return 0; | 497 return 0; |
| 498 } | 498 } |
| 499 return number_value; | 499 return number_value; |
| 500 } | 500 } |
| 501 | 501 |
| 502 double ToDoubleSlow(v8::Isolate* isolate, | 502 double ToDoubleSlow(v8::Isolate* isolate, |
| 503 v8::Local<v8::Value> value, | 503 v8::Local<v8::Value> value, |
| 504 ExceptionState& exception_state) { | 504 ExceptionState& exception_state) { |
| 505 ASSERT(!value->IsNumber()); | 505 DCHECK(!value->IsNumber()); |
| 506 v8::TryCatch block(isolate); | 506 v8::TryCatch block(isolate); |
| 507 v8::Local<v8::Number> number_value; | 507 v8::Local<v8::Number> number_value; |
| 508 if (!value->ToNumber(isolate->GetCurrentContext()).ToLocal(&number_value)) { | 508 if (!value->ToNumber(isolate->GetCurrentContext()).ToLocal(&number_value)) { |
| 509 exception_state.RethrowV8Exception(block.Exception()); | 509 exception_state.RethrowV8Exception(block.Exception()); |
| 510 return 0; | 510 return 0; |
| 511 } | 511 } |
| 512 return number_value->Value(); | 512 return number_value->Value(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 double ToRestrictedDouble(v8::Isolate* isolate, | 515 double ToRestrictedDouble(v8::Isolate* isolate, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 // This roughly implements http://heycam.github.io/webidl/#dfn-obtain-unicode | 597 // This roughly implements http://heycam.github.io/webidl/#dfn-obtain-unicode |
| 598 // but since Blink strings are 16-bits internally, the output is simply | 598 // but since Blink strings are 16-bits internally, the output is simply |
| 599 // re-encoded to UTF-16. | 599 // re-encoded to UTF-16. |
| 600 | 600 |
| 601 // The concept of surrogate pairs is explained at: | 601 // The concept of surrogate pairs is explained at: |
| 602 // http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf#G2630 | 602 // http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf#G2630 |
| 603 | 603 |
| 604 // Blink-specific optimization to avoid making an unnecessary copy. | 604 // Blink-specific optimization to avoid making an unnecessary copy. |
| 605 if (!HasUnmatchedSurrogates(string)) | 605 if (!HasUnmatchedSurrogates(string)) |
| 606 return string; | 606 return string; |
| 607 ASSERT(!string.Is8Bit()); | 607 DCHECK(!string.Is8Bit()); |
| 608 | 608 |
| 609 // 1. Let S be the DOMString value. | 609 // 1. Let S be the DOMString value. |
| 610 const UChar* s = string.Characters16(); | 610 const UChar* s = string.Characters16(); |
| 611 | 611 |
| 612 // 2. Let n be the length of S. | 612 // 2. Let n be the length of S. |
| 613 const unsigned n = string.length(); | 613 const unsigned n = string.length(); |
| 614 | 614 |
| 615 // 3. Initialize i to 0. | 615 // 3. Initialize i to 0. |
| 616 unsigned i = 0; | 616 unsigned i = 0; |
| 617 | 617 |
| 618 // 4. Initialize U to be an empty sequence of Unicode characters. | 618 // 4. Initialize U to be an empty sequence of Unicode characters. |
| 619 StringBuilder u; | 619 StringBuilder u; |
| 620 u.ReserveCapacity(n); | 620 u.ReserveCapacity(n); |
| 621 | 621 |
| 622 // 5. While i < n: | 622 // 5. While i < n: |
| 623 while (i < n) { | 623 while (i < n) { |
| 624 // 1. Let c be the code unit in S at index i. | 624 // 1. Let c be the code unit in S at index i. |
| 625 UChar c = s[i]; | 625 UChar c = s[i]; |
| 626 // 2. Depending on the value of c: | 626 // 2. Depending on the value of c: |
| 627 if (U16_IS_SINGLE(c)) { | 627 if (U16_IS_SINGLE(c)) { |
| 628 // c < 0xD800 or c > 0xDFFF | 628 // c < 0xD800 or c > 0xDFFF |
| 629 // Append to U the Unicode character with code point c. | 629 // Append to U the Unicode character with code point c. |
| 630 u.Append(c); | 630 u.Append(c); |
| 631 } else if (U16_IS_TRAIL(c)) { | 631 } else if (U16_IS_TRAIL(c)) { |
| 632 // 0xDC00 <= c <= 0xDFFF | 632 // 0xDC00 <= c <= 0xDFFF |
| 633 // Append to U a U+FFFD REPLACEMENT CHARACTER. | 633 // Append to U a U+FFFD REPLACEMENT CHARACTER. |
| 634 u.Append(kReplacementCharacter); | 634 u.Append(kReplacementCharacter); |
| 635 } else { | 635 } else { |
| 636 // 0xD800 <= c <= 0xDBFF | 636 // 0xD800 <= c <= 0xDBFF |
| 637 ASSERT(U16_IS_LEAD(c)); | 637 DCHECK(U16_IS_LEAD(c)); |
| 638 if (i == n - 1) { | 638 if (i == n - 1) { |
| 639 // 1. If i = n-1, then append to U a U+FFFD REPLACEMENT CHARACTER. | 639 // 1. If i = n-1, then append to U a U+FFFD REPLACEMENT CHARACTER. |
| 640 u.Append(kReplacementCharacter); | 640 u.Append(kReplacementCharacter); |
| 641 } else { | 641 } else { |
| 642 // 2. Otherwise, i < n-1: | 642 // 2. Otherwise, i < n-1: |
| 643 ASSERT(i < n - 1); | 643 DCHECK(i < n - 1); |
|
tkent
2017/04/13 05:37:16
use DCHECK_LT
bhagirathi.s
2017/04/13 09:10:35
Done.
| |
| 644 // ....1. Let d be the code unit in S at index i+1. | 644 // ....1. Let d be the code unit in S at index i+1. |
| 645 UChar d = s[i + 1]; | 645 UChar d = s[i + 1]; |
| 646 if (U16_IS_TRAIL(d)) { | 646 if (U16_IS_TRAIL(d)) { |
| 647 // 2. If 0xDC00 <= d <= 0xDFFF, then: | 647 // 2. If 0xDC00 <= d <= 0xDFFF, then: |
| 648 // ..1. Let a be c & 0x3FF. | 648 // ..1. Let a be c & 0x3FF. |
| 649 // ..2. Let b be d & 0x3FF. | 649 // ..2. Let b be d & 0x3FF. |
| 650 // ..3. Append to U the Unicode character with code point | 650 // ..3. Append to U the Unicode character with code point |
| 651 // 2^16+2^10*a+b. | 651 // 2^16+2^10*a+b. |
| 652 u.Append(U16_GET_SUPPLEMENTARY(c, d)); | 652 u.Append(U16_GET_SUPPLEMENTARY(c, d)); |
| 653 // Blink: This is equivalent to u.append(c); u.append(d); | 653 // Blink: This is equivalent to u.append(c); u.append(d); |
| 654 ++i; | 654 ++i; |
| 655 } else { | 655 } else { |
| 656 // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a U+FFFD | 656 // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a U+FFFD |
| 657 // REPLACEMENT CHARACTER. | 657 // REPLACEMENT CHARACTER. |
| 658 u.Append(kReplacementCharacter); | 658 u.Append(kReplacementCharacter); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 } | 661 } |
| 662 // 3. Set i to i+1. | 662 // 3. Set i to i+1. |
| 663 ++i; | 663 ++i; |
| 664 } | 664 } |
| 665 | 665 |
| 666 // 6. Return U. | 666 // 6. Return U. |
| 667 ASSERT(u.length() == string.length()); | 667 DCHECK_EQ(u.length(), string.length()); |
| 668 return u.ToString(); | 668 return u.ToString(); |
| 669 } | 669 } |
| 670 | 670 |
| 671 String ToUSVString(v8::Isolate* isolate, | 671 String ToUSVString(v8::Isolate* isolate, |
| 672 v8::Local<v8::Value> value, | 672 v8::Local<v8::Value> value, |
| 673 ExceptionState& exception_state) { | 673 ExceptionState& exception_state) { |
| 674 // http://heycam.github.io/webidl/#es-USVString | 674 // http://heycam.github.io/webidl/#es-USVString |
| 675 if (value.IsEmpty()) | 675 if (value.IsEmpty()) |
| 676 return String(); | 676 return String(); |
| 677 | 677 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 // We return 0 here because |context| is detached from the Frame. If we | 767 // We return 0 here because |context| is detached from the Frame. If we |
| 768 // did return |frame| we could get in trouble because the frame could be | 768 // did return |frame| we could get in trouble because the frame could be |
| 769 // navigated to another security origin. | 769 // navigated to another security origin. |
| 770 return nullptr; | 770 return nullptr; |
| 771 } | 771 } |
| 772 | 772 |
| 773 void ToFlexibleArrayBufferView(v8::Isolate* isolate, | 773 void ToFlexibleArrayBufferView(v8::Isolate* isolate, |
| 774 v8::Local<v8::Value> value, | 774 v8::Local<v8::Value> value, |
| 775 FlexibleArrayBufferView& result, | 775 FlexibleArrayBufferView& result, |
| 776 void* storage) { | 776 void* storage) { |
| 777 ASSERT(value->IsArrayBufferView()); | 777 DCHECK(value->IsArrayBufferView()); |
| 778 v8::Local<v8::ArrayBufferView> buffer = value.As<v8::ArrayBufferView>(); | 778 v8::Local<v8::ArrayBufferView> buffer = value.As<v8::ArrayBufferView>(); |
| 779 if (!storage) { | 779 if (!storage) { |
| 780 result.SetFull(V8ArrayBufferView::toImpl(buffer)); | 780 result.SetFull(V8ArrayBufferView::toImpl(buffer)); |
| 781 return; | 781 return; |
| 782 } | 782 } |
| 783 size_t length = buffer->ByteLength(); | 783 size_t length = buffer->ByteLength(); |
| 784 buffer->CopyContents(storage, length); | 784 buffer->CopyContents(storage, length); |
| 785 result.SetSmall(storage, length); | 785 result.SetSmall(storage, length); |
| 786 } | 786 } |
| 787 | 787 |
| 788 static ScriptState* ToScriptStateImpl(LocalFrame* frame, | 788 static ScriptState* ToScriptStateImpl(LocalFrame* frame, |
| 789 DOMWrapperWorld& world) { | 789 DOMWrapperWorld& world) { |
| 790 if (!frame) | 790 if (!frame) |
| 791 return nullptr; | 791 return nullptr; |
| 792 v8::Local<v8::Context> context = ToV8ContextEvenIfDetached(frame, world); | 792 v8::Local<v8::Context> context = ToV8ContextEvenIfDetached(frame, world); |
| 793 if (context.IsEmpty()) | 793 if (context.IsEmpty()) |
| 794 return nullptr; | 794 return nullptr; |
| 795 ScriptState* script_state = ScriptState::From(context); | 795 ScriptState* script_state = ScriptState::From(context); |
| 796 if (!script_state->ContextIsValid()) | 796 if (!script_state->ContextIsValid()) |
| 797 return nullptr; | 797 return nullptr; |
| 798 DCHECK_EQ(frame, ToLocalFrameIfNotDetached(context)); | 798 DCHECK_EQ(frame, ToLocalFrameIfNotDetached(context)); |
| 799 return script_state; | 799 return script_state; |
| 800 } | 800 } |
| 801 | 801 |
| 802 v8::Local<v8::Context> ToV8Context(ExecutionContext* context, | 802 v8::Local<v8::Context> ToV8Context(ExecutionContext* context, |
| 803 DOMWrapperWorld& world) { | 803 DOMWrapperWorld& world) { |
| 804 ASSERT(context); | 804 DCHECK(context); |
| 805 if (context->IsDocument()) { | 805 if (context->IsDocument()) { |
| 806 if (LocalFrame* frame = ToDocument(context)->GetFrame()) | 806 if (LocalFrame* frame = ToDocument(context)->GetFrame()) |
| 807 return ToV8Context(frame, world); | 807 return ToV8Context(frame, world); |
| 808 } else if (context->IsWorkerGlobalScope()) { | 808 } else if (context->IsWorkerGlobalScope()) { |
| 809 if (WorkerOrWorkletScriptController* script = | 809 if (WorkerOrWorkletScriptController* script = |
| 810 ToWorkerOrWorkletGlobalScope(context)->ScriptController()) { | 810 ToWorkerOrWorkletGlobalScope(context)->ScriptController()) { |
| 811 if (script->GetScriptState()->ContextIsValid()) | 811 if (script->GetScriptState()->ContextIsValid()) |
| 812 return script->GetScriptState()->GetContext(); | 812 return script->GetScriptState()->GetContext(); |
| 813 } | 813 } |
| 814 } | 814 } |
| 815 return v8::Local<v8::Context>(); | 815 return v8::Local<v8::Context>(); |
| 816 } | 816 } |
| 817 | 817 |
| 818 v8::Local<v8::Context> ToV8Context(LocalFrame* frame, DOMWrapperWorld& world) { | 818 v8::Local<v8::Context> ToV8Context(LocalFrame* frame, DOMWrapperWorld& world) { |
| 819 ScriptState* script_state = ToScriptStateImpl(frame, world); | 819 ScriptState* script_state = ToScriptStateImpl(frame, world); |
| 820 if (!script_state) | 820 if (!script_state) |
| 821 return v8::Local<v8::Context>(); | 821 return v8::Local<v8::Context>(); |
| 822 return script_state->GetContext(); | 822 return script_state->GetContext(); |
| 823 } | 823 } |
| 824 | 824 |
| 825 v8::Local<v8::Context> ToV8ContextEvenIfDetached(LocalFrame* frame, | 825 v8::Local<v8::Context> ToV8ContextEvenIfDetached(LocalFrame* frame, |
| 826 DOMWrapperWorld& world) { | 826 DOMWrapperWorld& world) { |
| 827 ASSERT(frame); | 827 DCHECK(frame); |
| 828 return frame->WindowProxy(world)->ContextIfInitialized(); | 828 return frame->WindowProxy(world)->ContextIfInitialized(); |
| 829 } | 829 } |
| 830 | 830 |
| 831 ScriptState* ToScriptState(LocalFrame* frame, DOMWrapperWorld& world) { | 831 ScriptState* ToScriptState(LocalFrame* frame, DOMWrapperWorld& world) { |
| 832 v8::HandleScope handle_scope(ToIsolate(frame)); | 832 v8::HandleScope handle_scope(ToIsolate(frame)); |
| 833 return ToScriptStateImpl(frame, world); | 833 return ToScriptStateImpl(frame, world); |
| 834 } | 834 } |
| 835 | 835 |
| 836 ScriptState* ToScriptStateForMainWorld(LocalFrame* frame) { | 836 ScriptState* ToScriptStateForMainWorld(LocalFrame* frame) { |
| 837 return ToScriptState(frame, DOMWrapperWorld::MainWorld()); | 837 return ToScriptState(frame, DOMWrapperWorld::MainWorld()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 exception_state.ThrowTypeError("Iterator is not an object."); | 901 exception_state.ThrowTypeError("Iterator is not an object."); |
| 902 return v8::Local<v8::Object>(); | 902 return v8::Local<v8::Object>(); |
| 903 } | 903 } |
| 904 return iterator.As<v8::Object>(); | 904 return iterator.As<v8::Object>(); |
| 905 } | 905 } |
| 906 | 906 |
| 907 bool AddHiddenValueToArray(v8::Isolate* isolate, | 907 bool AddHiddenValueToArray(v8::Isolate* isolate, |
| 908 v8::Local<v8::Object> object, | 908 v8::Local<v8::Object> object, |
| 909 v8::Local<v8::Value> value, | 909 v8::Local<v8::Value> value, |
| 910 int array_index) { | 910 int array_index) { |
| 911 ASSERT(!value.IsEmpty()); | 911 DCHECK(!value.IsEmpty()); |
| 912 v8::Local<v8::Value> array_value = object->GetInternalField(array_index); | 912 v8::Local<v8::Value> array_value = object->GetInternalField(array_index); |
| 913 if (array_value->IsNull() || array_value->IsUndefined()) { | 913 if (array_value->IsNull() || array_value->IsUndefined()) { |
| 914 array_value = v8::Array::New(isolate); | 914 array_value = v8::Array::New(isolate); |
| 915 object->SetInternalField(array_index, array_value); | 915 object->SetInternalField(array_index, array_value); |
| 916 } | 916 } |
| 917 | 917 |
| 918 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(array_value); | 918 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(array_value); |
| 919 return V8CallBoolean(array->CreateDataProperty(isolate->GetCurrentContext(), | 919 return V8CallBoolean(array->CreateDataProperty(isolate->GetCurrentContext(), |
| 920 array->Length(), value)); | 920 array->Length(), value)); |
| 921 } | 921 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 988 if (!V8Call(v8::JSON::Parse(isolate, V8String(isolate, stringified_json)), | 988 if (!V8Call(v8::JSON::Parse(isolate, V8String(isolate, stringified_json)), |
| 989 parsed, try_catch)) { | 989 parsed, try_catch)) { |
| 990 if (try_catch.HasCaught()) | 990 if (try_catch.HasCaught()) |
| 991 exception_state.RethrowV8Exception(try_catch.Exception()); | 991 exception_state.RethrowV8Exception(try_catch.Exception()); |
| 992 } | 992 } |
| 993 | 993 |
| 994 return parsed; | 994 return parsed; |
| 995 } | 995 } |
| 996 | 996 |
| 997 } // namespace blink | 997 } // namespace blink |
| OLD | NEW |