idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
31,600 | public static int murmurhash3x8632 ( byte [ ] data , int offset , int len , int seed ) { int c1 = 0xcc9e2d51 ; int c2 = 0x1b873593 ; int h1 = seed ; int roundedEnd = offset + ( len & 0xfffffffc ) ; for ( int i = offset ; i < roundedEnd ; i += 4 ) { int k1 = ( data [ i ] & 0xff ) | ( ( data [ i + 1 ] & 0xff ) << 8 ) | ( ( data [ i + 2 ] & 0xff ) << 16 ) | ( data [ i + 3 ] << 24 ) ; k1 *= c1 ; k1 = ( k1 << 15 ) | ( k1 >>> 17 ) ; k1 *= c2 ; h1 ^= k1 ; h1 = ( h1 << 13 ) | ( h1 >>> 19 ) ; h1 = h1 * 5 + 0xe6546b64 ; } int k1 = 0 ; switch ( len & 0x03 ) { case 3 : k1 = ( data [ roundedEnd + 2 ] & 0xff ) << 16 ; case 2 : k1 |= ( data [ roundedEnd + 1 ] & 0xff ) << 8 ; case 1 : k1 |= data [ roundedEnd ] & 0xff ; k1 *= c1 ; k1 = ( k1 << 15 ) | ( k1 >>> 17 ) ; k1 *= c2 ; h1 ^= k1 ; default : } h1 ^= len ; h1 ^= h1 >>> 16 ; h1 *= 0x85ebca6b ; h1 ^= h1 >>> 13 ; h1 *= 0xc2b2ae35 ; h1 ^= h1 >>> 16 ; return h1 ; } | This code is public domain . |
31,601 | public static Map < String , ? > getMapFromProperties ( Properties properties , String prefix ) { Map < String , Object > result = new HashMap < String , Object > ( ) ; for ( String key : properties . stringPropertyNames ( ) ) { if ( key . startsWith ( prefix ) ) { String name = key . substring ( prefix . length ( ) ) ; result . put ( name , properties . getProperty ( key ) ) ; } } return result ; } | Extract a Map from some properties by removing a prefix from the key names . |
31,602 | public Collection < GrantedAuthority > getGrantedAuthorities ( DirContextOperations user , String username ) { String userDn = user . getNameInNamespace ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Getting authorities for user " + userDn ) ; } Set < GrantedAuthority > roles = getGroupMembershipRoles ( userDn , username ) ; Set < GrantedAuthority > extraRoles = getAdditionalRoles ( user , username ) ; if ( extraRoles != null ) { roles . addAll ( extraRoles ) ; } if ( defaultRole != null ) { roles . add ( defaultRole ) ; } List < GrantedAuthority > result = new ArrayList < GrantedAuthority > ( roles . size ( ) ) ; result . addAll ( roles ) ; return result ; } | Obtains the authorities for the user who s directory entry is represented by the supplied LdapUserDetails object . |
31,603 | public void setDefaultRole ( String defaultRole ) { Assert . notNull ( defaultRole , "The defaultRole property cannot be set to null" ) ; this . defaultRole = new SimpleGrantedAuthority ( defaultRole ) ; } | The default role which will be assigned to all users . |
31,604 | public void setSearchSubtree ( boolean searchSubtree ) { int searchScope = searchSubtree ? SearchControls . SUBTREE_SCOPE : SearchControls . ONELEVEL_SCOPE ; searchControls . setSearchScope ( searchScope ) ; } | If set to true a subtree scope search will be performed . If false a single - level search is used . |
31,605 | private boolean checkFilter ( SCIMFilter filter ) { switch ( filter . getFilterType ( ) ) { case AND : case OR : return checkFilter ( filter . getFilterComponents ( ) . get ( 0 ) ) | checkFilter ( filter . getFilterComponents ( ) . get ( 1 ) ) ; case EQUALITY : String name = filter . getFilterAttribute ( ) . getAttributeName ( ) ; if ( "id" . equalsIgnoreCase ( name ) || "userName" . equalsIgnoreCase ( name ) ) { return true ; } else if ( OriginKeys . ORIGIN . equalsIgnoreCase ( name ) ) { return false ; } else { throw new ScimException ( "Invalid filter attribute." , HttpStatus . BAD_REQUEST ) ; } case PRESENCE : case STARTS_WITH : case CONTAINS : throw new ScimException ( "Wildcards are not allowed in filter." , HttpStatus . BAD_REQUEST ) ; case GREATER_THAN : case GREATER_OR_EQUAL : case LESS_THAN : case LESS_OR_EQUAL : throw new ScimException ( "Invalid operator." , HttpStatus . BAD_REQUEST ) ; } return false ; } | Returns true if the field id or userName are present in the query . |
31,606 | private ModelAndView getUserApprovalPageResponse ( Map < String , Object > model , AuthorizationRequest authorizationRequest , Authentication principal ) { logger . debug ( "Loading user approval page: " + userApprovalPage ) ; model . putAll ( userApprovalHandler . getUserApprovalRequest ( authorizationRequest , principal ) ) ; return new ModelAndView ( userApprovalPage , model ) ; } | We need explicit approval from the user . |
31,607 | protected String getOrigin ( Principal principal ) { if ( principal instanceof Authentication ) { Authentication caller = ( Authentication ) principal ; StringBuilder builder = new StringBuilder ( ) ; if ( caller instanceof OAuth2Authentication ) { OAuth2Authentication oAuth2Authentication = ( OAuth2Authentication ) caller ; builder . append ( "client=" ) . append ( oAuth2Authentication . getOAuth2Request ( ) . getClientId ( ) ) ; if ( ! oAuth2Authentication . isClientOnly ( ) ) { builder . append ( ", " ) . append ( "user=" ) . append ( oAuth2Authentication . getName ( ) ) ; } } else { builder . append ( "caller=" ) . append ( caller . getName ( ) ) ; } if ( caller . getDetails ( ) != null ) { builder . append ( ", details=(" ) ; try { @ SuppressWarnings ( "unchecked" ) Map < String , Object > map = JsonUtils . readValue ( ( String ) caller . getDetails ( ) , new TypeReference < Map < String , Object > > ( ) { } ) ; if ( map . containsKey ( "remoteAddress" ) ) { builder . append ( "remoteAddress=" ) . append ( map . get ( "remoteAddress" ) ) . append ( ", " ) ; } builder . append ( "type=" ) . append ( caller . getDetails ( ) . getClass ( ) . getSimpleName ( ) ) ; } catch ( Exception e ) { builder . append ( caller . getDetails ( ) ) ; } appendTokenDetails ( caller , builder ) ; builder . append ( ")" ) ; } return builder . toString ( ) ; } return principal == null ? null : principal . getName ( ) ; } | due to some OAuth authentication scenarios which don t set it . |
31,608 | public Set < Map < String , String [ ] > > searchForMultipleAttributeValues ( final String base , final String filter , final Object [ ] params , final String [ ] attributeNames ) { Object [ ] encodedParams = new String [ params . length ] ; for ( int i = 0 ; i < params . length ; i ++ ) { encodedParams [ i ] = LdapEncoder . filterEncode ( params [ i ] . toString ( ) ) ; } String formattedFilter = MessageFormat . format ( filter , encodedParams ) ; logger . debug ( "Using filter: " + formattedFilter ) ; final HashSet < Map < String , String [ ] > > set = new HashSet < Map < String , String [ ] > > ( ) ; ContextMapper roleMapper = new ContextMapper ( ) { public Object mapFromContext ( Object ctx ) { DirContextAdapter adapter = ( DirContextAdapter ) ctx ; Map < String , String [ ] > record = new HashMap < String , String [ ] > ( ) ; for ( String attributeName : attributeNames ) { String [ ] values = adapter . getStringAttributes ( attributeName ) ; if ( values == null || values . length == 0 ) { logger . debug ( "No attribute value found for '" + attributeName + "'" ) ; } else { record . put ( attributeName , values ) ; } } record . put ( DN_KEY , new String [ ] { adapter . getDn ( ) . toString ( ) } ) ; set . add ( record ) ; return null ; } } ; SearchControls ctls = new SearchControls ( ) ; ctls . setSearchScope ( searchControls . getSearchScope ( ) ) ; ctls . setReturningAttributes ( attributeNames ) ; search ( base , formattedFilter , ctls , roleMapper ) ; return set ; } | Performs a search using the supplied filter and returns the values of each named attribute found in all entries matched by the search . Note that one directory entry may have several values for the attribute . Intended for role searches and similar scenarios . |
31,609 | public void setParams ( List < AstNode > params ) { if ( params == null ) { this . params = null ; } else { if ( this . params != null ) this . params . clear ( ) ; for ( AstNode param : params ) addParam ( param ) ; } } | Sets the function parameter list and sets the parent for each element of the list . |
31,610 | public void addParam ( AstNode param ) { assertNotNull ( param ) ; if ( params == null ) { params = new ArrayList < AstNode > ( ) ; } params . add ( param ) ; param . setParent ( this ) ; } | Adds a parameter to the function parameter list . Sets the parent of the param node to this node . |
31,611 | public void visit ( NodeVisitor v ) { if ( v . visit ( this ) ) { if ( functionName != null ) { functionName . visit ( v ) ; } for ( AstNode param : getParams ( ) ) { param . visit ( v ) ; } getBody ( ) . visit ( v ) ; if ( ! isExpressionClosure ) { if ( memberExprNode != null ) { memberExprNode . visit ( v ) ; } } } } | Visits this node the function name node if supplied the parameters and the body . If there is a member - expr node it is visited last . |
31,612 | public static Context getCurrentContext ( ) { Object helper = VMBridge . instance . getThreadContextHelper ( ) ; return VMBridge . instance . getContext ( helper ) ; } | Get the current Context . |
31,613 | public static void exit ( ) { Object helper = VMBridge . instance . getThreadContextHelper ( ) ; Context cx = VMBridge . instance . getContext ( helper ) ; if ( cx == null ) { throw new IllegalStateException ( "Calling Context.exit without previous Context.enter" ) ; } if ( cx . enterCount < 1 ) Kit . codeBug ( ) ; if ( -- cx . enterCount == 0 ) { VMBridge . instance . setContext ( helper , null ) ; cx . factory . onContextReleased ( cx ) ; } } | Exit a block of code requiring a Context . |
31,614 | public void setLanguageVersion ( int version ) { if ( sealed ) onSealedMutation ( ) ; checkLanguageVersion ( version ) ; Object listeners = propertyListeners ; if ( listeners != null && version != this . version ) { firePropertyChangeImpl ( listeners , languageVersionProperty , Integer . valueOf ( this . version ) , Integer . valueOf ( version ) ) ; } this . version = version ; } | Set the language version . |
31,615 | public final String getImplementationVersion ( ) { if ( implementationVersion == null ) { Enumeration < URL > urls ; try { urls = Context . class . getClassLoader ( ) . getResources ( "META-INF/MANIFEST.MF" ) ; } catch ( IOException ioe ) { return null ; } while ( urls . hasMoreElements ( ) ) { URL metaUrl = urls . nextElement ( ) ; InputStream is = null ; try { is = metaUrl . openStream ( ) ; Manifest mf = new Manifest ( is ) ; Attributes attrs = mf . getMainAttributes ( ) ; if ( "Mozilla Rhino" . equals ( attrs . getValue ( "Implementation-Title" ) ) ) { implementationVersion = "Rhino " + attrs . getValue ( "Implementation-Version" ) + " " + attrs . getValue ( "Built-Date" ) . replaceAll ( "-" , " " ) ; return implementationVersion ; } } catch ( IOException e ) { } finally { try { if ( is != null ) is . close ( ) ; } catch ( IOException e ) { } } } } return implementationVersion ; } | Get the implementation version . |
31,616 | public final ErrorReporter setErrorReporter ( ErrorReporter reporter ) { if ( sealed ) onSealedMutation ( ) ; if ( reporter == null ) throw new IllegalArgumentException ( ) ; ErrorReporter old = getErrorReporter ( ) ; if ( reporter == old ) { return old ; } Object listeners = propertyListeners ; if ( listeners != null ) { firePropertyChangeImpl ( listeners , errorReporterProperty , old , reporter ) ; } this . errorReporter = reporter ; return old ; } | Change the current error reporter . |
31,617 | public final Locale setLocale ( Locale loc ) { if ( sealed ) onSealedMutation ( ) ; Locale result = locale ; locale = loc ; return result ; } | Set the current locale . |
31,618 | public final void addPropertyChangeListener ( PropertyChangeListener l ) { if ( sealed ) onSealedMutation ( ) ; propertyListeners = Kit . addListener ( propertyListeners , l ) ; } | Register an object to receive notifications when a bound property has changed |
31,619 | public final void removePropertyChangeListener ( PropertyChangeListener l ) { if ( sealed ) onSealedMutation ( ) ; propertyListeners = Kit . removeListener ( propertyListeners , l ) ; } | Remove an object from the list of objects registered to receive notification of changes to a bounded property |
31,620 | final void firePropertyChange ( String property , Object oldValue , Object newValue ) { Object listeners = propertyListeners ; if ( listeners != null ) { firePropertyChangeImpl ( listeners , property , oldValue , newValue ) ; } } | Notify any registered listeners that a bounded property has changed |
31,621 | public final Object evaluateString ( Scriptable scope , String source , String sourceName , int lineno , Object securityDomain ) { Script script = compileString ( source , sourceName , lineno , securityDomain ) ; if ( script != null ) { return script . exec ( this , scope ) ; } return null ; } | Evaluate a JavaScript source string . |
31,622 | public final Object evaluateReader ( Scriptable scope , Reader in , String sourceName , int lineno , Object securityDomain ) throws IOException { Script script = compileReader ( scope , in , sourceName , lineno , securityDomain ) ; if ( script != null ) { return script . exec ( this , scope ) ; } return null ; } | Evaluate a reader as JavaScript source . |
31,623 | public Scriptable newObject ( Scriptable scope ) { NativeObject result = new NativeObject ( ) ; ScriptRuntime . setBuiltinProtoAndParent ( result , scope , TopLevel . Builtins . Object ) ; return result ; } | Create a new JavaScript object . |
31,624 | public Scriptable newObject ( Scriptable scope , String constructorName ) { return newObject ( scope , constructorName , ScriptRuntime . emptyArgs ) ; } | Create a new JavaScript object by executing the named constructor . |
31,625 | public Scriptable newObject ( Scriptable scope , String constructorName , Object [ ] args ) { return ScriptRuntime . newObject ( this , scope , constructorName , args ) ; } | Creates a new JavaScript object by executing the named constructor . |
31,626 | public Scriptable newArray ( Scriptable scope , Object [ ] elements ) { if ( elements . getClass ( ) . getComponentType ( ) != ScriptRuntime . ObjectClass ) throw new IllegalArgumentException ( ) ; NativeArray result = new NativeArray ( elements ) ; ScriptRuntime . setBuiltinProtoAndParent ( result , scope , TopLevel . Builtins . Array ) ; return result ; } | Create an array with a set of initial elements . |
31,627 | public static Object jsToJava ( Object value , Class < ? > desiredType ) throws EvaluatorException { return NativeJavaObject . coerceTypeImpl ( desiredType , value ) ; } | Convert a JavaScript value into the desired type . Uses the semantics defined with LiveConnect3 and throws an Illegal argument exception if the conversion cannot be performed . |
31,628 | public final void removeThreadLocal ( Object key ) { if ( sealed ) onSealedMutation ( ) ; if ( threadLocalMap == null ) return ; threadLocalMap . remove ( key ) ; } | Remove values from thread - local storage . |
31,629 | public final void setDebugger ( Debugger debugger , Object contextData ) { if ( sealed ) onSealedMutation ( ) ; this . debugger = debugger ; debuggerData = contextData ; } | Set the associated debugger . |
31,630 | public static DebuggableScript getDebuggableView ( Script script ) { if ( script instanceof NativeFunction ) { return ( ( NativeFunction ) script ) . getDebuggableView ( ) ; } return null ; } | Return DebuggableScript instance if any associated with the script . If callable supports DebuggableScript implementation the method returns it . Otherwise null is returned . |
31,631 | SecurityController getSecurityController ( ) { SecurityController global = SecurityController . global ( ) ; if ( global != null ) { return global ; } return securityController ; } | The method must NOT be public or protected |
31,632 | public void addActivationName ( String name ) { if ( sealed ) onSealedMutation ( ) ; if ( activationNames == null ) activationNames = new HashSet < String > ( ) ; activationNames . add ( name ) ; } | Add a name to the list of names forcing the creation of real activation objects for functions . |
31,633 | public void removeActivationName ( String name ) { if ( sealed ) onSealedMutation ( ) ; if ( activationNames != null ) activationNames . remove ( name ) ; } | Remove a name from the list of names forcing the creation of real activation objects for functions . |
31,634 | private static int preferSignature ( Object [ ] args , Class < ? > [ ] sig1 , boolean vararg1 , Class < ? > [ ] sig2 , boolean vararg2 ) { int totalPreference = 0 ; for ( int j = 0 ; j < args . length ; j ++ ) { Class < ? > type1 = vararg1 && j >= sig1 . length ? sig1 [ sig1 . length - 1 ] : sig1 [ j ] ; Class < ? > type2 = vararg2 && j >= sig2 . length ? sig2 [ sig2 . length - 1 ] : sig2 [ j ] ; if ( type1 == type2 ) { continue ; } Object arg = args [ j ] ; int rank1 = NativeJavaObject . getConversionWeight ( arg , type1 ) ; int rank2 = NativeJavaObject . getConversionWeight ( arg , type2 ) ; int preference ; if ( rank1 < rank2 ) { preference = PREFERENCE_FIRST_ARG ; } else if ( rank1 > rank2 ) { preference = PREFERENCE_SECOND_ARG ; } else { if ( rank1 == NativeJavaObject . CONVERSION_NONTRIVIAL ) { if ( type1 . isAssignableFrom ( type2 ) ) { preference = PREFERENCE_SECOND_ARG ; } else if ( type2 . isAssignableFrom ( type1 ) ) { preference = PREFERENCE_FIRST_ARG ; } else { preference = PREFERENCE_AMBIGUOUS ; } } else { preference = PREFERENCE_AMBIGUOUS ; } } totalPreference |= preference ; if ( totalPreference == PREFERENCE_AMBIGUOUS ) { break ; } } return totalPreference ; } | Determine which of two signatures is the closer fit . Returns one of PREFERENCE_EQUAL PREFERENCE_FIRST_ARG PREFERENCE_SECOND_ARG or PREFERENCE_AMBIGUOUS . |
31,635 | static Object callSecurely ( final CodeSource codeSource , Callable callable , Context cx , Scriptable scope , Scriptable thisObj , Object [ ] args ) { final Thread thread = Thread . currentThread ( ) ; final ClassLoader classLoader = ( ClassLoader ) AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) { public Object run ( ) { return thread . getContextClassLoader ( ) ; } } ) ; Map < ClassLoader , SoftReference < SecureCaller > > classLoaderMap ; synchronized ( callers ) { classLoaderMap = callers . get ( codeSource ) ; if ( classLoaderMap == null ) { classLoaderMap = new WeakHashMap < ClassLoader , SoftReference < SecureCaller > > ( ) ; callers . put ( codeSource , classLoaderMap ) ; } } SecureCaller caller ; synchronized ( classLoaderMap ) { SoftReference < SecureCaller > ref = classLoaderMap . get ( classLoader ) ; if ( ref != null ) { caller = ref . get ( ) ; } else { caller = null ; } if ( caller == null ) { try { caller = ( SecureCaller ) AccessController . doPrivileged ( new PrivilegedExceptionAction < Object > ( ) { public Object run ( ) throws Exception { ClassLoader effectiveClassLoader ; Class < ? > thisClass = getClass ( ) ; if ( classLoader . loadClass ( thisClass . getName ( ) ) != thisClass ) { effectiveClassLoader = thisClass . getClassLoader ( ) ; } else { effectiveClassLoader = classLoader ; } SecureClassLoaderImpl secCl = new SecureClassLoaderImpl ( effectiveClassLoader ) ; Class < ? > c = secCl . defineAndLinkClass ( SecureCaller . class . getName ( ) + "Impl" , secureCallerImplBytecode , codeSource ) ; return c . newInstance ( ) ; } } ) ; classLoaderMap . put ( classLoader , new SoftReference < SecureCaller > ( caller ) ) ; } catch ( PrivilegedActionException ex ) { throw new UndeclaredThrowableException ( ex . getCause ( ) ) ; } } } return caller . call ( callable , cx , scope , thisObj , args ) ; } | Call the specified callable using a protection domain belonging to the specified code source . |
31,636 | public void visit ( NodeVisitor v ) { if ( v . visit ( this ) && value != null ) { value . visit ( v ) ; } } | Visits this node and if present the yielded value . |
31,637 | public void visit ( NodeVisitor v ) { if ( v . visit ( this ) ) { initializer . visit ( v ) ; condition . visit ( v ) ; increment . visit ( v ) ; body . visit ( v ) ; } } | Visits this node the initializer expression the loop condition expression the increment expression and then the loop body . |
31,638 | public void setParentScope ( Scope parentScope ) { this . parentScope = parentScope ; this . top = parentScope == null ? ( ScriptNode ) this : parentScope . top ; } | Sets parent scope |
31,639 | public void addChildScope ( Scope child ) { if ( childScopes == null ) { childScopes = new ArrayList < Scope > ( ) ; } childScopes . add ( child ) ; child . setParentScope ( this ) ; } | Add a scope to our list of child scopes . Sets the child s parent scope to this scope . |
31,640 | public void replaceWith ( Scope newScope ) { if ( childScopes != null ) { for ( Scope kid : childScopes ) { newScope . addChildScope ( kid ) ; } childScopes . clear ( ) ; childScopes = null ; } if ( symbolTable != null && ! symbolTable . isEmpty ( ) ) { joinScopes ( this , newScope ) ; } } | Used by the parser ; not intended for typical use . Changes the parent - scope links for this scope s child scopes to the specified new scope . Copies symbols from this scope into new scope . |
31,641 | public static Scope splitScope ( Scope scope ) { Scope result = new Scope ( scope . getType ( ) ) ; result . symbolTable = scope . symbolTable ; scope . symbolTable = null ; result . parent = scope . parent ; result . setParentScope ( scope . getParentScope ( ) ) ; result . setParentScope ( result ) ; scope . parent = result ; result . top = scope . top ; return result ; } | Creates a new scope node moving symbol table information from scope to the new node and making scope a nested scope contained by the new node . Useful for injecting a new scope in a scope chain . |
31,642 | public static void joinScopes ( Scope source , Scope dest ) { Map < String , Symbol > src = source . ensureSymbolTable ( ) ; Map < String , Symbol > dst = dest . ensureSymbolTable ( ) ; if ( ! Collections . disjoint ( src . keySet ( ) , dst . keySet ( ) ) ) { codeBug ( ) ; } for ( Map . Entry < String , Symbol > entry : src . entrySet ( ) ) { Symbol sym = entry . getValue ( ) ; sym . setContainingTable ( dest ) ; dst . put ( entry . getKey ( ) , sym ) ; } } | Copies all symbols from source scope to dest scope . |
31,643 | public Scope getDefiningScope ( String name ) { for ( Scope s = this ; s != null ; s = s . parentScope ) { Map < String , Symbol > symbolTable = s . getSymbolTable ( ) ; if ( symbolTable != null && symbolTable . containsKey ( name ) ) { return s ; } } return null ; } | Returns the scope in which this name is defined |
31,644 | public Symbol getSymbol ( String name ) { return symbolTable == null ? null : symbolTable . get ( name ) ; } | Looks up a symbol in this scope . |
31,645 | public void putSymbol ( Symbol symbol ) { if ( symbol . getName ( ) == null ) throw new IllegalArgumentException ( "null symbol name" ) ; ensureSymbolTable ( ) ; symbolTable . put ( symbol . getName ( ) , symbol ) ; symbol . setContainingTable ( this ) ; top . addSymbol ( symbol ) ; } | Enters a symbol into this scope . |
31,646 | public void visit ( NodeVisitor v ) { if ( v . visit ( this ) ) { variables . visit ( v ) ; if ( body != null ) { body . visit ( v ) ; } } } | Visits this node the variable list and if present the body expression or statement . |
31,647 | public void setImmunePrototypeProperty ( Object value ) { if ( ( prototypePropertyAttributes & READONLY ) != 0 ) { throw new IllegalStateException ( ) ; } prototypeProperty = ( value != null ) ? value : UniqueTag . NULL_VALUE ; prototypePropertyAttributes = DONTENUM | PERMANENT | READONLY ; } | Make value as DontEnum DontDelete ReadOnly prototype property of this Function object |
31,648 | public Object call ( Context cx , Scriptable scope , Scriptable thisObj , Object [ ] args ) { return Undefined . instance ; } | Should be overridden . |
31,649 | private static Object [ ] getSortedIds ( final Scriptable s ) { final Object [ ] ids = getIds ( s ) ; Arrays . sort ( ids , ( a , b ) -> { if ( a instanceof Integer ) { if ( b instanceof Integer ) { return ( ( Integer ) a ) . compareTo ( ( Integer ) b ) ; } else if ( b instanceof String || b instanceof Symbol ) { return - 1 ; } } else if ( a instanceof String ) { if ( b instanceof String ) { return ( ( String ) a ) . compareTo ( ( String ) b ) ; } else if ( b instanceof Integer ) { return 1 ; } else if ( b instanceof Symbol ) { return - 1 ; } } else if ( a instanceof Symbol ) { if ( b instanceof Symbol ) { return getSymbolName ( ( Symbol ) a ) . compareTo ( getSymbolName ( ( Symbol ) b ) ) ; } else if ( b instanceof Integer || b instanceof String ) { return 1 ; } } throw new ClassCastException ( ) ; } ) ; return ids ; } | Sort IDs deterministically |
31,650 | public Object intern ( Object keyArg ) { boolean nullKey = false ; if ( keyArg == null ) { nullKey = true ; keyArg = UniqueTag . NULL_VALUE ; } int index = ensureIndex ( keyArg ) ; values [ index ] = 0 ; return ( nullKey ) ? null : keys [ index ] ; } | If table already contains a key that equals to keyArg return that key while setting its value to zero otherwise add keyArg with 0 value to the table and return it . |
31,651 | public void visit ( NodeVisitor v ) { if ( v . visit ( this ) ) { condition . visit ( v ) ; thenPart . visit ( v ) ; if ( elsePart != null ) { elsePart . visit ( v ) ; } } } | Visits this node the condition the then - part and if supplied the else - part . |
31,652 | public Scriptable wrapNewObject ( Context cx , Scriptable scope , Object obj ) { if ( obj instanceof Scriptable ) { return ( Scriptable ) obj ; } Class < ? > cls = obj . getClass ( ) ; if ( cls . isArray ( ) ) { return NativeJavaArray . wrap ( scope , obj ) ; } return wrapAsJavaObject ( cx , scope , obj , null ) ; } | Wrap an object newly created by a constructor call . |
31,653 | public void setBody ( AstNode body ) { this . body = body ; int end = body . getPosition ( ) + body . getLength ( ) ; this . setLength ( end - this . getPosition ( ) ) ; body . setParent ( this ) ; } | Sets loop body . Sets the parent of the body to this loop node and updates its offset to be relative . Extends the length of this node to include the body . |
31,654 | public static boolean equalImplementations ( NativeContinuation c1 , NativeContinuation c2 ) { return Objects . equals ( c1 . implementation , c2 . implementation ) ; } | Returns true if both continuations have equal implementations . |
31,655 | NativeJavaPackage forcePackage ( String name , Scriptable scope ) { Object cached = super . get ( name , this ) ; if ( cached != null && cached instanceof NativeJavaPackage ) { return ( NativeJavaPackage ) cached ; } String newPackage = packageName . length ( ) == 0 ? name : packageName + "." + name ; NativeJavaPackage pkg = new NativeJavaPackage ( true , newPackage , classLoader ) ; ScriptRuntime . setObjectProtoAndParent ( pkg , scope ) ; super . put ( name , this , pkg ) ; return pkg ; } | need to look for a class by that name |
31,656 | public boolean hasInstance ( Scriptable value ) { Scriptable proto = value . getPrototype ( ) ; while ( proto != null ) { if ( proto . equals ( this ) ) return true ; proto = proto . getPrototype ( ) ; } return false ; } | instanceof operator . |
31,657 | static boolean accept ( Object nameObj ) { String name ; try { name = ScriptRuntime . toString ( nameObj ) ; } catch ( EcmaError ee ) { if ( "TypeError" . equals ( ee . getName ( ) ) ) { return false ; } throw ee ; } int length = name . length ( ) ; if ( length != 0 ) { if ( isNCNameStartChar ( name . charAt ( 0 ) ) ) { for ( int i = 1 ; i != length ; ++ i ) { if ( ! isNCNameChar ( name . charAt ( i ) ) ) { return false ; } } return true ; } } return false ; } | See ECMA357 13 . 1 . 2 . 1 |
31,658 | static void loadFromIterable ( Context cx , Scriptable scope , ScriptableObject set , Object arg1 ) { if ( ( arg1 == null ) || Undefined . instance . equals ( arg1 ) ) { return ; } Object ito = ScriptRuntime . callIterator ( arg1 , cx , scope ) ; if ( Undefined . instance . equals ( ito ) ) { return ; } ScriptableObject dummy = ensureScriptableObject ( cx . newObject ( scope , set . getClassName ( ) ) ) ; final Callable add = ScriptRuntime . getPropFunctionAndThis ( dummy . getPrototype ( ) , "add" , cx , scope ) ; ScriptRuntime . lastStoredScriptable ( cx ) ; try ( IteratorLikeIterable it = new IteratorLikeIterable ( cx , scope , ito ) ) { for ( Object val : it ) { final Object finalVal = val == Scriptable . NOT_FOUND ? Undefined . instance : val ; add . call ( cx , scope , set , new Object [ ] { finalVal } ) ; } } } | If an iterable object was passed to the constructor there are many many things to do . This is common code with NativeWeakSet . |
31,659 | public KeywordLiteral setType ( int nodeType ) { if ( ! ( nodeType == Token . THIS || nodeType == Token . NULL || nodeType == Token . TRUE || nodeType == Token . FALSE || nodeType == Token . DEBUGGER ) ) throw new IllegalArgumentException ( "Invalid node type: " + nodeType ) ; type = nodeType ; return this ; } | Sets node token type |
31,660 | public static Class < ? > classOrNull ( ClassLoader loader , String className ) { try { return loader . loadClass ( className ) ; } catch ( ClassNotFoundException ex ) { } catch ( SecurityException ex ) { } catch ( LinkageError ex ) { } catch ( IllegalArgumentException e ) { } return null ; } | Attempt to load the class of the given name . Note that the type parameter isn t checked . |
31,661 | public Scriptable getExtraMethodSource ( Context cx ) { if ( hasSimpleContent ( ) ) { String src = toString ( ) ; return ScriptRuntime . toObjectOrNull ( cx , src ) ; } return null ; } | See ECMA 357 11_2_2_1 Semantics 3_f . |
31,662 | static void normalizedBoundaries ( long d64 , DiyFp m_minus , DiyFp m_plus ) { DiyFp v = asDiyFp ( d64 ) ; boolean significand_is_zero = ( v . f ( ) == kHiddenBit ) ; m_plus . setF ( ( v . f ( ) << 1 ) + 1 ) ; m_plus . setE ( v . e ( ) - 1 ) ; m_plus . normalize ( ) ; if ( significand_is_zero && v . e ( ) != kDenormalExponent ) { m_minus . setF ( ( v . f ( ) << 2 ) - 1 ) ; m_minus . setE ( v . e ( ) - 2 ) ; } else { m_minus . setF ( ( v . f ( ) << 1 ) - 1 ) ; m_minus . setE ( v . e ( ) - 1 ) ; } m_minus . setF ( m_minus . f ( ) << ( m_minus . e ( ) - m_plus . e ( ) ) ) ; m_minus . setE ( m_plus . e ( ) ) ; } | exponent as m_plus . |
31,663 | public synchronized static void initGlobal ( ContextFactory factory ) { if ( factory == null ) { throw new IllegalArgumentException ( ) ; } if ( hasCustomGlobal ) { throw new IllegalStateException ( ) ; } hasCustomGlobal = true ; global = factory ; } | Set global ContextFactory . The method can only be called once . |
31,664 | public final void initApplicationClassLoader ( ClassLoader loader ) { if ( loader == null ) throw new IllegalArgumentException ( "loader is null" ) ; if ( ! Kit . testIfCanLoadRhinoClasses ( loader ) ) throw new IllegalArgumentException ( "Loader can not resolve Rhino classes" ) ; if ( this . applicationClassLoader != null ) throw new IllegalStateException ( "applicationClassLoader can only be set once" ) ; checkNotSealed ( ) ; this . applicationClassLoader = loader ; } | Set explicit class loader to use when searching for Java classes . |
31,665 | protected Object doTopCall ( Callable callable , Context cx , Scriptable scope , Scriptable thisObj , Object [ ] args ) { Object result = callable . call ( cx , scope , thisObj , args ) ; return result instanceof ConsString ? result . toString ( ) : result ; } | Execute top call to script or function . When the runtime is about to execute a script or function that will create the first stack frame with scriptable code it calls this method to perform the real call . In this way execution of any script happens inside this function . |
31,666 | public ScriptableObject . Slot query ( Object key , int index ) { if ( slots == null ) { return null ; } final int indexOrHash = ( key != null ? key . hashCode ( ) : index ) ; final int slotIndex = getSlotIndex ( slots . length , indexOrHash ) ; for ( ScriptableObject . Slot slot = slots [ slotIndex ] ; slot != null ; slot = slot . next ) { Object skey = slot . name ; if ( indexOrHash == slot . indexOrHash && ( skey == key || ( key != null && key . equals ( skey ) ) ) ) { return slot ; } } return null ; } | Locate the slot with the given name or index . |
31,667 | public ScriptableObject . Slot get ( Object key , int index , ScriptableObject . SlotAccess accessType ) { if ( slots == null && accessType == SlotAccess . QUERY ) { return null ; } final int indexOrHash = ( key != null ? key . hashCode ( ) : index ) ; ScriptableObject . Slot slot = null ; if ( slots != null ) { final int slotIndex = getSlotIndex ( slots . length , indexOrHash ) ; for ( slot = slots [ slotIndex ] ; slot != null ; slot = slot . next ) { Object skey = slot . name ; if ( indexOrHash == slot . indexOrHash && ( skey == key || ( key != null && key . equals ( skey ) ) ) ) { break ; } } switch ( accessType ) { case QUERY : return slot ; case MODIFY : case MODIFY_CONST : if ( slot != null ) { return slot ; } break ; case MODIFY_GETTER_SETTER : if ( slot instanceof ScriptableObject . GetterSlot ) { return slot ; } break ; case CONVERT_ACCESSOR_TO_DATA : if ( ! ( slot instanceof ScriptableObject . GetterSlot ) ) { return slot ; } break ; } } return createSlot ( key , indexOrHash , accessType , slot ) ; } | Locate the slot with given name or index . Depending on the accessType parameter and the current slot status a new slot may be allocated . |
31,668 | private void addKnownAbsentSlot ( ScriptableObject . Slot [ ] addSlots , ScriptableObject . Slot slot ) { final int insertPos = getSlotIndex ( addSlots . length , slot . indexOrHash ) ; ScriptableObject . Slot old = addSlots [ insertPos ] ; addSlots [ insertPos ] = slot ; slot . next = old ; } | Add slot with keys that are known to absent from the table . This is an optimization to use when inserting into empty table after table growth or during deserialization . |
31,669 | int [ ] getTrimmedLocals ( ) { int last = locals . length - 1 ; while ( last >= 0 && locals [ last ] == TypeInfo . TOP && ! TypeInfo . isTwoWords ( locals [ last - 1 ] ) ) { last -- ; } last ++ ; int size = last ; for ( int i = 0 ; i < last ; i ++ ) { if ( TypeInfo . isTwoWords ( locals [ i ] ) ) { size -- ; } } int [ ] copy = new int [ size ] ; for ( int i = 0 , j = 0 ; i < size ; i ++ , j ++ ) { copy [ i ] = locals [ j ] ; if ( TypeInfo . isTwoWords ( locals [ j ] ) ) { j ++ ; } } return copy ; } | Get a copy of the super block s locals without any trailing TOP types . |
31,670 | private boolean mergeState ( int [ ] current , int [ ] incoming , int size , ConstantPool pool ) { boolean changed = false ; for ( int i = 0 ; i < size ; i ++ ) { int currentType = current [ i ] ; current [ i ] = TypeInfo . merge ( current [ i ] , incoming [ i ] , pool ) ; if ( currentType != current [ i ] ) { changed = true ; } } return changed ; } | Merge an operand stack or local variable array with incoming state . |
31,671 | private DocumentBuilder getDocumentBuilderFromPool ( ) throws ParserConfigurationException { DocumentBuilder builder = documentBuilderPool . pollFirst ( ) ; if ( builder == null ) { builder = getDomFactory ( ) . newDocumentBuilder ( ) ; } builder . setErrorHandler ( errorHandler ) ; return builder ; } | Get from pool or create one without locking if needed . |
31,672 | public void visit ( NodeVisitor v ) { if ( v . visit ( this ) ) { iterator . visit ( v ) ; iteratedObject . visit ( v ) ; } } | Visits the iterator expression and the iterated object expression . There is no body - expression for this loop type . |
31,673 | static BigInteger pow5mult ( BigInteger b , int k ) { return b . multiply ( BigInteger . valueOf ( 5 ) . pow ( k ) ) ; } | XXXX the C version built a cache of these |
31,674 | public boolean has ( Symbol key , Scriptable start ) { return null != slotMap . query ( key , 0 ) ; } | A version of has that supports symbols . |
31,675 | public Object get ( Symbol key , Scriptable start ) { Slot slot = slotMap . query ( key , 0 ) ; if ( slot == null ) { return Scriptable . NOT_FOUND ; } return slot . getValue ( start ) ; } | Another version of Get that supports Symbol keyed properties . |
31,676 | public void put ( Symbol key , Scriptable start , Object value ) { if ( putImpl ( key , 0 , start , value ) ) return ; if ( start == this ) throw Kit . codeBug ( ) ; ensureSymbolScriptable ( start ) . put ( key , start , value ) ; } | Implementation of put required by SymbolScriptable objects . |
31,677 | public void delete ( int index ) { checkNotSealed ( null , index ) ; slotMap . remove ( null , index ) ; } | Removes the indexed property from the object . |
31,678 | public void putConst ( String name , Scriptable start , Object value ) { if ( putConstImpl ( name , 0 , start , value , READONLY ) ) return ; if ( start == this ) throw Kit . codeBug ( ) ; if ( start instanceof ConstProperties ) ( ( ConstProperties ) start ) . putConst ( name , start , value ) ; else start . put ( name , start , value ) ; } | Sets the value of the named const property creating it if need be . |
31,679 | public boolean isConst ( String name ) { Slot slot = slotMap . query ( name , 0 ) ; if ( slot == null ) { return false ; } return ( slot . getAttributes ( ) & ( PERMANENT | READONLY ) ) == ( PERMANENT | READONLY ) ; } | Returns true if the named property is defined as a const on this object . |
31,680 | public void setAttributes ( String name , int attributes ) { checkNotSealed ( name , 0 ) ; findAttributeSlot ( name , 0 , SlotAccess . MODIFY ) . setAttributes ( attributes ) ; } | Set the attributes of a named property . |
31,681 | public void setAttributes ( int index , int attributes ) { checkNotSealed ( null , index ) ; findAttributeSlot ( null , index , SlotAccess . MODIFY ) . setAttributes ( attributes ) ; } | Set the attributes of an indexed property . |
31,682 | public void setAttributes ( Symbol key , int attributes ) { checkNotSealed ( key , 0 ) ; findAttributeSlot ( key , SlotAccess . MODIFY ) . setAttributes ( attributes ) ; } | Set attributes of a Symbol - keyed property . |
31,683 | protected boolean isGetterOrSetter ( String name , int index , boolean setter ) { Slot slot = slotMap . query ( name , index ) ; if ( slot instanceof GetterSlot ) { if ( setter && ( ( GetterSlot ) slot ) . setter != null ) return true ; if ( ! setter && ( ( GetterSlot ) slot ) . getter != null ) return true ; } return false ; } | Returns whether a property is a getter or a setter |
31,684 | public static < T extends Scriptable > void defineClass ( Scriptable scope , Class < T > clazz ) throws IllegalAccessException , InstantiationException , InvocationTargetException { defineClass ( scope , clazz , false , false ) ; } | Defines JavaScript objects from a Java class that implements Scriptable . |
31,685 | public static < T extends Scriptable > String defineClass ( Scriptable scope , Class < T > clazz , boolean sealed , boolean mapInheritance ) throws IllegalAccessException , InstantiationException , InvocationTargetException { BaseFunction ctor = buildClassCtor ( scope , clazz , sealed , mapInheritance ) ; if ( ctor == null ) return null ; String name = ctor . getClassPrototype ( ) . getClassName ( ) ; defineProperty ( scope , name , ctor , ScriptableObject . DONTENUM ) ; return name ; } | Defines JavaScript objects from a Java class optionally allowing sealing and mapping of Java inheritance to JavaScript prototype - based inheritance . |
31,686 | public void defineProperty ( Symbol key , Object value , int attributes ) { checkNotSealed ( key , 0 ) ; put ( key , this , value ) ; setAttributes ( key , attributes ) ; } | A version of defineProperty that uses a Symbol key . |
31,687 | public void defineProperty ( String propertyName , Class < ? > clazz , int attributes ) { int length = propertyName . length ( ) ; if ( length == 0 ) throw new IllegalArgumentException ( ) ; char [ ] buf = new char [ 3 + length ] ; propertyName . getChars ( 0 , length , buf , 3 ) ; buf [ 3 ] = Character . toUpperCase ( buf [ 3 ] ) ; buf [ 0 ] = 'g' ; buf [ 1 ] = 'e' ; buf [ 2 ] = 't' ; String getterName = new String ( buf ) ; buf [ 0 ] = 's' ; String setterName = new String ( buf ) ; Method [ ] methods = FunctionObject . getMethodList ( clazz ) ; Method getter = FunctionObject . findSingleMethod ( methods , getterName ) ; Method setter = FunctionObject . findSingleMethod ( methods , setterName ) ; if ( setter == null ) attributes |= ScriptableObject . READONLY ; defineProperty ( propertyName , null , getter , setter == null ? null : setter , attributes ) ; } | Define a JavaScript property with getter and setter side effects . |
31,688 | public void defineOwnProperties ( Context cx , ScriptableObject props ) { Object [ ] ids = props . getIds ( false , true ) ; ScriptableObject [ ] descs = new ScriptableObject [ ids . length ] ; for ( int i = 0 , len = ids . length ; i < len ; ++ i ) { Object descObj = ScriptRuntime . getObjectElem ( props , ids [ i ] , cx ) ; ScriptableObject desc = ensureScriptableObject ( descObj ) ; checkPropertyDefinition ( desc ) ; descs [ i ] = desc ; } for ( int i = 0 , len = ids . length ; i < len ; ++ i ) { defineOwnProperty ( cx , ids [ i ] , descs [ i ] ) ; } } | Defines one or more properties on this object . |
31,689 | protected boolean sameValue ( Object newValue , Object currentValue ) { if ( newValue == NOT_FOUND ) { return true ; } if ( currentValue == NOT_FOUND ) { currentValue = Undefined . instance ; } if ( currentValue instanceof Number && newValue instanceof Number ) { double d1 = ( ( Number ) currentValue ) . doubleValue ( ) ; double d2 = ( ( Number ) newValue ) . doubleValue ( ) ; if ( Double . isNaN ( d1 ) && Double . isNaN ( d2 ) ) { return true ; } if ( d1 == 0.0 && Double . doubleToLongBits ( d1 ) != Double . doubleToLongBits ( d2 ) ) { return false ; } } return ScriptRuntime . shallowEq ( currentValue , newValue ) ; } | Implements SameValue as described in ES5 9 . 12 additionally checking if new value is defined . |
31,690 | public void defineFunctionProperties ( String [ ] names , Class < ? > clazz , int attributes ) { Method [ ] methods = FunctionObject . getMethodList ( clazz ) ; for ( int i = 0 ; i < names . length ; i ++ ) { String name = names [ i ] ; Method m = FunctionObject . findSingleMethod ( methods , name ) ; if ( m == null ) { throw Context . reportRuntimeError2 ( "msg.method.not.found" , name , clazz . getName ( ) ) ; } FunctionObject f = new FunctionObject ( name , m , this ) ; defineProperty ( name , f , attributes ) ; } } | Search for names in a class adding the resulting methods as properties . |
31,691 | public static Scriptable getObjectPrototype ( Scriptable scope ) { return TopLevel . getBuiltinPrototype ( getTopLevelScope ( scope ) , TopLevel . Builtins . Object ) ; } | Get the Object . prototype property . See ECMA 15 . 2 . 4 . |
31,692 | public static Scriptable getFunctionPrototype ( Scriptable scope ) { return TopLevel . getBuiltinPrototype ( getTopLevelScope ( scope ) , TopLevel . Builtins . Function ) ; } | Get the Function . prototype property . See ECMA 15 . 3 . 4 . |
31,693 | public static Scriptable getClassPrototype ( Scriptable scope , String className ) { scope = getTopLevelScope ( scope ) ; Object ctor = getProperty ( scope , className ) ; Object proto ; if ( ctor instanceof BaseFunction ) { proto = ( ( BaseFunction ) ctor ) . getPrototypeProperty ( ) ; } else if ( ctor instanceof Scriptable ) { Scriptable ctorObj = ( Scriptable ) ctor ; proto = ctorObj . get ( "prototype" , ctorObj ) ; } else { return null ; } if ( proto instanceof Scriptable ) { return ( Scriptable ) proto ; } return null ; } | Get the prototype for the named class . |
31,694 | public static Scriptable getTopLevelScope ( Scriptable obj ) { for ( ; ; ) { Scriptable parent = obj . getParentScope ( ) ; if ( parent == null ) { return obj ; } obj = parent ; } } | Get the global scope . |
31,695 | public void sealObject ( ) { if ( ! isSealed ) { final long stamp = slotMap . readLock ( ) ; try { for ( Slot slot : slotMap ) { Object value = slot . value ; if ( value instanceof LazilyLoadedCtor ) { LazilyLoadedCtor initializer = ( LazilyLoadedCtor ) value ; try { initializer . init ( ) ; } finally { slot . value = initializer . getValue ( ) ; } } } isSealed = true ; } finally { slotMap . unlockRead ( stamp ) ; } } } | Seal this object . |
31,696 | public static Object getProperty ( Scriptable obj , Symbol key ) { Scriptable start = obj ; Object result ; do { result = ensureSymbolScriptable ( obj ) . get ( key , start ) ; if ( result != Scriptable . NOT_FOUND ) break ; obj = obj . getPrototype ( ) ; } while ( obj != null ) ; return result ; } | This is a version of getProperty that works with Symbols . |
31,697 | public static void putProperty ( Scriptable obj , Symbol key , Object value ) { Scriptable base = getBase ( obj , key ) ; if ( base == null ) base = obj ; ensureSymbolScriptable ( base ) . put ( key , obj , value ) ; } | This is a version of putProperty for Symbol keys . |
31,698 | public static Object callMethod ( Context cx , Scriptable obj , String methodName , Object [ ] args ) { Object funObj = getProperty ( obj , methodName ) ; if ( ! ( funObj instanceof Function ) ) { throw ScriptRuntime . notFunctionError ( obj , methodName ) ; } Function fun = ( Function ) funObj ; Scriptable scope = ScriptableObject . getTopLevelScope ( obj ) ; if ( cx != null ) { return fun . call ( cx , scope , obj , args ) ; } return Context . call ( null , fun , scope , obj , args ) ; } | Call a method of an object . |
31,699 | public final Object getAssociatedValue ( Object key ) { Map < Object , Object > h = associatedValues ; if ( h == null ) return null ; return h . get ( key ) ; } | Get arbitrary application - specific value associated with this object . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.