Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -855,25 +855,12 @@ dependencies {
BuildUtils.addExternalDependency(
project,
new ExternalDependency(
'com.sun.script.js:jsr223-js-engine:Aug2008',
"JSR-223 ScriptEngine for Rhino",
"Scripting Project",
"https://scripting.dev.java.net/",
ExternalDependency.BSD_LICENSE_NAME,
ExternalDependency.BSD_LICENSE_URL,
"JSR-223 ScriptEngine APIs for Rhino"
)
)

BuildUtils.addExternalDependency(
project,
new ExternalDependency(
'org.mozilla:rhino:1.7R3',
"org.mozilla:rhino:${rhinoVersion}",
"Mozilla Rhino",
"Mozilla Rhino",
"http://www.mozilla.org/rhino/",
"MPL 1.1",
"http://www.mozilla.org/MPL",
"https://github.com/mozilla/rhino",
"MPL 2.0",
"https://www.mozilla.org/en-US/MPL/2.0/",
"Embedded JavaScript engine"
)
)
Expand Down
8 changes: 2 additions & 6 deletions api/src/org/labkey/api/data/triggers/ScriptTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,11 @@ public static ServerContextModuleScript create(Script serverContext)
public static Script getServerContext(Container c, User u)
{
String jsCode = PageFlowUtil.class.getName() + ".jsInitObject(" + ContainerUser.class.getName() + ".create(" + ContainerManager.class.getName() + ".getForId(" + PageFlowUtil.jsString(c.getId()) + "), " + UserManager.class.getName() + ".getUser(" + u.getUserId() + ")), null, null, false).toMap()";
Context ctx = Context.enter();
try

try (Context ctx = Context.enter())
{
return ctx.compileString("module.exports = " + jsCode, SERVER_CONTEXT_SCRIPT_NAME + ".js", 1, null);
}
finally
{
Context.exit();
}
}

interface ScriptFn<R>
Expand Down
32 changes: 27 additions & 5 deletions core/src/org/labkey/core/script/ExternalScriptable.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Symbol;
import org.mozilla.javascript.SymbolScriptable;
import org.mozilla.javascript.Wrapper;

import javax.script.Bindings;
Expand All @@ -47,7 +49,7 @@
* @since 1.6
*/
// kevink: changes marked
final class ExternalScriptable implements Scriptable
final class ExternalScriptable implements Scriptable, SymbolScriptable
{
/* Underlying ScriptContext that we use to store
* named variables of this scope.
Expand Down Expand Up @@ -387,11 +389,9 @@ public Object getDefaultValue(Class typeHint) {
Object v = ScriptableObject.getProperty(this, methodName);
if (!(v instanceof Function fun))
continue;
Context cx = RhinoScriptEngine.enterContext();
try {
try (Context cx = Context.enter())
{
v = fun.call(cx, fun.getParentScope(), this, args);
} finally {
cx.exit();
}
if (v != null) {
if (!(v instanceof Scriptable)) {
Expand All @@ -417,6 +417,28 @@ public Object getDefaultValue(Class typeHint) {
"Cannot find default value for object " + arg);
}

@Override
public Object get(Symbol key, Scriptable start)
{
return NOT_FOUND;
}

@Override
public boolean has(Symbol key, Scriptable start)
{
return false;
}

@Override
public void put(Symbol key, Scriptable start, Object value)
{
}

@Override
public void delete(Symbol key)
{
}

/**
* Implements the instanceof operator.
*
Expand Down
36 changes: 6 additions & 30 deletions core/src/org/labkey/core/script/RhinoCompiledScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

package org.labkey.core.script;

import com.sun.phobos.script.util.ExtendedScriptException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.labkey.api.util.ExceptionUtil;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.JavaScriptException;
import org.mozilla.javascript.RhinoException;
Expand All @@ -40,14 +38,7 @@
import javax.script.ScriptEngine;
import javax.script.ScriptException;

/**
* Represents compiled JavaScript code.
*
* @author Mike Grogan
* @version 1.0
* @since 1.6
*/
// kevink: Essentially the same as the original, with changes marked with kevink
/** Represents compiled JavaScript code. */
final class RhinoCompiledScript extends CompiledScript
{
private final Logger _log = LogManager.getLogger(RhinoCompiledScript.class);
Expand All @@ -65,32 +56,17 @@ public Object eval(ScriptContext context) throws ScriptException
{

Object result;
Context cx = RhinoScriptEngine.enterContext();
try {

try (Context cx = Context.enter())
{
Scriptable scope = engine.getRuntimeScope(context);
Object ret = script.exec(cx, scope);
Object ret = script.exec(cx, scope, scope);
result = engine.unwrapReturnValue(ret);
} catch (JavaScriptException jse) {
_log.debug(jse);
int line = (line = jse.lineNumber()) == 0 ? -1 : line;
Object value = jse.getValue();
String str = (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError") ?
value.toString() :
jse.toString());
// kevink: suppress mothership logging.
ScriptException ex = new ExtendedScriptException(jse, str, jse.sourceName(), line);
ExceptionUtil.decorateException(ex, ExceptionUtil.ExceptionInfo.SkipMothershipLogging, "true", true);
throw ex;
throw RhinoScriptEngine.toScriptException(jse);
} catch (RhinoException re) {
_log.debug(re);
int line = (line = re.lineNumber()) == 0 ? -1 : line;
// kevink: suppress mothership logging.
ScriptException ex = new ExtendedScriptException(re, re.toString(), re.sourceName(), line);
ExceptionUtil.decorateException(ex, ExceptionUtil.ExceptionInfo.SkipMothershipLogging, "true", true);
throw ex;
} finally {
Context.exit();
throw RhinoScriptEngine.toScriptException(re);
}

return result;
Expand Down
Loading
Loading