Go to the first, previous, next, last section, table of contents.


NGS JavaScript Language

Language

Lexical Conventions

White Space

Comments

Reserved Words

Identifiers

Punctuators

Literals

Automatic Semicolon Insertion

Certain ECMAScript statements must be terminated with a semicolon. Such a semicolon may always appear explicitly in the source text. For pain of the compiler implementator, however, such semicolons may be omitted from the source text in certain situations. These situations are described in details in the ECMA-262 Version 2 draft 22-Apr-98 standard. Here is @email{mtr@ngs.fi}'s interpretation of the rules:

Insert semicolons as you would do in the C language. Now, you can omit them:

  1. before '}' character
  2. from the end of the line
  3. from the end of the file

The automatic semicolon insertion sets some restrictions how you can insert whitespace to you code. You can't insert line breaks:

  1. between LeftHandSideExpression and ++ or -- operator
  2. between return and the returned Expression

Function Definition

Statements

Block

Variable Statement

Empty Statement

The if Statement

The do...while Statement

The while Statement

The for Statement

The for...in Statement

The continue Statement

The break Statement

The return Statement

The with Statement

The syntax of the with-statement is:

with (expr) statement
with (Math)
  {
    result = sin (PI);
    result -= tan (45);
  }

The switch Statement

Labeled Statements

The throw Statement

The try Statement

Expressions

Primary Expressions

Left-Hand-Side Expressions

Postfix Expressions

Unary Operators

Multiplicative Operators

Additive Operators

Bitwise Shift Operators

Relational Operators

Equality Operators

Binary Bitwise Operators

Binary Logical Operators

Conditional Operator

Assignment Operators

Comma Operator

Global Methods and Properties

Standard
ECMA-262 Version 2 draft 22-Apr-98

Property: Global NaN
The not a number value.

Property: Global Infinity
The positive infinity value.

Function: eval (any)

Function: parseInt (string, radix)

Function: parseFloat (string)

Function: escape (string)

Function: unescape (string)

Function: isNaN (any)

Function: isFinite (any)

Function: debug (any)

Standard
Netscape JavaScript Reference 12-Dec-97

Function: print (any[,...])

Standard
Netscape JavaScript Reference 12-Dec-97 ???

Function: error (message)

Standard
Netscape JavaScript Reference 12-Dec-97 ???

Function: float (any)

Standard
NGS JavaScript Interpreter 0.2.4

Function: int (any)

Standard
NGS JavaScript Interpreter 0.2.4

Function: isFloat (any)

Standard
NGS JavaScript Interpreter 0.2.4

Function: isInt (any)

Standard
NGS JavaScript Interpreter 0.2.4

Function: load (file...)

Standard
NGS JavaScript Interpreter 0.2.4

Function: loadClass (class_spec...)

Standard
NGS JavaScript Interpreter 0.2.4

Extend interpreter by calling an initialization function from shared library class_spec. The argument class_spec can be given in the following formats:

library:function
The argument library specifies the shared library from which function function is called. The library specification can be given in absolute or relative formats.
library
The argument library specifies both the shared library, and the name of the entry function. The name of the entry function is the name of the library, without the possible leading directory path and any suffixes.
loadClass ("libexts.so:init_all");
=> call function init_all from library `libexts.so'

loadClass ("/usr/local/lib/libexts.so:init_all");
=> call function init_all from library `/usr/local/lib/libexts.so'

loadClass ("/usr/local/lib/libdbexts.so");
=> call function dbexts from library `/usr/local/lib/libexts.so'

The initialization function must be a void function that takes one argument that is a pointer to the interpreter.

void
entry (JSInterpPtr interp)
{
  Initialize extensions using normal `js.h' and `jsint.h'
  interfaces.
}

Function: callMethod (object, method, arguments)

Standard
NGS JavaScript Interpreter 0.2.4

Call method method from object object with arguments arguments.

callMethod (System.stdout, "writeln", ["Hello, world!"]);
-| Hello, world!

Native Objects

Array

Standard
ECMA-262 Version 2 draft 22-Apr-98
Incompatibilities

Function: Array (count)
Function: Array (item...)
Do exactly the same as the expression new Array() called with the same arguments.

Constructor: Array (count)
Constructor: Array (item...)

Create a new array object. The first form creates a new array which length is count. All items are set to value `undefined'. The second form creates an array that contains the given items as its values.

var a = new Array (5);
a.length;
=> 5
a.toString ();
=> undefined,undefined,undefined,undefined,undefined

a = new Array (1, 2, "hello");
a.length;
=> 3
a.toString ();
=> 1,2,hello

Method: Array concat (array[, ...])
Create a new array object from the items of the called array object and the argument arrays array, .... The contents of the argument arrays are not modified.

var a = new Array (1, 2, 3);
var b = a.concat (new Array (4, 5));
b.length;
=> 5;
b.toString ();
=> 1,2,3,4,5

Method: Array join ([glue])
Convert the array to a string. Individual items of the array are combined with the string glue. If the argument glue is omitted, string "," is used.

var a = new Array (1, 2, "three");
a.join ();
=> "1,2,three"

a.join ("-");
=> "1-2-three"

Method: Array pop ()
Remove the last item of the array. The method returns the item removed. If the array is empty, value undefined is returned.

a = new Array (1, 2, 3);
a.pop ();
=> 3
a.length;
=> 2

Method: Array push (any...)
Insert items to the end of the array. The method returns the last item pushed.

a = new Array (1, 2);
a.push (7);
=> 7
a.push (7, 8, 9);
=> 9
System.print (a.join (", "), "\n");
-| 1, 2, 7, 7, 8, 9

Method: Array reverse ()
Reverse the array.

a = new Array (1, 2, 3);
a.reverse ();
System.print (a.join (""), "\n");
-| 321

Method: Array shift ()
Remove item from the beginning of the array. The method returns the item removed, or value `undefined' if the array was empty.

a = new Array (1, 2, 3);
a.shift ();
=> 1

Method: Array slice (start[, end])
Return a new array containing items between start (inclusively) and end (exclusively) in the array. If the argument end is negative, it is counted from the end of the array. If the argument end is omitted, the method extract items from the position start to the end of the array.

a = new Array (1, 2, 3, 4, 5);
b = a.slice (1, 4);
System.print (b.join (", "), "\n");
-| 2, 3, 4
b = a.slice (1, -2);
System.print (b.join (", "), "\n");
-| 2, 3
b = a.slice (2);
System.print (b.join (", "), "\n");
-| 3, 4, 5

Method: Array splice (index, remove[, any...])
Modify array by removing old items and by inserting new ones. The argument index specifies the index from which the array is modified. The argument remove specifies how many old items are removed. If the argument remove is 0, no old items are removed and at least one new item must have been given. After the items are removed, all remaining arguments are inserted after the position index.

var a = new Array (1, 2, 3);
a.splice (1, 1);
=> 1, 3
a.splice (1, 0, "new item");
=> 1, "new item", 2, 3

var a = new Array (1, 2, 3, 4);
a.splice (1, 2, "new item");
=> 1, "new item", 4

Method: Array sort ([sort_function])
Sort the array to the order specified by the argument function sort_function. The comparison function sort_function takes two arguments and it must return one of the following codes:

-1
the first argument items is smaller than the second item (must come before the second item)
0
the items are equal
1
the first argument item is bigger than the second item (it must come after the second item)

If the argument sort_function is omitted, the items are sorted to an alphabetical (lexicographical) order.

a = new Array ("Jukka-Pekka", "Jukka", "Kari", "Markku");
a.sort ();
System.print (a, "\n");
-| Jukka,Jukka-Pekka,Kari,Markku
a = new Array (1, 2, 10, 20, 100, 200);
a.sort ();
System.stdout.writeln (a.toString ());
-| 1,10,100,2,20,200

The sort method is stable in that sense that, if the comparison function returns 0 for two items, their original order in the array is preserved. For example, if a list of person objects is sorted first by their names, and second by their ages, all persons with the same age will remain sorted in an alphabetical order.

function by_age (a, b)
{
  return a.age - b.age;
}

function by_name (a, b)
{
  if (a.name < b.name)
    return -1;
  if (a.name > b.name)
    return 1;
  return 0;
}

function Person (name, age)
{
  this.name = name;
  this.age = age;
}

a = new Array (new Person ("Smith", 30),
               new Person ("Jones", 31),
               new Person ("Bob", 30),
               new Person ("Chris", 29));

a.sort (by_name);
a.sort (by_age);

for (i in a)
  System.print (i.name, ", ", i.age, "\n");
-| Chris, 29
-| Bob, 30
-| Smith, 30
-| Jones, 31

Method: Array toSource ()

Method: Array toString ()
Convert the array to a string. The method converts each item of the array to string and combines them with the string ",".

var a = new Array (1, "foo", 2, new Array (7, 8));
a.toString ();
=> 1,foo,2,7,8

Method: Array unshift (any...)
Insert items any... to the beginning of the array. The method returns the new length of the array.

a = new Array (1, 2, 3);
System.print (a.unshift (7, 8, 9), "\n");
-| 6

Property: Array length
The length of the array.

var a = new Array (1, 2);
a.length;
=> 2
a.push (3, 4, 5);
a.length;
=> 5

Boolean

Standard
ECMA-262 Version 2 draft 22-Apr-98
Incompatibilities

Function: Boolean()
Return false.

Function: Boolean(value)

Constructor: Boolean ()
Constructor: Boolean (value)
Create a new boolean object. If no arguments are given, the returned object will have value `false'. If the argument value is given, the initial value of the object is determined by the type of the argument and its value. If the argument value is undefined, null, false, "" (an empty string), or 0, the value of the object will be `false'. All other values for the argument value will set the initial value of the object to `true'.

Method: Boolean toString ()
Return a string presentation of the boolean object. The method will return string "true" or "false" according to the value of the object.

Method: Boolean valueOf ()

Date

Standard
ECMA-262 Version 2 draft 22-Apr-98
Incompatibilities
XXX Check all methods and properties.

Constructor: Date ()
Constructor: Date ("month day, year hours:minutes:seconds")
Constructor: Date (yr_num, mo_num, day_num)
Constructor: Date (yr_num, mo_num, day_num, hr_num, min_num, sec_num)

Static Method: Date UTC (year, month, day, hrs, min, sec)

Method: Date format (format)

Method: Date formatGMT (format)

Method: Date getDate ()

Method: Date getDay ()

Method: Date getHours ()

Method: Date getMinutes ()

Method: Date getMonth ()

Method: Date getSeconds ()

Method: Date getTime ()

Method: Date getTimezoneOffset ()

Method: Date getYear ()

Method: Date parse (string)

Method: Date setDate (day)

Method: Date setHours (hours)

Method: Date setMinutes (minutes)

Method: Date setMonths (months)

Method: Date setSeconds (seconds)

Method: Date setTime (time)

Method: Date setYear (year)

Method: Date toGMTString ()

Method: Date toLocaleString ()

File

Standard
Netscape JavaScript Reference 12-Dec-97
Incompatibilities
XXX Check all methods and properties.

Constructor: File (path)

Static Method: File byteToString (byte)

Static Method: File chmod (path, mode)

Standard
NGS JavaScript Interpreter 0.2.4

Change permissions of file path to mode. The modes are specifeid by or'ing the following values:

04000
set user ID on execution
02000
set group ID on execution
01000
sticky bit
00400
read by owner
00200
write by owner
00100
execute / search by owner
00040
read by group
00020
write by group
00010
execute / search by group
00004
read by others
00002
write by others
00001
execute / search by others

Static Method: File lstat (path)

Standard
NGS JavaScript Interpreter 0.2.4

Static Method: File remove (path)

Standard
NGS JavaScript Interpreter 0.2.4

Static Method: File rename (path)

Standard
NGS JavaScript Interpreter 0.2.4

Static Method: File stat (path)

Standard
NGS JavaScript Interpreter 0.2.4

Return statistics about the file file. The method returns a 13 element array containing the statistics, or `false' if the file couldn't be inspected.

The returned array contains the following items:

dev
Device that contains a directory entry for this file.
ino
Index of this file on its device. A file is uniquely identified by specifying its dev and ino.
mode
The mode of the file.
nlink
The number of hard links to the file.
uid
The ID of the file owner.
gid
The ID of the file group.
rdev
The ID of the device.
size
The size of the file.
atime
The time when the data was last accessed.
mtime
The time when the data was last modified.
ctime
The time when the file status was last changed.
blksize
Preferred blocksize for file system I/O.
blocks
The number of blocks the file actually uses.
fields = new Array ("dev", "ino", "mode", "nlink", "uid",
                    "gid", "rdev", "size", "atime",
                    "mtime", "ctime", "blksize", "blocks");

var a = File.stat ("js");
if (a)
  {
    var i;
    for (i = 0; i < a.length; i++)
      System.print (fields[i], "=", a[i], " ");
    System.print ("\n");
  }

-| dev=655368 ino=370741 mode=33261 nlink=1 uid=201 gid=200
-| rdev=2979328 size=731370 atime=893159080 mtime=893158537
-| ctime=893158537 blksize=4096 blocks=1432

Static Method: File stringToByte (string)

Method: File open (mode)

The argument mode must have one of the following values:

r[b]
w[b]
a[b]
r+[b]
w+[b]
a+[b]

Method: File close ()

Method: File setPosition (position[, whence])

Method: File getPosition ()

Method: File eof ()

Method: File read (size)

Method: File readln ()

Method: File readByte ()

Method: File toString ()

Method: File write (string)

Method: File writeln (string)

Method: File writeByte (byte)

Method: File ungetByte (byte)

Standard
NGS JavaScript Interpreter 0.2.4

Method: File flush ()

Method: File getLength ()

Method: File exists ()

Method: File error ()

Method: File clearError ()

Property: File autoFlush

Standard
NGS JavaScript Interpreter 0.2.4

Flag that specifies whether the stream should automatically flush its buffers after a write.

Property: File bufferSize

Standard
NGS JavaScript Interpreter 0.2.4

The I/O buffer size of the stream. The buffer size can be changed at the runtime.

Directory

Standard
NGS JavaScript Interpreter 0.2.4

Constructor: Directory (path)

Method: Directory close ()

Method: Directory open ()

Method: Directory read ()

Method: Directory rewind ()

Method: Directory seek (pos)

Method: Directory tell ()

Function

Math

Standard
ECMA-262 Version 2 draft 22-Apr-98

Static Method: Math abs (x)

Static Method: Math acos (x)

Static Method: Math asin (x)

Static Method: Math atan (x)

Static Method: Math atan2 (y, x)

Static Method: Math ceil (x)

Static Method: Math cos (x)

Static Method: Math exp (x)

Static Method: Math floor (x)

Static Method: Math log (x)

Static Method: Math max (x, y)

Static Method: Math min (x, y)

Static Method: Math pow (x, y)

Static Method: Math random ()

Static Method: Math round (x)

Static Method: Math seed (x)

Standard
NGS JavaScript Interpreter 0.2.4

Static Method: Math sin (x)

Static Method: Math sqrt (x)

Static Method: Math tan (x)

Static Property: Math E

Static Property: Math LN10

Static Property: Math LN2

Static Property: Math LOG10E

Static Property: Math LOG2E

Static Property: Math PI

Static Property: Math SQRT1_2

Static Property: Math SQRT2

Number

Standard
ECMA-262 Version 2 draft 22-Apr-98

Function: Number()
Return value 0.

Function: Number (value)

Constructor: Number ()
Constructor: Number (value)
Create a new number object. If no argument is given, the constructor returns value +0. If the argument value is given, the constructor returns ToNumber(value).

new Number ();
=> 0
new Number (3.1415);
=> 3.1415
new Number (true);
=> 1

Method: Number toString ([radix])
Convert the number to its textual presentation. If the argument radix is given, it specifies the radix to which the number is formatted. If the argument radix is not given, it defaults to 10.

System.stdout.writeln ((193).toString ());
-| 193
System.stdout.writeln ((193).toString (8));
-| 301
System.stdout.writeln ((193).toString (16));
-| c1
System.stdout.writeln ((193).toString (2));
-| 11000001

Method: Number valueOf ()
Return the value of the number object.

Static Property: Number MAX_VALUE

Static Property: Number MIN_VALUE

Static Property: Number NaN

Static Property: Number NEGATIVE_INFINITY

Static Property: Number POSITIVE_INFINITY

Object

Standard
ECMA-262 Version 2 draft 22-Apr-98
Incompatibilities

Function: Object ([value])

Constructor: Object ([value])
Create a new object.

var o = new Object ();

Method: Object toString ()

Method: Object toSource ()

Method: Object valueOf ()

RegExp

Standard
ECMA-262 Version 2 draft 22-Apr-98
Incompatibilities

Constructor: RegExp (pattern[, flags])

Create a new regular expression from string pattern. The optional argument string flags can contain the following options:

i
Ignore case; the matching is case-insensitive.
g
Global search. This allows you to iterate over all matches of the expression by executing the exec method multiple times against the string.

Method: RegExp compile (pattern[, flags])
Create a new regular expression from string pattern using optional options flags. The method can be used to change the regular expression pattern or its flags in the regular expression object. The method returns an error if the string pattern do not specify a well-formed regular expression.

Note! All regular expressions are always compiled in this implementation. This holds also for the expressions, created with the RegExp() constructor.

var re = new RegExp ("ab*");
re.compile ("ab*", "i");

Method: RegExp exec ([string])
Match the expression against the string string. If the argument string is omitted, the regular expression is matched against the RegExp.input string. The method returns an array that holds the matched portions of the expression.

var re = new RegExp ("d(b+)(d)", "ig");
var a = re.exec ("cdbBdbsbz");
a.toString ();
=> "dbBd,bB,d"

In the previous example, the result array `a' has the following items:

dbBd
The substring that matched the regular expression. This string can also be retrieved as `RegExp.lastMatch'.
bB
The matched substring for the first parenthesized subexpression `(b+)'. This match can also be found as `RegExp.$1'.
d
The matched substring for the second parentsized subexpression `(d)'. This match can also be found as `RegExp.$2'.

The option `g' of the regular expression can be used to iterate over multiple matches of the expression on at a time. For example, the following code fragment searches for the expression `a(b*)' from the string `str'. In the inial state -- when the expression is create with the constructor -- the object's `lastIndex' property is set to 0. When the expression is matched against the string, the `lastIndex' property is updated to point to the next index from which the matching should be continued. Therefore, the following example iterates over all matches in the string `str'.

var re = new RegExp ("a(b*)", "g");
var str = "abbcdefabh";
while (a = re.exec (str))
  System.print ("Found ", a, ". Next match starts at ", re.lastIndex,
		    ".\n");
-| Found abb. Next match starts at 3.
-| Found ab. Next match starts at 9.

The property `regexp.lastIndex' can also be set explicitly to start the matching from a pre-defined position.

Method: RegExp test ([string])
Test whether the regular expression matches for the string string. If the argument string is omitted, the regular expression is tested against the RegExp.input string.

var re = new RegExp ("fo*bar");
re.test ("fbar");
=> true
re.test ("fooBar");
=> false

re = new RegExp ("fo*bar", "i");
re.test ("FOObAR");
=> true

RegExp.input = "#include <stdio.h>";
re = new RegExp ("^#");
re.test ();
=> true

Static Property: RegExp $1
Static Property: RegExp $2
Static Property: RegExp $3
Static Property: RegExp $4
Static Property: RegExp $5
Static Property: RegExp $6
Static Property: RegExp $7
Static Property: RegExp $8
Static Property: RegExp $9
The matching substring for the n:th parenthesized subexpression. If the latest regular expression didn't have that many parenthesized subexpressions, the property has value `undefined'.

Static Property: RegExp $_
Static Property: RegExp input
The string against which the expression was tested. The `input' property is also used, if no string argument was given for the `test()' or `exec()' methods.

var str = file.readln ();
re.test (str);
RegExp.input;
=> The string returned by the `file.readln()' method.

Static Property: RegExp lastMatch
The substring that matched the whole expression in the last regular expression matching.

Static Property: RegExp lastParen
The last parenthesized subexpression of the last regular expression matching.

Static Property: RegExp leftContext
The substring from the beginning of the input string to the beginning of the matching substring of the last regular expression.

var re = new RegExp ("foo");
var str = "garbage foo tail garbage";
re.exec (str);
RegExp.leftContext;
=> "garbage "

Static Property: RegExp multiline

Static Property: RegExp rightContext
The substring from the end of the matching substring to the end the input string.

var re = new RegExp ("foo");
var str = "garbage foo tail garbage";
re.exec (str);
RegExp.rightContext;
=> " tail garbage"

Property: RegExp global
Flag that tells if the option `g' was given for the constructor or for the compile method.

Property: RegExp ignoreCase
Flat that tells if the option `i' was given for the construtor or for the compile method.

Property: RegExp lastIndex
The index from which the matching is continued with the global (`g') expressions.

Property: RegExp source
The source string from which the regular expression object was created.

String

Standard
ECMA-262 Version 2 draft 22-Apr-98
Incompatibilities

Constructor: String (string)
Create a new string object and set its data to string.

var str = new String ("Hello, world");
=> "Hello, world!"

Static Method: String fromCharCode (code...)
Create a new string object from the character codes code....

var str = String.fromCharCode (72, 101, 108, 108, 111, 33);
=> "Hello!"

Static Method: String pack (format, arg[, ...])

Standard
NGS JavaScript Interpreter 0.2.4

Create a new string by packing values arg... to a string according to the format string format.

The format is a sequence of characters that specify the type of values as follows:

C
an unsigned char value
n
a short in "network" (big-endian) order
N
a long in "network" (big-endian) order
d
a double-precision float in the native format

Method: String append (string)

Standard
NGS JavaScript Interpreter 0.2.4

Append string string to the end of the string object. The string object must be a dynamic string, not a constant string literal.

var str = new String ("");
str.append ("foo");
str.append ("-");
str.append ("bar");
=> "foo-bar"

Method: String charAt (position)
Create a new string that constains the character from position position of the the string object.

"foobar".charAt (3);
=> "b"

Method: String charCodeAt (position)
Return the code of the character at position position in the string object.

"foobar".charCodeAt (3);
=> 98

Method: String concat (string[, ...])
Create a new string by appending the argument strings string, ... to the end of the string object.

"foo".concat ("bar");
=> "foobar"

Method: String crc32 ()

Standard
NGS JavaScript Interpreter 0.2.4

Count a 32-bit CRC of the string.

var str = "Hello, world!";
System.print ("CRC32 of \"", str, "\" is ",
              str.crc32 ().toString (16), ".\n");
-| CRC32 of "Hello, world!" is e4928064.

Method: String indexOf (string[, start_index])
Return the index of the first substring of string within the string object, or -1 if the string didn't contain the substring. The optional argument start_index can be used to specify the index from which the searching is started.

var str = "foobar foo bar foo";
str.indexOf ("foo");
=> 0
str.indexOf (" foo");
=> 6
str.indexOf ("foo", 1);
=> 7
str.indexOf ("Foo");
=> -1

Method: String lastIndexOf (string[, start_index])
Return the the index of the last substring of string within the string object, or -1 if the string didn't contain the substring. The optional argument start_index can be used to specify the index from which the searching is started.

var str = "foobar foo bar foo";
str.lastIndexOf ("foo");
=> 15
str.lastIndexOf ("bar");
=> 11
str.lastIndexOf ("foo", 14);
=> 7
str.lastIndexOf ("Foo");
=> -1

Method: String match (regexp)

Method: String replace (regexp, substitution)

Method: String search (regexp)

Method: String slice (start[, end])

Method: String split (separtor[, limit])

Method: String substr (start[, length])

Method: String substring (start[, end])

Method: String toLowerCase ()
Create a new string which contents is the data of the string object, converted to the lower case.

"FoObAr".toLowerCase ();
=> "foobar"

Method: String toUpperCase ()
Create a new string which contents is the data of the string object, converted to the upper case.

"FoObAr".toUpperCase ();
=> "FOOBAR"

Method: String unpack (format)

Standard
NGS JavaScript Interpreter 0.2.4

Property: String length
The length of the string.

"foobar".length;
=> 6
var str = new String ("foo");
str.append ("bar");
str.length;
=> 6

System

Standard
NGS JavaScript Interpreter 0.2.4

Static Method: System chdir (directory)
Change the process' current working directory to directory. The function returns a boolean success status.

Static Method: System error (any[, ...])
Convert arguments any... to string and print the resulting string to the standard error stream of the system.

Static Method: System exit (code)
Terminate the program execution and return the value code to the operating system as the return value of the running program. Effectively the method performs C-code `exit (code)'.

Static Method: System getcwd ()
Get the current working directory of the process. The function returns a strings presenting the directory or false if errors were encountered.

Static Method: System getenv (variable)
Return the value of the environment variable variable. The method returns the value as a string or `undefined' if the variable was not defined in the environment.

Static Method: System popen (command, mode)

Static Method: System print (any[, ...])
Convert arguments any... to string and print the resulting string to the standard output stream of the system.

Static Method: System sleep (seconds)
Stop the interpreter for seconds seconds.

Static Method: System strerror (errno)
Return a string that describes the system error code errno.

Static Method: System system (command)

Static Method: System usleep (micro_seconds)
Stop the interpreter for micro_seconds micro seconds.

Static Property: System bits
Return a value that describes the "bitness" of the underlying system. Possible values might be `16', `32', `64', or even `128'. Normally this is the size of a host system pointer in bits.

Static Property: System canonicalHost
The canonical host name of the system where the interpreter was compiled.

System.stdout.writeln (System.canonicalHost);
-| powerpc-ibm-aix4.2.1.0

Static Property: System canonicalHostCPU
The CPU part of the canonical host name.

System.stdout.writeln (System.canonicalHostCPU);
-| powerpc

Static Property: System canonicalHostVendor
The Vendor part of the canonical host name.

System.stdout.writeln (System.canonicalHostVendor);
-| ibm

Static Property: System canonicalHostOS
The OS part of the canonical host name.

System.stdout.writeln (System.canonicalHostOS);
-| aix4.2.1.0

Static Property: System errno
The system's error number. The error number can be converted to a string with the strerror() method of the System object.

var fp = new File ("output.txt");
if (!fp.open ("w"))
  System.error ("couldn't create output file `", fp, "': ",
                System.strerror (System.errno), "\n");
-| couldn't create output file `output.txt': Permission denied

Static Property: System lineBreakSequence
The line break sequence that is used in the underlying system. For example, the outputs from the following lines are identical:

System.stdout.writeln ("Hello!");
-| Hello!
System.stdout.write ("Hello!" + System.lineBreakSequence);
-| Hello!

Static Property: System stderr
The system's standard error stream. This is a normal JavaScript file and all methods of the File object can be called for it.

System.stderr.writeln ("panic: must exit");
System.exit (1);
-| panic: must exit

Static Property: System stdin
The system's standard input stream.

Static Property: System stdout
The system's standard output stream.

VM

Standard
NGS JavaScript Interpreter 0.2.4

Static Method: VM garbageCollect ()
Perform a garbage collection for the virtual machine heap. Normally, the garbage collection is triggered automatically, but the garbageCollect() method can be used to trigger the collection explicitly.

Static Method: VM stackTrace ([limit])
Print the contents of the virtual machine stack. Optional argument limit specifies how many stack frames are printed. If no arguments are given, the whole virtual machine stack is printed.

function recursive (n)
{
  if (n > 5)
    VM.stackTrace ();
  else
    recursive (n + 1);
}

recursive (0);
-|VM: stacktrace: stacksize=2048, used=78
-|#0   recursive(): builtin 0
-|#1   recursive(): null 1 6
-|#2   recursive(): null 1 5
-|#3   recursive(): null 1 4
-|#4   recursive(): null 1 3
-|#5   recursive(): null 1 2
-|#6   recursive(): null 1 1
-|#7   .global(): null 1 0

Static Property: VM dispatchMethod
The name of the dispatch method, currently used in the virtual machine. The method returns a string that describes the method. The possible return values are `switch-basic', `switch', and `jumps'.

Static Property: VM gcCount
How many times the garbage collection has been performed for the heap.

Static Property: VM gcTrigger
The garbage collection trigger. When the virtual machine heap has allocated more than gcTrigger number of bytes of memory, the virtual machine will perform a garbage collection.

Static Property: VM heapAllocated
The number of bytes of memory the system has allocated from the heap.

Static Property: VM heapFree
The number of bytes of memory the heap freelist contains.

Static Property: VM heapSize
The size of the heap in bytes.

Static Property: VM numConstants
The number of constants defined in the virtual machine.

Static Property: VM numGlobals
The number of global symbols defined in the virtual machine. This value equals to the number of global variables and functions, defined in the system.

Static Property: VM stackSize
The size of the virtual machine stack.

Static Property: VM stacktraceOnError
A boolean flag that tells whether the virtual machine stack trace is printed if an error occurs in the program execution.

Static Property: VM verbose
The verbosity level of the virtual machine.

Static Property: VM verboseStacktrace
A boolean flag that tells whether the virtual machine prints the normal or verbose stacktrace.

Static Property: VM version
The version string of the interpreter virtual machine.

Static Property: VM versionMajor
The major version number of the virtual machine.

Static Property: VM versionMinor
The minor version number of the virtual machine.

Static Property: VM versionPatch
The patch level number of the virtual machine.

Static Property: VM warnUndef
A boolean flag that tells whether the virtual machine should print a warning message if an undefined variable is used.

Extensions

Curses

JS

Constructor: JS ()

Method: JS compile (file, asm_file, bc_file)

Method: JS eval (string)

Method: JS evalFile (filename)

Method: JS evalJavaScriptFile (filename)

Method: JS executeByteCodeFile (filename)

Method: JS getVar (name)

Method: JS setVar (name, value)

Property: JS errorMessage

MD5

Constructor: MD5 ()
Create a new MD5 message digest object.

var md5 = new MD5 ();

Method: MD5 final ()
Return the MD5 value of the data, set to the object with the update() method. The method returns a 32 bytes long string that holds the MD5 value as a hexadecimal number.

function print_md5 (str)
{
  var md5 = new MD5 ();
  md5.update (str);
  System.print ("MD5 of \"", str, "\" is ",
                md5.final (), ".\n");
}
print_md5 ("Hello, world!");
-| MD5 of "Hello, world!" is 6CD3556DEB0DA54BCA060B4C39479839.

Method: MD5 finalBinary ()
Return the MD5 value of the data. The method returns a 128 bits long MD5 value.

Method: MD5 init ()
Initalize the object to the initial state. The method can be used to reset the object after some data has been set to it with the update() method.

Method: MD5 update (str)
Append data to the object. The method can be called multiple times, so that the MD5 message digest can be counted one block at a time.

function count_md5_for_file (stream)
{
  var md5 = new MD5 ();

  while (!stream.eof ())
    {
      var data = stream.read (1024);
      md5.update (data);
    }

  return md5.final ();
}


Go to the first, previous, next, last section, table of contents.