Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Throw TypeError if [[DefineOwnProperty]] returns false #6868

Merged
merged 9 commits into from
Jan 25, 2023

Conversation

ShortDevelopment
Copy link
Contributor

Issue

According to es spec Object.defineProperty should throw if internal [[DefineOwnProperty]] returns false-ish.
This happens specifically if the defineProperty proxy trap returns false (See #6505).

Changes

  • Throw TypeError in JavascriptObject::EntryDefineProperty if DefineOwnPropertyHelper returns false-ish
  • Changed content of JSERR_ProxyHandlerReturnedFalse
  • Routed PropertyOperationFlags through the call stack

Open questions

  • Why is test\Bugs\misc_bugs.js tagged with exclude_windows?

@rhuanjl

Related to PR #5412
Fixes #6505

@ShortDevelopment ShortDevelopment changed the title Throw TypeError if defineProperty trap returns false Throw TypeError if [[DefineOwnProperty]] returns false Dec 31, 2022
@rhuanjl
Copy link
Collaborator

rhuanjl commented Jan 22, 2023

test\Bugs\misc_bugs.js being marked to exclude_windows looks like a mistake (I can see the PR where that was set - it was me that did it but... I can't see why I did) unless there's a weird test in there that can't be run on windows, I'd suggest removing the tag and seeing if the tests pass.

@@ -2174,7 +2178,7 @@ BOOL JavascriptObject::DefineOwnPropertyHelper(RecyclableObject* obj, PropertyId
// TODO: implement DefineOwnProperty for other object built-in exotic types.
else
{
returnValue = JavascriptOperators::DefineOwnPropertyDescriptor(obj, propId, descriptor, throwOnError, scriptContext);
returnValue = JavascriptOperators::DefineOwnPropertyDescriptor(obj, propId, descriptor, throwOnError, scriptContext, Js::PropertyOperation_StrictMode);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why should this always be strict mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understood, calls to Object.defineXXX should always throw on error (be strict) opposed to using the assignment operator (property = value).

The error is actually only thrown, if throwOnError == true.

if (throwOnError && flags & PropertyOperation_StrictMode)

Copy link
Collaborator

Choose a reason for hiding this comment

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

indeed, i'm pretty sure all builtins always are effectively ran in strict mode

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 guess it seems strange as (in my understanding) PropertyOperation_StrictModein CC code base always meant “strict mode” has been turned on explicitly; That’s reflected by CC error messages like

RT_ERROR_MSG(JSERR_CantDeleteExpr, 5041, "Calling delete on '%s' is not allowed in strict mode", "Object member not configurable", kjstTypeError, 0) // string 4

The error messages throw by me do not explicitly state “strict mode” (According to the behaviour of node).

Copy link
Collaborator

Choose a reason for hiding this comment

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

The strict mode check in the Proxy Trap seems like it may be wrong - this call should throw if it's strict mode or not.

Trying to think if there's any case where throwOnError would be true and strict mode would be false and it should NOT throw - what could actually get there?

Copy link
Contributor Author

@ShortDevelopment ShortDevelopment Jan 24, 2023

Choose a reason for hiding this comment

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

You could use the assignment operator in non-strict mode; that should not throw.

assert.doesNotThrow(() => {
proxy.a = {};
}, "Set property in NON-strict mode does NOT throw if trap returns falsy");

Copy link
Collaborator

Choose a reason for hiding this comment

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

But would the throwOnError parameter be true at that point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to be like throwOnError is true in both scenarios so we need a seperate way to check for strict mode.

@rhuanjl
Copy link
Collaborator

rhuanjl commented Jan 24, 2023

test\Bugs\misc_bugs.js being marked to exclude_windows looks like a mistake (I can see the PR where that was set - it was me that did it but... I can't see why I did) unless there's a weird test in there that can't be run on windows, I'd suggest removing the tag and seeing if the tests pass.

Unfortunately there clearly is an issue with that test case on windows - I should probably try and fix it but, that's beyond the scope of this PR can you drop your last commit.

Copy link
Collaborator

@rhuanjl rhuanjl left a comment

Choose a reason for hiding this comment

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

Note on the test fails:

  1. exclude_windows for misc_bugs is an unrelated issue I'll look into
  2. macOS test fail is an unrelated issue brought in by an update to the macOS test image being used - I'll investigate that seperately
  3. Windows x86 is an unrelated known intermittent bug

Hence approving in spite of these.

@rhuanjl rhuanjl merged commit cbb9b10 into chakra-core:master Jan 25, 2023
@ShortDevelopment ShortDevelopment deleted the defineProperty branch January 25, 2023 22:31
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A question about defineProperty of Proxy object
3 participants