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

Unified Diff: src/code-stub-assembler.cc

Issue 2870013004: [builtins] String.prototype.slice as a CSA builtin. (Closed)
Patch Set: Flags for SubString. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/code-stub-assembler.cc
diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc
index 8b006713bbeaa18d40b1e75158fd3a0387c87cfd..de1ee8cd782496e1e3b1d1a930cbe3efdabc8493 100644
--- a/src/code-stub-assembler.cc
+++ b/src/code-stub-assembler.cc
@@ -3544,7 +3544,9 @@ Node* AllocAndCopyStringCharacters(CodeStubAssembler* a, Node* context,
} // namespace
Node* CodeStubAssembler::SubString(Node* context, Node* string, Node* from,
- Node* to) {
+ Node* to, SubStringFlags flags) {
+ DCHECK(flags == SubStringFlags::NONE ||
+ flags == SubStringFlags::FROM_TO_ARE_BOUNDED);
VARIABLE(var_result, MachineRepresentation::kTagged);
ToDirectStringAssembler to_direct(state(), string);
Label end(this), runtime(this);
@@ -3555,8 +3557,10 @@ Node* CodeStubAssembler::SubString(Node* context, Node* string, Node* from,
// Make sure that both from and to are non-negative smis.
- GotoIfNot(TaggedIsPositiveSmi(from), &runtime);
- GotoIfNot(TaggedIsPositiveSmi(to), &runtime);
+ if (flags == SubStringFlags::NONE) {
+ GotoIfNot(TaggedIsPositiveSmi(from), &runtime);
jgruber 2017/05/11 08:57:41 We should assert the conditions otherwise, same be
mvstanton 2017/05/12 11:00:43 Done.
+ GotoIfNot(TaggedIsPositiveSmi(to), &runtime);
+ }
Node* const substr_length = SmiSub(to, from);
Node* const string_length = LoadStringLength(string);
@@ -3657,8 +3661,10 @@ Node* CodeStubAssembler::SubString(Node* context, Node* string, Node* from,
BIND(&original_string_or_invalid_length);
{
- // Longer than original string's length or negative: unsafe arguments.
- GotoIf(SmiAbove(substr_length, string_length), &runtime);
+ if (flags == SubStringFlags::NONE) {
+ // Longer than original string's length or negative: unsafe arguments.
+ GotoIf(SmiAbove(substr_length, string_length), &runtime);
+ }
// Equal length - check if {from, to} == {0, str.length}.
GotoIf(SmiAbove(from, SmiConstant(Smi::kZero)), &runtime);

Powered by Google App Engine
This is Rietveld 408576698