Commit c8e3846e authored by Ujjwal Sharma's avatar Ujjwal Sharma Committed by Commit Bot

[intl] Port V8BreakIterator.prototype.next to C++

This increases the size of a V8BreakIterator instance by a word to store
the next function.

The instance to be bound is stored on the context of this builtin function.

Bug: v8:5751
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ibdfabe53c7d0790c1ba44d5de8d1c8fc8de517c9
Reviewed-on: https://chromium-review.googlesource.com/1193502Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55463}
parent d62ec0d8
......@@ -3038,6 +3038,17 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
factory->empty_string(), 0);
native_context()->set_break_iterator_internal_first_shared_fun(*info);
}
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("next"),
Builtins::kBreakIteratorPrototypeNext, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kBreakIteratorInternalNext,
factory->empty_string(), 0);
native_context()->set_break_iterator_internal_next_shared_fun(*info);
}
}
{
......
......@@ -1407,7 +1407,9 @@ namespace internal {
CPP(BreakIteratorInternalAdoptText) \
CPP(BreakIteratorPrototypeAdoptText) \
CPP(BreakIteratorInternalFirst) \
CPP(BreakIteratorPrototypeFirst)
CPP(BreakIteratorPrototypeFirst) \
CPP(BreakIteratorInternalNext) \
CPP(BreakIteratorPrototypeNext)
#else
#define BUILTIN_LIST_INTL(CPP, TFJ, TFS) \
/* no-op fallback version */ \
......
......@@ -1451,5 +1451,67 @@ BUILTIN(BreakIteratorInternalFirst) {
return *isolate->factory()->NewNumberFromInt(break_iterator->first());
}
BUILTIN(BreakIteratorPrototypeNext) {
const char* const method = "get Intl.v8BreakIterator.prototype.next";
HandleScope scope(isolate);
CHECK_RECEIVER(JSObject, break_iterator_holder, method);
if (!Intl::IsObjectOfType(isolate, break_iterator_holder,
Intl::Type::kBreakIterator)) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
isolate->factory()->NewStringFromAsciiChecked(method),
break_iterator_holder));
}
Handle<Object> bound_next = Handle<Object>(
break_iterator_holder->GetEmbedderField(V8BreakIterator::kBoundNextIndex),
isolate);
if (!bound_next->IsUndefined(isolate)) {
DCHECK(bound_next->IsJSFunction());
return *bound_next;
}
Handle<NativeContext> native_context(isolate->context()->native_context(),
isolate);
Handle<Context> context = isolate->factory()->NewBuiltinContext(
native_context, static_cast<int>(V8BreakIterator::ContextSlot::kLength));
context->set(static_cast<int>(V8BreakIterator::ContextSlot::kV8BreakIterator),
*break_iterator_holder);
Handle<SharedFunctionInfo> info = Handle<SharedFunctionInfo>(
native_context->break_iterator_internal_next_shared_fun(), isolate);
Handle<Map> map = isolate->strict_function_without_prototype_map();
Handle<JSFunction> new_bound_next_function =
isolate->factory()->NewFunctionFromSharedFunctionInfo(map, info, context);
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundNextIndex,
*new_bound_next_function);
return *new_bound_next_function;
}
BUILTIN(BreakIteratorInternalNext) {
HandleScope scope(isolate);
Handle<Context> context = Handle<Context>(isolate->context(), isolate);
Handle<JSObject> break_iterator_holder = Handle<JSObject>(
JSObject::cast(context->get(
static_cast<int>(V8BreakIterator::ContextSlot::kV8BreakIterator))),
isolate);
DCHECK(Intl::IsObjectOfType(isolate, break_iterator_holder,
Intl::Type::kBreakIterator));
icu::BreakIterator* break_iterator =
V8BreakIterator::UnpackBreakIterator(break_iterator_holder);
CHECK_NOT_NULL(break_iterator);
return *isolate->factory()->NewNumberFromInt(break_iterator->next());
}
} // namespace internal
} // namespace v8
......@@ -221,6 +221,8 @@ enum ContextLookupFlags {
break_iterator_internal_adopt_text_shared_fun) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_FIRST_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_first_shared_fun) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_NEXT_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_next_shared_fun) \
V(JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX, Map, \
js_array_packed_smi_elements_map) \
V(JS_ARRAY_HOLEY_SMI_ELEMENTS_MAP_INDEX, Map, \
......
......@@ -1309,14 +1309,6 @@ DEFINE_METHOD(
);
/**
* Returns the index of the next break and moves the pointer.
*/
function next(iterator) {
return %BreakIteratorNext(iterator);
}
/**
* Returns index of the current break.
*/
......@@ -1333,8 +1325,6 @@ function breakType(iterator) {
}
AddBoundMethod(GlobalIntlv8BreakIterator, 'next', next, 0,
BREAK_ITERATOR_TYPE, false);
AddBoundMethod(GlobalIntlv8BreakIterator, 'current', current, 0,
BREAK_ITERATOR_TYPE, false);
AddBoundMethod(GlobalIntlv8BreakIterator, 'breakType', breakType, 0,
......
......@@ -195,6 +195,7 @@ class V8BreakIterator {
V(kUnicodeString, kPointerSize) \
V(kBoundAdoptText, kPointerSize) \
V(kBoundFirst, kPointerSize) \
V(kBoundNext, kPointerSize) \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, BREAK_ITERATOR_FIELDS)
......@@ -216,6 +217,7 @@ class V8BreakIterator {
static const int kUnicodeStringIndex = 1;
static const int kBoundAdoptTextIndex = 2;
static const int kBoundFirstIndex = 3;
static const int kBoundNextIndex = 4;
private:
V8BreakIterator();
......
......@@ -374,20 +374,6 @@ RUNTIME_FUNCTION(Runtime_CreateBreakIterator) {
return *local_object;
}
RUNTIME_FUNCTION(Runtime_BreakIteratorNext) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
icu::BreakIterator* break_iterator =
V8BreakIterator::UnpackBreakIterator(break_iterator_holder);
CHECK_NOT_NULL(break_iterator);
return *isolate->factory()->NewNumberFromInt(break_iterator->next());
}
RUNTIME_FUNCTION(Runtime_BreakIteratorCurrent) {
HandleScope scope(isolate);
......
......@@ -202,7 +202,6 @@ namespace internal {
F(AvailableLocalesOf, 1, 1) \
F(BreakIteratorBreakType, 1, 1) \
F(BreakIteratorCurrent, 1, 1) \
F(BreakIteratorNext, 1, 1) \
F(CanonicalizeLanguageTag, 1, 1) \
F(CollatorResolvedOptions, 1, 1) \
F(CreateBreakIterator, 3, 1) \
......
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