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

Unified Diff: src/builtins/builtins-typedarray.cc

Issue 2735563002: Migrate %TypedArray%.prototype.fill to C++ (Closed)
Patch Set: Merge branch 'master' into fill Created 3 years, 9 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
« no previous file with comments | « src/builtins/builtins.h ('k') | src/elements.h » ('j') | src/elements.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-typedarray.cc
diff --git a/src/builtins/builtins-typedarray.cc b/src/builtins/builtins-typedarray.cc
index 3a85c18620c5d8f20cbd567e30ba275a8734d23a..ceed1730ef5947c9744ef8cd3e9395510a7bff3d 100644
--- a/src/builtins/builtins-typedarray.cc
+++ b/src/builtins/builtins-typedarray.cc
@@ -108,6 +108,55 @@ BUILTIN(TypedArrayPrototypeCopyWithin) {
return *array;
}
+BUILTIN(TypedArrayPrototypeFill) {
+ HandleScope scope(isolate);
+
+ Handle<JSTypedArray> array;
+ const char* method = "%TypedArray%.prototype.fill";
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
+
+ if (V8_UNLIKELY(array->WasNeutered())) return *array;
+
+ int64_t len = array->length_value();
+ int64_t start = 0;
+ int64_t end = len;
+
+ if (args.length() > 2) {
+ Handle<Object> num = args.atOrUndefined(isolate, 2);
+ if (!num->IsUndefined(isolate)) {
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, num, Object::ToInteger(isolate, num));
+ start = CapRelativeIndex(num, 0, len);
+
+ num = args.atOrUndefined(isolate, 3);
+ if (!num->IsUndefined(isolate)) {
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, num, Object::ToInteger(isolate, num));
+ end = CapRelativeIndex(num, 0, len);
+ }
+ }
+ }
+
+ int64_t count = end - start;
+ if (count <= 0) return *array;
+
+ if (V8_UNLIKELY(array->WasNeutered())) return *array;
+
+ // Ensure processed indexes are within array bounds
+ DCHECK_GE(start, 0);
+ DCHECK_LT(start, len);
+ DCHECK_GE(end, 0);
+ DCHECK_LE(end, len);
+ DCHECK_LE(count, len);
+
+ Handle<Object> obj_value = args.atOrUndefined(isolate, 1);
+
+ return array->GetElementsAccessor()->Fill(isolate, array, obj_value,
+ static_cast<uint32_t>(start),
+ static_cast<uint32_t>(end));
+}
+
BUILTIN(TypedArrayPrototypeIncludes) {
HandleScope scope(isolate);
« no previous file with comments | « src/builtins/builtins.h ('k') | src/elements.h » ('j') | src/elements.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698