Skip to content
Snippets Groups Projects
Commit 755b0d61 authored by Leonardo Balter's avatar Leonardo Balter Committed by Mike Pennisi
Browse files

Add tests for typedArrays extensibility

parent c4086508
No related branches found
No related tags found
No related merge requests found
// 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-buffer-byteoffset-length
description: >
The new typedArray instance from a buffer argument is extensible
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
"%TypedArrayPrototype%").
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
...
2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
11. Set the [[Extensible]] internal slot of A to true.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var buffer = new ArrayBuffer(8);
var sample = new TA(buffer);
assert(Object.isExtensible(sample));
});
// 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-length
description: >
The new typedArray instance from a length argument is extensible
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
8. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, elementLength).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
...
2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
11. Set the [[Extensible]] internal slot of A to true.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(4);
assert(Object.isExtensible(sample));
});
// 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
description: >
The new typedArray instance is extensible
info: >
22.2.4.1 TypedArray( )
This description applies only if the TypedArray function is called with no
arguments.
...
3. Return ? AllocateTypedArray(constructorName, NewTarget,
%TypedArrayPrototype%, 0).
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
...
2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
11. Set the [[Extensible]] internal slot of A to true.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
assert(Object.isExtensible(sample));
});
// 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-object
description: >
The new typedArray instance from an object argument is extensible
info: >
22.2.4.4 TypedArray ( object )
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
"%TypedArrayPrototype%").
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
...
2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
11. Set the [[Extensible]] internal slot of A to true.
...
includes: [testTypedArray.js]
---*/
var obj = {
"0": 0,
"1": 1,
"2": 2,
length: 3
};
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(obj);
assert(Object.isExtensible(sample));
});
// 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-typedarray
description: >
The new typedArray instance from a typedArray argument is extensible
info: >
22.2.4.3 TypedArray ( typedArray )
...
4. Let O be ? AllocateTypedArray(constructorName, NewTarget,
"%TypedArrayPrototype%").
...
22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget,
defaultProto [ , length ])
...
2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]],
[[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »).
...
9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList)
...
11. Set the [[Extensible]] internal slot of A to true.
...
includes: [testTypedArray.js]
---*/
var typedArraySample1 = new Int8Array();
var typedArraySample2 = new Int8Array();
Object.preventExtensions(typedArraySample2);
testWithTypedArrayConstructors(function(TA) {
var sample1 = new TA(typedArraySample1);
assert(Object.isExtensible(sample1), "new instance is extensible");
var sample2 = new TA(typedArraySample2);
assert(
Object.isExtensible(sample2),
"new instance does not inherit extensibility from typedarray argument"
);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment