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-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/counters.h" | 7 #include "src/counters.h" |
8 #include "src/elements.h" | 8 #include "src/elements.h" |
9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 to = to * element_size; | 101 to = to * element_size; |
102 from = from * element_size; | 102 from = from * element_size; |
103 count = count * element_size; | 103 count = count * element_size; |
104 | 104 |
105 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); | 105 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); |
106 std::memmove(data + to, data + from, count); | 106 std::memmove(data + to, data + from, count); |
107 | 107 |
108 return *array; | 108 return *array; |
109 } | 109 } |
110 | 110 |
| 111 BUILTIN(TypedArrayPrototypeFill) { |
| 112 HandleScope scope(isolate); |
| 113 |
| 114 Handle<JSTypedArray> array; |
| 115 const char* method = "%TypedArray%.prototype.fill"; |
| 116 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 117 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
| 118 |
| 119 if (V8_UNLIKELY(array->WasNeutered())) return *array; |
| 120 |
| 121 int64_t len = array->length_value(); |
| 122 int64_t start = 0; |
| 123 int64_t end = len; |
| 124 |
| 125 if (args.length() > 2) { |
| 126 Handle<Object> num = args.atOrUndefined(isolate, 2); |
| 127 if (!num->IsUndefined(isolate)) { |
| 128 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 129 isolate, num, Object::ToInteger(isolate, num)); |
| 130 start = CapRelativeIndex(num, 0, len); |
| 131 |
| 132 num = args.atOrUndefined(isolate, 3); |
| 133 if (!num->IsUndefined(isolate)) { |
| 134 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 135 isolate, num, Object::ToInteger(isolate, num)); |
| 136 end = CapRelativeIndex(num, 0, len); |
| 137 } |
| 138 } |
| 139 } |
| 140 |
| 141 int64_t count = end - start; |
| 142 if (count <= 0) return *array; |
| 143 |
| 144 if (V8_UNLIKELY(array->WasNeutered())) return *array; |
| 145 |
| 146 // Ensure processed indexes are within array bounds |
| 147 DCHECK_GE(start, 0); |
| 148 DCHECK_LT(start, len); |
| 149 DCHECK_GE(end, 0); |
| 150 DCHECK_LE(end, len); |
| 151 DCHECK_LE(count, len); |
| 152 |
| 153 Handle<Object> obj_value = args.atOrUndefined(isolate, 1); |
| 154 |
| 155 return array->GetElementsAccessor()->Fill(isolate, array, obj_value, |
| 156 static_cast<uint32_t>(start), |
| 157 static_cast<uint32_t>(end)); |
| 158 } |
| 159 |
111 BUILTIN(TypedArrayPrototypeIncludes) { | 160 BUILTIN(TypedArrayPrototypeIncludes) { |
112 HandleScope scope(isolate); | 161 HandleScope scope(isolate); |
113 | 162 |
114 Handle<JSTypedArray> array; | 163 Handle<JSTypedArray> array; |
115 const char* method = "%TypedArray%.prototype.includes"; | 164 const char* method = "%TypedArray%.prototype.includes"; |
116 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 165 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
117 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); | 166 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
118 | 167 |
119 if (args.length() < 2) return isolate->heap()->false_value(); | 168 if (args.length() < 2) return isolate->heap()->false_value(); |
120 | 169 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 Handle<Object> search_element = args.atOrUndefined(isolate, 1); | 250 Handle<Object> search_element = args.atOrUndefined(isolate, 1); |
202 ElementsAccessor* elements = array->GetElementsAccessor(); | 251 ElementsAccessor* elements = array->GetElementsAccessor(); |
203 Maybe<int64_t> result = elements->LastIndexOfValue( | 252 Maybe<int64_t> result = elements->LastIndexOfValue( |
204 isolate, array, search_element, static_cast<uint32_t>(index)); | 253 isolate, array, search_element, static_cast<uint32_t>(index)); |
205 MAYBE_RETURN(result, isolate->heap()->exception()); | 254 MAYBE_RETURN(result, isolate->heap()->exception()); |
206 return *isolate->factory()->NewNumberFromInt64(result.FromJust()); | 255 return *isolate->factory()->NewNumberFromInt64(result.FromJust()); |
207 } | 256 } |
208 | 257 |
209 } // namespace internal | 258 } // namespace internal |
210 } // namespace v8 | 259 } // namespace v8 |
OLD | NEW |