Skip to content

Commit

Permalink
Update ArrayBuffer, DataView and TypedArray related tests (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jul 10, 2021
1 parent c55a5e4 commit e90e4b3
Show file tree
Hide file tree
Showing 1,042 changed files with 16,540 additions and 2,734 deletions.
9 changes: 6 additions & 3 deletions Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ static Test262Test()
"compareIterator.js",
"nativeFunctionMatcher.js",
"wellKnownIntrinsicObjects.js",
"fnGlobalObject.js"
"fnGlobalObject.js",
"testTypedArray.js",
"detachArrayBuffer.js"
};

Sources = new Dictionary<string, Script>(files.Length);
Expand Down Expand Up @@ -114,7 +116,8 @@ protected void RunTestCode(string fileName, string code, bool strict)
var script = parser.ParseScript(strict);
return engine.Evaluate(script);
}), true, true, true));
}), true, true, true));

o.FastSetProperty("createRealm", new PropertyDescriptor(new ClrFunctionInstance(engine, "createRealm",
(thisObj, args) =>
{
Expand Down Expand Up @@ -318,7 +321,7 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
skip = true;
reason = "TypedArray not implemented";
}

if (name.StartsWith("language/statements/class/subclass/builtin-objects/ArrayBuffer/"))
{
skip = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/*---
esid: sec-get-arraybuffer-@@species
es6id: 24.1.3.3
description: >
get ArrayBuffer [ @@species ].length is 0.
info: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-arraybuffer-@@species
es6id: 24.1.3.3
description: Return value of @@species accessor method
info: |
1. Return the this value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-arraybuffer-@@species
es6id: 24.1.3.3
description: >
ArrayBuffer[Symbol.species] accessor property get name
info: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
info: |
ArrayBuffer has a property at `Symbol.species`
esid: sec-get-arraybuffer-@@species
es6id: 24.1.3.3
author: Sam Mikes
description: ArrayBuffer[Symbol.species] exists per spec
features: [ ArrayBuffer, Symbol.species ]
features: [ArrayBuffer, Symbol.species]
includes: [propertyHelper.js]
---*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/*---
esid: sec-arraybuffer-length
es6id: 24.1.2.1
description: >
Throws a RangeError if requested Data Block is too large.
info: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/*---
esid: sec-arraybuffer-length
es6id: 24.1.2.1
description: >
The new ArrayBuffer instance is created prior to allocating the Data Block.
info: |
Expand Down
1 change: 0 additions & 1 deletion Jint.Tests.Test262/test/built-ins/ArrayBuffer/init-zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-length
es6id: 24.1.1.1
description: All bytes are initialized to zero
info: |
[...]
Expand Down
24 changes: 24 additions & 0 deletions Jint.Tests.Test262/test/built-ins/ArrayBuffer/is-a-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-ecmascript-standard-built-in-objects
description: >
The ArrayBuffer constructor implements [[Construct]]
info: |
IsConstructor ( argument )
The abstract operation IsConstructor takes argument argument (an ECMAScript language value).
It determines if argument is a function object with a [[Construct]] internal method.
It performs the following steps when called:
If Type(argument) is not Object, return false.
If argument has a [[Construct]] internal method, return true.
Return false.
includes: [isConstructor.js]
features: [Reflect.construct, ArrayBuffer]
---*/

assert.sameValue(isConstructor(ArrayBuffer), true, 'isConstructor(ArrayBuffer) must return true');
new ArrayBuffer();

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/*---
esid: sec-arraybuffer.isview
es6id: 24.1.3.1
description: >
ArrayBuffer.isView.length is 1.
info: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/*---
esid: sec-arraybuffer.isview
es6id: 24.1.3.1
description: >
ArrayBuffer.isView.name is "isView".
info: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-ecmascript-standard-built-in-objects
description: >
ArrayBuffer.isView does not implement [[Construct]], is not new-able
info: |
ECMAScript Function Objects
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified in
the description of a particular function.
sec-evaluatenew
...
7. If IsConstructor(constructor) is false, throw a TypeError exception.
...
includes: [isConstructor.js]
features: [Reflect.construct, ArrayBuffer, arrow-function]
---*/

assert.sameValue(isConstructor(ArrayBuffer.isView), false, 'isConstructor(ArrayBuffer.isView) must return false');

assert.throws(TypeError, () => {
new ArrayBuffer.isView();
}, '`new ArrayBuffer.isView()` throws TypeError');

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.

/*---
es6id: 24.1.2.1
esid: sec-arraybuffer-length
description: >
Throws a RangeError if length >= 2 ** 53
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/*---
esid: sec-arraybuffer-length
es6id: 24.1.2.1
description: >
[[Prototype]] defaults to %ArrayBufferPrototype% if NewTarget.prototype is not an object.
info: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: |
Invoked with an options object whose `maxByteLength` property is less than
the length.
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
4. If requestedMaxByteLength is empty, then
a. [...]
5. If byteLength > requestedMaxByteLength, throw a RangeError exception.
features: [resizable-arraybuffer]
---*/

assert.throws(RangeError, function() {
new ArrayBuffer(1, {maxByteLength: 0});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: |
Invoked with an options object whose `maxByteLength` property exceeds the
maximum length value
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
4. Return ? ToIndex(maxByteLength).
features: [resizable-arraybuffer]
---*/

assert.throws(RangeError, function() {
// Math.pow(2, 53) = 9007199254740992
new ArrayBuffer(0, { maxByteLength: 9007199254740992 });
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: Invoked with an options object whose `maxByteLength` property is negative
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
4. Return ? ToIndex(maxByteLength).
features: [resizable-arraybuffer]
---*/

assert.throws(RangeError, function() {
new ArrayBuffer(0, { maxByteLength: -1 });
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: |
Invoked with an options object whose `maxByteLength` property cannot be
coerced to a primitive value
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
4. Return ? ToIndex(maxByteLength).
features: [resizable-arraybuffer]
---*/

var log = [];
var options = {
maxByteLength: {
toString: function() {
log.push('toString');
return {};
},
valueOf: function() {
log.push('valueOf');
return {};
}
}
};

assert.throws(TypeError, function() {
new ArrayBuffer(0, options);
});

assert.sameValue(log.length, 2);
assert.sameValue(log[0], 'valueOf');
assert.sameValue(log[1], 'toString');
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: Invoked with an options object whose `maxByteLength` property throws
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
[...]
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
features: [resizable-arraybuffer]
---*/

var options = {
get maxByteLength() {
throw new Test262Error();
}
};

assert.throws(Test262Error, function() {
new ArrayBuffer(0, options);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: Invoked with an options object whose `maxByteLength` property is undefined
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
4. If requestedMaxByteLength is empty, then
a. Return ? AllocateArrayBuffer(NewTarget, byteLength).
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
2. Let maxByteLength be ? Get(options, "maxByteLength").
3. If maxByteLength is undefined, return empty.
features: [resizable-arraybuffer]
---*/

assert.sameValue(new ArrayBuffer(0, {}).resizable, false);
assert.sameValue(new ArrayBuffer(0, {maxByteLength: undefined}).resizable, false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-constructor
description: Invoked with a non-object value for options
info: |
ArrayBuffer( length [ , options ] )
1. If NewTarget is undefined, throw a TypeError exception.
2. Let byteLength be ? ToIndex(length).
3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
4. If requestedMaxByteLength is empty, then
a. Return ? AllocateArrayBuffer(NewTarget, byteLength).
1.1.5 GetArrayBufferMaxByteLengthOption ( options )
1. If Type(options) is not Object, return empty.
features: [resizable-arraybuffer]
---*/

assert.sameValue(new ArrayBuffer(0, null).resizable, false, 'null');
assert.sameValue(new ArrayBuffer(0, true).resizable, false, 'boolean');
assert.sameValue(new ArrayBuffer(0, Symbol(3)).resizable, false, 'symbol');
assert.sameValue(new ArrayBuffer(0, 1n).resizable, false, 'bigint');
assert.sameValue(new ArrayBuffer(0, 'string').resizable, false, 'string');
assert.sameValue(new ArrayBuffer(0, 9).resizable, false, 'number');
assert.sameValue(new ArrayBuffer(0, undefined).resizable, false, 'undefined');
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer-length
es6id: 24.1.1.1
description: Default [[Prototype]] value derived from realm of the newTarget
info: |
[...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/*---
esid: sec-arraybuffer-length
es6id: 24.1.2.1
description: >
The [[Prototype]] internal slot is computed from NewTarget.
info: |
Expand Down

0 comments on commit e90e4b3

Please sign in to comment.