mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Add tests for TypedArrays reverse
This commit is contained in:
parent
19c09e95d9
commit
800300e120
41
test/built-ins/TypedArray/prototype/reverse/get-length-uses-internal-arraylength.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/reverse/get-length-uses-internal-arraylength.js
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// 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-%typedarray%.prototype.reverse
|
||||||
|
description: Get "length" uses internal ArrayLength
|
||||||
|
info: >
|
||||||
|
22.2.3.22 %TypedArray%.prototype.reverse ( )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.reverse is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the
|
||||||
|
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||||
|
a [[Get]] of "length".
|
||||||
|
|
||||||
|
22.1.3.21 Array.prototype.reverse ( )
|
||||||
|
|
||||||
|
1. Let O be ? ToObject(this value).
|
||||||
|
2. Let len be ? ToLength(? Get(O, "length")).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var getCalls = 0;
|
||||||
|
var desc = {
|
||||||
|
get: function getLen() {
|
||||||
|
getCalls++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([42, 43]);
|
||||||
|
|
||||||
|
Object.defineProperty(TA.prototype, "length", desc);
|
||||||
|
Object.defineProperty(sample, "length", desc);
|
||||||
|
|
||||||
|
sample.reverse();
|
||||||
|
|
||||||
|
assert.sameValue(getCalls, 0, "ignores length properties");
|
||||||
|
});
|
35
test/built-ins/TypedArray/prototype/reverse/preserves-non-numeric-properties.js
vendored
Normal file
35
test/built-ins/TypedArray/prototype/reverse/preserves-non-numeric-properties.js
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// 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-%typedarray%.prototype.reverse
|
||||||
|
description: Preserves non numeric properties
|
||||||
|
info: >
|
||||||
|
22.2.3.22 %TypedArray%.prototype.reverse ( )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.reverse is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the
|
||||||
|
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||||
|
a [[Get]] of "length".
|
||||||
|
|
||||||
|
22.1.3.21 Array.prototype.reverse ( )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Return O.
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var s = Symbol("1");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample, result;
|
||||||
|
|
||||||
|
sample = new TA(2);
|
||||||
|
sample.foo = 42;
|
||||||
|
sample.bar = "bar";
|
||||||
|
sample[s] = 1;
|
||||||
|
result = sample.reverse();
|
||||||
|
assert.sameValue(result.foo, 42, "sample.foo === 42");
|
||||||
|
assert.sameValue(result.bar, "bar", "sample.bar === 'bar'");
|
||||||
|
assert.sameValue(result[s], 1, "sample[s] === 1");
|
||||||
|
});
|
38
test/built-ins/TypedArray/prototype/reverse/returns-original-object.js
vendored
Normal file
38
test/built-ins/TypedArray/prototype/reverse/returns-original-object.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-%typedarray%.prototype.reverse
|
||||||
|
description: Returns the same object
|
||||||
|
info: >
|
||||||
|
22.2.3.22 %TypedArray%.prototype.reverse ( )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.reverse is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the
|
||||||
|
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||||
|
a [[Get]] of "length".
|
||||||
|
|
||||||
|
22.1.3.21 Array.prototype.reverse ( )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Return O.
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var buffer = new ArrayBuffer(64);
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample, result, expectedLength;
|
||||||
|
|
||||||
|
sample = new TA(buffer, 0);
|
||||||
|
expectedLength = sample.length;
|
||||||
|
result = sample.reverse();
|
||||||
|
assert.sameValue(result, sample, "returns the same object");
|
||||||
|
assert.sameValue(sample.buffer, buffer, "keeps the same buffer");
|
||||||
|
assert.sameValue(sample.length, expectedLength, "length is preserved");
|
||||||
|
|
||||||
|
sample = new TA(buffer, 0, 0);
|
||||||
|
result = sample.reverse();
|
||||||
|
assert.sameValue(result, sample, "returns the same object (empty instance)");
|
||||||
|
assert.sameValue(sample.buffer, buffer, "keeps the same buffer (empty instance)");
|
||||||
|
assert.sameValue(sample.length, 0, "length is preserved (empty instance)");
|
||||||
|
});
|
56
test/built-ins/TypedArray/prototype/reverse/reverts.js
vendored
Normal file
56
test/built-ins/TypedArray/prototype/reverse/reverts.js
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// 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-%typedarray%.prototype.reverse
|
||||||
|
description: Reverts values
|
||||||
|
info: >
|
||||||
|
22.2.3.22 %TypedArray%.prototype.reverse ( )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.reverse is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the
|
||||||
|
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||||
|
a [[Get]] of "length".
|
||||||
|
|
||||||
|
22.1.3.21 Array.prototype.reverse ( )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Return O.
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var buffer = new ArrayBuffer(64);
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(buffer, 0, 4);
|
||||||
|
var other = new TA(buffer, 0, 5);
|
||||||
|
|
||||||
|
sample[0] = 42;
|
||||||
|
sample[1] = 43;
|
||||||
|
sample[2] = 2;
|
||||||
|
sample[3] = 1;
|
||||||
|
other[4] = 7;
|
||||||
|
|
||||||
|
sample.reverse();
|
||||||
|
assert(
|
||||||
|
compareArray(sample, [1, 2, 43, 42])
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(other, [1, 2, 43, 42, 7])
|
||||||
|
);
|
||||||
|
|
||||||
|
sample[0] = 7;
|
||||||
|
sample[1] = 17;
|
||||||
|
sample[2] = 1;
|
||||||
|
sample[3] = 0;
|
||||||
|
other[4] = 42;
|
||||||
|
|
||||||
|
other.reverse();
|
||||||
|
assert(
|
||||||
|
compareArray(other, [42, 0, 1, 17, 7])
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(sample, [42, 0, 1, 17])
|
||||||
|
);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user