Project

Profile

Help

Bug #3718

closed

Mishandling null, undefined, and array results from ixsl functions

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

Status:
Closed
Priority:
Normal
Category:
-
Sprint/Milestone:
-
Start date:
2018-03-13
Due date:
% Done:

100%

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

Description

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);

Please register to edit this issue

Also available in: Atom PDF Tracking page