public static Scriptable bind ( Context cx , Scriptable scope , String id ) { Scriptable firstXMLObject = null ; Scriptable parent = scope . getParentScope ( ) ; childScopesChecks : if ( parent != null ) { // Check for possibly nested "with" scopes first while ( scope instanceof NativeWith ) { Scriptable withObj = scope . getPrototype ( ) ; if ( withObj instanceof XMLObject ) { XMLObject xmlObject = ( XMLObject ) withObj ; if ( xmlObject . has ( cx , id ) ) { return xmlObject ; } if ( firstXMLObject == null ) { firstXMLObject = xmlObject ; } } else { if ( ScriptableObject . hasProperty ( withObj , id ) ) { return withObj ; } } scope = parent ; parent = parent . getParentScope ( ) ; if ( parent == null ) { break childScopesChecks ; } } for ( ; ; ) { if ( ScriptableObject . hasProperty ( scope , id ) ) { return scope ; } scope = parent ; parent = parent . getParentScope ( ) ; if ( parent == null ) { break childScopesChecks ; } } } // scope here is top scope if ( cx . useDynamicScope ) { scope = checkDynamicScope ( cx . topCallScope , scope ) ; } if ( ScriptableObject . hasProperty ( scope , id ) ) { return scope ; } // Nothing was found, but since XML objects always bind // return one if found return firstXMLObject ; }
Returns the object in the scope chain that has a given property .