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