summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/typed-array-some.tq
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/builtins/typed-array-some.tq')
-rw-r--r--deps/v8/src/builtins/typed-array-some.tq53
1 files changed, 53 insertions, 0 deletions
diff --git a/deps/v8/src/builtins/typed-array-some.tq b/deps/v8/src/builtins/typed-array-some.tq
new file mode 100644
index 0000000000..f56d63c071
--- /dev/null
+++ b/deps/v8/src/builtins/typed-array-some.tq
@@ -0,0 +1,53 @@
+// Copyright 2019 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include 'src/builtins/builtins-typed-array-gen.h'
+
+namespace typed_array_some {
+ const kBuiltinName: constexpr string = '%TypedArray%.prototype.some';
+
+ transitioning macro SomeAllElements(implicit context: Context)(
+ array: typed_array::AttachedJSTypedArray, callbackfn: Callable,
+ thisArg: Object): Boolean {
+ let witness = typed_array::NewAttachedJSTypedArrayWitness(array);
+ const length: Smi = Convert<Smi>(witness.Get().length);
+ for (let k: Smi = 0; k < length; k++) {
+ // BUG(4895): We should throw on detached buffers rather than simply exit.
+ witness.Recheck() otherwise break;
+ const value: Object = witness.Load(k);
+ const result =
+ Call(context, callbackfn, thisArg, value, k, witness.GetStable());
+ if (ToBoolean(result)) {
+ return True;
+ }
+ }
+ return False;
+ }
+
+ // https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.some
+ transitioning javascript builtin
+ TypedArrayPrototypeSome(implicit context:
+ Context)(receiver: Object, ...arguments): Object {
+ // arguments[0] = callback
+ // arguments[1] = thisArg.
+ try {
+ const array: JSTypedArray = Cast<JSTypedArray>(receiver)
+ otherwise NotTypedArray;
+ const uarray = typed_array::EnsureAttached(array) otherwise IsDetached;
+
+ const callbackfn = Cast<Callable>(arguments[0]) otherwise NotCallable;
+ const thisArg = arguments[1];
+ return SomeAllElements(uarray, callbackfn, thisArg);
+ }
+ label NotCallable deferred {
+ ThrowTypeError(kCalledNonCallable, arguments[0]);
+ }
+ label NotTypedArray deferred {
+ ThrowTypeError(kNotTypedArray, kBuiltinName);
+ }
+ label IsDetached deferred {
+ ThrowTypeError(kDetachedOperation, kBuiltinName);
+ }
+ }
+}