Skip to content

Unexpected ScriptException when bound functions are called inside Promise.then() #522

@duonglaiquang

Description

@duonglaiquang

Problem in brief

HtmlUnit/Rhino throws ScriptException: null when a "bound function" is given as the callback function of Promise.then(). This error is caused by cx.topCallScope being null when passed to BoundFunction.call().

More details

This problem was introduced after the implementation of Promise was changed to Rhino's native implementation in HtmlUnit version 2.56.

Testing

Here are some tests to show the behavior of HtmlUnit 2.66 and Chrome.

<!DOCTYPE html>
<html>
<head>
<script>

let f = function () { console.log(this) }

Promise.resolve().then(f.bind(null)); // Chrome prints Window {...}, HtmlUnit throws ScriptException -- bad
Promise.resolve().then(f.bind("")); // Chrome and HtmlUnit prints String {''} -- good
Promise.resolve().then(() => f.bind(null).call()); // Chrome and HtmlUnit prints Window {...} -- good
Promise.resolve().then(() => f.bind('').call()); // Chrome and HtmlUnit prints String {''} -- good

</script>
</head>
<body>
</body>
</html> 

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions