From 6bbeaa9db560d12b27b1052c19e4283bec6c0d13 Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Wed, 3 Nov 1999 23:56:28 +0000 Subject: [PATCH] Add closure support --- .../org/mozilla/javascript/InterpretedFunction.java | 12 +++++++++++- .../org/mozilla/javascript/InterpretedFunction.java | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/js/rhino/org/mozilla/javascript/InterpretedFunction.java b/js/rhino/org/mozilla/javascript/InterpretedFunction.java index d9d64e930b45..80dcef932df7 100644 --- a/js/rhino/org/mozilla/javascript/InterpretedFunction.java +++ b/js/rhino/org/mozilla/javascript/InterpretedFunction.java @@ -54,6 +54,12 @@ class InterpretedFunction extends NativeFunction { version = (short)cx.getLanguageVersion(); } + InterpretedFunction(InterpretedFunction theOther, Scriptable theScope) + { + itsData = theOther.itsData; + itsClosure = theScope; + } + public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) throws JavaScriptException @@ -61,12 +67,16 @@ class InterpretedFunction extends NativeFunction { if (itsData.itsNeedsActivation) scope = ScriptRuntime.initVarObj(cx, scope, this, thisObj, args); itsData.itsCX = cx; - itsData.itsScope = scope; + if (itsClosure == null) + itsData.itsScope = scope; + else + itsData.itsScope = itsClosure; itsData.itsThisObj = thisObj; itsData.itsInArgs = args; return Interpreter.interpret(itsData); } InterpreterData itsData; + Scriptable itsClosure; } diff --git a/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java b/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java index d9d64e930b45..80dcef932df7 100644 --- a/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java +++ b/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java @@ -54,6 +54,12 @@ class InterpretedFunction extends NativeFunction { version = (short)cx.getLanguageVersion(); } + InterpretedFunction(InterpretedFunction theOther, Scriptable theScope) + { + itsData = theOther.itsData; + itsClosure = theScope; + } + public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) throws JavaScriptException @@ -61,12 +67,16 @@ class InterpretedFunction extends NativeFunction { if (itsData.itsNeedsActivation) scope = ScriptRuntime.initVarObj(cx, scope, this, thisObj, args); itsData.itsCX = cx; - itsData.itsScope = scope; + if (itsClosure == null) + itsData.itsScope = scope; + else + itsData.itsScope = itsClosure; itsData.itsThisObj = thisObj; itsData.itsInArgs = args; return Interpreter.interpret(itsData); } InterpreterData itsData; + Scriptable itsClosure; }