interfaceimpl.js revision 877:cf4d2252d444
11541Srgrimes/* 21541Srgrimes * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41541Srgrimes * 51541Srgrimes * This code is free software; you can redistribute it and/or modify it 61541Srgrimes * under the terms of the GNU General Public License version 2 only, as 71541Srgrimes * published by the Free Software Foundation. 81541Srgrimes * 91541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 101541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 131541Srgrimes * accompanied this code). 141541Srgrimes * 151541Srgrimes * You should have received a copy of the GNU General Public License version 161541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 171541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 181541Srgrimes * 191541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 201541Srgrimes * or visit www.oracle.com if you need additional information or have any 211541Srgrimes * questions. 221541Srgrimes */ 231541Srgrimes 241541Srgrimes/** 251541Srgrimes * Check that user defined interface can be implemented. 261541Srgrimes * 271541Srgrimes * @test 281541Srgrimes * @run 291541Srgrimes * @security 301541Srgrimes */ 311541Srgrimes 321541Srgrimesvar Window = Java.type("jdk.nashorn.api.scripting.Window"); 331541Srgrimesvar WindowEventHandler = Java.type("jdk.nashorn.api.scripting.WindowEventHandler"); 341541Srgrimes 351541Srgrimesvar w = new Window(); 361541Srgrimes 371541Srgrimesvar loadedFuncReached = false; 3814508Shsu// try function to SAM converter 3917658Sjulianw.onload = function() { 401541Srgrimes loadedFuncReached = true; 411541Srgrimes return true; 422165Spaul} 432865Sbde 442165Spaulw.onload.loaded(); 451549Srgrimesif (! loadedFuncReached) { 467566Sjoerg fail("Interface method impl. not called"); 471549Srgrimes} 481541Srgrimes 491541Srgrimes// reset 501541SrgrimesloadedFuncReached = false; 511541Srgrimes 521541Srgrimes// try direct interface implementation 5313765Smppw.onload = new WindowEventHandler() { 541541Srgrimes loaded: function() { 551541Srgrimes loadedFuncReached = true; 561541Srgrimes return true; 571541Srgrimes } 581541Srgrimes}; 591541Srgrimes 608876Srgrimesw.onload.loaded(); 611541Srgrimesif (! loadedFuncReached) { 621541Srgrimes fail("Interface method impl. not called"); 631541Srgrimes} 641541Srgrimes