X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FJSFunction.java;h=2f75ff2dfdc8de8d3be1592e25ed43960ec37423;hb=de378041d5ca2aca1a2b5a31ef15ae90a86c977f;hp=a9164b8663102b105f24c38568bdfcb1d88d3815;hpb=c2a138c3882a4bd8dce0212ac59765af5cb126c6;p=org.ibex.core.git diff --git a/src/org/xwt/js/JSFunction.java b/src/org/xwt/js/JSFunction.java index a9164b8..2f75ff2 100644 --- a/src/org/xwt/js/JSFunction.java +++ b/src/org/xwt/js/JSFunction.java @@ -1,4 +1,4 @@ -// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt.js; import org.xwt.util.*; @@ -6,7 +6,7 @@ import java.util.*; import java.io.*; /** A JavaScript function, compiled into bytecode */ -public class JSFunction extends JS implements ByteCodes, Tokens { +class JSFunction extends JS implements ByteCodes, Tokens, org.xwt.Scheduler.Task { // Fields and Accessors /////////////////////////////////////////////// @@ -26,8 +26,16 @@ public class JSFunction extends JS implements ByteCodes, Tokens { // Public ////////////////////////////////////////////////////////////////////////////// + // FEATURE: make sure that this can only be called from the Scheduler... + /** if you enqueue a function, it gets invoked in its own pauseable context */ + public void perform() throws JSExn { + Interpreter i = new Interpreter(this, true, new JSArray()); + int oldpausecount = i.pausecount; + i.resume(); + } + /** parse and compile a function */ - public static JSFunction fromReader(String sourceName, int firstLine, Reader sourceCode) throws IOException { + public static JSFunction _fromReader(String sourceName, int firstLine, Reader sourceCode) throws IOException { JSFunction ret = new JSFunction(sourceName, firstLine, null); if (sourceCode == null) return ret; Parser p = new Parser(sourceCode, sourceName, firstLine); @@ -41,7 +49,7 @@ public class JSFunction extends JS implements ByteCodes, Tokens { return ret; } - public JSFunction cloneWithNewParentScope(JSScope s) { + public JSFunction _cloneWithNewParentScope(JSScope s) { JSFunction ret = new JSFunction(sourceName, firstLine, s); // Reuse the same op, arg, line, and size variables for the new "instance" of the function // NOTE: Neither *this* function nor the new function should be modified after this call @@ -54,7 +62,7 @@ public class JSFunction extends JS implements ByteCodes, Tokens { } /** Note: code gets run in an unpauseable context. */ - public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) { + public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { JSArray args = new JSArray(); if (nargs > 0) args.addElement(a0); if (nargs > 1) args.addElement(a1); @@ -64,6 +72,7 @@ public class JSFunction extends JS implements ByteCodes, Tokens { return cx.resume(); } + public JSScope getParentScope() { return parentScope; } // Adding and Altering Bytecodes /////////////////////////////////////////////////// @@ -97,6 +106,7 @@ public class JSFunction extends JS implements ByteCodes, Tokens { // Debugging ////////////////////////////////////////////////////////////////////// public String toString() { return "JSFunction [" + sourceName + ":" + firstLine + "]"; } + public String dump() { StringBuffer sb = new StringBuffer(1024); sb.append("\n" + sourceName + ": " + firstLine + "\n");