| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // Use a different bound object. | 59 // Use a different bound object. |
| 60 var obj = {x: 42, y: 43}; | 60 var obj = {x: 42, y: 43}; |
| 61 // Values that would normally be in "this" when calling f_bound_this. | 61 // Values that would normally be in "this" when calling f_bound_this. |
| 62 var x = 42; | 62 var x = 42; |
| 63 var y = 44; | 63 var y = 44; |
| 64 | 64 |
| 65 function f_bound_this(z) { | 65 function f_bound_this(z) { |
| 66 return z + this.y - this.x; | 66 return z + this.y - this.x; |
| 67 } | 67 } |
| 68 | 68 |
| 69 assertEquals(3, f_bound_this(1)) | 69 assertEquals(3, f_bound_this(1)); |
| 70 f = f_bound_this.bind(obj); | 70 f = f_bound_this.bind(obj); |
| 71 assertEquals(2, f(1)); | 71 assertEquals(2, f(1)); |
| 72 assertEquals(1, f.length); | 72 assertEquals(1, f.length); |
| 73 | 73 |
| 74 f = f_bound_this.bind(obj, 2); | 74 f = f_bound_this.bind(obj, 2); |
| 75 assertEquals(3, f()); | 75 assertEquals(3, f()); |
| 76 assertEquals(0, f.length); | 76 assertEquals(0, f.length); |
| 77 | 77 |
| 78 // Test chained binds. | 78 // Test chained binds. |
| 79 | 79 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 287 |
| 288 assertThrows(function() { return f.caller; }, TypeError); | 288 assertThrows(function() { return f.caller; }, TypeError); |
| 289 assertThrows(function() { f.caller = 42; }, TypeError); | 289 assertThrows(function() { f.caller = 42; }, TypeError); |
| 290 assertThrows(function() { return f.arguments; }, TypeError); | 290 assertThrows(function() { return f.arguments; }, TypeError); |
| 291 assertThrows(function() { f.arguments = 42; }, TypeError); | 291 assertThrows(function() { f.arguments = 42; }, TypeError); |
| 292 | 292 |
| 293 // Shouldn't throw. Accessing the functions caller must throw if | 293 // Shouldn't throw. Accessing the functions caller must throw if |
| 294 // the caller is strict and the callee isn't. A bound function is built-in, | 294 // the caller is strict and the callee isn't. A bound function is built-in, |
| 295 // but not considered strict. | 295 // but not considered strict. |
| 296 (function foo() { return foo.caller; }).bind()(); | 296 (function foo() { return foo.caller; }).bind()(); |
| OLD | NEW |