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

Unified Diff: src/builtins/builtins-regexp-gen.cc

Issue 2863643004: [regexp] Avoid runtime call on OOB lastIndex values (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-regexp-gen.cc
diff --git a/src/builtins/builtins-regexp-gen.cc b/src/builtins/builtins-regexp-gen.cc
index d1fb9e82f193276867951be555e5d52635a59507..e8e4da889735b4bb253d9903673fb0c636d0128f 100644
--- a/src/builtins/builtins-regexp-gen.cc
+++ b/src/builtins/builtins-regexp-gen.cc
@@ -306,9 +306,15 @@ Node* RegExpBuiltinsAssembler::RegExpExecInternal(Node* const context,
Node* const smi_string_length = LoadStringLength(string);
- // Bail out to runtime for invalid {last_index} values.
- GotoIfNot(TaggedIsSmi(last_index), &runtime);
- GotoIf(SmiAboveOrEqual(last_index, smi_string_length), &runtime);
+ // At this point, last_index is definitely a canonicalized non-negative
+ // number, which implies that any non-Smi last_index is greater than
+ // the maximal string length. If lastIndex > string.length then the matcher
+ // must fail.
+
+ Label if_failure(this);
+ CSA_ASSERT(this, IsNumberNormalized(last_index));
+ GotoIfNot(TaggedIsSmi(last_index), &if_failure); // Outside Smi range.
+ GotoIf(SmiAbove(last_index, smi_string_length), &if_failure);
// Load the irregexp code object and offsets into the subject string. Both
// depend on whether the string is one- or two-byte.
@@ -358,8 +364,7 @@ Node* RegExpBuiltinsAssembler::RegExpExecInternal(Node* const context,
GotoIf(TaggedIsSmi(code), &runtime);
CSA_ASSERT(this, HasInstanceType(code, CODE_TYPE));
- Label if_success(this), if_failure(this),
- if_exception(this, Label::kDeferred);
+ Label if_success(this), if_exception(this, Label::kDeferred);
{
IncrementCounter(isolate()->counters()->regexp_entry_native(), 1);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698