| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --restricted-realms |
| 6 |
| 5 var r = Realm.create(); | 7 var r = Realm.create(); |
| 6 var f = Realm.eval(r, "function f() { return this }; f()"); | 8 var f = Realm.eval(r, "function f() { return this }; f()"); |
| 7 assertEquals(f, Realm.global(r)); | 9 assertEquals(f, Realm.global(r)); |
| 8 | 10 |
| 9 // Cross-origin property access throws | 11 // Cross-origin property access throws |
| 10 assertThrows(() => f.a, TypeError); | 12 assertThrows(() => f.a, TypeError); |
| 11 assertThrows(() => { 'use strict'; f.a = 1 }, TypeError); | 13 assertThrows(() => { 'use strict'; f.a = 1 }, TypeError); |
| 12 | 14 |
| 13 var r2 = Realm.createAllowCrossRealmAccess(); | 15 var r2 = Realm.createAllowCrossRealmAccess(); |
| 14 var f2 = Realm.eval(r2, "function f() { return this }; f()"); | 16 var f2 = Realm.eval(r2, "function f() { return this }; f()"); |
| 15 assertEquals(f2, Realm.global(r2)); | 17 assertEquals(f2, Realm.global(r2)); |
| 16 | 18 |
| 17 // Same-origin property access doesn't throw | 19 // Same-origin property access doesn't throw |
| 18 assertEquals(undefined, f2.a); | 20 assertEquals(undefined, f2.a); |
| 19 f2.a = 1; | 21 f2.a = 1; |
| 20 assertEquals(1, f2.a); | 22 assertEquals(1, f2.a); |
| OLD | NEW |