Compatibility layer

The library offers a common compatibility layer whatever the environment it runs on.

Standard object methods and statics

Array

Date

The Date constructor supports ISO 8601 format and instances offers:

Function

NOTE: Function.prototype.toString() does not include comments on Rhino.

Object

NOTES:

  • Object.assign fails with Chakra if one parameter is undefined
  • Object.keys doesn't behave the same way on primitive types depending on the host.

String

Console

The library defines (when not existing) console.log, console.warn and console.error.

NOTE: Only one string parameter is expected.

Promise

The library offers (when necessary) a Promise/A+ implementation based on promise-polyfill

Timeout

setInterval / clearInterval are not managed but can be easily simulated by chaining timeouts.

On some hosts, gpf.handleTimeout() must be used to activate timeouts.

JSON

NOTE: Some hosts have their own specificities in the way the reviver / replacer keys are transmitted. It is recommended to convert the keys to string to ensure maximum compatibility.

Base64 helpers

Strict mode

When functions are generated, strict mode is always assumed even if the host (such as Rhino or WScript) does not support it.

Known limitations

gpf.http.request

When it comes to supporting custom verbs, some hosts are not working properly:

  • PhantomJS does not even try to send the request.
  • On JAVA hosts (Nashorn and Rhino), the method is validated and refused.

Since most of the above hosts are not maintained, no further research was conducted.

If one is looking for a workaround, the custom http header X-HTTP-Method-Override seems to be an option.