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

Side by Side Diff: src/js/string.js

Issue 2399423003: [builtins] Move StringIncludes to a builtin. (Closed)
Patch Set: Add another test. Re-use IsRegExp logic Created 4 years, 2 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
« no previous file with comments | « src/builtins/builtins-string.cc ('k') | src/objects.h » ('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 (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
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
464 // ES6 Draft 05-22-2014, section 21.1.3.3 436 // ES6 Draft 05-22-2014, section 21.1.3.3
465 function StringCodePointAt(pos) { 437 function StringCodePointAt(pos) {
466 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); 438 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt");
467 439
468 var string = TO_STRING(this); 440 var string = TO_STRING(this);
469 var size = string.length; 441 var size = string.length;
470 pos = TO_INTEGER(pos); 442 pos = TO_INTEGER(pos);
471 if (pos < 0 || pos >= size) { 443 if (pos < 0 || pos >= size) {
472 return UNDEFINED; 444 return UNDEFINED;
473 } 445 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // Set up the non-enumerable functions on the String object. 484 // Set up the non-enumerable functions on the String object.
513 utils.InstallFunctions(GlobalString, DONT_ENUM, [ 485 utils.InstallFunctions(GlobalString, DONT_ENUM, [
514 "raw", StringRaw 486 "raw", StringRaw
515 ]); 487 ]);
516 488
517 // Set up the non-enumerable functions on the String prototype object. 489 // Set up the non-enumerable functions on the String prototype object.
518 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ 490 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
519 "codePointAt", StringCodePointAt, 491 "codePointAt", StringCodePointAt,
520 "concat", StringConcat, 492 "concat", StringConcat,
521 "endsWith", StringEndsWith, 493 "endsWith", StringEndsWith,
522 "includes", StringIncludes,
523 "match", StringMatchJS, 494 "match", StringMatchJS,
524 "repeat", StringRepeat, 495 "repeat", StringRepeat,
525 "replace", StringReplace, 496 "replace", StringReplace,
526 "search", StringSearch, 497 "search", StringSearch,
527 "slice", StringSlice, 498 "slice", StringSlice,
528 "split", StringSplitJS, 499 "split", StringSplitJS,
529 "startsWith", StringStartsWith, 500 "startsWith", StringStartsWith,
530 "toLowerCase", StringToLowerCaseJS, 501 "toLowerCase", StringToLowerCaseJS,
531 "toLocaleLowerCase", StringToLocaleLowerCase, 502 "toLocaleLowerCase", StringToLocaleLowerCase,
532 "toUpperCase", StringToUpperCaseJS, 503 "toUpperCase", StringToUpperCaseJS,
(...skipping 18 matching lines...) Expand all
551 // Exports 522 // Exports
552 523
553 utils.Export(function(to) { 524 utils.Export(function(to) {
554 to.StringMatch = StringMatchJS; 525 to.StringMatch = StringMatchJS;
555 to.StringReplace = StringReplace; 526 to.StringReplace = StringReplace;
556 to.StringSlice = StringSlice; 527 to.StringSlice = StringSlice;
557 to.StringSplit = StringSplitJS; 528 to.StringSplit = StringSplitJS;
558 }); 529 });
559 530
560 }) 531 })
OLDNEW
« no previous file with comments | « src/builtins/builtins-string.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698