OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "src/builtins/builtins-utils.h" |
5 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 7 #include "src/frames-inl.h" |
7 | 8 |
8 namespace v8 { | 9 namespace v8 { |
9 namespace internal { | 10 namespace internal { |
10 | 11 |
11 void Builtins::Generate_IteratorPrototypeIterator( | 12 void Builtins::Generate_IteratorPrototypeIterator( |
12 CodeStubAssembler* assembler) { | 13 CodeStubAssembler* assembler) { |
13 assembler->Return(assembler->Parameter(0)); | 14 assembler->Return(assembler->Parameter(0)); |
14 } | 15 } |
15 | 16 |
| 17 BUILTIN(ModuleNamespaceIterator) { |
| 18 HandleScope scope(isolate); |
| 19 DCHECK_EQ(1, args.length()); |
| 20 Handle<Object> receiver = args.at<Object>(0); |
| 21 |
| 22 if (!receiver->IsJSModuleNamespace()) { |
| 23 THROW_NEW_ERROR_RETURN_FAILURE( |
| 24 isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, |
| 25 isolate->factory()->iterator_symbol(), receiver)); |
| 26 } |
| 27 auto ns = Handle<JSModuleNamespace>::cast(receiver); |
| 28 |
| 29 Handle<FixedArray> names = |
| 30 KeyAccumulator::GetKeys(ns, KeyCollectionMode::kOwnOnly, SKIP_SYMBOLS) |
| 31 .ToHandleChecked(); |
| 32 return *isolate->factory()->NewJSFixedArrayIterator(names); |
| 33 } |
| 34 |
| 35 BUILTIN(FixedArrayIteratorNext) { |
| 36 HandleScope scope(isolate); |
| 37 DCHECK_EQ(1, args.length()); |
| 38 Handle<Object> receiver = args.at<Object>(0); |
| 39 |
| 40 // It is an error if this function is called on anything other than the |
| 41 // particular iterator object for which the function was created. |
| 42 if (!receiver->IsJSFixedArrayIterator() || |
| 43 Handle<JSFixedArrayIterator>::cast(receiver)->initial_next() != |
| 44 *args.target<JSFunction>()) { |
| 45 THROW_NEW_ERROR_RETURN_FAILURE( |
| 46 isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, |
| 47 isolate->factory()->next_string(), receiver)); |
| 48 } |
| 49 |
| 50 auto iterator = Handle<JSFixedArrayIterator>::cast(receiver); |
| 51 Handle<Object> value; |
| 52 bool done; |
| 53 |
| 54 int index = iterator->index(); |
| 55 if (index < iterator->array()->length()) { |
| 56 value = handle(iterator->array()->get(index), isolate); |
| 57 done = false; |
| 58 iterator->set_index(index + 1); |
| 59 } else { |
| 60 value = isolate->factory()->undefined_value(); |
| 61 done = true; |
| 62 } |
| 63 |
| 64 return *isolate->factory()->NewJSIteratorResult(value, done); |
| 65 } |
| 66 |
16 } // namespace internal | 67 } // namespace internal |
17 } // namespace v8 | 68 } // namespace v8 |
OLD | NEW |