/src/hermes/lib/VM/JSLib/ArrayIterator.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// \file |
10 | | /// ES6.0 22.1.5 Array Iterator Objects |
11 | | //===----------------------------------------------------------------------===// |
12 | | #include "JSLibInternal.h" |
13 | | |
14 | | #include "hermes/VM/JSArray.h" |
15 | | #include "hermes/VM/Runtime.h" |
16 | | #include "hermes/VM/StringPrimitive.h" |
17 | | |
18 | | namespace hermes { |
19 | | namespace vm { |
20 | | |
21 | 94 | void populateArrayIteratorPrototype(Runtime &runtime) { |
22 | 94 | auto proto = Handle<JSObject>::vmcast(&runtime.arrayIteratorPrototype); |
23 | | |
24 | 94 | defineMethod( |
25 | 94 | runtime, |
26 | 94 | proto, |
27 | 94 | Predefined::getSymbolID(Predefined::next), |
28 | 94 | nullptr, |
29 | 94 | arrayIteratorPrototypeNext, |
30 | 94 | 0); |
31 | | |
32 | 94 | auto dpf = DefinePropertyFlags::getDefaultNewPropertyFlags(); |
33 | 94 | dpf.writable = 0; |
34 | 94 | dpf.enumerable = 0; |
35 | 94 | defineProperty( |
36 | 94 | runtime, |
37 | 94 | proto, |
38 | 94 | Predefined::getSymbolID(Predefined::SymbolToStringTag), |
39 | 94 | runtime.getPredefinedStringHandle(Predefined::ArrayIterator), |
40 | 94 | dpf); |
41 | 94 | } |
42 | | |
43 | | CallResult<HermesValue> |
44 | 0 | arrayIteratorPrototypeNext(void *, Runtime &runtime, NativeArgs args) { |
45 | 0 | auto O = args.dyncastThis<JSArrayIterator>(); |
46 | 0 | if (LLVM_UNLIKELY(!O)) { |
47 | 0 | return runtime.raiseTypeError( |
48 | 0 | "ArrayIteratorPrototype.next requires that 'this' be an Array Iterator"); |
49 | 0 | } |
50 | 0 | return JSArrayIterator::nextElement(O, runtime); |
51 | 0 | } |
52 | | |
53 | | } // namespace vm |
54 | | } // namespace hermes |