Skip to content

Commit 955b81b

Browse files
committed
scope handling fix (wip)
1 parent aefd8de commit 955b81b

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

src/main/java/org/htmlunit/html/HtmlPage.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,26 +2576,21 @@ public void setSelectionRange(final SimpleRange selectionRange) {
25762576
* @param function the JavaScript Function to call
25772577
* @param thisObject the "this" object to be used during invocation
25782578
* @param args the arguments to pass into the call
2579-
* @param htmlElementScope the HTML element for which this script is being executed
2579+
* @param htmlElement the HTML element for which this script is being executed
25802580
* This element will be the context during the JavaScript execution. If null,
25812581
* the context will default to the page.
25822582
* @return a ScriptResult which will contain both the current page (which may be different from
25832583
* the previous page) and a JavaScript result object.
25842584
*/
25852585
public ScriptResult executeJavaScriptFunction(final Object function, final Object thisObject,
2586-
final Object[] args, final DomNode htmlElementScope) {
2586+
final Object[] args, final DomNode htmlElement) {
25872587
if (!getWebClient().isJavaScriptEnabled()) {
25882588
return new ScriptResult(null);
25892589
}
25902590

2591-
return executeJavaScriptFunction((Function) function, (Scriptable) thisObject, args, htmlElementScope);
2592-
}
2593-
2594-
private ScriptResult executeJavaScriptFunction(final Function function, final Scriptable thisObject,
2595-
final Object[] args, final DomNode htmlElementScope) {
2596-
25972591
final JavaScriptEngine engine = (JavaScriptEngine) getWebClient().getJavaScriptEngine();
2598-
final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope);
2592+
final Object result = engine.callFunction(this,
2593+
(Function) function, (Scriptable) thisObject, args, htmlElement);
25992594

26002595
return new ScriptResult(result);
26012596
}

src/main/java/org/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public static ImageData createImageData(final Context context, final VarScope sc
306306
if (args.length > 0 && args[0] instanceof ImageData imageDataParameter) {
307307
final ImageData imageData = new ImageData(null,
308308
0, 0, imageDataParameter.getWidth(), imageDataParameter.getHeight());
309-
imageData.setParentScope(canvas.getParentScope());
309+
imageData.setParentScope(scope);
310310
imageData.setPrototype(canvas.getPrototype(imageData.getClass()));
311311
return imageData;
312312
}

src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItemList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static DataTransferItem add(final Context context, final VarScope scope,
8181
if (args.length == 1) {
8282
if (args[0] instanceof File file) {
8383
final DataTransferItem item = DataTransferItem.buildFileItem(file);
84-
item.setParentScope(itemList.getParentScope());
84+
item.setParentScope(scope);
8585
item.setPrototype(itemList.getPrototype(item.getClass()));
8686

8787
if (itemList.items_ == null) {
@@ -100,7 +100,7 @@ public static DataTransferItem add(final Context context, final VarScope scope,
100100
final String data = JavaScriptEngine.toString(args[0]);
101101
final String type = JavaScriptEngine.toString(args[1]);
102102
final DataTransferItem item = DataTransferItem.buildStringItem(data, type);
103-
item.setParentScope(itemList.getParentScope());
103+
item.setParentScope(scope);
104104
item.setPrototype(itemList.getPrototype(item.getClass()));
105105

106106
if (itemList.items_ == null) {

0 commit comments

Comments
 (0)