Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	rhino/src/main/java/org/mozilla/javascript/Context.java
  • Loading branch information
rbri committed Dec 24, 2024
2 parents b4696b2 + a65afb3 commit 0b13f94
Show file tree
Hide file tree
Showing 94 changed files with 1,680 additions and 1,656 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
# 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@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0
# By putting JVMs in reverse order, the last one is the one that
# will go in the path.
with:
Expand All @@ -35,7 +35,7 @@ jobs:
run: >-
./gradlew check
- name: Upload results Java 21
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
if: ${{ always() }}
with:
name: reports-java-21
Expand All @@ -46,7 +46,7 @@ jobs:
run: >-
./gradlew check
- name: Upload results Java 17
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
if: ${{ always() }}
with:
name: reports-java-17
Expand All @@ -57,7 +57,7 @@ jobs:
run: >-
./gradlew check
- name: Upload results Java 11
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
if: ${{ always() }}
with:
name: reports-java-11
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up JDK
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0
with:
java-version: '21'
distribution: 'adopt'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up JDK
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0
with:
java-version: '21'
distribution: 'adopt'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: SARIF file
path: results.sarif
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/groovy/rhino.java-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This file contains Gradle "conventions" that we use in all of our projects.
// It is the appropriate set of conventions to use for modules that will not be
// published, such as test modules.

plugins {
id 'java-library'
id 'com.diffplug.spotless'
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/groovy/rhino.library-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// This file inherits from "java-conventions" and adds additional error
// checks and publishing data for modules that will be published to
// Maven Central. It should only be used for those modules that will
// be published and used by other projects.

plugins {
id 'rhino.java-conventions'
id 'maven-publish'
Expand Down
3 changes: 3 additions & 0 deletions rhino/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ plugins {
id 'rhino.library-conventions'
}

dependencies {
testImplementation project(':testutils')
}

publishing {
publications {
Expand Down
31 changes: 16 additions & 15 deletions rhino/src/main/java/org/mozilla/javascript/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.function.Consumer;
Expand Down Expand Up @@ -2674,25 +2673,27 @@ static String getSourcePositionFromStack(int[] linep) {
Evaluator evaluator = createInterpreter();
if (evaluator != null) return evaluator.getSourcePositionFromStack(cx, linep);
}
/**
* A bit of a hack, but the only way to get filename and line number from an enclosing
* frame.
*/
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
for (StackTraceElement st : stackTrace) {
String file = st.getFileName();
if (!(file == null || file.endsWith(".java"))) {
int line = st.getLineNumber();
if (line >= 0) {
linep[0] = line;
return file;
}

return getSourcePositionFromJavaStack(linep);
}

/** Returns the current filename in the java stack. */
static String getSourcePositionFromJavaStack(int[] linep) {
StackTraceElement[] stack = new Throwable().getStackTrace();
for (StackTraceElement e : stack) {
if (frameMatches(e)) {
linep[0] = e.getLineNumber();
return e.getFileName();
}
}

return null;
}

private static boolean frameMatches(StackTraceElement e) {
return (e.getFileName() == null || !e.getFileName().endsWith(".java"))
&& e.getLineNumber() > 0;
}

RegExpProxy getRegExpProxy() {
if (regExpProxy == null) {
Class<?> cl = Kit.classOrNull("org.mozilla.javascript.regexp.RegExpImpl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,26 @@ protected static NativeTypedArrayView<?> js_constructor(
}

if ((byteOff < 0) || (byteOff > na.getLength())) {
throw ScriptRuntime.rangeError("offset out of range");
String msg = ScriptRuntime.getMessageById("msg.typed.array.bad.offset", byteOff);
throw ScriptRuntime.rangeError(msg);
}
if ((byteLen < 0) || ((byteOff + byteLen) > na.getLength())) {
throw ScriptRuntime.rangeError("length out of range");
String msg = ScriptRuntime.getMessageById("msg.typed.array.bad.length", byteLen);
throw ScriptRuntime.rangeError(msg);
}
if ((byteOff % bytesPerElement) != 0) {
throw ScriptRuntime.rangeError("offset must be a multiple of the byte size");
String msg =
ScriptRuntime.getMessageById(
"msg.typed.array.bad.offset.byte.size", byteOff, bytesPerElement);
throw ScriptRuntime.rangeError(msg);
}
if ((byteLen % bytesPerElement) != 0) {
throw ScriptRuntime.rangeError(
"offset and buffer must be a multiple of the byte size");
String msg =
ScriptRuntime.getMessageById(
"msg.typed.array.bad.buffer.length.byte.size",
byteLen,
bytesPerElement);
throw ScriptRuntime.rangeError(msg);
}

return constructable.construct(na, byteOff, byteLen / bytesPerElement);
Expand Down Expand Up @@ -608,12 +617,14 @@ protected static NativeTypedArrayView<?> js_constructor(
}

private void setRange(NativeTypedArrayView<?> v, int off) {
if (off >= length) {
throw ScriptRuntime.rangeError("offset out of range");
if (off < 0 || off > length) {
String msg = ScriptRuntime.getMessageById("msg.typed.array.bad.offset", off);
throw ScriptRuntime.rangeError(msg);
}

if (v.length > (length - off)) {
throw ScriptRuntime.rangeError("source array too long");
String msg = ScriptRuntime.getMessageById("msg.typed.array.bad.source.array");
throw ScriptRuntime.rangeError(msg);
}

if (v.arrayBuffer == arrayBuffer) {
Expand All @@ -633,11 +644,13 @@ private void setRange(NativeTypedArrayView<?> v, int off) {
}

private void setRange(NativeArray a, int off) {
if (off > length) {
throw ScriptRuntime.rangeError("offset out of range");
if (off < 0 || off > length) {
String msg = ScriptRuntime.getMessageById("msg.typed.array.bad.offset", off);
throw ScriptRuntime.rangeError(msg);
}
if ((off + a.size()) > length) {
throw ScriptRuntime.rangeError("offset + length out of range");
String msg = ScriptRuntime.getMessageById("msg.typed.array.bad.source.array");
throw ScriptRuntime.rangeError(msg);
}

int pos = off;
Expand Down Expand Up @@ -1118,7 +1131,13 @@ private static Object js_with(
Object argsValue = args.length > 1 ? ScriptRuntime.toNumber(args[1]) : 0.0;

if (actualIndex < 0 || actualIndex >= self.length) {
throw ScriptRuntime.rangeError("index out of range");
String msg =
ScriptRuntime.getMessageById(
"msg.typed.array.index.out.of.bounds",
relativeIndex,
self.length * -1,
self.length - 1);
throw ScriptRuntime.rangeError(msg);
}

NativeArrayBuffer newBuffer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,24 @@ msg.promise.any.toobig =\
msg.typed.array.ctor.incompatible = \
Method %TypedArray%.prototype.{0} called on incompatible receiver

msg.typed.array.bad.offset = \
offset {0} out of range

msg.typed.array.bad.length = \
length {0} out of range

msg.typed.array.bad.offset.byte.size = \
offset {0} must be a multiple of the byte size {1}

msg.typed.array.bad.buffer.length.byte.size = \
used buffer length {0} must be a multiple of the byte size {1}

msg.typed.array.bad.source.array = \
source array is too long

msg.typed.array.index.out.of.bounds =\
index {0} is out of bounds [{1}..{2}]

# Error
msg.iterable.expected =\
Expected the first argument to be iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void worksWithUndefined() {
}

private static void canUseEvalSpecialWithThisSetTo(Object thisArg) {
Utils.runWithAllOptimizationLevels(
Utils.runWithAllModes(
cx -> {
ScriptableObject scope = cx.initStandardObjects();
Object o =
Expand Down
Loading

0 comments on commit 0b13f94

Please sign in to comment.