Proxy ownKeys should throw a TypeError if returned keys are not String or Symbol. Fixes gh-1169 (#1173)

This commit is contained in:
Rick Waldron 2017-08-11 12:18:06 -04:00 committed by Leo Balter
parent 33995100cd
commit fe7e906f4a
6 changed files with 204 additions and 0 deletions

View File

@ -0,0 +1,34 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
description: >
The returned list must not have entries whose type does not match
« String, Symbol ».
info: >
[[OwnPropertyKeys]] ( )
...
7. Let trapResultArray be ? Call(trap, handler, « target »).
8. Let trapResult be ?
CreateListFromArrayLike(trapResultArray, « String, Symbol »).
...
CreateListFromArrayLike ( obj [ , elementTypes ] )
...
6. Repeat, while index < len
...
d. If Type(next) is not an element of elementTypes,
throw a TypeError exception.
---*/
var p = new Proxy({}, {
ownKeys() {
return [[]];
}
});
assert.throws(TypeError, function() {
Object.keys(p);
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
description: >
The returned list must not have entries whose type does not match
« String, Symbol ».
info: >
[[OwnPropertyKeys]] ( )
...
7. Let trapResultArray be ? Call(trap, handler, « target »).
8. Let trapResult be ?
CreateListFromArrayLike(trapResultArray, « String, Symbol »).
...
CreateListFromArrayLike ( obj [ , elementTypes ] )
...
6. Repeat, while index < len
...
d. If Type(next) is not an element of elementTypes,
throw a TypeError exception.
---*/
var p = new Proxy({}, {
ownKeys() {
return [true];
}
});
assert.throws(TypeError, function() {
Object.keys(p);
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
description: >
The returned list must not have entries whose type does not match
« String, Symbol ».
info: >
[[OwnPropertyKeys]] ( )
...
7. Let trapResultArray be ? Call(trap, handler, « target »).
8. Let trapResult be ?
CreateListFromArrayLike(trapResultArray, « String, Symbol »).
...
CreateListFromArrayLike ( obj [ , elementTypes ] )
...
6. Repeat, while index < len
...
d. If Type(next) is not an element of elementTypes,
throw a TypeError exception.
---*/
var p = new Proxy({}, {
ownKeys() {
return [null];
}
});
assert.throws(TypeError, function() {
Object.keys(p);
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
description: >
The returned list must not have entries whose type does not match
« String, Symbol ».
info: >
[[OwnPropertyKeys]] ( )
...
7. Let trapResultArray be ? Call(trap, handler, « target »).
8. Let trapResult be ?
CreateListFromArrayLike(trapResultArray, « String, Symbol »).
...
CreateListFromArrayLike ( obj [ , elementTypes ] )
...
6. Repeat, while index < len
...
d. If Type(next) is not an element of elementTypes,
throw a TypeError exception.
---*/
var p = new Proxy({}, {
ownKeys() {
return [1];
}
});
assert.throws(TypeError, function() {
Object.keys(p);
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
description: >
The returned list must not have entries whose type does not match
« String, Symbol ».
info: >
[[OwnPropertyKeys]] ( )
...
7. Let trapResultArray be ? Call(trap, handler, « target »).
8. Let trapResult be ?
CreateListFromArrayLike(trapResultArray, « String, Symbol »).
...
CreateListFromArrayLike ( obj [ , elementTypes ] )
...
6. Repeat, while index < len
...
d. If Type(next) is not an element of elementTypes,
throw a TypeError exception.
---*/
var p = new Proxy({}, {
ownKeys() {
return [{}];
}
});
assert.throws(TypeError, function() {
Object.keys(p);
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
description: >
The returned list must not have entries whose type does not match
« String, Symbol ».
info: >
[[OwnPropertyKeys]] ( )
...
7. Let trapResultArray be ? Call(trap, handler, « target »).
8. Let trapResult be ?
CreateListFromArrayLike(trapResultArray, « String, Symbol »).
...
CreateListFromArrayLike ( obj [ , elementTypes ] )
...
6. Repeat, while index < len
...
d. If Type(next) is not an element of elementTypes,
throw a TypeError exception.
---*/
var p = new Proxy({}, {
ownKeys() {
return [undefined];
}
});
assert.throws(TypeError, function() {
Object.keys(p);
});