Skip to content
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

The DataView constructor can return DVs backed by detached ArrayBuffers #1025

Merged
merged 1 commit into from
Jul 18, 2018

Conversation

jswalden
Copy link
Contributor

Two ways this can happen. One, "Let viewByteLength be ? ToIndex(byteLength)." step 9a could detach the already-checked buffer. And two, "Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »)." step 10 could do so.

The super-easy fix, that alters the existing order of checks and potential side effects the least, is to doubly check for detachment by duplicating step 5 as a new step 10.5.

A more complicated fix, that would be consistent with how typed arrays handle the similar problem, but that would reorder some of the checking and side effects, would be to move the single IsDetachedArrayBuffer check to the end of the algorithm and adjust the other steps' ordering as needed. Finicky, but doable.

I don't like creating newborn-and-incompletely-initialized objects, then putting them aside for other operations for a bit, as the typed array constructor algorithm does right now. But avoiding doing that in DataView probably would warrant also doing so for typed arrays, which would mean both algorithms would have to change. That might not be desirable.

This PR does the super-easy fix. Is that the fix we want?

This is a followup to both Mozilla bug 1285960 and, it so happens, #852 (comment) as well. (I started from the former and was pointed at the latter.)

…tor is detached one last time before returning the fresh `DataView` in case creating the fresh `DataView` object incidentally detached the buffer.
@littledan littledan added needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 normative change Affects behavior required to correctly evaluate some ECMAScript source text labels Oct 31, 2017
@littledan
Copy link
Member

The change makes sense to me, and fits with the rest of the design where we're trying to prevent this sort of thing from happening.

@anba
Copy link
Contributor

anba commented Jan 11, 2018

@ljharb ljharb added the has consensus This has committee consensus. label Jan 11, 2018
@ljharb
Copy link
Member

ljharb commented Apr 1, 2018

@jswalden would you be able to file a PR to test262 with tests for this change?

@jswalden
Copy link
Contributor Author

jswalden commented Apr 2, 2018

Filed tc39/test262#1504 for the test262 change.

@littledan littledan added has test262 tests and removed needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Apr 4, 2018
@littledan
Copy link
Member

OK, this change seems ready to land then.

@ljharb ljharb requested review from bterlson and bmeck April 4, 2018 07:45
@rwaldron
Copy link
Contributor

rwaldron commented Apr 4, 2018

Filed tc39/test262#1504 for the test262 change.

Confirm: this was merged

@ljharb ljharb assigned ljharb and unassigned bterlson Jul 18, 2018
@ljharb ljharb force-pushed the extra-dv-detached-check branch from a246676 to aeb2026 Compare July 18, 2018 18:55
@ljharb ljharb merged commit aeb2026 into tc39:master Jul 18, 2018
@jswalden jswalden deleted the extra-dv-detached-check branch May 1, 2020 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus This has committee consensus. has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants