I made some refinements. I found that it wasn't so much the resolution, but the inches per pixel that matters. So This script keeps the pixel dimension the same and just changes the resolution to match the ppi, so no quality is lost in placing the new image. However, on line 27, the Math.max and Math.min are reversed. If you want it to fit within the confines of the existing SO, then you have to use Math.max. If you want it to fill the existing SO, then you have to use Math.min.
#target photoshop
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var soLayer = doc.activeLayer;
if (soLayer.kind == LayerKind.SMARTOBJECT){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var obj = executeActionGet(ref).getObjectValue(stringIDToTypeID("smartObjectMore"));
var soSize = obj.getObjectValue(stringIDToTypeID("size"));
var soWidth = soSize.getDouble(stringIDToTypeID("width"));
var soHeight = soSize.getDouble(stringIDToTypeID("height"));
var res = obj.getDouble(charIDToTypeID("Rslt"));
var scrDocFile = File.openDialog ('Select file to \nto replace Smart Object content','*.*',false);
var scrDoc = open(scrDocFile)
app.preferences.rulerUnits = Units.PIXELS;
scrWidth = scrDoc.width.value;
scrHeight = scrDoc.height.value;
var widthRatio = soWidth/scrWidth
var heightRatio = soHeight/scrHeight
var widthIn = soWidth/res
var heightIn = soHeight/res
app.activeDocument = scrDoc
var resUse = Math.max(scrWidth/widthIn,scrHeight/heightIn)
scrDoc.resizeImage (undefined, undefined, resUse, ResampleMethod.NONE )
scrDoc.saveAs (new File('~/desktop/tempSO.psd'))
var temp_SO = new File('~/desktop/tempSO.psd');
scrDoc.close(SaveOptions.DONOTSAVECHANGES);
replaceSO (temp_SO);
temp_SO.remove();
}
else{alert ('The current layer is not a Smart Object.')}
function replaceSO(file){
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc866 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc866.putPath( idnull, new File( file ) );
executeAction( idplacedLayerReplaceContents, desc866, DialogModes.NO );
}
function openSO(){
var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
var desc9 = new ActionDescriptor();
executeAction( idplacedLayerEditContents, desc9, DialogModes.NO );
}