src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/JSObject.java

Print this page




  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.api.scripting;
  27 
  28 import java.util.Collection;
  29 import java.util.Set;
  30 
  31 /**
  32  * This interface can be implemented by an arbitrary Java class. Nashorn will
  33  * treat objects of such classes just like nashorn script objects. Usual nashorn
  34  * operations like obj[i], obj.foo, obj.func(), delete obj.foo will be glued
  35  * to appropriate method call of this interface.


  36  */

  37 public interface JSObject {
  38     /**
  39      * Call this object as a JavaScript function. This is equivalent to
  40      * 'func.apply(thiz, args)' in JavaScript.
  41      *
  42      * @param thiz 'this' object to be passed to the function
  43      * @param args arguments to method
  44      * @return result of call
  45      */
  46     public Object call(final Object thiz, final Object... args);
  47 
  48     /**
  49      * Call this 'constructor' JavaScript function to create a new object.
  50      * This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
  51      *
  52      * @param args arguments to method
  53      * @return result of constructor call
  54      */
  55     public Object newObject(final Object... args);
  56 




  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.api.scripting;
  27 
  28 import java.util.Collection;
  29 import java.util.Set;
  30 
  31 /**
  32  * This interface can be implemented by an arbitrary Java class. Nashorn will
  33  * treat objects of such classes just like nashorn script objects. Usual nashorn
  34  * operations like obj[i], obj.foo, obj.func(), delete obj.foo will be glued
  35  * to appropriate method call of this interface.
  36  *
  37  * @since 1.8u40
  38  */
  39 @jdk.Exported
  40 public interface JSObject {
  41     /**
  42      * Call this object as a JavaScript function. This is equivalent to
  43      * 'func.apply(thiz, args)' in JavaScript.
  44      *
  45      * @param thiz 'this' object to be passed to the function
  46      * @param args arguments to method
  47      * @return result of call
  48      */
  49     public Object call(final Object thiz, final Object... args);
  50 
  51     /**
  52      * Call this 'constructor' JavaScript function to create a new object.
  53      * This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
  54      *
  55      * @param args arguments to method
  56      * @return result of constructor call
  57      */
  58     public Object newObject(final Object... args);
  59