Commit 16f8417b authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[Intl] Convert options to an object in v8BreakIterator

Previously in the JS implementation, this would throw (on property
access) but this new behavior is more in line with how all the other
intl objects work.

Bug: v8:5751, chromium:880697
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I0bd073b2a0a6fc1eacd686083d8f1a72252cea53
Reviewed-on: https://chromium-review.googlesource.com/1207579
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55664}
parent f548c1c9
......@@ -26,20 +26,25 @@ JSV8BreakIterator::Type JSV8BreakIterator::getType(const char* str) {
MaybeHandle<JSV8BreakIterator> JSV8BreakIterator::InitializeV8BreakIterator(
Isolate* isolate, Handle<JSV8BreakIterator> break_iterator_holder,
Handle<Object> input_locales, Handle<Object> input_options) {
Handle<Object> locales, Handle<Object> options_obj) {
Factory* factory = isolate->factory();
// If no options were provided, fallback to { __proto__: null }
if (input_options->IsUndefined(isolate)) {
input_options = factory->NewJSObjectWithNullProto();
Handle<JSReceiver> options;
if (options_obj->IsUndefined(isolate)) {
options = factory->NewJSObjectWithNullProto();
} else {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, options,
Object::ToObject(isolate, options_obj, "Intl.JSV8BreakIterator"),
JSV8BreakIterator);
}
// Extract locale string
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(isolate, r,
Intl::ResolveLocale(isolate, "breakiterator",
input_locales, input_options),
JSV8BreakIterator);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, r,
Intl::ResolveLocale(isolate, "breakiterator", locales, options),
JSV8BreakIterator);
Handle<Object> locale_obj =
JSObject::GetDataProperty(r, factory->locale_string());
CHECK(locale_obj->IsString());
......@@ -50,8 +55,7 @@ MaybeHandle<JSV8BreakIterator> JSV8BreakIterator::InitializeV8BreakIterator(
std::vector<const char*> type_values = {"character", "word", "sentence",
"line"};
Maybe<bool> maybe_found_type = Intl::GetStringOption(
isolate, Handle<JSReceiver>::cast(input_options), "type", type_values,
"Intl.v8BreakIterator", &type_str);
isolate, options, "type", type_values, "Intl.v8BreakIterator", &type_str);
Type type_enum = Type::WORD;
MAYBE_RETURN(maybe_found_type, MaybeHandle<JSV8BreakIterator>());
if (maybe_found_type.FromJust()) {
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertThrows(() => new Intl.v8BreakIterator('en', null));
assertDoesNotThrow(() => new Intl.v8BreakIterator('en', undefined));
for (let key of [false, true, "foo", Symbol, 1]) {
assertDoesNotThrow(() => new Intl.v8BreakIterator('en', key));
}
assertDoesNotThrow(() => new Intl.v8BreakIterator('en', {}));
assertDoesNotThrow(() => new Intl.v8BreakIterator('en', new Proxy({}, {})));
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