Commit 24aca870 authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[api] expose Array Iterators to API

Allow access to Array Iterator through the API, in order to simplify
setting up interfaces which use these methods. This applies to
WebIDL interfaces with "length" attributes returning integer types and
a getter taking an unsigned long type.

BUG=
LOG=N
R=adamk@chromium.org

Review URL: https://codereview.chromium.org/1378403004

Cr-Commit-Position: refs/heads/master@{#31152}
parent ed5b12a5
......@@ -2962,7 +2962,15 @@ class V8_EXPORT Array : public Object {
*/
static Local<Array> New(Isolate* isolate, int length = 0);
/**
* Access to Array Iterator methods
*/
static Local<Function> GetKeysIterator(Isolate* isolate);
static Local<Function> GetValuesIterator(Isolate* isolate);
static Local<Function> GetEntriesIterator(Isolate* isolate);
V8_INLINE static Array* Cast(Value* obj);
private:
Array();
static void CheckCast(Value* obj);
......
......@@ -6094,6 +6094,33 @@ Local<Object> Array::CloneElementAt(uint32_t index) {
}
Local<Function> Array::GetKeysIterator(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::JSFunction> keys(
i_isolate->native_context()->array_keys_iterator(), i_isolate);
DCHECK(!keys.is_null());
return Utils::ToLocal(keys);
}
Local<Function> Array::GetValuesIterator(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::JSFunction> values(
i_isolate->native_context()->array_values_iterator(), i_isolate);
DCHECK(!values.is_null());
return Utils::ToLocal(values);
}
Local<Function> Array::GetEntriesIterator(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::JSFunction> entries(
i_isolate->native_context()->array_entries_iterator(), i_isolate);
DCHECK(!entries.is_null());
return Utils::ToLocal(entries);
}
Local<v8::Map> v8::Map::New(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, "Map::New");
......
......@@ -163,6 +163,10 @@ TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
$arrayValues = ArrayValues;
%InstallToContext(["array_values_iterator", ArrayValues]);
%InstallToContext([
"array_keys_iterator", ArrayKeys,
"array_values_iterator", ArrayValues,
"array_entries_iterator", ArrayEntries
]);
})
......@@ -102,7 +102,9 @@ enum BindingFlags {
V(ARRAY_SPLICE_INDEX, JSFunction, array_splice) \
V(ARRAY_SLICE_INDEX, JSFunction, array_slice) \
V(ARRAY_UNSHIFT_INDEX, JSFunction, array_unshift) \
V(ARRAY_KEYS_ITERATOR_INDEX, JSFunction, array_keys_iterator) \
V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
V(ARRAY_ENTRIES_ITERATOR_INDEX, JSFunction, array_entries_iterator) \
V(CREATE_DATE_FUN_INDEX, JSFunction, create_date_fun) \
V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \
V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \
......
......@@ -21900,3 +21900,18 @@ TEST(AccessCheckedIsConcatSpreadable) {
ExpectTrue("result.length === 1");
ExpectTrue("object[Symbol.isConcatSpreadable] === undefined");
}
TEST(ArrayIteratorMethods) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
env->Global()->Set(v8_str("keys"), v8::Array::GetKeysIterator(isolate));
env->Global()->Set(v8_str("values"), v8::Array::GetValuesIterator(isolate));
env->Global()->Set(v8_str("entries"), v8::Array::GetEntriesIterator(isolate));
ExpectString("typeof keys", "function");
ExpectString("typeof values", "function");
ExpectString("typeof entries", "function");
}
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