static void loadFromIterable ( Context cx , Scriptable scope , ScriptableObject map , Object arg1 ) { if ( ( arg1 == null ) || Undefined . instance . equals ( arg1 ) ) { return ; } // Call the "[Symbol.iterator]" property as a function. final Object ito = ScriptRuntime . callIterator ( arg1 , cx , scope ) ; if ( Undefined . instance . equals ( ito ) ) { // Per spec, ignore if the iterator is undefined return ; } // Find the "add" function of our own prototype, since it might have // been replaced. Since we're not fully constructed yet, create a dummy instance // so that we can get our own prototype. ScriptableObject dummy = ensureScriptableObject ( cx . newObject ( scope , map . getClassName ( ) ) ) ; final Callable set = ScriptRuntime . getPropFunctionAndThis ( dummy . getPrototype ( ) , "set" , cx , scope ) ; ScriptRuntime . lastStoredScriptable ( cx ) ; // Finally, run through all the iterated values and add them! try ( IteratorLikeIterable it = new IteratorLikeIterable ( cx , scope , ito ) ) { for ( Object val : it ) { Scriptable sVal = ScriptableObject . ensureScriptable ( val ) ; if ( sVal instanceof Symbol ) { throw ScriptRuntime . typeError1 ( "msg.arg.not.object" , ScriptRuntime . typeof ( sVal ) ) ; } Object finalKey = sVal . get ( 0 , sVal ) ; if ( finalKey == NOT_FOUND ) { finalKey = Undefined . instance ; } Object finalVal = sVal . get ( 1 , sVal ) ; if ( finalVal == NOT_FOUND ) { finalVal = Undefined . instance ; } set . call ( cx , scope , map , new Object [ ] { finalKey , finalVal } ) ; } } }
If an iterable object was passed to the constructor there are many many things to do ... Make this static because NativeWeakMap has the exact same requirement .