-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
TypeError
if defineProperty
trap returns falseTypeError
if [[DefineOwnProperty]]
returns false
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); |
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.
Why should this always be strict mode?
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.
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) |
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.
indeed, i'm pretty sure all builtins always are effectively ran in strict mode
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.
I guess it seems strange as (in my understanding) PropertyOperation_StrictMode
in CC code base always meant “strict mode” has been turned on explicitly; That’s reflected by CC error messages like
ChakraCore/lib/Parser/rterrors.h
Line 155 in 320a7a8
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
).
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.
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?
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.
You could use the assignment operator in non-strict mode; that should not throw.
ChakraCore/test/Bugs/misc_bugs.js
Lines 202 to 204 in 625ba77
assert.doesNotThrow(() => { | |
proxy.a = {}; | |
}, "Set property in NON-strict mode does NOT throw if trap returns falsy"); |
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.
But would the throwOnError parameter be true at that point?
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.
It seems to be like throwOnError
is true
in both scenarios so we need a seperate way to check for strict mode.
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. |
This reverts commit 320a7a8.
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.
Note on the test fails:
- exclude_windows for misc_bugs is an unrelated issue I'll look into
- macOS test fail is an unrelated issue brought in by an update to the macOS test image being used - I'll investigate that seperately
- Windows x86 is an unrelated known intermittent bug
Hence approving in spite of these.
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
TypeError
inJavascriptObject::EntryDefineProperty
ifDefineOwnPropertyHelper
returns false-ishJSERR_ProxyHandlerReturnedFalse
PropertyOperationFlags
through the call stackOpen questions
test\Bugs\misc_bugs.js
tagged withexclude_windows
?@rhuanjl
Related to PR #5412
Fixes #6505