From e97e80635e506b39b7b1ba4594afcc9866be146e Mon Sep 17 00:00:00 2001 From: "nboyd%atg.com" Date: Tue, 24 Apr 2001 18:08:46 +0000 Subject: [PATCH] Break dependency between core and tools. --- .../org/mozilla/javascript/ScriptRuntime.java | 29 +++++++++++++++++-- .../org/mozilla/javascript/ScriptRuntime.java | 29 +++++++++++++++++-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/js/rhino/org/mozilla/javascript/ScriptRuntime.java b/js/rhino/org/mozilla/javascript/ScriptRuntime.java index 9ce1e52ee962..f67f4134f9c8 100644 --- a/js/rhino/org/mozilla/javascript/ScriptRuntime.java +++ b/js/rhino/org/mozilla/javascript/ScriptRuntime.java @@ -42,7 +42,6 @@ package org.mozilla.javascript; import java.util.*; import java.lang.reflect.*; -import org.mozilla.javascript.tools.shell.Global; /** * This is the class that implements the runtime. @@ -1780,11 +1779,35 @@ public class ScriptRuntime { // Statements // ------------------ + private static final String GLOBAL_CLASS = + "org.mozilla.javascript.tools.shell.Global"; + + private static ScriptableObject getGlobal(Context cx) { + try { + Class globalClass = loadClassName(GLOBAL_CLASS); + Class[] parm = { Context.class }; + Constructor globalClassCtor = globalClass.getConstructor(parm); + Object[] arg = { cx }; + return (ScriptableObject) globalClassCtor.newInstance(arg); + } catch (ClassNotFoundException e) { + // fall through... + } catch (NoSuchMethodException e) { + // fall through... + } catch (InvocationTargetException e) { + // fall through... + } catch (IllegalAccessException e) { + // fall through... + } catch (InstantiationException e) { + // fall through... + } + return new ImporterTopLevel(cx); + } + public static void main(String scriptClassName, String[] args) throws JavaScriptException { Context cx = Context.enter(); - ScriptableObject global = new Global(cx); + ScriptableObject global = getGlobal(cx); // get the command line arguments and define "arguments" // array in the top-level object @@ -1858,7 +1881,7 @@ public class ScriptRuntime { public static Scriptable runScript(Script script) { Context cx = Context.enter(); - ScriptableObject global = new Global(cx); + ScriptableObject global = getGlobal(cx); try { script.exec(cx, global); } catch (JavaScriptException e) { diff --git a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java index 9ce1e52ee962..f67f4134f9c8 100644 --- a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java +++ b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java @@ -42,7 +42,6 @@ package org.mozilla.javascript; import java.util.*; import java.lang.reflect.*; -import org.mozilla.javascript.tools.shell.Global; /** * This is the class that implements the runtime. @@ -1780,11 +1779,35 @@ public class ScriptRuntime { // Statements // ------------------ + private static final String GLOBAL_CLASS = + "org.mozilla.javascript.tools.shell.Global"; + + private static ScriptableObject getGlobal(Context cx) { + try { + Class globalClass = loadClassName(GLOBAL_CLASS); + Class[] parm = { Context.class }; + Constructor globalClassCtor = globalClass.getConstructor(parm); + Object[] arg = { cx }; + return (ScriptableObject) globalClassCtor.newInstance(arg); + } catch (ClassNotFoundException e) { + // fall through... + } catch (NoSuchMethodException e) { + // fall through... + } catch (InvocationTargetException e) { + // fall through... + } catch (IllegalAccessException e) { + // fall through... + } catch (InstantiationException e) { + // fall through... + } + return new ImporterTopLevel(cx); + } + public static void main(String scriptClassName, String[] args) throws JavaScriptException { Context cx = Context.enter(); - ScriptableObject global = new Global(cx); + ScriptableObject global = getGlobal(cx); // get the command line arguments and define "arguments" // array in the top-level object @@ -1858,7 +1881,7 @@ public class ScriptRuntime { public static Scriptable runScript(Script script) { Context cx = Context.enter(); - ScriptableObject global = new Global(cx); + ScriptableObject global = getGlobal(cx); try { script.exec(cx, global); } catch (JavaScriptException e) {