mirror of
				https://github.com/tc39/test262.git
				synced 2025-10-31 03:34:08 +01:00 
			
		
		
		
	Add tests to ensure that:
1. First `byteLength` isn't larger than `maxByteLength`.
2. Then `OrdinaryCreateFromConstructor` is called.
3. And finally `Create{Shared}ByteDataBlock` is called.
		
	
			
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // Copyright (C) 2024 André Bargull. All rights reserved.
 | |
| // This code is governed by the BSD license found in the LICENSE file.
 | |
| 
 | |
| /*---
 | |
| esid: sec-arraybuffer-length
 | |
| description: >
 | |
|   The byteLength argument is validated before OrdinaryCreateFromConstructor.
 | |
| info: |
 | |
|   ArrayBuffer ( length [ , options ] )
 | |
| 
 | |
|   ...
 | |
|   4. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
 | |
| 
 | |
|   AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] )
 | |
| 
 | |
|   ...
 | |
|   3. If allocatingResizableBuffer is true, then
 | |
|     a. If byteLength > maxByteLength, throw a RangeError exception.
 | |
|   ...
 | |
|   4. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBuffer.prototype%", slots).
 | |
|   ...
 | |
| 
 | |
| features: [resizable-arraybuffer, Reflect.construct]
 | |
| ---*/
 | |
| 
 | |
| let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", {
 | |
|   get() {
 | |
|     throw new Test262Error();
 | |
|   }
 | |
| });
 | |
| 
 | |
| assert.throws(RangeError, function() {
 | |
|   let byteLength = 10;
 | |
|   let options = {
 | |
|     maxByteLength: 0,
 | |
|   };
 | |
| 
 | |
|   // Throws a RangeError, because `byteLength` is larger than `options.maxByteLength`.
 | |
|   Reflect.construct(ArrayBuffer, [byteLength, options], newTarget);
 | |
| });
 |