Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Unified Diff: src/messages.cc

Issue 1087633005: Start migrating error message templates to the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix windows build Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/messages.h ('k') | src/messages.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.cc
diff --git a/src/messages.cc b/src/messages.cc
index 290f756770c7d4b287ee2f5ce6d5b2326b7fe521..fd6dae86eced868bb313264367aff4e8746cf3ca 100644
--- a/src/messages.cc
+++ b/src/messages.cc
@@ -8,6 +8,7 @@
#include "src/execution.h"
#include "src/heap/spaces-inl.h"
#include "src/messages.h"
+#include "src/string-builder.h"
namespace v8 {
namespace internal {
@@ -162,4 +163,39 @@ SmartArrayPointer<char> MessageHandler::GetLocalizedMessage(
}
+MaybeHandle<String> MessageTemplate::FormatMessage(int template_index,
+ Handle<String> arg0,
+ Handle<String> arg1,
+ Handle<String> arg2) {
+ const char* template_string;
+ switch (template_index) {
+#define CASE(NAME, STRING) \
+ case k##NAME: \
+ template_string = STRING; \
+ break;
+ MESSAGE_TEMPLATES(CASE)
+#undef CASE
+ case kLastMessage:
+ default:
+ UNREACHABLE();
+ template_string = "";
+ break;
+ }
+
+ Isolate* isolate = arg0->GetIsolate();
+ IncrementalStringBuilder builder(isolate);
+
+ int i = 0;
+ Handle<String> args[] = {arg0, arg1, arg2};
+ for (const char* c = template_string; *c != '\0'; c++) {
+ if (*c == '%') {
+ builder.AppendString(args[i++]);
+ DCHECK(i < arraysize(args));
+ } else {
+ builder.AppendCharacter(*c);
+ }
+ }
+
+ return builder.Finish();
+}
} } // namespace v8::internal
« no previous file with comments | « src/messages.h ('k') | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698