OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var realms = [Realm.current(), Realm.create()]; |
| 6 |
| 7 // Check stack trace filtering across security contexts. |
| 8 var thrower_script = |
| 9 "(function () { Realm.eval(Realm.current(), 'throw Error()') })"; |
| 10 Realm.shared = { |
| 11 thrower_0: Realm.eval(realms[0], thrower_script), |
| 12 thrower_1: Realm.eval(realms[1], thrower_script), |
| 13 }; |
| 14 |
| 15 var script = " \ |
| 16 Error.prepareStackTrace = function(a, b) { return b; }; \ |
| 17 try { \ |
| 18 Realm.shared.thrower_0(); \ |
| 19 } catch (e) { \ |
| 20 Realm.shared.error_0 = e.stack; \ |
| 21 } \ |
| 22 try { \ |
| 23 Realm.shared.thrower_1(); \ |
| 24 } catch (e) { \ |
| 25 Realm.shared.error_1 = e.stack; \ |
| 26 } \ |
| 27 "; |
| 28 |
| 29 function assertNotIn(thrower, error) { |
| 30 for (var i = 0; i < error.length; i++) { |
| 31 assertFalse(false === error[i].getFunction()); |
| 32 } |
| 33 } |
| 34 |
| 35 Realm.eval(realms[1], script); |
| 36 assertSame(3, Realm.shared.error_0.length); |
| 37 assertSame(4, Realm.shared.error_1.length); |
| 38 |
| 39 assertTrue(Realm.shared.thrower_1 === Realm.shared.error_1[2].getFunction()); |
| 40 assertNotIn(Realm.shared.thrower_0, Realm.shared.error_0); |
| 41 assertNotIn(Realm.shared.thrower_0, Realm.shared.error_1); |
| 42 |
| 43 Realm.eval(realms[0], script); |
| 44 assertSame(5, Realm.shared.error_0.length); |
| 45 assertSame(4, Realm.shared.error_1.length); |
| 46 |
| 47 assertTrue(Realm.shared.thrower_0 === Realm.shared.error_0[2].getFunction()); |
| 48 assertNotIn(Realm.shared.thrower_1, Realm.shared.error_0); |
| 49 assertNotIn(Realm.shared.thrower_1, Realm.shared.error_1); |
| 50 |
| 51 |
| 52 // Check .caller filtering across security contexts. |
| 53 var caller_script = "(function (f) { f(); })"; |
| 54 Realm.shared = { |
| 55 caller_0 : Realm.eval(realms[0], caller_script), |
| 56 caller_1 : Realm.eval(realms[1], caller_script), |
| 57 } |
| 58 |
| 59 script = " \ |
| 60 function f_0() { Realm.shared.result_0 = arguments.callee.caller; }; \ |
| 61 function f_1() { Realm.shared.result_1 = arguments.callee.caller; }; \ |
| 62 Realm.shared.caller_0(f_0); \ |
| 63 Realm.shared.caller_1(f_1); \ |
| 64 "; |
| 65 |
| 66 Realm.eval(realms[1], script); |
| 67 assertSame(null, Realm.shared.result_0); |
| 68 assertSame(Realm.shared.caller_1, Realm.shared.result_1); |
| 69 |
| 70 Realm.eval(realms[0], script); |
| 71 assertSame(Realm.shared.caller_0, Realm.shared.result_0); |
| 72 assertSame(null, Realm.shared.result_1); |
OLD | NEW |