Bug: Grouping shapes fails in JavaScript for Automation

In AppleScript we can group some selected shapes by writing and running:

tell application "OmniGraffle"
    tell front window
        set selection to {assemble selection}
    end tell
end tell

(The selection method of the front window returns a list/array of graphics, and this is also the type expected as first argument by the assemble method of the application)

In JavaScript for Applications, .assemble() is found as a method of the OmniGraffle Application object, but fails silently when called on an array of graphics. It returns a null value, and has no effect, producing not even an error message.

var og = Application("OmniGraffle"),
    w = og.windows[0];

w.selection = [og.assemble(
    w.selection()
)];

An update:

It looks like some kind of type error. In Applescript, assemble succeeds with both:

  1. A list of graphics (such as the return value of the selection method - see snippet above)
  2. A reference, such as graphics of canvas of front window
tell application "OmniGraffle"
	tell front window
		set selection to {assemble graphics of its canvas}
	end tell
end tell

In the case of JavaScript for Automation, however, while the command succeeds with references, e.g. (all the graphics on the canvas:

var og = Application("OmniGraffle"),
    w = og.windows[0];

w.selection = [og.assemble(
    w.canvas.graphics
)];

It fails (though without any error message) with arrays.

i.e. we can group a logically defined set of shapes (using the ObjectSpecifier() syntax, but this is a rather marginal case. The core case will always be an array of specific shapes, such as the selection array.

and we can circumvent the type error in the scripting library by writing an elaborate kludge to convert the type of an array of shapes to a reference to a set of shapes that have the same ids as the elements of the array …

Sort of works (slowly), but offloads a noticeable burden onto the scripting customer :-)

(The hackRef() function which is needed is longer than the original code …

    // OG_graphics_collection -> [ og_graphic ] -> OG_graphics_collection
    function hackRef(graphics, lstGraphics) {
        var lng = lstGraphics.length;

        if (lng) {
            return graphics.whose(lng > 1 ? {
                _or: lstGraphics.map(function (g) {
                    return {
                        _match: [ObjectSpecifier().id, g.id()]
                    }
                })
            } : {
                id: lstGraphics[0].id()
            });
        } else return null;
    }

var og = Application("OmniGraffle"),
    w = og.windows[0];

w.selection = [og.assemble(
    hackRef(w.canvas.graphics, w.selection())
)];