@@ -673,6 +673,24 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
673
673
} ) ;
674
674
675
675
var vm_ = require ( 'vm' ) ;
676
+ var context = { require : require } ;
677
+ for ( var key in global ) {
678
+ context [ key ] = global [ key ] ;
679
+ }
680
+ context . list = function ( locator ) {
681
+ /* globals browser */
682
+ return browser . findElements ( locator ) . then ( function ( arr ) {
683
+ var found = [ ] ;
684
+ for ( var i = 0 ; i < arr . length ; ++ i ) {
685
+ arr [ i ] . getText ( ) . then ( function ( text ) {
686
+ found . push ( text ) ;
687
+ } ) ;
688
+ }
689
+ return found ;
690
+ } ) ;
691
+ } ;
692
+ var sandbox = vm_ . createContext ( context ) ;
693
+
676
694
var browserUnderDebug = this ;
677
695
678
696
// Helper used only by debuggers at './debugger/modes/*.js' to insert code
@@ -719,7 +737,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
719
737
var execFn_ = function ( ) {
720
738
// Run code through vm so that we can maintain a local scope which is
721
739
// isolated from the rest of the execution.
722
- var res = vm_ . runInThisContext ( code ) ;
740
+ var res = vm_ . runInContext ( code , sandbox ) ;
723
741
if ( ! webdriver . promise . isPromise ( res ) ) {
724
742
res = webdriver . promise . fulfilled ( res ) ;
725
743
}
@@ -774,19 +792,6 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
774
792
}
775
793
} ;
776
794
777
- global . list = function ( locator ) {
778
- /* globals browser */
779
- return browser . findElements ( locator ) . then ( function ( arr ) {
780
- var found = [ ] ;
781
- for ( var i = 0 ; i < arr . length ; ++ i ) {
782
- arr [ i ] . getText ( ) . then ( function ( text ) {
783
- found . push ( text ) ;
784
- } ) ;
785
- }
786
- return found ;
787
- } ) ;
788
- } ;
789
-
790
795
flow . timeout ( 1000 , 'waiting for debugger to attach' ) ;
791
796
} ;
792
797
0 commit comments