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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/messages.h ('k') | src/messages.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/execution.h" 8 #include "src/execution.h"
9 #include "src/heap/spaces-inl.h" 9 #include "src/heap/spaces-inl.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
11 #include "src/string-builder.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace internal { 14 namespace internal {
14 15
15 16
16 // If no message listeners have been registered this one is called 17 // If no message listeners have been registered this one is called
17 // by default. 18 // by default.
18 void MessageHandler::DefaultMessageReport(Isolate* isolate, 19 void MessageHandler::DefaultMessageReport(Isolate* isolate,
19 const MessageLocation* loc, 20 const MessageLocation* loc,
20 Handle<Object> message_obj) { 21 Handle<Object> message_obj) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 156
156 157
157 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( 158 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage(
158 Isolate* isolate, 159 Isolate* isolate,
159 Handle<Object> data) { 160 Handle<Object> data) {
160 HandleScope scope(isolate); 161 HandleScope scope(isolate);
161 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); 162 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS);
162 } 163 }
163 164
164 165
166 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index,
167 Handle<String> arg0,
168 Handle<String> arg1,
169 Handle<String> arg2) {
170 const char* template_string;
171 switch (template_index) {
172 #define CASE(NAME, STRING) \
173 case k##NAME: \
174 template_string = STRING; \
175 break;
176 MESSAGE_TEMPLATES(CASE)
177 #undef CASE
178 case kLastMessage:
179 default:
180 UNREACHABLE();
181 template_string = "";
182 break;
183 }
184
185 Isolate* isolate = arg0->GetIsolate();
186 IncrementalStringBuilder builder(isolate);
187
188 int i = 0;
189 Handle<String> args[] = {arg0, arg1, arg2};
190 for (const char* c = template_string; *c != '\0'; c++) {
191 if (*c == '%') {
192 builder.AppendString(args[i++]);
193 DCHECK(i < arraysize(args));
194 } else {
195 builder.AppendCharacter(*c);
196 }
197 }
198
199 return builder.Finish();
200 }
165 } } // namespace v8::internal 201 } } // namespace v8::internal
OLDNEW
« 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