mirror of https://github.com/tc39/test262.git
Add tests for DataView.prototype.getUint32
This commit is contained in:
parent
0d5b6ea20c
commit
7f8e559cda
54
test/built-ins/DataView/prototype/getUint32/byteoffset-is-different-integer-throws.js
vendored
Normal file
54
test/built-ins/DataView/prototype/getUint32/byteoffset-is-different-integer-throws.js
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Throws a RangeError if numberIndex ≠ getIndex
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
4. Let numberIndex be ? ToNumber(requestIndex).
|
||||
5. Let getIndex be ToInteger(numberIndex).
|
||||
6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(12);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32();
|
||||
}, "no args");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(undefined);
|
||||
}, "undefined");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(1.1);
|
||||
}, "floating number");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(0.1);
|
||||
}, "0.1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(NaN);
|
||||
}, "NaN");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(-0.1);
|
||||
}, "-0.1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(-1.1);
|
||||
}, "-1.1");
|
34
test/built-ins/DataView/prototype/getUint32/byteoffset-is-negative-throws.js
vendored
Normal file
34
test/built-ins/DataView/prototype/getUint32/byteoffset-is-negative-throws.js
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Throws a RangeError if getIndex < 0
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
4. Let numberIndex be ? ToNumber(requestIndex).
|
||||
5. Let getIndex be ToInteger(numberIndex).
|
||||
6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(12);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(-1);
|
||||
}, "-1");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(-Infinity);
|
||||
}, "-Infinity");
|
38
test/built-ins/DataView/prototype/getUint32/detached-buffer-after-integer-byteoffset.js
vendored
Normal file
38
test/built-ins/DataView/prototype/getUint32/detached-buffer-after-integer-byteoffset.js
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Detached buffer is checked after checking If numberIndex ≠ getIndex or
|
||||
getIndex < 0,
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
|
||||
...
|
||||
8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot.
|
||||
9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
...
|
||||
includes: [detachArrayBuffer.js]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
$DETACHBUFFER(buffer);
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(1.1);
|
||||
});
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(-1);
|
||||
});
|
40
test/built-ins/DataView/prototype/getUint32/detached-buffer-before-outofrange-byteoffset.js
vendored
Normal file
40
test/built-ins/DataView/prototype/getUint32/detached-buffer-before-outofrange-byteoffset.js
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Detached buffer is checked before out of range byteOffset's value
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot.
|
||||
9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
...
|
||||
13. If getIndex + elementSize > viewSize, throw a RangeError exception.
|
||||
...
|
||||
includes: [detachArrayBuffer.js]
|
||||
---*/
|
||||
|
||||
var sample;
|
||||
var buffer = new ArrayBuffer(12);
|
||||
|
||||
sample = new DataView(buffer, 0);
|
||||
|
||||
$DETACHBUFFER(buffer);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.getUint32(Infinity);
|
||||
}, "Infinity");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.getUint32(13);
|
||||
}, "13");
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Throws a TypeError if buffer is detached
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot.
|
||||
9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
...
|
||||
includes: [detachArrayBuffer.js]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(1);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
$DETACHBUFFER(buffer);
|
||||
assert.throws(TypeError, function() {
|
||||
sample.getUint32(0);
|
||||
});
|
|
@ -0,0 +1,84 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Throws a RangeError if getIndex + elementSize > viewSize
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
10. Let viewOffset be the value of view's [[ByteOffset]] internal slot.
|
||||
11. Let viewSize be the value of view's [[ByteLength]] internal slot.
|
||||
12. Let elementSize be the Number value of the Element Size value specified in
|
||||
Table 50 for Element Type type.
|
||||
13. If getIndex + elementSize > viewSize, throw a RangeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var sample;
|
||||
var buffer = new ArrayBuffer(12);
|
||||
|
||||
sample = new DataView(buffer, 0);
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(Infinity);
|
||||
}, "getIndex == Infinity");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(13);
|
||||
}, "13 + 4 > 12");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(12);
|
||||
}, "12 + 4 > 12");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(11);
|
||||
}, "11 + 4 > 12");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(10);
|
||||
}, "10 + 4 > 12");
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(9);
|
||||
}, "9 + 4 > 12");
|
||||
|
||||
sample = new DataView(buffer, 8);
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(1);
|
||||
}, "1 + 4 > 4 (offset)");
|
||||
|
||||
sample = new DataView(buffer, 9);
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(0);
|
||||
}, "0 + 4 > 3 (offset)");
|
||||
|
||||
sample = new DataView(buffer, 0, 4);
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(1);
|
||||
}, "1 + 4 > 4 (length)");
|
||||
|
||||
sample = new DataView(buffer, 0, 3);
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(0);
|
||||
}, "0 + 4 > 3 (length)");
|
||||
|
||||
sample = new DataView(buffer, 4, 4);
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(1);
|
||||
}, "1 + 4 > 4 (offset+length)");
|
||||
|
||||
sample = new DataView(buffer, 4, 3);
|
||||
assert.throws(RangeError, function() {
|
||||
sample.getUint32(0);
|
||||
}, "0 + 4 > 3 (offset+length)");
|
31
test/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset-symbol.js
vendored
Normal file
31
test/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset-symbol.js
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Return abrupt from ToNumber(symbol byteOffset)
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
4. Let numberIndex be ? ToNumber(requestIndex).
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(1);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
var s = Symbol("1");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.getUint32(s);
|
||||
});
|
44
test/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset.js
vendored
Normal file
44
test/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset.js
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Return abrupt from ToNumber(byteOffset)
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
4. Let numberIndex be ? ToNumber(requestIndex).
|
||||
...
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(1);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
var bo1 = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
var bo2 = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.getUint32(bo1);
|
||||
}, "valueOf");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.getUint32(bo2);
|
||||
}, "toString");
|
43
test/built-ins/DataView/prototype/getUint32/return-value-clean-arraybuffer.js
vendored
Normal file
43
test/built-ins/DataView/prototype/getUint32/return-value-clean-arraybuffer.js
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Return value from Buffer using a clean ArrayBuffer
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
14. Let bufferIndex be getIndex + viewOffset.
|
||||
15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian).
|
||||
...
|
||||
|
||||
24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian
|
||||
] )
|
||||
|
||||
...
|
||||
8. If isLittleEndian is false, reverse the order of the elements of rawValue.
|
||||
...
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(8);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
assert.sameValue(sample.getUint32(0, true), 0, "sample.getUint32(0, true)");
|
||||
assert.sameValue(sample.getUint32(1, true), 0, "sample.getUint32(1, true)");
|
||||
assert.sameValue(sample.getUint32(2, true), 0, "sample.getUint32(2, true)");
|
||||
assert.sameValue(sample.getUint32(3, true), 0, "sample.getUint32(3, true)");
|
||||
assert.sameValue(sample.getUint32(4, true), 0, "sample.getUint32(4, true)");
|
||||
assert.sameValue(sample.getUint32(0, false), 0, "sample.getUint32(0, false)");
|
||||
assert.sameValue(sample.getUint32(1, false), 0, "sample.getUint32(1, false)");
|
||||
assert.sameValue(sample.getUint32(2, false), 0, "sample.getUint32(2, false)");
|
||||
assert.sameValue(sample.getUint32(3, false), 0, "sample.getUint32(3, false)");
|
||||
assert.sameValue(sample.getUint32(4, false), 0, "sample.getUint32(4, false)");
|
73
test/built-ins/DataView/prototype/getUint32/return-values-coerced-byteoffset.js
vendored
Normal file
73
test/built-ins/DataView/prototype/getUint32/return-values-coerced-byteoffset.js
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Return values using coerced ToInteger byteOffset values
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
14. Let bufferIndex be getIndex + viewOffset.
|
||||
15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian).
|
||||
...
|
||||
|
||||
24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian
|
||||
] )
|
||||
|
||||
...
|
||||
8. If isLittleEndian is false, reverse the order of the elements of rawValue.
|
||||
...
|
||||
features: [DataView.prototype.setUint8]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(5);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
sample.setUint8(0, 127);
|
||||
sample.setUint8(1, 255);
|
||||
sample.setUint8(2, 255);
|
||||
sample.setUint8(3, 255);
|
||||
sample.setUint8(4, 128);
|
||||
|
||||
assert.sameValue(sample.getUint32("", false), 2147483647, "'', false");
|
||||
assert.sameValue(sample.getUint32("", true), 4294967167, "'', true");
|
||||
|
||||
assert.sameValue(sample.getUint32("0", false), 2147483647, "'0', false");
|
||||
assert.sameValue(sample.getUint32("0", true), 4294967167, "'0', true");
|
||||
|
||||
assert.sameValue(sample.getUint32("1", false), 4294967168, "'1', false");
|
||||
assert.sameValue(sample.getUint32("1", true), 2164260863, "'1', true");
|
||||
|
||||
var obj1 = {
|
||||
valueOf: function() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
assert.sameValue(sample.getUint32(obj1, false), 4294967168, "{}.valueOf, false");
|
||||
assert.sameValue(sample.getUint32(obj1, true), 2164260863, "{}.valueOf, true");
|
||||
|
||||
var obj2 = {
|
||||
toString: function() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
assert.sameValue(sample.getUint32(obj2, false), 4294967168, "{}.toString, false");
|
||||
assert.sameValue(sample.getUint32(obj2, true), 2164260863, "{}.toString, true");
|
||||
|
||||
assert.sameValue(sample.getUint32(true, false), 4294967168, "true, false");
|
||||
assert.sameValue(sample.getUint32(true, true), 2164260863, "true, true");
|
||||
|
||||
assert.sameValue(sample.getUint32(false, false), 2147483647, "false, false");
|
||||
assert.sameValue(sample.getUint32(false, true), 4294967167, "false, true");
|
||||
|
||||
assert.sameValue(sample.getUint32(null, false), 2147483647, "null, false");
|
||||
assert.sameValue(sample.getUint32(null, true), 4294967167, "null, true");
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Return values from Buffer using a custom offset
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
14. Let bufferIndex be getIndex + viewOffset.
|
||||
15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian).
|
||||
...
|
||||
|
||||
24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian
|
||||
] )
|
||||
|
||||
...
|
||||
8. If isLittleEndian is false, reverse the order of the elements of rawValue.
|
||||
...
|
||||
features: [DataView.prototype.setUint8]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(12);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
sample.setUint8(0, 39);
|
||||
sample.setUint8(1, 2);
|
||||
sample.setUint8(2, 6);
|
||||
sample.setUint8(3, 2);
|
||||
sample.setUint8(4, 128);
|
||||
sample.setUint8(5, 0);
|
||||
sample.setUint8(6, 128);
|
||||
sample.setUint8(7, 1);
|
||||
sample.setUint8(8, 127);
|
||||
sample.setUint8(9, 0);
|
||||
sample.setUint8(10, 127);
|
||||
sample.setUint8(11, 1);
|
||||
|
||||
sample = new DataView(buffer, 4);
|
||||
|
||||
assert.sameValue(sample.getUint32(0, false), 2147516417, "0, false");
|
||||
assert.sameValue(sample.getUint32(1, false), 8388991, "1, false");
|
||||
assert.sameValue(sample.getUint32(2, false), 2147581696, "2, false");
|
||||
assert.sameValue(sample.getUint32(3, false), 25100415, "3, false");
|
||||
|
||||
assert.sameValue(sample.getUint32(0, true), 25165952, "0, true");
|
||||
assert.sameValue(sample.getUint32(1, true), 2130804736, "1, true");
|
||||
assert.sameValue(sample.getUint32(2, true), 8323456, "2, true");
|
||||
assert.sameValue(sample.getUint32(3, true), 2130738945, "3, true");
|
|
@ -0,0 +1,66 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Return values from Buffer
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
14. Let bufferIndex be getIndex + viewOffset.
|
||||
15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian).
|
||||
...
|
||||
|
||||
24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian
|
||||
] )
|
||||
|
||||
...
|
||||
8. If isLittleEndian is false, reverse the order of the elements of rawValue.
|
||||
...
|
||||
features: [DataView.prototype.setUint8]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(12);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
sample.setUint8(0, 127);
|
||||
sample.setUint8(1, 255);
|
||||
sample.setUint8(2, 255);
|
||||
sample.setUint8(3, 255);
|
||||
sample.setUint8(4, 128);
|
||||
sample.setUint8(5, 0);
|
||||
sample.setUint8(6, 0);
|
||||
sample.setUint8(7, 0);
|
||||
sample.setUint8(8, 1);
|
||||
sample.setUint8(9, 0);
|
||||
sample.setUint8(10, 0);
|
||||
sample.setUint8(11, 0);
|
||||
|
||||
assert.sameValue(sample.getUint32(0, false), 2147483647, "0, false");
|
||||
assert.sameValue(sample.getUint32(1, false), 4294967168, "1, false");
|
||||
assert.sameValue(sample.getUint32(2, false), 4294934528, "2, false");
|
||||
assert.sameValue(sample.getUint32(3, false), 4286578688, "3, false");
|
||||
assert.sameValue(sample.getUint32(4, false), 2147483648, "4, false");
|
||||
assert.sameValue(sample.getUint32(5, false), 1, "5, false");
|
||||
assert.sameValue(sample.getUint32(6, false), 256, "6, false");
|
||||
assert.sameValue(sample.getUint32(7, false), 65536, "7, false");
|
||||
assert.sameValue(sample.getUint32(8, false), 16777216, "8, false");
|
||||
|
||||
assert.sameValue(sample.getUint32(0, true), 4294967167, "0, true");
|
||||
assert.sameValue(sample.getUint32(1, true), 2164260863, "1, true");
|
||||
assert.sameValue(sample.getUint32(2, true), 8454143, "2, true");
|
||||
assert.sameValue(sample.getUint32(3, true), 33023, "3, true");
|
||||
assert.sameValue(sample.getUint32(4, true), 128, "4, true");
|
||||
assert.sameValue(sample.getUint32(5, true), 16777216, "5, true");
|
||||
assert.sameValue(sample.getUint32(6, true), 65536, "6, true");
|
||||
assert.sameValue(sample.getUint32(7, true), 256, "7, true");
|
||||
assert.sameValue(sample.getUint32(8, true), 1, "8, true");
|
43
test/built-ins/DataView/prototype/getUint32/this-has-no-dataview-internal.js
vendored
Normal file
43
test/built-ins/DataView/prototype/getUint32/this-has-no-dataview-internal.js
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Throws a TypeError if this does not have a [[DataView]] internal slot
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
1. If Type(view) is not Object, throw a TypeError exception.
|
||||
2. If view does not have a [[DataView]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
features: [Int8Array]
|
||||
---*/
|
||||
|
||||
var getUint32 = DataView.prototype.getUint32;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call({});
|
||||
}, "{}");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call([]);
|
||||
}, "[]");
|
||||
|
||||
var ab = new ArrayBuffer(1);
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(ab);
|
||||
}, "ArrayBuffer");
|
||||
|
||||
var ta = new Int8Array();
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(ta);
|
||||
}, "TypedArray");
|
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: Throws a TypeError if this is not Object
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
1. If Type(view) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var getUint32 = DataView.prototype.getUint32;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(undefined);
|
||||
}, "undefined");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(null);
|
||||
}, "null");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(1);
|
||||
}, "1");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call("string");
|
||||
}, "string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(true);
|
||||
}, "true");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(false);
|
||||
}, "false");
|
||||
|
||||
var s = Symbol("1");
|
||||
assert.throws(TypeError, function() {
|
||||
getUint32.call(s);
|
||||
}, "symbol");
|
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-dataview.prototype.getuint32
|
||||
es6id: 24.2.4.12
|
||||
description: >
|
||||
Boolean littleEndian argument coerced in ToBoolean
|
||||
info: |
|
||||
24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
|
||||
|
||||
1. Let v be the this value.
|
||||
2. If littleEndian is not present, let littleEndian be false.
|
||||
3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32").
|
||||
|
||||
24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
|
||||
|
||||
...
|
||||
14. Let bufferIndex be getIndex + viewOffset.
|
||||
15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian).
|
||||
...
|
||||
|
||||
24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian
|
||||
] )
|
||||
|
||||
...
|
||||
8. If isLittleEndian is false, reverse the order of the elements of rawValue.
|
||||
...
|
||||
features: [DataView.prototype.setUint8, Symbol]
|
||||
---*/
|
||||
|
||||
var buffer = new ArrayBuffer(4);
|
||||
var sample = new DataView(buffer, 0);
|
||||
|
||||
sample.setUint8(0, 0);
|
||||
sample.setUint8(1, 17);
|
||||
sample.setUint8(2, 4);
|
||||
sample.setUint8(3, 0);
|
||||
|
||||
// False
|
||||
assert.sameValue(sample.getUint32(0), 1115136, "no arg");
|
||||
assert.sameValue(sample.getUint32(0, undefined), 1115136, "undefined");
|
||||
assert.sameValue(sample.getUint32(0, null), 1115136, "null");
|
||||
assert.sameValue(sample.getUint32(0, 0), 1115136, "0");
|
||||
assert.sameValue(sample.getUint32(0, ""), 1115136, "the empty string");
|
||||
|
||||
// True
|
||||
assert.sameValue(sample.getUint32(0, {}), 266496, "{}");
|
||||
assert.sameValue(sample.getUint32(0, Symbol("1")), 266496, "symbol");
|
||||
assert.sameValue(sample.getUint32(0, 1), 266496, "1");
|
||||
assert.sameValue(sample.getUint32(0, "string"), 266496, "string");
|
Loading…
Reference in New Issue