Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Unified Diff: src/objects.cc

Issue 2814683002: [builtins] Implement %TypedArray%.prototype.map in the CSA (Closed)
Patch Set: added spec comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index cc8056402d88dc3859facd8fe85e530a686a196c..bf15a6de644e912c9beed48a4e8bdf250d431480 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -17287,6 +17287,68 @@ size_t JSTypedArray::element_size() {
}
}
+// static
+MaybeHandle<JSTypedArray> JSTypedArray::Create(Isolate* isolate,
+ Handle<JSFunction> default_ctor,
+ int argc, Handle<Object>* argv) {
+ // 1. Let newTypedArray be ? Construct(constructor, argumentList).
+ Handle<Object> new_obj;
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, new_obj, Execution::New(default_ctor, argc, argv), JSTypedArray);
+
+ // 2. Perform ? ValidateTypedArray(newTypedArray).
+ Handle<JSTypedArray> new_array;
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, new_array,
+ JSTypedArray::Validate(isolate, new_obj),
+ JSTypedArray);
+
+ // 3. If argumentList is a List of a single Number, then
+ // If newTypedArray.[[ArrayLength]] < size, throw a TypeError exception.
+ DCHECK_IMPLIES(argc == 1, argv[0]->IsSmi());
+ if (argc == 1 && new_array->length_value() < argv[0]->Number()) {
+ const MessageTemplate::Template message =
+ MessageTemplate::kTypedArrayTooShort;
+ THROW_NEW_ERROR(isolate, NewTypeError(message), JSTypedArray);
+ }
+
+ // 4. Return newTypedArray.
+ return new_array;
+}
+
+// static
+MaybeHandle<JSTypedArray> JSTypedArray::SpeciesCreate(
+ Isolate* isolate, Handle<JSTypedArray> exemplar, int argc,
+ Handle<Object>* argv) {
+ // 1. Assert: exemplar is an Object that has a [[TypedArrayName]] internal
+ // slot.
+ DCHECK(exemplar->IsJSTypedArray());
+
+ // 2. Let defaultConstructor be the intrinsic object listed in column one of
+ // Table 51 for exemplar.[[TypedArrayName]].
+ Handle<JSFunction> default_ctor = isolate->uint8_array_fun();
+ switch (exemplar->type()) {
+#define TYPED_ARRAY_CTOR(Type, type, TYPE, ctype, size) \
+ case kExternal##Type##Array: { \
+ default_ctor = isolate->type##_array_fun(); \
+ break; \
+ }
+
+ TYPED_ARRAYS(TYPED_ARRAY_CTOR)
+#undef TYPED_ARRAY_CTOR
+ default:
+ UNREACHABLE();
+ }
+
+ // 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor).
+ Handle<Object> ctor;
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, ctor,
+ Object::SpeciesConstructor(isolate, exemplar, default_ctor),
+ JSTypedArray);
+
+ // 4. Return ? TypedArrayCreate(constructor, argumentList).
+ return Create(isolate, Handle<JSFunction>::cast(ctor), argc, argv);
+}
void JSGlobalObject::InvalidatePropertyCell(Handle<JSGlobalObject> global,
Handle<Name> name) {
« src/builtins/builtins-array-gen.cc ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698