NativeSyntaxError.java revision 953:221a84ef44c0
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
26package jdk.nashorn.internal.objects;
27
28import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
29
30import jdk.nashorn.internal.objects.annotations.Attribute;
31import jdk.nashorn.internal.objects.annotations.Constructor;
32import jdk.nashorn.internal.objects.annotations.Property;
33import jdk.nashorn.internal.objects.annotations.ScriptClass;
34import jdk.nashorn.internal.objects.annotations.Where;
35import jdk.nashorn.internal.runtime.JSType;
36import jdk.nashorn.internal.runtime.PropertyMap;
37import jdk.nashorn.internal.runtime.ScriptObject;
38
39/**
40 * ECMA 15.11.6.4 SyntaxError
41 *
42 */
43@ScriptClass("Error")
44public final class NativeSyntaxError extends ScriptObject {
45
46    /** message property in instance */
47    @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE)
48    public Object instMessage;
49
50    /** error name property */
51    @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE)
52    public Object name;
53
54    /** ECMA 15.1.1.1 message property */
55    @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE)
56    public Object message;
57
58    /** Nashorn extension: underlying exception */
59    @Property(attributes = Attribute.NOT_ENUMERABLE)
60    public Object nashornException;
61
62    // initialized by nasgen
63    private static PropertyMap $nasgenmap$;
64
65    @SuppressWarnings("LeakingThisInConstructor")
66    NativeSyntaxError(final Object msg, final Global global) {
67        super(global.getSyntaxErrorPrototype(), $nasgenmap$);
68        if (msg != UNDEFINED) {
69            this.instMessage = JSType.toString(msg);
70        } else {
71            this.delete(NativeError.MESSAGE, false);
72        }
73        NativeError.initException(this);
74    }
75
76    private NativeSyntaxError(final Object msg) {
77        this(msg, Global.instance());
78    }
79
80    @Override
81    public String getClassName() {
82        return "Error";
83    }
84
85    /**
86     * ECMA 15.11.6.4 SyntaxError
87     *
88     * Constructor
89     *
90     * @param newObj was this error instantiated with the new operator
91     * @param self   self reference
92     * @param msg    error message
93     *
94     * @return new SyntaxError
95     */
96    @Constructor(name = "SyntaxError")
97    public static NativeSyntaxError constructor(final boolean newObj, final Object self, final Object msg) {
98        return new NativeSyntaxError(msg);
99    }
100}
101
102
103