Commit daae98c3 authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[Torque] Porting TypedArray entries, keys, values

Bug: v8:8906
Change-Id: Ie83540f9dd9448a09c5a8af0c7b7e1ea58aaf497
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2110029Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68040}
parent cbd380d8
......@@ -1103,11 +1103,13 @@ torque_files = [
"src/builtins/torque-internal.tq",
"src/builtins/typed-array-createtypedarray.tq",
"src/builtins/typed-array-every.tq",
"src/builtins/typed-array-entries.tq",
"src/builtins/typed-array-filter.tq",
"src/builtins/typed-array-find.tq",
"src/builtins/typed-array-findindex.tq",
"src/builtins/typed-array-foreach.tq",
"src/builtins/typed-array-from.tq",
"src/builtins/typed-array-keys.tq",
"src/builtins/typed-array-of.tq",
"src/builtins/typed-array-reduce.tq",
"src/builtins/typed-array-reduceright.tq",
......@@ -1116,6 +1118,7 @@ torque_files = [
"src/builtins/typed-array-some.tq",
"src/builtins/typed-array-sort.tq",
"src/builtins/typed-array-subarray.tq",
"src/builtins/typed-array-values.tq",
"src/builtins/typed-array.tq",
"src/builtins/wasm.tq",
"src/ic/handler-configuration.tq",
......
......@@ -1152,7 +1152,7 @@ TF_BUILTIN(ArrayIndexOfHoleyDoubles, ArrayIncludesIndexofAssembler) {
// ES #sec-array.prototype.values
TF_BUILTIN(ArrayPrototypeValues, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<NativeContext> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
Return(CreateArrayIterator(context, ToObject_Inline(context, receiver),
IterationKind::kValues));
......@@ -1160,7 +1160,7 @@ TF_BUILTIN(ArrayPrototypeValues, CodeStubAssembler) {
// ES #sec-array.prototype.entries
TF_BUILTIN(ArrayPrototypeEntries, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<NativeContext> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
Return(CreateArrayIterator(context, ToObject_Inline(context, receiver),
IterationKind::kEntries));
......@@ -1168,7 +1168,7 @@ TF_BUILTIN(ArrayPrototypeEntries, CodeStubAssembler) {
// ES #sec-array.prototype.keys
TF_BUILTIN(ArrayPrototypeKeys, CodeStubAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<NativeContext> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
Return(CreateArrayIterator(context, ToObject_Inline(context, receiver),
IterationKind::kKeys));
......
......@@ -795,12 +795,6 @@ namespace internal {
TFJ(TypedArrayPrototypeByteOffset, 0, kReceiver) \
/* ES6 #sec-get-%typedarray%.prototype.length */ \
TFJ(TypedArrayPrototypeLength, 0, kReceiver) \
/* ES6 #sec-%typedarray%.prototype.entries */ \
TFJ(TypedArrayPrototypeEntries, 0, kReceiver) \
/* ES6 #sec-%typedarray%.prototype.keys */ \
TFJ(TypedArrayPrototypeKeys, 0, kReceiver) \
/* ES6 #sec-%typedarray%.prototype.values */ \
TFJ(TypedArrayPrototypeValues, 0, kReceiver) \
/* ES6 #sec-%typedarray%.prototype.copywithin */ \
CPP(TypedArrayPrototypeCopyWithin) \
/* ES6 #sec-%typedarray%.prototype.fill */ \
......
......@@ -505,49 +505,5 @@ TF_BUILTIN(TypedArrayPrototypeToStringTag, TypedArrayBuiltinsAssembler) {
BIND(&return_undefined);
Return(UndefinedConstant());
}
void TypedArrayBuiltinsAssembler::GenerateTypedArrayPrototypeIterationMethod(
TNode<Context> context, TNode<Object> receiver, const char* method_name,
IterationKind kind) {
Label throw_bad_receiver(this, Label::kDeferred);
GotoIf(TaggedIsSmi(receiver), &throw_bad_receiver);
GotoIfNot(IsJSTypedArray(CAST(receiver)), &throw_bad_receiver);
// Check if the {receiver}'s JSArrayBuffer was detached.
ThrowIfArrayBufferViewBufferIsDetached(context, CAST(receiver), method_name);
Return(CreateArrayIterator(context, receiver, kind));
BIND(&throw_bad_receiver);
ThrowTypeError(context, MessageTemplate::kNotTypedArray, method_name);
}
// ES #sec-%typedarray%.prototype.values
TF_BUILTIN(TypedArrayPrototypeValues, TypedArrayBuiltinsAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
GenerateTypedArrayPrototypeIterationMethod(context, receiver,
"%TypedArray%.prototype.values()",
IterationKind::kValues);
}
// ES #sec-%typedarray%.prototype.entries
TF_BUILTIN(TypedArrayPrototypeEntries, TypedArrayBuiltinsAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
GenerateTypedArrayPrototypeIterationMethod(context, receiver,
"%TypedArray%.prototype.entries()",
IterationKind::kEntries);
}
// ES #sec-%typedarray%.prototype.keys
TF_BUILTIN(TypedArrayPrototypeKeys, TypedArrayBuiltinsAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> receiver = CAST(Parameter(Descriptor::kReceiver));
GenerateTypedArrayPrototypeIterationMethod(
context, receiver, "%TypedArray%.prototype.keys()", IterationKind::kKeys);
}
} // namespace internal
} // namespace v8
......@@ -16,11 +16,6 @@ class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {}
void GenerateTypedArrayPrototypeIterationMethod(TNode<Context> context,
TNode<Object> receiver,
const char* method_name,
IterationKind iteration_kind);
void SetupTypedArrayEmbedderFields(TNode<JSTypedArray> holder);
void AttachBuffer(TNode<JSTypedArray> holder, TNode<JSArrayBuffer> buffer,
TNode<Map> map, TNode<Smi> length,
......
......@@ -95,6 +95,11 @@ FromConstexpr<PromiseState, constexpr PromiseState>(c: constexpr PromiseState):
return %RawDownCast<PromiseState>(Int32Constant(c));
}
FromConstexpr<IterationKind, constexpr IterationKind>(
c: constexpr IterationKind): IterationKind {
return %RawDownCast<IterationKind>(Unsigned(%FromConstexpr<int32>(c)));
}
macro Convert<To: type, From: type>(i: From): To {
return i;
}
......
// 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 {
const kBuiltinNameEntries: constexpr string = '%TypedArray%.prototype.entries';
// %TypedArray%.entries ()
// https://tc39.github.io/ecma262/#sec-%typedarray%.entries
transitioning javascript builtin
TypedArrayPrototypeEntries(js-implicit context: NativeContext, receiver: JSAny)(
...arguments): JSArrayIterator {
try {
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray;
EnsureAttached(array) otherwise IsDetached;
return CreateArrayIterator(array, IterationKind::kEntries);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameEntries);
} label IsDetached deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameEntries);
}
}
}
// 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 {
const kBuiltinNameKeys: constexpr string = '%TypedArray%.prototype.keys';
// %TypedArray%.keys ()
// https://tc39.github.io/ecma262/#sec-%typedarray%.keys
transitioning javascript builtin
TypedArrayPrototypeKeys(js-implicit context: NativeContext, receiver: JSAny)(
...arguments): JSArrayIterator {
try {
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray;
EnsureAttached(array) otherwise IsDetached;
return CreateArrayIterator(array, IterationKind::kKeys);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameKeys);
} label IsDetached deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameKeys);
}
}
}
// 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 {
const kBuiltinNameValues: constexpr string = '%TypedArray%.prototype.values';
// %TypedArray%.values ()
// https://tc39.github.io/ecma262/#sec-%typedarray%.values
transitioning javascript builtin
TypedArrayPrototypeValues(js-implicit context: NativeContext, receiver: JSAny)(
...arguments): JSArrayIterator {
try {
const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise NotTypedArray;
EnsureAttached(array) otherwise IsDetached;
return CreateArrayIterator(array, IterationKind::kValues);
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameValues);
} label IsDetached deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameValues);
}
}
}
......@@ -12433,28 +12433,6 @@ TNode<Number> CodeStubAssembler::BitwiseOp(TNode<Word32T> left32,
UNREACHABLE();
}
// ES #sec-createarrayiterator
TNode<JSArrayIterator> CodeStubAssembler::CreateArrayIterator(
TNode<Context> context, TNode<Object> object, IterationKind kind) {
TNode<NativeContext> native_context = LoadNativeContext(context);
TNode<Map> iterator_map = CAST(LoadContextElement(
native_context, Context::INITIAL_ARRAY_ITERATOR_MAP_INDEX));
TNode<HeapObject> iterator = Allocate(JSArrayIterator::kHeaderSize);
StoreMapNoWriteBarrier(iterator, iterator_map);
StoreObjectFieldRoot(iterator, JSArrayIterator::kPropertiesOrHashOffset,
RootIndex::kEmptyFixedArray);
StoreObjectFieldRoot(iterator, JSArrayIterator::kElementsOffset,
RootIndex::kEmptyFixedArray);
StoreObjectFieldNoWriteBarrier(
iterator, JSArrayIterator::kIteratedObjectOffset, object);
StoreObjectFieldNoWriteBarrier(iterator, JSArrayIterator::kNextIndexOffset,
SmiConstant(0));
StoreObjectFieldNoWriteBarrier(
iterator, JSArrayIterator::kKindOffset,
SmiConstant(Smi::FromInt(static_cast<int>(kind))));
return CAST(iterator);
}
TNode<JSObject> CodeStubAssembler::AllocateJSIteratorResult(
SloppyTNode<Context> context, SloppyTNode<Object> value,
SloppyTNode<Oddball> done) {
......
......@@ -2042,11 +2042,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
Node* capacity, ParameterMode mode = INTPTR_PARAMETERS,
AllocationFlags flags = kNone);
// Perform CreateArrayIterator (ES #sec-createarrayiterator).
TNode<JSArrayIterator> CreateArrayIterator(TNode<Context> context,
TNode<Object> object,
IterationKind mode);
// TODO(v8:9722): Return type should be JSIteratorResult
TNode<JSObject> AllocateJSIteratorResult(SloppyTNode<Context> context,
SloppyTNode<Object> value,
......
......@@ -42,6 +42,7 @@ extern enum NativeContextSlot extends intptr constexpr 'Context::Field' {
REGEXP_FUNCTION_INDEX,
REGEXP_LAST_MATCH_INFO_INDEX,
INITIAL_STRING_ITERATOR_MAP_INDEX,
INITIAL_ARRAY_ITERATOR_MAP_INDEX,
SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP,
STRICT_ARGUMENTS_MAP_INDEX,
SLOPPY_ARGUMENTS_MAP_INDEX,
......
......@@ -2,10 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
extern enum IterationKind extends uint31
constexpr 'IterationKind' { kKeys, kValues, kEntries }
extern class JSArrayIterator extends JSObject {
iterated_object: JSReceiver;
next_index: Number;
kind: Smi;
kind: SmiTagged<IterationKind>;
}
// Perform CreateArrayIterator (ES #sec-createarrayiterator).
@export
macro CreateArrayIterator(implicit context: NativeContext)(
array: JSReceiver, kind: constexpr IterationKind): JSArrayIterator {
return new JSArrayIterator{
map: UnsafeCast<Map>(
context[NativeContextSlot::INITIAL_ARRAY_ITERATOR_MAP_INDEX]),
properties_or_hash: kEmptyFixedArray,
elements: kEmptyFixedArray,
iterated_object: array,
next_index: 0,
kind: SmiTag<IterationKind>(kind)
};
}
extern class JSArray extends JSObject {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment