nashorn/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js
changeset 16522 d643e3ee819c
parent 16205 93fda2507e35
child 16755 1db736812802
equal deleted inserted replaced
16346:5e8c55025644 16522:d643e3ee819c
     1 /*
     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * 
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
     8  * 
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    13  * accompanied this code).
    14  * 
    14  *
    15  * You should have received a copy of the GNU General Public License version
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  * 
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    32     configurable: true, enumerable: false, writable: true,
    32     configurable: true, enumerable: false, writable: true,
    33     value: function() {
    33     value: function() {
    34         if (arguments.length < 2) {
    34         if (arguments.length < 2) {
    35             throw new TypeError("JavaAdapter requires atleast two arguments");
    35             throw new TypeError("JavaAdapter requires atleast two arguments");
    36         }
    36         }
    37             
    37 
    38         var types = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    38         var types = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    39         var NewType = Java.extend.apply(Java, types);
    39         var NewType = Java.extend.apply(Java, types);
    40         return new NewType(arguments[arguments.length - 1]);
    40         return new NewType(arguments[arguments.length - 1]);
    41     }
    41     }
    42 });
    42 });
    54                     var type = Java.type(_packages[i] + "." + name);
    54                     var type = Java.type(_packages[i] + "." + name);
    55                     global[name] = type;
    55                     global[name] = type;
    56                     return type;
    56                     return type;
    57                 } catch (e) {}
    57                 } catch (e) {}
    58             }
    58             }
    59             
    59 
    60             return oldNoSuchProperty? oldNoSuchProperty(name) : undefined;
    60             return oldNoSuchProperty? oldNoSuchProperty(name) : undefined;
    61         }
    61         }
    62         
    62 
    63         var prefix = "[JavaPackage ";
    63         var prefix = "[JavaPackage ";
    64         return function() {
    64         return function() {
    65             for (var i in arguments) {
    65             for (var i in arguments) {
    66                 var pkgName = arguments[i];
    66                 var pkgName = arguments[i];
    67                 if ((typeof pkgName) != 'string') {
    67                 if ((typeof pkgName) != 'string') {
   341 // Rhino: global.importClass
   341 // Rhino: global.importClass
   342 Object.defineProperty(this, "importClass", {
   342 Object.defineProperty(this, "importClass", {
   343     configurable: true, enumerable: false, writable: true,
   343     configurable: true, enumerable: false, writable: true,
   344     value: function(clazz) {
   344     value: function(clazz) {
   345         if (Java.isType(clazz)) {
   345         if (Java.isType(clazz)) {
   346             this[clazz.class.getSimpleName()] = clazz;
   346             var className = Java.typeName(clazz);
       
   347             var simpleName = className.substring(className.lastIndexOf('.') + 1);
       
   348             this[simpleName] = clazz;
   347         } else {
   349         } else {
   348             throw new TypeError(clazz + " is not a Java class");
   350             throw new TypeError(clazz + " is not a Java class");
   349         }
   351         }
   350     }
   352     }
   351 });
   353 });