| OLD | NEW |
| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 8 | 8 |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 // Imports | 10 // Imports |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 var subject = TO_STRING(this); | 47 var subject = TO_STRING(this); |
| 48 | 48 |
| 49 // Equivalent to RegExpCreate (ES#sec-regexpcreate) | 49 // Equivalent to RegExpCreate (ES#sec-regexpcreate) |
| 50 var regexp = %RegExpCreate(pattern); | 50 var regexp = %RegExpCreate(pattern); |
| 51 return %_Call(regexp[searchSymbol], regexp, subject); | 51 return %_Call(regexp[searchSymbol], regexp, subject); |
| 52 } | 52 } |
| 53 | 53 |
| 54 | 54 |
| 55 // ECMA-262 section 15.5.4.13 | |
| 56 function StringSlice(start, end) { | |
| 57 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice"); | |
| 58 | |
| 59 var s = TO_STRING(this); | |
| 60 var s_len = s.length; | |
| 61 var start_i = TO_INTEGER(start); | |
| 62 var end_i = s_len; | |
| 63 if (!IS_UNDEFINED(end)) { | |
| 64 end_i = TO_INTEGER(end); | |
| 65 } | |
| 66 | |
| 67 if (start_i < 0) { | |
| 68 start_i += s_len; | |
| 69 if (start_i < 0) { | |
| 70 start_i = 0; | |
| 71 } | |
| 72 } else { | |
| 73 if (start_i > s_len) { | |
| 74 return ''; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 if (end_i < 0) { | |
| 79 end_i += s_len; | |
| 80 if (end_i < 0) { | |
| 81 return ''; | |
| 82 } | |
| 83 } else { | |
| 84 if (end_i > s_len) { | |
| 85 end_i = s_len; | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 if (end_i <= start_i) { | |
| 90 return ''; | |
| 91 } | |
| 92 | |
| 93 return %_SubString(s, start_i, end_i); | |
| 94 } | |
| 95 | |
| 96 | |
| 97 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1 | 55 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1 |
| 98 function HtmlEscape(str) { | 56 function HtmlEscape(str) { |
| 99 return %RegExpInternalReplace(/"/g, TO_STRING(str), """); | 57 return %RegExpInternalReplace(/"/g, TO_STRING(str), """); |
| 100 } | 58 } |
| 101 | 59 |
| 102 | 60 |
| 103 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2 | 61 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2 |
| 104 function StringAnchor(name) { | 62 function StringAnchor(name) { |
| 105 CHECK_OBJECT_COERCIBLE(this, "String.prototype.anchor"); | 63 CHECK_OBJECT_COERCIBLE(this, "String.prototype.anchor"); |
| 106 return "<a name=\"" + HtmlEscape(name) + "\">" + TO_STRING(this) + | 64 return "<a name=\"" + HtmlEscape(name) + "\">" + TO_STRING(this) + |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 ]); | 285 ]); |
| 328 | 286 |
| 329 // Set up the non-enumerable functions on the String prototype object. | 287 // Set up the non-enumerable functions on the String prototype object. |
| 330 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 288 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
| 331 "codePointAt", StringCodePointAt, | 289 "codePointAt", StringCodePointAt, |
| 332 "match", StringMatchJS, | 290 "match", StringMatchJS, |
| 333 "padEnd", StringPadEnd, | 291 "padEnd", StringPadEnd, |
| 334 "padStart", StringPadStart, | 292 "padStart", StringPadStart, |
| 335 "repeat", StringRepeat, | 293 "repeat", StringRepeat, |
| 336 "search", StringSearch, | 294 "search", StringSearch, |
| 337 "slice", StringSlice, | |
| 338 | |
| 339 "link", StringLink, | 295 "link", StringLink, |
| 340 "anchor", StringAnchor, | 296 "anchor", StringAnchor, |
| 341 "fontcolor", StringFontcolor, | 297 "fontcolor", StringFontcolor, |
| 342 "fontsize", StringFontsize, | 298 "fontsize", StringFontsize, |
| 343 "big", StringBig, | 299 "big", StringBig, |
| 344 "blink", StringBlink, | 300 "blink", StringBlink, |
| 345 "bold", StringBold, | 301 "bold", StringBold, |
| 346 "fixed", StringFixed, | 302 "fixed", StringFixed, |
| 347 "italics", StringItalics, | 303 "italics", StringItalics, |
| 348 "small", StringSmall, | 304 "small", StringSmall, |
| 349 "strike", StringStrike, | 305 "strike", StringStrike, |
| 350 "sub", StringSub, | 306 "sub", StringSub, |
| 351 "sup", StringSup | 307 "sup", StringSup |
| 352 ]); | 308 ]); |
| 353 | 309 |
| 354 }) | 310 }) |
| OLD | NEW |