Re: Exposing constructors of readonly interfaces to web authors

To use Rik's example on DOMRectReadOnly and DOMQuad:

[NoInterface]
interface DOMRectReadOnly {
    readonly attribute unrestricted double x;
    readonly attribute unrestricted double y;
    readonly attribute unrestricted double width;
    readonly attribute unrestricted double height;
    readonly attribute unrestricted double top;
    readonly attribute unrestricted double right;
    readonly attribute unrestricted double bottom;
    readonly attribute unrestricted double left;
};

[Constructor ...]
interface DOMQuad {
    ...
    [SameObject] readonly attribute DOMRectReadOnly bounds;
};

In JS it could look similar to:

function DOMQuad() {
	var rect = { x: 0, y: 0, width: 100, height: 100, top: 0, left: 0, bottom: 100, right: 100 }; // Or var rect = new DOMRect(…) if DOMRect is implemented.
	….

	var bounds_internal = {}; // Or var bounds_internal = new DOMRectReadOnly(); with function DOMRectReadOnly() { }
	Object.defineProperty(bounds_internal, 'x’, { get: function() { return rect.x; } });
	Object.defineProperty(bounds_internal, 'y’, { get: function() { return rect.y; } });
	Object.defineProperty(bounds_internal, 'width’, { get: function() { return rect.width; } });
	Object.defineProperty(bounds_internal, 'height’, { get: function() { return rect.height; } });
	Object.defineProperty(bounds_internal, 'top’, { get: function() { return rect.top; } });
	Object.defineProperty(bounds_internal, 'left’, { get: function() { return rect.left; } });
	Object.defineProperty(bounds_internal, 'bottom’, { get: function() { return rect.bottom; } });
	Object.defineProperty(bounds_internal, 'right’, { get: function() { return rect.right; } });

	this.bounds = bounds_internal;
}

Greetings,
Dirk

On Jun 28, 2014, at 7:23 AM, Rik Cabanier <cabanier@gmail.com> wrote:

> After sending this out, I realized that there was a typo.
> Here's the correction for a function that return a readonly interface of DOMMatrix:
> getMatrix: function(){
> var retval = {};
> Object.DefineAttribute(retval, "a", { get: function() { return this.m11_equivalent; } });
> ...
> retval.translate = function(...){...};
> ...
> return retval;
> }

Received on Saturday, 28 June 2014 07:00:08 UTC