jlaskey@3: /*
jlaskey@7: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962: *
jlaskey@3: * This code is free software; you can redistribute it and/or modify it
jlaskey@3: * under the terms of the GNU General Public License version 2 only, as
jlaskey@3: * published by the Free Software Foundation.
attila@962: *
jlaskey@3: * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3: * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3: * accompanied this code).
attila@962: *
jlaskey@3: * You should have received a copy of the GNU General Public License version
jlaskey@3: * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962: *
jlaskey@3: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3: * or visit www.oracle.com if you need additional information or have any
jlaskey@3: * questions.
jlaskey@3: */
jlaskey@3:
jlaskey@3: /**
jlaskey@3: * NASHORN-478 : Provide mozilla compatibility script for nashorn
jlaskey@3: *
jlaskey@3: * @test
jlaskey@3: * @run
jlaskey@3: */
jlaskey@3:
jlaskey@3: // compatibility script is loaded using "nashorn:" pseudo URL scheme
jlaskey@3: try {
jlaskey@3: load('nashorn:mozilla_compat.js');
jlaskey@3: } catch(e) {
jlaskey@3: }
jlaskey@3:
jlaskey@3: var obj = {};
jlaskey@3: if (obj.__proto__ !== Object.prototype) {
jlaskey@3: fail("#1 obj.__proto__ read not supported");
jlaskey@3: }
jlaskey@3:
jlaskey@3: function fooGetter() { return 3.14; }
jlaskey@3: function fooSetter(x) {}
jlaskey@3:
jlaskey@3: Object.defineProperty(obj, "foo", { set: fooSetter, get: fooGetter });
jlaskey@3: if (!obj.__lookupGetter__ || obj.__lookupGetter__('foo') !== fooGetter) {
jlaskey@3: fail("#2 Object.prototype.__lookupGetter__ not supported");
jlaskey@3: }
jlaskey@3:
jlaskey@3: if (!obj.__lookupSetter__ || obj.__lookupSetter__('foo') !== fooSetter) {
jlaskey@3: fail("#3 Object.prototype.__lookupSetter__ not supported");
jlaskey@3: }
jlaskey@3:
jlaskey@3: function barGetter() { return 42; }
jlaskey@3:
jlaskey@3: if (obj.__defineGetter__) {
jlaskey@3: obj.__defineGetter__("bar", barGetter);
jlaskey@3: }
jlaskey@3:
jlaskey@3: if (obj.bar !== 42) {
jlaskey@3: fail("#4 Object.prototype.__defineGetter__ not supported");
jlaskey@3: }
jlaskey@3:
jlaskey@3: var barSetterCalled = false;
jlaskey@3: function barSetter(x) {
jlaskey@3: barSetterCalled = true;
jlaskey@3: }
jlaskey@3:
jlaskey@3: if (obj.__defineSetter__) {
jlaskey@3: obj.__defineSetter__("bar", barSetter);
jlaskey@3: }
jlaskey@3:
jlaskey@3: obj.bar = 'hello';
jlaskey@3: if (! barSetterCalled) {
jlaskey@3: fail("#5 Object.prototype.__defineSetter__ not supported");
jlaskey@3: }
jlaskey@3:
jlaskey@3: var obj = { bar: 343, foo : new Boolean(true) };
jlaskey@3: obj.self = obj;
jlaskey@3: if (!obj.toSource ||
jlaskey@3: obj.toSource() !== '({bar:343, foo:(new Boolean(true)), self:{}})') {
jlaskey@3: fail("#6 Object.prototype.toSource method failed");
jlaskey@3: }
jlaskey@3:
jlaskey@3: // check String html generation methods
jlaskey@3: if (!'sss'.anchor || "sss".anchor("foo") !== 'sss') {
jlaskey@3: fail("#7 String.prototype.anchor method failed");
jlaskey@3: }
jlaskey@3:
jlaskey@3: if (!'hello'.blink || "hello".blink() !== '') {
jlaskey@3: fail("#8 String.prototype.blink method failed");
jlaskey@3: }
jlaskey@3:
jlaskey@3: if (!'hello'.fixed || "hello".fixed() !== 'hello') {
jlaskey@3: fail("#9 String.prototype.fixed method failed");
jlaskey@3: }
jlaskey@3:
jlaskey@3: if (!'ss'.link || "ss".link('foo') !== 'ss') {
jlaskey@3: fail("#10 String.prototype.link method failed");
jlaskey@3: }
jlaskey@3:
jlaskey@3: if (typeof importClass != 'function') {
jlaskey@3: fail("#11 importClass function not defined");
jlaskey@3: }
jlaskey@3:
jlaskey@3: importClass(java.util.HashMap);
jlaskey@3: if (typeof HashMap != 'function') {
jlaskey@3: fail("#12 global.importClass method failed");
jlaskey@3: }
jlaskey@3: var m = new HashMap();
jlaskey@3: m.put('foo', 'bar');
jlaskey@3: if (m.toString() != '{foo=bar}') {
jlaskey@3: fail("#13 global.importClass failed to work");
jlaskey@3: }
jlaskey@3: