From ba93cfa52dcfe6ce4e9f9f0c4571048bc64e2fb8 Mon Sep 17 00:00:00 2001 From: Keith Miller <keith_miller@apple.com> Date: Tue, 30 Aug 2016 14:03:54 -0700 Subject: [PATCH] Update the toString/proxy.js to test stringifing functions --- .../Object/prototype/toString/proxy.js | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/test/built-ins/Object/prototype/toString/proxy.js b/test/built-ins/Object/prototype/toString/proxy.js index 366607adfe..670bf12f86 100644 --- a/test/built-ins/Object/prototype/toString/proxy.js +++ b/test/built-ins/Object/prototype/toString/proxy.js @@ -1,9 +1,10 @@ // Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2016 the Apple Inc. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-object.prototype.tostring es6id: 19.1.3.6 -description: Proxy of an array is treated as an array +description: Proxy of an array/function is treated as an array/function info: | [...] 3. Let O be ToObject(this value). @@ -20,6 +21,14 @@ info: | b. Let target be the value of the [[ProxyTarget]] internal slot of argument. c. Return ? IsArray(target). + + 9.5.14 ProxyCreate(target, handler) + + [...] + 7. If IsCallable(target) is true, then + a. Set the [[Call]] internal method of P as specified in 9.5.12. + [...] + features: [Proxy] ---*/ @@ -38,3 +47,50 @@ assert.sameValue( '[object Array]', 'proxy for array proxy' ); + +var functionProxy = new Proxy(function() { }, {}); +var functionProxyProxy = new Proxy(functionProxy, {}); + +assert.sameValue( + Object.prototype.toString.call(functionProxy), '[object Function]', 'function proxy' +); +assert.sameValue( + Object.prototype.toString.call(functionProxyProxy), + '[object Function]', + 'proxy for function proxy' +); + +var arrowProxy = new Proxy(() => { }, {}); +var arrowProxyProxy = new Proxy(arrowProxy, {}); + +assert.sameValue( + Object.prototype.toString.call(arrowProxy), '[object Function]', 'arrow function proxy' +); +assert.sameValue( + Object.prototype.toString.call(arrowProxyProxy), + '[object Function]', + 'proxy for arrow function proxy' +); + +var generatorProxy = new Proxy(function*() { }, {}); +var generatorProxyProxy = new Proxy(generatorProxy, {}); + +assert.sameValue( + Object.prototype.toString.call(generatorProxy), '[object GeneratorFunction]', 'generator function proxy' +); +assert.sameValue( + Object.prototype.toString.call(generatorProxyProxy), + '[object GeneratorFunction]', + 'proxy for generator function proxy' +); + +delete generatorProxy.__proto__[Symbol.toStringTag]; + +assert.sameValue( + Object.prototype.toString.call(generatorProxy), '[object Function]', 'generator function proxy without Symbol.toStringTag' +); +assert.sameValue( + Object.prototype.toString.call(generatorProxyProxy), + '[object Function]', + 'proxy for generator function proxy without Symbol.toStringTag' +); -- GitLab