throw MakeTypeError('incompatible_method_receiver',
['ArrayBuffer.prototype.byteLength', this]);
}
- return %_ArrayBufferGetByteLength(this);
+ return %ArrayBufferGetByteLength(this);
}
// ES6 Draft 15.13.5.5.3
end = TO_INTEGER(end);
}
var first;
- var byte_length = %_ArrayBufferGetByteLength(this);
+ var byte_length = %ArrayBufferGetByteLength(this);
if (relativeStart < 0) {
first = MathMax(byte_length + relativeStart, 0);
} else {
JSArrayBuffer::kBackingStoreOffset, Representation::External());
}
- static HObjectAccess ForJSArrayBufferByteLength() {
- return HObjectAccess::ForObservableJSObjectOffset(
- JSArrayBuffer::kByteLengthOffset, Representation::Tagged());
- }
-
static HObjectAccess ForExternalArrayExternalPointer() {
return HObjectAccess::ForObservableJSObjectOffset(
ExternalArray::kExternalPointerOffset, Representation::External());
}
-void HOptimizedGraphBuilder::GenerateArrayBufferGetByteLength(
- CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 1);
- CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
- HValue* buffer = Pop();
- HInstruction* result = New<HLoadNamedField>(
- buffer,
- static_cast<HValue*>(NULL),
- HObjectAccess::ForJSArrayBufferByteLength());
- return ast_context()->ReturnInstruction(result, expr->id());
-}
-
-
-void HOptimizedGraphBuilder::GenerateArrayBufferViewGetByteLength(
- CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 1);
- CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
- HValue* buffer = Pop();
- HInstruction* result = New<HLoadNamedField>(
- buffer,
- static_cast<HValue*>(NULL),
- HObjectAccess::ForJSArrayBufferViewByteLength());
- return ast_context()->ReturnInstruction(result, expr->id());
-}
-
-
-void HOptimizedGraphBuilder::GenerateArrayBufferViewGetByteOffset(
- CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 1);
- CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
- HValue* buffer = Pop();
- HInstruction* result = New<HLoadNamedField>(
- buffer,
- static_cast<HValue*>(NULL),
- HObjectAccess::ForJSArrayBufferViewByteOffset());
- return ast_context()->ReturnInstruction(result, expr->id());
-}
-
-
-void HOptimizedGraphBuilder::GenerateTypedArrayGetLength(
- CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 1);
- CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
- HValue* buffer = Pop();
- HInstruction* result = New<HLoadNamedField>(
- buffer,
- static_cast<HValue*>(NULL),
- HObjectAccess::ForJSTypedArrayLength());
- return ast_context()->ReturnInstruction(result, expr->id());
-}
-
-
void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
}
-#define BUFFER_VIEW_GETTER(Type, getter, accessor) \
- RUNTIME_FUNCTION(MaybeObject*, Runtime_##Type##Get##getter) { \
+#define TYPED_ARRAY_GETTER(getter, accessor) \
+ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGet##getter) { \
HandleScope scope(isolate); \
ASSERT(args.length() == 1); \
- CONVERT_ARG_HANDLE_CHECKED(JS##Type, holder, 0); \
- return holder->accessor(); \
+ CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); \
+ if (!holder->IsJSTypedArray()) \
+ return isolate->Throw(*isolate->factory()->NewTypeError( \
+ "not_typed_array", HandleVector<Object>(NULL, 0))); \
+ Handle<JSTypedArray> typed_array(JSTypedArray::cast(*holder)); \
+ return typed_array->accessor(); \
}
-BUFFER_VIEW_GETTER(ArrayBufferView, ByteLength, byte_length)
-BUFFER_VIEW_GETTER(ArrayBufferView, ByteOffset, byte_offset)
-BUFFER_VIEW_GETTER(TypedArray, Length, length)
-BUFFER_VIEW_GETTER(DataView, Buffer, buffer)
+TYPED_ARRAY_GETTER(ByteLength, byte_length)
+TYPED_ARRAY_GETTER(ByteOffset, byte_offset)
+TYPED_ARRAY_GETTER(Length, length)
-#undef BUFFER_VIEW_GETTER
+#undef TYPED_ARRAY_GETTER
RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGetBuffer) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);
- CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
- return *holder->GetBuffer();
+ CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
+ if (!holder->IsJSTypedArray())
+ return isolate->Throw(*isolate->factory()->NewTypeError(
+ "not_typed_array", HandleVector<Object>(NULL, 0)));
+ Handle<JSTypedArray> typed_array(JSTypedArray::cast(*holder));
+ return *typed_array->GetBuffer();
}
}
+RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewGetBuffer) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSDataView, data_view, 0);
+ return data_view->buffer();
+}
+
+
+RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewGetByteOffset) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSDataView, data_view, 0);
+ return data_view->byte_offset();
+}
+
+
+RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewGetByteLength) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSDataView, data_view, 0);
+ return data_view->byte_length();
+}
+
+
inline static bool NeedToFlipBytes(bool is_little_endian) {
#ifdef V8_TARGET_LITTLE_ENDIAN
return !is_little_endian;
\
/* Harmony typed arrays */ \
F(ArrayBufferInitialize, 2, 1)\
+ F(ArrayBufferGetByteLength, 1, 1)\
F(ArrayBufferSliceImpl, 3, 1) \
F(ArrayBufferIsView, 1, 1) \
F(ArrayBufferNeuter, 1, 1) \
\
F(TypedArrayInitializeFromArrayLike, 4, 1) \
F(TypedArrayGetBuffer, 1, 1) \
+ F(TypedArrayGetByteLength, 1, 1) \
+ F(TypedArrayGetByteOffset, 1, 1) \
+ F(TypedArrayGetLength, 1, 1) \
F(TypedArraySetFastCases, 3, 1) \
\
F(DataViewGetBuffer, 1, 1) \
+ F(DataViewGetByteLength, 1, 1) \
+ F(DataViewGetByteOffset, 1, 1) \
F(DataViewGetInt8, 3, 1) \
F(DataViewGetUint8, 3, 1) \
F(DataViewGetInt16, 3, 1) \
// Entries have the form F(name, number of arguments, number of return values).
#define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
/* Typed Arrays */ \
+ F(ConstructDouble, 2, 1) \
F(TypedArrayInitialize, 5, 1) \
F(DataViewInitialize, 4, 1) \
F(MaxSmi, 0, 1) \
F(TypedArrayMaxSizeInHeap, 0, 1) \
- F(ArrayBufferViewGetByteLength, 1, 1) \
- F(ArrayBufferViewGetByteOffset, 1, 1) \
- F(TypedArrayGetLength, 1, 1) \
- /* ArrayBuffer */ \
- F(ArrayBufferGetByteLength, 1, 1) \
+ \
/* Maths */ \
- F(ConstructDouble, 2, 1) \
F(DoubleHi, 1, 1) \
F(DoubleLo, 1, 1) \
F(MathSqrt, 1, 1) \
int size = 0;
switch (identity()) {
case OLD_POINTER_SPACE:
- size = 96 * kPointerSize * KB;
+ size = 72 * kPointerSize * KB;
break;
case OLD_DATA_SPACE:
size = 192 * KB;
length = ToPositiveInteger(length, "invalid_typed_array_length");
}
- var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
+ var bufferByteLength = %ArrayBufferGetByteLength(buffer);
var offset;
if (IS_UNDEFINED(byteOffset)) {
offset = 0;
}
function NAMEConstructor(arg1, arg2, arg3) {
+
if (%_IsConstructCall()) {
if (IS_ARRAYBUFFER(arg1)) {
NAMEConstructByArrayBuffer(this, arg1, arg2, arg3);
throw MakeTypeError("constructor_not_function", ["NAME"])
}
}
+endmacro
- function NAME_GetBuffer() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.buffer", this]);
- }
- return %TypedArrayGetBuffer(this);
- }
+TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
- function NAME_GetByteLength() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.byteLength", this]);
- }
- return %_ArrayBufferViewGetByteLength(this);
- }
+function TypedArrayGetBuffer() {
+ return %TypedArrayGetBuffer(this);
+}
- function NAME_GetByteOffset() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.byteOffset", this]);
- }
- return %_ArrayBufferViewGetByteOffset(this);
- }
+function TypedArrayGetByteLength() {
+ return %TypedArrayGetByteLength(this);
+}
- function NAME_GetLength() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.length", this]);
- }
- return %_TypedArrayGetLength(this);
- }
+function TypedArrayGetByteOffset() {
+ return %TypedArrayGetByteOffset(this);
+}
- var $NAME = global.NAME;
+function TypedArrayGetLength() {
+ return %TypedArrayGetLength(this);
+}
- function NAMESubArray(begin, end) {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.subarray", this]);
- }
+function CreateSubArray(elementSize, constructor) {
+ return function(begin, end) {
var beginInt = TO_INTEGER(begin);
if (!IS_UNDEFINED(end)) {
end = TO_INTEGER(end);
}
- var srcLength = %_TypedArrayGetLength(this);
+ var srcLength = %TypedArrayGetLength(this);
if (beginInt < 0) {
beginInt = MathMax(0, srcLength + beginInt);
} else {
}
var newLength = endInt - beginInt;
var beginByteOffset =
- %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
- return new $NAME(%TypedArrayGetBuffer(this),
- beginByteOffset, newLength);
+ %TypedArrayGetByteOffset(this) + beginInt * elementSize;
+ return new constructor(%TypedArrayGetBuffer(this),
+ beginByteOffset, newLength);
}
-endmacro
-
-TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
-
+}
function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
if (offset > 0) {
// -------------------------------------------------------------------
-function SetupTypedArrays() {
-macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
+function SetupTypedArray(constructor, fun, elementSize) {
%CheckIsBootstrapping();
- %SetCode(global.NAME, NAMEConstructor);
- %FunctionSetPrototype(global.NAME, new $Object());
+ %SetCode(constructor, fun);
+ %FunctionSetPrototype(constructor, new $Object());
- %SetProperty(global.NAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
+ %SetProperty(constructor, "BYTES_PER_ELEMENT", elementSize,
READ_ONLY | DONT_ENUM | DONT_DELETE);
- %SetProperty(global.NAME.prototype,
- "constructor", global.NAME, DONT_ENUM);
- %SetProperty(global.NAME.prototype,
- "BYTES_PER_ELEMENT", ELEMENT_SIZE,
+ %SetProperty(constructor.prototype,
+ "constructor", constructor, DONT_ENUM);
+ %SetProperty(constructor.prototype,
+ "BYTES_PER_ELEMENT", elementSize,
READ_ONLY | DONT_ENUM | DONT_DELETE);
- InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer);
- InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset);
- InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength);
- InstallGetter(global.NAME.prototype, "length", NAME_GetLength);
+ InstallGetter(constructor.prototype, "buffer", TypedArrayGetBuffer);
+ InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset);
+ InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength);
+ InstallGetter(constructor.prototype, "length", TypedArrayGetLength);
- InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
- "subarray", NAMESubArray,
+ InstallFunctions(constructor.prototype, DONT_ENUM, $Array(
+ "subarray", CreateSubArray(elementSize, constructor),
"set", TypedArraySet
));
+}
+
+macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
+ SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE);
endmacro
TYPED_ARRAYS(SETUP_TYPED_ARRAY)
-}
-
-SetupTypedArrays();
// --------------------------- DataView -----------------------------
byteLength = TO_INTEGER(byteLength);
}
- var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
+ var bufferByteLength = %ArrayBufferGetByteLength(buffer);
var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset;
if (offset > bufferByteLength) {
throw MakeTypeError('incompatible_method_receiver',
['DataView.byteOffset', this]);
}
- return %_ArrayBufferViewGetByteOffset(this);
+ return %DataViewGetByteOffset(this);
}
function DataViewGetByteLength() {
throw MakeTypeError('incompatible_method_receiver',
['DataView.byteLength', this]);
}
- return %_ArrayBufferViewGetByteLength(this);
+ return %DataViewGetByteLength(this);
}
macro DATA_VIEW_TYPES(FUNCTION)
SubarrayTestCase(constructor, item, 10,90, 100, 90);
SubarrayTestCase(constructor, item, 10,90, 100, -10);
-
- var method = constructor.prototype.subarray;
- method.call(new constructor(100), 0, 100);
- var o = {};
- assertThrows(function() { method.call(o, 0, 100); }, TypeError);
}
TestSubArray(Uint8Array, 0xFF);