2003/05/12 05:10:30
[org.ibex.core.git] / src / org / mozilla / javascript / Undefined.java
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-\r
2  *\r
3  * The contents of this file are subject to the Netscape Public\r
4  * License Version 1.1 (the "License"); you may not use this file\r
5  * except in compliance with the License. You may obtain a copy of\r
6  * the License at http://www.mozilla.org/NPL/\r
7  *\r
8  * Software distributed under the License is distributed on an "AS\r
9  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr\r
10  * implied. See the License for the specific language governing\r
11  * rights and limitations under the License.\r
12  *\r
13  * The Original Code is Rhino code, released\r
14  * May 6, 1999.\r
15  *\r
16  * The Initial Developer of the Original Code is Netscape\r
17  * Communications Corporation.  Portions created by Netscape are\r
18  * Copyright (C) 1997-1999 Netscape Communications Corporation. All\r
19  * Rights Reserved.\r
20  *\r
21  * Contributor(s): \r
22  * Norris Boyd\r
23  *\r
24  * Alternatively, the contents of this file may be used under the\r
25  * terms of the GNU Public License (the "GPL"), in which case the\r
26  * provisions of the GPL are applicable instead of those above.\r
27  * If you wish to allow use of your version of this file only\r
28  * under the terms of the GPL and not to allow others to use your\r
29  * version of this file under the NPL, indicate your decision by\r
30  * deleting the provisions above and replace them with the notice\r
31  * and other provisions required by the GPL.  If you do not delete\r
32  * the provisions above, a recipient may use your version of this\r
33  * file under either the NPL or the GPL.\r
34  */\r
35 \r
36 package org.mozilla.javascript;\r
37 \r
38 /**\r
39  * This class implements the Undefined value in JavaScript.\r
40  */\r
41 public class Undefined implements Scriptable {\r
42 \r
43     static final public Scriptable instance = new Undefined();\r
44 \r
45     public String getClassName() {\r
46         return "undefined";\r
47     }\r
48 \r
49     public boolean has(String id, Scriptable start) {\r
50         return false;\r
51     }\r
52 \r
53     public boolean has(int index, Scriptable start) {\r
54         return false;\r
55     }\r
56 \r
57     public Object get(String id, Scriptable start) {\r
58         throw reportError();\r
59     }\r
60 \r
61     public Object get(int index, Scriptable start) {\r
62         throw reportError();\r
63     }\r
64 \r
65     public void put(String id,Scriptable start, Object value) {\r
66         throw reportError();\r
67     }\r
68 \r
69     public void put(int index, Scriptable start, Object value) {\r
70         throw reportError();\r
71     }\r
72 \r
73     public void delete(String id) {\r
74         throw reportError();\r
75     }\r
76 \r
77     public void delete(int index) {\r
78         throw reportError();\r
79     }\r
80 \r
81     public short getAttributes(String id, Scriptable start) {\r
82         throw reportError();\r
83     }\r
84 \r
85     public short getAttributes(int index, Scriptable start) {\r
86         throw reportError();\r
87     }\r
88 \r
89     public void setAttributes(String id, Scriptable start, short attributes) {\r
90         throw reportError();\r
91     }\r
92 \r
93     public void setAttributes(int index, Scriptable start, short attributes) {\r
94         throw reportError();\r
95     }\r
96 \r
97     public Scriptable getPrototype() {\r
98         throw reportError();\r
99     }\r
100 \r
101     public void setPrototype(Scriptable prototype) {\r
102         throw reportError();\r
103     }\r
104 \r
105     public Scriptable getParentScope() {\r
106         throw reportError();\r
107     }\r
108 \r
109     public void setParentScope(Scriptable parent) {\r
110         throw reportError();\r
111     }\r
112 \r
113     public Object[] getIds() {\r
114         throw reportError();\r
115     }\r
116 \r
117     public Object getDefaultValue(Class cl) {\r
118         if (cl == ScriptRuntime.StringClass)\r
119             return "undefined";\r
120         if (cl == ScriptRuntime.NumberClass)\r
121             return ScriptRuntime.NaNobj;\r
122         if (cl == ScriptRuntime.BooleanClass)\r
123             return Boolean.FALSE;\r
124         return this;\r
125     }\r
126 \r
127     public boolean hasInstance(Scriptable value) {\r
128         throw reportError();\r
129     }\r
130 \r
131     public boolean instanceOf(Scriptable prototype) {\r
132         return false;\r
133     }\r
134 \r
135     private RuntimeException reportError() {\r
136         return Context.reportRuntimeError0("msg.undefined");\r
137     }\r
138 }\r