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

Add mutable references for argv, execArgv and env without ST #26

Merged
merged 5 commits into from
Dec 15, 2020

Conversation

jvliwanag
Copy link
Contributor

Alternative to #25 without the ffi as suggested in #8 (comment).

Fixes #8

return function (dest) {
return function () {
dest.splice(0);
Array.prototype.push.apply(dest, source);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unnecessarily complex and problematic if the array is very large; I’d prefer to just do process.env = xs here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be for args though. Worried that if we're using node libs that has the line this.myArgs = process.args, won't it break if we don't do this?

Copy link
Member

@hdgarrood hdgarrood Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I see. I mean, Array.prototype.push.apply is best avoided in general. If you really need to treat process.argv as a mutable array then I guess your previous formulation with STArray is preferable. But the more I think about it the more I reckon I don’t want to provide this API at all, especially since nobody has asked for it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally though, the mutation on argv is just by pushing and popping rather than replacing the entire thing. I can change the public api's to replace this. Then again, at that point, I'm thinking the ST stuff would be preferable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, I think if you’re treating it as a mutable reference I think the ST stuff is preferable. However, I don’t think it is appropriate for this library to take a stance on how argv should be treated (ie should it be treated as a mutable reference or should you overwrite the whole property), which is why I no longer want to provide any API for writing it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It did feel a bit off. Removing it then.

Note though that we're treating env differently and allowing setting / unsetting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that’s a good point. I think in the case of env it’s an easier call to make, since process.env isn’t quite a real object because it has its own special behaviour, like being able to set a value on process.env.FOO and then read it again as process.env.foo on Windows, and so it probably shouldn’t be overwritten. AFAICT process.argv is just a normal array though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the setters. Let me know if there are other things to change. :)

@hdgarrood
Copy link
Member

Thanks!

@thomashoneyman thomashoneyman merged commit 552e99a into purescript-node:master Dec 15, 2020
@jvliwanag jvliwanag deleted the mutable-refs-ffi branch December 15, 2020 07:12
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 this pull request may close these issues.

Should argv clone the array?
3 participants