| OLD | NEW | 
|    1 // Copyright 2011 the V8 project authors. All rights reserved. |    1 // Copyright 2011 the V8 project authors. All rights reserved. | 
|    2 // Redistribution and use in source and binary forms, with or without |    2 // Redistribution and use in source and binary forms, with or without | 
|    3 // modification, are permitted provided that the following conditions are |    3 // modification, are permitted provided that the following conditions are | 
|    4 // met: |    4 // met: | 
|    5 // |    5 // | 
|    6 //     * Redistributions of source code must retain the above copyright |    6 //     * Redistributions of source code must retain the above copyright | 
|    7 //       notice, this list of conditions and the following disclaimer. |    7 //       notice, this list of conditions and the following disclaimer. | 
|    8 //     * Redistributions in binary form must reproduce the above |    8 //     * Redistributions in binary form must reproduce the above | 
|    9 //       copyright notice, this list of conditions and the following |    9 //       copyright notice, this list of conditions and the following | 
|   10 //       disclaimer in the documentation and/or other materials provided |   10 //       disclaimer in the documentation and/or other materials provided | 
|   11 //       with the distribution. |   11 //       with the distribution. | 
|   12 //     * Neither the name of Google Inc. nor the names of its |   12 //     * Neither the name of Google Inc. nor the names of its | 
|   13 //       contributors may be used to endorse or promote products derived |   13 //       contributors may be used to endorse or promote products derived | 
|   14 //       from this software without specific prior written permission. |   14 //       from this software without specific prior written permission. | 
|   15 // |   15 // | 
|   16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |   16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|   17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |   17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|   18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |   18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
|   19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |   19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
|   20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |   20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
|   21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |   21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
|   22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |   22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|   23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |   23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|   24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |   24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|   25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |   25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
|   26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |   26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|   27  |   27  | 
|   28 // Flags: --harmony-proxies |   28 // Flags: --harmony-proxies --allow-natives-syntax | 
|   29  |   29  | 
|   30  |   30  | 
|   31 // Helper. |   31 // Helper. | 
|   32  |   32  | 
|   33 function CreateFrozen(handler, callTrap, constructTrap) { |   33 function CreateFrozen(handler, callTrap, constructTrap) { | 
|   34   if (handler.fix === undefined) handler.fix = function() { return {} } |   34   if (handler.fix === undefined) handler.fix = function() { return {} } | 
|   35   var f = Proxy.createFunction(handler, callTrap, constructTrap) |   35   var f = Proxy.createFunction(handler, callTrap, constructTrap) | 
|   36   Object.freeze(f) |   36   Object.freeze(f) | 
|   37   return f |   37   return f | 
|   38 } |   38 } | 
|   39  |   39  | 
|   40  |   40  | 
|   41 // Ensures that checking the "length" property of a function proxy doesn't |   41 // Ensures that checking the "length" property of a function proxy doesn't | 
|   42 // crash due to lack of a [[Get]] method. |   42 // crash due to lack of a [[Get]] method. | 
|   43 var handler = { |   43 var handler = { | 
|   44   get : function(r, n) { return n == "length" ? 2 : undefined } |   44   get : function(r, n) { return n == "length" ? 2 : undefined } | 
|   45 } |   45 } | 
|   46  |   46  | 
|   47  |   47  | 
|   48 // Calling (call, Function.prototype.call, Function.prototype.apply, |   48 // Calling (call, Function.prototype.call, Function.prototype.apply, | 
|   49 //          Function.prototype.bind). |   49 //          Function.prototype.bind). | 
|   50  |   50  | 
|   51 var global_object = this |   51 var global_object = this | 
|   52 var receiver |   52 var receiver | 
|   53  |   53  | 
|   54 function TestCall(isStrict, callTrap) { |   54 function TestCall(isStrict, callTrap) { | 
|   55   assertEquals(42, callTrap(5, 37)) |   55   assertEquals(42, callTrap(5, 37)) | 
|   56   assertEquals(isStrict ? undefined : global_object, receiver) |   56   assertSame(isStrict ? undefined : global_object, receiver) | 
|   57  |   57  | 
|   58   var handler = { |   58   var handler = { | 
|   59     get: function(r, k) { |   59     get: function(r, k) { | 
|   60       return k == "length" ? 2 : Function.prototype[k] |   60       return k == "length" ? 2 : Function.prototype[k] | 
|   61     } |   61     } | 
|   62   } |   62   } | 
|   63   var f = Proxy.createFunction(handler, callTrap) |   63   var f = Proxy.createFunction(handler, callTrap) | 
 |   64   var o = {f: f} | 
 |   65   global_object.f = f | 
|   64  |   66  | 
|   65   receiver = 333 |   67   receiver = 333 | 
|   66   assertEquals(42, f(11, 31)) |   68   assertEquals(42, f(11, 31)) | 
|   67   assertEquals(isStrict ? undefined : global_object, receiver) |   69   assertSame(isStrict ? undefined : global_object, receiver) | 
|   68   var o = {f: f} |  | 
|   69   receiver = 333 |   70   receiver = 333 | 
|   70   assertEquals(42, o.f(10, 32)) |   71   assertEquals(42, o.f(10, 32)) | 
|   71   assertSame(o, receiver) |   72   assertSame(o, receiver) | 
|   72   receiver = 333 |   73   receiver = 333 | 
|   73   assertEquals(42, o["f"](9, 33)) |   74   assertEquals(42, o["f"](9, 33)) | 
|   74   assertSame(o, receiver) |   75   assertSame(o, receiver) | 
|   75   receiver = 333 |   76   receiver = 333 | 
|   76   assertEquals(42, (1, o).f(8, 34)) |   77   assertEquals(42, (1, o).f(8, 34)) | 
|   77   assertSame(o, receiver) |   78   assertSame(o, receiver) | 
|   78   receiver = 333 |   79   receiver = 333 | 
|   79   assertEquals(42, (1, o)["f"](7, 35)) |   80   assertEquals(42, (1, o)["f"](7, 35)) | 
|   80   assertSame(o, receiver) |   81   assertSame(o, receiver) | 
|   81   receiver = 333 |   82   receiver = 333 | 
|   82   assertEquals(42, f.call(o, 32, 10)) |   83   assertEquals(42, f.call(o, 32, 10)) | 
|   83   assertSame(o, receiver) |   84   assertSame(o, receiver) | 
|   84   receiver = 333 |   85   receiver = 333 | 
 |   86   assertEquals(42, f.call(undefined, 33, 9)) | 
 |   87   assertSame(isStrict ? undefined : global_object, receiver) | 
 |   88   receiver = 333 | 
|   85   assertEquals(42, f.call(null, 33, 9)) |   89   assertEquals(42, f.call(null, 33, 9)) | 
|   86   assertSame(isStrict ? null : global_object, receiver) |   90   assertSame(isStrict ? null : global_object, receiver) | 
|   87   receiver = 333 |   91   receiver = 333 | 
|   88   assertEquals(44, f.call(2, 21, 23)) |   92   assertEquals(44, f.call(2, 21, 23)) | 
|   89   assertSame(2, receiver.valueOf()) |   93   assertSame(2, receiver.valueOf()) | 
|   90   receiver = 333 |   94   receiver = 333 | 
|   91   assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) |   95   assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) | 
|   92   assertSame(o, receiver) |   96   assertSame(o, receiver) | 
|   93   receiver = 333 |   97   receiver = 333 | 
|   94   assertEquals(43, Function.prototype.call.call(f, null, 20, 23)) |   98   assertEquals(43, Function.prototype.call.call(f, null, 20, 23)) | 
|   95   assertSame(isStrict ? null : global_object, receiver) |   99   assertSame(isStrict ? null : global_object, receiver) | 
|   96   assertEquals(44, Function.prototype.call.call(f, 2, 21, 23)) |  100   assertEquals(44, Function.prototype.call.call(f, 2, 21, 23)) | 
|   97   assertEquals(2, receiver.valueOf()) |  101   assertEquals(2, receiver.valueOf()) | 
|   98   receiver = 333 |  102   receiver = 333 | 
|   99   assertEquals(32, f.apply(o, [16, 16])) |  103   assertEquals(32, f.apply(o, [16, 16])) | 
|  100   assertSame(o, receiver) |  104   assertSame(o, receiver) | 
|  101   receiver = 333 |  105   receiver = 333 | 
|  102   assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) |  106   assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) | 
|  103   assertSame(o, receiver) |  107   assertSame(o, receiver) | 
 |  108   receiver = 333 | 
 |  109   assertEquals(42, %Call(o, 11, 31, f)) | 
 |  110   assertSame(o, receiver) | 
 |  111   receiver = 333 | 
 |  112   assertEquals(42, %Call(null, 11, 31, f)) | 
 |  113   assertSame(isStrict ? null : global_object, receiver) | 
 |  114   receiver = 333 | 
 |  115   assertEquals(42, %Apply(f, o, [11, 31], 0, 2)) | 
 |  116   assertSame(o, receiver) | 
 |  117   receiver = 333 | 
 |  118   assertEquals(42, %Apply(f, null, [11, 31], 0, 2)) | 
 |  119   assertSame(isStrict ? null : global_object, receiver) | 
 |  120   receiver = 333 | 
 |  121   assertEquals(42, %_CallFunction(o, 11, 31, f)) | 
 |  122   assertSame(o, receiver) | 
 |  123   receiver = 333 | 
 |  124   assertEquals(42, %_CallFunction(null, 11, 31, f)) | 
 |  125   assertSame(isStrict ? null : global_object, receiver) | 
|  104  |  126  | 
|  105   var ff = Function.prototype.bind.call(f, o, 12) |  127   var ff = Function.prototype.bind.call(f, o, 12) | 
|  106   assertTrue(ff.length <= 1)  // TODO(rossberg): Not spec'ed yet, be lax. |  128   assertTrue(ff.length <= 1)  // TODO(rossberg): Not spec'ed yet, be lax. | 
|  107   receiver = 333 |  129   receiver = 333 | 
|  108   assertEquals(42, ff(30)) |  130   assertEquals(42, ff(30)) | 
|  109   assertSame(o, receiver) |  131   assertSame(o, receiver) | 
|  110   receiver = 333 |  132   receiver = 333 | 
 |  133   assertEquals(33, Function.prototype.call.call(ff, {}, 21)) | 
 |  134   assertSame(o, receiver) | 
 |  135   receiver = 333 | 
|  111   assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) |  136   assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) | 
|  112   assertSame(o, receiver) |  137   assertSame(o, receiver) | 
 |  138   receiver = 333 | 
 |  139   assertEquals(23, %Call({}, 11, ff)) | 
 |  140   assertSame(o, receiver) | 
 |  141   receiver = 333 | 
 |  142   assertEquals(23, %Call({}, 11, 3, ff)) | 
 |  143   assertSame(o, receiver) | 
 |  144   receiver = 333 | 
 |  145   assertEquals(24, %Apply(ff, {}, [12, 13], 0, 1)) | 
 |  146   assertSame(o, receiver) | 
 |  147   receiver = 333 | 
 |  148   assertEquals(24, %Apply(ff, {}, [12, 13], 0, 2)) | 
 |  149   assertSame(o, receiver) | 
 |  150   receiver = 333 | 
 |  151   assertEquals(34, %_CallFunction({}, 22, ff)) | 
 |  152   assertSame(o, receiver) | 
 |  153   receiver = 333 | 
 |  154   assertEquals(34, %_CallFunction({}, 22, 3, ff)) | 
 |  155   assertSame(o, receiver) | 
|  113  |  156  | 
|  114   var fff = Function.prototype.bind.call(ff, o, 30) |  157   var fff = Function.prototype.bind.call(ff, o, 30) | 
|  115   assertEquals(0, fff.length) |  158   assertEquals(0, fff.length) | 
|  116   receiver = 333 |  159   receiver = 333 | 
|  117   assertEquals(42, fff()) |  160   assertEquals(42, fff()) | 
|  118   assertSame(o, receiver) |  161   assertSame(o, receiver) | 
|  119   receiver = 333 |  162   receiver = 333 | 
|  120   assertEquals(42, Function.prototype.call.call(fff, {})) |  163   assertEquals(42, Function.prototype.call.call(fff, {})) | 
|  121   assertSame(o, receiver) |  164   assertSame(o, receiver) | 
 |  165   receiver = 333 | 
 |  166   assertEquals(42, Function.prototype.apply.call(fff, {})) | 
 |  167   assertSame(o, receiver) | 
 |  168   receiver = 333 | 
 |  169   assertEquals(42, %Call({}, fff)) | 
 |  170   assertSame(o, receiver) | 
 |  171   receiver = 333 | 
 |  172   assertEquals(42, %Call({}, 11, 3, fff)) | 
 |  173   assertSame(o, receiver) | 
 |  174   receiver = 333 | 
 |  175   assertEquals(42, %Apply(fff, {}, [], 0, 0)) | 
 |  176   assertSame(o, receiver) | 
 |  177   receiver = 333 | 
 |  178   assertEquals(42, %Apply(fff, {}, [12, 13], 0, 0)) | 
 |  179   assertSame(o, receiver) | 
 |  180   receiver = 333 | 
 |  181   assertEquals(42, %Apply(fff, {}, [12, 13], 0, 2)) | 
 |  182   assertSame(o, receiver) | 
 |  183   receiver = 333 | 
 |  184   assertEquals(42, %_CallFunction({}, fff)) | 
 |  185   assertSame(o, receiver) | 
 |  186   receiver = 333 | 
 |  187   assertEquals(42, %_CallFunction({}, 3, 4, 5, fff)) | 
 |  188   assertSame(o, receiver) | 
|  122  |  189  | 
|  123   var f = CreateFrozen({}, callTrap) |  190   var f = CreateFrozen({}, callTrap) | 
|  124   receiver = 333 |  191   receiver = 333 | 
|  125   assertEquals(42, f(11, 31)) |  192   assertEquals(42, f(11, 31)) | 
|  126   assertSame(isStrict ? undefined : global_object, receiver) |  193   assertSame(isStrict ? undefined : global_object, receiver) | 
|  127   var o = {f: f} |  194   var o = {f: f} | 
|  128   receiver = 333 |  195   receiver = 333 | 
|  129   assertEquals(42, o.f(10, 32)) |  196   assertEquals(42, o.f(10, 32)) | 
|  130   assertSame(o, receiver) |  197   assertSame(o, receiver) | 
|  131   receiver = 333 |  198   receiver = 333 | 
|  132   assertEquals(42, o["f"](9, 33)) |  199   assertEquals(42, o["f"](9, 33)) | 
|  133   assertSame(o, receiver) |  200   assertSame(o, receiver) | 
|  134   receiver = 333 |  201   receiver = 333 | 
|  135   assertEquals(42, (1, o).f(8, 34)) |  202   assertEquals(42, (1, o).f(8, 34)) | 
|  136   assertSame(o, receiver) |  203   assertSame(o, receiver) | 
|  137   receiver = 333 |  204   receiver = 333 | 
|  138   assertEquals(42, (1, o)["f"](7, 35)) |  205   assertEquals(42, (1, o)["f"](7, 35)) | 
|  139   assertSame(o, receiver) |  206   assertSame(o, receiver) | 
|  140   receiver = 333 |  207   receiver = 333 | 
|  141   assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) |  208   assertEquals(42, Function.prototype.call.call(f, o, 20, 22)) | 
|  142   assertSame(o, receiver) |  209   assertSame(o, receiver) | 
|  143   receiver = 333 |  210   receiver = 333 | 
|  144   assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) |  211   assertEquals(32, Function.prototype.apply.call(f, o, [17, 15])) | 
|  145   assertSame(o, receiver) |  212   assertSame(o, receiver) | 
|  146   receiver = 333 |  213   receiver = 333 | 
|  147   assertEquals(42, ff(30)) |  214   assertEquals(23, %Call({}, 11, 12, f)) | 
|  148   assertSame(o, receiver) |  215   assertSame(o, receiver) | 
|  149   receiver = 333 |  216   receiver = 333 | 
|  150   assertEquals(32, Function.prototype.apply.call(ff, {}, [20])) |  217   assertEquals(27, %Apply(f, {}, [12, 13, 14], 1, 2)) | 
 |  218   assertSame(o, receiver) | 
 |  219   receiver = 333 | 
 |  220   assertEquals(42, %_CallFunction(o, 18, 24, f)) | 
|  151   assertSame(o, receiver) |  221   assertSame(o, receiver) | 
|  152 } |  222 } | 
|  153  |  223  | 
|  154 TestCall(false, function(x, y) { |  224 TestCall(false, function(x, y) { | 
|  155   receiver = this |  225   receiver = this | 
|  156   return x + y |  226   return x + y | 
|  157 }) |  227 }) | 
|  158  |  228  | 
|  159 TestCall(true, function(x, y) { |  229 TestCall(true, function(x, y) { | 
|  160   "use strict" |  230   "use strict" | 
|  161   receiver = this |  231   receiver = this | 
|  162   return x + y |  232   return x + y | 
|  163 }) |  233 }) | 
|  164  |  234  | 
|  165 TestCall(false, function() { |  235 TestCall(false, function() { | 
|  166   receiver = this; return arguments[0] + arguments[1] |  236   receiver = this | 
 |  237   return arguments[0] + arguments[1] | 
|  167 }) |  238 }) | 
|  168  |  239  | 
|  169 TestCall(false, Proxy.createFunction(handler, function(x, y) { |  240 TestCall(false, Proxy.createFunction(handler, function(x, y) { | 
|  170   receiver = this |  241   receiver = this | 
|  171   return x + y |  242   return x + y | 
|  172 })) |  243 })) | 
|  173  |  244  | 
|  174 TestCall(true, Proxy.createFunction(handler, function(x, y) { |  245 TestCall(true, Proxy.createFunction(handler, function(x, y) { | 
|  175   "use strict" |  246   "use strict" | 
|  176   receiver = this |  247   receiver = this | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  202  |  273  | 
|  203 // Throwing from call trap. |  274 // Throwing from call trap. | 
|  204  |  275  | 
|  205 function TestCallThrow(callTrap) { |  276 function TestCallThrow(callTrap) { | 
|  206   var f = Proxy.createFunction({}, callTrap) |  277   var f = Proxy.createFunction({}, callTrap) | 
|  207   assertThrows(function(){ f(11) }, "myexn") |  278   assertThrows(function(){ f(11) }, "myexn") | 
|  208   assertThrows(function(){ ({x: f}).x(11) }, "myexn") |  279   assertThrows(function(){ ({x: f}).x(11) }, "myexn") | 
|  209   assertThrows(function(){ ({x: f})["x"](11) }, "myexn") |  280   assertThrows(function(){ ({x: f})["x"](11) }, "myexn") | 
|  210   assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") |  281   assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") | 
|  211   assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") |  282   assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") | 
 |  283   assertThrows(function(){ %Call({}, f) }, "myexn") | 
 |  284   assertThrows(function(){ %Call({}, 1, 2, f) }, "myexn") | 
 |  285   assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") | 
 |  286   assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") | 
 |  287   assertThrows(function(){ %_CallFunction({}, f) }, "myexn") | 
 |  288   assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") | 
|  212  |  289  | 
|  213   var f = CreateFrozen({}, callTrap) |  290   var f = CreateFrozen({}, callTrap) | 
|  214   assertThrows(function(){ f(11) }, "myexn") |  291   assertThrows(function(){ f(11) }, "myexn") | 
|  215   assertThrows(function(){ ({x: f}).x(11) }, "myexn") |  292   assertThrows(function(){ ({x: f}).x(11) }, "myexn") | 
|  216   assertThrows(function(){ ({x: f})["x"](11) }, "myexn") |  293   assertThrows(function(){ ({x: f})["x"](11) }, "myexn") | 
|  217   assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") |  294   assertThrows(function(){ Function.prototype.call.call(f, {}, 2) }, "myexn") | 
|  218   assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") |  295   assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") | 
 |  296   assertThrows(function(){ %Call({}, f) }, "myexn") | 
 |  297   assertThrows(function(){ %Call({}, 1, 2, f) }, "myexn") | 
 |  298   assertThrows(function(){ %Apply({}, f, [], 3, 0) }, "myexn") | 
 |  299   assertThrows(function(){ %Apply({}, f, [3, 4], 0, 1) }, "myexn") | 
 |  300   assertThrows(function(){ %_CallFunction({}, f) }, "myexn") | 
 |  301   assertThrows(function(){ %_CallFunction({}, 1, 2, f) }, "myexn") | 
|  219 } |  302 } | 
|  220  |  303  | 
|  221 TestCallThrow(function() { throw "myexn" }) |  304 TestCallThrow(function() { throw "myexn" }) | 
|  222 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" })) |  305 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" })) | 
|  223 TestCallThrow(CreateFrozen({}, function() { throw "myexn" })) |  306 TestCallThrow(CreateFrozen({}, function() { throw "myexn" })) | 
|  224  |  307  | 
|  225  |  308  | 
|  226  |  309  | 
|  227 // Construction (new). |  310 // Construction (new). | 
|  228  |  311  | 
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  540  |  623  | 
|  541 TestAccessorCall( |  624 TestAccessorCall( | 
|  542   Proxy.createFunction({}, function() { receiver = this; return 42 }), |  625   Proxy.createFunction({}, function() { receiver = this; return 42 }), | 
|  543   Proxy.createFunction({}, function(x) { receiver = this; value = x }) |  626   Proxy.createFunction({}, function(x) { receiver = this; value = x }) | 
|  544 ) |  627 ) | 
|  545  |  628  | 
|  546 TestAccessorCall( |  629 TestAccessorCall( | 
|  547   CreateFrozen({}, function() { receiver = this; return 42 }), |  630   CreateFrozen({}, function() { receiver = this; return 42 }), | 
|  548   CreateFrozen({}, function(x) { receiver = this; value = x }) |  631   CreateFrozen({}, function(x) { receiver = this; value = x }) | 
|  549 ) |  632 ) | 
 |  633  | 
 |  634  | 
 |  635  | 
 |  636 // TODO(rossberg): Ultimately, I want to have the following test function | 
 |  637 // run through, but it currently fails on so many cases (some not even | 
 |  638 // involving proxies), that I leave that for later... | 
 |  639 /* | 
 |  640 function TestCalls() { | 
 |  641   var handler = { | 
 |  642     get: function(r, k) { | 
 |  643       return k == "length" ? 2 : Function.prototype[k] | 
 |  644     } | 
 |  645   } | 
 |  646   var bind = Function.prototype.bind | 
 |  647   var o = {} | 
 |  648  | 
 |  649   var traps = [ | 
 |  650     function(x, y) { | 
 |  651       return {receiver: this, result: x + y, strict: false} | 
 |  652     }, | 
 |  653     function(x, y) { "use strict"; | 
 |  654       return {receiver: this, result: x + y, strict: true} | 
 |  655     }, | 
 |  656     function() { | 
 |  657       var x = arguments[0], y = arguments[1] | 
 |  658       return {receiver: this, result: x + y, strict: false} | 
 |  659     }, | 
 |  660     Proxy.createFunction(handler, function(x, y) { | 
 |  661       return {receiver: this, result: x + y, strict: false} | 
 |  662     }), | 
 |  663     Proxy.createFunction(handler, function() { | 
 |  664       var x = arguments[0], y = arguments[1] | 
 |  665       return {receiver: this, result: x + y, strict: false} | 
 |  666     }), | 
 |  667     Proxy.createFunction(handler, function(x, y) { "use strict" | 
 |  668       return {receiver: this, result: x + y, strict: true} | 
 |  669     }), | 
 |  670     CreateFrozen(handler, function(x, y) { | 
 |  671       return {receiver: this, result: x + y, strict: false} | 
 |  672     }), | 
 |  673     CreateFrozen(handler, function(x, y) { "use strict" | 
 |  674       return {receiver: this, result: x + y, strict: true} | 
 |  675     }), | 
 |  676   ] | 
 |  677   var creates = [ | 
 |  678     function(trap) { return trap }, | 
 |  679     function(trap) { return CreateFrozen({}, callTrap) }, | 
 |  680     function(trap) { return Proxy.createFunction(handler, callTrap) }, | 
 |  681     function(trap) { | 
 |  682       return Proxy.createFunction(handler, CreateFrozen({}, callTrap)) | 
 |  683     }, | 
 |  684     function(trap) { | 
 |  685       return Proxy.createFunction(handler, Proxy.createFunction(handler, callTra
     p)) | 
 |  686     }, | 
 |  687   ] | 
 |  688   var binds = [ | 
 |  689     function(f, o, x, y) { return f }, | 
 |  690     function(f, o, x, y) { return bind.call(f, o) }, | 
 |  691     function(f, o, x, y) { return bind.call(f, o, x) }, | 
 |  692     function(f, o, x, y) { return bind.call(f, o, x, y) }, | 
 |  693     function(f, o, x, y) { return bind.call(f, o, x, y, 5) }, | 
 |  694     function(f, o, x, y) { return bind.call(bind.call(f, o), {}, x, y) }, | 
 |  695     function(f, o, x, y) { return bind.call(bind.call(f, o, x), {}, y) }, | 
 |  696     function(f, o, x, y) { return bind.call(bind.call(f, o, x, y), {}, 5) }, | 
 |  697   ] | 
 |  698   var calls = [ | 
 |  699     function(f, x, y) { return f(x, y) }, | 
 |  700     function(f, x, y) { var g = f; return g(x, y) }, | 
 |  701     function(f, x, y) { with ({}) return f(x, y) }, | 
 |  702     function(f, x, y) { var g = f; with ({}) return g(x, y) }, | 
 |  703     function(f, x, y, o) { with (o) return f(x, y) }, | 
 |  704     function(f, x, y, o) { return f.call(o, x, y) }, | 
 |  705     function(f, x, y, o) { return f.apply(o, [x, y]) }, | 
 |  706     function(f, x, y, o) { return Function.prototype.call.call(f, o, x, y) }, | 
 |  707     function(f, x, y, o) { return Function.prototype.apply.call(f, o, [x, y]) }, | 
 |  708     function(f, x, y, o) { return %_CallFunction(o, x, y, f) }, | 
 |  709     function(f, x, y, o) { return %Call(o, x, y, f) }, | 
 |  710     function(f, x, y, o) { return %Apply(f, o, [null, x, y, null], 1, 2) }, | 
 |  711     function(f, x, y, o) { return %Apply(f, o, arguments, 2, 2) }, | 
 |  712     function(f, x, y, o) { if (typeof o == "object") return o.f(x, y) }, | 
 |  713     function(f, x, y, o) { if (typeof o == "object") return o["f"](x, y) }, | 
 |  714     function(f, x, y, o) { if (typeof o == "object") return (1, o).f(x, y) }, | 
 |  715     function(f, x, y, o) { if (typeof o == "object") return (1, o)["f"](x, y) }, | 
 |  716   ] | 
 |  717   var receivers = [o, global_object, undefined, null, 2, "bla", true] | 
 |  718   var expectedNonStricts = [o, global_object, global_object, global_object] | 
 |  719  | 
 |  720   for (var t = 0; t < traps.length; ++t) { | 
 |  721     for (var i = 0; i < creates.length; ++i) { | 
 |  722       for (var j = 0; j < binds.length; ++j) { | 
 |  723         for (var k = 0; k < calls.length; ++k) { | 
 |  724           for (var m = 0; m < receivers.length; ++m) { | 
 |  725             for (var n = 0; n < receivers.length; ++n) { | 
 |  726               var bound = receivers[m] | 
 |  727               var receiver = receivers[n] | 
 |  728               var func = binds[j](creates[i](traps[t]), bound, 31, 11) | 
 |  729               var expected = j > 0 ? bound : receiver | 
 |  730               var expectedNonStrict = expectedNonStricts[j > 0 ? m : n] | 
 |  731               o.f = func | 
 |  732               global_object.f = func | 
 |  733               var x = calls[k](func, 11, 31, receiver) | 
 |  734               if (x !== undefined) { | 
 |  735                 assertEquals(42, x.result) | 
 |  736                 if (calls[k].length < 4) | 
 |  737                   assertSame(x.strict ? undefined : global_object, x.receiver) | 
 |  738                 else if (x.strict) | 
 |  739                   assertSame(expected, x.receiver) | 
 |  740                 else if (expectedNonStrict === undefined) | 
 |  741                   assertSame(expected, x.receiver.valueOf()) | 
 |  742                 else | 
 |  743                   assertSame(expectedNonStrict, x.receiver) | 
 |  744               } | 
 |  745             } | 
 |  746           } | 
 |  747         } | 
 |  748       } | 
 |  749     } | 
 |  750   } | 
 |  751 } | 
 |  752  | 
 |  753 TestCalls() | 
 |  754 */ | 
| OLD | NEW |