Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 720204
Collapse All | Expand All

(-)file_not_specified_in_diff (-37 / +40 lines)
Line  Link Here
0
-- a/deps/v8/src/objects/js-number-format.cc
0
++ b/deps/v8/src/objects/js-number-format.cc
Lines 1257-1298 Link Here
1257
}
1257
}
1258
1258
1259
namespace {
1259
namespace {
1260
Maybe<icu::UnicodeString> IcuFormatNumber(
1260
Maybe<bool> IcuFormatNumber(
1261
    Isolate* isolate,
1261
    Isolate* isolate,
1262
    const icu::number::LocalizedNumberFormatter& number_format,
1262
    const icu::number::LocalizedNumberFormatter& number_format,
1263
    Handle<Object> numeric_obj, icu::FieldPositionIterator* fp_iter) {
1263
    Handle<Object> numeric_obj, icu::number::FormattedNumber* formatted) {
1264
  // If it is BigInt, handle it differently.
1264
  // If it is BigInt, handle it differently.
1265
  UErrorCode status = U_ZERO_ERROR;
1265
  UErrorCode status = U_ZERO_ERROR;
1266
  icu::number::FormattedNumber formatted;
1267
  if (numeric_obj->IsBigInt()) {
1266
  if (numeric_obj->IsBigInt()) {
1268
    Handle<BigInt> big_int = Handle<BigInt>::cast(numeric_obj);
1267
    Handle<BigInt> big_int = Handle<BigInt>::cast(numeric_obj);
1269
    Handle<String> big_int_string;
1268
    Handle<String> big_int_string;
1270
    ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, big_int_string,
1269
    ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, big_int_string,
1271
                                     BigInt::ToString(isolate, big_int),
1270
                                     BigInt::ToString(isolate, big_int),
1272
                                     Nothing<icu::UnicodeString>());
1271
                                     Nothing<bool>());
1273
    formatted = number_format.formatDecimal(
1272
    *formatted = number_format.formatDecimal(
1274
        {big_int_string->ToCString().get(), big_int_string->length()}, status);
1273
        {big_int_string->ToCString().get(), big_int_string->length()}, status);
1275
  } else {
1274
  } else {
1276
    double number = numeric_obj->Number();
1275
    double number = numeric_obj->Number();
1277
    formatted = number_format.formatDouble(number, status);
1276
    *formatted = number_format.formatDouble(number, status);
1278
  }
1277
  }
1279
  if (U_FAILURE(status)) {
1278
  if (U_FAILURE(status)) {
1280
    // This happen because of icu data trimming trim out "unit".
1279
    // This happen because of icu data trimming trim out "unit".
1281
    // See https://bugs.chromium.org/p/v8/issues/detail?id=8641
1280
    // See https://bugs.chromium.org/p/v8/issues/detail?id=8641
1282
    THROW_NEW_ERROR_RETURN_VALUE(isolate,
1281
    THROW_NEW_ERROR_RETURN_VALUE(
1283
                                 NewTypeError(MessageTemplate::kIcuError),
1282
        isolate, NewTypeError(MessageTemplate::kIcuError), Nothing<bool>());
1284
                                 Nothing<icu::UnicodeString>());
1283
  }
1285
  }
1284
  return Just(true);
1286
  if (fp_iter) {
1287
    formatted.getAllFieldPositions(*fp_iter, status);
1288
  }
1289
  icu::UnicodeString result = formatted.toString(status);
1290
  if (U_FAILURE(status)) {
1291
    THROW_NEW_ERROR_RETURN_VALUE(isolate,
1292
                                 NewTypeError(MessageTemplate::kIcuError),
1293
                                 Nothing<icu::UnicodeString>());
1294
  }
1295
  return Just(result);
1296
}
1285
}
1297
1286
1298
}  // namespace
1287
}  // namespace
Lines 1303-1312 Link Here
1303
    Handle<Object> numeric_obj) {
1292
    Handle<Object> numeric_obj) {
1304
  DCHECK(numeric_obj->IsNumeric());
1293
  DCHECK(numeric_obj->IsNumeric());
1305
1294
1306
  Maybe<icu::UnicodeString> maybe_format =
1295
  icu::number::FormattedNumber formatted;
1307
      IcuFormatNumber(isolate, number_format, numeric_obj, nullptr);
1296
  Maybe<bool> maybe_format =
1297
      IcuFormatNumber(isolate, number_format, numeric_obj, &formatted);
1308
  MAYBE_RETURN(maybe_format, Handle<String>());
1298
  MAYBE_RETURN(maybe_format, Handle<String>());
1309
  return Intl::ToString(isolate, maybe_format.FromJust());
1299
  UErrorCode status = U_ZERO_ERROR;
1300
  icu::UnicodeString result = formatted.toString(status);
1301
  if (U_FAILURE(status)) {
1302
    THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIcuError), String);
1303
  }
1304
  return Intl::ToString(isolate, result);
1305
1310
}
1306
}
1311
1307
1312
namespace {
1308
namespace {
Lines 1419-1430 Link Here
1419
}
1415
}
1420
1416
1421
namespace {
1417
namespace {
1422
Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted,
1418
Maybe<int> ConstructParts(Isolate* isolate,
1423
                          icu::FieldPositionIterator* fp_iter,
1419
                          icu::number::FormattedNumber* formatted,
1424
                          Handle<JSArray> result, int start_index,
1420
                          Handle<JSArray> result, int start_index,
1425
                          Handle<Object> numeric_obj, bool style_is_unit) {
1421
                          Handle<Object> numeric_obj, bool style_is_unit) {
1422
  UErrorCode status = U_ZERO_ERROR;
1423
  icu::UnicodeString formatted_text = formatted->toString(status);
1424
  if (U_FAILURE(status)) {
1425
    THROW_NEW_ERROR_RETURN_VALUE(
1426
        isolate, NewTypeError(MessageTemplate::kIcuError), Nothing<int>());
1427
  }
1426
  DCHECK(numeric_obj->IsNumeric());
1428
  DCHECK(numeric_obj->IsNumeric());
1427
  int32_t length = formatted.length();
1429
  int32_t length = formatted_text.length();
1428
  int index = start_index;
1430
  int index = start_index;
1429
  if (length == 0) return Just(index);
1431
  if (length == 0) return Just(index);
1430
1432
Lines 1433-1445 Link Here
1433
  // other region covers some part of the formatted string. It's possible
1435
  // other region covers some part of the formatted string. It's possible
1434
  // there's another field with exactly the same begin and end as this backdrop,
1436
  // there's another field with exactly the same begin and end as this backdrop,
1435
  // in which case the backdrop's field_id of -1 will give it lower priority.
1437
  // in which case the backdrop's field_id of -1 will give it lower priority.
1436
  regions.push_back(NumberFormatSpan(-1, 0, formatted.length()));
1438
  regions.push_back(NumberFormatSpan(-1, 0, formatted_text.length()));
1437
1439
1438
  {
1440
  {
1439
    icu::FieldPosition fp;
1441
    icu::ConstrainedFieldPosition cfp;
1440
    while (fp_iter->next(fp)) {
1442
    cfp.constrainCategory(UFIELD_CATEGORY_NUMBER);
1441
      regions.push_back(NumberFormatSpan(fp.getField(), fp.getBeginIndex(),
1443
    while (formatted->nextPosition(cfp, status)) {
1442
                                         fp.getEndIndex()));
1444
      regions.push_back(
1445
          NumberFormatSpan(cfp.getField(), cfp.getStart(), cfp.getLimit()));
1443
    }
1446
    }
1444
  }
1447
  }
1445
1448
Lines 1461-1467 Link Here
1461
    Handle<String> substring;
1464
    Handle<String> substring;
1462
    ASSIGN_RETURN_ON_EXCEPTION_VALUE(
1465
    ASSIGN_RETURN_ON_EXCEPTION_VALUE(
1463
        isolate, substring,
1466
        isolate, substring,
1464
        Intl::ToString(isolate, formatted, part.begin_pos, part.end_pos),
1467
        Intl::ToString(isolate, formatted_text, part.begin_pos, part.end_pos),
1465
        Nothing<int>());
1468
        Nothing<int>());
1466
    Intl::AddElement(isolate, result, index, field_type_string, substring);
1469
    Intl::AddElement(isolate, result, index, field_type_string, substring);
1467
    ++index;
1470
    ++index;
Lines 1481-1494 Link Here
1481
      number_format->icu_number_formatter().raw();
1484
      number_format->icu_number_formatter().raw();
1482
  CHECK_NOT_NULL(fmt);
1485
  CHECK_NOT_NULL(fmt);
1483
1486
1484
  icu::FieldPositionIterator fp_iter;
1487
  icu::number::FormattedNumber formatted;
1485
  Maybe<icu::UnicodeString> maybe_format =
1488
  Maybe<bool> maybe_format =
1486
      IcuFormatNumber(isolate, *fmt, numeric_obj, &fp_iter);
1489
      IcuFormatNumber(isolate, *fmt, numeric_obj, &formatted);
1487
  MAYBE_RETURN(maybe_format, Handle<JSArray>());
1490
  MAYBE_RETURN(maybe_format, Handle<JSArray>());
1488
1491
1489
  Handle<JSArray> result = factory->NewJSArray(0);
1492
  Handle<JSArray> result = factory->NewJSArray(0);
1490
  Maybe<int> maybe_format_to_parts = ConstructParts(
1493
  Maybe<int> maybe_format_to_parts = ConstructParts(
1491
      isolate, maybe_format.FromJust(), &fp_iter, result, 0, numeric_obj,
1494
      isolate, &formatted, result, 0, numeric_obj,
1492
      number_format->style() == JSNumberFormat::Style::UNIT);
1495
      number_format->style() == JSNumberFormat::Style::UNIT);
1493
  MAYBE_RETURN(maybe_format_to_parts, Handle<JSArray>());
1496
  MAYBE_RETURN(maybe_format_to_parts, Handle<JSArray>());
1494
1497
1495
  return result;
1498
  return result;

Return to bug 720204