Commit 03558130 authored by Jungshik Shin's avatar Jungshik Shin Committed by Commit Bot

Fix GetOption per Ecma 402 #sec-getoption

getGetoption() in intl.js misimplemented Ecma 402 #sec-getoption by
calling options[property] twice, once to check if it's defined
and the second time to retrieve the value when it's defined.

Bug: v8:7869
Test: test262/intl402/RelativeTimeFormat/con*/cons*/option*order
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I6d585767232c9f4c0252e65e2891c813db3da641
Reviewed-on: https://chromium-review.googlesource.com/1128444
Commit-Queue: Jungshik Shin <jshin@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54405}
parent a119f9ca
...@@ -354,23 +354,29 @@ function bestFitSupportedLocalesOf(requestedLocales, availableLocales) { ...@@ -354,23 +354,29 @@ function bestFitSupportedLocalesOf(requestedLocales, availableLocales) {
function getGetOption(options, caller) { function getGetOption(options, caller) {
if (IS_UNDEFINED(options)) throw %make_error(kDefaultOptionsMissing, caller); if (IS_UNDEFINED(options)) throw %make_error(kDefaultOptionsMissing, caller);
var getOption = function getOption(property, type, values, defaultValue) { // Ecma 402 #sec-getoption
if (!IS_UNDEFINED(options[property])) { var getOption = function (property, type, values, fallback) {
var value = options[property]; // 1. Let value be ? Get(options, property).
var value = options[property];
// 2. If value is not undefined, then
if (!IS_UNDEFINED(value)) {
switch (type) { switch (type) {
// If type is "boolean", then let value be ToBoolean(value).
case 'boolean': case 'boolean':
value = TO_BOOLEAN(value); value = TO_BOOLEAN(value);
break; break;
// If type is "string", then let value be ToString(value).
case 'string': case 'string':
value = TO_STRING(value); value = TO_STRING(value);
break; break;
case 'number': // Assert: type is "boolean" or "string".
value = TO_NUMBER(value);
break;
default: default:
throw %make_error(kWrongValueType); throw %make_error(kWrongValueType);
} }
// d. If values is not undefined, then
// If values does not contain an element equal to value, throw a
// RangeError exception.
if (!IS_UNDEFINED(values) && %ArrayIndexOf(values, value, 0) === -1) { if (!IS_UNDEFINED(values) && %ArrayIndexOf(values, value, 0) === -1) {
throw %make_range_error(kValueOutOfRange, value, caller, property); throw %make_range_error(kValueOutOfRange, value, caller, property);
} }
...@@ -378,7 +384,7 @@ function getGetOption(options, caller) { ...@@ -378,7 +384,7 @@ function getGetOption(options, caller) {
return value; return value;
} }
return defaultValue; return fallback;
} }
return getOption; return getOption;
......
...@@ -480,7 +480,6 @@ ...@@ -480,7 +480,6 @@
'intl402/Locale/prototype/toStringTag/toString': [FAIL], 'intl402/Locale/prototype/toStringTag/toString': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7869 # https://bugs.chromium.org/p/v8/issues/detail?id=7869
'intl402/RelativeTimeFormat/constructor/constructor/options-order': [FAIL],
'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/branding': [FAIL], 'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/branding': [FAIL],
'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length': [FAIL], 'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length': [FAIL],
'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/name': [FAIL], 'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/name': [FAIL],
......
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