Skip to content

Commit 574fc77

Browse files
committed
When a proxy's has() is true for a property, we try to look it up and if it isn't there, set it to the default value. This causes a semantically correct TypeError to be thrown from ToPropertyDescriptor.
1 parent 79fd461 commit 574fc77

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/Parser/rterrors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ RT_ERROR_MSG(JSERR_Property_CannotDelete_NullOrUndefined, 5049, "Unable to delet
164164
RT_ERROR_MSG(JSERR_Property_VarDate, 5050, "Unable to access property '%s': type 'VarDate' does not support user-defined properties", "Object expected", kjstTypeError, JSERR_NeedObject)
165165
RT_ERROR_MSG(JSERR_Property_NeedFunction, 5051, "The value of the property '%s' is not a Function object", "Function expected", kjstTypeError, JSERR_NeedFunction)
166166
RT_ERROR_MSG(JSERR_Property_NeedFunction_NullOrUndefined, 5052, "The value of the property '%s' is null or undefined, not a Function object", "Function expected", kjstTypeError, JSERR_NeedObject)
167-
RT_ERROR_MSG(JSERR_Property_CannotHaveAccessorsAndValue, 5053, "", "Property cannot have both accessors and a value", kjstTypeError, VBSERR_ActionNotSupported)
167+
RT_ERROR_MSG(JSERR_Property_CannotHaveAccessorsAndValue, 5053, "", "Invalid property descriptor: cannot both specify accessors and a 'value' attribute", kjstTypeError, VBSERR_ActionNotSupported)
168168

169169
RT_ERROR_MSG(JSERR_This_NullOrUndefined, 5054, "%s: 'this' is null or undefined", "'this' is null or undefined", kjstTypeError, JSERR_NeedObject) // {Locked="\'this\'"}
170170
RT_ERROR_MSG(JSERR_This_NeedObject, 5055, "%s: 'this' is not an Object", "Object expected", kjstTypeError, JSERR_NeedObject) // {Locked="\'this\'"}

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8686,6 +8686,11 @@ namespace Js
86868686
{
86878687
descriptor->SetEnumerable(JavascriptConversion::ToBoolean(value, scriptContext) ? true : false);
86888688
}
8689+
else
8690+
{
8691+
// The proxy said we have the property, so we try to read the property and get the default value.
8692+
descriptor->SetEnumerable(false);
8693+
}
86898694
}
86908695

86918696
if (JavascriptOperators::HasProperty(propertySpecObj, PropertyIds::configurable) == TRUE)
@@ -8694,6 +8699,11 @@ namespace Js
86948699
{
86958700
descriptor->SetConfigurable(JavascriptConversion::ToBoolean(value, scriptContext) ? true : false);
86968701
}
8702+
else
8703+
{
8704+
// The proxy said we have the property, so we try to read the property and get the default value.
8705+
descriptor->SetConfigurable(false);
8706+
}
86978707
}
86988708

86998709
if (JavascriptOperators::HasProperty(propertySpecObj, PropertyIds::value) == TRUE)
@@ -8702,6 +8712,11 @@ namespace Js
87028712
{
87038713
descriptor->SetValue(value);
87048714
}
8715+
else
8716+
{
8717+
// The proxy said we have the property, so we try to read the property and get the default value.
8718+
descriptor->SetValue(scriptContext->GetLibrary()->GetUndefined());
8719+
}
87058720
}
87068721

87078722
if (JavascriptOperators::HasProperty(propertySpecObj, PropertyIds::writable) == TRUE)
@@ -8710,6 +8725,11 @@ namespace Js
87108725
{
87118726
descriptor->SetWritable(JavascriptConversion::ToBoolean(value, scriptContext) ? true : false);
87128727
}
8728+
else
8729+
{
8730+
// The proxy said we have the property, so we try to read the property and get the default value.
8731+
descriptor->SetWritable(false);
8732+
}
87138733
}
87148734

87158735
if (JavascriptOperators::HasProperty(propertySpecObj, PropertyIds::get) == TRUE)
@@ -8722,6 +8742,11 @@ namespace Js
87228742
}
87238743
descriptor->SetGetter(value);
87248744
}
8745+
else
8746+
{
8747+
// The proxy said we have the property, so we try to read the property and get the default value.
8748+
descriptor->SetGetter(scriptContext->GetLibrary()->GetUndefined());
8749+
}
87258750
}
87268751

87278752
if (JavascriptOperators::HasProperty(propertySpecObj, PropertyIds::set) == TRUE)
@@ -8734,6 +8759,11 @@ namespace Js
87348759
}
87358760
descriptor->SetSetter(value);
87368761
}
8762+
else
8763+
{
8764+
// The proxy said we have the property, so we try to read the property and get the default value.
8765+
descriptor->SetSetter(scriptContext->GetLibrary()->GetUndefined());
8766+
}
87378767
}
87388768

87398769
return TRUE;

0 commit comments

Comments
 (0)