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