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

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

Issue 2405253006: [builtins] implement Array.prototype[@@iterator] in TFJ builtins (Closed)
Patch Set: latest round Created 4 years, 2 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-array.cc ('k') | src/code-stub-assembler.h » ('j') | no next file with comments »
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 d63affe3ba62a62721af14a66e39bf7655d401f7..94173fa6131d8a6fa648a610f11110725ee40def 100644
--- a/src/builtins/builtins-typedarray.cc
+++ b/src/builtins/builtins-typedarray.cc
@@ -42,16 +42,9 @@ void Generate_TypedArrayProtoypeGetter(CodeStubAssembler* assembler,
// Check if the {receiver}'s JSArrayBuffer was neutered.
Node* receiver_buffer =
assembler->LoadObjectField(receiver, JSTypedArray::kBufferOffset);
- Node* receiver_buffer_bit_field = assembler->LoadObjectField(
- receiver_buffer, JSArrayBuffer::kBitFieldOffset, MachineType::Uint32());
Label if_receiverisneutered(assembler, Label::kDeferred);
- assembler->GotoUnless(
- assembler->Word32Equal(
- assembler->Word32And(
- receiver_buffer_bit_field,
- assembler->Int32Constant(JSArrayBuffer::WasNeutered::kMask)),
- assembler->Int32Constant(0)),
- &if_receiverisneutered);
+ assembler->GotoIf(assembler->IsDetachedBuffer(receiver_buffer),
+ &if_receiverisneutered);
assembler->Return(assembler->LoadObjectField(receiver, object_offset));
assembler->Bind(&if_receiverisneutered);
@@ -98,5 +91,79 @@ void Builtins::Generate_TypedArrayPrototypeLength(
JSTypedArray::kLengthOffset);
}
+namespace {
+
+template <IterationKind kIterationKind>
+void Generate_TypedArrayPrototypeIterationMethod(CodeStubAssembler* assembler,
+ const char* method_name) {
+ typedef compiler::Node Node;
+ typedef CodeStubAssembler::Label Label;
+ typedef CodeStubAssembler::Variable Variable;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ Label throw_bad_receiver(assembler, Label::kDeferred);
+ Label throw_typeerror(assembler, Label::kDeferred);
+
+ assembler->GotoIf(assembler->TaggedIsSmi(receiver), &throw_bad_receiver);
+
+ Node* map = assembler->LoadMap(receiver);
+ Node* instance_type = assembler->LoadMapInstanceType(map);
+ assembler->GotoIf(
+ assembler->Word32NotEqual(instance_type,
+ assembler->Int32Constant(JS_TYPED_ARRAY_TYPE)),
+ &throw_bad_receiver);
+
+ // Check if the {receiver}'s JSArrayBuffer was neutered.
+ Node* receiver_buffer =
+ assembler->LoadObjectField(receiver, JSTypedArray::kBufferOffset);
+ Label if_receiverisneutered(assembler, Label::kDeferred);
+ assembler->GotoIf(assembler->IsDetachedBuffer(receiver_buffer),
+ &if_receiverisneutered);
+
+ assembler->Return(assembler->CreateArrayIterator(receiver, map, instance_type,
+ context, kIterationKind));
+
+ Variable var_message(assembler, MachineRepresentation::kTagged);
+ assembler->Bind(&throw_bad_receiver);
+ var_message.Bind(
+ assembler->SmiConstant(Smi::FromInt(MessageTemplate::kNotTypedArray)));
+ assembler->Goto(&throw_typeerror);
+
+ assembler->Bind(&if_receiverisneutered);
+ var_message.Bind(assembler->SmiConstant(
+ Smi::FromInt(MessageTemplate::kDetachedOperation)));
+ assembler->Goto(&throw_typeerror);
+
+ assembler->Bind(&throw_typeerror);
+ {
+ Node* arg1 = assembler->HeapConstant(
+ assembler->isolate()->factory()->NewStringFromAsciiChecked(method_name,
+ TENURED));
+ Node* result = assembler->CallRuntime(Runtime::kThrowTypeError, context,
+ var_message.value(), arg1);
+ assembler->Return(result);
+ }
+}
+} // namespace
+
+void Builtins::Generate_TypedArrayPrototypeValues(
+ CodeStubAssembler* assembler) {
+ Generate_TypedArrayPrototypeIterationMethod<IterationKind::kValues>(
+ assembler, "%TypedArray%.prototype.values()");
+}
+
+void Builtins::Generate_TypedArrayPrototypeEntries(
+ CodeStubAssembler* assembler) {
+ Generate_TypedArrayPrototypeIterationMethod<IterationKind::kEntries>(
+ assembler, "%TypedArray%.prototype.entries()");
+}
+
+void Builtins::Generate_TypedArrayPrototypeKeys(CodeStubAssembler* assembler) {
+ Generate_TypedArrayPrototypeIterationMethod<IterationKind::kKeys>(
+ assembler, "%TypedArray%.prototype.keys()");
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/builtins/builtins-array.cc ('k') | src/code-stub-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698