2013-03-28 12:50:18 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2013-04-11 12:15:25 +00:00
|
|
|
// This file relies on the fact that the following declaration has been made
|
|
|
|
// in runtime.js:
|
|
|
|
// var $Array = global.Array;
|
2013-10-15 11:27:12 +00:00
|
|
|
var $ArrayBuffer = global.ArrayBuffer;
|
2013-03-28 12:50:18 +00:00
|
|
|
|
|
|
|
|
2013-04-16 14:16:30 +00:00
|
|
|
// --------------- Typed Arrays ---------------------
|
2013-11-05 14:08:03 +00:00
|
|
|
macro TYPED_ARRAYS(FUNCTION)
|
|
|
|
// arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
|
|
|
|
FUNCTION(1, Uint8Array, 1)
|
|
|
|
FUNCTION(2, Int8Array, 1)
|
|
|
|
FUNCTION(3, Uint16Array, 2)
|
|
|
|
FUNCTION(4, Int16Array, 2)
|
|
|
|
FUNCTION(5, Uint32Array, 4)
|
|
|
|
FUNCTION(6, Int32Array, 4)
|
|
|
|
FUNCTION(7, Float32Array, 4)
|
|
|
|
FUNCTION(8, Float64Array, 8)
|
|
|
|
FUNCTION(9, Uint8ClampedArray, 1)
|
|
|
|
endmacro
|
2013-04-16 14:16:30 +00:00
|
|
|
|
2013-11-05 14:08:03 +00:00
|
|
|
macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
|
2013-11-06 16:28:38 +00:00
|
|
|
function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
|
|
|
|
var bufferByteLength = buffer.byteLength;
|
2013-11-07 14:56:40 +00:00
|
|
|
var offset;
|
|
|
|
if (IS_UNDEFINED(byteOffset)) {
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length");
|
|
|
|
|
|
|
|
if (offset % ELEMENT_SIZE !== 0) {
|
|
|
|
throw MakeRangeError("invalid_typed_array_alignment",
|
|
|
|
"start offset", "NAME", ELEMENT_SIZE);
|
|
|
|
}
|
|
|
|
if (offset > bufferByteLength) {
|
|
|
|
throw MakeRangeError("invalid_typed_array_offset");
|
|
|
|
}
|
2013-11-06 16:28:38 +00:00
|
|
|
}
|
2013-11-05 14:08:03 +00:00
|
|
|
|
2013-11-06 16:28:38 +00:00
|
|
|
var newByteLength;
|
|
|
|
var newLength;
|
|
|
|
if (IS_UNDEFINED(length)) {
|
|
|
|
if (bufferByteLength % ELEMENT_SIZE !== 0) {
|
|
|
|
throw MakeRangeError("invalid_typed_array_alignment",
|
|
|
|
"byte length", "NAME", ELEMENT_SIZE);
|
2013-11-05 14:08:03 +00:00
|
|
|
}
|
2013-11-06 16:28:38 +00:00
|
|
|
newByteLength = bufferByteLength - offset;
|
|
|
|
newLength = newByteLength / ELEMENT_SIZE;
|
|
|
|
} else {
|
|
|
|
var newLength = ToPositiveInteger(length, "invalid_typed_array_length");
|
|
|
|
newByteLength = newLength * ELEMENT_SIZE;
|
2013-04-29 16:16:31 +00:00
|
|
|
}
|
2013-11-06 16:28:38 +00:00
|
|
|
if (offset + newByteLength > bufferByteLength) {
|
|
|
|
throw MakeRangeError("invalid_typed_array_length");
|
2013-11-05 14:08:03 +00:00
|
|
|
}
|
2013-11-06 16:28:38 +00:00
|
|
|
%TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
|
|
|
|
}
|
2013-04-16 14:16:30 +00:00
|
|
|
|
2013-11-06 16:28:38 +00:00
|
|
|
function NAMEConstructByLength(obj, length) {
|
2013-11-07 14:56:40 +00:00
|
|
|
var l = IS_UNDEFINED(length) ?
|
|
|
|
0 : ToPositiveInteger(length, "invalid_typed_array_length");
|
2013-11-06 16:28:38 +00:00
|
|
|
var byteLength = l * ELEMENT_SIZE;
|
|
|
|
var buffer = new $ArrayBuffer(byteLength);
|
|
|
|
%TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
function NAMEConstructByArrayLike(obj, arrayLike) {
|
|
|
|
var length = arrayLike.length;
|
|
|
|
var l = ToPositiveInteger(length, "invalid_typed_array_length");
|
|
|
|
if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
|
|
|
|
for (var i = 0; i < l; i++) {
|
|
|
|
// It is crucial that we let any execptions from arrayLike[i]
|
|
|
|
// propagate outside the function.
|
|
|
|
obj[i] = arrayLike[i];
|
2013-08-01 08:52:21 +00:00
|
|
|
}
|
2013-05-02 12:27:03 +00:00
|
|
|
}
|
2013-11-06 16:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function NAMEConstructor(arg1, arg2, arg3) {
|
2013-05-02 12:27:03 +00:00
|
|
|
|
2013-04-29 16:16:31 +00:00
|
|
|
if (%_IsConstructCall()) {
|
|
|
|
if (IS_ARRAYBUFFER(arg1)) {
|
2013-11-06 16:28:38 +00:00
|
|
|
NAMEConstructByArrayBuffer(this, arg1, arg2, arg3);
|
2013-07-09 19:34:21 +00:00
|
|
|
} else if (IS_NUMBER(arg1) || IS_STRING(arg1) ||
|
|
|
|
IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
|
2013-11-06 16:28:38 +00:00
|
|
|
NAMEConstructByLength(this, arg1);
|
2013-05-02 12:27:03 +00:00
|
|
|
} else {
|
2013-11-06 16:28:38 +00:00
|
|
|
NAMEConstructByArrayLike(this, arg1);
|
2013-04-16 14:16:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-11-05 14:08:03 +00:00
|
|
|
throw MakeTypeError("constructor_not_function", ["NAME"])
|
2013-04-16 14:16:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-05 14:08:03 +00:00
|
|
|
endmacro
|
|
|
|
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
|
2013-04-16 14:16:30 +00:00
|
|
|
|
|
|
|
function TypedArrayGetBuffer() {
|
|
|
|
return %TypedArrayGetBuffer(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function TypedArrayGetByteLength() {
|
|
|
|
return %TypedArrayGetByteLength(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function TypedArrayGetByteOffset() {
|
|
|
|
return %TypedArrayGetByteOffset(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function TypedArrayGetLength() {
|
|
|
|
return %TypedArrayGetLength(this);
|
|
|
|
}
|
|
|
|
|
2013-05-03 09:43:44 +00:00
|
|
|
function CreateSubArray(elementSize, constructor) {
|
|
|
|
return function(begin, end) {
|
|
|
|
var srcLength = %TypedArrayGetLength(this);
|
|
|
|
var beginInt = TO_INTEGER(begin);
|
|
|
|
if (beginInt < 0) {
|
|
|
|
beginInt = MathMax(0, srcLength + beginInt);
|
|
|
|
} else {
|
|
|
|
beginInt = MathMin(srcLength, beginInt);
|
|
|
|
}
|
|
|
|
|
|
|
|
var endInt = IS_UNDEFINED(end) ? srcLength : TO_INTEGER(end);
|
|
|
|
if (endInt < 0) {
|
|
|
|
endInt = MathMax(0, srcLength + endInt);
|
|
|
|
} else {
|
|
|
|
endInt = MathMin(endInt, srcLength);
|
|
|
|
}
|
|
|
|
if (endInt < beginInt) {
|
|
|
|
endInt = beginInt;
|
|
|
|
}
|
|
|
|
var newLength = endInt - beginInt;
|
|
|
|
var beginByteOffset =
|
|
|
|
%TypedArrayGetByteOffset(this) + beginInt * elementSize;
|
|
|
|
return new constructor(%TypedArrayGetBuffer(this),
|
|
|
|
beginByteOffset, newLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-31 12:10:49 +00:00
|
|
|
function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
|
|
|
|
if (offset > 0) {
|
|
|
|
for (var i = 0; i < sourceLength; i++) {
|
|
|
|
target[offset + i] = source[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (var i = 0; i < sourceLength; i++) {
|
|
|
|
target[i] = source[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function TypedArraySetFromOverlappingTypedArray(target, source, offset) {
|
|
|
|
var sourceElementSize = source.BYTES_PER_ELEMENT;
|
|
|
|
var targetElementSize = target.BYTES_PER_ELEMENT;
|
|
|
|
var sourceLength = source.length;
|
|
|
|
|
|
|
|
// Copy left part.
|
|
|
|
function CopyLeftPart() {
|
|
|
|
// First un-mutated byte after the next write
|
|
|
|
var targetPtr = target.byteOffset + (offset + 1) * targetElementSize;
|
|
|
|
// Next read at sourcePtr. We do not care for memory changing before
|
|
|
|
// sourcePtr - we have already copied it.
|
|
|
|
var sourcePtr = source.byteOffset;
|
|
|
|
for (var leftIndex = 0;
|
|
|
|
leftIndex < sourceLength && targetPtr <= sourcePtr;
|
|
|
|
leftIndex++) {
|
|
|
|
target[offset + leftIndex] = source[leftIndex];
|
|
|
|
targetPtr += targetElementSize;
|
|
|
|
sourcePtr += sourceElementSize;
|
|
|
|
}
|
|
|
|
return leftIndex;
|
|
|
|
}
|
|
|
|
var leftIndex = CopyLeftPart();
|
|
|
|
|
|
|
|
// Copy rigth part;
|
|
|
|
function CopyRightPart() {
|
|
|
|
// First unmutated byte before the next write
|
|
|
|
var targetPtr =
|
|
|
|
target.byteOffset + (offset + sourceLength - 1) * targetElementSize;
|
|
|
|
// Next read before sourcePtr. We do not care for memory changing after
|
|
|
|
// sourcePtr - we have already copied it.
|
|
|
|
var sourcePtr =
|
|
|
|
source.byteOffset + sourceLength * sourceElementSize;
|
|
|
|
for(var rightIndex = sourceLength - 1;
|
|
|
|
rightIndex >= leftIndex && targetPtr >= sourcePtr;
|
|
|
|
rightIndex--) {
|
|
|
|
target[offset + rightIndex] = source[rightIndex];
|
|
|
|
targetPtr -= targetElementSize;
|
|
|
|
sourcePtr -= sourceElementSize;
|
|
|
|
}
|
|
|
|
return rightIndex;
|
|
|
|
}
|
|
|
|
var rightIndex = CopyRightPart();
|
|
|
|
|
|
|
|
var temp = new $Array(rightIndex + 1 - leftIndex);
|
|
|
|
for (var i = leftIndex; i <= rightIndex; i++) {
|
|
|
|
temp[i - leftIndex] = source[i];
|
|
|
|
}
|
|
|
|
for (i = leftIndex; i <= rightIndex; i++) {
|
|
|
|
target[offset + i] = temp[i - leftIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 14:42:17 +00:00
|
|
|
function TypedArraySet(obj, offset) {
|
2013-06-24 13:58:52 +00:00
|
|
|
var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset);
|
|
|
|
if (intOffset < 0) {
|
|
|
|
throw MakeTypeError("typed_array_set_negative_offset");
|
|
|
|
}
|
2013-07-31 12:10:49 +00:00
|
|
|
switch (%TypedArraySetFastCases(this, obj, intOffset)) {
|
|
|
|
// These numbers should be synchronized with runtime.cc.
|
|
|
|
case 0: // TYPED_ARRAY_SET_TYPED_ARRAY_SAME_TYPE
|
|
|
|
return;
|
|
|
|
case 1: // TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING
|
|
|
|
TypedArraySetFromOverlappingTypedArray(this, obj, intOffset);
|
|
|
|
return;
|
|
|
|
case 2: // TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING
|
|
|
|
TypedArraySetFromArrayLike(this, obj, obj.length, intOffset);
|
|
|
|
return;
|
|
|
|
case 3: // TYPED_ARRAY_SET_NON_TYPED_ARRAY
|
|
|
|
var l = obj.length;
|
|
|
|
if (IS_UNDEFINED(l)) {
|
|
|
|
if (IS_NUMBER(obj)) {
|
|
|
|
// For number as a first argument, throw TypeError
|
|
|
|
// instead of silently ignoring the call, so that
|
|
|
|
// the user knows (s)he did something wrong.
|
|
|
|
// (Consistent with Firefox and Blink/WebKit)
|
|
|
|
throw MakeTypeError("invalid_argument");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (intOffset + l > this.length) {
|
|
|
|
throw MakeRangeError("typed_array_set_source_too_large");
|
|
|
|
}
|
|
|
|
TypedArraySetFromArrayLike(this, obj, l, intOffset);
|
|
|
|
return;
|
2013-05-07 14:42:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-28 12:50:18 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2013-11-05 14:08:03 +00:00
|
|
|
function SetupTypedArray(constructor, fun, elementSize) {
|
2013-04-29 16:16:31 +00:00
|
|
|
%CheckIsBootstrapping();
|
|
|
|
%SetCode(constructor, fun);
|
2013-04-16 14:16:30 +00:00
|
|
|
%FunctionSetPrototype(constructor, new $Object());
|
|
|
|
|
2013-07-17 11:16:07 +00:00
|
|
|
%SetProperty(constructor, "BYTES_PER_ELEMENT", elementSize,
|
|
|
|
READ_ONLY | DONT_ENUM | DONT_DELETE);
|
2013-04-16 14:16:30 +00:00
|
|
|
%SetProperty(constructor.prototype,
|
|
|
|
"constructor", constructor, DONT_ENUM);
|
|
|
|
%SetProperty(constructor.prototype,
|
|
|
|
"BYTES_PER_ELEMENT", elementSize,
|
|
|
|
READ_ONLY | DONT_ENUM | DONT_DELETE);
|
|
|
|
InstallGetter(constructor.prototype, "buffer", TypedArrayGetBuffer);
|
|
|
|
InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset);
|
|
|
|
InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength);
|
|
|
|
InstallGetter(constructor.prototype, "length", TypedArrayGetLength);
|
2013-05-03 09:43:44 +00:00
|
|
|
|
|
|
|
InstallFunctions(constructor.prototype, DONT_ENUM, $Array(
|
2013-05-07 14:42:17 +00:00
|
|
|
"subarray", CreateSubArray(elementSize, constructor),
|
|
|
|
"set", TypedArraySet
|
2013-05-03 09:43:44 +00:00
|
|
|
));
|
2013-04-16 14:16:30 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 14:08:03 +00:00
|
|
|
macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
|
|
|
|
SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE);
|
|
|
|
endmacro
|
|
|
|
|
|
|
|
TYPED_ARRAYS(SETUP_TYPED_ARRAY)
|
2013-06-21 13:02:38 +00:00
|
|
|
|
|
|
|
// --------------------------- DataView -----------------------------
|
|
|
|
|
|
|
|
var $DataView = global.DataView;
|
|
|
|
|
|
|
|
function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
|
|
|
|
if (%_IsConstructCall()) {
|
|
|
|
if (!IS_ARRAYBUFFER(buffer)) {
|
|
|
|
throw MakeTypeError('data_view_not_array_buffer', []);
|
|
|
|
}
|
|
|
|
var bufferByteLength = %ArrayBufferGetByteLength(buffer);
|
2013-11-07 14:56:40 +00:00
|
|
|
var offset = IS_UNDEFINED(byteOffset) ?
|
|
|
|
0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
|
2013-06-21 13:02:38 +00:00
|
|
|
if (offset > bufferByteLength) {
|
2013-06-24 13:58:52 +00:00
|
|
|
throw MakeRangeError('invalid_data_view_offset');
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
var length = IS_UNDEFINED(byteLength) ?
|
2013-06-24 13:58:52 +00:00
|
|
|
bufferByteLength - offset : TO_INTEGER(byteLength);
|
|
|
|
if (length < 0 || offset + length > bufferByteLength) {
|
2013-06-21 13:02:38 +00:00
|
|
|
throw new MakeRangeError('invalid_data_view_length');
|
|
|
|
}
|
|
|
|
%DataViewInitialize(this, buffer, offset, length);
|
|
|
|
} else {
|
2013-06-27 07:42:08 +00:00
|
|
|
throw MakeTypeError('constructor_not_function', ["DataView"]);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetBuffer() {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.buffer', this]);
|
|
|
|
}
|
|
|
|
return %DataViewGetBuffer(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetByteOffset() {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.byteOffset', this]);
|
|
|
|
}
|
|
|
|
return %DataViewGetByteOffset(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetByteLength() {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.byteLength', this]);
|
|
|
|
}
|
|
|
|
return %DataViewGetByteLength(this);
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:58:52 +00:00
|
|
|
function ToPositiveDataViewOffset(offset) {
|
|
|
|
return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset');
|
|
|
|
}
|
|
|
|
|
2013-06-21 13:02:38 +00:00
|
|
|
function DataViewGetInt8(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getInt8', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-24 13:58:52 +00:00
|
|
|
return %DataViewGetInt8(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetInt8(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setInt8', this]);
|
|
|
|
}
|
2013-07-24 17:35:15 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
2013-07-10 16:18:59 +00:00
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetInt8(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetUint8(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getUint8', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-24 13:58:52 +00:00
|
|
|
return %DataViewGetUint8(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetUint8(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setUint8', this]);
|
|
|
|
}
|
2013-07-24 17:35:15 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
2013-07-10 16:18:59 +00:00
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetUint8(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetInt16(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getInt16', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-24 13:58:52 +00:00
|
|
|
return %DataViewGetInt16(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetInt16(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setInt16', this]);
|
|
|
|
}
|
2013-07-24 17:35:15 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
2013-07-10 16:18:59 +00:00
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetInt16(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetUint16(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getUint16', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-24 13:58:52 +00:00
|
|
|
return %DataViewGetUint16(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetUint16(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setUint16', this]);
|
|
|
|
}
|
2013-07-24 17:35:15 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
2013-07-10 16:18:59 +00:00
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetUint16(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetInt32(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getInt32', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-24 13:58:52 +00:00
|
|
|
return %DataViewGetInt32(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetInt32(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setInt32', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetInt32(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetUint32(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getUint32', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-24 13:58:52 +00:00
|
|
|
return %DataViewGetUint32(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetUint32(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setUint32', this]);
|
|
|
|
}
|
2013-07-24 17:35:15 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
2013-07-10 16:18:59 +00:00
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetUint32(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetFloat32(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getFloat32', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-24 13:58:52 +00:00
|
|
|
return %DataViewGetFloat32(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetFloat32(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setFloat32', this]);
|
|
|
|
}
|
2013-07-24 17:35:15 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
2013-07-10 16:18:59 +00:00
|
|
|
throw MakeTypeError('invalid_argument');
|
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetFloat32(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewGetFloat64(offset, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.getFloat64', this]);
|
|
|
|
}
|
2013-07-10 16:18:59 +00:00
|
|
|
if (%_ArgumentsLength() < 1) {
|
|
|
|
throw MakeTypeError('invalid_argument');
|
2013-06-24 13:58:52 +00:00
|
|
|
}
|
|
|
|
return %DataViewGetFloat64(this,
|
|
|
|
ToPositiveDataViewOffset(offset),
|
|
|
|
!!little_endian);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DataViewSetFloat64(offset, value, little_endian) {
|
|
|
|
if (!IS_DATAVIEW(this)) {
|
2013-07-24 17:35:15 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2013-06-21 13:02:38 +00:00
|
|
|
['DataView.setFloat64', this]);
|
|
|
|
}
|
2013-07-24 17:35:15 +00:00
|
|
|
if (%_ArgumentsLength() < 2) {
|
2013-07-10 16:18:59 +00:00
|
|
|
throw MakeTypeError('invalid_argument');
|
2013-06-24 13:58:52 +00:00
|
|
|
}
|
2013-06-21 13:02:38 +00:00
|
|
|
%DataViewSetFloat64(this,
|
2013-06-24 13:58:52 +00:00
|
|
|
ToPositiveDataViewOffset(offset),
|
2013-06-21 13:02:38 +00:00
|
|
|
TO_NUMBER_INLINE(value),
|
|
|
|
!!little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SetupDataView() {
|
|
|
|
%CheckIsBootstrapping();
|
|
|
|
|
|
|
|
// Setup the DataView constructor.
|
|
|
|
%SetCode($DataView, DataViewConstructor);
|
|
|
|
%FunctionSetPrototype($DataView, new $Object);
|
|
|
|
|
|
|
|
// Set up constructor property on the DataView prototype.
|
|
|
|
%SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM);
|
|
|
|
|
|
|
|
InstallGetter($DataView.prototype, "buffer", DataViewGetBuffer);
|
|
|
|
InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset);
|
|
|
|
InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength);
|
|
|
|
|
|
|
|
InstallFunctions($DataView.prototype, DONT_ENUM, $Array(
|
|
|
|
"getInt8", DataViewGetInt8,
|
|
|
|
"setInt8", DataViewSetInt8,
|
|
|
|
|
|
|
|
"getUint8", DataViewGetUint8,
|
|
|
|
"setUint8", DataViewSetUint8,
|
|
|
|
|
|
|
|
"getInt16", DataViewGetInt16,
|
|
|
|
"setInt16", DataViewSetInt16,
|
|
|
|
|
|
|
|
"getUint16", DataViewGetUint16,
|
|
|
|
"setUint16", DataViewSetUint16,
|
|
|
|
|
|
|
|
"getInt32", DataViewGetInt32,
|
|
|
|
"setInt32", DataViewSetInt32,
|
|
|
|
|
|
|
|
"getUint32", DataViewGetUint32,
|
|
|
|
"setUint32", DataViewSetUint32,
|
|
|
|
|
|
|
|
"getFloat32", DataViewGetFloat32,
|
|
|
|
"setFloat32", DataViewSetFloat32,
|
|
|
|
|
|
|
|
"getFloat64", DataViewGetFloat64,
|
|
|
|
"setFloat64", DataViewSetFloat64
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupDataView();
|