OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
883 | 883 |
884 | 884 |
885 // Helper function for very basic XSS protection. | 885 // Helper function for very basic XSS protection. |
886 function HtmlEscape(str) { | 886 function HtmlEscape(str) { |
887 return TO_STRING_INLINE(str).replace(/</g, "<") | 887 return TO_STRING_INLINE(str).replace(/</g, "<") |
888 .replace(/>/g, ">") | 888 .replace(/>/g, ">") |
889 .replace(/"/g, """) | 889 .replace(/"/g, """) |
890 .replace(/'/g, "'"); | 890 .replace(/'/g, "'"); |
891 } | 891 } |
892 | 892 |
893 // ES6 draft 07-15-13, section 15.5.3.23 | |
894 function StringEndsWith(searchString /* position */) { // length == 1 | |
Michael Starzinger
2013/07/29 13:16:27
nit: Two white-spaces before comment at end of lin
| |
895 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
896 throw MakeTypeError("called_on_null_or_undefined", | |
897 ["String.prototype.endsWith"]); | |
898 } | |
899 | |
900 var s = TO_STRING_INLINE(this); | |
901 var s_len = s.length; | |
902 var ss = TO_STRING_INLINE(searchString); | |
903 var ss_len = ss.length; | |
904 | |
905 if (ss_len > 0) { | |
906 var pos = s_len; | |
907 if (%_ArgumentsLength() > 1) { | |
Michael Starzinger
2013/07/29 13:16:27
There is a missing check as to whether "position"
| |
908 var arg = ToNumber(%_Arguments(1)); // position | |
909 if (!NUMBER_IS_NAN(arg)) { | |
Michael Starzinger
2013/07/29 13:16:27
In case ToNumber(position) yields NaN, then "pos"
| |
910 pos = TO_INTEGER(arg); | |
911 } | |
912 } | |
913 | |
914 var end = $Math.min($Math.max(pos, 0), s_len); | |
Michael Starzinger
2013/07/29 13:16:27
This calls potentially monkey-patched versions of
| |
915 var start = end - ss_len; | |
916 if (start < 0) { | |
917 return false; | |
918 } | |
919 | |
920 return %StringLastIndexOf(s, ss, start) === end - ss_len; | |
921 } | |
922 | |
923 return true; | |
924 } | |
925 | |
893 | 926 |
894 // Compatibility support for KJS. | 927 // Compatibility support for KJS. |
895 // Tested by mozilla/js/tests/js1_5/Regress/regress-276103.js. | 928 // Tested by mozilla/js/tests/js1_5/Regress/regress-276103.js. |
896 function StringLink(s) { | 929 function StringLink(s) { |
897 return "<a href=\"" + HtmlEscape(s) + "\">" + this + "</a>"; | 930 return "<a href=\"" + HtmlEscape(s) + "\">" + this + "</a>"; |
898 } | 931 } |
899 | 932 |
900 | 933 |
901 function StringAnchor(name) { | 934 function StringAnchor(name) { |
902 return "<a name=\"" + HtmlEscape(name) + "\">" + this + "</a>"; | 935 return "<a name=\"" + HtmlEscape(name) + "\">" + this + "</a>"; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 "fontcolor", StringFontcolor, | 1036 "fontcolor", StringFontcolor, |
1004 "fontsize", StringFontsize, | 1037 "fontsize", StringFontsize, |
1005 "big", StringBig, | 1038 "big", StringBig, |
1006 "blink", StringBlink, | 1039 "blink", StringBlink, |
1007 "bold", StringBold, | 1040 "bold", StringBold, |
1008 "fixed", StringFixed, | 1041 "fixed", StringFixed, |
1009 "italics", StringItalics, | 1042 "italics", StringItalics, |
1010 "small", StringSmall, | 1043 "small", StringSmall, |
1011 "strike", StringStrike, | 1044 "strike", StringStrike, |
1012 "sub", StringSub, | 1045 "sub", StringSub, |
1013 "sup", StringSup | 1046 "sup", StringSup, |
1047 "endsWith", StringEndsWith | |
1014 )); | 1048 )); |
1015 } | 1049 } |
1016 | 1050 |
1017 SetUpString(); | 1051 SetUpString(); |
OLD | NEW |