Fix RegExp.source for uncompiled regexp.
authoryangguo <yangguo@chromium.org>
Mon, 24 Nov 2014 11:21:45 +0000 (03:21 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 24 Nov 2014 11:21:52 +0000 (11:21 +0000)
R=jkummerow@chromium.org
BUG=435825
LOG=N

Review URL: https://codereview.chromium.org/753983002

Cr-Commit-Position: refs/heads/master@{#25476}

src/accessors.cc
test/mjsunit/regress/regress-crbug-435825.js [new file with mode: 0644]

index c108236b855703b6b3e0398d52fd862520c72eae..6b7ec058d93c59bfda56bf936dba56b5fcee9ecc 100644 (file)
@@ -385,13 +385,16 @@ void Accessors::RegExpSourceGetter(
   Handle<Object> receiver =
       Utils::OpenHandle(*v8::Local<v8::Value>(info.This()));
   Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(receiver);
-  Handle<String> pattern(regexp->Pattern(), isolate);
-  MaybeHandle<String> maybe = EscapeRegExpSource(isolate, pattern);
-
   Handle<String> result;
-  if (!maybe.ToHandle(&result)) {
-    isolate->OptionalRescheduleException(false);
-    return;
+  if (regexp->TypeTag() == JSRegExp::NOT_COMPILED) {
+    result = isolate->factory()->empty_string();
+  } else {
+    Handle<String> pattern(regexp->Pattern(), isolate);
+    MaybeHandle<String> maybe = EscapeRegExpSource(isolate, pattern);
+    if (!maybe.ToHandle(&result)) {
+      isolate->OptionalRescheduleException(false);
+      return;
+    }
   }
   info.GetReturnValue().Set(Utils::ToLocal(result));
 }
diff --git a/test/mjsunit/regress/regress-crbug-435825.js b/test/mjsunit/regress/regress-crbug-435825.js
new file mode 100644 (file)
index 0000000..e10b812
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+Error.prepareStackTrace = function (a,b) { return b; };
+
+try {
+  /(invalid regexp/;
+} catch (e) {
+  e.stack[0].getThis().toString();
+}