Skip to content

Commit bb3baf7

Browse files
committed
Add thisObj validation to prevent NullPointerException on non-object this values
1 parent 9ddd6a6 commit bb3baf7

File tree

2 files changed

+3404
-2200
lines changed

2 files changed

+3404
-2200
lines changed

rhino/src/main/java/org/mozilla/javascript/NativeES2025Iterator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ private static Object js_concat(
132132
return new ConcatIterator(cx, scope, iterables, iteratorMethods);
133133
}
134134

135-
private static Callable getNextMethod(Scriptable iterator) {
136-
Object next = ScriptableObject.getProperty(iterator, "next");
135+
private static Callable getNextMethod(Object thisObj) {
136+
if (thisObj == null || !(thisObj instanceof Scriptable)) {
137+
throw ScriptRuntime.typeError("Iterator method called on non-object");
138+
}
139+
Object next = ScriptableObject.getProperty((Scriptable) thisObj, "next");
137140
if (!(next instanceof Callable)) {
138141
throw ScriptRuntime.typeError("Iterator must have a next method");
139142
}

0 commit comments

Comments
 (0)