Source Code Cross Referenced for InterpretedFunction.java in  » Scripting » rhino » org » mozilla » javascript » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » rhino » org.mozilla.javascript 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002:         *
003:         * ***** BEGIN LICENSE BLOCK *****
004:         * Version: MPL 1.1/GPL 2.0
005:         *
006:         * The contents of this file are subject to the Mozilla Public License Version
007:         * 1.1 (the "License"); you may not use this file except in compliance with
008:         * the License. You may obtain a copy of the License at
009:         * http://www.mozilla.org/MPL/
010:         *
011:         * Software distributed under the License is distributed on an "AS IS" basis,
012:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013:         * for the specific language governing rights and limitations under the
014:         * License.
015:         *
016:         * The Original Code is Rhino code, released
017:         * May 6, 1999.
018:         *
019:         * The Initial Developer of the Original Code is
020:         * Netscape Communications Corporation.
021:         * Portions created by the Initial Developer are Copyright (C) 1997-2000
022:         * the Initial Developer. All Rights Reserved.
023:         *
024:         * Contributor(s):
025:         *   Igor Bukanov
026:         *   Bob Jervis
027:         *   Roger Lawrence
028:         *
029:         * Alternatively, the contents of this file may be used under the terms of
030:         * the GNU General Public License Version 2 or later (the "GPL"), in which
031:         * case the provisions of the GPL are applicable instead of those above. If
032:         * you wish to allow use of your version of this file only under the terms of
033:         * the GPL and not to allow others to use your version of this file under the
034:         * MPL, indicate your decision by deleting the provisions above and replacing
035:         * them with the notice and other provisions required by the GPL. If you do
036:         * not delete the provisions above, a recipient may use your version of this
037:         * file under either the MPL or the GPL.
038:         *
039:         * ***** END LICENSE BLOCK ***** */
040:
041:        package org.mozilla.javascript;
042:
043:        import org.mozilla.javascript.debug.DebuggableScript;
044:
045:        final class InterpretedFunction extends NativeFunction implements 
046:                Script {
047:            static final long serialVersionUID = 541475680333911468L;
048:
049:            InterpreterData idata;
050:            SecurityController securityController;
051:            Object securityDomain;
052:            Scriptable[] functionRegExps;
053:
054:            private InterpretedFunction(InterpreterData idata,
055:                    Object staticSecurityDomain) {
056:                this .idata = idata;
057:
058:                // Always get Context from the current thread to
059:                // avoid security breaches via passing mangled Context instances
060:                // with bogus SecurityController
061:                Context cx = Context.getContext();
062:                SecurityController sc = cx.getSecurityController();
063:                Object dynamicDomain;
064:                if (sc != null) {
065:                    dynamicDomain = sc
066:                            .getDynamicSecurityDomain(staticSecurityDomain);
067:                } else {
068:                    if (staticSecurityDomain != null) {
069:                        throw new IllegalArgumentException();
070:                    }
071:                    dynamicDomain = null;
072:                }
073:
074:                this .securityController = sc;
075:                this .securityDomain = dynamicDomain;
076:            }
077:
078:            private InterpretedFunction(InterpretedFunction parent, int index) {
079:                this .idata = parent.idata.itsNestedFunctions[index];
080:                this .securityController = parent.securityController;
081:                this .securityDomain = parent.securityDomain;
082:            }
083:
084:            /**
085:             * Create script from compiled bytecode.
086:             */
087:            static InterpretedFunction createScript(InterpreterData idata,
088:                    Object staticSecurityDomain) {
089:                InterpretedFunction f;
090:                f = new InterpretedFunction(idata, staticSecurityDomain);
091:                return f;
092:            }
093:
094:            /**
095:             * Create function compiled from Function(...) constructor.
096:             */
097:            static InterpretedFunction createFunction(Context cx,
098:                    Scriptable scope, InterpreterData idata,
099:                    Object staticSecurityDomain) {
100:                InterpretedFunction f;
101:                f = new InterpretedFunction(idata, staticSecurityDomain);
102:                f.initInterpretedFunction(cx, scope);
103:                return f;
104:            }
105:
106:            /**
107:             * Create function embedded in script or another function.
108:             */
109:            static InterpretedFunction createFunction(Context cx,
110:                    Scriptable scope, InterpretedFunction parent, int index) {
111:                InterpretedFunction f = new InterpretedFunction(parent, index);
112:                f.initInterpretedFunction(cx, scope);
113:                return f;
114:            }
115:
116:            Scriptable[] createRegExpWraps(Context cx, Scriptable scope) {
117:                if (idata.itsRegExpLiterals == null)
118:                    Kit.codeBug();
119:
120:                RegExpProxy rep = ScriptRuntime.checkRegExpProxy(cx);
121:                int N = idata.itsRegExpLiterals.length;
122:                Scriptable[] array = new Scriptable[N];
123:                for (int i = 0; i != N; ++i) {
124:                    array[i] = rep.wrapRegExp(cx, scope,
125:                            idata.itsRegExpLiterals[i]);
126:                }
127:                return array;
128:            }
129:
130:            private void initInterpretedFunction(Context cx, Scriptable scope) {
131:                initScriptFunction(cx, scope);
132:                if (idata.itsRegExpLiterals != null) {
133:                    functionRegExps = createRegExpWraps(cx, scope);
134:                }
135:            }
136:
137:            public String getFunctionName() {
138:                return (idata.itsName == null) ? "" : idata.itsName;
139:            }
140:
141:            /**
142:             * Calls the function.
143:             * @param cx the current context 
144:             * @param scope the scope used for the call
145:             * @param thisObj the value of "this"
146:             * @param args function arguments. Must not be null. You can use 
147:             * {@link ScriptRuntime#emptyArgs} to pass empty arguments.
148:             * @return the result of the function call.
149:             */
150:            public Object call(Context cx, Scriptable scope,
151:                    Scriptable this Obj, Object[] args) {
152:                if (!ScriptRuntime.hasTopCall(cx)) {
153:                    return ScriptRuntime.doTopCall(this , cx, scope, this Obj,
154:                            args);
155:                }
156:                return Interpreter.interpret(this , cx, scope, this Obj, args);
157:            }
158:
159:            public Object exec(Context cx, Scriptable scope) {
160:                if (idata.itsFunctionType != 0) {
161:                    // Can only be applied to scripts
162:                    throw new IllegalStateException();
163:                }
164:                if (!ScriptRuntime.hasTopCall(cx)) {
165:                    // It will go through "call" path. but they are equivalent
166:                    return ScriptRuntime.doTopCall(this , cx, scope, scope,
167:                            ScriptRuntime.emptyArgs);
168:                }
169:                return Interpreter.interpret(this , cx, scope, scope,
170:                        ScriptRuntime.emptyArgs);
171:            }
172:
173:            public String getEncodedSource() {
174:                return Interpreter.getEncodedSource(idata);
175:            }
176:
177:            public DebuggableScript getDebuggableView() {
178:                return idata;
179:            }
180:
181:            public Object resumeGenerator(Context cx, Scriptable scope,
182:                    int operation, Object state, Object value) {
183:                return Interpreter.resumeGenerator(cx, scope, operation, state,
184:                        value);
185:            }
186:
187:            protected int getLanguageVersion() {
188:                return idata.languageVersion;
189:            }
190:
191:            protected int getParamCount() {
192:                return idata.argCount;
193:            }
194:
195:            protected int getParamAndVarCount() {
196:                return idata.argNames.length;
197:            }
198:
199:            protected String getParamOrVarName(int index) {
200:                return idata.argNames[index];
201:            }
202:
203:            protected boolean getParamOrVarConst(int index) {
204:                return idata.argIsConst[index];
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.