Hello,
obvious answer first: Don't modify ScriptNode.java to implement some use-case requirement. Work with it, e.g. by using it in Repository-tier JavaScript - and work around any subjectively felt limitation by using other Services / root scope objects.
The only place to change ScriptNode.java would be in a forked / checked out branch of the Alfresco SVN / Git in the projects/repository sub-tree, and then re-build the alfresco-repository.jar for that project. This then needs to replace the alfresco-repository.jar from the vanilla WAR.
THe above explains how it can be done. By no means do I encourage you to actually do this. As in my first answer, try to work around any limitations by adding your own code / script extensions to complement ScriptNode.
Regards
Axel