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

Side by Side Diff: src/i18n.cc

Issue 239243018: Heap::AllocateStringFromOneByte() and major part of its callers handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing comment + some cleanup Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/heap.cc ('k') | src/jsregexp.h » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 namespace v8 { 51 namespace v8 {
52 namespace internal { 52 namespace internal {
53 53
54 namespace { 54 namespace {
55 55
56 bool ExtractStringSetting(Isolate* isolate, 56 bool ExtractStringSetting(Isolate* isolate,
57 Handle<JSObject> options, 57 Handle<JSObject> options,
58 const char* key, 58 const char* key,
59 icu::UnicodeString* setting) { 59 icu::UnicodeString* setting) {
60 Handle<String> str = isolate->factory()->NewStringFromAscii(CStrVector(key)); 60 Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(key);
61 Handle<Object> object = Object::GetProperty(options, str).ToHandleChecked(); 61 Handle<Object> object = Object::GetProperty(options, str).ToHandleChecked();
62 if (object->IsString()) { 62 if (object->IsString()) {
63 v8::String::Utf8Value utf8_string( 63 v8::String::Utf8Value utf8_string(
64 v8::Utils::ToLocal(Handle<String>::cast(object))); 64 v8::Utils::ToLocal(Handle<String>::cast(object)));
65 *setting = icu::UnicodeString::fromUTF8(*utf8_string); 65 *setting = icu::UnicodeString::fromUTF8(*utf8_string);
66 return true; 66 return true;
67 } 67 }
68 return false; 68 return false;
69 } 69 }
70 70
71 71
72 bool ExtractIntegerSetting(Isolate* isolate, 72 bool ExtractIntegerSetting(Isolate* isolate,
73 Handle<JSObject> options, 73 Handle<JSObject> options,
74 const char* key, 74 const char* key,
75 int32_t* value) { 75 int32_t* value) {
76 Handle<String> str = isolate->factory()->NewStringFromAscii(CStrVector(key)); 76 Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(key);
77 Handle<Object> object = Object::GetProperty(options, str).ToHandleChecked(); 77 Handle<Object> object = Object::GetProperty(options, str).ToHandleChecked();
78 if (object->IsNumber()) { 78 if (object->IsNumber()) {
79 object->ToInt32(value); 79 object->ToInt32(value);
80 return true; 80 return true;
81 } 81 }
82 return false; 82 return false;
83 } 83 }
84 84
85 85
86 bool ExtractBooleanSetting(Isolate* isolate, 86 bool ExtractBooleanSetting(Isolate* isolate,
87 Handle<JSObject> options, 87 Handle<JSObject> options,
88 const char* key, 88 const char* key,
89 bool* value) { 89 bool* value) {
90 Handle<String> str = isolate->factory()->NewStringFromAscii(CStrVector(key)); 90 Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(key);
91 Handle<Object> object = Object::GetProperty(options, str).ToHandleChecked(); 91 Handle<Object> object = Object::GetProperty(options, str).ToHandleChecked();
92 if (object->IsBoolean()) { 92 if (object->IsBoolean()) {
93 *value = object->BooleanValue(); 93 *value = object->BooleanValue();
94 return true; 94 return true;
95 } 95 }
96 return false; 96 return false;
97 } 97 }
98 98
99 99
100 icu::SimpleDateFormat* CreateICUDateFormat( 100 icu::SimpleDateFormat* CreateICUDateFormat(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 return date_format; 144 return date_format;
145 } 145 }
146 146
147 147
148 void SetResolvedDateSettings(Isolate* isolate, 148 void SetResolvedDateSettings(Isolate* isolate,
149 const icu::Locale& icu_locale, 149 const icu::Locale& icu_locale,
150 icu::SimpleDateFormat* date_format, 150 icu::SimpleDateFormat* date_format,
151 Handle<JSObject> resolved) { 151 Handle<JSObject> resolved) {
152 Factory* factory = isolate->factory();
152 UErrorCode status = U_ZERO_ERROR; 153 UErrorCode status = U_ZERO_ERROR;
153 icu::UnicodeString pattern; 154 icu::UnicodeString pattern;
154 date_format->toPattern(pattern); 155 date_format->toPattern(pattern);
155 JSObject::SetProperty( 156 JSObject::SetProperty(
156 resolved, 157 resolved,
157 isolate->factory()->NewStringFromAscii(CStrVector("pattern")), 158 factory->NewStringFromStaticAscii("pattern"),
158 isolate->factory()->NewStringFromTwoByte( 159 factory->NewStringFromTwoByte(
159 Vector<const uint16_t>( 160 Vector<const uint16_t>(
160 reinterpret_cast<const uint16_t*>(pattern.getBuffer()), 161 reinterpret_cast<const uint16_t*>(pattern.getBuffer()),
161 pattern.length())), 162 pattern.length())).ToHandleChecked(),
162 NONE, 163 NONE,
163 SLOPPY).Assert(); 164 SLOPPY).Assert();
164 165
165 // Set time zone and calendar. 166 // Set time zone and calendar.
166 const icu::Calendar* calendar = date_format->getCalendar(); 167 const icu::Calendar* calendar = date_format->getCalendar();
167 const char* calendar_name = calendar->getType(); 168 const char* calendar_name = calendar->getType();
168 JSObject::SetProperty( 169 JSObject::SetProperty(
169 resolved, 170 resolved,
170 isolate->factory()->NewStringFromAscii(CStrVector("calendar")), 171 factory->NewStringFromStaticAscii("calendar"),
171 isolate->factory()->NewStringFromAscii(CStrVector(calendar_name)), 172 factory->NewStringFromAsciiChecked(calendar_name),
172 NONE, 173 NONE,
173 SLOPPY).Assert(); 174 SLOPPY).Assert();
174 175
175 const icu::TimeZone& tz = calendar->getTimeZone(); 176 const icu::TimeZone& tz = calendar->getTimeZone();
176 icu::UnicodeString time_zone; 177 icu::UnicodeString time_zone;
177 tz.getID(time_zone); 178 tz.getID(time_zone);
178 179
179 icu::UnicodeString canonical_time_zone; 180 icu::UnicodeString canonical_time_zone;
180 icu::TimeZone::getCanonicalID(time_zone, canonical_time_zone, status); 181 icu::TimeZone::getCanonicalID(time_zone, canonical_time_zone, status);
181 if (U_SUCCESS(status)) { 182 if (U_SUCCESS(status)) {
182 if (canonical_time_zone == UNICODE_STRING_SIMPLE("Etc/GMT")) { 183 if (canonical_time_zone == UNICODE_STRING_SIMPLE("Etc/GMT")) {
183 JSObject::SetProperty( 184 JSObject::SetProperty(
184 resolved, 185 resolved,
185 isolate->factory()->NewStringFromAscii(CStrVector("timeZone")), 186 factory->NewStringFromStaticAscii("timeZone"),
186 isolate->factory()->NewStringFromAscii(CStrVector("UTC")), 187 factory->NewStringFromStaticAscii("UTC"),
187 NONE, 188 NONE,
188 SLOPPY).Assert(); 189 SLOPPY).Assert();
189 } else { 190 } else {
190 JSObject::SetProperty( 191 JSObject::SetProperty(
191 resolved, 192 resolved,
192 isolate->factory()->NewStringFromAscii(CStrVector("timeZone")), 193 factory->NewStringFromStaticAscii("timeZone"),
193 isolate->factory()->NewStringFromTwoByte( 194 factory->NewStringFromTwoByte(
194 Vector<const uint16_t>( 195 Vector<const uint16_t>(
195 reinterpret_cast<const uint16_t*>( 196 reinterpret_cast<const uint16_t*>(
196 canonical_time_zone.getBuffer()), 197 canonical_time_zone.getBuffer()),
197 canonical_time_zone.length())), 198 canonical_time_zone.length())).ToHandleChecked(),
198 NONE, 199 NONE,
199 SLOPPY).Assert(); 200 SLOPPY).Assert();
200 } 201 }
201 } 202 }
202 203
203 // Ugly hack. ICU doesn't expose numbering system in any way, so we have 204 // Ugly hack. ICU doesn't expose numbering system in any way, so we have
204 // to assume that for given locale NumberingSystem constructor produces the 205 // to assume that for given locale NumberingSystem constructor produces the
205 // same digits as NumberFormat/Calendar would. 206 // same digits as NumberFormat/Calendar would.
206 status = U_ZERO_ERROR; 207 status = U_ZERO_ERROR;
207 icu::NumberingSystem* numbering_system = 208 icu::NumberingSystem* numbering_system =
208 icu::NumberingSystem::createInstance(icu_locale, status); 209 icu::NumberingSystem::createInstance(icu_locale, status);
209 if (U_SUCCESS(status)) { 210 if (U_SUCCESS(status)) {
210 const char* ns = numbering_system->getName(); 211 const char* ns = numbering_system->getName();
211 JSObject::SetProperty( 212 JSObject::SetProperty(
212 resolved, 213 resolved,
213 isolate->factory()->NewStringFromAscii(CStrVector("numberingSystem")), 214 factory->NewStringFromStaticAscii("numberingSystem"),
214 isolate->factory()->NewStringFromAscii(CStrVector(ns)), 215 factory->NewStringFromAsciiChecked(ns),
215 NONE, 216 NONE,
216 SLOPPY).Assert(); 217 SLOPPY).Assert();
217 } else { 218 } else {
218 JSObject::SetProperty( 219 JSObject::SetProperty(
219 resolved, 220 resolved,
220 isolate->factory()->NewStringFromAscii(CStrVector("numberingSystem")), 221 factory->NewStringFromStaticAscii("numberingSystem"),
221 isolate->factory()->undefined_value(), 222 factory->undefined_value(),
222 NONE, 223 NONE,
223 SLOPPY).Assert(); 224 SLOPPY).Assert();
224 } 225 }
225 delete numbering_system; 226 delete numbering_system;
226 227
227 // Set the locale 228 // Set the locale
228 char result[ULOC_FULLNAME_CAPACITY]; 229 char result[ULOC_FULLNAME_CAPACITY];
229 status = U_ZERO_ERROR; 230 status = U_ZERO_ERROR;
230 uloc_toLanguageTag( 231 uloc_toLanguageTag(
231 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status); 232 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status);
232 if (U_SUCCESS(status)) { 233 if (U_SUCCESS(status)) {
233 JSObject::SetProperty( 234 JSObject::SetProperty(
234 resolved, 235 resolved,
235 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 236 factory->NewStringFromStaticAscii("locale"),
236 isolate->factory()->NewStringFromAscii(CStrVector(result)), 237 factory->NewStringFromAsciiChecked(result),
237 NONE, 238 NONE,
238 SLOPPY).Assert(); 239 SLOPPY).Assert();
239 } else { 240 } else {
240 // This would never happen, since we got the locale from ICU. 241 // This would never happen, since we got the locale from ICU.
241 JSObject::SetProperty( 242 JSObject::SetProperty(
242 resolved, 243 resolved,
243 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 244 factory->NewStringFromStaticAscii("locale"),
244 isolate->factory()->NewStringFromAscii(CStrVector("und")), 245 factory->NewStringFromStaticAscii("und"),
245 NONE, 246 NONE,
246 SLOPPY).Assert(); 247 SLOPPY).Assert();
247 } 248 }
248 } 249 }
249 250
250 251
251 template<int internal_fields, EternalHandles::SingletonHandle field> 252 template<int internal_fields, EternalHandles::SingletonHandle field>
252 Handle<ObjectTemplateInfo> GetEternal(Isolate* isolate) { 253 Handle<ObjectTemplateInfo> GetEternal(Isolate* isolate) {
253 if (isolate->eternal_handles()->Exists(field)) { 254 if (isolate->eternal_handles()->Exists(field)) {
254 return Handle<ObjectTemplateInfo>::cast( 255 return Handle<ObjectTemplateInfo>::cast(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 number_format->setRoundingMode(icu::DecimalFormat::kRoundHalfUp); 370 number_format->setRoundingMode(icu::DecimalFormat::kRoundHalfUp);
370 371
371 return number_format; 372 return number_format;
372 } 373 }
373 374
374 375
375 void SetResolvedNumberSettings(Isolate* isolate, 376 void SetResolvedNumberSettings(Isolate* isolate,
376 const icu::Locale& icu_locale, 377 const icu::Locale& icu_locale,
377 icu::DecimalFormat* number_format, 378 icu::DecimalFormat* number_format,
378 Handle<JSObject> resolved) { 379 Handle<JSObject> resolved) {
380 Factory* factory = isolate->factory();
379 icu::UnicodeString pattern; 381 icu::UnicodeString pattern;
380 number_format->toPattern(pattern); 382 number_format->toPattern(pattern);
381 JSObject::SetProperty( 383 JSObject::SetProperty(
382 resolved, 384 resolved,
383 isolate->factory()->NewStringFromAscii(CStrVector("pattern")), 385 factory->NewStringFromStaticAscii("pattern"),
384 isolate->factory()->NewStringFromTwoByte( 386 factory->NewStringFromTwoByte(
385 Vector<const uint16_t>( 387 Vector<const uint16_t>(
386 reinterpret_cast<const uint16_t*>(pattern.getBuffer()), 388 reinterpret_cast<const uint16_t*>(pattern.getBuffer()),
387 pattern.length())), 389 pattern.length())).ToHandleChecked(),
388 NONE, 390 NONE,
389 SLOPPY).Assert(); 391 SLOPPY).Assert();
390 392
391 // Set resolved currency code in options.currency if not empty. 393 // Set resolved currency code in options.currency if not empty.
392 icu::UnicodeString currency(number_format->getCurrency()); 394 icu::UnicodeString currency(number_format->getCurrency());
393 if (!currency.isEmpty()) { 395 if (!currency.isEmpty()) {
394 JSObject::SetProperty( 396 JSObject::SetProperty(
395 resolved, 397 resolved,
396 isolate->factory()->NewStringFromAscii(CStrVector("currency")), 398 factory->NewStringFromStaticAscii("currency"),
397 isolate->factory()->NewStringFromTwoByte( 399 factory->NewStringFromTwoByte(
398 Vector<const uint16_t>( 400 Vector<const uint16_t>(
399 reinterpret_cast<const uint16_t*>(currency.getBuffer()), 401 reinterpret_cast<const uint16_t*>(currency.getBuffer()),
400 currency.length())), 402 currency.length())).ToHandleChecked(),
401 NONE, 403 NONE,
402 SLOPPY).Assert(); 404 SLOPPY).Assert();
403 } 405 }
404 406
405 // Ugly hack. ICU doesn't expose numbering system in any way, so we have 407 // Ugly hack. ICU doesn't expose numbering system in any way, so we have
406 // to assume that for given locale NumberingSystem constructor produces the 408 // to assume that for given locale NumberingSystem constructor produces the
407 // same digits as NumberFormat/Calendar would. 409 // same digits as NumberFormat/Calendar would.
408 UErrorCode status = U_ZERO_ERROR; 410 UErrorCode status = U_ZERO_ERROR;
409 icu::NumberingSystem* numbering_system = 411 icu::NumberingSystem* numbering_system =
410 icu::NumberingSystem::createInstance(icu_locale, status); 412 icu::NumberingSystem::createInstance(icu_locale, status);
411 if (U_SUCCESS(status)) { 413 if (U_SUCCESS(status)) {
412 const char* ns = numbering_system->getName(); 414 const char* ns = numbering_system->getName();
413 JSObject::SetProperty( 415 JSObject::SetProperty(
414 resolved, 416 resolved,
415 isolate->factory()->NewStringFromAscii(CStrVector("numberingSystem")), 417 factory->NewStringFromStaticAscii("numberingSystem"),
416 isolate->factory()->NewStringFromAscii(CStrVector(ns)), 418 factory->NewStringFromAsciiChecked(ns),
417 NONE, 419 NONE,
418 SLOPPY).Assert(); 420 SLOPPY).Assert();
419 } else { 421 } else {
420 JSObject::SetProperty( 422 JSObject::SetProperty(
421 resolved, 423 resolved,
422 isolate->factory()->NewStringFromAscii(CStrVector("numberingSystem")), 424 factory->NewStringFromStaticAscii("numberingSystem"),
423 isolate->factory()->undefined_value(), 425 factory->undefined_value(),
424 NONE, 426 NONE,
425 SLOPPY).Assert(); 427 SLOPPY).Assert();
426 } 428 }
427 delete numbering_system; 429 delete numbering_system;
428 430
429 JSObject::SetProperty( 431 JSObject::SetProperty(
430 resolved, 432 resolved,
431 isolate->factory()->NewStringFromAscii(CStrVector("useGrouping")), 433 factory->NewStringFromStaticAscii("useGrouping"),
432 isolate->factory()->ToBoolean(number_format->isGroupingUsed()), 434 factory->ToBoolean(number_format->isGroupingUsed()),
433 NONE, 435 NONE,
434 SLOPPY).Assert(); 436 SLOPPY).Assert();
435 437
436 JSObject::SetProperty( 438 JSObject::SetProperty(
437 resolved, 439 resolved,
438 isolate->factory()->NewStringFromAscii( 440 factory->NewStringFromStaticAscii("minimumIntegerDigits"),
439 CStrVector("minimumIntegerDigits")), 441 factory->NewNumberFromInt(number_format->getMinimumIntegerDigits()),
440 isolate->factory()->NewNumberFromInt(
441 number_format->getMinimumIntegerDigits()),
442 NONE, 442 NONE,
443 SLOPPY).Assert(); 443 SLOPPY).Assert();
444 444
445 JSObject::SetProperty( 445 JSObject::SetProperty(
446 resolved, 446 resolved,
447 isolate->factory()->NewStringFromAscii( 447 factory->NewStringFromStaticAscii("minimumFractionDigits"),
448 CStrVector("minimumFractionDigits")), 448 factory->NewNumberFromInt(number_format->getMinimumFractionDigits()),
449 isolate->factory()->NewNumberFromInt(
450 number_format->getMinimumFractionDigits()),
451 NONE, 449 NONE,
452 SLOPPY).Assert(); 450 SLOPPY).Assert();
453 451
454 JSObject::SetProperty( 452 JSObject::SetProperty(
455 resolved, 453 resolved,
456 isolate->factory()->NewStringFromAscii( 454 factory->NewStringFromStaticAscii("maximumFractionDigits"),
457 CStrVector("maximumFractionDigits")), 455 factory->NewNumberFromInt(number_format->getMaximumFractionDigits()),
458 isolate->factory()->NewNumberFromInt(
459 number_format->getMaximumFractionDigits()),
460 NONE, 456 NONE,
461 SLOPPY).Assert(); 457 SLOPPY).Assert();
462 458
463 Handle<String> key = isolate->factory()->NewStringFromAscii( 459 Handle<String> key =
464 CStrVector("minimumSignificantDigits")); 460 factory->NewStringFromStaticAscii("minimumSignificantDigits");
465 if (JSReceiver::HasLocalProperty(resolved, key)) { 461 if (JSReceiver::HasLocalProperty(resolved, key)) {
466 JSObject::SetProperty( 462 JSObject::SetProperty(
467 resolved, 463 resolved,
468 isolate->factory()->NewStringFromAscii( 464 factory->NewStringFromStaticAscii("minimumSignificantDigits"),
469 CStrVector("minimumSignificantDigits")), 465 factory->NewNumberFromInt(number_format->getMinimumSignificantDigits()),
470 isolate->factory()->NewNumberFromInt(
471 number_format->getMinimumSignificantDigits()),
472 NONE, 466 NONE,
473 SLOPPY).Assert(); 467 SLOPPY).Assert();
474 } 468 }
475 469
476 key = isolate->factory()->NewStringFromAscii( 470 key = factory->NewStringFromStaticAscii("maximumSignificantDigits");
477 CStrVector("maximumSignificantDigits"));
478 if (JSReceiver::HasLocalProperty(resolved, key)) { 471 if (JSReceiver::HasLocalProperty(resolved, key)) {
479 JSObject::SetProperty( 472 JSObject::SetProperty(
480 resolved, 473 resolved,
481 isolate->factory()->NewStringFromAscii( 474 factory->NewStringFromStaticAscii("maximumSignificantDigits"),
482 CStrVector("maximumSignificantDigits")), 475 factory->NewNumberFromInt(number_format->getMaximumSignificantDigits()),
483 isolate->factory()->NewNumberFromInt(
484 number_format->getMaximumSignificantDigits()),
485 NONE, 476 NONE,
486 SLOPPY).Assert(); 477 SLOPPY).Assert();
487 } 478 }
488 479
489 // Set the locale 480 // Set the locale
490 char result[ULOC_FULLNAME_CAPACITY]; 481 char result[ULOC_FULLNAME_CAPACITY];
491 status = U_ZERO_ERROR; 482 status = U_ZERO_ERROR;
492 uloc_toLanguageTag( 483 uloc_toLanguageTag(
493 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status); 484 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status);
494 if (U_SUCCESS(status)) { 485 if (U_SUCCESS(status)) {
495 JSObject::SetProperty( 486 JSObject::SetProperty(
496 resolved, 487 resolved,
497 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 488 factory->NewStringFromStaticAscii("locale"),
498 isolate->factory()->NewStringFromAscii(CStrVector(result)), 489 factory->NewStringFromAsciiChecked(result),
499 NONE, 490 NONE,
500 SLOPPY).Assert(); 491 SLOPPY).Assert();
501 } else { 492 } else {
502 // This would never happen, since we got the locale from ICU. 493 // This would never happen, since we got the locale from ICU.
503 JSObject::SetProperty( 494 JSObject::SetProperty(
504 resolved, 495 resolved,
505 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 496 factory->NewStringFromStaticAscii("locale"),
506 isolate->factory()->NewStringFromAscii(CStrVector("und")), 497 factory->NewStringFromStaticAscii("und"),
507 NONE, 498 NONE,
508 SLOPPY).Assert(); 499 SLOPPY).Assert();
509 } 500 }
510 } 501 }
511 502
512 503
513 icu::Collator* CreateICUCollator( 504 icu::Collator* CreateICUCollator(
514 Isolate* isolate, 505 Isolate* isolate,
515 const icu::Locale& icu_locale, 506 const icu::Locale& icu_locale,
516 Handle<JSObject> options) { 507 Handle<JSObject> options) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 } 562 }
572 563
573 return collator; 564 return collator;
574 } 565 }
575 566
576 567
577 void SetResolvedCollatorSettings(Isolate* isolate, 568 void SetResolvedCollatorSettings(Isolate* isolate,
578 const icu::Locale& icu_locale, 569 const icu::Locale& icu_locale,
579 icu::Collator* collator, 570 icu::Collator* collator,
580 Handle<JSObject> resolved) { 571 Handle<JSObject> resolved) {
572 Factory* factory = isolate->factory();
581 UErrorCode status = U_ZERO_ERROR; 573 UErrorCode status = U_ZERO_ERROR;
582 574
583 JSObject::SetProperty( 575 JSObject::SetProperty(
584 resolved, 576 resolved,
585 isolate->factory()->NewStringFromAscii(CStrVector("numeric")), 577 factory->NewStringFromStaticAscii("numeric"),
586 isolate->factory()->ToBoolean( 578 factory->ToBoolean(
587 collator->getAttribute(UCOL_NUMERIC_COLLATION, status) == UCOL_ON), 579 collator->getAttribute(UCOL_NUMERIC_COLLATION, status) == UCOL_ON),
588 NONE, 580 NONE,
589 SLOPPY).Assert(); 581 SLOPPY).Assert();
590 582
591 switch (collator->getAttribute(UCOL_CASE_FIRST, status)) { 583 switch (collator->getAttribute(UCOL_CASE_FIRST, status)) {
592 case UCOL_LOWER_FIRST: 584 case UCOL_LOWER_FIRST:
593 JSObject::SetProperty( 585 JSObject::SetProperty(
594 resolved, 586 resolved,
595 isolate->factory()->NewStringFromAscii(CStrVector("caseFirst")), 587 factory->NewStringFromStaticAscii("caseFirst"),
596 isolate->factory()->NewStringFromAscii(CStrVector("lower")), 588 factory->NewStringFromStaticAscii("lower"),
597 NONE, 589 NONE,
598 SLOPPY).Assert(); 590 SLOPPY).Assert();
599 break; 591 break;
600 case UCOL_UPPER_FIRST: 592 case UCOL_UPPER_FIRST:
601 JSObject::SetProperty( 593 JSObject::SetProperty(
602 resolved, 594 resolved,
603 isolate->factory()->NewStringFromAscii(CStrVector("caseFirst")), 595 factory->NewStringFromStaticAscii("caseFirst"),
604 isolate->factory()->NewStringFromAscii(CStrVector("upper")), 596 factory->NewStringFromStaticAscii("upper"),
605 NONE, 597 NONE,
606 SLOPPY).Assert(); 598 SLOPPY).Assert();
607 break; 599 break;
608 default: 600 default:
609 JSObject::SetProperty( 601 JSObject::SetProperty(
610 resolved, 602 resolved,
611 isolate->factory()->NewStringFromAscii(CStrVector("caseFirst")), 603 factory->NewStringFromStaticAscii("caseFirst"),
612 isolate->factory()->NewStringFromAscii(CStrVector("false")), 604 factory->NewStringFromStaticAscii("false"),
613 NONE, 605 NONE,
614 SLOPPY).Assert(); 606 SLOPPY).Assert();
615 } 607 }
616 608
617 switch (collator->getAttribute(UCOL_STRENGTH, status)) { 609 switch (collator->getAttribute(UCOL_STRENGTH, status)) {
618 case UCOL_PRIMARY: { 610 case UCOL_PRIMARY: {
619 JSObject::SetProperty( 611 JSObject::SetProperty(
620 resolved, 612 resolved,
621 isolate->factory()->NewStringFromAscii(CStrVector("strength")), 613 factory->NewStringFromStaticAscii("strength"),
622 isolate->factory()->NewStringFromAscii(CStrVector("primary")), 614 factory->NewStringFromStaticAscii("primary"),
623 NONE, 615 NONE,
624 SLOPPY).Assert(); 616 SLOPPY).Assert();
625 617
626 // case level: true + s1 -> case, s1 -> base. 618 // case level: true + s1 -> case, s1 -> base.
627 if (UCOL_ON == collator->getAttribute(UCOL_CASE_LEVEL, status)) { 619 if (UCOL_ON == collator->getAttribute(UCOL_CASE_LEVEL, status)) {
628 JSObject::SetProperty( 620 JSObject::SetProperty(
629 resolved, 621 resolved,
630 isolate->factory()->NewStringFromAscii(CStrVector("sensitivity")), 622 factory->NewStringFromStaticAscii("sensitivity"),
631 isolate->factory()->NewStringFromAscii(CStrVector("case")), 623 factory->NewStringFromStaticAscii("case"),
632 NONE, 624 NONE,
633 SLOPPY).Assert(); 625 SLOPPY).Assert();
634 } else { 626 } else {
635 JSObject::SetProperty( 627 JSObject::SetProperty(
636 resolved, 628 resolved,
637 isolate->factory()->NewStringFromAscii(CStrVector("sensitivity")), 629 factory->NewStringFromStaticAscii("sensitivity"),
638 isolate->factory()->NewStringFromAscii(CStrVector("base")), 630 factory->NewStringFromStaticAscii("base"),
639 NONE, 631 NONE,
640 SLOPPY).Assert(); 632 SLOPPY).Assert();
641 } 633 }
642 break; 634 break;
643 } 635 }
644 case UCOL_SECONDARY: 636 case UCOL_SECONDARY:
645 JSObject::SetProperty( 637 JSObject::SetProperty(
646 resolved, 638 resolved,
647 isolate->factory()->NewStringFromAscii(CStrVector("strength")), 639 factory->NewStringFromStaticAscii("strength"),
648 isolate->factory()->NewStringFromAscii(CStrVector("secondary")), 640 factory->NewStringFromStaticAscii("secondary"),
649 NONE, 641 NONE,
650 SLOPPY).Assert(); 642 SLOPPY).Assert();
651 JSObject::SetProperty( 643 JSObject::SetProperty(
652 resolved, 644 resolved,
653 isolate->factory()->NewStringFromAscii(CStrVector("sensitivity")), 645 factory->NewStringFromStaticAscii("sensitivity"),
654 isolate->factory()->NewStringFromAscii(CStrVector("accent")), 646 factory->NewStringFromStaticAscii("accent"),
655 NONE, 647 NONE,
656 SLOPPY).Assert(); 648 SLOPPY).Assert();
657 break; 649 break;
658 case UCOL_TERTIARY: 650 case UCOL_TERTIARY:
659 JSObject::SetProperty( 651 JSObject::SetProperty(
660 resolved, 652 resolved,
661 isolate->factory()->NewStringFromAscii(CStrVector("strength")), 653 factory->NewStringFromStaticAscii("strength"),
662 isolate->factory()->NewStringFromAscii(CStrVector("tertiary")), 654 factory->NewStringFromStaticAscii("tertiary"),
663 NONE, 655 NONE,
664 SLOPPY).Assert(); 656 SLOPPY).Assert();
665 JSObject::SetProperty( 657 JSObject::SetProperty(
666 resolved, 658 resolved,
667 isolate->factory()->NewStringFromAscii(CStrVector("sensitivity")), 659 factory->NewStringFromStaticAscii("sensitivity"),
668 isolate->factory()->NewStringFromAscii(CStrVector("variant")), 660 factory->NewStringFromStaticAscii("variant"),
669 NONE, 661 NONE,
670 SLOPPY).Assert(); 662 SLOPPY).Assert();
671 break; 663 break;
672 case UCOL_QUATERNARY: 664 case UCOL_QUATERNARY:
673 // We shouldn't get quaternary and identical from ICU, but if we do 665 // We shouldn't get quaternary and identical from ICU, but if we do
674 // put them into variant. 666 // put them into variant.
675 JSObject::SetProperty( 667 JSObject::SetProperty(
676 resolved, 668 resolved,
677 isolate->factory()->NewStringFromAscii(CStrVector("strength")), 669 factory->NewStringFromStaticAscii("strength"),
678 isolate->factory()->NewStringFromAscii(CStrVector("quaternary")), 670 factory->NewStringFromStaticAscii("quaternary"),
679 NONE, 671 NONE,
680 SLOPPY).Assert(); 672 SLOPPY).Assert();
681 JSObject::SetProperty( 673 JSObject::SetProperty(
682 resolved, 674 resolved,
683 isolate->factory()->NewStringFromAscii(CStrVector("sensitivity")), 675 factory->NewStringFromStaticAscii("sensitivity"),
684 isolate->factory()->NewStringFromAscii(CStrVector("variant")), 676 factory->NewStringFromStaticAscii("variant"),
685 NONE, 677 NONE,
686 SLOPPY).Assert(); 678 SLOPPY).Assert();
687 break; 679 break;
688 default: 680 default:
689 JSObject::SetProperty( 681 JSObject::SetProperty(
690 resolved, 682 resolved,
691 isolate->factory()->NewStringFromAscii(CStrVector("strength")), 683 factory->NewStringFromStaticAscii("strength"),
692 isolate->factory()->NewStringFromAscii(CStrVector("identical")), 684 factory->NewStringFromStaticAscii("identical"),
693 NONE, 685 NONE,
694 SLOPPY).Assert(); 686 SLOPPY).Assert();
695 JSObject::SetProperty( 687 JSObject::SetProperty(
696 resolved, 688 resolved,
697 isolate->factory()->NewStringFromAscii(CStrVector("sensitivity")), 689 factory->NewStringFromStaticAscii("sensitivity"),
698 isolate->factory()->NewStringFromAscii(CStrVector("variant")), 690 factory->NewStringFromStaticAscii("variant"),
699 NONE, 691 NONE,
700 SLOPPY).Assert(); 692 SLOPPY).Assert();
701 } 693 }
702 694
703 JSObject::SetProperty( 695 JSObject::SetProperty(
704 resolved, 696 resolved,
705 isolate->factory()->NewStringFromAscii(CStrVector("ignorePunctuation")), 697 factory->NewStringFromStaticAscii("ignorePunctuation"),
706 isolate->factory()->ToBoolean(collator->getAttribute( 698 factory->ToBoolean(collator->getAttribute(
707 UCOL_ALTERNATE_HANDLING, status) == UCOL_SHIFTED), 699 UCOL_ALTERNATE_HANDLING, status) == UCOL_SHIFTED),
708 NONE, 700 NONE,
709 SLOPPY).Assert(); 701 SLOPPY).Assert();
710 702
711 // Set the locale 703 // Set the locale
712 char result[ULOC_FULLNAME_CAPACITY]; 704 char result[ULOC_FULLNAME_CAPACITY];
713 status = U_ZERO_ERROR; 705 status = U_ZERO_ERROR;
714 uloc_toLanguageTag( 706 uloc_toLanguageTag(
715 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status); 707 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status);
716 if (U_SUCCESS(status)) { 708 if (U_SUCCESS(status)) {
717 JSObject::SetProperty( 709 JSObject::SetProperty(
718 resolved, 710 resolved,
719 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 711 factory->NewStringFromStaticAscii("locale"),
720 isolate->factory()->NewStringFromAscii(CStrVector(result)), 712 factory->NewStringFromAsciiChecked(result),
721 NONE, 713 NONE,
722 SLOPPY).Assert(); 714 SLOPPY).Assert();
723 } else { 715 } else {
724 // This would never happen, since we got the locale from ICU. 716 // This would never happen, since we got the locale from ICU.
725 JSObject::SetProperty( 717 JSObject::SetProperty(
726 resolved, 718 resolved,
727 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 719 factory->NewStringFromStaticAscii("locale"),
728 isolate->factory()->NewStringFromAscii(CStrVector("und")), 720 factory->NewStringFromStaticAscii("und"),
729 NONE, 721 NONE,
730 SLOPPY).Assert(); 722 SLOPPY).Assert();
731 } 723 }
732 } 724 }
733 725
734 726
735 icu::BreakIterator* CreateICUBreakIterator( 727 icu::BreakIterator* CreateICUBreakIterator(
736 Isolate* isolate, 728 Isolate* isolate,
737 const icu::Locale& icu_locale, 729 const icu::Locale& icu_locale,
738 Handle<JSObject> options) { 730 Handle<JSObject> options) {
(...skipping 23 matching lines...) Expand all
762 } 754 }
763 755
764 return break_iterator; 756 return break_iterator;
765 } 757 }
766 758
767 759
768 void SetResolvedBreakIteratorSettings(Isolate* isolate, 760 void SetResolvedBreakIteratorSettings(Isolate* isolate,
769 const icu::Locale& icu_locale, 761 const icu::Locale& icu_locale,
770 icu::BreakIterator* break_iterator, 762 icu::BreakIterator* break_iterator,
771 Handle<JSObject> resolved) { 763 Handle<JSObject> resolved) {
764 Factory* factory = isolate->factory();
772 UErrorCode status = U_ZERO_ERROR; 765 UErrorCode status = U_ZERO_ERROR;
773 766
774 // Set the locale 767 // Set the locale
775 char result[ULOC_FULLNAME_CAPACITY]; 768 char result[ULOC_FULLNAME_CAPACITY];
776 status = U_ZERO_ERROR; 769 status = U_ZERO_ERROR;
777 uloc_toLanguageTag( 770 uloc_toLanguageTag(
778 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status); 771 icu_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status);
779 if (U_SUCCESS(status)) { 772 if (U_SUCCESS(status)) {
780 JSObject::SetProperty( 773 JSObject::SetProperty(
781 resolved, 774 resolved,
782 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 775 factory->NewStringFromStaticAscii("locale"),
783 isolate->factory()->NewStringFromAscii(CStrVector(result)), 776 factory->NewStringFromAsciiChecked(result),
784 NONE, 777 NONE,
785 SLOPPY).Assert(); 778 SLOPPY).Assert();
786 } else { 779 } else {
787 // This would never happen, since we got the locale from ICU. 780 // This would never happen, since we got the locale from ICU.
788 JSObject::SetProperty( 781 JSObject::SetProperty(
789 resolved, 782 resolved,
790 isolate->factory()->NewStringFromAscii(CStrVector("locale")), 783 factory->NewStringFromStaticAscii("locale"),
791 isolate->factory()->NewStringFromAscii(CStrVector("und")), 784 factory->NewStringFromStaticAscii("und"),
792 NONE, 785 NONE,
793 SLOPPY).Assert(); 786 SLOPPY).Assert();
794 } 787 }
795 } 788 }
796 789
797 } // namespace 790 } // namespace
798 791
799 792
800 // static 793 // static
801 Handle<ObjectTemplateInfo> I18N::GetTemplate(Isolate* isolate) { 794 Handle<ObjectTemplateInfo> I18N::GetTemplate(Isolate* isolate) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 } 838 }
846 839
847 return date_format; 840 return date_format;
848 } 841 }
849 842
850 843
851 icu::SimpleDateFormat* DateFormat::UnpackDateFormat( 844 icu::SimpleDateFormat* DateFormat::UnpackDateFormat(
852 Isolate* isolate, 845 Isolate* isolate,
853 Handle<JSObject> obj) { 846 Handle<JSObject> obj) {
854 Handle<String> key = 847 Handle<String> key =
855 isolate->factory()->NewStringFromAscii(CStrVector("dateFormat")); 848 isolate->factory()->NewStringFromStaticAscii("dateFormat");
856 if (JSReceiver::HasLocalProperty(obj, key)) { 849 if (JSReceiver::HasLocalProperty(obj, key)) {
857 return reinterpret_cast<icu::SimpleDateFormat*>( 850 return reinterpret_cast<icu::SimpleDateFormat*>(
858 obj->GetInternalField(0)); 851 obj->GetInternalField(0));
859 } 852 }
860 853
861 return NULL; 854 return NULL;
862 } 855 }
863 856
864 857
865 template<class T> 858 template<class T>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 } 912 }
920 913
921 return number_format; 914 return number_format;
922 } 915 }
923 916
924 917
925 icu::DecimalFormat* NumberFormat::UnpackNumberFormat( 918 icu::DecimalFormat* NumberFormat::UnpackNumberFormat(
926 Isolate* isolate, 919 Isolate* isolate,
927 Handle<JSObject> obj) { 920 Handle<JSObject> obj) {
928 Handle<String> key = 921 Handle<String> key =
929 isolate->factory()->NewStringFromAscii(CStrVector("numberFormat")); 922 isolate->factory()->NewStringFromStaticAscii("numberFormat");
930 if (JSReceiver::HasLocalProperty(obj, key)) { 923 if (JSReceiver::HasLocalProperty(obj, key)) {
931 return reinterpret_cast<icu::DecimalFormat*>(obj->GetInternalField(0)); 924 return reinterpret_cast<icu::DecimalFormat*>(obj->GetInternalField(0));
932 } 925 }
933 926
934 return NULL; 927 return NULL;
935 } 928 }
936 929
937 930
938 void NumberFormat::DeleteNumberFormat( 931 void NumberFormat::DeleteNumberFormat(
939 const v8::WeakCallbackData<v8::Value, void>& data) { 932 const v8::WeakCallbackData<v8::Value, void>& data) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 } else { 967 } else {
975 SetResolvedCollatorSettings(isolate, icu_locale, collator, resolved); 968 SetResolvedCollatorSettings(isolate, icu_locale, collator, resolved);
976 } 969 }
977 970
978 return collator; 971 return collator;
979 } 972 }
980 973
981 974
982 icu::Collator* Collator::UnpackCollator(Isolate* isolate, 975 icu::Collator* Collator::UnpackCollator(Isolate* isolate,
983 Handle<JSObject> obj) { 976 Handle<JSObject> obj) {
984 Handle<String> key = 977 Handle<String> key = isolate->factory()->NewStringFromStaticAscii("collator");
985 isolate->factory()->NewStringFromAscii(CStrVector("collator"));
986 if (JSReceiver::HasLocalProperty(obj, key)) { 978 if (JSReceiver::HasLocalProperty(obj, key)) {
987 return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0)); 979 return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0));
988 } 980 }
989 981
990 return NULL; 982 return NULL;
991 } 983 }
992 984
993 985
994 void Collator::DeleteCollator( 986 void Collator::DeleteCollator(
995 const v8::WeakCallbackData<v8::Value, void>& data) { 987 const v8::WeakCallbackData<v8::Value, void>& data) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 isolate, icu_locale, break_iterator, resolved); 1026 isolate, icu_locale, break_iterator, resolved);
1035 } 1027 }
1036 1028
1037 return break_iterator; 1029 return break_iterator;
1038 } 1030 }
1039 1031
1040 1032
1041 icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate, 1033 icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate,
1042 Handle<JSObject> obj) { 1034 Handle<JSObject> obj) {
1043 Handle<String> key = 1035 Handle<String> key =
1044 isolate->factory()->NewStringFromAscii(CStrVector("breakIterator")); 1036 isolate->factory()->NewStringFromStaticAscii("breakIterator");
1045 if (JSReceiver::HasLocalProperty(obj, key)) { 1037 if (JSReceiver::HasLocalProperty(obj, key)) {
1046 return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0)); 1038 return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0));
1047 } 1039 }
1048 1040
1049 return NULL; 1041 return NULL;
1050 } 1042 }
1051 1043
1052 1044
1053 void BreakIterator::DeleteBreakIterator( 1045 void BreakIterator::DeleteBreakIterator(
1054 const v8::WeakCallbackData<v8::Value, void>& data) { 1046 const v8::WeakCallbackData<v8::Value, void>& data) {
1055 DeleteNativeObjectAt<icu::BreakIterator>(data, 0); 1047 DeleteNativeObjectAt<icu::BreakIterator>(data, 0);
1056 DeleteNativeObjectAt<icu::UnicodeString>(data, 1); 1048 DeleteNativeObjectAt<icu::UnicodeString>(data, 1);
1057 DestroyGlobalHandle(data); 1049 DestroyGlobalHandle(data);
1058 } 1050 }
1059 1051
1060 } } // namespace v8::internal 1052 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/jsregexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698