Monday, September 5, 2011

LiveConnect and JavaScript Wrappers

From the LiveConnect page on the Mozilla web site:

LiveConnect is the name of an application programming interface that provides JavaScript with the ability to call methods of Java classes and vice-versa using the existing Java infrastructure.

LiveConnect use by applets is enabled via the use of the "MAYSCRIPT" attribute in applet tags on an HTML page, following which the applet may refer to classes in the netscape.javascript package to access Javascript objects, and scripts may directly call applet methods (using the syntax

From the LiveConnect Overview page on the same site:

In JavaScript, a wrapper is an object of the target language data type that encloses an object of the source language. When programming in JavaScript, you can use a wrapper object to access methods and fields of the Java object; calling a method or accessing a property on the wrapper results in a call on the Java object. On the Java side, JavaScript objects are wrapped in an instance of the class netscape.javascript.JSObject and passed to Java.

When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type JSObject; when a JSObject is sent from Java to JavaScript, the runtime engine unwraps it to its original JavaScript object type. The JSObject class provides an interface for invoking JavaScript methods and examining JavaScript properties.

The LiveConnect page has a number of dead links, including one called "LiveConnect Testcases", which sounded interesting, and another called "Core JavaScript 1.5 Reference: LiveConnect". I found a current JavaScript Reference page, but I could find no reference to LiveConnect on the page.

No comments: