Commit 91b9a923 authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Addressing Mads' comments from http://codereview.chromium.org/3585010/show.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5588 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a3e66d2d
......@@ -1372,6 +1372,10 @@ class Date : public Value {
*/
class RegExp : public Value {
public:
/**
* Regular expression flag bits. They can be or'ed to enable a set
* of flags.
*/
enum Flags {
kNone = 0,
kGlobal = 1,
......@@ -1379,6 +1383,16 @@ class RegExp : public Value {
kMultiline = 4
};
/**
* Creates a regular expression from the given pattern string and
* the flags bit field. May throw a JavaScript exception as
* described in ECMA-252, 15.10.4.1.
*
* For example,
* RegExp::New(v8::String::New("foo"),
* static_cast<RegExp::Flags>(kGlobal | kMultiline))
* is equivalent to evaluating "/foo/gm".
*/
V8EXPORT static Local<RegExp> New(Handle<String> pattern,
Flags flags);
......@@ -1388,6 +1402,9 @@ class RegExp : public Value {
*/
V8EXPORT Local<String> GetSource() const;
/**
* Returns the flags bit field.
*/
V8EXPORT Flags GetFlags() const;
static inline RegExp* Cast(v8::Value* obj);
......
......@@ -3754,14 +3754,9 @@ Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern,
LOG_API("RegExp::New");
ENTER_V8;
EXCEPTION_PREAMBLE();
i::Handle<i::String> flags_string = RegExpFlagsToString(flags);
i::Object** argv[2] = {
i::Handle<i::Object>::cast(Utils::OpenHandle(*pattern)).location(),
i::Handle<i::Object>::cast(flags_string).location()
};
i::Handle<i::Object> obj = i::Execution::New(
i::Handle<i::JSFunction>(i::Top::global_context()->regexp_function()),
2, argv,
i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp(
Utils::OpenHandle(*pattern),
RegExpFlagsToString(flags),
&has_pending_exception);
EXCEPTION_BAILOUT_CHECK(Local<v8::RegExp>());
return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj));
......
......@@ -473,6 +473,19 @@ Handle<Object> Execution::NewDate(double time, bool* exc) {
#undef RETURN_NATIVE_CALL
Handle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern,
Handle<String> flags,
bool* exc) {
Handle<Object> re_obj = RegExpImpl::CreateRegExpLiteral(
Handle<JSFunction>(Top::global_context()->regexp_function()),
pattern,
flags,
exc);
if (*exc) return Handle<JSRegExp>();
return Handle<JSRegExp>::cast(re_obj);
}
Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
int int_index = static_cast<int>(index);
if (int_index < 0 || int_index >= string->length()) {
......
......@@ -105,6 +105,11 @@ class Execution : public AllStatic {
// Create a new date object from 'time'.
static Handle<Object> NewDate(double time, bool* exc);
// Create a new regular expression object from 'pattern' and 'flags'.
static Handle<JSRegExp> NewJSRegExp(Handle<String> pattern,
Handle<String> flags,
bool* exc);
// Used to implement [] notation on strings (calls JS code)
static Handle<Object> CharAt(Handle<String> str, uint32_t index);
......
......@@ -11715,4 +11715,11 @@ TEST(RegExp) {
context->Global()->Set(v8_str("re"), re);
ExpectTrue("re.test('FoobarbaZ')");
v8::TryCatch try_catch;
re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone);
CHECK(re.IsEmpty());
CHECK(try_catch.HasCaught());
context->Global()->Set(v8_str("ex"), try_catch.Exception());
ExpectTrue("ex instanceof SyntaxError");
}
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