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

Side by Side Diff: src/builtins/builtins-string.cc

Issue 2358133004: [stubs] Port String.prototype.substring to TurboFan (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 #include "src/builtins/builtins.h" 5 #include "src/builtins/builtins.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 7
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 Handle<String> valid_forms = 464 Handle<String> valid_forms =
465 isolate->factory()->NewStringFromStaticChars("NFC, NFD, NFKC, NFKD"); 465 isolate->factory()->NewStringFromStaticChars("NFC, NFD, NFKC, NFKD");
466 THROW_NEW_ERROR_RETURN_FAILURE( 466 THROW_NEW_ERROR_RETURN_FAILURE(
467 isolate, 467 isolate,
468 NewRangeError(MessageTemplate::kNormalizationForm, valid_forms)); 468 NewRangeError(MessageTemplate::kNormalizationForm, valid_forms));
469 } 469 }
470 470
471 return *string; 471 return *string;
472 } 472 }
473 473
474 namespace {
475
476 compiler::Node* EnsureSmiBetweenZeroAnd(CodeStubAssembler* a,
477 compiler::Node* value,
478 compiler::Node* limit) {
479 typedef CodeStubAssembler::Label Label;
480 typedef compiler::Node Node;
481 typedef CodeStubAssembler::Variable Variable;
482
483 Label out(a);
484 Variable var_result(a, MachineRepresentation::kTagged);
485
486 Label if_isinbounds(a), if_isoutofbounds(a, Label::kDeferred);
487 a->Branch(a->SmiAbove(value, limit), &if_isoutofbounds, &if_isinbounds);
488
489 a->Bind(&if_isinbounds);
490 {
491 var_result.Bind(value);
492 a->Goto(&out);
493 }
494
495 a->Bind(&if_isoutofbounds);
496 {
497 Node* const zero = a->SmiConstant(Smi::FromInt(0));
498 var_result.Bind(a->Select(a->SmiLessThan(value, zero), zero, limit));
499 a->Goto(&out);
500 }
501
502 a->Bind(&out);
503 return var_result.value();
504 }
505
506 } // namespace
507
508 // ES6 section 21.1.3.19 String.prototype.substring ( start, end )
509 void Builtins::Generate_StringPrototypeSubstring(CodeStubAssembler* a) {
510 typedef CodeStubAssembler::Label Label;
511 typedef compiler::Node Node;
512 typedef CodeStubAssembler::Variable Variable;
513
514 Label out(a);
515
516 Variable var_start(a, MachineRepresentation::kTagged);
517 Variable var_end(a, MachineRepresentation::kTagged);
518
519 Node* const receiver = a->Parameter(0);
520 Node* const start = a->Parameter(1);
521 Node* const end = a->Parameter(2);
522 Node* const context = a->Parameter(5);
523
524 // Check that {receiver} is coercible to Object and convert it to a String.
525 Node* const string =
526 a->ToThisString(context, receiver, "String.prototype.charCodeAt");
527
528 Node* const length = a->LoadStringLength(string);
529 Node* const zero = a->SmiConstant(Smi::FromInt(0));
530
531 // Conversion and bounds-checks for {start}.
532 {
533 Node* const start_int =
534 a->ToInteger(context, start, CodeStubAssembler::kTruncateMinusZero);
535 var_start.Bind(EnsureSmiBetweenZeroAnd(a, start_int, length));
536 }
537
538 // Conversion and bounds-checks for {end}.
539 {
540 var_end.Bind(length);
541 a->GotoIf(a->WordEqual(end, a->UndefinedConstant()), &out);
542
543 Node* const end_int =
544 a->ToInteger(context, end, CodeStubAssembler::kTruncateMinusZero);
545 var_end.Bind(EnsureSmiBetweenZeroAnd(a, end_int, length));
546
547 Label if_endislessthanstart(a);
548 a->Branch(a->SmiLessThan(var_end.value(), var_start.value()),
549 &if_endislessthanstart, &out);
550
551 a->Bind(&if_endislessthanstart);
552 {
553 Node* const tmp = var_end.value();
554 var_end.Bind(var_start.value());
555 var_start.Bind(tmp);
556 a->Goto(&out);
557 }
558 }
559
560 a->Bind(&out);
561 {
562 Node* result =
563 a->SubString(context, string, var_start.value(), var_end.value());
564 a->Return(result);
565 }
566 }
567
474 // ES6 section 21.1.3.25 String.prototype.toString () 568 // ES6 section 21.1.3.25 String.prototype.toString ()
475 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) { 569 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) {
476 typedef compiler::Node Node; 570 typedef compiler::Node Node;
477 571
478 Node* receiver = assembler->Parameter(0); 572 Node* receiver = assembler->Parameter(0);
479 Node* context = assembler->Parameter(3); 573 Node* context = assembler->Parameter(3);
480 574
481 Node* result = assembler->ToThisValue( 575 Node* result = assembler->ToThisValue(
482 context, receiver, PrimitiveType::kString, "String.prototype.toString"); 576 context, receiver, PrimitiveType::kString, "String.prototype.toString");
483 assembler->Return(result); 577 assembler->Return(result);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 659 }
566 660
567 iterator->set_string(isolate->heap()->empty_string()); 661 iterator->set_string(isolate->heap()->empty_string());
568 662
569 return *isolate->factory()->NewJSIteratorResult( 663 return *isolate->factory()->NewJSIteratorResult(
570 isolate->factory()->undefined_value(), true); 664 isolate->factory()->undefined_value(), true);
571 } 665 }
572 666
573 } // namespace internal 667 } // namespace internal
574 } // namespace v8 668 } // namespace v8
OLDNEW
« src/builtins/builtins.h ('K') | « src/builtins/builtins.h ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698