Commit f42f5144 authored by Josh Wolfe's avatar Josh Wolfe Committed by Commit Bot

[intl] fix off-by-1 in NumberFormat formatToParts parameter parsing

R=adamk@chromium.org, mstarzinger@chromium.org

Bug: v8:5244, chromium:765479
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: I684805acc194a93b96d74e3e64834867dce78dee
Reviewed-on: https://chromium-review.googlesource.com/668677Reviewed-by: 's avatarDaniel Ehrenberg <littledan@chromium.org>
Commit-Queue: Josh Wolfe <jwolfe@igalia.com>
Cr-Commit-Position: refs/heads/master@{#48069}
parent 88a4cf73
...@@ -351,7 +351,7 @@ BUILTIN(NumberFormatPrototypeFormatToParts) { ...@@ -351,7 +351,7 @@ BUILTIN(NumberFormatPrototypeFormatToParts) {
} }
Handle<Object> x; Handle<Object> x;
if (args.length() >= 1) { if (args.length() >= 2) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x,
Object::ToNumber(args.at(1))); Object::ToNumber(args.at(1)));
} else { } else {
......
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: #sec-intl.numberformat.prototype.formattoparts
description: Intl.NumberFormat.prototype.formatToParts called with no parameters
info: >
Intl.NumberFormat.prototype.formatToParts ([ value ])
3. If value is not provided, let value be undefined.
---*/
var nf = new Intl.NumberFormat();
// Example value: [{"type":"nan","value":"NaN"}]
var implicit = nf.formatToParts();
var explicit = nf.formatToParts(undefined);
assert(partsEquals(implicit, explicit),
"formatToParts() should be equivalent to formatToParts(undefined)");
function partsEquals(parts1, parts2) {
if (parts1.length !== parts2.length) return false;
for (var i = 0; i < parts1.length; i++) {
var part1 = parts1[i];
var part2 = parts2[i];
if (part1.type !== part2.type) return false;
if (part1.value !== part2.value) return false;
}
return true;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment