Skip to content

Should transferToImmutable support a newByteLength argument? #15

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

Closed
Tracked by #1
erights opened this issue Dec 1, 2024 · 1 comment · Fixed by #17
Closed
Tracked by #1

Should transferToImmutable support a newByteLength argument? #15

erights opened this issue Dec 1, 2024 · 1 comment · Fixed by #17
Assignees

Comments

@erights
Copy link
Collaborator

erights commented Dec 1, 2024

In favor: Least surprise. Minimize consequences of reasonable surprise. If we add this parameter, those who expect it not to be there and don't provide such an argument get what they expect anyway. OTOH, if we omit it, those who expect it to be there and provide such an argument do not get either a static or dynamic diagnostic. Rather, the code proceeds to silently do something other than they expect.

Against: It might be useful for truncation, but probably rarely for expansion because the output would have an all-zeroes suffix that could not be changed.

Both sides can also make arguments from orthogonality:

  • In favor is more orthogonal because the parameter exists and means the same thing across all transfer* operations.
  • Against is more orthogonal because making a buffer immutable is distinct from changing its size, and can be painlessly composed with a transfer operation which does change the size, while still being zero-copy.
@erights erights self-assigned this Dec 1, 2024
@erights
Copy link
Collaborator Author

erights commented Dec 1, 2024

I find the "Minimize consequences of reasonable surprise" argument the most compelling, so I'm inclined towards including this parameter. This would involve a change to the spec and shim as currently (1 dec 2024) written. The Moddable XS implementation already implements this parameter, and so would not need to change.

If tc39 agrees, I'll close with this decision.

@erights erights changed the title Should transferToImmutable support a _newByteLength_ argument? Should transferToImmutable support a _newByteLength_ argument? Dec 1, 2024
@erights erights changed the title Should transferToImmutable support a _newByteLength_ argument? Should transferToImmutable support a newByteLength argument? Dec 1, 2024
gibson042 added a commit to gibson042/tc39-proposal-immutable-arraybuffer that referenced this issue Dec 3, 2024
gibson042 added a commit to gibson042/tc39-proposal-immutable-arraybuffer that referenced this issue Dec 3, 2024
erights added a commit to endojs/endo that referenced this issue Jan 13, 2025
Closes: tc39/proposal-immutable-arraybuffer#26
Refs: https://github.com/tc39/proposal-immutable-arraybuffer
tc39/proposal-immutable-arraybuffer#15
tc39/proposal-immutable-arraybuffer#9
tc39/proposal-immutable-arraybuffer#16

## Description

Since the last work on this immutable-arraybuffer shim, at the tc39
plenary we decided that
- `transferToImmutable` should take an optional `newLength` parameter,
to stay parallel to the other `transfer*` methods.
- The `sliceToImmutable` method should be added.

The spec at https://github.com/tc39/proposal-immutable-arraybuffer and
the Moddable XS implementation both already reflect these changes. This
PR brings this shim up to date with those changes, closing
tc39/proposal-immutable-arraybuffer#26

### Security Considerations

none

### Scaling Considerations

none

### Documentation Considerations

The proposal's draft spec has already been updated.

### Testing Considerations

New tests lightly test the new functionality. The code and tests may
differ from the current draft spec on order of operations and errors
thrown. But since these issues are purposely still open
tc39/proposal-immutable-arraybuffer#16 , this
divergence is not yet a big deal.

### Compatibility Considerations

No more than the baseline shim already on master.

### Upgrade Considerations

No production code yet depends on this shim. So, none.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant