mirror of https://github.com/tc39/test262.git
Add [[Get]] tests
This commit is contained in:
parent
2d60dc0f65
commit
6155fcad3d
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. 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-get-p-receiver
|
||||
description: >
|
||||
If "get" trap is null or undefined, [[Get]] call is properly
|
||||
forwarded to [[ProxyTarget]] (which is also a Proxy object).
|
||||
info: |
|
||||
[[Get]] ( P, Receiver )
|
||||
|
||||
[...]
|
||||
5. Let target be O.[[ProxyTarget]].
|
||||
6. Let trap be ? GetMethod(handler, "get").
|
||||
7. If trap is undefined, then
|
||||
a. Return ? target.[[Get]](P, Receiver).
|
||||
features: [Proxy, Symbol.match]
|
||||
---*/
|
||||
|
||||
var regExp = /(?:)/i;
|
||||
var regExpTarget = new Proxy(regExp, {});
|
||||
var regExpProxy = new Proxy(regExpTarget, {});
|
||||
|
||||
assert.sameValue(Object.create(regExpProxy).lastIndex, 0);
|
||||
assert.sameValue(regExpProxy[Symbol.match], RegExp.prototype[Symbol.match]);
|
||||
|
||||
|
||||
var functionTarget = new Proxy(function(_arg) {}, {});
|
||||
var functionProxy = new Proxy(functionTarget, {});
|
||||
|
||||
assert.sameValue(Object.create(functionProxy).length, 1);
|
||||
assert.sameValue(functionProxy.__proto__, Function.prototype);
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. 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-get-p-receiver
|
||||
description: >
|
||||
If "get" trap is null or undefined, [[Get]] call is properly
|
||||
forwarded to [[ProxyTarget]] (which is also a Proxy object).
|
||||
info: |
|
||||
[[Get]] ( P, Receiver )
|
||||
|
||||
[...]
|
||||
5. Let target be O.[[ProxyTarget]].
|
||||
6. Let trap be ? GetMethod(handler, "get").
|
||||
7. If trap is undefined, then
|
||||
a. Return ? target.[[Get]](P, Receiver).
|
||||
features: [Proxy, Symbol]
|
||||
---*/
|
||||
|
||||
var stringTarget = new Proxy(new String("str"), {});
|
||||
var stringProxy = new Proxy(stringTarget, {
|
||||
get: null,
|
||||
});
|
||||
|
||||
assert.sameValue(stringProxy.length, 3);
|
||||
assert.sameValue(stringProxy[0], "s");
|
||||
assert.sameValue(stringProxy[4], undefined);
|
||||
|
||||
|
||||
var sym = Symbol();
|
||||
var target = new Proxy({}, {
|
||||
get: function(_target, key) {
|
||||
switch (key) {
|
||||
case sym: return 1;
|
||||
case "10": return 2;
|
||||
case "foo": return 3;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var proxy = new Proxy(target, {
|
||||
get: null,
|
||||
});
|
||||
|
||||
assert.sameValue(proxy[sym], 1);
|
||||
assert.sameValue(proxy[10], 2);
|
||||
assert.sameValue(Object.create(proxy).foo, 3);
|
||||
assert.sameValue(proxy.bar, undefined);
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. 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-get-p-receiver
|
||||
description: >
|
||||
If "get" trap is null or undefined, [[Get]] call is properly
|
||||
forwarded to [[ProxyTarget]] (which is also a Proxy object).
|
||||
info: |
|
||||
[[Get]] ( P, Receiver )
|
||||
|
||||
[...]
|
||||
5. Let target be O.[[ProxyTarget]].
|
||||
6. Let trap be ? GetMethod(handler, "get").
|
||||
7. If trap is undefined, then
|
||||
a. Return ? target.[[Get]](P, Receiver).
|
||||
features: [Proxy]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var plainObject = {
|
||||
get 0() {
|
||||
return 1;
|
||||
},
|
||||
foo: 2,
|
||||
set bar(_value) {},
|
||||
};
|
||||
|
||||
var plainObjectTarget = new Proxy(plainObject, {});
|
||||
var plainObjectProxy = new Proxy(plainObjectTarget, {
|
||||
get: undefined,
|
||||
});
|
||||
|
||||
assert.sameValue(Object.create(plainObjectProxy)[0], 1);
|
||||
assert.sameValue(plainObjectProxy.foo, 2);
|
||||
assert.sameValue(plainObjectProxy.bar, undefined);
|
||||
|
||||
|
||||
var array = [1, 2, 3];
|
||||
var arrayTarget = new Proxy(array, {});
|
||||
var arrayProxy = new Proxy(arrayTarget, {
|
||||
get: undefined,
|
||||
});
|
||||
|
||||
assert.compareArray(arrayProxy, array);
|
Loading…
Reference in New Issue