Skip to content

Commit

Permalink
Merge branch 'master-upstream' into better-type-support
Browse files Browse the repository at this point in the history
  • Loading branch information
rPraml committed Oct 16, 2023
2 parents 104dc07 + dd9c638 commit 46240e2
Show file tree
Hide file tree
Showing 65 changed files with 7,102 additions and 1,316 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
name: Rhino Java ${{ matrix.java }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# Need all history or spotless check will fail
fetch-depth: 0
- name: Check out test262
# We don't actually want all the history for this part
run: git submodule update --init --single-branch
- name: Set up Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
Expand All @@ -44,7 +44,7 @@ jobs:
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
- name: Upload results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: reports
path: buildGradle/reports
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.mozilla.javascript.benchmarks;

import java.io.FileReader;
import java.io.IOException;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.openjdk.jmh.annotations.*;

public class PropertyBenchmark {
@State(Scope.Thread)
public static class PropertyState {
Context cx;
Scriptable scope;

Function create;
Function createFieldByField;
Function getName;
Function check;

Object object;

@Setup(Level.Trial)
public void setup() throws IOException {
cx = Context.enter();
cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = cx.initStandardObjects();

try (FileReader rdr =
new FileReader("testsrc/benchmarks/micro/property-benchmarks.js")) {
cx.evaluateReader(scope, rdr, "property-benchmarks.js", 1, null);
}
create = (Function) ScriptableObject.getProperty(scope, "createObject");
createFieldByField =
(Function) ScriptableObject.getProperty(scope, "createObjectFieldByField");
getName = (Function) ScriptableObject.getProperty(scope, "getName");
check = (Function) ScriptableObject.getProperty(scope, "check");

object = create.call(cx, scope, null, new Object[] {"testing"});
}

@TearDown(Level.Trial)
public void tearDown() {
cx.close();
}
}

@Benchmark
public Object createObject(PropertyBenchmark.PropertyState state) {
Object obj = state.create.call(state.cx, state.scope, null, new Object[] {"testing"});
String name =
ScriptRuntime.toString(
state.getName.call(state.cx, state.scope, null, new Object[] {obj}));
if (!"testing".equals(name)) {
throw new AssertionError("Expected testing");
}
return name;
}

@Benchmark
public Object createObjectFieldByField(PropertyBenchmark.PropertyState state) {
Object obj =
state.createFieldByField.call(
state.cx, state.scope, null, new Object[] {"testing"});
String name =
ScriptRuntime.toString(
state.getName.call(state.cx, state.scope, null, new Object[] {obj}));
if (!"testing".equals(name)) {
throw new AssertionError("Expected testing");
}
return name;
}

@Benchmark
public Object getOneProperty(PropertyBenchmark.PropertyState state) {
String name =
ScriptRuntime.toString(
state.getName.call(
state.cx, state.scope, null, new Object[] {state.object}));
if (!"testing".equals(name)) {
throw new AssertionError("Expected testing");
}
return name;
}

@Benchmark
public Object addTwoProperties(PropertyBenchmark.PropertyState state) {
return state.check.call(state.cx, state.scope, null, new Object[] {state.object});
}
}
Loading

0 comments on commit 46240e2

Please sign in to comment.