[intl] Port V8BreakIterator.prototype.current to C++
This increases the size of a V8BreakIterator instance by a word to store the current 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: I1bdf3d3cd9db5ab16abb644b33b44705ca58684e Reviewed-on: https://chromium-review.googlesource.com/1194802 Commit-Queue: Ujjwal Sharma <usharma1998@gmail.com> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#55471}
This commit is contained in:
parent
067afa54cf
commit
b56e299d58
@ -3049,6 +3049,17 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
||||
factory->empty_string(), 0);
|
||||
native_context()->set_break_iterator_internal_next_shared_fun(*info);
|
||||
}
|
||||
|
||||
SimpleInstallGetter(isolate_, prototype,
|
||||
factory->InternalizeUtf8String("current"),
|
||||
Builtins::kBreakIteratorPrototypeCurrent, false);
|
||||
|
||||
{
|
||||
Handle<SharedFunctionInfo> info = SimpleCreateBuiltinSharedFunctionInfo(
|
||||
isolate_, Builtins::kBreakIteratorInternalCurrent,
|
||||
factory->empty_string(), 0);
|
||||
native_context()->set_break_iterator_internal_current_shared_fun(*info);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1409,7 +1409,9 @@ namespace internal {
|
||||
CPP(BreakIteratorInternalFirst) \
|
||||
CPP(BreakIteratorPrototypeFirst) \
|
||||
CPP(BreakIteratorInternalNext) \
|
||||
CPP(BreakIteratorPrototypeNext)
|
||||
CPP(BreakIteratorPrototypeNext) \
|
||||
CPP(BreakIteratorInternalCurrent) \
|
||||
CPP(BreakIteratorPrototypeCurrent)
|
||||
#else
|
||||
#define BUILTIN_LIST_INTL(CPP, TFJ, TFS) \
|
||||
/* no-op fallback version */ \
|
||||
|
@ -1513,5 +1513,68 @@ BUILTIN(BreakIteratorInternalNext) {
|
||||
return *isolate->factory()->NewNumberFromInt(break_iterator->next());
|
||||
}
|
||||
|
||||
BUILTIN(BreakIteratorPrototypeCurrent) {
|
||||
const char* const method = "get Intl.v8BreakIterator.prototype.current";
|
||||
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_current =
|
||||
Handle<Object>(break_iterator_holder->GetEmbedderField(
|
||||
V8BreakIterator::kBoundCurrentIndex),
|
||||
isolate);
|
||||
|
||||
if (!bound_current->IsUndefined(isolate)) {
|
||||
DCHECK(bound_current->IsJSFunction());
|
||||
return *bound_current;
|
||||
}
|
||||
|
||||
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_current_shared_fun(), isolate);
|
||||
Handle<Map> map = isolate->strict_function_without_prototype_map();
|
||||
|
||||
Handle<JSFunction> new_bound_current_function =
|
||||
isolate->factory()->NewFunctionFromSharedFunctionInfo(map, info, context);
|
||||
break_iterator_holder->SetEmbedderField(V8BreakIterator::kBoundCurrentIndex,
|
||||
*new_bound_current_function);
|
||||
|
||||
return *new_bound_current_function;
|
||||
}
|
||||
|
||||
BUILTIN(BreakIteratorInternalCurrent) {
|
||||
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->current());
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -223,6 +223,8 @@ enum ContextLookupFlags {
|
||||
break_iterator_internal_first_shared_fun) \
|
||||
V(INTL_V8_BREAK_ITERATOR_INTERNAL_NEXT_SHARED_FUN, SharedFunctionInfo, \
|
||||
break_iterator_internal_next_shared_fun) \
|
||||
V(INTL_V8_BREAK_ITERATOR_INTERNAL_CURRENT_SHARED_FUN, SharedFunctionInfo, \
|
||||
break_iterator_internal_current_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 current break.
|
||||
*/
|
||||
function current(iterator) {
|
||||
return %BreakIteratorCurrent(iterator);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns type of the current break.
|
||||
*/
|
||||
@ -1325,8 +1317,6 @@ function breakType(iterator) {
|
||||
}
|
||||
|
||||
|
||||
AddBoundMethod(GlobalIntlv8BreakIterator, 'current', current, 0,
|
||||
BREAK_ITERATOR_TYPE, false);
|
||||
AddBoundMethod(GlobalIntlv8BreakIterator, 'breakType', breakType, 0,
|
||||
BREAK_ITERATOR_TYPE, false);
|
||||
|
||||
|
@ -196,6 +196,7 @@ class V8BreakIterator {
|
||||
V(kBoundAdoptText, kPointerSize) \
|
||||
V(kBoundFirst, kPointerSize) \
|
||||
V(kBoundNext, kPointerSize) \
|
||||
V(kBoundCurrent, kPointerSize) \
|
||||
V(kSize, 0)
|
||||
|
||||
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, BREAK_ITERATOR_FIELDS)
|
||||
@ -218,6 +219,7 @@ class V8BreakIterator {
|
||||
static const int kBoundAdoptTextIndex = 2;
|
||||
static const int kBoundFirstIndex = 3;
|
||||
static const int kBoundNextIndex = 4;
|
||||
static const int kBoundCurrentIndex = 5;
|
||||
|
||||
private:
|
||||
V8BreakIterator();
|
||||
|
@ -374,20 +374,6 @@ RUNTIME_FUNCTION(Runtime_CreateBreakIterator) {
|
||||
return *local_object;
|
||||
}
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_BreakIteratorCurrent) {
|
||||
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->current());
|
||||
}
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_BreakIteratorBreakType) {
|
||||
HandleScope scope(isolate);
|
||||
|
||||
|
@ -201,7 +201,6 @@ namespace internal {
|
||||
#define FOR_EACH_INTRINSIC_INTL(F) \
|
||||
F(AvailableLocalesOf, 1, 1) \
|
||||
F(BreakIteratorBreakType, 1, 1) \
|
||||
F(BreakIteratorCurrent, 1, 1) \
|
||||
F(CanonicalizeLanguageTag, 1, 1) \
|
||||
F(CollatorResolvedOptions, 1, 1) \
|
||||
F(CreateBreakIterator, 3, 1) \
|
||||
|
Loading…
Reference in New Issue
Block a user