Skip to content

Commit 7944007

Browse files
committed
Merge branch 'master-upstream' into improve-array-compatibility
2 parents 16c864d + dd9c638 commit 7944007

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+7102
-1316
lines changed

.github/workflows/gradle.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ jobs:
1919
name: Rhino Java ${{ matrix.java }}
2020
steps:
2121
- name: Checkout
22-
uses: actions/checkout@v2
22+
uses: actions/checkout@v3
2323
with:
2424
# Need all history or spotless check will fail
2525
fetch-depth: 0
2626
- name: Check out test262
2727
# We don't actually want all the history for this part
2828
run: git submodule update --init --single-branch
2929
- name: Set up Java
30-
uses: actions/setup-java@v2
30+
uses: actions/setup-java@v3
3131
with:
3232
java-version: ${{ matrix.java }}
3333
distribution: 'adopt'
@@ -44,7 +44,7 @@ jobs:
4444
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
4545
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
4646
- name: Upload results
47-
uses: actions/upload-artifact@v2
47+
uses: actions/upload-artifact@v3
4848
with:
4949
name: reports
5050
path: buildGradle/reports

.github/workflows/publish-github.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
packages: write
1717
steps:
1818
- name: Checkout
19-
uses: actions/checkout@v2
19+
uses: actions/checkout@v3
2020
- name: Set up JDK
21-
uses: actions/setup-java@v2
21+
uses: actions/setup-java@v3
2222
with:
2323
java-version: '8'
2424
distribution: 'adopt'

.github/workflows/publish-maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
packages: write
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616
- name: Set up JDK
17-
uses: actions/setup-java@v2
17+
uses: actions/setup-java@v3
1818
with:
1919
java-version: '8'
2020
distribution: 'adopt'
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.mozilla.javascript.benchmarks;
2+
3+
import java.io.FileReader;
4+
import java.io.IOException;
5+
import org.mozilla.javascript.Context;
6+
import org.mozilla.javascript.Function;
7+
import org.mozilla.javascript.ScriptRuntime;
8+
import org.mozilla.javascript.Scriptable;
9+
import org.mozilla.javascript.ScriptableObject;
10+
import org.openjdk.jmh.annotations.*;
11+
12+
public class PropertyBenchmark {
13+
@State(Scope.Thread)
14+
public static class PropertyState {
15+
Context cx;
16+
Scriptable scope;
17+
18+
Function create;
19+
Function createFieldByField;
20+
Function getName;
21+
Function check;
22+
23+
Object object;
24+
25+
@Setup(Level.Trial)
26+
public void setup() throws IOException {
27+
cx = Context.enter();
28+
cx.setOptimizationLevel(9);
29+
cx.setLanguageVersion(Context.VERSION_ES6);
30+
scope = cx.initStandardObjects();
31+
32+
try (FileReader rdr =
33+
new FileReader("testsrc/benchmarks/micro/property-benchmarks.js")) {
34+
cx.evaluateReader(scope, rdr, "property-benchmarks.js", 1, null);
35+
}
36+
create = (Function) ScriptableObject.getProperty(scope, "createObject");
37+
createFieldByField =
38+
(Function) ScriptableObject.getProperty(scope, "createObjectFieldByField");
39+
getName = (Function) ScriptableObject.getProperty(scope, "getName");
40+
check = (Function) ScriptableObject.getProperty(scope, "check");
41+
42+
object = create.call(cx, scope, null, new Object[] {"testing"});
43+
}
44+
45+
@TearDown(Level.Trial)
46+
public void tearDown() {
47+
cx.close();
48+
}
49+
}
50+
51+
@Benchmark
52+
public Object createObject(PropertyBenchmark.PropertyState state) {
53+
Object obj = state.create.call(state.cx, state.scope, null, new Object[] {"testing"});
54+
String name =
55+
ScriptRuntime.toString(
56+
state.getName.call(state.cx, state.scope, null, new Object[] {obj}));
57+
if (!"testing".equals(name)) {
58+
throw new AssertionError("Expected testing");
59+
}
60+
return name;
61+
}
62+
63+
@Benchmark
64+
public Object createObjectFieldByField(PropertyBenchmark.PropertyState state) {
65+
Object obj =
66+
state.createFieldByField.call(
67+
state.cx, state.scope, null, new Object[] {"testing"});
68+
String name =
69+
ScriptRuntime.toString(
70+
state.getName.call(state.cx, state.scope, null, new Object[] {obj}));
71+
if (!"testing".equals(name)) {
72+
throw new AssertionError("Expected testing");
73+
}
74+
return name;
75+
}
76+
77+
@Benchmark
78+
public Object getOneProperty(PropertyBenchmark.PropertyState state) {
79+
String name =
80+
ScriptRuntime.toString(
81+
state.getName.call(
82+
state.cx, state.scope, null, new Object[] {state.object}));
83+
if (!"testing".equals(name)) {
84+
throw new AssertionError("Expected testing");
85+
}
86+
return name;
87+
}
88+
89+
@Benchmark
90+
public Object addTwoProperties(PropertyBenchmark.PropertyState state) {
91+
return state.check.call(state.cx, state.scope, null, new Object[] {state.object});
92+
}
93+
}

0 commit comments

Comments
 (0)