test/script/basic/circular_proto.js

Wed, 21 Aug 2013 17:28:53 +0530

author
sundar
date
Wed, 21 Aug 2013 17:28:53 +0530
changeset 513
b7c04b3b01a7
child 537
b5ff11e00050
permissions
-rw-r--r--

8023368: Instance __proto__ property should exist and be writable.
Reviewed-by: attila, hannesw

sundar@513 1 /*
sundar@513 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
sundar@513 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@513 4 *
sundar@513 5 * This code is free software; you can redistribute it and/or modify it
sundar@513 6 * under the terms of the GNU General Public License version 2 only, as
sundar@513 7 * published by the Free Software Foundation.
sundar@513 8 *
sundar@513 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sundar@513 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sundar@513 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sundar@513 12 * version 2 for more details (a copy is included in the LICENSE file that
sundar@513 13 * accompanied this code).
sundar@513 14 *
sundar@513 15 * You should have received a copy of the GNU General Public License version
sundar@513 16 * 2 along with this work; if not, write to the Free Software Foundation,
sundar@513 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@513 18 *
sundar@513 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sundar@513 20 * or visit www.oracle.com if you need additional information or have any
sundar@513 21 * questions.
sundar@513 22 */
sundar@513 23
sundar@513 24 /**
sundar@513 25 * JDK-8023368: Instance __proto__ property should exist and be writable.
sundar@513 26 *
sundar@513 27 * @test
sundar@513 28 * @run
sundar@513 29 */
sundar@513 30
sundar@513 31 // check that we cannot create __proto__ cycle
sundar@513 32 load("nashorn:mozilla_compat.js");
sundar@513 33
sundar@513 34 var obj = {};
sundar@513 35 var obj2 = Object.create(obj);
sundar@513 36
sundar@513 37 // attempt to create __proto__ cycle
sundar@513 38 try {
sundar@513 39 obj.__proto__ = obj2;
sundar@513 40 fail("Should have thrown TypeError");
sundar@513 41 } catch (e) {
sundar@513 42 if (! (e instanceof TypeError)) {
sundar@513 43 fail("Expected TypeError, got " + e);
sundar@513 44 }
sundar@513 45 print(e);
sundar@513 46 }

mercurial