Commit 03c85c23 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[regexp] Eliminate all GetIsolates

Remove all uses of GetIsolate/GetHeap by passing Isolate in from all
call sites.

Bug: v8:7786
Change-Id: I64ff8d5796db9d602e86bff4d0b9297cbe700d0d
Reviewed-on: https://chromium-review.googlesource.com/1080819Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53467}
parent f69527ee
......@@ -16341,8 +16341,8 @@ MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp,
ASSIGN_RETURN_ON_EXCEPTION(isolate, escaped_source,
EscapeRegExpSource(isolate, source), JSRegExp);
RETURN_ON_EXCEPTION(isolate, RegExpImpl::Compile(regexp, source, flags),
JSRegExp);
RETURN_ON_EXCEPTION(
isolate, RegExpImpl::Compile(isolate, regexp, source, flags), JSRegExp);
regexp->set_source(*escaped_source);
regexp->set_flags(Smi::FromInt(flags));
......
......@@ -39,11 +39,9 @@ int32_t* RegExpImpl::GlobalCache::FetchNext() {
int last_end_index = last_match[1];
if (regexp_->TypeTag() == JSRegExp::ATOM) {
num_matches_ = RegExpImpl::AtomExecRaw(regexp_,
subject_,
last_end_index,
register_array_,
register_array_size_);
num_matches_ =
RegExpImpl::AtomExecRaw(isolate_, regexp_, subject_, last_end_index,
register_array_, register_array_size_);
} else {
int last_start_index = last_match[0];
if (last_start_index == last_end_index) {
......@@ -54,11 +52,9 @@ int32_t* RegExpImpl::GlobalCache::FetchNext() {
num_matches_ = 0; // Signal failed match.
return nullptr;
}
num_matches_ = RegExpImpl::IrregexpExecRaw(regexp_,
subject_,
last_end_index,
register_array_,
register_array_size_);
num_matches_ = RegExpImpl::IrregexpExecRaw(
isolate_, regexp_, subject_, last_end_index, register_array_,
register_array_size_);
}
if (num_matches_ <= 0) return nullptr;
......
......@@ -61,17 +61,17 @@ namespace internal {
V8_WARN_UNUSED_RESULT
static inline MaybeHandle<Object> ThrowRegExpException(
Handle<JSRegExp> re, Handle<String> pattern, Handle<String> error_text) {
Isolate* isolate = re->GetIsolate();
Isolate* isolate, Handle<JSRegExp> re, Handle<String> pattern,
Handle<String> error_text) {
THROW_NEW_ERROR(isolate, NewSyntaxError(MessageTemplate::kMalformedRegExp,
pattern, error_text),
Object);
}
inline void ThrowRegExpException(Handle<JSRegExp> re,
inline void ThrowRegExpException(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> error_text) {
USE(ThrowRegExpException(re, Handle<String>(re->Pattern()), error_text));
USE(ThrowRegExpException(isolate, re, Handle<String>(re->Pattern(), isolate),
error_text));
}
......@@ -128,12 +128,11 @@ static bool HasFewDifferentCharacters(Handle<String> pattern) {
// Generic RegExp methods. Dispatches to implementation specific methods.
MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
MaybeHandle<Object> RegExpImpl::Compile(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> pattern,
JSRegExp::Flags flags) {
DCHECK(pattern->IsFlat());
Isolate* isolate = re->GetIsolate();
Zone zone(isolate->allocator(), ZONE_NAME);
CompilationCache* compilation_cache = isolate->compilation_cache();
MaybeHandle<FixedArray> maybe_cached =
......@@ -151,7 +150,7 @@ MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
if (!RegExpParser::ParseRegExp(isolate, &zone, &reader, flags,
&parse_result)) {
// Throw an exception if we fail to parse the pattern.
return ThrowRegExpException(re, pattern, parse_result.error);
return ThrowRegExpException(isolate, re, pattern, parse_result.error);
}
bool has_been_compiled = false;
......@@ -159,7 +158,7 @@ MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
if (parse_result.simple && !IgnoreCase(flags) && !IsSticky(flags) &&
!HasFewDifferentCharacters(pattern)) {
// Parse-tree is a single atom that is equal to the pattern.
AtomCompile(re, pattern, flags, pattern);
AtomCompile(isolate, re, pattern, flags, pattern);
has_been_compiled = true;
} else if (parse_result.tree->IsAtom() && !IsSticky(flags) &&
parse_result.capture_count == 0) {
......@@ -170,12 +169,12 @@ MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
isolate, atom_string,
isolate->factory()->NewStringFromTwoByte(atom_pattern), Object);
if (!IgnoreCase(atom->flags()) && !HasFewDifferentCharacters(atom_string)) {
AtomCompile(re, pattern, flags, atom_string);
AtomCompile(isolate, re, pattern, flags, atom_string);
has_been_compiled = true;
}
}
if (!has_been_compiled) {
IrregexpInitialize(re, pattern, flags, parse_result.capture_count);
IrregexpInitialize(isolate, re, pattern, flags, parse_result.capture_count);
}
DCHECK(re->data()->IsFixedArray());
// Compilation succeeded so the data is set on the regexp
......@@ -186,14 +185,14 @@ MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
return re;
}
MaybeHandle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp,
MaybeHandle<Object> RegExpImpl::Exec(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject, int index,
Handle<RegExpMatchInfo> last_match_info) {
switch (regexp->TypeTag()) {
case JSRegExp::ATOM:
return AtomExec(regexp, subject, index, last_match_info);
return AtomExec(isolate, regexp, subject, index, last_match_info);
case JSRegExp::IRREGEXP: {
return IrregexpExec(regexp, subject, index, last_match_info);
return IrregexpExec(isolate, regexp, subject, index, last_match_info);
}
default:
UNREACHABLE();
......@@ -203,21 +202,17 @@ MaybeHandle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp,
// RegExp Atom implementation: Simple string search using indexOf.
void RegExpImpl::AtomCompile(Handle<JSRegExp> re,
Handle<String> pattern,
JSRegExp::Flags flags,
void RegExpImpl::AtomCompile(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> pattern, JSRegExp::Flags flags,
Handle<String> match_pattern) {
re->GetIsolate()->factory()->SetRegExpAtomData(re,
JSRegExp::ATOM,
pattern,
flags,
match_pattern);
isolate->factory()->SetRegExpAtomData(re, JSRegExp::ATOM, pattern, flags,
match_pattern);
}
static void SetAtomLastCapture(Handle<RegExpMatchInfo> last_match_info,
static void SetAtomLastCapture(Isolate* isolate,
Handle<RegExpMatchInfo> last_match_info,
String* subject, int from, int to) {
SealHandleScope shs(last_match_info->GetIsolate());
SealHandleScope shs(isolate);
last_match_info->SetNumberOfCaptureRegisters(2);
last_match_info->SetLastSubject(subject);
last_match_info->SetLastInput(subject);
......@@ -225,14 +220,9 @@ static void SetAtomLastCapture(Handle<RegExpMatchInfo> last_match_info,
last_match_info->SetCapture(1, to);
}
int RegExpImpl::AtomExecRaw(Handle<JSRegExp> regexp,
Handle<String> subject,
int index,
int32_t* output,
int RegExpImpl::AtomExecRaw(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject, int index, int32_t* output,
int output_size) {
Isolate* isolate = regexp->GetIsolate();
DCHECK_LE(0, index);
DCHECK_LE(index, subject->length());
......@@ -277,22 +267,21 @@ int RegExpImpl::AtomExecRaw(Handle<JSRegExp> regexp,
return output_size / 2;
}
Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, Handle<String> subject,
int index,
Handle<Object> RegExpImpl::AtomExec(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> subject, int index,
Handle<RegExpMatchInfo> last_match_info) {
Isolate* isolate = re->GetIsolate();
static const int kNumRegisters = 2;
STATIC_ASSERT(kNumRegisters <= Isolate::kJSRegexpStaticOffsetsVectorSize);
int32_t* output_registers = isolate->jsregexp_static_offsets_vector();
int res = AtomExecRaw(re, subject, index, output_registers, kNumRegisters);
int res =
AtomExecRaw(isolate, re, subject, index, output_registers, kNumRegisters);
if (res == RegExpImpl::RE_FAILURE) return isolate->factory()->null_value();
DCHECK_EQ(res, RegExpImpl::RE_SUCCESS);
SealHandleScope shs(isolate);
SetAtomLastCapture(last_match_info, *subject, output_registers[0],
SetAtomLastCapture(isolate, last_match_info, *subject, output_registers[0],
output_registers[1]);
return last_match_info;
}
......@@ -306,7 +295,7 @@ Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, Handle<String> subject,
// from the source pattern.
// If compilation fails, an exception is thrown and this function
// returns false.
bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re,
bool RegExpImpl::EnsureCompiledIrregexp(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> sample_subject,
bool is_one_byte) {
Object* compiled_code = re->DataAt(JSRegExp::code_index(is_one_byte));
......@@ -315,15 +304,13 @@ bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re,
#else // V8_INTERPRETED_REGEXP (RegExp native code)
if (compiled_code->IsCode()) return true;
#endif
return CompileIrregexp(re, sample_subject, is_one_byte);
return CompileIrregexp(isolate, re, sample_subject, is_one_byte);
}
bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
bool RegExpImpl::CompileIrregexp(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> sample_subject,
bool is_one_byte) {
// Compile the RegExp.
Isolate* isolate = re->GetIsolate();
Zone zone(isolate->allocator(), ZONE_NAME);
PostponeInterruptsScope postpone(isolate);
#ifdef DEBUG
......@@ -345,7 +332,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
&compile_data)) {
// Throw an exception if we fail to parse the pattern.
// THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once.
USE(ThrowRegExpException(re, pattern, compile_data.error));
USE(ThrowRegExpException(isolate, re, pattern, compile_data.error));
return false;
}
RegExpEngine::CompilationResult result =
......@@ -359,11 +346,12 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
}
Handle<String> error_message = isolate->factory()->NewStringFromUtf8(
CStrVector(result.error_message)).ToHandleChecked();
ThrowRegExpException(re, error_message);
ThrowRegExpException(isolate, re, error_message);
return false;
}
Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data()));
Handle<FixedArray> data =
Handle<FixedArray>(FixedArray::cast(re->data()), isolate);
data->set(JSRegExp::code_index(is_one_byte), result.code);
SetIrregexpCaptureNameMap(*data, compile_data.capture_name_map);
int register_max = IrregexpMaxRegisterCount(*data);
......@@ -413,27 +401,21 @@ Code* RegExpImpl::IrregexpNativeCode(FixedArray* re, bool is_one_byte) {
return Code::cast(re->get(JSRegExp::code_index(is_one_byte)));
}
void RegExpImpl::IrregexpInitialize(Handle<JSRegExp> re,
void RegExpImpl::IrregexpInitialize(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> pattern,
JSRegExp::Flags flags,
int capture_count) {
JSRegExp::Flags flags, int capture_count) {
// Initialize compiled code entries to null.
re->GetIsolate()->factory()->SetRegExpIrregexpData(re,
JSRegExp::IRREGEXP,
pattern,
flags,
capture_count);
isolate->factory()->SetRegExpIrregexpData(re, JSRegExp::IRREGEXP, pattern,
flags, capture_count);
}
int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp,
int RegExpImpl::IrregexpPrepare(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject) {
DCHECK(subject->IsFlat());
// Check representation of the underlying storage.
bool is_one_byte = subject->IsOneByteRepresentationUnderneath();
if (!EnsureCompiledIrregexp(regexp, subject, is_one_byte)) return -1;
if (!EnsureCompiledIrregexp(isolate, regexp, subject, is_one_byte)) return -1;
#ifdef V8_INTERPRETED_REGEXP
// Byte-code regexp needs space allocated for all its registers.
......@@ -449,14 +431,9 @@ int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp,
#endif // V8_INTERPRETED_REGEXP
}
int RegExpImpl::IrregexpExecRaw(Handle<JSRegExp> regexp,
Handle<String> subject,
int index,
int32_t* output,
int output_size) {
Isolate* isolate = regexp->GetIsolate();
int RegExpImpl::IrregexpExecRaw(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject, int index,
int32_t* output, int output_size) {
Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()), isolate);
DCHECK_LE(0, index);
......@@ -468,7 +445,7 @@ int RegExpImpl::IrregexpExecRaw(Handle<JSRegExp> regexp,
#ifndef V8_INTERPRETED_REGEXP
DCHECK(output_size >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2);
do {
EnsureCompiledIrregexp(regexp, subject, is_one_byte);
EnsureCompiledIrregexp(isolate, regexp, subject, is_one_byte);
Handle<Code> code(IrregexpNativeCode(*irregexp, is_one_byte), isolate);
// The stack is used to allocate registers for the compiled regexp code.
// This means that in case of failure, the output registers array is left
......@@ -498,7 +475,7 @@ int RegExpImpl::IrregexpExecRaw(Handle<JSRegExp> regexp,
// the, potentially, different subject (the string can switch between
// being internal and external, and even between being Latin1 and UC16,
// but the characters are always the same).
IrregexpPrepare(regexp, subject);
IrregexpPrepare(isolate, regexp, subject);
is_one_byte = subject->IsOneByteRepresentationUnderneath();
} while (true);
UNREACHABLE();
......@@ -537,9 +514,8 @@ int RegExpImpl::IrregexpExecRaw(Handle<JSRegExp> regexp,
}
MaybeHandle<Object> RegExpImpl::IrregexpExec(
Handle<JSRegExp> regexp, Handle<String> subject, int previous_index,
Handle<RegExpMatchInfo> last_match_info) {
Isolate* isolate = regexp->GetIsolate();
Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject,
int previous_index, Handle<RegExpMatchInfo> last_match_info) {
DCHECK_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP);
subject = String::Flatten(subject);
......@@ -552,7 +528,8 @@ MaybeHandle<Object> RegExpImpl::IrregexpExec(
PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get());
}
#endif
int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject);
int required_registers =
RegExpImpl::IrregexpPrepare(isolate, regexp, subject);
if (required_registers < 0) {
// Compiling failed with an exception.
DCHECK(isolate->has_pending_exception());
......@@ -568,13 +545,14 @@ MaybeHandle<Object> RegExpImpl::IrregexpExec(
output_registers = isolate->jsregexp_static_offsets_vector();
}
int res = RegExpImpl::IrregexpExecRaw(
regexp, subject, previous_index, output_registers, required_registers);
int res =
RegExpImpl::IrregexpExecRaw(isolate, regexp, subject, previous_index,
output_registers, required_registers);
if (res == RE_SUCCESS) {
int capture_count =
IrregexpNumberOfCaptures(FixedArray::cast(regexp->data()));
return SetLastMatchInfo(
last_match_info, subject, capture_count, output_registers);
return SetLastMatchInfo(isolate, last_match_info, subject, capture_count,
output_registers);
}
if (res == RE_EXCEPTION) {
DCHECK(isolate->has_pending_exception());
......@@ -585,8 +563,8 @@ MaybeHandle<Object> RegExpImpl::IrregexpExec(
}
Handle<RegExpMatchInfo> RegExpImpl::SetLastMatchInfo(
Handle<RegExpMatchInfo> last_match_info, Handle<String> subject,
int capture_count, int32_t* match) {
Isolate* isolate, Handle<RegExpMatchInfo> last_match_info,
Handle<String> subject, int capture_count, int32_t* match) {
// This is the only place where match infos can grow. If, after executing the
// regexp, RegExpExecStub finds that the match info is too small, it restarts
// execution in RegExpImpl::Exec, which finally grows the match info right
......@@ -600,7 +578,6 @@ Handle<RegExpMatchInfo> RegExpImpl::SetLastMatchInfo(
if (*result != *last_match_info) {
// The match info has been reallocated, update the corresponding reference
// on the native context.
Isolate* isolate = last_match_info->GetIsolate();
if (*last_match_info == *isolate->regexp_last_match_info()) {
isolate->native_context()->set_regexp_last_match_info(*result);
} else if (*last_match_info == *isolate->regexp_internal_match_info()) {
......@@ -625,7 +602,8 @@ RegExpImpl::GlobalCache::GlobalCache(Handle<JSRegExp> regexp,
: register_array_(nullptr),
register_array_size_(0),
regexp_(regexp),
subject_(subject) {
subject_(subject),
isolate_(isolate) {
#ifdef V8_INTERPRETED_REGEXP
bool interpreted = true;
#else
......@@ -638,7 +616,8 @@ RegExpImpl::GlobalCache::GlobalCache(Handle<JSRegExp> regexp,
// There is no distinction between interpreted and native for atom regexps.
interpreted = false;
} else {
registers_per_match_ = RegExpImpl::IrregexpPrepare(regexp_, subject_);
registers_per_match_ =
RegExpImpl::IrregexpPrepare(isolate_, regexp_, subject_);
if (registers_per_match_ < 0) {
num_matches_ = -1; // Signal exception.
return;
......@@ -964,9 +943,9 @@ class RegExpCompiler {
return unicode_lookaround_position_register_;
}
RegExpEngine::CompilationResult Assemble(RegExpMacroAssembler* assembler,
RegExpNode* start,
int capture_count,
RegExpEngine::CompilationResult Assemble(Isolate* isolate,
RegExpMacroAssembler* assembler,
RegExpNode* start, int capture_count,
Handle<String> pattern);
inline void AddWork(RegExpNode* node) {
......@@ -1069,14 +1048,9 @@ RegExpCompiler::RegExpCompiler(Isolate* isolate, Zone* zone, int capture_count,
DCHECK_GE(RegExpMacroAssembler::kMaxRegister, next_register_ - 1);
}
RegExpEngine::CompilationResult RegExpCompiler::Assemble(
RegExpMacroAssembler* macro_assembler,
RegExpNode* start,
int capture_count,
Handle<String> pattern) {
Isolate* isolate = pattern->GetHeap()->isolate();
Isolate* isolate, RegExpMacroAssembler* macro_assembler, RegExpNode* start,
int capture_count, Handle<String> pattern) {
#ifdef DEBUG
if (FLAG_trace_regexp_assembler)
macro_assembler_ = new RegExpMacroAssemblerTracer(isolate, macro_assembler);
......@@ -6664,7 +6638,8 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
bool is_unicode = IsUnicode(flags);
RegExpCompiler compiler(isolate, zone, data->capture_count, is_one_byte);
if (compiler.optimize()) compiler.set_optimize(!TooMuchRegExpCode(pattern));
if (compiler.optimize())
compiler.set_optimize(!TooMuchRegExpCode(isolate, pattern));
// Sample some characters from the middle of the string.
static const int kSampleSize = 128;
......@@ -6771,7 +6746,7 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
RegExpMacroAssemblerIrregexp macro_assembler(isolate, codes, zone);
#endif // V8_INTERPRETED_REGEXP
macro_assembler.set_slow_safe(TooMuchRegExpCode(pattern));
macro_assembler.set_slow_safe(TooMuchRegExpCode(isolate, pattern));
// Inserted here, instead of in Assembler, because it depends on information
// in the AST that isn't replicated in the Node structure.
......@@ -6791,15 +6766,12 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
macro_assembler.set_global_mode(mode);
}
return compiler.Assemble(&macro_assembler,
node,
data->capture_count,
return compiler.Assemble(isolate, &macro_assembler, node, data->capture_count,
pattern);
}
bool RegExpEngine::TooMuchRegExpCode(Handle<String> pattern) {
Heap* heap = pattern->GetHeap();
bool RegExpEngine::TooMuchRegExpCode(Isolate* isolate, Handle<String> pattern) {
Heap* heap = isolate->heap();
bool too_much = pattern->length() > RegExpImpl::kRegExpTooLargeToOptimize;
if (heap->isolate()->total_regexp_code_generated() >
RegExpImpl::kRegExpCompiledLimit &&
......
......@@ -73,34 +73,29 @@ class RegExpImpl {
// the implementation wants to store in the data field.
// Returns false if compilation fails.
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Compile(
Handle<JSRegExp> re, Handle<String> pattern, JSRegExp::Flags flags);
Isolate* isolate, Handle<JSRegExp> re, Handle<String> pattern,
JSRegExp::Flags flags);
// See ECMA-262 section 15.10.6.2.
// This function calls the garbage collector if necessary.
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Exec(
Handle<JSRegExp> regexp, Handle<String> subject, int index,
Handle<RegExpMatchInfo> last_match_info);
Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject,
int index, Handle<RegExpMatchInfo> last_match_info);
// Prepares a JSRegExp object with Irregexp-specific data.
static void IrregexpInitialize(Handle<JSRegExp> re,
Handle<String> pattern,
JSRegExp::Flags flags,
static void IrregexpInitialize(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> pattern, JSRegExp::Flags flags,
int capture_register_count);
static void AtomCompile(Handle<JSRegExp> re,
Handle<String> pattern,
JSRegExp::Flags flags,
static void AtomCompile(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> pattern, JSRegExp::Flags flags,
Handle<String> match_pattern);
static int AtomExecRaw(Handle<JSRegExp> regexp,
Handle<String> subject,
int index,
int32_t* output,
static int AtomExecRaw(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject, int index, int32_t* output,
int output_size);
static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
static Handle<Object> AtomExec(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject, int index,
Handle<RegExpMatchInfo> last_match_info);
......@@ -113,7 +108,7 @@ class RegExpImpl {
// Returns the number of integer spaces required by IrregexpExecOnce
// as its "registers" argument. If the regexp cannot be compiled,
// an exception is set as pending, and this function returns negative.
static int IrregexpPrepare(Handle<JSRegExp> regexp,
static int IrregexpPrepare(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject);
// Execute a regular expression on the subject, starting from index.
......@@ -122,10 +117,8 @@ class RegExpImpl {
// The captures and subcaptures are stored into the registers vector.
// If matching fails, returns RE_FAILURE.
// If execution fails, sets a pending exception and returns RE_EXCEPTION.
static int IrregexpExecRaw(Handle<JSRegExp> regexp,
Handle<String> subject,
int index,
int32_t* output,
static int IrregexpExecRaw(Isolate* isolate, Handle<JSRegExp> regexp,
Handle<String> subject, int index, int32_t* output,
int output_size);
// Execute an Irregexp bytecode pattern.
......@@ -133,14 +126,14 @@ class RegExpImpl {
// captured positions. On a failure, the result is the null value.
// Returns an empty handle in case of an exception.
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> IrregexpExec(
Handle<JSRegExp> regexp, Handle<String> subject, int index,
Handle<RegExpMatchInfo> last_match_info);
Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject,
int index, Handle<RegExpMatchInfo> last_match_info);
// Set last match info. If match is nullptr, then setting captures is
// omitted.
static Handle<RegExpMatchInfo> SetLastMatchInfo(
Handle<RegExpMatchInfo> last_match_info, Handle<String> subject,
int capture_count, int32_t* match);
Isolate* isolate, Handle<RegExpMatchInfo> last_match_info,
Handle<String> subject, int capture_count, int32_t* match);
class GlobalCache {
public:
......@@ -172,6 +165,7 @@ class RegExpImpl {
int register_array_size_;
Handle<JSRegExp> regexp_;
Handle<String> subject_;
Isolate* isolate_;
};
// For acting on the JSRegExp data FixedArray.
......@@ -194,9 +188,10 @@ class RegExpImpl {
static const int kRegExpTooLargeToOptimize = 20 * KB;
private:
static bool CompileIrregexp(Handle<JSRegExp> re,
static bool CompileIrregexp(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> sample_subject, bool is_one_byte);
static inline bool EnsureCompiledIrregexp(Handle<JSRegExp> re,
static inline bool EnsureCompiledIrregexp(Isolate* isolate,
Handle<JSRegExp> re,
Handle<String> sample_subject,
bool is_one_byte);
};
......@@ -1535,7 +1530,7 @@ class RegExpEngine: public AllStatic {
Handle<String> sample_subject,
bool is_one_byte);
static bool TooMuchRegExpCode(Handle<String> pattern);
static bool TooMuchRegExpCode(Isolate* isolate, Handle<String> pattern);
static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
};
......
......@@ -601,7 +601,8 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalAtomRegExpWithString(
}
int32_t match_indices[] = {indices->back(), indices->back() + pattern_len};
RegExpImpl::SetLastMatchInfo(last_match_info, subject, 0, match_indices);
RegExpImpl::SetLastMatchInfo(isolate, last_match_info, subject, 0,
match_indices);
TruncateRegexpIndicesList(isolate);
......@@ -620,7 +621,7 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalRegExpWithString(
JSRegExp::Type typeTag = regexp->TypeTag();
if (typeTag == JSRegExp::IRREGEXP) {
// Ensure the RegExp is compiled so we can access the capture-name map.
if (RegExpImpl::IrregexpPrepare(regexp, subject) == -1) {
if (RegExpImpl::IrregexpPrepare(isolate, regexp, subject) == -1) {
DCHECK(isolate->has_pending_exception());
return isolate->heap()->exception();
}
......@@ -692,7 +693,7 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalRegExpWithString(
builder.AddSubjectSlice(prev, subject_length);
}
RegExpImpl::SetLastMatchInfo(last_match_info, subject, capture_count,
RegExpImpl::SetLastMatchInfo(isolate, last_match_info, subject, capture_count,
global_cache.LastSuccessfulMatch());
RETURN_RESULT_OR_FAILURE(isolate, builder.ToString());
......@@ -760,7 +761,7 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalRegExpWithEmptyString(
if (global_cache.HasException()) return isolate->heap()->exception();
RegExpImpl::SetLastMatchInfo(last_match_info, subject, capture_count,
RegExpImpl::SetLastMatchInfo(isolate, last_match_info, subject, capture_count,
global_cache.LastSuccessfulMatch());
if (prev < subject_length) {
......@@ -915,8 +916,8 @@ RUNTIME_FUNCTION(Runtime_RegExpExec) {
CHECK_LE(0, index);
CHECK_GE(subject->length(), index);
isolate->counters()->regexp_entry_runtime()->Increment();
RETURN_RESULT_OR_FAILURE(
isolate, RegExpImpl::Exec(regexp, subject, index, last_match_info));
RETURN_RESULT_OR_FAILURE(isolate, RegExpImpl::Exec(isolate, regexp, subject,
index, last_match_info));
}
RUNTIME_FUNCTION(Runtime_RegExpInternalReplace) {
......@@ -1160,8 +1161,8 @@ static Object* SearchRegExpMultiple(Isolate* isolate, Handle<String> subject,
isolate->factory()->CopyFixedArrayWithMap(
cached_fixed_array, isolate->factory()->fixed_array_map());
JSArray::SetContent(result_array, copied_fixed_array);
RegExpImpl::SetLastMatchInfo(last_match_array, subject, capture_count,
last_match);
RegExpImpl::SetLastMatchInfo(isolate, last_match_array, subject,
capture_count, last_match);
DeleteArray(last_match);
return *result_array;
}
......@@ -1269,7 +1270,8 @@ static Object* SearchRegExpMultiple(Isolate* isolate, Handle<String> subject,
subject_length);
}
RegExpImpl::SetLastMatchInfo(last_match_array, subject, capture_count,
RegExpImpl::SetLastMatchInfo(isolate, last_match_array, subject,
capture_count,
global_cache.LastSuccessfulMatch());
if (subject_length > kMinLengthToCache) {
......@@ -1337,7 +1339,8 @@ V8_WARN_UNUSED_RESULT MaybeHandle<String> RegExpReplace(
Handle<Object> match_indices_obj;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, match_indices_obj,
RegExpImpl::Exec(regexp, string, last_index, last_match_info), String);
RegExpImpl::Exec(isolate, regexp, string, last_index, last_match_info),
String);
if (match_indices_obj->IsNull(isolate)) {
if (sticky) regexp->set_last_index(Smi::kZero, SKIP_WRITE_BARRIER);
......@@ -1456,7 +1459,7 @@ RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) {
Handle<Object> match_indices_obj;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, match_indices_obj,
RegExpImpl::Exec(regexp, subject, last_index, last_match_info));
RegExpImpl::Exec(isolate, regexp, subject, last_index, last_match_info));
if (match_indices_obj->IsNull(isolate)) {
if (sticky) regexp->set_last_index(Smi::kZero, SKIP_WRITE_BARRIER);
......
......@@ -18,8 +18,9 @@ void Test(v8::Isolate* isolate, i::Handle<i::JSRegExp> regexp,
i::Handle<i::String> subject,
i::Handle<i::RegExpMatchInfo> results_array) {
v8::TryCatch try_catch(isolate);
if (i::RegExpImpl::Exec(regexp, subject, 0, results_array).is_null()) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
if (i::RegExpImpl::Exec(i_isolate, regexp, subject, 0, results_array)
.is_null()) {
i_isolate->OptionalRescheduleException(true);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment