Bug #3718


Mishandling null, undefined, and array results from ixsl functions

Added by Debbie Lockett over 6 years ago. Updated about 6 years ago.

Start date:
Due date:
% Done:


Estimated time:
Applies to JS Branch:
1.0, Trunk
Fix Committed on JS Branch:
1.0, Trunk
Fixed in JS Release:
SEF Generated with:
Contact person:
Additional contact persons:


Incorrect results are being returned from expressions such as empty(ixsl:eval('null')), ixsl:eval('[1,2,3]'), and ixsl:get(ixsl:window() , 'nullObj') where var nullObj = null.

Internally function expressions return iterators. The JavaScript results from ixsl functions such as ixsl:get(), ixsl:eval(), and ixsl:apply, are converted from JavaScript using Expr.convertFromJS(), and then put in an iterator. However there are a few cases where this is not being done correctly, and so for null, undefined and arrays, the end results are not always right.

JavaScript null, undefined and [] should all be converted to an empty sequence, which as an iterator can be either Iter.Empty (or Iter.Singleton(null)), or Iter.ForArray([]). Note that convertFromJS() returns [] for each of null, undefined and [].

JS arrays should be converted to XDM sequences - internally this is an iterator Iter.ForArray(a). There are cases where we just put all converted results in Iter.Singleton(), neglecting the case for arrays/sequences (e.g. ixsl:eval()).

There are some cases where we do check for null and/or undefined before converting (using convertFromJS) and handle these separately (to return Iter.Empty), but we should be consistent that we always check for an array after converting (and in that case the check for null/undefined beforehand is unnecessary). So always use something like:

var y = Expr.convertFromJS(x);
return Array.isArray(y) ? Iter.ForArray(y) : Iter.Singleton(y);
Actions #1

Updated by Debbie Lockett over 6 years ago

  • Status changed from New to Resolved
  • Fix Committed on JS Branch 1.0, Trunk added

Checked how we handle results for all uses of Expr.convertFromJS(). Code fixes only required for implementations of ixsl:get() and ixsl:eval(); other uses are being handled correctly.

Code fixes committed on 1.0 and 2.0 branches.

JS unit tests ixsl/get03 and ixsl/eval03 tests added.

Actions #2

Updated by Debbie Lockett about 6 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 1.1.0

Bug fix applied in the Saxon-JS 1.1.0 maintenance release.

Please register to edit this issue

Also available in: Atom PDF Tracking page