Commit 38e7b9b8 authored by Ujjwal Sharma's avatar Ujjwal Sharma Committed by Commit Bot

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

This increases the size of a V8BreakIterator instance by a word to store
the first 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: Ib1e8cb8353d0885e0d9bcfdc5fe558c1de0a0738
Reviewed-on: https://chromium-review.googlesource.com/1192823
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55459}
parent 988d703f
......@@ -3027,6 +3027,17 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_break_iterator_internal_adopt_text_shared_fun(
*info);
}
SimpleInstallGetter(isolate_, prototype,
factory->InternalizeUtf8String("first"),
Builtins::kBreakIteratorPrototypeFirst, false);
{
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
isolate_, Builtins::kBreakIteratorInternalFirst,
factory->empty_string(), 0);
native_context()->set_break_iterator_internal_first_shared_fun(*info);
}
}
{
......
......@@ -1405,7 +1405,9 @@ namespace internal {
/* ecma 402 #sec-collator-compare-functions*/ \
CPP(CollatorInternalCompare) \
CPP(BreakIteratorInternalAdoptText) \
CPP(BreakIteratorPrototypeAdoptText)
CPP(BreakIteratorPrototypeAdoptText) \
CPP(BreakIteratorInternalFirst) \
CPP(BreakIteratorPrototypeFirst)
#else
#define BUILTIN_LIST_INTL(CPP, TFJ, TFS) \
/* no-op fallback version */ \
......
......@@ -1388,5 +1388,68 @@ BUILTIN(BreakIteratorInternalAdoptText) {
return ReadOnlyRoots(isolate).undefined_value();
}
BUILTIN(BreakIteratorPrototypeFirst) {
const char* const method = "get Intl.v8BreakIterator.prototype.first";
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_first =
Handle<Object>(break_iterator_holder->GetEmbedderField(
V8BreakIterator::kBoundFirstIndex),
isolate);
if (!bound_first->IsUndefined(isolate)) {
DCHECK(bound_first->IsJSFunction());
return *bound_first;
}
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_first_shared_fun(), isolate);
Handle<Map> map = isolate->strict_function_without_prototype_map();
Handle<JSFunction> new_bound_first_function =
isolate->factory()->NewFunctionFromSharedFunctionInfo(map, info, context);
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundFirstIndex,
*new_bound_first_function);
return *new_bound_first_function;
}
BUILTIN(BreakIteratorInternalFirst) {
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->first());
}
} // namespace internal
} // namespace v8
......@@ -219,6 +219,8 @@ enum ContextLookupFlags {
intl_v8_break_iterator_function) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_ADOPT_TEXT_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_adopt_text_shared_fun) \
V(INTL_V8_BREAK_ITERATOR_INTERNAL_FIRST_SHARED_FUN, SharedFunctionInfo, \
break_iterator_internal_first_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 index of the first break in the string and moves current pointer.
*/
function first(iterator) {
return %BreakIteratorFirst(iterator);
}
/**
* Returns the index of the next break and moves the pointer.
*/
......@@ -1341,8 +1333,6 @@ function breakType(iterator) {
}
AddBoundMethod(GlobalIntlv8BreakIterator, 'first', first, 0,
BREAK_ITERATOR_TYPE, false);
AddBoundMethod(GlobalIntlv8BreakIterator, 'next', next, 0,
BREAK_ITERATOR_TYPE, false);
AddBoundMethod(GlobalIntlv8BreakIterator, 'current', current, 0,
......
......@@ -194,6 +194,7 @@ class V8BreakIterator {
V(kBreakIterator, kPointerSize) \
V(kUnicodeString, kPointerSize) \
V(kBoundAdoptText, kPointerSize) \
V(kBoundFirst, kPointerSize) \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, BREAK_ITERATOR_FIELDS)
......@@ -214,6 +215,7 @@ class V8BreakIterator {
static const int kBreakIteratorIndex = 0;
static const int kUnicodeStringIndex = 1;
static const int kBoundAdoptTextIndex = 2;
static const int kBoundFirstIndex = 3;
private:
V8BreakIterator();
......
......@@ -374,20 +374,6 @@ RUNTIME_FUNCTION(Runtime_CreateBreakIterator) {
return *local_object;
}
RUNTIME_FUNCTION(Runtime_BreakIteratorFirst) {
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->first());
}
RUNTIME_FUNCTION(Runtime_BreakIteratorNext) {
HandleScope scope(isolate);
......
......@@ -202,7 +202,6 @@ namespace internal {
F(AvailableLocalesOf, 1, 1) \
F(BreakIteratorBreakType, 1, 1) \
F(BreakIteratorCurrent, 1, 1) \
F(BreakIteratorFirst, 1, 1) \
F(BreakIteratorNext, 1, 1) \
F(CanonicalizeLanguageTag, 1, 1) \
F(CollatorResolvedOptions, 1, 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