Commit 93f5bfdb authored by lrn@chromium.org's avatar lrn@chromium.org

Make the irregexp interpreter throw on stack overflow.

BUG=v8:904

Review URL: http://codereview.chromium.org/8387027

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9780 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f8f8c672
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
#include "utils.h" #include "utils.h"
#include "ast.h" #include "ast.h"
#include "bytecodes-irregexp.h" #include "bytecodes-irregexp.h"
#include "jsregexp.h"
#include "interpreter-irregexp.h" #include "interpreter-irregexp.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -187,7 +187,7 @@ class BacktrackStack { ...@@ -187,7 +187,7 @@ class BacktrackStack {
template <typename Char> template <typename Char>
static bool RawMatch(Isolate* isolate, static RegExpImpl::IrregexpResult RawMatch(Isolate* isolate,
const byte* code_base, const byte* code_base,
Vector<const Char> subject, Vector<const Char> subject,
int* registers, int* registers,
...@@ -211,24 +211,24 @@ static bool RawMatch(Isolate* isolate, ...@@ -211,24 +211,24 @@ static bool RawMatch(Isolate* isolate,
switch (insn & BYTECODE_MASK) { switch (insn & BYTECODE_MASK) {
BYTECODE(BREAK) BYTECODE(BREAK)
UNREACHABLE(); UNREACHABLE();
return false; return RegExpImpl::RE_FAILURE;
BYTECODE(PUSH_CP) BYTECODE(PUSH_CP)
if (--backtrack_stack_space < 0) { if (--backtrack_stack_space < 0) {
return false; // No match on backtrack stack overflow. return RegExpImpl::RE_EXCEPTION;
} }
*backtrack_sp++ = current; *backtrack_sp++ = current;
pc += BC_PUSH_CP_LENGTH; pc += BC_PUSH_CP_LENGTH;
break; break;
BYTECODE(PUSH_BT) BYTECODE(PUSH_BT)
if (--backtrack_stack_space < 0) { if (--backtrack_stack_space < 0) {
return false; // No match on backtrack stack overflow. return RegExpImpl::RE_EXCEPTION;
} }
*backtrack_sp++ = Load32Aligned(pc + 4); *backtrack_sp++ = Load32Aligned(pc + 4);
pc += BC_PUSH_BT_LENGTH; pc += BC_PUSH_BT_LENGTH;
break; break;
BYTECODE(PUSH_REGISTER) BYTECODE(PUSH_REGISTER)
if (--backtrack_stack_space < 0) { if (--backtrack_stack_space < 0) {
return false; // No match on backtrack stack overflow. return RegExpImpl::RE_EXCEPTION;
} }
*backtrack_sp++ = registers[insn >> BYTECODE_SHIFT]; *backtrack_sp++ = registers[insn >> BYTECODE_SHIFT];
pc += BC_PUSH_REGISTER_LENGTH; pc += BC_PUSH_REGISTER_LENGTH;
...@@ -278,9 +278,9 @@ static bool RawMatch(Isolate* isolate, ...@@ -278,9 +278,9 @@ static bool RawMatch(Isolate* isolate,
pc += BC_POP_REGISTER_LENGTH; pc += BC_POP_REGISTER_LENGTH;
break; break;
BYTECODE(FAIL) BYTECODE(FAIL)
return false; return RegExpImpl::RE_FAILURE;
BYTECODE(SUCCEED) BYTECODE(SUCCEED)
return true; return RegExpImpl::RE_SUCCESS;
BYTECODE(ADVANCE_CP) BYTECODE(ADVANCE_CP)
current += insn >> BYTECODE_SHIFT; current += insn >> BYTECODE_SHIFT;
pc += BC_ADVANCE_CP_LENGTH; pc += BC_ADVANCE_CP_LENGTH;
...@@ -625,7 +625,8 @@ static bool RawMatch(Isolate* isolate, ...@@ -625,7 +625,8 @@ static bool RawMatch(Isolate* isolate,
} }
bool IrregexpInterpreter::Match(Isolate* isolate, RegExpImpl::IrregexpResult IrregexpInterpreter::Match(
Isolate* isolate,
Handle<ByteArray> code_array, Handle<ByteArray> code_array,
Handle<String> subject, Handle<String> subject,
int* registers, int* registers,
......
// Copyright 2008 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -36,7 +36,7 @@ namespace internal { ...@@ -36,7 +36,7 @@ namespace internal {
class IrregexpInterpreter { class IrregexpInterpreter {
public: public:
static bool Match(Isolate* isolate, static RegExpImpl::IrregexpResult Match(Isolate* isolate,
Handle<ByteArray> code, Handle<ByteArray> code,
Handle<String> subject, Handle<String> subject,
int* captures, int* captures,
......
...@@ -509,14 +509,16 @@ RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce( ...@@ -509,14 +509,16 @@ RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce(
} }
Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_ascii), isolate); Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_ascii), isolate);
if (IrregexpInterpreter::Match(isolate, IrregexpResult result = IrregexpInterpreter::Match(isolate,
byte_codes, byte_codes,
subject, subject,
register_vector, register_vector,
index)) { index);
return RE_SUCCESS; if (result == RE_EXCEPTION) {
ASSERT(!isolate->has_pending_exception());
isolate->StackOverflow();
} }
return RE_FAILURE; return result;
#endif // V8_INTERPRETED_REGEXP #endif // V8_INTERPRETED_REGEXP
} }
......
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