Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: src/string.js

Issue 422543003: Add `CheckObjectCoercible` for the `String.prototype` HTML methods (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updated as per rossberg’s and aandrey’s feedback Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/es6/string-html.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file relies on the fact that the following declaration has been made 5 // This file relies on the fact that the following declaration has been made
6 // in runtime.js: 6 // in runtime.js:
7 // var $String = global.String; 7 // var $String = global.String;
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 10
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 end_i = start_i; 699 end_i = start_i;
700 start_i = tmp; 700 start_i = tmp;
701 } 701 }
702 } 702 }
703 } 703 }
704 704
705 return %_SubString(s, start_i, end_i); 705 return %_SubString(s, start_i, end_i);
706 } 706 }
707 707
708 708
709 // This is not a part of ECMA-262. 709 // ES6 draft, revision 26 (2014-07-18), section B.2.3.1
710 function StringSubstr(start, n) { 710 function StringSubstr(start, n) {
711 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); 711 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr");
712 712
713 var s = TO_STRING_INLINE(this); 713 var s = TO_STRING_INLINE(this);
714 var len; 714 var len;
715 715
716 // Correct n: If not given, set to string length; if explicitly 716 // Correct n: If not given, set to string length; if explicitly
717 // set to undefined, zero, or negative, returns empty string. 717 // set to undefined, zero, or negative, returns empty string.
718 if (IS_UNDEFINED(n)) { 718 if (IS_UNDEFINED(n)) {
719 len = s.length; 719 len = s.length;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING); 820 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING);
821 for (var j = 0; i < n; i++, j++) { 821 for (var j = 0; i < n; i++, j++) {
822 var code = %_Arguments(i); 822 var code = %_Arguments(i);
823 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff; 823 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
824 %_TwoByteSeqStringSetChar(two_byte, j, code); 824 %_TwoByteSeqStringSetChar(two_byte, j, code);
825 } 825 }
826 return one_byte + two_byte; 826 return one_byte + two_byte;
827 } 827 }
828 828
829 829
830 // Helper function for very basic XSS protection. 830 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
831 function HtmlEscape(str) { 831 function HtmlEscape(str) {
832 return TO_STRING_INLINE(str).replace(/</g, "&lt;") 832 return TO_STRING_INLINE(str).replace(/</g, "&lt;")
833 .replace(/>/g, "&gt;") 833 .replace(/>/g, "&gt;")
834 .replace(/"/g, "&quot;") 834 .replace(/"/g, "&quot;")
835 .replace(/'/g, "&#039;"); 835 .replace(/'/g, "&#039;");
836 } 836 }
837 837
838 838
839 // Compatibility support for KJS. 839 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2
840 // Tested by mozilla/js/tests/js1_5/Regress/regress-276103.js. 840 function StringAnchor(name) {
841 CHECK_OBJECT_COERCIBLE(this, "String.prototype.anchor");
842 return "<a name=\"" + HtmlEscape(name) + "\">" + this + "</a>";
843 }
844
845
846 // ES6 draft, revision 26 (2014-07-18), section B.2.3.3
847 function StringBig() {
848 CHECK_OBJECT_COERCIBLE(this, "String.prototype.big");
849 return "<big>" + this + "</big>";
850 }
851
852
853 // ES6 draft, revision 26 (2014-07-18), section B.2.3.4
854 function StringBlink() {
855 CHECK_OBJECT_COERCIBLE(this, "String.prototype.blink");
856 return "<blink>" + this + "</blink>";
857 }
858
859
860 // ES6 draft, revision 26 (2014-07-18), section B.2.3.5
861 function StringBold() {
862 CHECK_OBJECT_COERCIBLE(this, "String.prototype.bold");
863 return "<b>" + this + "</b>";
864 }
865
866
867 // ES6 draft, revision 26 (2014-07-18), section B.2.3.6
868 function StringFixed() {
869 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fixed");
870 return "<tt>" + this + "</tt>";
871 }
872
873
874 // ES6 draft, revision 26 (2014-07-18), section B.2.3.7
875 function StringFontcolor(color) {
876 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontcolor");
877 return "<font color=\"" + HtmlEscape(color) + "\">" + this + "</font>";
878 }
879
880
881 // ES6 draft, revision 26 (2014-07-18), section B.2.3.8
882 function StringFontsize(size) {
883 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontsize");
884 return "<font size=\"" + HtmlEscape(size) + "\">" + this + "</font>";
885 }
886
887
888 // ES6 draft, revision 26 (2014-07-18), section B.2.3.9
889 function StringItalics() {
890 CHECK_OBJECT_COERCIBLE(this, "String.prototype.italics");
891 return "<i>" + this + "</i>";
892 }
893
894
895 // ES6 draft, revision 26 (2014-07-18), section B.2.3.10
841 function StringLink(s) { 896 function StringLink(s) {
897 CHECK_OBJECT_COERCIBLE(this, "String.prototype.link");
842 return "<a href=\"" + HtmlEscape(s) + "\">" + this + "</a>"; 898 return "<a href=\"" + HtmlEscape(s) + "\">" + this + "</a>";
843 } 899 }
844 900
845 901
846 function StringAnchor(name) { 902 // ES6 draft, revision 26 (2014-07-18), section B.2.3.11
847 return "<a name=\"" + HtmlEscape(name) + "\">" + this + "</a>";
848 }
849
850
851 function StringFontcolor(color) {
852 return "<font color=\"" + HtmlEscape(color) + "\">" + this + "</font>";
853 }
854
855
856 function StringFontsize(size) {
857 return "<font size=\"" + HtmlEscape(size) + "\">" + this + "</font>";
858 }
859
860
861 function StringBig() {
862 return "<big>" + this + "</big>";
863 }
864
865
866 function StringBlink() {
867 return "<blink>" + this + "</blink>";
868 }
869
870
871 function StringBold() {
872 return "<b>" + this + "</b>";
873 }
874
875
876 function StringFixed() {
877 return "<tt>" + this + "</tt>";
878 }
879
880
881 function StringItalics() {
882 return "<i>" + this + "</i>";
883 }
884
885
886 function StringSmall() { 903 function StringSmall() {
904 CHECK_OBJECT_COERCIBLE(this, "String.prototype.small");
887 return "<small>" + this + "</small>"; 905 return "<small>" + this + "</small>";
888 } 906 }
889 907
890 908
909 // ES6 draft, revision 26 (2014-07-18), section B.2.3.12
891 function StringStrike() { 910 function StringStrike() {
911 CHECK_OBJECT_COERCIBLE(this, "String.prototype.strike");
892 return "<strike>" + this + "</strike>"; 912 return "<strike>" + this + "</strike>";
893 } 913 }
894 914
895 915
916 // ES6 draft, revision 26 (2014-07-18), section B.2.3.13
896 function StringSub() { 917 function StringSub() {
918 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sub");
897 return "<sub>" + this + "</sub>"; 919 return "<sub>" + this + "</sub>";
898 } 920 }
899 921
900 922
923 // ES6 draft, revision 26 (2014-07-18), section B.2.3.14
901 function StringSup() { 924 function StringSup() {
925 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup");
902 return "<sup>" + this + "</sup>"; 926 return "<sup>" + this + "</sup>";
903 } 927 }
904 928
905 // ------------------------------------------------------------------- 929 // -------------------------------------------------------------------
906 930
907 function SetUpString() { 931 function SetUpString() {
908 %CheckIsBootstrapping(); 932 %CheckIsBootstrapping();
909 933
910 // Set the String function and constructor. 934 // Set the String function and constructor.
911 %SetCode($String, StringConstructor); 935 %SetCode($String, StringConstructor);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 "fixed", StringFixed, 978 "fixed", StringFixed,
955 "italics", StringItalics, 979 "italics", StringItalics,
956 "small", StringSmall, 980 "small", StringSmall,
957 "strike", StringStrike, 981 "strike", StringStrike,
958 "sub", StringSub, 982 "sub", StringSub,
959 "sup", StringSup 983 "sup", StringSup
960 )); 984 ));
961 } 985 }
962 986
963 SetUpString(); 987 SetUpString();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/string-html.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698