Throw illegal exception when formatting with invalid template index.
authoryangguo <yangguo@chromium.org>
Thu, 28 May 2015 07:05:01 +0000 (00:05 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 28 May 2015 07:05:12 +0000 (07:05 +0000)
R=arv@chromium.org
BUG=chromium:492526
LOG=N

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

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

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

index daf6c82..84ce4c3 100644 (file)
@@ -331,6 +331,7 @@ MaybeHandle<String> MessageTemplate::FormatMessage(int template_index,
                                                    Handle<String> arg0,
                                                    Handle<String> arg1,
                                                    Handle<String> arg2) {
+  Isolate* isolate = arg0->GetIsolate();
   const char* template_string;
   switch (template_index) {
 #define CASE(NAME, STRING)    \
@@ -341,12 +342,10 @@ MaybeHandle<String> MessageTemplate::FormatMessage(int template_index,
 #undef CASE
     case kLastMessage:
     default:
-      UNREACHABLE();
-      template_string = "";
-      break;
+      isolate->ThrowIllegalOperation();
+      return MaybeHandle<String>();
   }
 
-  Isolate* isolate = arg0->GetIsolate();
   IncrementalStringBuilder builder(isolate);
 
   unsigned int i = 0;
diff --git a/test/mjsunit/regress/regress-crbug-492526.js b/test/mjsunit/regress/regress-crbug-492526.js
new file mode 100644 (file)
index 0000000..e8ea298
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2015 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.
+
+// Flags: --allow-natives-syntax
+
+assertThrows(function() { %FormatMessageString(-1, "", "", ""); });