| 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/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 162 } |
| 163 | 163 |
| 164 void Builtins::Generate_TypedArrayPrototypeKeys( | 164 void Builtins::Generate_TypedArrayPrototypeKeys( |
| 165 compiler::CodeAssemblerState* state) { | 165 compiler::CodeAssemblerState* state) { |
| 166 Generate_TypedArrayPrototypeIterationMethod<IterationKind::kKeys>( | 166 Generate_TypedArrayPrototypeIterationMethod<IterationKind::kKeys>( |
| 167 state, "%TypedArray%.prototype.keys()"); | 167 state, "%TypedArray%.prototype.keys()"); |
| 168 } | 168 } |
| 169 | 169 |
| 170 namespace { | 170 namespace { |
| 171 | 171 |
| 172 MaybeHandle<JSTypedArray> ValidateTypedArray(Isolate* isolate, | |
| 173 Handle<Object> receiver, | |
| 174 const char* method_name) { | |
| 175 if (V8_UNLIKELY(!receiver->IsJSTypedArray())) { | |
| 176 const MessageTemplate::Template message = MessageTemplate::kNotTypedArray; | |
| 177 THROW_NEW_ERROR(isolate, NewTypeError(message), JSTypedArray); | |
| 178 } | |
| 179 | |
| 180 // TODO(caitp): throw if array.[[ViewedArrayBuffer]] is neutered (per v8:4648) | |
| 181 return Handle<JSTypedArray>::cast(receiver); | |
| 182 } | |
| 183 | |
| 184 int64_t CapRelativeIndex(Handle<Object> num, int64_t minimum, int64_t maximum) { | 172 int64_t CapRelativeIndex(Handle<Object> num, int64_t minimum, int64_t maximum) { |
| 185 int64_t relative; | 173 int64_t relative; |
| 186 if (V8_LIKELY(num->IsSmi())) { | 174 if (V8_LIKELY(num->IsSmi())) { |
| 187 relative = Smi::cast(*num)->value(); | 175 relative = Smi::cast(*num)->value(); |
| 188 } else { | 176 } else { |
| 189 DCHECK(num->IsHeapNumber()); | 177 DCHECK(num->IsHeapNumber()); |
| 190 double fp = HeapNumber::cast(*num)->value(); | 178 double fp = HeapNumber::cast(*num)->value(); |
| 191 if (V8_UNLIKELY(!std::isfinite(fp))) { | 179 if (V8_UNLIKELY(!std::isfinite(fp))) { |
| 192 // +Infinity / -Infinity | 180 // +Infinity / -Infinity |
| 193 DCHECK(!std::isnan(fp)); | 181 DCHECK(!std::isnan(fp)); |
| 194 return fp < 0 ? minimum : maximum; | 182 return fp < 0 ? minimum : maximum; |
| 195 } | 183 } |
| 196 relative = static_cast<int64_t>(fp); | 184 relative = static_cast<int64_t>(fp); |
| 197 } | 185 } |
| 198 return relative < 0 ? std::max<int64_t>(relative + maximum, minimum) | 186 return relative < 0 ? std::max<int64_t>(relative + maximum, minimum) |
| 199 : std::min<int64_t>(relative, maximum); | 187 : std::min<int64_t>(relative, maximum); |
| 200 } | 188 } |
| 201 | 189 |
| 202 } // namespace | 190 } // namespace |
| 203 | 191 |
| 204 BUILTIN(TypedArrayPrototypeCopyWithin) { | 192 BUILTIN(TypedArrayPrototypeCopyWithin) { |
| 205 HandleScope scope(isolate); | 193 HandleScope scope(isolate); |
| 206 | 194 |
| 207 Handle<JSTypedArray> array; | 195 Handle<JSTypedArray> array; |
| 208 const char* method = "%TypedArray%.prototype.copyWithin"; | 196 const char* method = "%TypedArray%.prototype.copyWithin"; |
| 209 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 197 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 210 isolate, array, ValidateTypedArray(isolate, args.receiver(), method)); | 198 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); |
| 211 | 199 |
| 212 if (V8_UNLIKELY(array->WasNeutered())) return *array; | 200 if (V8_UNLIKELY(array->WasNeutered())) return *array; |
| 213 | 201 |
| 214 int64_t len = array->length_value(); | 202 int64_t len = array->length_value(); |
| 215 int64_t to = 0; | 203 int64_t to = 0; |
| 216 int64_t from = 0; | 204 int64_t from = 0; |
| 217 int64_t final = len; | 205 int64_t final = len; |
| 218 | 206 |
| 219 if (V8_LIKELY(args.length() > 1)) { | 207 if (V8_LIKELY(args.length() > 1)) { |
| 220 Handle<Object> num; | 208 Handle<Object> num; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 count = count * element_size; | 249 count = count * element_size; |
| 262 | 250 |
| 263 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); | 251 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); |
| 264 std::memmove(data + to, data + from, count); | 252 std::memmove(data + to, data + from, count); |
| 265 | 253 |
| 266 return *array; | 254 return *array; |
| 267 } | 255 } |
| 268 | 256 |
| 269 } // namespace internal | 257 } // namespace internal |
| 270 } // namespace v8 | 258 } // namespace v8 |
| OLD | NEW |