mirror of https://github.com/tc39/test262.git
Proxy: get
This commit is contained in:
parent
54e82687d7
commit
21a1fbe68e
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
if trap result is not undefined, then proxy must report the same value for a
|
||||
non-configurable accessor property with an undefined get.
|
||||
info: >
|
||||
13. If targetDesc is not undefined, then
|
||||
b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]]
|
||||
is false and targetDesc.[[Get]] is undefined, then
|
||||
i. If trapResult is not undefined, throw a TypeError exception.
|
||||
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
get: undefined
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.attr;
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p['attr'];
|
||||
});
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
9. Let trapResult be Call(trap, handler, «target, P, Receiver»).
|
||||
info: >
|
||||
6.1.7.2 Object Internal Methods and Internal Slots
|
||||
|
||||
(...) Receiver is used as the this value when evaluating the code
|
||||
---*/
|
||||
|
||||
var _target, _handler, _prop, _receiver;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var handler = {
|
||||
get: function(t, prop, receiver) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_prop = prop;
|
||||
_receiver = receiver;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
p.attr;
|
||||
|
||||
assert.sameValue(_handler, handler);
|
||||
assert.sameValue(_target, target);
|
||||
assert.sameValue(_prop, "attr");
|
||||
assert.sameValue(_receiver, p, "receiver is the Proxy object");
|
||||
|
||||
_prop = null;
|
||||
p["attr"];
|
||||
assert.sameValue(
|
||||
_prop, "attr",
|
||||
"trap is triggered both by p.attr and p['attr']"
|
||||
);
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
Throws if proxy return has not the same value for a non-writable,
|
||||
non-configurable property
|
||||
info: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
13. If targetDesc is not undefined, then
|
||||
a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is
|
||||
false and targetDesc.[[Writable]] is false, then
|
||||
i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a
|
||||
TypeError exception.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
writable: false,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.attr;
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p['attr'];
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
2. If handler is null, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.proxy.attr;
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.proxy['attr'];
|
||||
});
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
Trap returns abrupt.
|
||||
info: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
9. Let trapResult be Call(trap, handler, «target, P, Receiver»).
|
||||
10. ReturnIfAbrupt(trapResult).
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
p.attr;
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
p["attr"];
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
14. Return trapResult.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
get: function() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(p.attr, 2);
|
||||
assert.sameValue(p['attr'], 2);
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
14. Return trapResult.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
writable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.sameValue(p.attr, 2);
|
||||
assert.sameValue(p['attr'], 2);
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
14. Return trapResult.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: true,
|
||||
get: undefined
|
||||
});
|
||||
|
||||
assert.sameValue(p.attr, 2);
|
||||
assert.sameValue(p['attr'], 2);
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
14. Return trapResult.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: true,
|
||||
writable: false,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.sameValue(p.attr, 2);
|
||||
assert.sameValue(p['attr'], 2);
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
Proxy must report the same value for a non-writable, non-configurable
|
||||
property.
|
||||
info: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
13. If targetDesc is not undefined, then
|
||||
a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is
|
||||
false and targetDesc.[[Writable]] is false, then
|
||||
i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a
|
||||
TypeError exception.
|
||||
...
|
||||
14. Return trapResult.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
writable: false,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.sameValue(p.attr, 1);
|
||||
assert.sameValue(p['attr'], 1);
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
14. Return trapResult.
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
get: function() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(p.attr, 2);
|
||||
assert.sameValue(p.foo, 2);
|
||||
|
||||
assert.sameValue(p['attr'], 2);
|
||||
assert.sameValue(p['foo'], 2);
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
Trap is not callable.
|
||||
info: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
6. Let trap be GetMethod(handler, "get").
|
||||
...
|
||||
|
||||
7.3.9 GetMethod (O, P)
|
||||
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
get: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.attr;
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p["attr"];
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
8. If trap is undefined, then return target.[[Get]](P, Receiver).
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
assert.sameValue(p.attr, 1, 'return target.attr');
|
||||
assert.sameValue(p.foo, undefined, 'return target.foo');
|
||||
assert.sameValue(p['attr'], 1, 'return target.attr');
|
||||
assert.sameValue(p['foo'], undefined, 'return target.foo');
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.8
|
||||
description: >
|
||||
[[Get]] (P, Receiver)
|
||||
|
||||
8. If trap is undefined, then return target.[[Get]](P, Receiver).
|
||||
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
get: undefined
|
||||
});
|
||||
|
||||
assert.sameValue(p.attr, 1, 'return target.attr');
|
||||
assert.sameValue(p.foo, undefined, 'return target.foo');
|
Loading…
Reference in New Issue