Code requirements

To ensure safe and efficient use of the Platform, and to avoid errors in one plugin affecting another, there are a number of requirements which are placed on the server side JavaScript code.

These requirements are enforced partially by the JavaScript runtime and API, and partially by a review process.

The code examples in this documentation assume you are using a requirements.schema file which has readable names for the standard schema objects.

Enforced restrictions

Because all the plugins run in a single JavaScript environment, and to allow the Platform API to be continually improved, restrictions are placed on plugin JavaScript code.

  • Always refer to your plugin with the shortcut variable name of P
  • No state should be stored in variables or objects, because there may be multiple JavaScript runtimes active at any point
  • No globals
  • No modification of core library prototypes (generally enforced by JavaScript runtime)
  • No use of eval, Function or anything which evaluates JavaScript code. (Use JSON for parsing JSON.)
  • Do not include library code into the runtime global, always hide it so it’s private. Contact us to see if the library is suitable for inclusion as standard.
  • Use documented interfaces only.
  • Do not use or create any runtime global with a name beginning $, and do not access any property of any object which begins with $. These are part of the implementation, and may be changed at any time.
  • JavaScript must pass JSHint testing with the options below.

See also the style guide, which should be followed for all plugin code.

Performance

The Platform runs as a shared hosting environment. As such, code must run efficiently and not place an undue burden on the Platform or affect other customers. In particular:

  • Hook handlers should not noticeably slow down the main application.
  • Request handling must complete quickly, matching the speed of built in operations.
  • Plugins must not use excessive amounts of memory.

The Platform is not intended for performing large amounts of computation. If you are number crunching, you should offload the work to another server.

JSHint options

{
    asi: false,
    bitwise: false,
    boss: false,
    curly: true,
    debug: false,
    devel: false,
    eqeqeq: false,
    evil: false,
    forin: false,
    immed: false,
    laxbreak: false,
    newcap: true,
    noarg: true,
    noempty: false,
    nonew: true,
    nomen: false,
    onevar: false,
    plusplus: false,
    regexp: false,
    undef: true,
    sub: true,
    strict: false,
    white: false
}