diff --git a/src/objects-inl.h b/src/objects-inl.h index 57fc2a056b..f26f4c220b 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -5288,7 +5288,7 @@ BOOL_ACCESSORS(JSPromise, flags, handled_hint, kHandledHintBit) ACCESSORS(JSRegExp, data, Object, kDataOffset) ACCESSORS(JSRegExp, flags, Object, kFlagsOffset) ACCESSORS(JSRegExp, source, Object, kSourceOffset) - +ACCESSORS(JSRegExp, last_index, Object, kLastIndexOffset) JSRegExp::Type JSRegExp::TypeTag() { Object* data = this->data(); @@ -5345,19 +5345,6 @@ void JSRegExp::SetDataAt(int index, Object* value) { FixedArray::cast(data())->set(index, value); } -void JSRegExp::SetLastIndex(int index) { - static const int offset = - kSize + JSRegExp::kLastIndexFieldIndex * kPointerSize; - Smi* value = Smi::FromInt(index); - WRITE_FIELD(this, offset, value); -} - -Object* JSRegExp::LastIndex() { - static const int offset = - kSize + JSRegExp::kLastIndexFieldIndex * kPointerSize; - return READ_FIELD(this, offset); -} - ElementsKind JSObject::GetElementsKind() { ElementsKind kind = map()->elements_kind(); #if VERIFY_HEAP && DEBUG diff --git a/src/objects.h b/src/objects.h index beb903aff3..010bec7741 100644 --- a/src/objects.h +++ b/src/objects.h @@ -5697,6 +5697,7 @@ class JSRegExp: public JSObject { DECL_ACCESSORS(data, Object) DECL_ACCESSORS(flags, Object) + DECL_ACCESSORS(last_index, Object) DECL_ACCESSORS(source, Object) V8_EXPORT_PRIVATE static MaybeHandle New(Handle source, @@ -5719,9 +5720,6 @@ class JSRegExp: public JSObject { // Set implementation data after the object has been prepared. inline void SetDataAt(int index, Object* value); - inline void SetLastIndex(int index); - inline Object* LastIndex(); - static int code_index(bool is_latin1) { if (is_latin1) { return kIrregexpLatin1CodeIndex; @@ -5740,6 +5738,7 @@ class JSRegExp: public JSObject { static const int kSourceOffset = kDataOffset + kPointerSize; static const int kFlagsOffset = kSourceOffset + kPointerSize; static const int kSize = kFlagsOffset + kPointerSize; + static const int kLastIndexOffset = kSize; // In-object field. // Indices in the data array. static const int kTagIndex = 0; diff --git a/src/regexp/regexp-utils.cc b/src/regexp/regexp-utils.cc index 88ecb85dfa..b683db27f3 100644 --- a/src/regexp/regexp-utils.cc +++ b/src/regexp/regexp-utils.cc @@ -45,7 +45,8 @@ MaybeHandle RegExpUtils::SetLastIndex(Isolate* isolate, Handle recv, int value) { if (HasInitialRegExpMap(isolate, recv)) { - JSRegExp::cast(*recv)->SetLastIndex(value); + JSRegExp::cast(*recv)->set_last_index(Smi::FromInt(value), + SKIP_WRITE_BARRIER); return recv; } else { return Object::SetProperty(recv, isolate->factory()->lastIndex_string(), @@ -56,7 +57,7 @@ MaybeHandle RegExpUtils::SetLastIndex(Isolate* isolate, MaybeHandle RegExpUtils::GetLastIndex(Isolate* isolate, Handle recv) { if (HasInitialRegExpMap(isolate, recv)) { - return handle(JSRegExp::cast(*recv)->LastIndex(), isolate); + return handle(JSRegExp::cast(*recv)->last_index(), isolate); } else { return Object::GetProperty(recv, isolate->factory()->lastIndex_string()); } @@ -151,7 +152,7 @@ bool RegExpUtils::IsUnmodifiedRegExp(Isolate* isolate, Handle obj) { // The smi check is required to omit ToLength(lastIndex) calls with possible // user-code execution on the fast path. - Object* last_index = JSRegExp::cast(recv)->LastIndex(); + Object* last_index = JSRegExp::cast(recv)->last_index(); return last_index->IsSmi() && Smi::ToInt(last_index) >= 0; } diff --git a/src/runtime/runtime-regexp.cc b/src/runtime/runtime-regexp.cc index a5d61d8348..968a1361f4 100644 --- a/src/runtime/runtime-regexp.cc +++ b/src/runtime/runtime-regexp.cc @@ -1352,7 +1352,7 @@ MUST_USE_RESULT MaybeHandle RegExpReplace(Isolate* isolate, uint32_t last_index = 0; if (sticky) { - Handle last_index_obj(regexp->LastIndex(), isolate); + Handle last_index_obj(regexp->last_index(), isolate); ASSIGN_RETURN_ON_EXCEPTION(isolate, last_index_obj, Object::ToLength(isolate, last_index_obj), String); @@ -1367,7 +1367,7 @@ MUST_USE_RESULT MaybeHandle RegExpReplace(Isolate* isolate, RegExpImpl::Exec(regexp, string, last_index, last_match_info), String); if (match_indices_obj->IsNull(isolate)) { - if (sticky) regexp->SetLastIndex(0); + if (sticky) regexp->set_last_index(Smi::kZero, SKIP_WRITE_BARRIER); return string; } @@ -1376,7 +1376,8 @@ MUST_USE_RESULT MaybeHandle RegExpReplace(Isolate* isolate, const int start_index = match_indices->Capture(0); const int end_index = match_indices->Capture(1); - if (sticky) regexp->SetLastIndex(end_index); + if (sticky) + regexp->set_last_index(Smi::FromInt(end_index), SKIP_WRITE_BARRIER); IncrementalStringBuilder builder(isolate); builder.AppendString(factory->NewSubString(string, 0, start_index)); @@ -1471,7 +1472,7 @@ RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) { const bool sticky = (flags & JSRegExp::kSticky) != 0; uint32_t last_index = 0; if (sticky) { - Handle last_index_obj(regexp->LastIndex(), isolate); + Handle last_index_obj(regexp->last_index(), isolate); ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, last_index_obj, Object::ToLength(isolate, last_index_obj)); last_index = PositiveNumberToUint32(*last_index_obj); @@ -1485,7 +1486,7 @@ RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) { RegExpImpl::Exec(regexp, subject, last_index, last_match_info)); if (match_indices_obj->IsNull(isolate)) { - if (sticky) regexp->SetLastIndex(0); + if (sticky) regexp->set_last_index(Smi::kZero, SKIP_WRITE_BARRIER); return *subject; } @@ -1495,7 +1496,8 @@ RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) { const int index = match_indices->Capture(0); const int end_of_match = match_indices->Capture(1); - if (sticky) regexp->SetLastIndex(end_of_match); + if (sticky) + regexp->set_last_index(Smi::FromInt(end_of_match), SKIP_WRITE_BARRIER); IncrementalStringBuilder builder(isolate); builder.AppendString(factory->NewSubString(subject, 0, index));