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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 if (start < 0) { | 426 if (start < 0) { |
427 return false; | 427 return false; |
428 } | 428 } |
429 | 429 |
430 return %_SubString(s, start, start + ss_len) === ss; | 430 return %_SubString(s, start, start + ss_len) === ss; |
431 } | 431 } |
432 | 432 |
433 %FunctionSetLength(StringEndsWith, 1); | 433 %FunctionSetLength(StringEndsWith, 1); |
434 | 434 |
435 | 435 |
| 436 // ES6 draft 04-05-14, section 21.1.3.6 |
| 437 function StringIncludes(searchString, position) { // length == 1 |
| 438 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); |
| 439 |
| 440 var string = TO_STRING(this); |
| 441 |
| 442 if (IsRegExp(searchString)) { |
| 443 throw %make_type_error(kFirstArgumentNotRegExp, "String.prototype.includes")
; |
| 444 } |
| 445 |
| 446 searchString = TO_STRING(searchString); |
| 447 var pos = TO_INTEGER(position); |
| 448 |
| 449 var stringLength = string.length; |
| 450 if (pos < 0) pos = 0; |
| 451 if (pos > stringLength) pos = stringLength; |
| 452 var searchStringLength = searchString.length; |
| 453 |
| 454 if (searchStringLength + pos > stringLength) { |
| 455 return false; |
| 456 } |
| 457 |
| 458 return %StringIndexOf(string, searchString, pos) !== -1; |
| 459 } |
| 460 |
| 461 %FunctionSetLength(StringIncludes, 1); |
| 462 |
| 463 |
436 // ES6 Draft 05-22-2014, section 21.1.3.3 | 464 // ES6 Draft 05-22-2014, section 21.1.3.3 |
437 function StringCodePointAt(pos) { | 465 function StringCodePointAt(pos) { |
438 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); | 466 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); |
439 | 467 |
440 var string = TO_STRING(this); | 468 var string = TO_STRING(this); |
441 var size = string.length; | 469 var size = string.length; |
442 pos = TO_INTEGER(pos); | 470 pos = TO_INTEGER(pos); |
443 if (pos < 0 || pos >= size) { | 471 if (pos < 0 || pos >= size) { |
444 return UNDEFINED; | 472 return UNDEFINED; |
445 } | 473 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 // Set up the non-enumerable functions on the String object. | 512 // Set up the non-enumerable functions on the String object. |
485 utils.InstallFunctions(GlobalString, DONT_ENUM, [ | 513 utils.InstallFunctions(GlobalString, DONT_ENUM, [ |
486 "raw", StringRaw | 514 "raw", StringRaw |
487 ]); | 515 ]); |
488 | 516 |
489 // Set up the non-enumerable functions on the String prototype object. | 517 // Set up the non-enumerable functions on the String prototype object. |
490 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 518 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
491 "codePointAt", StringCodePointAt, | 519 "codePointAt", StringCodePointAt, |
492 "concat", StringConcat, | 520 "concat", StringConcat, |
493 "endsWith", StringEndsWith, | 521 "endsWith", StringEndsWith, |
| 522 "includes", StringIncludes, |
494 "match", StringMatchJS, | 523 "match", StringMatchJS, |
495 "repeat", StringRepeat, | 524 "repeat", StringRepeat, |
496 "replace", StringReplace, | 525 "replace", StringReplace, |
497 "search", StringSearch, | 526 "search", StringSearch, |
498 "slice", StringSlice, | 527 "slice", StringSlice, |
499 "split", StringSplitJS, | 528 "split", StringSplitJS, |
500 "startsWith", StringStartsWith, | 529 "startsWith", StringStartsWith, |
501 "toLowerCase", StringToLowerCaseJS, | 530 "toLowerCase", StringToLowerCaseJS, |
502 "toLocaleLowerCase", StringToLocaleLowerCase, | 531 "toLocaleLowerCase", StringToLocaleLowerCase, |
503 "toUpperCase", StringToUpperCaseJS, | 532 "toUpperCase", StringToUpperCaseJS, |
(...skipping 18 matching lines...) Expand all Loading... |
522 // Exports | 551 // Exports |
523 | 552 |
524 utils.Export(function(to) { | 553 utils.Export(function(to) { |
525 to.StringMatch = StringMatchJS; | 554 to.StringMatch = StringMatchJS; |
526 to.StringReplace = StringReplace; | 555 to.StringReplace = StringReplace; |
527 to.StringSlice = StringSlice; | 556 to.StringSlice = StringSlice; |
528 to.StringSplit = StringSplitJS; | 557 to.StringSplit = StringSplitJS; |
529 }); | 558 }); |
530 | 559 |
531 }) | 560 }) |
OLD | NEW |