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

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

Issue 2165593002: [builtins] Move builtins into own files (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove builtins-error.cc from BUILD.gn Created 4 years, 5 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-symbol.cc ('k') | src/v8.gyp » ('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
new file mode 100644
index 0000000000000000000000000000000000000000..ede04f26d8a97e1ef784b6bd4e60f4c1baf6c3eb
--- /dev/null
+++ b/src/builtins/builtins-typedarray.cc
@@ -0,0 +1,101 @@
+// Copyright 2016 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.h"
+#include "src/builtins/builtins-utils.h"
+
+namespace v8 {
+namespace internal {
+
+// -----------------------------------------------------------------------------
+// ES6 section 22.2 TypedArray Objects
+
+// ES6 section 22.2.3.1 get %TypedArray%.prototype.buffer
+BUILTIN(TypedArrayPrototypeBuffer) {
+ HandleScope scope(isolate);
+ CHECK_RECEIVER(JSTypedArray, typed_array, "get TypedArray.prototype.buffer");
+ return *typed_array->GetBuffer();
+}
+
+namespace {
+
+void Generate_TypedArrayProtoypeGetter(CodeStubAssembler* assembler,
+ const char* method_name,
+ int object_offset) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ // Check if the {receiver} is actually a JSTypedArray.
+ Label if_receiverisincompatible(assembler, Label::kDeferred);
+ assembler->GotoIf(assembler->WordIsSmi(receiver), &if_receiverisincompatible);
+ Node* receiver_instance_type = assembler->LoadInstanceType(receiver);
+ assembler->GotoUnless(
+ assembler->Word32Equal(receiver_instance_type,
+ assembler->Int32Constant(JS_TYPED_ARRAY_TYPE)),
+ &if_receiverisincompatible);
+
+ // 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->Return(assembler->LoadObjectField(receiver, object_offset));
+
+ assembler->Bind(&if_receiverisneutered);
+ {
+ // The {receiver}s buffer was neutered, default to zero.
+ assembler->Return(assembler->SmiConstant(0));
+ }
+
+ assembler->Bind(&if_receiverisincompatible);
+ {
+ // The {receiver} is not a valid JSGeneratorObject.
+ Node* result = assembler->CallRuntime(
+ Runtime::kThrowIncompatibleMethodReceiver, context,
+ assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked(
+ method_name, TENURED)),
+ receiver);
+ assembler->Return(result); // Never reached.
+ }
+}
+
+} // namespace
+
+// ES6 section 22.2.3.2 get %TypedArray%.prototype.byteLength
+void Builtins::Generate_TypedArrayPrototypeByteLength(
+ CodeStubAssembler* assembler) {
+ Generate_TypedArrayProtoypeGetter(assembler,
+ "get TypedArray.prototype.byteLength",
+ JSTypedArray::kByteLengthOffset);
+}
+
+// ES6 section 22.2.3.3 get %TypedArray%.prototype.byteOffset
+void Builtins::Generate_TypedArrayPrototypeByteOffset(
+ CodeStubAssembler* assembler) {
+ Generate_TypedArrayProtoypeGetter(assembler,
+ "get TypedArray.prototype.byteOffset",
+ JSTypedArray::kByteOffsetOffset);
+}
+
+// ES6 section 22.2.3.18 get %TypedArray%.prototype.length
+void Builtins::Generate_TypedArrayPrototypeLength(
+ CodeStubAssembler* assembler) {
+ Generate_TypedArrayProtoypeGetter(assembler,
+ "get TypedArray.prototype.length",
+ JSTypedArray::kLengthOffset);
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/builtins/builtins-symbol.cc ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698