To the extent possible under law,
Yehuda Katz
has waived all copyright and related or neighboring rights to
JSIDL.
This document is an attempt to define an ECMAScript focused IDL for use by web specifications.
It is a work in progress and is still missing a significant amount of semantics provided by the current WebIDL specification.
This is a work in progress.
Among many other things, it still needs a formal description of the syntax of JSIDL, a description of the programming environment, and a description and specification of a branding mechanism.
This document is not yet ready for wide feedback and is being circulated to get the work I'm doing on this topic into the open. It is still at an extremely early stage.
JSIDL does not define any "types". Instead, it defines a series of coercion rules that can be applied to an input value and produce an output value.
In some cases, those coercion rules may produce an error, either by virtue of delegation to ECMAScript algorithms, or as defined in the algorithms themselves.
This section describes how to coerce values when:
Each sub-section below describes how to coerce a value using the specified coercion rule.
No coercion is performed.
A value V is coerced to a ToBoolean value using the ECMAScript ToBoolean abstract operation.
A value V is coerced to a ToInteger value using the ECMAScript ToInteger abstract operation.
A value V is coerced to a ToPositiveInteger value using the ECMAScript ToPositiveInteger abstract operation.
A value V is coerced to a ToNumber value using the ECMAScript ToNumber abstract operation.
A value V is coerced to a ToString value using the ECMAScript ToString abstract operation.
A value V is coerced to a ToObject value using the ECMAScript ToObject abstract operation.
WebIDL requires that the value V return Object for Type(V).
However, this coercion is not uniformly implemented, and coercing primitives to objects in this situation is more consistent with similar built-in ECMAScript operations.
Each platform-defined class or interface installs a non-forgable Brand on each object using its @@create method.
A value V is coerced to a class or interface value by performing the following algorithm.
TypeError
.An options type is an ObjectBindingPattern with type annotations.
This algorithm boils down to:
Work through the most elegant way to define these coercion in terms of ECMAScript
An enum is a set of strings E.
A value V is coerced into an enum E as follows.
Function parameters are specified in JSIDL as a coercion-annotated FormalParameterList.
If a parameter is specified without a default, it is a TypeError to call the function without specifying that parameter.
Default arguments are specified as in ECMAScript, by following the parameter's name with an Initialiser.
As a shortcut, =undefined
may be replaced with ?
.
class ColorCreator {
object createColor(number v1, number v2, number v3, number alpha?);
}
In this example, createColor
must be called with three or four arguments. If the
fourth argument is omitted, its value will be undefined.
Thanks to Dave Herman and Sam Tobin-Hochstadt for helping me work through some semantic differences with WebIDL. Thanks to Anne van Kesteren and Boris Zbarsky for helping me with the precise semantics of existing specs. Thanks to Alex Russell for the inspiration to begin this project.