You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is weird to see delete operator to return false it strict-mode. It should return true or throw an error there. While this seems to be also a bug in V8 (it should throw an error when the deleter callback returns false in strict-mode) the implementation of EnvDeleter (in src/node.cc) should be fixed as well. It should return true for any environment variable (even the non-existing ones) to match the behaviour of delete operator that is supposed to return true unless non-configurable property is being deleted.
I'm inclined to say it's a V8 bug because node.js follows the contract for delete interceptors to the letter. From the doc comment for GenericNamedPropertyDeleterCallback:
The return value is true if the property could be deleted and false otherwise.
Yes, the callback should return true 'if the property could be deleted'. The question is: what does it mean that it could be deleted? In JavaScript world this means that the property should not be non-configurable (and it may not even exist). Compare it with
'use strict';
var o = {};
console.log(delete o.nonExistentProperty);
that returns true. That's why I believe EnvDeleter should return true for any environment variable as well.
@fhinkel What would you do in that case though? Users can't freeze/seal process.env or put non-configurable properties on it so I think the only thing to do for the deleter is to return true instead of false.
Activity
bnoordhuis commentedon Aug 3, 2016
I'm inclined to say it's a V8 bug because node.js follows the contract for delete interceptors to the letter. From the doc comment for
GenericNamedPropertyDeleterCallback:iamstolis commentedon Aug 3, 2016
Yes, the callback should return true 'if the property could be deleted'. The question is: what does it mean that it could be deleted? In JavaScript world this means that the property should not be non-configurable (and it may not even exist). Compare it with
that returns
true. That's why I believeEnvDeletershould returntruefor any environment variable as well.bnoordhuis commentedon Aug 3, 2016
Can you open a V8 bug? I'd like to hear what they have to say.
iamstolis commentedon Aug 3, 2016
OK, I have filled https://bugs.chromium.org/p/v8/issues/detail?id=5260
fhinkel commentedon Aug 3, 2016
We can use
info.ShouldThrowOnError()in EnvDeleter to determine if we're in strict mode.bnoordhuis commentedon Aug 3, 2016
@fhinkel What would you do in that case though? Users can't freeze/seal
process.envor put non-configurable properties on it so I think the only thing to do for the deleter is to return true instead of false.fhinkel commentedon Aug 4, 2016
I misunderstood, I thought the issue is, that we should throw. If
process.envnever has non-configurable properties I guess we can always returntrue.iamstolis commentedon Aug 5, 2016
Thank you for a quick fix!
src: make EnvDelete behave like the delete operator
src: make EnvDelete behave like the delete operator