| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 x = 5; | 42 x = 5; |
| 43 assertEquals(7, x); | 43 assertEquals(7, x); |
| 44 })(); | 44 })(); |
| 45 | 45 |
| 46 | 46 |
| 47 // const variables may be declared but never initialized, in which case | 47 // const variables may be declared but never initialized, in which case |
| 48 // their value is undefined. | 48 // their value is undefined. |
| 49 | 49 |
| 50 (function (sel) { | 50 (function (sel) { |
| 51 if (sel == 0) | 51 if (sel == 0) { |
| 52 with ({ x: 42 }) { | 52 with ({ x: 42 }) { |
| 53 const x; | 53 const x; |
| 54 } | 54 } |
| 55 else | 55 } else { |
| 56 x = 3; | 56 x = 3; |
| 57 } |
| 57 x = 5; | 58 x = 5; |
| 58 assertTrue(typeof x == 'undefined'); | 59 assertTrue(typeof x == 'undefined'); |
| 59 })(1); | 60 })(1); |
| 60 | 61 |
| 61 | 62 |
| 62 // const variables may be initialized to undefined. | 63 // const variables may be initialized to undefined. |
| 63 (function () { | 64 (function () { |
| 64 with ({ x: 42 }) { | 65 with ({ x: 42 }) { |
| 65 const x = undefined; | 66 const x = undefined; |
| 66 } | 67 } |
| 67 x = 5; | 68 x = 5; |
| 68 assertTrue(typeof x == 'undefined'); | 69 assertTrue(typeof x == 'undefined'); |
| 69 })(); | 70 })(); |
| 70 | 71 |
| 71 | 72 |
| 72 // const variables may be accessed in inner scopes like any other variable. | 73 // const variables may be accessed in inner scopes like any other variable. |
| 73 (function () { | 74 (function () { |
| 74 function bar() { | 75 function bar() { |
| 75 assertEquals(7, x); | 76 assertEquals(7, x); |
| 76 } | 77 } |
| 77 with ({ x: 42 }) { | 78 with ({ x: 42 }) { |
| 78 const x = 7; | 79 const x = 7; |
| 79 } | 80 } |
| 80 x = 5 | 81 x = 5; |
| 81 bar(); | 82 bar(); |
| 82 })(); | 83 })(); |
| 83 | 84 |
| 84 | 85 |
| 85 // const variables may be declared via 'eval' | 86 // const variables may be declared via 'eval' |
| 86 (function () { | 87 (function () { |
| 87 with ({ x: 42 }) { | 88 with ({ x: 42 }) { |
| 88 eval('const x = 7'); | 89 eval('const x = 7'); |
| 89 } | 90 } |
| 90 x = 5; | 91 x = 5; |
| 91 assertEquals(7, x); | 92 assertEquals(7, x); |
| 92 })(); | 93 })(); |
| OLD | NEW |