+++ /dev/null
-/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-\r
- *\r
- * The contents of this file are subject to the Netscape Public\r
- * License Version 1.1 (the "License"); you may not use this file\r
- * except in compliance with the License. You may obtain a copy of\r
- * the License at http://www.mozilla.org/NPL/\r
- *\r
- * Software distributed under the License is distributed on an "AS\r
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr\r
- * implied. See the License for the specific language governing\r
- * rights and limitations under the License.\r
- *\r
- * The Original Code is Rhino code, released\r
- * May 6, 1999.\r
- *\r
- * The Initial Developer of the Original Code is Netscape\r
- * Communications Corporation. Portions created by Netscape are\r
- * Copyright (C) 1997-2000 Netscape Communications Corporation. All\r
- * Rights Reserved.\r
- *\r
- * Contributor(s): \r
- * Roger Lawrence\r
- *\r
- * Alternatively, the contents of this file may be used under the\r
- * terms of the GNU Public License (the "GPL"), in which case the\r
- * provisions of the GPL are applicable instead of those above.\r
- * If you wish to allow use of your version of this file only\r
- * under the terms of the GPL and not to allow others to use your\r
- * version of this file under the NPL, indicate your decision by\r
- * deleting the provisions above and replace them with the notice\r
- * and other provisions required by the GPL. If you do not delete\r
- * the provisions above, a recipient may use your version of this\r
- * file under either the NPL or the GPL.\r
- */\r
-\r
-package org.mozilla.javascript;\r
-\r
-import java.util.*;\r
-import org.mozilla.javascript.debug.DebuggableScript;\r
-\r
-public class InterpretedFunction extends NativeFunction implements DebuggableScript {\r
- \r
- InterpretedFunction(Context cx,\r
- InterpreterData theData, \r
- String[] argNames, short argCount)\r
- {\r
- itsData = theData;\r
- this.argNames = argNames;\r
- this.argCount = argCount;\r
- init(cx);\r
- }\r
- \r
- void init(Context cx)\r
- {\r
- functionName = itsData.itsName;\r
- source = itsData.itsSource;\r
- nestedFunctions = itsData.itsNestedFunctions;\r
- if (cx != null)\r
- version = (short)cx.getLanguageVersion();\r
- }\r
- \r
- InterpretedFunction(InterpretedFunction theOther,\r
- Scriptable theScope, Context cx)\r
- {\r
- itsData = theOther.itsData;\r
- this.argNames = theOther.argNames;\r
- this.argCount = theOther.argCount;\r
- itsClosure = theScope;\r
- init(cx);\r
- }\r
- \r
- public Object call(Context cx, Scriptable scope, Scriptable thisObj,\r
- Object[] args)\r
- throws JavaScriptException\r
- { \r
- Function temp = cx.currentFunction;\r
- if (cx.stackDepth++ > 200) {\r
- NativeError ne = new NativeError();\r
- ne.put("message", ne, "maximum interpreter stack depth limit exceeded");\r
- cx.stackDepth--;\r
- throw new EcmaError(ne, cx.interpreterSourceFile, cx.interpreterLine, 0, "");\r
- }\r
- cx.currentFunction = this;\r
- cx.interpreterSourceFile = itsData.itsSourceFile;\r
- if (itsClosure != null)\r
- scope = itsClosure;\r
- else if (!itsData.itsUseDynamicScope)\r
- scope = getParentScope();\r
-\r
- if (itsData.itsCheckThis) \r
- thisObj = ScriptRuntime.getThis(thisObj);\r
- \r
- if (itsData.itsNeedsActivation) {\r
- scope = ScriptRuntime.initVarObj(cx, scope, this, thisObj, args);\r
- }\r
- try {\r
- return Interpreter.interpret(cx, scope, thisObj, args, this,\r
- itsData);\r
- } finally {\r
- if (itsData.itsNeedsActivation) {\r
- ScriptRuntime.popActivation(cx);\r
- }\r
- cx.currentFunction = temp;\r
- cx.stackDepth--;\r
- }\r
- }\r
- \r
- public boolean isFunction() {\r
- return true;\r
- }\r
- \r
- public Scriptable getScriptable() {\r
- return this;\r
- }\r
- \r
- public String getSourceName() {\r
- return itsData.itsSourceFile;\r
- }\r
- \r
- public int[] getLineNumbers() { \r
- return itsData.itsLineNumberTable.getKeys();\r
- }\r
- \r
- public boolean placeBreakpoint(int line) { // XXX throw exn?\r
- return itsData.placeBreakpoint(line);\r
- }\r
- \r
- public boolean removeBreakpoint(int line) {\r
- return itsData.removeBreakpoint(line);\r
- }\r
- \r
- InterpreterData itsData;\r
- Scriptable itsClosure;\r
-}\r
- \r