OLD | NEW |
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" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // other operations that are likely to take place (see GetLocalizedMessage | 305 // other operations that are likely to take place (see GetLocalizedMessage |
306 // for example). | 306 // for example). |
307 return String::Flatten(result_string); | 307 return String::Flatten(result_string); |
308 } | 308 } |
309 | 309 |
310 | 310 |
311 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, | 311 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, |
312 Handle<String> arg0, | 312 Handle<String> arg0, |
313 Handle<String> arg1, | 313 Handle<String> arg1, |
314 Handle<String> arg2) { | 314 Handle<String> arg2) { |
| 315 Isolate* isolate = arg0->GetIsolate(); |
315 const char* template_string; | 316 const char* template_string; |
316 switch (template_index) { | 317 switch (template_index) { |
317 #define CASE(NAME, STRING) \ | 318 #define CASE(NAME, STRING) \ |
318 case k##NAME: \ | 319 case k##NAME: \ |
319 template_string = STRING; \ | 320 template_string = STRING; \ |
320 break; | 321 break; |
321 MESSAGE_TEMPLATES(CASE) | 322 MESSAGE_TEMPLATES(CASE) |
322 #undef CASE | 323 #undef CASE |
323 case kLastMessage: | 324 case kLastMessage: |
324 default: | 325 default: |
325 UNREACHABLE(); | 326 isolate->ThrowIllegalOperation(); |
326 template_string = ""; | 327 return MaybeHandle<String>(); |
327 break; | |
328 } | 328 } |
329 | 329 |
330 Isolate* isolate = arg0->GetIsolate(); | |
331 IncrementalStringBuilder builder(isolate); | 330 IncrementalStringBuilder builder(isolate); |
332 | 331 |
333 unsigned int i = 0; | 332 unsigned int i = 0; |
334 Handle<String> args[] = {arg0, arg1, arg2}; | 333 Handle<String> args[] = {arg0, arg1, arg2}; |
335 for (const char* c = template_string; *c != '\0'; c++) { | 334 for (const char* c = template_string; *c != '\0'; c++) { |
336 if (*c == '%') { | 335 if (*c == '%') { |
337 // %% results in verbatim %. | 336 // %% results in verbatim %. |
338 if (*(c + 1) == '%') { | 337 if (*(c + 1) == '%') { |
339 c++; | 338 c++; |
340 builder.AppendCharacter('%'); | 339 builder.AppendCharacter('%'); |
341 } else { | 340 } else { |
342 DCHECK(i < arraysize(args)); | 341 DCHECK(i < arraysize(args)); |
343 builder.AppendString(args[i++]); | 342 builder.AppendString(args[i++]); |
344 } | 343 } |
345 } else { | 344 } else { |
346 builder.AppendCharacter(*c); | 345 builder.AppendCharacter(*c); |
347 } | 346 } |
348 } | 347 } |
349 | 348 |
350 return builder.Finish(); | 349 return builder.Finish(); |
351 } | 350 } |
352 } } // namespace v8::internal | 351 } } // namespace v8::internal |
OLD | NEW |