Commit 56312be1 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Refactor builtins-typedarray.cc to use TF_BUILTIN macro.

This is in preparation for porting TypedArrayInitialize to CSA.

BUG=v8:5977

Change-Id: I8b4b4bc7a30f3d0dedf85081bb47ec613c7fce52
Reviewed-on: https://chromium-review.googlesource.com/445259
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43364}
parent 901c29eb
......@@ -9,6 +9,18 @@
namespace v8 {
namespace internal {
class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
public:
explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {}
protected:
void GenerateTypedArrayPrototypeGetter(const char* method_name,
int object_offset);
template <IterationKind kIterationKind>
void GenerateTypedArrayPrototypeIterationMethod(const char* method_name);
};
// -----------------------------------------------------------------------------
// ES6 section 22.2 TypedArray Objects
......@@ -19,152 +31,118 @@ BUILTIN(TypedArrayPrototypeBuffer) {
return *typed_array->GetBuffer();
}
namespace {
void Generate_TypedArrayPrototypeGetter(compiler::CodeAssemblerState* state,
const char* method_name,
int object_offset) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
CodeStubAssembler assembler(state);
Node* receiver = assembler.Parameter(0);
Node* context = assembler.Parameter(3);
void TypedArrayBuiltinsAssembler::GenerateTypedArrayPrototypeGetter(
const char* method_name, int object_offset) {
Node* receiver = Parameter(0);
Node* context = Parameter(3);
// Check if the {receiver} is actually a JSTypedArray.
Label if_receiverisincompatible(&assembler, Label::kDeferred);
assembler.GotoIf(assembler.TaggedIsSmi(receiver), &if_receiverisincompatible);
Node* receiver_instance_type = assembler.LoadInstanceType(receiver);
assembler.GotoIfNot(
assembler.Word32Equal(receiver_instance_type,
assembler.Int32Constant(JS_TYPED_ARRAY_TYPE)),
&if_receiverisincompatible);
Label receiver_is_incompatible(this, Label::kDeferred);
GotoIf(TaggedIsSmi(receiver), &receiver_is_incompatible);
GotoIfNot(HasInstanceType(receiver, JS_TYPED_ARRAY_TYPE),
&receiver_is_incompatible);
// 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.LoadObjectField(receiver, object_offset));
LoadObjectField(receiver, JSTypedArray::kBufferOffset);
Label if_receiverisneutered(this, Label::kDeferred);
GotoIf(IsDetachedBuffer(receiver_buffer), &if_receiverisneutered);
Return(LoadObjectField(receiver, object_offset));
assembler.Bind(&if_receiverisneutered);
Bind(&if_receiverisneutered);
{
// The {receiver}s buffer was neutered, default to zero.
assembler.Return(assembler.SmiConstant(0));
Return(SmiConstant(0));
}
assembler.Bind(&if_receiverisincompatible);
Bind(&receiver_is_incompatible);
{
// The {receiver} is not a valid JSTypedArray.
Node* result = assembler.CallRuntime(
Runtime::kThrowIncompatibleMethodReceiver, context,
assembler.HeapConstant(assembler.factory()->NewStringFromAsciiChecked(
Node* result =
CallRuntime(Runtime::kThrowIncompatibleMethodReceiver, context,
HeapConstant(factory()->NewStringFromAsciiChecked(
method_name, TENURED)),
receiver);
assembler.Return(result); // Never reached.
Return(result); // Never reached.
}
}
} // namespace
// ES6 section 22.2.3.2 get %TypedArray%.prototype.byteLength
void Builtins::Generate_TypedArrayPrototypeByteLength(
compiler::CodeAssemblerState* state) {
Generate_TypedArrayPrototypeGetter(state,
"get TypedArray.prototype.byteLength",
TF_BUILTIN(TypedArrayPrototypeByteLength, TypedArrayBuiltinsAssembler) {
GenerateTypedArrayPrototypeGetter("get TypedArray.prototype.byteLength",
JSTypedArray::kByteLengthOffset);
}
// ES6 section 22.2.3.3 get %TypedArray%.prototype.byteOffset
void Builtins::Generate_TypedArrayPrototypeByteOffset(
compiler::CodeAssemblerState* state) {
Generate_TypedArrayPrototypeGetter(state,
"get TypedArray.prototype.byteOffset",
TF_BUILTIN(TypedArrayPrototypeByteOffset, TypedArrayBuiltinsAssembler) {
GenerateTypedArrayPrototypeGetter("get TypedArray.prototype.byteOffset",
JSTypedArray::kByteOffsetOffset);
}
// ES6 section 22.2.3.18 get %TypedArray%.prototype.length
void Builtins::Generate_TypedArrayPrototypeLength(
compiler::CodeAssemblerState* state) {
Generate_TypedArrayPrototypeGetter(state, "get TypedArray.prototype.length",
TF_BUILTIN(TypedArrayPrototypeLength, TypedArrayBuiltinsAssembler) {
GenerateTypedArrayPrototypeGetter("get TypedArray.prototype.length",
JSTypedArray::kLengthOffset);
}
namespace {
template <IterationKind kIterationKind>
void Generate_TypedArrayPrototypeIterationMethod(
compiler::CodeAssemblerState* state, const char* method_name) {
typedef compiler::Node Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
CodeStubAssembler assembler(state);
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)),
void TypedArrayBuiltinsAssembler::GenerateTypedArrayPrototypeIterationMethod(
const char* method_name) {
Node* receiver = Parameter(0);
Node* context = Parameter(3);
Label throw_bad_receiver(this, Label::kDeferred);
Label throw_typeerror(this, Label::kDeferred);
GotoIf(TaggedIsSmi(receiver), &throw_bad_receiver);
Node* map = LoadMap(receiver);
Node* instance_type = LoadMapInstanceType(map);
GotoIf(Word32NotEqual(instance_type, 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);
LoadObjectField(receiver, JSTypedArray::kBufferOffset);
Label if_receiverisneutered(this, Label::kDeferred);
GotoIf(IsDetachedBuffer(receiver_buffer), &if_receiverisneutered);
assembler.Return(assembler.CreateArrayIterator(receiver, map, instance_type,
context, kIterationKind));
Return(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);
Variable var_message(this, MachineRepresentation::kTagged);
Bind(&throw_bad_receiver);
var_message.Bind(SmiConstant(MessageTemplate::kNotTypedArray));
Goto(&throw_typeerror);
assembler.Bind(&if_receiverisneutered);
Bind(&if_receiverisneutered);
var_message.Bind(
assembler.SmiConstant(Smi::FromInt(MessageTemplate::kDetachedOperation)));
assembler.Goto(&throw_typeerror);
SmiConstant(Smi::FromInt(MessageTemplate::kDetachedOperation)));
Goto(&throw_typeerror);
assembler.Bind(&throw_typeerror);
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);
Node* method_arg = HeapConstant(
isolate()->factory()->NewStringFromAsciiChecked(method_name, TENURED));
Node* result = CallRuntime(Runtime::kThrowTypeError, context,
var_message.value(), method_arg);
Return(result);
}
}
} // namespace
void Builtins::Generate_TypedArrayPrototypeValues(
compiler::CodeAssemblerState* state) {
Generate_TypedArrayPrototypeIterationMethod<IterationKind::kValues>(
state, "%TypedArray%.prototype.values()");
TF_BUILTIN(TypedArrayPrototypeValues, TypedArrayBuiltinsAssembler) {
GenerateTypedArrayPrototypeIterationMethod<IterationKind::kValues>(
"%TypedArray%.prototype.values()");
}
void Builtins::Generate_TypedArrayPrototypeEntries(
compiler::CodeAssemblerState* state) {
Generate_TypedArrayPrototypeIterationMethod<IterationKind::kEntries>(
state, "%TypedArray%.prototype.entries()");
TF_BUILTIN(TypedArrayPrototypeEntries, TypedArrayBuiltinsAssembler) {
GenerateTypedArrayPrototypeIterationMethod<IterationKind::kEntries>(
"%TypedArray%.prototype.entries()");
}
void Builtins::Generate_TypedArrayPrototypeKeys(
compiler::CodeAssemblerState* state) {
Generate_TypedArrayPrototypeIterationMethod<IterationKind::kKeys>(
state, "%TypedArray%.prototype.keys()");
TF_BUILTIN(TypedArrayPrototypeKeys, TypedArrayBuiltinsAssembler) {
GenerateTypedArrayPrototypeIterationMethod<IterationKind::kKeys>(
"%TypedArray%.prototype.keys()");
}
namespace {
......
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