sundar@1511: /* sundar@1511: * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. sundar@1511: * sundar@1511: * Redistribution and use in source and binary forms, with or without sundar@1511: * modification, are permitted provided that the following conditions sundar@1511: * are met: sundar@1511: * sundar@1511: * - Redistributions of source code must retain the above copyright sundar@1511: * notice, this list of conditions and the following disclaimer. sundar@1511: * sundar@1511: * - Redistributions in binary form must reproduce the above copyright sundar@1511: * notice, this list of conditions and the following disclaimer in the sundar@1511: * documentation and/or other materials provided with the distribution. sundar@1511: * sundar@1511: * - Neither the name of Oracle nor the names of its sundar@1511: * contributors may be used to endorse or promote products derived sundar@1511: * from this software without specific prior written permission. sundar@1511: * sundar@1511: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS sundar@1511: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, sundar@1511: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR sundar@1511: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR sundar@1511: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, sundar@1511: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, sundar@1511: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR sundar@1511: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF sundar@1511: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING sundar@1511: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS sundar@1511: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sundar@1511: */ sundar@1511: sundar@1511: // Using a Java map with Javascript "with" statement sundar@1511: sundar@1511: var map = new java.util.HashMap(); sundar@1511: map.put("foo", 34); sundar@1511: map.put("bar", "hello"); sundar@1511: sundar@1511: var obj = { sundar@1511: __noSuchProperty__: function(name) { sundar@1511: return map.get(name); sundar@1511: } sundar@1511: }; sundar@1511: sundar@1511: with(obj) { sundar@1511: print(foo); sundar@1511: print(bar); sundar@1511: }