| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 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 'use strict'; |
| 6 |
| 7 // ------------------------------------------------------------------- |
| 8 |
| 9 function SpreadCall(function, thisArg, spread0) { |
| 10 if (!IS_SPEC_FUNCTION(function)) { |
| 11 // TODO(caitp): use name of function rather than value |
| 12 throw MakeTypeError("called_non_callable", [function]); |
| 13 } |
| 14 |
| 15 var args = new InternalArray(); |
| 16 |
| 17 var pos = 3; |
| 18 var count = %_ArgumentsLength(); |
| 19 |
| 20 for (var index = spread0; index < count; ++index) { |
| 21 var nextSpread = %_Arguments(index); |
| 22 |
| 23 while (pos < nextSpread) { |
| 24 args.push(%_Arguments(pos++)); |
| 25 } |
| 26 |
| 27 var collection = %_Arguments(pos++); |
| 28 var iterable = collection[symbolIterator]; |
| 29 var iterator = GetIterator(collection, iterable); |
| 30 |
| 31 while (true) { |
| 32 var next = iterator.next(); |
| 33 |
| 34 if (!IS_OBJECT(next)) { |
| 35 throw MakeTypeError("iterator_result_not_an_object", [next]); |
| 36 } |
| 37 |
| 38 if (next.done) { |
| 39 break; |
| 40 } |
| 41 |
| 42 args.push(next.value); |
| 43 } |
| 44 } |
| 45 |
| 46 while (pos < spread0) { |
| 47 args.push(%_Arguments(pos++)); |
| 48 } |
| 49 |
| 50 return %Apply(function, thisArg, args, 0, args.length); |
| 51 } |
| 52 |
| 53 |
| 54 function SpreadCallNew(function, spread0) { |
| 55 if (!IS_SPEC_FUNCTION(function)) { |
| 56 // TODO(caitp): use name of function rather than value |
| 57 throw MakeTypeError("called_non_callable", [function]); |
| 58 } |
| 59 |
| 60 var args = new InternalArray(); |
| 61 |
| 62 var pos = 2; |
| 63 var count = %_ArgumentsLength(); |
| 64 |
| 65 for (var index = spread0; index < count; ++index) { |
| 66 var nextSpread = %_Arguments(index); |
| 67 |
| 68 while (pos < nextSpread) { |
| 69 args.push(%_Arguments(pos++)); |
| 70 } |
| 71 |
| 72 var collection = %_Arguments(pos++); |
| 73 var iterable = collection[symbolIterator]; |
| 74 var iterator = GetIterator(collection, iterable); |
| 75 |
| 76 while (true) { |
| 77 var next = iterator.next(); |
| 78 |
| 79 if (!IS_OBJECT(next)) { |
| 80 throw MakeTypeError("iterator_result_not_an_object", [next]); |
| 81 } |
| 82 |
| 83 if (next.done) { |
| 84 break; |
| 85 } |
| 86 |
| 87 args.push(next.value); |
| 88 } |
| 89 } |
| 90 |
| 91 while (pos < spread0) { |
| 92 args.push(%_Arguments(pos++)); |
| 93 } |
| 94 |
| 95 return %ApplyConstruct(function, args, 0, args.length); |
| 96 } |
| OLD | NEW |