*/
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,
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);
*/
V8EXPORT Local<String> GetSource() const;
+ /**
+ * Returns the flags bit field.
+ */
V8EXPORT Flags GetFlags() const;
static inline RegExp* Cast(v8::Value* obj);
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));
#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()) {
// 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);
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");
}