Skip to content
This repository was archived by the owner on Nov 8, 2020. It is now read-only.
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Rhino is an implementation of JavaScript in Java.
## This repository is a fork of rhino for [fixRTM](https://github.com/anatawa12/fixRTM)

Here is the list of difference from the original Rhino:
- use dynlink to resolve overload and casting values

## License

Expand Down
28 changes: 28 additions & 0 deletions THIRD-PERTY-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
This project uses and copies some part of source code of dynalink,
a library released under BSD 3-clause. the license is shown below:

Copyright 2009-2013 Attila Szegedi

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dependencies {
testCompile "junit:junit:4.12"
testCompile "org.yaml:snakeyaml:1.15"
testCompile "net.trajano.caliper:caliper:1.2.1"

compile 'org.dynalang:dynalink:0.7'
}

test {
Expand Down Expand Up @@ -135,6 +137,7 @@ task runtimeJar(type: Jar) {
jar {
dependsOn runtimeJar
from "LICENSE.txt"
from "THIRD-PERTY-LICENSE.txt"
manifest {
attributes(
"Manifest-Version": "1.0",
Expand Down
46 changes: 46 additions & 0 deletions src/org/mozilla/javascript/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
Expand All @@ -28,11 +29,14 @@
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import org.dynalang.dynalink.DynamicLinker;
import org.dynalang.dynalink.DynamicLinkerFactory;
import org.mozilla.classfile.ClassFileWriter.ClassFileFormatException;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.ast.ScriptNode;
import org.mozilla.javascript.debug.DebuggableScript;
import org.mozilla.javascript.debug.Debugger;
import org.mozilla.javascript.dynalink.RhinoLinker;
import org.mozilla.javascript.xml.XMLLib;

/**
Expand Down Expand Up @@ -2795,4 +2799,46 @@ public final boolean isStrictMode() {
public boolean generateObserverCount = false;

boolean isTopLevelStrict;

// add linker
private static DynamicLinker linker = makeLinker();

private static DynamicLinker makeLinker() {
DynamicLinkerFactory factory = new DynamicLinkerFactory();
factory.setPrioritizedLinkers(new RhinoLinker());
return factory.createLinker();
}

public static DynamicLinker getLinker() {
if (linker == null) {
linker = makeLinker();
}
return linker;
}

static Class<?> getClassLink(Object object) {
return getClassLink(object, NULL_CLASS);
}

static Class<?> getClassLink(Object object, Class<?> ifNull) {
if (object instanceof Wrapper) {
object = ((Wrapper)object).unwrap();
}
if (object == null) return ifNull;
return object.getClass();
}

// add NULL_CLASS

static Class<?> NULL_CLASS;

static {
try {
Field field = Class.forName("org.dynalang.dynalink.beans.ClassString").getDeclaredField("NULL_CLASS");
field.setAccessible(true);
NULL_CLASS = (Class<?>) field.get(null);
} catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) {
throw new AssertionError(e);
}
}
}
Loading