Fri, 17 Jan 2014 20:09:47 +0530
8032060: PropertyMap of Error objects is not stable
Reviewed-by: jlaskey, hannesw
jlaskey@3 | 1 | /* |
jlaskey@7 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
jlaskey@3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jlaskey@3 | 4 | * |
jlaskey@3 | 5 | * This code is free software; you can redistribute it and/or modify it |
jlaskey@3 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jlaskey@3 | 7 | * published by the Free Software Foundation. Oracle designates this |
jlaskey@3 | 8 | * particular file as subject to the "Classpath" exception as provided |
jlaskey@3 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jlaskey@3 | 10 | * |
jlaskey@3 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jlaskey@3 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jlaskey@3 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jlaskey@3 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jlaskey@3 | 15 | * accompanied this code). |
jlaskey@3 | 16 | * |
jlaskey@3 | 17 | * You should have received a copy of the GNU General Public License version |
jlaskey@3 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jlaskey@3 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jlaskey@3 | 20 | * |
jlaskey@3 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jlaskey@3 | 22 | * or visit www.oracle.com if you need additional information or have any |
jlaskey@3 | 23 | * questions. |
jlaskey@3 | 24 | */ |
jlaskey@3 | 25 | |
jlaskey@3 | 26 | package jdk.nashorn.internal.objects; |
jlaskey@3 | 27 | |
jlaskey@3 | 28 | import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
jlaskey@3 | 29 | |
jlaskey@3 | 30 | import jdk.nashorn.internal.objects.annotations.Attribute; |
jlaskey@3 | 31 | import jdk.nashorn.internal.objects.annotations.Constructor; |
jlaskey@3 | 32 | import jdk.nashorn.internal.objects.annotations.Property; |
jlaskey@3 | 33 | import jdk.nashorn.internal.objects.annotations.ScriptClass; |
jlaskey@3 | 34 | import jdk.nashorn.internal.objects.annotations.Where; |
jlaskey@3 | 35 | import jdk.nashorn.internal.runtime.JSType; |
hannesw@380 | 36 | import jdk.nashorn.internal.runtime.PropertyMap; |
jlaskey@3 | 37 | import jdk.nashorn.internal.runtime.ScriptObject; |
jlaskey@3 | 38 | |
jlaskey@3 | 39 | /** |
jlaskey@3 | 40 | * ECMA 15.11.6.2 RangeError |
jlaskey@3 | 41 | * |
jlaskey@3 | 42 | */ |
jlaskey@3 | 43 | @ScriptClass("Error") |
sundar@82 | 44 | public final class NativeRangeError extends ScriptObject { |
jlaskey@3 | 45 | |
jlaskey@3 | 46 | /** message property in instance */ |
sundar@759 | 47 | @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) |
jlaskey@3 | 48 | public Object instMessage; |
jlaskey@3 | 49 | |
jlaskey@3 | 50 | /** error name property */ |
jlaskey@3 | 51 | @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) |
jlaskey@3 | 52 | public Object name; |
jlaskey@3 | 53 | |
jlaskey@3 | 54 | /** ECMA 15.1.1.1 message property */ |
jlaskey@3 | 55 | @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) |
jlaskey@3 | 56 | public Object message; |
jlaskey@3 | 57 | |
sundar@760 | 58 | /** Nashorn extension: underlying exception */ |
sundar@760 | 59 | @Property(attributes = Attribute.NOT_ENUMERABLE) |
sundar@760 | 60 | public Object nashornException; |
sundar@760 | 61 | |
hannesw@380 | 62 | // initialized by nasgen |
hannesw@380 | 63 | private static PropertyMap $nasgenmap$; |
hannesw@380 | 64 | |
sundar@414 | 65 | static PropertyMap getInitialMap() { |
sundar@414 | 66 | return $nasgenmap$; |
sundar@414 | 67 | } |
sundar@414 | 68 | |
sundar@758 | 69 | @SuppressWarnings("LeakingThisInConstructor") |
sundar@414 | 70 | private NativeRangeError(final Object msg, final ScriptObject proto, final PropertyMap map) { |
sundar@414 | 71 | super(proto, map); |
jlaskey@3 | 72 | if (msg != UNDEFINED) { |
jlaskey@3 | 73 | this.instMessage = JSType.toString(msg); |
jlaskey@3 | 74 | } else { |
sundar@344 | 75 | this.delete(NativeError.MESSAGE, false); |
jlaskey@3 | 76 | } |
sundar@758 | 77 | NativeError.initException(this); |
jlaskey@3 | 78 | } |
jlaskey@3 | 79 | |
sundar@414 | 80 | NativeRangeError(final Object msg, final Global global) { |
sundar@414 | 81 | this(msg, global.getRangeErrorPrototype(), global.getRangeErrorMap()); |
sundar@414 | 82 | } |
sundar@414 | 83 | |
sundar@414 | 84 | private NativeRangeError(final Object msg) { |
sundar@414 | 85 | this(msg, Global.instance()); |
sundar@414 | 86 | } |
sundar@414 | 87 | |
jlaskey@3 | 88 | @Override |
jlaskey@3 | 89 | public String getClassName() { |
jlaskey@3 | 90 | return "Error"; |
jlaskey@3 | 91 | } |
jlaskey@3 | 92 | |
jlaskey@3 | 93 | /** |
jlaskey@3 | 94 | * ECMA 15.11.6.2 RangeError |
jlaskey@3 | 95 | * |
jlaskey@3 | 96 | * Constructor |
jlaskey@3 | 97 | * |
jlaskey@3 | 98 | * @param newObj was this error instantiated with the new operator |
jlaskey@3 | 99 | * @param self self reference |
jlaskey@3 | 100 | * @param msg error message |
jlaskey@3 | 101 | * |
jlaskey@3 | 102 | * @return new RangeError |
jlaskey@3 | 103 | */ |
jlaskey@3 | 104 | @Constructor(name = "RangeError") |
jlaskey@3 | 105 | public static Object constructor(final boolean newObj, final Object self, final Object msg) { |
jlaskey@3 | 106 | return new NativeRangeError(msg); |
jlaskey@3 | 107 | } |
jlaskey@3 | 108 | } |