Skip to content

Commit 2c0a71e

Browse files
committed
several fixes for calling bind() in the interpreter (regression from 4.14.0)
1 parent c199f12 commit 2c0a71e

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="4.16.0" date="August 17, 2025" description="StringUtils, Brotli, spread for object literals, Bugfixes">
11+
<action type="add" dev="rbri">
12+
core-js: Several fixes for calling bind() in the interpreter (regression from 4.14.0)
13+
</action>
1114
<action type="add" dev="RhinoTeam">
1215
core-js: ES2025 ArrayBuffer transfer(), and transferToFixedLength() implemented
1316
</action>

src/test/java/org/htmlunit/javascript/FunctionsTest.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,71 @@ public void applyToCallSetsCorrectFunctionThis() throws Exception {
281281

282282
loadPageVerifyTitle2(html);
283283
}
284+
285+
/**
286+
* @throws Exception if the test fails
287+
*/
288+
@Test
289+
@Alerts("abcd / undefined")
290+
public void boundWithoutArgs() throws Exception {
291+
final String html = DOCTYPE_HTML
292+
+ "<html><head></head>\n"
293+
+ "<body>\n"
294+
+ "<script>\n"
295+
+ LOG_TITLE_FUNCTION
296+
+ " function foo(x) { return this.toString() + ' / ' + x; };\n"
297+
+ " var boundThis = 'abcd';\n"
298+
+ " var boundFoo = Function.prototype.bind.call(foo, boundThis);\n"
299+
+ " var r = boundFoo.call('Hello!');\n"
300+
+ " log(r);\n"
301+
+ "</script>\n"
302+
+ "</body></html>";
303+
304+
loadPageVerifyTitle2(html);
305+
}
306+
307+
/**
308+
* @throws Exception if the test fails
309+
*/
310+
@Test
311+
@Alerts("abcd / world")
312+
public void boundWithArg() throws Exception {
313+
final String html = DOCTYPE_HTML
314+
+ "<html><head></head>\n"
315+
+ "<body>\n"
316+
+ "<script>\n"
317+
+ LOG_TITLE_FUNCTION
318+
+ " function foo(x) { return this.toString() + ' / ' + x; };\n"
319+
+ " var boundThis = 'abcd';\n"
320+
+ " var boundFoo = Function.prototype.bind.call(foo, boundThis, 'world');\n"
321+
+ " var r = boundFoo.call('Hello!');\n"
322+
+ " log(r);\n"
323+
+ "</script>\n"
324+
+ "</body></html>";
325+
326+
loadPageVerifyTitle2(html);
327+
}
328+
329+
330+
/**
331+
* @throws Exception if the test fails
332+
*/
333+
@Test
334+
@Alerts("world")
335+
public void bound() throws Exception {
336+
final String html = DOCTYPE_HTML
337+
+ "<html><head></head>\n"
338+
+ "<body>\n"
339+
+ "<script>\n"
340+
+ LOG_TITLE_FUNCTION
341+
+ " function foo() { return 'world'; };\n"
342+
+ " var boundThis = 'abcd';\n"
343+
+ " var boundFoo = Function.prototype.bind.call(foo, boundThis);\n"
344+
+ " var r = boundFoo.call(' dd');\n"
345+
+ " log(r);\n"
346+
+ "</script>\n"
347+
+ "</body></html>";
348+
349+
loadPageVerifyTitle2(html);
350+
}
284351
}

0 commit comments

Comments
 (0)