Recommended code changes based on code review

This is a series of changes following a detailed code review of the duktape API usage.

There are two sets of changes
 - Use of new APIs that have been added to duktape relatively recently
 - Memory lifetime including potential memory leaks
 - Improved (and more consistent) argument checking

Change-Id: I1743ee11aa7b40df3cc633a454d61551ab241929
Signed-off-by: Greg Burns <gburns@qce.qualcomm.com>