OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "src/builtins/builtins-utils.h" | |
6 #include "src/builtins/builtins.h" | |
7 | |
8 namespace v8 { | |
9 namespace internal { | |
10 | |
11 BUILTIN(SpreadIterablePrepare) { | |
12 HandleScope scope(isolate); | |
13 DCHECK_EQ(2, args.length()); | |
14 Handle<Object> spread = args.at<Object>(1); | |
15 | |
16 if (spread->IsJSArray()) { | |
17 // Check that the spread arg has fast elements | |
18 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread); | |
19 ElementsKind array_kind = spread_array->GetElementsKind(); | |
20 | |
21 if (IsFastElementsKind(array_kind)) { | |
22 // Check that the iterator hasn't been touched | |
23 Handle<Object> iterator_func; | |
24 Handle<Name> it_name = isolate->factory()->iterator_symbol(); | |
25 | |
26 if (Object::GetProperty(spread, it_name).ToHandle(&iterator_func)) { | |
Yang
2016/11/08 14:08:41
Does this violate the spec? GetProperty may be obs
petermarshall
2016/11/10 12:19:20
Yeah it does violate the spec. I added a test case
| |
27 JSObject* default_iterator = | |
28 isolate->native_context()->initial_array_iterator(); | |
29 | |
30 if (*iterator_func == default_iterator) { | |
31 return *spread; | |
32 } | |
33 } | |
34 } | |
35 } | |
36 | |
37 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); | |
38 | |
39 Handle<Object> spreaded; | |
40 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
41 isolate, spreaded, | |
42 Execution::Call(isolate, spread_iterable_function, | |
43 isolate->factory()->undefined_value(), 1, &spread)); | |
44 | |
45 return *spreaded; | |
46 } | |
47 | |
48 } // namespace internal | |
49 } // namespace v8 | |
OLD | NEW |