wiki.webvm.net/ webvm/ func/ Module loader

Introduction

This section defines the functionality of the module loader component of WebVM. This is a utility library to assist in the creation of JavaScript bindings for WebVM libraries as independent JavaScript modules, and to assist web applications load and manage those modules.

Note that the module loader is simply a utility library, and it is possible to access WebVM functionality without it. Developers that already have functionally equivalent libraries can elect not to use the WebVM module loader. However, the loader contains functionality that makes it easier to use WebVM functionality, and can also be used to mask certain browser-specific details in the use of WebVM that otherwise harm cross-browser interoperability of WebVM modules.

Scope

The WebVM module loader provides the following functionality:

Implementation namespace

The module loader uses webvm.* JavaScript globals.

Module identification/parameterisation

Modules are identified by their id which is a URI. There are no restrictions placed on the form of the URI by the WebVM module loader, but certain functionality is available for URIs that follow a particular form.

Module ids can describe an interface module (wherein the id is a reference to a module interface definition or specification) or an actual concrete module which MAY implement one or more interface modules. When asking the module loader to load a module by id, the caller can request a specific concrete module, or can request an interface module and leave it up to the system to determine the most appropriate concrete module implementing that interface.

The WebVM module loader allows different specific loaders to be registered to handle the loading of modules according to domain and a default loader used for all cases that are not overridden by loaders for specific domains.

The default loader assumes module ids of the form:

http[s]:///

where:

A module also has a version which is a string. The string can be of any form a€” the loader itself only tests for string equality between versions.

Module ids may be combined with parameters when loading modules (particularly if, for example, specifying additional parameters with an interface module request to help the system resolve the request to a concrete module satisfying certain properties). A parameter set is a set of name,value pairs where name and value are strings.

Module loading

The module load API is as follows:

webvm.load(name,version,params)

where:

The loader first determines whether or not a matching module has already been loaded, according to the following criteria:

If no currently loaded module matches, the default loader resolves the request to a CGI-encoded URI of the form:

name?version=&

The loader attempts to load the module by HTTP GET on this URI.

Support for API security

This section is a placeholder for specific functionality to be decided. It is desirable to provide some support for JavaScript API security so, for example, a web application can use a private API key for a specific web service, and pass that key to a WebVM library, without making that key vulnerable to interception by other scripts running in the same page.