Converting JS Objects to XDM maps
[Mike email 24/07/2016]
JS-to-XDM conversion shouldn't construct a HashTrie as the conversion of a JS object; rather it should wrap the JS object as a JSValue, and a JSValue should behave like a map. To make a JSValue behave like a map, it needs to implement the same methods as HashTrie, at least for read access:
containsKey - true if the object contains the given key
get - if the object contains the given key, return the result of doing JS-to-XDM conversion on the corresponding value
inSituPut - throw error
put - throw error
remove - throw error
keys - return all the keys as XDMString objects
forAllPairs - a composite of keys() and get()
conforms - roughly the same logic as HashTrie.conforms()
SaxonJS.U.isMap(item) should return true if item is a JSValue.
With this, we don't have the conflict between JS objects (like Style) that are converted to maps, and others (like Window) that are wrapped as a JSValue.
#1 Updated by Debbie Lockett about 2 years ago
- Status changed from New to In Progress
The methods have been added to JSValue as suggested, so that it behaves like a map.
Corresponding changes made to the convertFromJS and convertParamFromJS methods in Expr.js. The changes to convertParamFromJS in fact mean that the value of a stylesheetParam can now also be a map (as long as the type was not declared at least! so still be work to be done here...)
Some unit tests have been written which test these conversions (e.g. when supplying stylesheetParams, and using global functions); but still also need to write more which use the interactive functions/instructions ixsl:get, ixsl:call, ixsl:style, etc.
#2 Updated by Debbie Lockett about 2 years ago
- Status changed from In Progress to Resolved
Marking this as resolved, as JS unit test coverage is much improved, and many of these demonstrate the conversion to JSValues (e.g. tests of interactive functions/instructions).
Relatedly, but on a bit of a tangent to the original Feature issue, the use of stylesheet parameters has also been sorted out:
Stylesheet parameters of declared type map() and array() can now be supplied using the stylesheetParams option on SaxonJS.transform (fix committed on the 9.7 and 9.8 dev branches - so allowed from 18.104.22.168).
Stylesheet parameters with no declared type, or declared type item(), are converted to the 'assumed' type using Expr.convertToJS.
Various JS unit tests added.
Please register to edit this issue