mirror of https://github.com/tc39/test262.git
commit
e4aac334b8
|
@ -0,0 +1,35 @@
|
|||
// 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.13
|
||||
description: >
|
||||
trap is called with handler object as its context, and parameters are:
|
||||
target, the call context and and an array list with the called arguments
|
||||
info: >
|
||||
[[Call]] (thisArgument, argumentsList)
|
||||
|
||||
9. Return Call(trap, handler, «target, thisArgument, argArray»).
|
||||
---*/
|
||||
|
||||
var _target, _args, _handler, _context;
|
||||
var target = function(a, b) { return a + b; };
|
||||
var handler = {
|
||||
apply: function(t, c, args) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_context = c;
|
||||
_args = args;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
var context = {};
|
||||
|
||||
p.call(context, 1, 2);
|
||||
|
||||
assert.sameValue(_handler, handler, "trap context is the handler object");
|
||||
assert.sameValue(_target, target, "first parameter is the target object");
|
||||
assert.sameValue(_context, context, "second parameter is the call context");
|
||||
assert.sameValue(_args.length, 2, "arguments list contains all call arguments");
|
||||
assert.sameValue(_args[0], 1, "arguments list has first call argument");
|
||||
assert.sameValue(_args[1], 2, "arguments list has second call argument");
|
|
@ -0,0 +1,22 @@
|
|||
// 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.13
|
||||
description: >
|
||||
Return the result from the trap method.
|
||||
info: >
|
||||
[[Call]] (thisArgument, argumentsList)
|
||||
|
||||
9. Return Call(trap, handler, «target, thisArgument, argArray»).
|
||||
---*/
|
||||
|
||||
var target = function(a, b) { return a + b; };
|
||||
var result = {};
|
||||
var handler = {
|
||||
apply: function(t, c, args) {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
assert.sameValue(p.call(), result);
|
|
@ -0,0 +1,18 @@
|
|||
// 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.13
|
||||
description: >
|
||||
[[Call]] (thisArgument, argumentsList)
|
||||
|
||||
2. If handler is null, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
|
||||
var p = Proxy.revocable(function() {}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.proxy();
|
||||
});
|
|
@ -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.13
|
||||
description: >
|
||||
Return is an abrupt completion
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var target = function(a, b) { return a + b; };
|
||||
var p = new Proxy(target, {
|
||||
apply: function(t, c, args) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
p.call();
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
// 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.13
|
||||
description: >
|
||||
Throws if trap is not callable.
|
||||
---*/
|
||||
|
||||
var p = new Proxy(function() {}, {
|
||||
apply: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p();
|
||||
});
|
|
@ -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.13
|
||||
description: >
|
||||
If trap is undefined, propagate the call to the target object.
|
||||
info: >
|
||||
[[Call]] (thisArgument, argumentsList)
|
||||
|
||||
7. If trap is undefined, then Return Call(target, thisArgument,
|
||||
argumentsList).
|
||||
---*/
|
||||
|
||||
var target = function(a, b) {
|
||||
return a + b;
|
||||
};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
assert.sameValue(p(1, 2), 3);
|
|
@ -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.13
|
||||
description: >
|
||||
If trap is undefined, propagate the call to the target object.
|
||||
info: >
|
||||
[[Call]] (thisArgument, argumentsList)
|
||||
|
||||
7. If trap is undefined, then Return Call(target, thisArgument,
|
||||
argumentsList).
|
||||
---*/
|
||||
|
||||
var target = function(a, b) {
|
||||
return a + b;
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
apply: undefined
|
||||
});
|
||||
|
||||
assert.sameValue(p(1, 2), 3);
|
|
@ -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.14
|
||||
description: >
|
||||
trap is called with handler object as its context, and parameters are:
|
||||
target, an array list with the called arguments and the new target, and the
|
||||
constructor new.target.
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
9. Let newObj be Call(trap, handler, «target, argArray, newTarget »).
|
||||
---*/
|
||||
|
||||
var _target, _handler, _args, _P;
|
||||
function Target() {}
|
||||
|
||||
var handler = {
|
||||
construct: function(t, args, newTarget) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_args = args;
|
||||
_P = newTarget;
|
||||
|
||||
return new t(args[0], args[1]);
|
||||
}
|
||||
};
|
||||
var P = new Proxy(Target, handler);
|
||||
|
||||
new P(1, 2);
|
||||
|
||||
assert.sameValue(_handler, handler, "trap context is the handler object");
|
||||
assert.sameValue(_target, Target, "first parameter is the target object");
|
||||
assert.sameValue(_args.length, 2, "arguments list contains all call arguments");
|
||||
assert.sameValue(_args[0], 1, "arguments list has first call argument");
|
||||
assert.sameValue(_args[1], 2, "arguments list has second call argument");
|
||||
assert.sameValue(_P, P, "constructor is sent as the third parameter");
|
|
@ -0,0 +1,23 @@
|
|||
// 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.14
|
||||
description: >
|
||||
Return the result from the trap method.
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
12. Return newObj
|
||||
---*/
|
||||
|
||||
function Target(a, b) {
|
||||
this.sum = a + b;
|
||||
};
|
||||
var handler = {
|
||||
construct: function(t, c, args) {
|
||||
return { sum: 42 };
|
||||
}
|
||||
};
|
||||
var P = new Proxy(Target, handler);
|
||||
|
||||
assert.sameValue((new P(1, 2)).sum, 42);
|
|
@ -0,0 +1,18 @@
|
|||
// 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.14
|
||||
description: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
2. If handler is null, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
|
||||
var p = Proxy.revocable(function() {}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new p.proxy();
|
||||
});
|
|
@ -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.14
|
||||
description: >
|
||||
Return abrupt from constructor call.
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
9. Let newObj be Call(trap, handler, «target, argArray, newTarget »).
|
||||
10. ReturnIfAbrupt(newObj).
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
function Target() {}
|
||||
var P = new Proxy(Target, {
|
||||
construct: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new P();
|
||||
});
|
|
@ -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.14
|
||||
description: >
|
||||
Throws a TypeError if trap result is not an Object: Boolean
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
11. If Type(newObj) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
function Target() {
|
||||
this.attr = "done";
|
||||
};
|
||||
var P = new Proxy(Target, {
|
||||
construct: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new P();
|
||||
});
|
|
@ -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.14
|
||||
description: >
|
||||
Throws a TypeError if trap result is not an Object: Number
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
11. If Type(newObj) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
function Target() {
|
||||
this.attr = "done";
|
||||
};
|
||||
var P = new Proxy(Target, {
|
||||
construct: function() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new P();
|
||||
});
|
|
@ -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.14
|
||||
description: >
|
||||
Throws a TypeError if trap result is not an Object: String
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
11. If Type(newObj) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
function Target() {
|
||||
this.attr = "done";
|
||||
};
|
||||
var P = new Proxy(Target, {
|
||||
construct: function() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new P();
|
||||
});
|
|
@ -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.14
|
||||
description: >
|
||||
Throws a TypeError if trap result is not an Object: Symbol
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
11. If Type(newObj) is not Object, throw a TypeError exception.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
function Target() {
|
||||
this.attr = "done";
|
||||
};
|
||||
var P = new Proxy(Target, {
|
||||
construct: function() {
|
||||
return Symbol();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new P();
|
||||
});
|
|
@ -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.14
|
||||
description: >
|
||||
Throws a TypeError if trap result is not an Object: undefined
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
11. If Type(newObj) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
function Target() {
|
||||
this.attr = "done";
|
||||
};
|
||||
var P = new Proxy(Target, {
|
||||
construct: function() {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new P();
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
// 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.14
|
||||
description: >
|
||||
Throws if trap is not callable.
|
||||
---*/
|
||||
|
||||
function Target() {}
|
||||
var p = new Proxy(Target, {
|
||||
construct: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new p();
|
||||
});
|
|
@ -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.14
|
||||
description: >
|
||||
If trap is undefined, propagate the construct to the target object.
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
7. If trap is undefined, then
|
||||
b. Return Construct(target, argumentsList, newTarget).
|
||||
---*/
|
||||
|
||||
function Target(arg) {
|
||||
this.attr = arg;
|
||||
}
|
||||
var P = new Proxy(Target, {});
|
||||
|
||||
assert.sameValue((new P("foo")).attr, "foo");
|
|
@ -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.14
|
||||
description: >
|
||||
If trap is undefined, propagate the construct to the target object.
|
||||
info: >
|
||||
[[Construct]] ( argumentsList, newTarget)
|
||||
|
||||
7. If trap is undefined, then
|
||||
b. Return Construct(target, argumentsList, newTarget).
|
||||
---*/
|
||||
|
||||
function Target(arg) {
|
||||
this.attr = arg;
|
||||
}
|
||||
var P = new Proxy(Target, {
|
||||
construct: undefined
|
||||
});
|
||||
|
||||
assert.sameValue((new P("foo")).attr, "foo");
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 26.2.1
|
||||
description: >
|
||||
The Proxy constructor is the %Proxy% intrinsic object and the
|
||||
initial value of the Proxy property of the global object.
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Proxy, "function", "`typeof Proxy` is `'function'`");
|
|
@ -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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
4. If handler is a Proxy exotic object and the value of the
|
||||
[[ProxyHandler]] internal slot of handler is null, throw a
|
||||
TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var revocable = Proxy.revocable({}, {});
|
||||
|
||||
revocable.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy({}, revocable.proxy);
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
3. If Type(handler) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy({}, false);
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
3. If Type(handler) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy({}, null);
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
3. If Type(handler) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy({}, 0);
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
3. If Type(handler) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy({}, "");
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
3. If Type(handler) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy({}, Symbol());
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
3. If Type(handler) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy({}, undefined);
|
||||
});
|
|
@ -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.15
|
||||
description: >
|
||||
A Proxy exotic object is only callable if the given target is callable.
|
||||
info: >
|
||||
Proxy ( target, handler )
|
||||
|
||||
7. If IsCallable(target) is true, then
|
||||
a. Set the [[Call]] internal method of P as specified in 9.5.13.
|
||||
...
|
||||
|
||||
|
||||
12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments,
|
||||
tailPosition )
|
||||
|
||||
4. If IsCallable(func) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
p.call();
|
||||
});
|
|
@ -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.15
|
||||
description: >
|
||||
A Proxy exotic object only accepts a constructor call if target is
|
||||
constructor.
|
||||
info: >
|
||||
Proxy ( target, handler )
|
||||
|
||||
7. If IsCallable(target) is true, then
|
||||
b. If target has a [[Construct]] internal method, then
|
||||
i. Set the [[Construct]] internal method of P as specified in
|
||||
9.5.14.
|
||||
...
|
||||
|
||||
12.3.3.1.1 Runtime Semantics: EvaluateNew(constructProduction, arguments)
|
||||
|
||||
8. If IsConstructor (constructor) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = new Proxy(eval, {});
|
||||
|
||||
p(); // the Proxy object is callable
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new p();
|
||||
});
|
|
@ -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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
2. If target is a Proxy exotic object and the value of the
|
||||
[[ProxyHandler]] internal slot of target is null, throw a
|
||||
TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var revocable = Proxy.revocable({}, {});
|
||||
|
||||
revocable.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy(revocable.proxy, {});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy(false, {});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy(null, {});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy(0, {});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy("", {});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy(Symbol(), {});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// 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.15
|
||||
description: >
|
||||
Proxy ( target, handler )
|
||||
...
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new Proxy(undefined, {});
|
||||
});
|
|
@ -0,0 +1,52 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Trap is called with handler as context and parameters are target, P, and the
|
||||
descriptor object.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
9. Let descObj be FromPropertyDescriptor(Desc).
|
||||
10. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P,
|
||||
descObj»)).
|
||||
...
|
||||
---*/
|
||||
|
||||
var _handler, _target, _prop, _desc;
|
||||
var target = {};
|
||||
var descriptor = {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: 1
|
||||
};
|
||||
var handler = {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_prop = prop;
|
||||
_desc = desc;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(p, "attr", descriptor);
|
||||
|
||||
assert.sameValue(_handler, handler);
|
||||
assert.sameValue(_target, target);
|
||||
assert.sameValue(_prop, "attr");
|
||||
|
||||
assert.sameValue(
|
||||
Object.keys(_desc).length, 4,
|
||||
"descriptor arg has the same amount of keys as given descriptor"
|
||||
);
|
||||
|
||||
assert(_desc.configurable);
|
||||
assert(_desc.writable);
|
||||
assert(_desc.enumerable);
|
||||
assert.sameValue(_desc.value, 1);
|
|
@ -0,0 +1,18 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Throws a TypeError exception if handler is null.
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(p.proxy, "foo", {
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
// 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.6
|
||||
description: >
|
||||
If a property has a corresponding target object property then applying the
|
||||
Property Descriptor of the property to the target object using
|
||||
[[DefineOwnProperty]] will not throw an exception.
|
||||
features: [Reflect]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
return Object.defineProperty(t, prop, desc);
|
||||
}
|
||||
});
|
||||
|
||||
var result = Reflect.defineProperty(p, "attr", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.sameValue(result, true, "result === true");
|
||||
|
||||
verifyEqualTo(target, "attr", 1);
|
||||
verifyWritable(target, "attr");
|
||||
verifyEnumerable(target, "attr");
|
||||
verifyConfigurable(target, "attr");
|
||||
|
||||
result = Reflect.defineProperty(p, "attr", {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: 2
|
||||
});
|
||||
|
||||
assert.sameValue(result, true, "result === true");
|
||||
|
||||
verifyEqualTo(target, "attr", 2);
|
||||
verifyNotWritable(target, "attr");
|
||||
verifyNotEnumerable(target, "attr");
|
||||
verifyNotConfigurable(target, "attr");
|
|
@ -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.6
|
||||
description: >
|
||||
Trap return is an abrupt.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
10. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P,
|
||||
descObj»)).
|
||||
11. ReturnIfAbrupt(booleanTrapResult).
|
||||
...
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Object.defineProperty(p, "foo", {});
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Throw a TypeError exception if Desc is not configurable and target property
|
||||
descriptor is configurable and trap result is true.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
20. Else targetDesc is not undefined,
|
||||
b. If settingConfigFalse is true and targetDesc.[[Configurable]] is
|
||||
true, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, "foo", {
|
||||
value: 1,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(p, "foo", {
|
||||
value: 1,
|
||||
configurable: false
|
||||
});
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Throw a TypeError exception if Desc and target property descriptor are not
|
||||
compatible and trap result is true.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
20. Else targetDesc is not undefined,
|
||||
a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc ,
|
||||
targetDesc) is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, "foo", {
|
||||
value: 1,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(p, "foo", {
|
||||
value: 1,
|
||||
configurable: true
|
||||
});
|
||||
});
|
|
@ -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.6
|
||||
description: >
|
||||
Throw a TypeError exception if Desc and target property descriptor are not
|
||||
compatible and trap result is true.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
20. Else targetDesc is not undefined,
|
||||
a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc ,
|
||||
targetDesc) is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, "foo", {
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(p, "foo", {
|
||||
value: 2
|
||||
});
|
||||
});
|
|
@ -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.6
|
||||
description: >
|
||||
Throw a TypeError exception if Desc is not configurable and target property
|
||||
descriptor is undefined, and trap result is true.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
19. If targetDesc is undefined, then
|
||||
...
|
||||
b. If settingConfigFalse is true, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(p, "foo", {
|
||||
configurable: false
|
||||
});
|
||||
});
|
|
@ -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.6
|
||||
description: >
|
||||
Throw a TypeError exception if Desc is not configurable and target is not
|
||||
extensible, and trap result is true.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
19. If targetDesc is undefined, then
|
||||
a. If extensibleTarget is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Object.preventExtensions(target);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(p, "foo", {});
|
||||
});
|
|
@ -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.6
|
||||
description: >
|
||||
Throw a TypeError exception if trap is not callable.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
6. Let trap be GetMethod(handler, "defineProperty").
|
||||
...
|
||||
7.3.9 GetMethod (O, P)
|
||||
...
|
||||
2. Let func be GetV(O, P).
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(p, "foo", {
|
||||
value: 1
|
||||
});
|
||||
});
|
|
@ -0,0 +1,42 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Return target.[[DefineOwnProperty]](P, Desc) if trap is undefined.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
8. If trap is undefined, then
|
||||
a. Return target.[[DefineOwnProperty]](P, Desc).
|
||||
...
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
Object.defineProperty(p, "attr", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
verifyEqualTo(target, "attr", 1);
|
||||
verifyWritable(target, "attr");
|
||||
verifyEnumerable(target, "attr");
|
||||
verifyConfigurable(target, "attr");
|
||||
|
||||
Object.defineProperty(p, "attr", {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: 2
|
||||
});
|
||||
|
||||
verifyEqualTo(target, "attr", 2);
|
||||
verifyNotWritable(target, "attr");
|
||||
verifyNotEnumerable(target, "attr");
|
||||
verifyNotConfigurable(target, "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.6
|
||||
description: >
|
||||
Trap returns a boolean. Checking on false values.
|
||||
info: >
|
||||
[[DefineOwnProperty]] (P, Desc)
|
||||
|
||||
...
|
||||
12. If booleanTrapResult is false, return false.
|
||||
...
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
defineProperty: function(t, prop, desc) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(Reflect.defineProperty(p, "attr", {}), false);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(target, "attr"),
|
||||
undefined
|
||||
);
|
|
@ -0,0 +1,32 @@
|
|||
// 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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
The result is a Boolean value.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
deleteProperty: function() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperties(target, {
|
||||
isConfigurable: {
|
||||
value: 1,
|
||||
configurable: true
|
||||
},
|
||||
notConfigurable: {
|
||||
value: 1,
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(Reflect.deleteProperty(p, "attr"), false);
|
||||
assert.sameValue(Reflect.deleteProperty(p, "isConfigurable"), false);
|
||||
assert.sameValue(Reflect.deleteProperty(p, "notConfigurable"), false);
|
|
@ -0,0 +1,17 @@
|
|||
// 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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
The result is a Boolean value.
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
deleteProperty: function() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(Reflect.deleteProperty(p, "attr"), true);
|
|
@ -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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)).
|
||||
info: >
|
||||
6.1.7.2 Object Internal Methods and Internal Slots
|
||||
|
||||
(...) Receiver is used as the this value when evaluating the code
|
||||
---*/
|
||||
|
||||
var _handler, _target, _prop;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var handler = {
|
||||
deleteProperty: function(t, prop) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_prop = prop;
|
||||
return delete t[prop];
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
delete p.attr;
|
||||
|
||||
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");
|
|
@ -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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
3. If handler is null, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({
|
||||
attr: 1
|
||||
}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
delete p.proxy.attr;
|
||||
});
|
|
@ -0,0 +1,18 @@
|
|||
// 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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
11. If booleanTrapResult is false, return false.
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
deleteProperty: function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(delete p.attr, false);
|
|
@ -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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
11. If booleanTrapResult is false, return false.
|
||||
flags: [onlyStrict]
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
deleteProperty: function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(Reflect.deleteProperty(p, "attr"), false);
|
|
@ -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.10
|
||||
description: >
|
||||
Trap return is an abrupt.
|
||||
info: >
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)).
|
||||
10. ReturnIfAbrupt(booleanTrapResult).
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
deleteProperty: function(t, prop) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
delete p.attr;
|
||||
});
|
|
@ -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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
A property cannot be reported as deleted, if it exists as a non-configurable
|
||||
own property of the target object.
|
||||
info: >
|
||||
14. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
deleteProperty: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: false,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
delete p.attr;
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
// 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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
14. If targetDesc is undefined, return true.
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
deleteProperty: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(delete p.attr, true);
|
|
@ -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.10
|
||||
description: >
|
||||
Throws when trap is not callable.
|
||||
info: >
|
||||
9.5.10 [[Delete]] (P)
|
||||
|
||||
6. Let trap be GetMethod(handler, "deleteProperty").
|
||||
...
|
||||
|
||||
7.3.9 GetMethod (O, P)
|
||||
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
deleteProperty: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
delete p.attr;
|
||||
});
|
|
@ -0,0 +1,30 @@
|
|||
// 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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
8. If trap is undefined, then Return target.[[Delete]](P).
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
assert.sameValue(delete p.attr, true);
|
||||
assert.sameValue(delete p.notThere, true);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(target, "attr"),
|
||||
undefined
|
||||
);
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.sameValue(delete p.attr, false);
|
|
@ -0,0 +1,31 @@
|
|||
// 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.10
|
||||
description: >
|
||||
[[Delete]] (P)
|
||||
|
||||
8. If trap is undefined, then Return target.[[Delete]](P).
|
||||
flags: [onlyStrict]
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
assert.sameValue(delete p.attr, true);
|
||||
assert.sameValue(delete p.notThere, true);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(target, "attr"),
|
||||
undefined
|
||||
);
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.sameValue(Reflect.deleteProperty(p, "attr"), false);
|
|
@ -0,0 +1,30 @@
|
|||
// 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.11
|
||||
description: >
|
||||
Trap called as trap.call(handler, target)
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
8. Let trapResult be Call(trap, handler, «target»).
|
||||
---*/
|
||||
|
||||
var x, _target, _handler;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var handler = {
|
||||
enumerate: function(t) {
|
||||
_target = t;
|
||||
_handler = this;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
for (x in p) {}
|
||||
} catch(e) {}
|
||||
|
||||
assert.sameValue(_handler, handler);
|
||||
assert.sameValue(_target, target);
|
|
@ -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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
2. If handler is null, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p.proxy) {
|
||||
x;
|
||||
}
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
|
@ -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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return Symbol();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
|
@ -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.11
|
||||
description: >
|
||||
Trap returns abrupt.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
8. Let trapResult be Call(trap, handler, «target»).
|
||||
9. ReturnIfAbrupt(trapResult).
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = new Proxy({}, {
|
||||
enumerate: function(t) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
for (x in p) {}
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// 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.11
|
||||
description: >
|
||||
Trap returns an iterator whose IteratorResult does not contain a value
|
||||
property.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
11. Return trapResult
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = new Proxy([1,2,3], {
|
||||
enumerate: function(t) {
|
||||
return {next: function() { return { done:true }; } };
|
||||
}
|
||||
});
|
||||
|
||||
for (x in p) {
|
||||
$ERROR("returned iterable interface from trap is flagged as done.");
|
||||
}
|
|
@ -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.11
|
||||
description: >
|
||||
Trap returns a iterable result.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
11. Return trapResult
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var iter = [
|
||||
{done: false, value: 1},
|
||||
{done: false, value: 2},
|
||||
{done: false, value: 3},
|
||||
{done: true, value: 42}
|
||||
];
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var foo = { bar: 1 };
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return { next: function() { return iter.shift(); } };
|
||||
}
|
||||
});
|
||||
|
||||
var results = [];
|
||||
for (x in p) {
|
||||
results.push(x);
|
||||
}
|
||||
|
||||
assert(compareArray(results, [1,2,3]));
|
|
@ -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.11
|
||||
description: >
|
||||
Trap is not callable.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
5. Let trap be GetMethod(handler, "enumerate").
|
||||
...
|
||||
|
||||
7.3.9 GetMethod (O, P)
|
||||
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = new Proxy({attr:1}, {
|
||||
enumerate: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
7. If trap is undefined, then Return target.[[Enumerate]]().
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
var count = 0;
|
||||
for (x in p) {
|
||||
count++;
|
||||
}
|
||||
|
||||
assert.sameValue(count, 1);
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 26.2.2
|
||||
description: >
|
||||
The value of the [[Prototype]] internal slot of the Proxy
|
||||
constructor is the intrinsic object %FunctionPrototype% (19.2.3).
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(Proxy),
|
||||
Function.prototype,
|
||||
"`Object.getPrototypeOf(Proxy)` returns `Function.prototype`"
|
||||
);
|
|
@ -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');
|
|
@ -0,0 +1,32 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Trap is called with hander context and parameters are target and P
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
9. Let trapResultObj be Call(trap, handler, «target, P»).
|
||||
...
|
||||
---*/
|
||||
|
||||
var _target, _handler, _prop;
|
||||
var target = {attr: 1};
|
||||
var handler = {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
_target = t;
|
||||
_handler = this;
|
||||
_prop = prop;
|
||||
|
||||
return Object.getOwnPropertyDescriptor(t);
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.getOwnPropertyDescriptor(p, "attr");
|
||||
|
||||
assert.sameValue(_handler, handler);
|
||||
assert.sameValue(_target, target);
|
||||
assert.sameValue(_prop, "attr");
|
|
@ -0,0 +1,15 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Throws a TypeError exception if handler is null.
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p.proxy);
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Throws a TypeError exception if trap result is undefined and target is not
|
||||
extensible
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
14. If trapResultObj is undefined, then
|
||||
...
|
||||
e. If ToBoolean(extensibleTarget) is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
foo: 1
|
||||
};
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Object.preventExtensions(target);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "foo");
|
||||
});
|
|
@ -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.5
|
||||
description: >
|
||||
Throws a TypeError exception if trap result is undefined and target property
|
||||
descriptor is not configurable
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
14. If trapResultObj is undefined, then
|
||||
...
|
||||
b. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
Object.defineProperty(target, "foo", {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
value: 1
|
||||
});
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "foo");
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Throws a TypeError exception if trap result is undefined and target property
|
||||
descriptor is undefined.
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
14. If trapResultObj is undefined, then
|
||||
a. If targetDesc is undefined, return undefined.
|
||||
...
|
||||
---*/
|
||||
|
||||
var t = {};
|
||||
var trapped;
|
||||
var p = new Proxy(t, {
|
||||
getOwnPropertyDescriptor: function(target, prop) {
|
||||
trapped = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(p, "attr"),
|
||||
undefined
|
||||
);
|
||||
|
||||
assert(trapped);
|
|
@ -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.5
|
||||
description: >
|
||||
Return undefined if trap result is undefined and target is extensible and
|
||||
the target property descriptor is configurable.
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
14. If trapResultObj is undefined, then
|
||||
...
|
||||
f. Return undefined.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(Object.getOwnPropertyDescriptor(p, "attr"), undefined);
|
|
@ -0,0 +1,48 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Throws a TypeError exception if trap result is neither Object nor Undefined
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
11. If Type(trapResultObj) is neither Object nor Undefined, throw a
|
||||
TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
number: 1,
|
||||
symbol: Symbol(),
|
||||
string: '',
|
||||
boolean: true,
|
||||
fn: function() {}
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
return t[prop];
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "number");
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "string");
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "symbol");
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "boolean");
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "fn");
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Throws a TypeError exception if trap result and target property descriptors
|
||||
are not compatible.
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
20. Let valid be IsCompatiblePropertyDescriptor (extensibleTarget,
|
||||
resultDesc, targetDesc).
|
||||
21. If valid is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
var foo = { bar: 1 };
|
||||
|
||||
return Object.getOwnPropertyDescriptor(foo, "bar");
|
||||
}
|
||||
});
|
||||
|
||||
Object.preventExtensions(target);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "bar");
|
||||
});
|
|
@ -0,0 +1,39 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Throws a TypeError exception if trap result is not configurable but target
|
||||
property descriptor is configurable.
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
22. If resultDesc.[[Configurable]] is false, then
|
||||
a. If targetDesc is undefined or targetDesc.[[Configurable]] is true,
|
||||
then
|
||||
i. Throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
bar: 1
|
||||
};
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
var foo = {};
|
||||
|
||||
Object.defineProperty(foo, "bar", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
return Object.getOwnPropertyDescriptor(foo, prop);
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "bar");
|
||||
});
|
|
@ -0,0 +1,47 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Throws a TypeError exception if trap result is not configurable but target
|
||||
property descriptor is undefined.
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
|
||||
...
|
||||
5. Let target be the value of the [[ProxyTarget]] internal slot of O.
|
||||
6. Let trap be GetMethod(handler, "getOwnPropertyDescriptor").
|
||||
...
|
||||
9. Let trapResultObj be Call(trap, handler, «target, P»).
|
||||
...
|
||||
12. Let targetDesc be target.[[GetOwnProperty]](P).
|
||||
...
|
||||
17. Let resultDesc be ToPropertyDescriptor(trapResultObj).
|
||||
...
|
||||
22. If resultDesc.[[Configurable]] is false, then
|
||||
a. If targetDesc is undefined or targetDesc.[[Configurable]] is true, then
|
||||
i. Throw a TypeError exception.
|
||||
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
var foo = {};
|
||||
|
||||
Object.defineProperty(foo, "bar", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
return Object.getOwnPropertyDescriptor(foo, prop);
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "bar");
|
||||
});
|
|
@ -0,0 +1,30 @@
|
|||
// 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.5
|
||||
description: >
|
||||
Return descriptor from trap result if it has the same value as the target
|
||||
property descriptor.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var descriptor = {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: 1
|
||||
};
|
||||
|
||||
Object.defineProperty(target, "bar", descriptor);
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
return Object.getOwnPropertyDescriptor(t, prop);
|
||||
}
|
||||
});
|
||||
|
||||
var proxyDesc = Object.getOwnPropertyDescriptor(p, "bar");
|
||||
|
||||
assert(proxyDesc.configurable);
|
||||
assert(proxyDesc.enumerable);
|
||||
assert.sameValue(proxyDesc.value, 1);
|
||||
assert.sameValue(proxyDesc.writable, false);
|
|
@ -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.5
|
||||
description: >
|
||||
Return descriptor from trap result if it has the same value as the target
|
||||
property descriptor and they're not configurable.
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
var p = new Proxy(target, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
return Object.getOwnPropertyDescriptor(t, prop);
|
||||
}
|
||||
});
|
||||
|
||||
var proxyDesc = Object.getOwnPropertyDescriptor(p, "attr");
|
||||
|
||||
assert.sameValue(proxyDesc.configurable, false);
|
||||
assert(proxyDesc.enumerable);
|
||||
assert.sameValue(proxyDesc.value, 1);
|
||||
assert.sameValue(proxyDesc.writable, false);
|
|
@ -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.5
|
||||
description: >
|
||||
Trap returns abrupt.
|
||||
info: >
|
||||
[[GetOwnProperty]] (P)
|
||||
|
||||
...
|
||||
9. Let trapResultObj be Call(trap, handler, «target, P»).
|
||||
10. ReturnIfAbrupt(trapResultObj).
|
||||
...
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
getOwnPropertyDescriptor: function(t, prop) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Object.getOwnPropertyDescriptor(p, "attr");
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue