[regexp] Turn JSRegExp::last_index into a standard accessor
In contrast to other internal fields (data, source, and flags), last_index is an in-object property. But we can still use the standard accessor macros to access it. Bug: Change-Id: If77f2bb01c6ddccebdde09d7a316c2ddaaf9b277 Reviewed-on: https://chromium-review.googlesource.com/577549 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#46779}
This commit is contained in:
parent
f2745256c4
commit
2bce488014
@ -5288,7 +5288,7 @@ BOOL_ACCESSORS(JSPromise, flags, handled_hint, kHandledHintBit)
|
|||||||
ACCESSORS(JSRegExp, data, Object, kDataOffset)
|
ACCESSORS(JSRegExp, data, Object, kDataOffset)
|
||||||
ACCESSORS(JSRegExp, flags, Object, kFlagsOffset)
|
ACCESSORS(JSRegExp, flags, Object, kFlagsOffset)
|
||||||
ACCESSORS(JSRegExp, source, Object, kSourceOffset)
|
ACCESSORS(JSRegExp, source, Object, kSourceOffset)
|
||||||
|
ACCESSORS(JSRegExp, last_index, Object, kLastIndexOffset)
|
||||||
|
|
||||||
JSRegExp::Type JSRegExp::TypeTag() {
|
JSRegExp::Type JSRegExp::TypeTag() {
|
||||||
Object* data = this->data();
|
Object* data = this->data();
|
||||||
@ -5345,19 +5345,6 @@ void JSRegExp::SetDataAt(int index, Object* value) {
|
|||||||
FixedArray::cast(data())->set(index, 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 JSObject::GetElementsKind() {
|
||||||
ElementsKind kind = map()->elements_kind();
|
ElementsKind kind = map()->elements_kind();
|
||||||
#if VERIFY_HEAP && DEBUG
|
#if VERIFY_HEAP && DEBUG
|
||||||
|
@ -5697,6 +5697,7 @@ class JSRegExp: public JSObject {
|
|||||||
|
|
||||||
DECL_ACCESSORS(data, Object)
|
DECL_ACCESSORS(data, Object)
|
||||||
DECL_ACCESSORS(flags, Object)
|
DECL_ACCESSORS(flags, Object)
|
||||||
|
DECL_ACCESSORS(last_index, Object)
|
||||||
DECL_ACCESSORS(source, Object)
|
DECL_ACCESSORS(source, Object)
|
||||||
|
|
||||||
V8_EXPORT_PRIVATE static MaybeHandle<JSRegExp> New(Handle<String> source,
|
V8_EXPORT_PRIVATE static MaybeHandle<JSRegExp> New(Handle<String> source,
|
||||||
@ -5719,9 +5720,6 @@ class JSRegExp: public JSObject {
|
|||||||
// Set implementation data after the object has been prepared.
|
// Set implementation data after the object has been prepared.
|
||||||
inline void SetDataAt(int index, Object* value);
|
inline void SetDataAt(int index, Object* value);
|
||||||
|
|
||||||
inline void SetLastIndex(int index);
|
|
||||||
inline Object* LastIndex();
|
|
||||||
|
|
||||||
static int code_index(bool is_latin1) {
|
static int code_index(bool is_latin1) {
|
||||||
if (is_latin1) {
|
if (is_latin1) {
|
||||||
return kIrregexpLatin1CodeIndex;
|
return kIrregexpLatin1CodeIndex;
|
||||||
@ -5740,6 +5738,7 @@ class JSRegExp: public JSObject {
|
|||||||
static const int kSourceOffset = kDataOffset + kPointerSize;
|
static const int kSourceOffset = kDataOffset + kPointerSize;
|
||||||
static const int kFlagsOffset = kSourceOffset + kPointerSize;
|
static const int kFlagsOffset = kSourceOffset + kPointerSize;
|
||||||
static const int kSize = kFlagsOffset + kPointerSize;
|
static const int kSize = kFlagsOffset + kPointerSize;
|
||||||
|
static const int kLastIndexOffset = kSize; // In-object field.
|
||||||
|
|
||||||
// Indices in the data array.
|
// Indices in the data array.
|
||||||
static const int kTagIndex = 0;
|
static const int kTagIndex = 0;
|
||||||
|
@ -45,7 +45,8 @@ MaybeHandle<Object> RegExpUtils::SetLastIndex(Isolate* isolate,
|
|||||||
Handle<JSReceiver> recv,
|
Handle<JSReceiver> recv,
|
||||||
int value) {
|
int value) {
|
||||||
if (HasInitialRegExpMap(isolate, recv)) {
|
if (HasInitialRegExpMap(isolate, recv)) {
|
||||||
JSRegExp::cast(*recv)->SetLastIndex(value);
|
JSRegExp::cast(*recv)->set_last_index(Smi::FromInt(value),
|
||||||
|
SKIP_WRITE_BARRIER);
|
||||||
return recv;
|
return recv;
|
||||||
} else {
|
} else {
|
||||||
return Object::SetProperty(recv, isolate->factory()->lastIndex_string(),
|
return Object::SetProperty(recv, isolate->factory()->lastIndex_string(),
|
||||||
@ -56,7 +57,7 @@ MaybeHandle<Object> RegExpUtils::SetLastIndex(Isolate* isolate,
|
|||||||
MaybeHandle<Object> RegExpUtils::GetLastIndex(Isolate* isolate,
|
MaybeHandle<Object> RegExpUtils::GetLastIndex(Isolate* isolate,
|
||||||
Handle<JSReceiver> recv) {
|
Handle<JSReceiver> recv) {
|
||||||
if (HasInitialRegExpMap(isolate, recv)) {
|
if (HasInitialRegExpMap(isolate, recv)) {
|
||||||
return handle(JSRegExp::cast(*recv)->LastIndex(), isolate);
|
return handle(JSRegExp::cast(*recv)->last_index(), isolate);
|
||||||
} else {
|
} else {
|
||||||
return Object::GetProperty(recv, isolate->factory()->lastIndex_string());
|
return Object::GetProperty(recv, isolate->factory()->lastIndex_string());
|
||||||
}
|
}
|
||||||
@ -151,7 +152,7 @@ bool RegExpUtils::IsUnmodifiedRegExp(Isolate* isolate, Handle<Object> obj) {
|
|||||||
|
|
||||||
// The smi check is required to omit ToLength(lastIndex) calls with possible
|
// The smi check is required to omit ToLength(lastIndex) calls with possible
|
||||||
// user-code execution on the fast path.
|
// 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;
|
return last_index->IsSmi() && Smi::ToInt(last_index) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1352,7 +1352,7 @@ MUST_USE_RESULT MaybeHandle<String> RegExpReplace(Isolate* isolate,
|
|||||||
|
|
||||||
uint32_t last_index = 0;
|
uint32_t last_index = 0;
|
||||||
if (sticky) {
|
if (sticky) {
|
||||||
Handle<Object> last_index_obj(regexp->LastIndex(), isolate);
|
Handle<Object> last_index_obj(regexp->last_index(), isolate);
|
||||||
ASSIGN_RETURN_ON_EXCEPTION(isolate, last_index_obj,
|
ASSIGN_RETURN_ON_EXCEPTION(isolate, last_index_obj,
|
||||||
Object::ToLength(isolate, last_index_obj),
|
Object::ToLength(isolate, last_index_obj),
|
||||||
String);
|
String);
|
||||||
@ -1367,7 +1367,7 @@ MUST_USE_RESULT MaybeHandle<String> RegExpReplace(Isolate* isolate,
|
|||||||
RegExpImpl::Exec(regexp, string, last_index, last_match_info), String);
|
RegExpImpl::Exec(regexp, string, last_index, last_match_info), String);
|
||||||
|
|
||||||
if (match_indices_obj->IsNull(isolate)) {
|
if (match_indices_obj->IsNull(isolate)) {
|
||||||
if (sticky) regexp->SetLastIndex(0);
|
if (sticky) regexp->set_last_index(Smi::kZero, SKIP_WRITE_BARRIER);
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1376,7 +1376,8 @@ MUST_USE_RESULT MaybeHandle<String> RegExpReplace(Isolate* isolate,
|
|||||||
const int start_index = match_indices->Capture(0);
|
const int start_index = match_indices->Capture(0);
|
||||||
const int end_index = match_indices->Capture(1);
|
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);
|
IncrementalStringBuilder builder(isolate);
|
||||||
builder.AppendString(factory->NewSubString(string, 0, start_index));
|
builder.AppendString(factory->NewSubString(string, 0, start_index));
|
||||||
@ -1471,7 +1472,7 @@ RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) {
|
|||||||
const bool sticky = (flags & JSRegExp::kSticky) != 0;
|
const bool sticky = (flags & JSRegExp::kSticky) != 0;
|
||||||
uint32_t last_index = 0;
|
uint32_t last_index = 0;
|
||||||
if (sticky) {
|
if (sticky) {
|
||||||
Handle<Object> last_index_obj(regexp->LastIndex(), isolate);
|
Handle<Object> last_index_obj(regexp->last_index(), isolate);
|
||||||
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
||||||
isolate, last_index_obj, Object::ToLength(isolate, last_index_obj));
|
isolate, last_index_obj, Object::ToLength(isolate, last_index_obj));
|
||||||
last_index = PositiveNumberToUint32(*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));
|
RegExpImpl::Exec(regexp, subject, last_index, last_match_info));
|
||||||
|
|
||||||
if (match_indices_obj->IsNull(isolate)) {
|
if (match_indices_obj->IsNull(isolate)) {
|
||||||
if (sticky) regexp->SetLastIndex(0);
|
if (sticky) regexp->set_last_index(Smi::kZero, SKIP_WRITE_BARRIER);
|
||||||
return *subject;
|
return *subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1495,7 +1496,8 @@ RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) {
|
|||||||
const int index = match_indices->Capture(0);
|
const int index = match_indices->Capture(0);
|
||||||
const int end_of_match = match_indices->Capture(1);
|
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);
|
IncrementalStringBuilder builder(isolate);
|
||||||
builder.AppendString(factory->NewSubString(subject, 0, index));
|
builder.AppendString(factory->NewSubString(subject, 0, index));
|
||||||
|
Loading…
Reference in New Issue
Block a user