-
Notifications
You must be signed in to change notification settings - Fork 444
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
Don't stomp on the object in verifyConfigurable
test.
#452
Conversation
Just as we do for `isWritable`, revert the change after we've verified the property.
var result = !Object.prototype.hasOwnProperty.call(obj, name); | ||
if (result) { | ||
// Put things back the way we found them. | ||
Object.defineProperty(obj, name, desc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call would fail when the property doesn't originally exist given that desc
would be undefined
. Instead of checking the result of the hasOwnProperty
call in the if
condition, we should check the descriptor.
Given that this test uses one aspect of the property descriptor API to test property descriptors themselves, I think there's a nontrivial opportunity for false positives in buggy implementations. It would be good to see unit tests for the new behavior added to the project's |
@@ -7,7 +8,12 @@ function isConfigurable(obj, name) { | |||
$ERROR("Expected TypeError, got " + e); | |||
} | |||
} | |||
return !Object.prototype.hasOwnProperty.call(obj, name); | |||
var result = !Object.prototype.hasOwnProperty.call(obj, name); | |||
if (result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this just be if (result && desc)
?
@cscott @goyakin @bterlson @jugglinmike what's the conclusion this PR should take? |
When I was running the tests for this branch I've found this example from var sample = new TA([42, 43]);
sample.foo = true;
sample.bar = true;
Object.preventExtensions(sample);
assert.sameValue(
Reflect.defineProperty(sample, "foo", {value:42}),
true,
"data descriptor"
);
assert.sameValue(sample.foo, 42);
verifyEnumerable(sample, "foo");
verifyWritable(sample, "foo");
verifyConfigurable(sample, "foo");
...
With these changes applied, verifyConfigurable will return the abrupt completion from trying to define a new descriptor. This comes from ValidateAndApplyPropertyDescriptor. Where it checks if the object is extensible only if I'm adding a new property. With this case, I really prefer not creating more side effects than we are already doing. Tests should be atomic and a property should be consumed once for each case. Trying to recover the previous status will add an extra functionality that would open a path for anti-patterns. What I believe we should add instead is a helper for to check a property at once, so we don't need to worry on the order for calling Example: verifyProperty(sample, 'foo', { value: 42, enumerable: true, writable: false, configurable: false }) This is a case for another PR, anyway. I'm closing this PR due to the long time with no further answer and believe I don't think it's currently a fit. Even though, I appreciate the contribution and efforts. |
Just as we do for
isWritable
, revert the change after we've verified the property.This helps us run tests in environments without full isolation between tests, as well as protecting test authors from shooting themselves in the foot inadvertently.