sealfreeze.js revision 2:da1e581c933b
10Sduke/* 216862Sbpb * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 30Sduke * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40Sduke * 50Sduke * This code is free software; you can redistribute it and/or modify it 60Sduke * under the terms of the GNU General Public License version 2 only, as 70Sduke * published by the Free Software Foundation. 80Sduke * 90Sduke * This code is distributed in the hope that it will be useful, but WITHOUT 100Sduke * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 110Sduke * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 120Sduke * version 2 for more details (a copy is included in the LICENSE file that 130Sduke * accompanied this code). 140Sduke * 150Sduke * You should have received a copy of the GNU General Public License version 160Sduke * 2 along with this work; if not, write to the Free Software Foundation, 170Sduke * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 180Sduke * 192362Sohair * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 202362Sohair * or visit www.oracle.com if you need additional information or have any 212362Sohair * questions. 220Sduke */ 230Sduke 240Sduke/** 250Sduke * Basic checks for Object.seal and Object.freeze. 260Sduke * 270Sduke * @test 280Sduke * @run 290Sduke */ 300Sduke 3116862Sbpbvar obj = { num: Math.E }; 320Sduke 330Sdukeprint("sealed? " + Object.isSealed(obj)); 340Sdukeprint("frozen? " + Object.isFrozen(obj)); 3516862Sbpb 3616862SbpbObject.seal(obj); 370Sdukeprint("sealed? " + Object.isSealed(obj)); 380Sduke 390Sduke// delete should fail - because we have sealed 400Sdukeprint("deleted num? " + (delete obj.num)); 410Sdukeprint("num = " + obj.num); 4216862Sbpb 430Sduke// assignment should succeed 440Sdukeprint("assign PI to num"); 450Sdukeobj.num = Math.PI; 4616862Sbpbprint("num = " + obj.num); 470Sduke 480Sduke// assignment should fail -- because we freeze 490SdukeObject.freeze(obj); 500Sdukeprint("frozen? " + Object.isFrozen(obj)); 510Sduke 520Sdukeprint("assign 1729 to num"); 530Sdukeobj.num = 1729; 540Sdukeprint("num = " + obj.num); 550Sduke 5616862Sbpb