OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if (%_CallFunction(thisArg, element, i, array, predicate)) { | 73 if (%_CallFunction(thisArg, element, i, array, predicate)) { |
74 return i; | 74 return i; |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 return -1; | 79 return -1; |
80 } | 80 } |
81 | 81 |
82 | 82 |
| 83 // ES6, draft 04-05-14, section 22.1.3.6 |
| 84 function ArrayFill(value /* [, start [, end ] ] */) { // length == 1 |
| 85 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); |
| 86 |
| 87 var array = ToObject(this); |
| 88 var length = TO_UINT32(array.length); |
| 89 |
| 90 var i = 0; |
| 91 var end = length; |
| 92 |
| 93 if (%_ArgumentsLength() > 1) { |
| 94 i = %_Arguments(1); |
| 95 i = IS_UNDEFINED(i) ? 0 : TO_INTEGER(i); |
| 96 if (%_ArgumentsLength() > 2) { |
| 97 end = %_Arguments(2); |
| 98 end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); |
| 99 } |
| 100 } |
| 101 |
| 102 if (i < 0) { |
| 103 i += length; |
| 104 if (i < 0) i = 0; |
| 105 } else { |
| 106 if (i > length) i = length; |
| 107 } |
| 108 |
| 109 if (end < 0) { |
| 110 end += length; |
| 111 if (end < 0) end = 0; |
| 112 } else { |
| 113 if (end > length) end = length; |
| 114 } |
| 115 |
| 116 if ((end - i) > 0 && ObjectIsFrozen(array)) { |
| 117 throw MakeTypeError("array_functions_on_frozen", |
| 118 ["Array.prototype.fill"]); |
| 119 } |
| 120 |
| 121 for (; i < end; i++) |
| 122 array[i] = value; |
| 123 return array; |
| 124 } |
| 125 |
83 // ------------------------------------------------------------------- | 126 // ------------------------------------------------------------------- |
84 | 127 |
85 function HarmonyArrayExtendArrayPrototype() { | 128 function HarmonyArrayExtendArrayPrototype() { |
86 %CheckIsBootstrapping(); | 129 %CheckIsBootstrapping(); |
87 | 130 |
88 // Set up the non-enumerable functions on the Array prototype object. | 131 // Set up the non-enumerable functions on the Array prototype object. |
89 InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 132 InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
90 "find", ArrayFind, | 133 "find", ArrayFind, |
91 "findIndex", ArrayFindIndex | 134 "findIndex", ArrayFindIndex, |
| 135 "fill", ArrayFill |
92 )); | 136 )); |
93 } | 137 } |
94 | 138 |
95 HarmonyArrayExtendArrayPrototype(); | 139 HarmonyArrayExtendArrayPrototype(); |
OLD | NEW |