FontoXML / fontoxpath

A minimalistic XPath 3.1 implementation in pure JavaScript
MIT License
131 stars 17 forks source link

"Cannot read property 'next' of undefined" error when calling an updating function in array:for-each #227

Open JosVerburg opened 4 years ago

JosVerburg commented 4 years ago

Can be reproduced with:

<p>This is a paragraph <b>for</b> testing <b>and</b> such.</p>
declare %private %updating function Q{x}nuke-it($x) {
  delete node $x
};
let $bolds := //b, $arr := array {$bolds[1], $bolds[2]} return
array:for-each($arr, Q{x}nuke-it#1)

This now results in the error "Cannot read property 'next' of undefined". The same works fine with a non-updating function e.g. trace#1

DrRataplan commented 4 years ago

Funnily enough, the spec does not say anything about this. I think in this case we are not able to statically determine whether the array function will 'turn' updating depending on its arguments. I think we should disallow this. @JosVerburg , what do you think?

JosVerburg commented 4 years ago

Would it not allow updating expressions to be inserted in it like here https://github.com/LeoWoerteler/XQUTS/blob/master/Queries/XQuery/FunctionCall/id-function-call-01.xq

DrRataplan commented 4 years ago

that is an updating function argument. the bug we have now is an updating function that is executed as a hicher order function, without the invoke updating function stuff you'd normally use

DrRataplan commented 2 years ago

Still present: https://xpath.playground.fontoxml.com/?state=H4sIACeKPGIAA01P24qDQAz9lTDrQgt2pX10Xf%2BhsG9rH6KT1mFtHOJMsYj%2F3mgpFAI5ObmdM5lrb8nkh9TcUBzWHQ0mN9NsUjNeO4WFL39bN4AGgkfBi6BvoajLcy9FVpcQaAiOLwuFbFdqiE37VWS%2BrHg5dIwkd71lqelQCD69uBsGBdFbXJfPkZvgeobjNM4c%2F2nnwiYZtzBVDGCpIx1n1QrJWPH8XbEykNR9ZwfIfyDL6hQSFFkKTXiH6dn925%2B084SH0wxCIQpXvA7lamJH2LSbZTd9%2F%2F6x36r2pudAY3g5MPMDZTNhfTIBAAA%3D