aboutsummaryrefslogtreecommitdiff
path: root/test/script/basic/NASHORN-478.js
blob: dd851bcf174f82ef2b7351e134822b213b64e51d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/**
 * NASHORN-478 : Provide mozilla compatibility script for nashorn
 *
 * @test
 * @run
 */

// compatibility script is loaded using "nashorn:" pseudo URL scheme
try {
    load('nashorn:mozilla_compat.js');
} catch(e) {
}

var obj = {};
if (obj.__proto__ !== Object.prototype) {
    fail("#1 obj.__proto__ read not supported");
}

function fooGetter() { return 3.14; }
function fooSetter(x) {}

Object.defineProperty(obj, "foo", { set: fooSetter, get: fooGetter });
if (!obj.__lookupGetter__ || obj.__lookupGetter__('foo') !== fooGetter) {
    fail("#2 Object.prototype.__lookupGetter__ not supported");
}

if (!obj.__lookupSetter__ || obj.__lookupSetter__('foo') !== fooSetter) {
    fail("#3 Object.prototype.__lookupSetter__ not supported");
}

function barGetter() { return 42; }

if (obj.__defineGetter__) {
    obj.__defineGetter__("bar", barGetter);
}

if (obj.bar !== 42) {
    fail("#4 Object.prototype.__defineGetter__ not supported");
}

var barSetterCalled = false;
function barSetter(x) {
    barSetterCalled = true;
}

if (obj.__defineSetter__) {
    obj.__defineSetter__("bar", barSetter);
}

obj.bar = 'hello';
if (! barSetterCalled) {
    fail("#5 Object.prototype.__defineSetter__ not supported");
}

var obj = { bar: 343, foo : new Boolean(true) };
obj.self = obj;
if (!obj.toSource ||
    obj.toSource() !== '({bar:343, foo:(new Boolean(true)), self:{}})') {
    fail("#6 Object.prototype.toSource method failed");
}

// check String html generation methods
if (!'sss'.anchor || "sss".anchor("foo") !== '<a name="foo">sss</a>') {
    fail("#7 String.prototype.anchor method failed");
}

if (!'hello'.blink || "hello".blink() !== '<blink>hello</blink>') {
    fail("#8 String.prototype.blink method failed");
}

if (!'hello'.fixed || "hello".fixed() !== '<tt>hello</tt>') {
    fail("#9 String.prototype.fixed method failed");
}

if (!'ss'.link || "ss".link('foo') !== '<a href="foo">ss</a>') {
    fail("#10 String.prototype.link method failed");
}

if (typeof importClass != 'function') {
    fail("#11 importClass function not defined");
}

importClass(java.util.HashMap);
if (typeof HashMap != 'function') {
    fail("#12 global.importClass method failed");
}
var m = new HashMap();
m.put('foo', 'bar');
if (m.toString() != '{foo=bar}') {
    fail("#13 global.importClass failed to work");
}