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 24 matching lines...) Expand all Loading... |
35 // +Infinity / -Infinity | 35 // +Infinity / -Infinity |
36 DCHECK(!std::isnan(fp)); | 36 DCHECK(!std::isnan(fp)); |
37 return fp < 0 ? minimum : maximum; | 37 return fp < 0 ? minimum : maximum; |
38 } | 38 } |
39 relative = static_cast<int64_t>(fp); | 39 relative = static_cast<int64_t>(fp); |
40 } | 40 } |
41 return relative < 0 ? std::max<int64_t>(relative + maximum, minimum) | 41 return relative < 0 ? std::max<int64_t>(relative + maximum, minimum) |
42 : std::min<int64_t>(relative, maximum); | 42 : std::min<int64_t>(relative, maximum); |
43 } | 43 } |
44 | 44 |
45 // ES7 section 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) | |
46 MaybeHandle<JSTypedArray> TypedArrayCreate(Isolate* isolate, | |
47 Handle<JSFunction> default_ctor, | |
48 int argc, Handle<Object>* argv, | |
49 const char* method_name) { | |
50 // 1. Let newTypedArray be ? Construct(constructor, argumentList). | |
51 Handle<Object> new_obj; | |
52 ASSIGN_RETURN_ON_EXCEPTION( | |
53 isolate, new_obj, Execution::New(default_ctor, argc, argv), JSTypedArray); | |
54 | |
55 // 2. Perform ? ValidateTypedArray(newTypedArray). | |
56 Handle<JSTypedArray> new_array; | |
57 ASSIGN_RETURN_ON_EXCEPTION( | |
58 isolate, new_array, JSTypedArray::Validate(isolate, new_obj, method_name), | |
59 JSTypedArray); | |
60 | |
61 // 3. If argumentList is a List of a single Number, then | |
62 // If newTypedArray.[[ArrayLength]] < size, throw a TypeError exception. | |
63 DCHECK_IMPLIES(argc == 1, argv[0]->IsSmi()); | |
64 if (argc == 1 && new_array->length_value() < argv[0]->Number()) { | |
65 const MessageTemplate::Template message = | |
66 MessageTemplate::kTypedArrayTooShort; | |
67 THROW_NEW_ERROR(isolate, NewTypeError(message), JSTypedArray); | |
68 } | |
69 | |
70 // 4. Return newTypedArray. | |
71 return new_array; | |
72 } | |
73 | |
74 // ES7 section 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) | |
75 MaybeHandle<JSTypedArray> TypedArraySpeciesCreate(Isolate* isolate, | |
76 Handle<JSTypedArray> exemplar, | |
77 int argc, | |
78 Handle<Object>* argv, | |
79 const char* method_name) { | |
80 // 1. Assert: exemplar is an Object that has a [[TypedArrayName]] internal | |
81 // slot. | |
82 DCHECK(exemplar->IsJSTypedArray()); | |
83 | |
84 // 2. Let defaultConstructor be the intrinsic object listed in column one of | |
85 // Table 51 for exemplar.[[TypedArrayName]]. | |
86 Handle<JSFunction> default_ctor = isolate->uint8_array_fun(); | |
87 switch (exemplar->type()) { | |
88 #define TYPED_ARRAY_CTOR(Type, type, TYPE, ctype, size) \ | |
89 case kExternal##Type##Array: { \ | |
90 default_ctor = isolate->type##_array_fun(); \ | |
91 break; \ | |
92 } | |
93 | |
94 TYPED_ARRAYS(TYPED_ARRAY_CTOR) | |
95 #undef TYPED_ARRAY_CTOR | |
96 default: | |
97 UNREACHABLE(); | |
98 } | |
99 | |
100 // 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). | |
101 Handle<Object> ctor; | |
102 ASSIGN_RETURN_ON_EXCEPTION( | |
103 isolate, ctor, | |
104 Object::SpeciesConstructor(isolate, exemplar, default_ctor), | |
105 JSTypedArray); | |
106 | |
107 // 4. Return ? TypedArrayCreate(constructor, argumentList). | |
108 return TypedArrayCreate(isolate, Handle<JSFunction>::cast(ctor), argc, argv, | |
109 method_name); | |
110 } | |
111 | |
112 MaybeHandle<JSTypedArray> TypedArraySpeciesCreateByLength( | 45 MaybeHandle<JSTypedArray> TypedArraySpeciesCreateByLength( |
113 Isolate* isolate, Handle<JSTypedArray> exemplar, const char* method_name, | 46 Isolate* isolate, Handle<JSTypedArray> exemplar, const char* method_name, |
114 int64_t length) { | 47 int64_t length) { |
115 const int argc = 1; | 48 const int argc = 1; |
116 ScopedVector<Handle<Object>> argv(argc); | 49 ScopedVector<Handle<Object>> argv(argc); |
117 argv[0] = isolate->factory()->NewNumberFromInt64(length); | 50 argv[0] = isolate->factory()->NewNumberFromInt64(length); |
118 return TypedArraySpeciesCreate(isolate, exemplar, argc, argv.start(), | 51 return JSTypedArray::SpeciesCreate(isolate, exemplar, argc, argv.start(), |
119 method_name); | 52 method_name); |
120 } | 53 } |
121 | 54 |
122 } // namespace | 55 } // namespace |
123 | 56 |
124 BUILTIN(TypedArrayPrototypeCopyWithin) { | 57 BUILTIN(TypedArrayPrototypeCopyWithin) { |
125 HandleScope scope(isolate); | 58 HandleScope scope(isolate); |
126 | 59 |
127 Handle<JSTypedArray> array; | 60 Handle<JSTypedArray> array; |
128 const char* method = "%TypedArray%.prototype.copyWithin"; | 61 const char* method = "%TypedArray%.prototype.copyWithin"; |
129 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 62 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 322 |
390 if (count == 0) return *result_array; | 323 if (count == 0) return *result_array; |
391 | 324 |
392 ElementsAccessor* accessor = array->GetElementsAccessor(); | 325 ElementsAccessor* accessor = array->GetElementsAccessor(); |
393 return *accessor->Slice(array, static_cast<uint32_t>(start), | 326 return *accessor->Slice(array, static_cast<uint32_t>(start), |
394 static_cast<uint32_t>(end), result_array); | 327 static_cast<uint32_t>(end), result_array); |
395 } | 328 } |
396 | 329 |
397 } // namespace internal | 330 } // namespace internal |
398 } // namespace v8 | 331 } // namespace v8 |
OLD | NEW |