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