mirror of
				https://github.com/tc39/test262.git
				synced 2025-11-03 21:24:30 +01:00 
			
		
		
		
	Add tests for ArrayBuffer.prototype.byteLength
This commit is contained in:
		
							parent
							
								
									a0cd3b07fc
								
							
						
					
					
						commit
						3af3af3d40
					
				
							
								
								
									
										23
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/detached-buffer.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/detached-buffer.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
 | 
			
		||||
// This code is governed by the BSD license found in the LICENSE file.
 | 
			
		||||
/*---
 | 
			
		||||
es6id: 24.1.4.1
 | 
			
		||||
esid: sec-get-arraybuffer.prototype.bytelength
 | 
			
		||||
description: Returns 0 if the buffer is detached
 | 
			
		||||
info: >
 | 
			
		||||
  24.1.4.1 get ArrayBuffer.prototype.byteLength
 | 
			
		||||
 | 
			
		||||
  1. Let O be the this value.
 | 
			
		||||
  ...
 | 
			
		||||
  4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
 | 
			
		||||
  ...
 | 
			
		||||
includes: [detachArrayBuffer.js]
 | 
			
		||||
---*/
 | 
			
		||||
 | 
			
		||||
var ab = new ArrayBuffer(1);
 | 
			
		||||
 | 
			
		||||
$DETACHBUFFER(ab);
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  ab.byteLength;
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										19
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/invoked-as-accessor.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/invoked-as-accessor.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
 | 
			
		||||
// This code is governed by the BSD license found in the LICENSE file.
 | 
			
		||||
/*---
 | 
			
		||||
es6id: 24.1.4.1
 | 
			
		||||
esid: sec-get-arraybuffer.prototype.bytelength
 | 
			
		||||
description: Requires this value to have a [[ArrayBufferData]] internal slot
 | 
			
		||||
info: >
 | 
			
		||||
  24.1.4.1 get ArrayBuffer.prototype.byteLength
 | 
			
		||||
 | 
			
		||||
  1. Let O be the this value.
 | 
			
		||||
  2. If Type(O) is not Object, throw a TypeError exception.
 | 
			
		||||
  3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError
 | 
			
		||||
  exception.
 | 
			
		||||
  ...
 | 
			
		||||
---*/
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  ArrayBuffer.prototype.byteLength;
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										23
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/invoked-as-func.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/invoked-as-func.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
 | 
			
		||||
// This code is governed by the BSD license found in the LICENSE file.
 | 
			
		||||
/*---
 | 
			
		||||
es6id: 24.1.4.1
 | 
			
		||||
esid: sec-get-arraybuffer.prototype.bytelength
 | 
			
		||||
description: Throws a TypeError exception when invoked as a function
 | 
			
		||||
info: >
 | 
			
		||||
  24.1.4.1 get ArrayBuffer.prototype.byteLength
 | 
			
		||||
 | 
			
		||||
  1. Let O be the this value.
 | 
			
		||||
  2. If Type(O) is not Object, throw a TypeError exception.
 | 
			
		||||
  3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError
 | 
			
		||||
  exception.
 | 
			
		||||
  ...
 | 
			
		||||
---*/
 | 
			
		||||
 | 
			
		||||
var getter = Object.getOwnPropertyDescriptor(
 | 
			
		||||
  ArrayBuffer.prototype, "byteLength"
 | 
			
		||||
).get;
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter();
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										23
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/prop-desc.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/prop-desc.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
 | 
			
		||||
// This code is governed by the BSD license found in the LICENSE file.
 | 
			
		||||
/*---
 | 
			
		||||
es6id: 24.1.4.1
 | 
			
		||||
esid: sec-get-arraybuffer.prototype.bytelength
 | 
			
		||||
description: >
 | 
			
		||||
  "byteLength" property of ArrayBuffer.prototype
 | 
			
		||||
info: >
 | 
			
		||||
  ArrayBuffer.prototype.byteLength is an accessor property whose set accessor
 | 
			
		||||
  function is undefined.
 | 
			
		||||
 | 
			
		||||
  Section 17: Every accessor property described in clauses 18 through 26 and in
 | 
			
		||||
  Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true }
 | 
			
		||||
includes: [propertyHelper.js]
 | 
			
		||||
---*/
 | 
			
		||||
 | 
			
		||||
var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength");
 | 
			
		||||
 | 
			
		||||
assert.sameValue(desc.set, undefined);
 | 
			
		||||
assert.sameValue(typeof desc.get, "function");
 | 
			
		||||
 | 
			
		||||
verifyNotEnumerable(ArrayBuffer.prototype, "byteLength");
 | 
			
		||||
verifyConfigurable(ArrayBuffer.prototype, "byteLength");
 | 
			
		||||
							
								
								
									
										19
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/return-bytelength.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/return-bytelength.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
 | 
			
		||||
// This code is governed by the BSD license found in the LICENSE file.
 | 
			
		||||
/*---
 | 
			
		||||
es6id: 24.1.4.1
 | 
			
		||||
esid: sec-get-arraybuffer.prototype.bytelength
 | 
			
		||||
description: Return value from [[ByteLength]] internal slot
 | 
			
		||||
info: >
 | 
			
		||||
  24.1.4.1 get ArrayBuffer.prototype.byteLength
 | 
			
		||||
 | 
			
		||||
  ...
 | 
			
		||||
  5. Let length be the value of O's [[ArrayBufferByteLength]] internal slot.
 | 
			
		||||
  6. Return length.
 | 
			
		||||
---*/
 | 
			
		||||
 | 
			
		||||
var ab1 = new ArrayBuffer(0);
 | 
			
		||||
assert.sameValue(ab1.byteLength, 0);
 | 
			
		||||
 | 
			
		||||
var ab2 = new ArrayBuffer(42);
 | 
			
		||||
assert.sameValue(ab2.byteLength, 42);
 | 
			
		||||
							
								
								
									
										40
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.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.
 | 
			
		||||
/*---
 | 
			
		||||
es6id: 24.1.4.1
 | 
			
		||||
esid: sec-get-arraybuffer.prototype.bytelength
 | 
			
		||||
description: >
 | 
			
		||||
  Throws a TypeError exception when `this` does not have a [[ArrayBufferData]]
 | 
			
		||||
  internal slot
 | 
			
		||||
info: >
 | 
			
		||||
  24.1.4.1 get ArrayBuffer.prototype.byteLength
 | 
			
		||||
 | 
			
		||||
  1. Let O be the this value.
 | 
			
		||||
  2. If Type(O) is not Object, throw a TypeError exception.
 | 
			
		||||
  3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError
 | 
			
		||||
  exception.
 | 
			
		||||
  ...
 | 
			
		||||
features: [DataView, Int8Array]
 | 
			
		||||
---*/
 | 
			
		||||
 | 
			
		||||
var getter = Object.getOwnPropertyDescriptor(
 | 
			
		||||
  ArrayBuffer.prototype, "byteLength"
 | 
			
		||||
).get;
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call({});
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call([]);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var ta = new Int8Array(8);
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(ta);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var dv = new DataView(new ArrayBuffer(8), 0);
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(dv);
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										47
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/this-is-not-object.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								test/built-ins/ArrayBuffer/prototype/byteLength/this-is-not-object.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,47 @@
 | 
			
		||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
 | 
			
		||||
// This code is governed by the BSD license found in the LICENSE file.
 | 
			
		||||
/*---
 | 
			
		||||
es6id: 24.1.4.1
 | 
			
		||||
esid: sec-get-arraybuffer.prototype.bytelength
 | 
			
		||||
description: Throws a TypeError exception when `this` is not Object
 | 
			
		||||
info: >
 | 
			
		||||
  24.1.4.1 get ArrayBuffer.prototype.byteLength
 | 
			
		||||
 | 
			
		||||
  1. Let O be the this value.
 | 
			
		||||
  2. If Type(O) is not Object, throw a TypeError exception.
 | 
			
		||||
  ...
 | 
			
		||||
features: [Symbol]
 | 
			
		||||
---*/
 | 
			
		||||
 | 
			
		||||
var getter = Object.getOwnPropertyDescriptor(
 | 
			
		||||
  ArrayBuffer.prototype, "byteLength"
 | 
			
		||||
).get;
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(undefined);
 | 
			
		||||
}, "this is undefined");
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(null);
 | 
			
		||||
}, "this is null");
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(42);
 | 
			
		||||
}, "this is 42");
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call("1");
 | 
			
		||||
}, "this is a string");
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(true);
 | 
			
		||||
}, "this is true");
 | 
			
		||||
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(false);
 | 
			
		||||
}, "this is false");
 | 
			
		||||
 | 
			
		||||
var s = Symbol("s");
 | 
			
		||||
assert.throws(TypeError, function() {
 | 
			
		||||
  getter.call(s);
 | 
			
		||||
}, "this is a Symbol");
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user