-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Array.copyWithin should throw when invoked on TypedArray with missing slots #4790
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -694,7 +694,7 @@ namespace Js | |
return false; | ||
} | ||
|
||
bool JavascriptError::ThrowCantDelete(PropertyOperationFlags flags, ScriptContext* scriptContext, PCWSTR varName) | ||
bool JavascriptError::ThrowCantDeleteIfStrictModeOrNonconfigurable(PropertyOperationFlags flags, ScriptContext* scriptContext, PCWSTR varName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ugly name, but similar to "ThrowCantDeleteIfStrictMode". #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In reply to: 173516752 [](ancestors = 173516752) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, on the topic of this method, I don't like how it forces the caller to do a possibly-expensive conversion to string before figuring out whether we need it. I'd rather take a Var and do In reply to: 173520340 [](ancestors = 173520340,173516752) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In reply to: 173521221 [](ancestors = 173521221,173520340,173516752) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be fair to have an overload of this method which takes a |
||
{ | ||
bool isNonConfigThrow = (flags & PropertyOperation_ThrowOnDeleteIfNotConfig) == PropertyOperation_ThrowOnDeleteIfNotConfig; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -851,6 +851,13 @@ namespace Js | |
return PropertyQueryFlags::Property_NotFound_NoProto; | ||
} | ||
|
||
BOOL TypedArrayBase::DeleteItem(uint32 index, Js::PropertyOperationFlags flags) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
when running in strict mode, the flags will contain PropertyOperation_StrictMode |
||
{ | ||
JavascriptError::ThrowCantDeleteIfStrictModeOrNonconfigurable( | ||
flags, GetScriptContext(), GetScriptContext()->GetIntegerString(index)->GetString()); | ||
return FALSE; | ||
} | ||
|
||
PropertyQueryFlags TypedArrayBase::GetItemQuery(Var originalInstance, uint32 index, Var* value, ScriptContext* requestContext) | ||
{ | ||
*value = DirectGetItem(index); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -912,7 +912,8 @@ namespace Js | |
else if (!(descriptor->Attributes & PropertyConfigurable)) | ||
{ | ||
// Let/const properties do not have attributes and they cannot be deleted | ||
JavascriptError::ThrowCantDelete(propertyOperationFlags, scriptContext, propertyNameString->GetString()); | ||
JavascriptError::ThrowCantDeleteIfStrictModeOrNonconfigurable( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wonder whether this one (and a few other current callers of ThrowCantDeleteIfStrictModeOrNonconfigurable) should actually call ThrowCantDeleteIfStrictMode because I don't think the flags would be set here to PropertyOperation_ThrowOnDeleteIfNotConfig (but I don't know how to confirm this). #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems safer to call the one that respects both flags. If ThrowOnDeleteIfNotConfig is never set, then it would make no difference in behavior. In reply to: 173517742 [](ancestors = 173517742) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, that it's safer. I was wondering about whether we could limit usage of ThrowCantDeleteIfStrictModeOrNonconfigurable (because I don't like this method :)). In reply to: 173523027 [](ancestors = 173523027,173517742) |
||
propertyOperationFlags, scriptContext, propertyNameString->GetString()); | ||
|
||
return false; | ||
} | ||
|
@@ -1007,7 +1008,8 @@ namespace Js | |
(allowLetConstGlobal && (descriptor->Attributes & PropertyLetConstGlobal))) | ||
{ | ||
// Let/const properties do not have attributes and they cannot be deleted | ||
JavascriptError::ThrowCantDelete(propertyOperationFlags, scriptContext, scriptContext->GetPropertyName(propertyId)->GetBuffer()); | ||
JavascriptError::ThrowCantDeleteIfStrictModeOrNonconfigurable( | ||
propertyOperationFlags, scriptContext, scriptContext->GetPropertyName(propertyId)->GetBuffer()); | ||
|
||
return false; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -879,7 +879,8 @@ namespace Js | |
} | ||
if (!(attr & ObjectSlotAttr_Configurable)) | ||
{ | ||
JavascriptError::ThrowCantDelete(PropertyOperation_None, scriptContext, scriptContext->GetPropertyName(propertyId)->GetBuffer()); | ||
JavascriptError::ThrowCantDeleteIfStrictModeOrNonconfigurable( | ||
flags, scriptContext, scriptContext->GetPropertyName(propertyId)->GetBuffer()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fix for #4118 (to throw when deleting non-configurable properties in strict mode) #Resolved |
||
return FALSE; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,7 +441,12 @@ | |
<files>13.delete.js</files> | ||
<baseline>13.delete.baseline</baseline> | ||
<compile-flags>-ES6RegExPrototypeProperties-</compile-flags> | ||
<!-- TODO: Delete depends on flag on scriptContext. Add a new opcode for delete 13.delete_sm.js --> | ||
</default> | ||
</test> | ||
<test> | ||
<default> | ||
<files>13.delete_sm.js</files> | ||
<baseline>13.delete_sm.baseline</baseline> | ||
</default> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This existing test passes "as is" so decided not to rewrite it :) #Resolved |
||
</test> | ||
<test> | ||
|
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.
To try and catch any errors in future, it might be worth to add an assert here along the lines of
Assert(result || !(propertyOperationFlags & PropertyOperation_StrictMode)
; that way there is no overhead in release builds, but we should catch regressions in testing. #ResolvedThere 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.
maybe
result || !(propertyOperationFlags & (PropertyOperation_StrictMode | PropertyOperation_ThrowOnDeleteOrNotConfig))
, since the point of this change is updating the contract elsewhere to respect both flagsIn reply to: 173516816 [](ancestors = 173516816)