Fix "Illegal invocation” issue when in node-webkit

Native functions must be executed in the context of window.