Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAvoid repeated ToNumber calls in %TypedArray%.prototype.fill() #855
Comments
littledan
referenced this issue
Mar 22, 2017
Merged
Normative: Ensure that TypedArray.prototype.fill does one coercion #856
added a commit
to littledan/test262
that referenced
this issue
Mar 22, 2017
littledan
referenced this issue
Mar 22, 2017
Merged
Test for TypedArray.prototype.fill semantics change #927
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
littledan
Mar 22, 2017
Member
I wrote up a spec patch with new semantics with only a single coercion, and tests to go along with it. I see a couple advantages to a single coercion:
- It's cleaner semantics. Generally, JavaScript standard library functions tend to coerce things in the beginning of functions once, rather than repeatedly.
- It simplifies implementing an optimized version of TypedArray.prototype.fill. Ideally, we should be able to use
memsethere under the hood. However, the interspersed coercions withSetmean that implementations would have to include both amemsetpath which is invoked when value is already a Number, and a "slow path" which will take things more literally to handle, e.g., the underlying ArrayBuffer being detached halfway through in the coercion.
|
I wrote up a spec patch with new semantics with only a single coercion, and tests to go along with it. I see a couple advantages to a single coercion:
|
added a commit
to tc39/test262
that referenced
this issue
Mar 27, 2017
bterlson
closed this
in
#856
Mar 31, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
camillobruni commentedMar 22, 2017
Example:
%TypedArray%.prototype.fill(proxy)causes a ToNumber with side-effects on every fill step.From the usual behavior of Array.prototype functions, the argument conversion should probably happen only once and in this case would be different for TypedArrays. Obviously this only an issue with non-number fill values.
Array.prototype.fill and %TypedArray%.prototype.fill share the same spec implementation, modulo getting the array length. The TypedArray version should probably introduce an additional step performing a
ToNumber(value)before step 3 in 22.1.3.6 to avoid the frequent conversion inside the fill step 7.b.Steps:
The following steps lead to the
ToNumberin question when calling%TypedArray%.prototype.fill.7.b Perform ? Set(O, Pk, value, true).4 Let success be ? O.[[Set]](P, V, O).2.b.i Return ? IntegerIndexedElementSet(O, numericIndex, V).3. Let numValue be ? ToNumber(value).