test/script/sandbox/nashorninternals.js

Mon, 11 Feb 2013 21:26:06 +0530

author
sundar
date
Mon, 11 Feb 2013 21:26:06 +0530
changeset 82
abea4ba28901
child 90
5a820fb11814
permissions
-rw-r--r--

8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
Reviewed-by: lagergren, jlaskey, attila

sundar@82 1 /*
sundar@82 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
sundar@82 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@82 4 *
sundar@82 5 * This code is free software; you can redistribute it and/or modify it
sundar@82 6 * under the terms of the GNU General Public License version 2 only, as
sundar@82 7 * published by the Free Software Foundation.
sundar@82 8 *
sundar@82 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sundar@82 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sundar@82 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sundar@82 12 * version 2 for more details (a copy is included in the LICENSE file that
sundar@82 13 * accompanied this code).
sundar@82 14 *
sundar@82 15 * You should have received a copy of the GNU General Public License version
sundar@82 16 * 2 along with this work; if not, write to the Free Software Foundation,
sundar@82 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@82 18 *
sundar@82 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sundar@82 20 * or visit www.oracle.com if you need additional information or have any
sundar@82 21 * questions.
sundar@82 22 */
sundar@82 23
sundar@82 24
sundar@82 25 /**
sundar@82 26 * Test to check that nashorn "internal" classes in codegen, parser, ir
sundar@82 27 * packages cannot * be accessed from sandbox scripts.
sundar@82 28 *
sundar@82 29 * @test
sundar@82 30 * @run
sundar@82 31 * @security
sundar@82 32 */
sundar@82 33
sundar@82 34 function checkClass(name) {
sundar@82 35 try {
sundar@82 36 Java.type(name);
sundar@82 37 fail("should have thrown exception for: " + name);
sundar@82 38 } catch (e) {
sundar@82 39 if (! (e instanceof java.lang.SecurityException)) {
sundar@82 40 fail("Expected SecurityException, but got " + e);
sundar@82 41 }
sundar@82 42 }
sundar@82 43 }
sundar@82 44
sundar@82 45 // Not exhaustive - but a representative list of classes
sundar@82 46 checkClass("jdk.nashorn.internal.codegen.Compiler");
sundar@82 47 checkClass("jdk.nashorn.internal.codegen.objects.MapCreator");
sundar@82 48 checkClass("jdk.nashorn.internal.codegen.types.Type");
sundar@82 49 checkClass("jdk.nashorn.internal.ir.Node");
sundar@82 50 checkClass("jdk.nashorn.internal.ir.FunctionNode");
sundar@82 51 checkClass("jdk.nashorn.internal.ir.debug.JSONWriter");
sundar@82 52 checkClass("jdk.nashorn.internal.ir.visitor.NodeVisitor");
sundar@82 53 checkClass("jdk.nashorn.internal.parser.AbstractParser");
sundar@82 54 checkClass("jdk.nashorn.internal.parser.Parser");
sundar@82 55 checkClass("jdk.nashorn.internal.parser.JSONParser");
sundar@82 56 checkClass("jdk.nashorn.internal.parser.Lexer");
sundar@82 57 checkClass("jdk.nashorn.internal.parser.Scanner");

mercurial