Thu, 31 Aug 2017 15:30:47 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /** |
aoqi@0 | 25 | * NASHORN-478 : Provide mozilla compatibility script for nashorn |
aoqi@0 | 26 | * |
aoqi@0 | 27 | * @test |
aoqi@0 | 28 | * @run |
aoqi@0 | 29 | */ |
aoqi@0 | 30 | |
aoqi@0 | 31 | // compatibility script is loaded using "nashorn:" pseudo URL scheme |
aoqi@0 | 32 | try { |
aoqi@0 | 33 | load('nashorn:mozilla_compat.js'); |
aoqi@0 | 34 | } catch(e) { |
aoqi@0 | 35 | } |
aoqi@0 | 36 | |
aoqi@0 | 37 | var obj = {}; |
aoqi@0 | 38 | if (obj.__proto__ !== Object.prototype) { |
aoqi@0 | 39 | fail("#1 obj.__proto__ read not supported"); |
aoqi@0 | 40 | } |
aoqi@0 | 41 | |
aoqi@0 | 42 | function fooGetter() { return 3.14; } |
aoqi@0 | 43 | function fooSetter(x) {} |
aoqi@0 | 44 | |
aoqi@0 | 45 | Object.defineProperty(obj, "foo", { set: fooSetter, get: fooGetter }); |
aoqi@0 | 46 | if (!obj.__lookupGetter__ || obj.__lookupGetter__('foo') !== fooGetter) { |
aoqi@0 | 47 | fail("#2 Object.prototype.__lookupGetter__ not supported"); |
aoqi@0 | 48 | } |
aoqi@0 | 49 | |
aoqi@0 | 50 | if (!obj.__lookupSetter__ || obj.__lookupSetter__('foo') !== fooSetter) { |
aoqi@0 | 51 | fail("#3 Object.prototype.__lookupSetter__ not supported"); |
aoqi@0 | 52 | } |
aoqi@0 | 53 | |
aoqi@0 | 54 | function barGetter() { return 42; } |
aoqi@0 | 55 | |
aoqi@0 | 56 | if (obj.__defineGetter__) { |
aoqi@0 | 57 | obj.__defineGetter__("bar", barGetter); |
aoqi@0 | 58 | } |
aoqi@0 | 59 | |
aoqi@0 | 60 | if (obj.bar !== 42) { |
aoqi@0 | 61 | fail("#4 Object.prototype.__defineGetter__ not supported"); |
aoqi@0 | 62 | } |
aoqi@0 | 63 | |
aoqi@0 | 64 | var barSetterCalled = false; |
aoqi@0 | 65 | function barSetter(x) { |
aoqi@0 | 66 | barSetterCalled = true; |
aoqi@0 | 67 | } |
aoqi@0 | 68 | |
aoqi@0 | 69 | if (obj.__defineSetter__) { |
aoqi@0 | 70 | obj.__defineSetter__("bar", barSetter); |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | obj.bar = 'hello'; |
aoqi@0 | 74 | if (! barSetterCalled) { |
aoqi@0 | 75 | fail("#5 Object.prototype.__defineSetter__ not supported"); |
aoqi@0 | 76 | } |
aoqi@0 | 77 | |
aoqi@0 | 78 | var obj = { bar: 343, foo : new Boolean(true) }; |
aoqi@0 | 79 | obj.self = obj; |
aoqi@0 | 80 | if (!obj.toSource || |
aoqi@0 | 81 | obj.toSource() !== '({bar:343, foo:(new Boolean(true)), self:{}})') { |
aoqi@0 | 82 | fail("#6 Object.prototype.toSource method failed"); |
aoqi@0 | 83 | } |
aoqi@0 | 84 | |
aoqi@0 | 85 | // check String html generation methods |
aoqi@0 | 86 | if (!'sss'.anchor || "sss".anchor("foo") !== '<a name="foo">sss</a>') { |
aoqi@0 | 87 | fail("#7 String.prototype.anchor method failed"); |
aoqi@0 | 88 | } |
aoqi@0 | 89 | |
aoqi@0 | 90 | if (!'hello'.blink || "hello".blink() !== '<blink>hello</blink>') { |
aoqi@0 | 91 | fail("#8 String.prototype.blink method failed"); |
aoqi@0 | 92 | } |
aoqi@0 | 93 | |
aoqi@0 | 94 | if (!'hello'.fixed || "hello".fixed() !== '<tt>hello</tt>') { |
aoqi@0 | 95 | fail("#9 String.prototype.fixed method failed"); |
aoqi@0 | 96 | } |
aoqi@0 | 97 | |
aoqi@0 | 98 | if (!'ss'.link || "ss".link('foo') !== '<a href="foo">ss</a>') { |
aoqi@0 | 99 | fail("#10 String.prototype.link method failed"); |
aoqi@0 | 100 | } |
aoqi@0 | 101 | |
aoqi@0 | 102 | if (typeof importClass != 'function') { |
aoqi@0 | 103 | fail("#11 importClass function not defined"); |
aoqi@0 | 104 | } |
aoqi@0 | 105 | |
aoqi@0 | 106 | importClass(java.util.HashMap); |
aoqi@0 | 107 | if (typeof HashMap != 'function') { |
aoqi@0 | 108 | fail("#12 global.importClass method failed"); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | var m = new HashMap(); |
aoqi@0 | 111 | m.put('foo', 'bar'); |
aoqi@0 | 112 | if (m.toString() != '{foo=bar}') { |
aoqi@0 | 113 | fail("#13 global.importClass failed to work"); |
aoqi@0 | 114 | } |
aoqi@0 | 115 |