mirror of https://github.com/tc39/test262.git
Proxy: set
This commit is contained in:
parent
21a1fbe68e
commit
99ca320b01
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
11. If booleanTrapResult is false, return false.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
assert.sameValue(Reflect.set(p, "attr", "foo"), false);
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
11. If booleanTrapResult is false, return false.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
assert.sameValue(Reflect.set(p, "attr", "foo"), false);
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
11. If booleanTrapResult is false, return false.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
assert.sameValue(Reflect.set(p, "attr", "foo"), false);
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
11. If booleanTrapResult is false, return false.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
assert.sameValue(Reflect.set(p, "attr", "foo"), false);
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
11. If booleanTrapResult is false, return false.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
assert.sameValue(Reflect.set(p, "attr", "foo"), false);
|
|
@ -0,0 +1,33 @@
|
|||
// 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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V,
|
||||
Receiver»)).
|
||||
|
||||
---*/
|
||||
|
||||
var _target, _handler, _prop, _value, _receiver;
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_prop = prop;
|
||||
_value = value;
|
||||
_receiver = receiver;
|
||||
return t[prop] = value;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
p.attr = "foo";
|
||||
|
||||
assert.sameValue(_handler, handler, "handler object as the trap context");
|
||||
assert.sameValue(_target, target, "first argument is the target object");
|
||||
assert.sameValue(_prop, "attr", "second argument is the property name");
|
||||
assert.sameValue(_value, "foo", "third argument is the new value");
|
||||
assert.sameValue(_receiver, p, "forth argument is the proxy object");
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
3. If handler is null, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.proxy.attr = 1;
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.proxy['attr'] = 1;
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
// 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.9
|
||||
description: >
|
||||
Trap returns abrupt.
|
||||
info: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
...
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, Receiver»)).
|
||||
10. ReturnIfAbrupt(booleanTrapResult).
|
||||
...
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
set: function(t, prop, value, receiver) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
p.attr = "bar";
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
p["attr"] = "bar";
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
// 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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
Returns true if trap returns true and target property accessor is
|
||||
configurable and set is undefined.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: true,
|
||||
set: undefined
|
||||
});
|
||||
|
||||
assert(Reflect.set(p, "attr", "bar"));
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
Returns true if trap returns true and target property accessor is not
|
||||
configurable and set is not undefined.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
set: function( value ) {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
|
||||
assert(Reflect.set(p, "attr", 1));
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
Returns true if trap returns true and target property is not configurable
|
||||
but writable.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
writable: true,
|
||||
value: 'foo'
|
||||
});
|
||||
|
||||
assert(Reflect.set(p, "attr", 1));
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
Returns true if trap returns true and target property is configurable
|
||||
but not writable.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: true,
|
||||
writable: false,
|
||||
value: "foo"
|
||||
});
|
||||
|
||||
assert(Reflect.set(p, "attr", "foo"));
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
Throws a TypeError when target property is an accessor not configurable and
|
||||
and set is undefined.
|
||||
info: >
|
||||
14. If targetDesc is not undefined, then
|
||||
b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] is false, then
|
||||
i. If targetDesc.[[Set]] is undefined, throw a TypeError exception.
|
||||
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
set: undefined
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.attr = 'bar';
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p['attr'] = 'bar';
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// 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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
Throws a TypeError when target property is not configurable neither writable
|
||||
and its value is not strictly equal to V.
|
||||
info: >
|
||||
14. If targetDesc is not undefined, then
|
||||
a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is
|
||||
false and targetDesc.[[Writable]] is false, then
|
||||
i. If SameValue(V, targetDesc.[[Value]]) is false, throw a TypeError
|
||||
exception.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
set: function(t, prop, value, receiver) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
writable: false,
|
||||
value: 'foo'
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.attr = 'bar';
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p['attr'] = 'bar';
|
||||
});
|
|
@ -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.9
|
||||
description: >
|
||||
Trap is not callable.
|
||||
info: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
6. Let trap be GetMethod(handler, "set").
|
||||
...
|
||||
|
||||
7.3.9 GetMethod (O, P)
|
||||
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
set: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.attr = 1;
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p["attr"] = 1;
|
||||
});
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
8. If trap is undefined, then return target.[[Set]](P, V, Receiver).
|
||||
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
p.attr = 2;
|
||||
|
||||
assert.sameValue(target.attr, 2);
|
|
@ -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.9
|
||||
description: >
|
||||
[[Set]] ( P, V, Receiver)
|
||||
|
||||
8. If trap is undefined, then return target.[[Set]](P, V, Receiver).
|
||||
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
get: undefined
|
||||
});
|
||||
|
||||
p.attr = 1;
|
||||
|
||||
assert.sameValue(target.attr, 1);
|
Loading…
Reference in New Issue