Make Direct test scripts portable to various JavaScript implementations.

As of this branch (which includes #1293), test-script-* should pass in all three supported JDKs.