protected Scriptable createThreadScope ( Context cx , Scriptable protoScope ) { // Create the scope object Scriptable scope = cx . newObject ( protoScope ) ; scope . setPrototype ( protoScope ) ; scope . setParentScope ( null ) ; // Set "global" variable to point to global scope scope . put ( "global" , scope , scope ) ; //$NON-NLS-1$ // Evaluate PostCSS javascript postcssJsScript . exec ( cx , scope ) ; // Initialize the plugins array that we pass to PostCSS NativeArray plugins = ( NativeArray ) cx . newArray ( scope , 0 ) ; // Get reference to Array.prototype.push() so that we can add elements Function pushFn = ( Function ) plugins . getPrototype ( ) . get ( "push" , scope ) ; //$NON-NLS-1$ /* * Now load and initialize plugins */ for ( PluginInfo info : pluginInfoList ) { // Set up new scope for defining the module so that module.exports is not shared between plugins Scriptable defineScope = cx . newObject ( scope ) ; defineScope . setParentScope ( scope ) ; amdDefineShimScript . exec ( cx , defineScope ) ; Scriptable moduleVar = ( Scriptable ) defineScope . get ( MODULE , defineScope ) ; info . moduleScript . exec ( cx , defineScope ) ; // Retrieve the module reference and initialize the plugin Function module = ( Function ) moduleVar . get ( EXPORTS , moduleVar ) ; Scriptable plugin = ( Scriptable ) info . initializer . call ( cx , scope , scope , new Object [ ] { module } ) ; // Add the plugin to the array pushFn . call ( cx , scope , plugins , new Object [ ] { plugin } ) ; } // Create an instance of the PostCSS processor and save to a variable in thread scope Function postcss = ( Function ) scope . get ( POSTCSS , scope ) ; postcssOptions = ( Scriptable ) Context . javaToJS ( POSTCSS_OPTIONS , scope ) ; Scriptable postcssInstance = ( Scriptable ) postcss . call ( cx , scope , scope , new Object [ ] { plugins } ) ; scope . put ( POSTCSS_INSTANCE , scope , postcssInstance ) ; return scope ; }
Creates a thread scope for the PostCSS processor and it s plugins . Thread scopes allow PostCSS to process multiple CSS modules concurrently each executing in a separate thread without interfering with each other .