Embedded JavaScript

GoAhead developed an embedded version of JavaScript.  Since JavaScript 1.2 is now quite a large language, its size prohibits its use in most embedded devices. GoAhead's embedded JavaScript is designed to solve this dilemma. It is a strict subset of JavaScript and implements the essential elements of the language. It also interfaces with Active Server Pages (ASP) to allow the easy creation of dynamic web pages.

When JavaScript is used inside an ASP web page it consists of a script within ASP delimiters. The basic format is:

<% function(arguments, ...); %>

JavaScript functions are created by the ejSetGlobalFunction. When the function is evaluated, the corresponding C procedure that implements the JavaScript function is called.

Embedded JavaScript implements the following JavaScript elements ( complete specification ):

The following language elements are not implemented.

JavaScript scripts can span multiple lines by using a "\" as the last character on the preceding line. When used in ASP pages, function arguments can contain any query variable defined in the URL query string or defined in either the standard variable set.  URL query strings are automatically decoded and JavaScript variables are defined to the decoded query value. For example, to parse the name and address encoded as a query string in a URL, use the following code:

http://localhost/mypage?name=smith&age=35

int myAspProcedure(webs_t wp, int argc, char_t **argv) {
    char_t *name = websGetVar(wp, "name", "undefined");
    char_t *age = websGetVar(wp, "age", "undefined");
    websWrite(wp, "Name %s, Age", args);
}

JavaScript procedures are registered by using the websAspDefine API. This publishes a C procedure as a JavaScript global function. For example:

extern int outputMyTable(int ejid, webs_t wp, int argc, char_t **argv);
websAspDefine("outputTable", outputMyTable);

The websAspDefine call publishes the JavaScript command "outputTable" and links it to the outputMyTable C procedure. When an ASP page is requested by the user's browser, any ASP JavaScript which uses the outputTablecommand will cause the outputMyTable to be called with the relevant arguments.

GoAhead embedded JavaScript is quite secure because it only grants access to only those C procedures for which you wish to provide access and you exploit the full power of C to implement control logic. Traditional scripting languages often expose security flaws because general purpose functions give unintended control over system or data functions.

See Also

Active Server Pages, GoForms™, websSecurityHandler, websUrlHandlerDefine