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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // other operations that are likely to take place (see GetLocalizedMessage | 325 // other operations that are likely to take place (see GetLocalizedMessage |
326 // for example). | 326 // for example). |
327 return String::Flatten(result_string); | 327 return String::Flatten(result_string); |
328 } | 328 } |
329 | 329 |
330 | 330 |
331 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, | 331 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, |
332 Handle<String> arg0, | 332 Handle<String> arg0, |
333 Handle<String> arg1, | 333 Handle<String> arg1, |
334 Handle<String> arg2) { | 334 Handle<String> arg2) { |
335 static const int kMaxArgLength = 256; | |
336 Isolate* isolate = arg0->GetIsolate(); | 335 Isolate* isolate = arg0->GetIsolate(); |
337 const char* template_string; | 336 const char* template_string; |
338 switch (template_index) { | 337 switch (template_index) { |
339 #define CASE(NAME, STRING) \ | 338 #define CASE(NAME, STRING) \ |
340 case k##NAME: \ | 339 case k##NAME: \ |
341 template_string = STRING; \ | 340 template_string = STRING; \ |
342 break; | 341 break; |
343 MESSAGE_TEMPLATES(CASE) | 342 MESSAGE_TEMPLATES(CASE) |
344 #undef CASE | 343 #undef CASE |
345 case kLastMessage: | 344 case kLastMessage: |
346 default: | 345 default: |
347 isolate->ThrowIllegalOperation(); | 346 isolate->ThrowIllegalOperation(); |
348 return MaybeHandle<String>(); | 347 return MaybeHandle<String>(); |
349 } | 348 } |
350 | 349 |
351 IncrementalStringBuilder builder(isolate); | 350 IncrementalStringBuilder builder(isolate); |
352 | 351 |
353 unsigned int i = 0; | 352 unsigned int i = 0; |
354 Handle<String> args[] = {arg0, arg1, arg2}; | 353 Handle<String> args[] = {arg0, arg1, arg2}; |
355 for (const char* c = template_string; *c != '\0'; c++) { | 354 for (const char* c = template_string; *c != '\0'; c++) { |
356 if (*c == '%') { | 355 if (*c == '%') { |
357 // %% results in verbatim %. | 356 // %% results in verbatim %. |
358 if (*(c + 1) == '%') { | 357 if (*(c + 1) == '%') { |
359 c++; | 358 c++; |
360 builder.AppendCharacter('%'); | 359 builder.AppendCharacter('%'); |
361 } else { | 360 } else { |
362 DCHECK(i < arraysize(args)); | 361 DCHECK(i < arraysize(args)); |
363 Handle<String> arg = args[i++]; | 362 Handle<String> arg = args[i++]; |
364 int length = arg->length(); | 363 builder.AppendString(arg); |
365 if (length > kMaxArgLength) { | |
366 builder.AppendString( | |
367 isolate->factory()->NewSubString(arg, 0, kMaxArgLength - 6)); | |
368 builder.AppendCString("..."); | |
369 builder.AppendString( | |
370 isolate->factory()->NewSubString(arg, length - 3, length)); | |
371 } else { | |
372 builder.AppendString(arg); | |
373 } | |
374 } | 364 } |
375 } else { | 365 } else { |
376 builder.AppendCharacter(*c); | 366 builder.AppendCharacter(*c); |
377 } | 367 } |
378 } | 368 } |
379 | 369 |
380 return builder.Finish(); | 370 return builder.Finish(); |
381 } | 371 } |
382 } // namespace internal | 372 } // namespace internal |
383 } // namespace v8 | 373 } // namespace v8 |
OLD | NEW |