Skip to content

Commit

Permalink
Only add defined properties to the result of getOwnPropertyDescriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
j-wing committed Jul 29, 2016
1 parent a716b46 commit 761bcd2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/Runtime/Library/JavascriptObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,10 @@ namespace Js
JavascriptConversion::ToPropertyKey(propKey, scriptContext, &propertyRecord);

Var newDescriptor = JavascriptObject::GetOwnPropertyDescriptorHelper(obj, propKey, scriptContext);
resultObj->SetProperty(propertyRecord->GetPropertyId(), newDescriptor, PropertyOperation_None, nullptr);
if (!JavascriptOperators::IsUndefined(newDescriptor))
{
resultObj->SetProperty(propertyRecord->GetPropertyId(), newDescriptor, PropertyOperation_None, nullptr);
}
}

return resultObj;
Expand Down
24 changes: 23 additions & 1 deletion test/Object/getOwnPropertyDescriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,29 @@ var tests = [

verifyObjectDescriptors(desc, allTrueSymbol, allFalseSymbol);
}
}
},
{
name:"For any property, if getOwnPropertyDescriptor(property) is undefined, that property should not be present on the result.",
body: function() {
// Adapted from: https://github.com/ljharb/test262/blob/c2eaa30b08fb1e041b7297e415b6bad8461f50dc/test/built-ins/Object/getOwnPropertyDescriptors/proxy-undefined-descriptor.js
var proxyHandler = {
getOwnPropertyDescriptor: function () {},
};

var key = "a";
var obj = {};
obj[key] = "value";

var proxy = new Proxy(obj, proxyHandler);

var descriptor = Object.getOwnPropertyDescriptor(proxy, key);
assert.areEqual(undefined, descriptor, "Descriptor matches result of [[GetOwnPropertyDescriptor]] trap");

var result = Object.getOwnPropertyDescriptors(proxy);
assert.isFalse(result.hasOwnProperty(key), "key should not be present in result");

}
},
]

testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 comments on commit 761bcd2

Please sign in to comment.