-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add Float16Array to all generic TypedArray tests #3849
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,23 @@ | |
description: | | ||
Collection of functions used to assert the correctness of TypedArray objects. | ||
defines: | ||
- typedArrayConstructors | ||
- floatArrayConstructors | ||
- intArrayConstructors | ||
- typedArrayConstructors | ||
- TypedArray | ||
- testWithTypedArrayConstructors | ||
- nonAtomicsFriendlyTypedArrayConstructors | ||
- testWithAtomicsFriendlyTypedArrayConstructors | ||
- testWithNonAtomicsFriendlyTypedArrayConstructors | ||
- testTypedArrayConversions | ||
---*/ | ||
|
||
/** | ||
* Array containing every typed array constructor. | ||
*/ | ||
var typedArrayConstructors = [ | ||
var floatArrayConstructors = [ | ||
Float64Array, | ||
Float32Array, | ||
Float32Array | ||
]; | ||
|
||
var intArrayConstructors = [ | ||
Int32Array, | ||
Int16Array, | ||
Int8Array, | ||
|
@@ -29,8 +30,17 @@ var typedArrayConstructors = [ | |
Uint8ClampedArray | ||
]; | ||
|
||
var floatArrayConstructors = typedArrayConstructors.slice(0, 2); | ||
var intArrayConstructors = typedArrayConstructors.slice(2, 7); | ||
// Float16Array is a newer feature | ||
// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it | ||
if (typeof Float16Array !== 'undefined') { | ||
floatArrayConstructors.push(Float16Array); | ||
} | ||
|
||
/** | ||
* Array containing every non-bigint typed array constructor. | ||
*/ | ||
|
||
var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR included
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iamstolis Please open an issue - if no-one happens to have time to fix this right when they see it, it'll likely get lost out of their notifications. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I have created #3989 |
||
|
||
/** | ||
* The %TypedArray% intrinsic constructor function. | ||
|
@@ -63,18 +73,15 @@ function testWithTypedArrayConstructors(f, selected) { | |
} | ||
} | ||
|
||
var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); | ||
/** | ||
* Calls the provided function for every non-"Atomics Friendly" typed array constructor. | ||
* | ||
* @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. | ||
* @param {Array} selected - An optional Array with filtered typed arrays | ||
*/ | ||
function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { | ||
testWithTypedArrayConstructors(f, [ | ||
Float64Array, | ||
Float32Array, | ||
Uint8ClampedArray | ||
]); | ||
testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); | ||
} | ||
|
||
/** | ||
|
@@ -120,3 +127,31 @@ function testTypedArrayConversions(byteConversionValues, fn) { | |
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Checks if the given argument is one of the float-based TypedArray constructors. | ||
* | ||
* @param {constructor} ctor - the value to check | ||
* @returns {boolean} | ||
*/ | ||
function isFloatTypedArrayConstructor(arg) { | ||
return floatArrayConstructors.indexOf(arg) !== -1; | ||
} | ||
|
||
/** | ||
* Determines the precision of the given float-based TypedArray constructor. | ||
* | ||
* @param {constructor} ctor - the value to check | ||
* @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. | ||
*/ | ||
function floatTypedArrayConstructorPrecision(FA) { | ||
if (typeof Float16Array !== "undefined" && FA === Float16Array) { | ||
return "half"; | ||
} else if (FA === Float32Array) { | ||
return "single"; | ||
} else if (FA === Float64Array) { | ||
return "double"; | ||
} else { | ||
throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intArrayConstructors
did not containUint8ClampedArray
but it is included now. This seems to be an intended change. Unfortunately, someAtomics
tests (likebuilt-ins/Atomics/add/good-views.js
) still useintArrayConstructors
. In other words, these tests are incorrect now. They should be rewritten to usetestWithAtomicsFriendlyTypedArrayConstructors()
, I guess.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch. Would you mind opening an issue for that, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that was not an intended change, I just didn't realize that the
.slice
above stopped before the end of the list.In fact the
.slice
was previously also omittingUint8Array
, which seems wrong. I've left it in, but opened #3984 to remove Uint8ClampedArray.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the original idea was to include
Uint8ClampedArray
inintArrayConstructors
. The author just haven't realized that the second argument intypedArrayConstructors.slice(2, 7);
is not the length but an (excluded) end index. That's whyUint8Array
andUint8ClampedArray
were missing by accident. I find it correct to includeUint8ClampedArray
in this array (it is a typed array with int elements). Some tests may skipUint8ClampedArray
unnecessarily when it is not included. That's why I though that the change was intentional and that just the problematic Atomics tests (that useintArrayConstructors
without excludingUint8ClampedArray
) should be fixed/updated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamstolis Do you happen to have a list of such tests? It's a bit painful to track them down manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following tests started to fail (when run against
graal-js
engine). So, this is the correct list, hopefully.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamstolis Thanks, see #3984.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I run the tests from the current revision (
62294b592e332bc16da6114e461fd7a8ed90daab
) of #3984 againstgraal-js
and I haven't seen any unexpected failures.