Skip to content

Commit 9366a64

Browse files
committed
[MERGE chakra-core#885] Fix chakra-core#884: Proxy: ToPropertyDescriptor assert; when assert not hit, should throw TypeError.
Merge pull request chakra-core#885 from dilijev:proxyassert Fixes chakra-core#884 (see issue for details).
2 parents 5ced209 + f4b45c5 commit 9366a64

6 files changed

Lines changed: 52 additions & 8 deletions

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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8688,7 +8688,8 @@ namespace Js
86888688
}
86898689
else
86908690
{
8691-
AssertMsg(FALSE, "Proxy : HasProperty and GetProperty's result don't match for 'enumerable'.");
8691+
// The proxy said we have the property, so we try to read the property and get the default value.
8692+
descriptor->SetEnumerable(false);
86928693
}
86938694
}
86948695

@@ -8700,7 +8701,8 @@ namespace Js
87008701
}
87018702
else
87028703
{
8703-
AssertMsg(FALSE, "Proxy : HasProperty and GetProperty's result don't match for 'configurable'.");
8704+
// The proxy said we have the property, so we try to read the property and get the default value.
8705+
descriptor->SetConfigurable(false);
87048706
}
87058707
}
87068708

@@ -8712,7 +8714,8 @@ namespace Js
87128714
}
87138715
else
87148716
{
8715-
AssertMsg(FALSE, "Proxy : HasProperty and GetProperty's result don't match for 'value'.");
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());
87168719
}
87178720
}
87188721

@@ -8724,7 +8727,8 @@ namespace Js
87248727
}
87258728
else
87268729
{
8727-
AssertMsg(FALSE, "Proxy : HasProperty and GetProperty's result don't match for 'writable'.");
8730+
// The proxy said we have the property, so we try to read the property and get the default value.
8731+
descriptor->SetWritable(false);
87288732
}
87298733
}
87308734

@@ -8740,7 +8744,8 @@ namespace Js
87408744
}
87418745
else
87428746
{
8743-
AssertMsg(FALSE, "Proxy : HasProperty and GetProperty's result don't match for 'get'.");
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());
87448749
}
87458750
}
87468751

@@ -8756,9 +8761,11 @@ namespace Js
87568761
}
87578762
else
87588763
{
8759-
AssertMsg(FALSE, "Proxy : HasProperty and GetProperty's result don't match for 'set'.");
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());
87608766
}
87618767
}
8768+
87628769
return TRUE;
87638770
}
87648771

test/es6/proxy-issue884.baseline

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
has enumerable
2+
has configurable
3+
has value
4+
has writable
5+
has get
6+
has set
7+
PASS

test/es6/proxy-issue884.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
var proxyHandler = {
7+
has(t, p) { WScript.Echo("has " + p); return true; }
8+
};
9+
var p = new Proxy({}, proxyHandler);
10+
var obj = {};
11+
12+
try {
13+
Object.defineProperty(obj, "x", p);
14+
} catch (e) {
15+
if (e instanceof TypeError) {
16+
if (e.message !== "Invalid property descriptor: cannot both specify accessors and a 'value' attribute") {
17+
print('FAIL');
18+
} else {
19+
print('PASS');
20+
}
21+
} else {
22+
print('FAIL');
23+
}
24+
}

test/es6/proxytest9.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function test2() {
4545
print('Expected to throw TypeError');
4646
} catch (e) {
4747
if (e instanceof TypeError) {
48-
if (e.message !== 'Property cannot have both accessors and a value') {
48+
if (e.message !== "Invalid property descriptor: cannot both specify accessors and a 'value' attribute") {
4949
print('FAIL');
5050
}
5151
} else {

test/es6/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,12 @@
688688
<compile-flags>-args summary -endargs</compile-flags>
689689
</default>
690690
</test>
691+
<test>
692+
<default>
693+
<files>proxy-issue884.js</files>
694+
<baseline>proxy-issue884.baseline</baseline>
695+
</default>
696+
</test>
691697
<test>
692698
<default>
693699
<files>object-is.js</files>

0 commit comments

Comments
 (0)