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

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 Yang’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 07-18-14, section B.2.3.1
rossberg 2014/08/05 11:15:29 Drive-by: please use ISO date order. Or in this ca
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 07-18-14, 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 07-18-14, 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 07-18-14, 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 07-18-14, 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 07-18-14, 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 07-18-14, section B.2.3.6
868 function StringFixed() {
869 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fixed");
870 return "<tt>" + this + "</tt>";
871 }
872
aandrey 2014/08/05 11:16:20 one more blank line
873 // ES6 draft 07-18-14, section B.2.3.7
874 function StringFontcolor(color) {
875 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontcolor");
876 return "<font color=\"" + HtmlEscape(color) + "\">" + this + "</font>";
877 }
878
879
880 // ES6 draft 07-18-14, section B.2.3.8
881 function StringFontsize(size) {
882 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontsize");
883 return "<font size=\"" + HtmlEscape(size) + "\">" + this + "</font>";
884 }
885
886
887 // ES6 draft 07-18-14, section B.2.3.9
888 function StringItalics() {
889 CHECK_OBJECT_COERCIBLE(this, "String.prototype.italics");
890 return "<i>" + this + "</i>";
891 }
892
893
894 // ES6 draft 07-18-14, section B.2.3.10
841 function StringLink(s) { 895 function StringLink(s) {
896 CHECK_OBJECT_COERCIBLE(this, "String.prototype.link");
842 return "<a href=\"" + HtmlEscape(s) + "\">" + this + "</a>"; 897 return "<a href=\"" + HtmlEscape(s) + "\">" + this + "</a>";
843 } 898 }
844 899
845 900
846 function StringAnchor(name) { 901 // ES6 draft 07-18-14, 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() { 902 function StringSmall() {
903 CHECK_OBJECT_COERCIBLE(this, "String.prototype.small");
887 return "<small>" + this + "</small>"; 904 return "<small>" + this + "</small>";
888 } 905 }
889 906
890 907
908 // ES6 draft 07-18-14, section B.2.3.12
891 function StringStrike() { 909 function StringStrike() {
910 CHECK_OBJECT_COERCIBLE(this, "String.prototype.strike");
892 return "<strike>" + this + "</strike>"; 911 return "<strike>" + this + "</strike>";
893 } 912 }
894 913
895 914
915 // ES6 draft 07-18-14, section B.2.3.13
896 function StringSub() { 916 function StringSub() {
917 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sub");
897 return "<sub>" + this + "</sub>"; 918 return "<sub>" + this + "</sub>";
898 } 919 }
899 920
900 921
922 // ES6 draft 07-18-14, section B.2.3.14
901 function StringSup() { 923 function StringSup() {
924 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup");
902 return "<sup>" + this + "</sup>"; 925 return "<sup>" + this + "</sup>";
903 } 926 }
904 927
905 // ------------------------------------------------------------------- 928 // -------------------------------------------------------------------
906 929
907 function SetUpString() { 930 function SetUpString() {
908 %CheckIsBootstrapping(); 931 %CheckIsBootstrapping();
909 932
910 // Set the String function and constructor. 933 // Set the String function and constructor.
911 %SetCode($String, StringConstructor); 934 %SetCode($String, StringConstructor);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 "fixed", StringFixed, 977 "fixed", StringFixed,
955 "italics", StringItalics, 978 "italics", StringItalics,
956 "small", StringSmall, 979 "small", StringSmall,
957 "strike", StringStrike, 980 "strike", StringStrike,
958 "sub", StringSub, 981 "sub", StringSub,
959 "sup", StringSup 982 "sup", StringSup
960 )); 983 ));
961 } 984 }
962 985
963 SetUpString(); 986 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