Skip to content

Commit

Permalink
First step to having an env.js-specific set of Rhino extensions. We now
Browse files Browse the repository at this point in the history
have a new (although still empty) main/shell Java class based on Rhino's
default shell that will be used for executing env.js.  This is located
in a separate jar so that we can continue to operate with unmodified
Rhino release jars.
  • Loading branch information
gleneivey committed Jul 11, 2009
1 parent 301375c commit fbcc448
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 3 deletions.
12 changes: 9 additions & 3 deletions build.xml
Expand Up @@ -39,8 +39,11 @@
location="${DIST_DIR}/env.rhino.js"/>

<!-- BUILD TARGETS -->
<target name="all" depends="concat,test"/>

<target name="all" depends="rhino,concat,test"/>
<target name="rhino">
<ant antfile="rhino/build.xml" target="all" inheritAll="false"/>
</target>

<target name="concat" description="Main ENV build">
<mkdir dir="${DIST_DIR}" />
<!-- CORE -->
Expand Down Expand Up @@ -147,7 +150,10 @@
</target>

<target name="test" description="Run the tests">
<java fork="true" jar="rhino/js.jar" failonerror="true">
<java fork="true"
failonerror="true"
classname="EnvjsRhinoMain"
classpath="rhino/js.jar:rhino/mainForEnvjs.jar">
<arg value="test/test.js"/>
<jvmarg value="-Dfile.encoding=utf-8"/>
</java>
Expand Down
21 changes: 21 additions & 0 deletions rhino/build.properties
@@ -0,0 +1,21 @@

name: mainforenvjs
Name: mainForEnvjs
version: 0
implementation.version: mainForEnvjs 0 ${implementation.date}
# ^^^ matches Context#getImplementationVersion()

build.dir: build
src.dir: mainForEnvjs
this.jar: mainForEnvjs.jar
dist.name: mainforenvjs${version}
dist.dir: ${build.dir}/${dist.name}

# compilation destionation
classes: ${build.dir}/classes

# compilation settings
debug: on
target-jvm: 1.5
source-level: 1.5
jar-compression: true
6 changes: 6 additions & 0 deletions rhino/build.xml
@@ -0,0 +1,6 @@

<project name="rhino" default="all" basedir=".">
<target name="all">
<ant antfile="mainForEnvjs/build.xml" target="jar"/>
</target>
</project>
Binary file added rhino/mainForEnvjs.jar
Binary file not shown.
47 changes: 47 additions & 0 deletions rhino/mainForEnvjs/EnvjsRhinoGlobal.java
@@ -0,0 +1,47 @@
/*
* This file is a component of env.js,
* http://github.com/gleneivey/env-js/commits/master/README
* a Pure JavaScript Browser Environment
* Copyright 2009 John Resig, licensed under the MIT License
* http://www.opensource.org/licenses/mit-license.php
*/


import org.mozilla.javascript.*;

public class EnvjsRhinoGlobal extends
org.mozilla.javascript.tools.shell.Global
{
public void init(Context cx)
{
// first, let the Rhino shell base class do its init
super.init(cx);

// now, we add the JavaScript methods we want to provide for env.js
String[] names = {
"createAGlobalObject",
"getThisScopesGlobalObject",
"setThisScopesGlobalObject"
};
defineFunctionProperties(names, EnvjsRhinoGlobal.class,
ScriptableObject.DONTENUM);
}


/* class methods intended to be called as JavaScript global functions */

public static void createAGlobalObject(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
}

public static void getThisScopesGlobalObject(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
}

public static void setThisScopesGlobalObject(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
}
}
21 changes: 21 additions & 0 deletions rhino/mainForEnvjs/EnvjsRhinoMain.java
@@ -0,0 +1,21 @@
/*
* This file is a component of env.js,
* http://github.com/gleneivey/env-js/commits/master/README
* a Pure JavaScript Browser Environment
* Copyright 2009 John Resig, licensed under the MIT License
* http://www.opensource.org/licenses/mit-license.php
*/


import org.mozilla.javascript.tools.shell.*;

public class EnvjsRhinoMain extends Main
{
static
{ // replace the generic Global object with our extended
System.out.println("Hello from EnvjsRhinoMain-static-initializer");
global = new EnvjsRhinoGlobal();
// not calling global.initQuitAction() Doesn't matter because env.js
// doesn't call the "quit" JS method provided by the Rhino shell app
}
}
38 changes: 38 additions & 0 deletions rhino/mainForEnvjs/build.xml
@@ -0,0 +1,38 @@


<project name="mainForEnvjs" default="jar" basedir="..">

<target name="properties">
<tstamp>
<format property="implementation.date" pattern="yyyy MM dd"/>
</tstamp>
<property file="build.properties"/>
</target>

<target name="init" depends="properties">
<mkdir dir="${build.dir}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${dist.dir}"/>
</target>

<target name="compile" depends="init">
<javac srcdir="${src.dir}"
destdir="${classes}"
includes="**/*.java"
deprecation="on"
classpath="js.jar"
debug="${debug}"
target="${target-jvm}"
source="${source-level}"
>
</javac>
</target>

<target name="jar" depends="compile">
<jar jarfile="${this.jar}"
basedir="${classes}"
manifest="${src.dir}/manifest"
compress="${jar-compression}"
/>
</target>
</project>
2 changes: 2 additions & 0 deletions rhino/mainForEnvjs/manifest
@@ -0,0 +1,2 @@
Manifest-Version: 1.0
Main-Class: EnvjsRhinoMain

0 comments on commit fbcc448

Please sign in to comment.