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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 v8::TryCatch block(isolate); | 545 v8::TryCatch block(isolate); |
546 if (!v8Call(value->ToString(isolate->GetCurrentContext()), stringObject, | 546 if (!v8Call(value->ToString(isolate->GetCurrentContext()), stringObject, |
547 block)) { | 547 block)) { |
548 exceptionState.rethrowV8Exception(block.Exception()); | 548 exceptionState.rethrowV8Exception(block.Exception()); |
549 return String(); | 549 return String(); |
550 } | 550 } |
551 } | 551 } |
552 | 552 |
553 String x = toCoreString(stringObject); | 553 String x = toCoreString(stringObject); |
554 | 554 |
555 // 2. If the value of any element of x is greater than 255, then throw a TypeE
rror. | 555 // 2. If the value of any element of x is greater than 255, then throw a |
| 556 // TypeError. |
556 if (!x.containsOnlyLatin1()) { | 557 if (!x.containsOnlyLatin1()) { |
557 exceptionState.throwTypeError("Value is not a valid ByteString."); | 558 exceptionState.throwTypeError("Value is not a valid ByteString."); |
558 return String(); | 559 return String(); |
559 } | 560 } |
560 | 561 |
561 // 3. Return an IDL ByteString value whose length is the length of x, and wher
e the | 562 // 3. Return an IDL ByteString value whose length is the length of x, and |
562 // value of each element is the value of the corresponding element of x. | 563 // where the value of each element is the value of the corresponding |
563 // Blink: A ByteString is simply a String with a range constrained per the abo
ve, so | 564 // element of x. |
564 // this is the identity operation. | 565 // Blink: A ByteString is simply a String with a range constrained per the |
| 566 // above, so this is the identity operation. |
565 return x; | 567 return x; |
566 } | 568 } |
567 | 569 |
568 static bool hasUnmatchedSurrogates(const String& string) { | 570 static bool hasUnmatchedSurrogates(const String& string) { |
569 // By definition, 8-bit strings are confined to the Latin-1 code page and | 571 // By definition, 8-bit strings are confined to the Latin-1 code page and |
570 // have no surrogates, matched or otherwise. | 572 // have no surrogates, matched or otherwise. |
571 if (string.is8Bit()) | 573 if (string.is8Bit()) |
572 return false; | 574 return false; |
573 | 575 |
574 const UChar* characters = string.characters16(); | 576 const UChar* characters = string.characters16(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 u.append(replacementCharacter); | 641 u.append(replacementCharacter); |
640 } else { | 642 } else { |
641 // 2. Otherwise, i < n-1: | 643 // 2. Otherwise, i < n-1: |
642 ASSERT(i < n - 1); | 644 ASSERT(i < n - 1); |
643 // ....1. Let d be the code unit in S at index i+1. | 645 // ....1. Let d be the code unit in S at index i+1. |
644 UChar d = s[i + 1]; | 646 UChar d = s[i + 1]; |
645 if (U16_IS_TRAIL(d)) { | 647 if (U16_IS_TRAIL(d)) { |
646 // 2. If 0xDC00 <= d <= 0xDFFF, then: | 648 // 2. If 0xDC00 <= d <= 0xDFFF, then: |
647 // ..1. Let a be c & 0x3FF. | 649 // ..1. Let a be c & 0x3FF. |
648 // ..2. Let b be d & 0x3FF. | 650 // ..2. Let b be d & 0x3FF. |
649 // ..3. Append to U the Unicode character with code point 2^16+2^10*a+
b. | 651 // ..3. Append to U the Unicode character with code point |
| 652 // 2^16+2^10*a+b. |
650 u.append(U16_GET_SUPPLEMENTARY(c, d)); | 653 u.append(U16_GET_SUPPLEMENTARY(c, d)); |
651 // Blink: This is equivalent to u.append(c); u.append(d); | 654 // Blink: This is equivalent to u.append(c); u.append(d); |
652 ++i; | 655 ++i; |
653 } else { | 656 } else { |
654 // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a U+FFFD REPLAC
EMENT CHARACTER. | 657 // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a U+FFFD |
| 658 // REPLACEMENT CHARACTER. |
655 u.append(replacementCharacter); | 659 u.append(replacementCharacter); |
656 } | 660 } |
657 } | 661 } |
658 } | 662 } |
659 // 3. Set i to i+1. | 663 // 3. Set i to i+1. |
660 ++i; | 664 ++i; |
661 } | 665 } |
662 | 666 |
663 // 6. Return U. | 667 // 6. Return U. |
664 ASSERT(u.length() == string.length()); | 668 ASSERT(u.length() == string.length()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 DOMWindow* toDOMWindow(v8::Local<v8::Context> context) { | 720 DOMWindow* toDOMWindow(v8::Local<v8::Context> context) { |
717 if (context.IsEmpty()) | 721 if (context.IsEmpty()) |
718 return 0; | 722 return 0; |
719 return toDOMWindow(context->GetIsolate(), context->Global()); | 723 return toDOMWindow(context->GetIsolate(), context->Global()); |
720 } | 724 } |
721 | 725 |
722 LocalDOMWindow* enteredDOMWindow(v8::Isolate* isolate) { | 726 LocalDOMWindow* enteredDOMWindow(v8::Isolate* isolate) { |
723 LocalDOMWindow* window = | 727 LocalDOMWindow* window = |
724 toLocalDOMWindow(toDOMWindow(isolate->GetEnteredContext())); | 728 toLocalDOMWindow(toDOMWindow(isolate->GetEnteredContext())); |
725 if (!window) { | 729 if (!window) { |
726 // We don't always have an entered DOM window, for example during microtask
callbacks from V8 | 730 // We don't always have an entered DOM window, for example during microtask |
727 // (where the entered context may be the DOM-in-JS context). In that case, w
e fall back | 731 // callbacks from V8 (where the entered context may be the DOM-in-JS |
728 // to the current context. | 732 // context). In that case, we fall back to the current context. |
729 // | 733 // |
730 // TODO(haraken): It's nasty to return a current window from enteredDOMWindo
w. | 734 // TODO(haraken): It's nasty to return a current window from |
731 // All call sites should be updated so that it works even if it doesn't have | 735 // enteredDOMWindow. All call sites should be updated so that it works even |
732 // an entered window. | 736 // if it doesn't have an entered window. |
733 window = currentDOMWindow(isolate); | 737 window = currentDOMWindow(isolate); |
734 ASSERT(window); | 738 ASSERT(window); |
735 } | 739 } |
736 return window; | 740 return window; |
737 } | 741 } |
738 | 742 |
739 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) { | 743 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) { |
740 return toLocalDOMWindow(toDOMWindow(isolate->GetCurrentContext())); | 744 return toLocalDOMWindow(toDOMWindow(isolate->GetCurrentContext())); |
741 } | 745 } |
742 | 746 |
(...skipping 19 matching lines...) Expand all Loading... |
762 return nullptr; | 766 return nullptr; |
763 } | 767 } |
764 | 768 |
765 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) { | 769 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) { |
766 return toExecutionContext(isolate->GetCurrentContext()); | 770 return toExecutionContext(isolate->GetCurrentContext()); |
767 } | 771 } |
768 | 772 |
769 ExecutionContext* enteredExecutionContext(v8::Isolate* isolate) { | 773 ExecutionContext* enteredExecutionContext(v8::Isolate* isolate) { |
770 ExecutionContext* context = toExecutionContext(isolate->GetEnteredContext()); | 774 ExecutionContext* context = toExecutionContext(isolate->GetEnteredContext()); |
771 if (!context) { | 775 if (!context) { |
772 // We don't always have an entered execution context, for example during mic
rotask callbacks from V8 | 776 // We don't always have an entered execution context, for example during |
773 // (where the entered context may be the DOM-in-JS context). In that case, w
e fall back | 777 // microtask callbacks from V8 (where the entered context may be the |
774 // to the current context. | 778 // DOM-in-JS context). In that case, we fall back to the current context. |
775 context = currentExecutionContext(isolate); | 779 context = currentExecutionContext(isolate); |
776 ASSERT(context); | 780 ASSERT(context); |
777 } | 781 } |
778 return context; | 782 return context; |
779 } | 783 } |
780 | 784 |
781 Frame* toFrameIfNotDetached(v8::Local<v8::Context> context) { | 785 Frame* toFrameIfNotDetached(v8::Local<v8::Context> context) { |
782 DOMWindow* window = toDOMWindow(context); | 786 DOMWindow* window = toDOMWindow(context); |
783 if (window && window->isCurrentlyDisplayedInFrame()) | 787 if (window && window->isCurrentlyDisplayedInFrame()) |
784 return window->frame(); | 788 return window->frame(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value> value, | 993 v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value> value, |
990 v8::Isolate* isolate) { | 994 v8::Isolate* isolate) { |
991 value.As<v8::Object>() | 995 value.As<v8::Object>() |
992 ->SetIntegrityLevel(isolate->GetCurrentContext(), | 996 ->SetIntegrityLevel(isolate->GetCurrentContext(), |
993 v8::IntegrityLevel::kFrozen) | 997 v8::IntegrityLevel::kFrozen) |
994 .ToChecked(); | 998 .ToChecked(); |
995 return value; | 999 return value; |
996 } | 1000 } |
997 | 1001 |
998 } // namespace blink | 1002 } // namespace blink |
OLD | NEW |