Chromium Code Reviews| Index: test/mjsunit/function-bind.js |
| diff --git a/test/mjsunit/function-bind.js b/test/mjsunit/function-bind.js |
| index ca1ed7e489e64f8d5d24a46106025fcca3b2fc1b..be604fbe8dad8edc238d016530137905b8dc5e8c 100644 |
| --- a/test/mjsunit/function-bind.js |
| +++ b/test/mjsunit/function-bind.js |
| @@ -25,9 +25,10 @@ |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| -// Flags: --allow-natives-syntax |
| +// Flags: --allow-natives-syntax --harmony-proxies --harmony-reflect |
| + |
| +// Tests the Function.prototype.bind method. |
| -// Tests the Function.prototype.bind (ES 15.3.4.5) method. |
| // Simple tests. |
| function foo(x, y, z) { |
| @@ -317,3 +318,109 @@ assertThrows(function() { f.arguments = 42; }, TypeError); |
| bound = Function.prototype.bind.call(fun, {}); |
| assertEquals(null, Object.getPrototypeOf(bound)); |
| })(); |
| + |
| + |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// Proxies |
| + |
| + |
| +var log = []; |
| +var logger = {}; |
| +var handler = new Proxy({}, logger); |
| + |
| +logger.get = function(t, trap, r) { |
| + return function() { |
| + log.push([trap, ...arguments]); |
| + return Reflect[trap](...arguments); |
| + } |
| +}; |
| + |
| + |
| +// Simple case |
| + |
| +var target = function(a, b, c) { "use strict"; return this }; |
| +var proxy = new Proxy(target, handler); |
| +var this_value = Symbol(); |
| + |
| +log.length = 0; |
| +result = Function.prototype.bind.call(proxy, this_value, "foo"); |
| +assertEquals(2, result.length); |
| +assertEquals(this_value, result()); |
| +assertEquals(4, log.length); |
| +for (var i in log) assertSame(target, log[i][1]); |
| +assertEquals(["getOwnPropertyDescriptor", target, "length"], log[0]); |
| +assertEquals(["get", target, "length", proxy], log[1]); |
| +assertEquals(["get", target, "name", proxy], log[2]); |
| +assertEquals(["apply", target, this_value, ["foo"]], log[3]); |
|
Camillo Bruni
2015/12/16 13:19:06
Could you add another test where you check the log
neis
2015/12/16 14:00:24
As discussed, the getPrototypeOf should already ha
|
| + |
| + |
| +// Custom length |
| + |
| +handler = { |
| + get() {return 42}, |
| + getOwnPropertyDescriptor() {return {configurable: true}} |
| +}; |
| +proxy = new Proxy(target, handler); |
| + |
| +result = Function.prototype.bind.call(proxy, this_value, "foo"); |
| +assertEquals(41, result.length); |
| +assertEquals(this_value, result()); |
| + |
| + |
| +// Long length |
| + |
| +handler = { |
| + get() {return Math.pow(2, 100)}, |
| + getOwnPropertyDescriptor() {return {configurable: true}} |
| +}; |
| +proxy = new Proxy(target, handler); |
| + |
| +result = Function.prototype.bind.call(proxy, this_value, "foo"); |
| +assertEquals(Math.pow(2, 100) - 1, result.length); |
| +assertEquals(this_value, result()); |
| + |
| + |
| +// Very long length |
| + |
| +handler = { |
| + get() {return 1/0}, |
| + getOwnPropertyDescriptor() {return {configurable: true}} |
| +}; |
| +proxy = new Proxy(target, handler); |
| + |
| +result = Function.prototype.bind.call(proxy, this_value, "foo"); |
| +assertEquals(1/0, result.length); |
| +assertEquals(this_value, result()); |
| + |
| + |
| +// Non-integer length |
| + |
| +handler = { |
| + get() {return 4.2}, |
| + getOwnPropertyDescriptor() {return {configurable: true}} |
| +}; |
| +proxy = new Proxy(target, handler); |
| + |
| +result = Function.prototype.bind.call(proxy, this_value, "foo"); |
| +assertEquals(3, result.length); |
| +assertEquals(this_value, result()); |
| + |
| + |
| +// Undefined length |
| + |
| +handler = { |
| + get() {}, |
| + getOwnPropertyDescriptor() {return {configurable: true}} |
| +}; |
| +proxy = new Proxy(target, handler); |
| + |
| +result = Function.prototype.bind.call(proxy, this_value, "foo"); |
| +assertEquals(0, result.length); |
| +assertEquals(this_value, result()); |
| + |
| + |
| +// Non-callable |
| + |
| +assertThrows(() => Function.prototype.bind.call(new Proxy({}, {})), TypeError); |
| +assertThrows(() => Function.prototype.bind.call(new Proxy([], {})), TypeError); |