Revision: 5588
Author: [email protected]
Date: Tue Oct  5 04:51:41 2010
Log: Addressing Mads' comments from http://codereview.chromium.org/3585010/show.

Review URL: http://codereview.chromium.org/3613009
http://code.google.com/p/v8/source/detail?r=5588

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/execution.cc
 /branches/bleeding_edge/src/execution.h
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Oct  5 01:53:51 2010
+++ /branches/bleeding_edge/include/v8.h        Tue Oct  5 04:51:41 2010
@@ -1372,6 +1372,10 @@
  */
 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 @@
     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 @@
    */
   V8EXPORT Local<String> GetSource() const;

+  /**
+   * Returns the flags bit field.
+   */
   V8EXPORT Flags GetFlags() const;

   static inline RegExp* Cast(v8::Value* obj);
=======================================
--- /branches/bleeding_edge/src/api.cc  Tue Oct  5 01:53:51 2010
+++ /branches/bleeding_edge/src/api.cc  Tue Oct  5 04:51:41 2010
@@ -3754,14 +3754,9 @@
   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));
=======================================
--- /branches/bleeding_edge/src/execution.cc    Sun Aug 22 23:30:00 2010
+++ /branches/bleeding_edge/src/execution.cc    Tue Oct  5 04:51:41 2010
@@ -471,6 +471,19 @@


 #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) {
=======================================
--- /branches/bleeding_edge/src/execution.h     Thu Jun 17 09:19:28 2010
+++ /branches/bleeding_edge/src/execution.h     Tue Oct  5 04:51:41 2010
@@ -105,6 +105,11 @@
   // 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);

=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Tue Oct  5 02:07:17 2010
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Tue Oct  5 04:51:41 2010
@@ -11715,4 +11715,11 @@

   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");
+}

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to