Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: sky/specs/idl.md

Issue 912653003: Specs: Dartification or various odds and ends (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/specs/dom.md ('k') | sky/specs/markup.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 Sky IDL
2 =======
3
4 The Sky IDL language is used to describe JS APIs found in Sky, in
5 particular, the JS APIs exposed by the four magical imports defined in
6 this document.
7
8 Sky IDL definitions are typically compiled to C++ that exposes the C++
9 implementations of the APIs to JavaScript.
10
11 Sky IDL works more or less the same as Web IDL but the syntax is a bit
12 different.
13
14 ```javascript
15 module 'sky:modulename' {
16
17 // this is a comment
18
19 typedef NewType OldType; // useful when OldType is a commonly-used union
20
21 callback CallbackName ReturnType (ArgumentType argumentName);
22
23 class ClassName {
24 // a class corresponds to a JavaScript prototype
25 // corresponds to a WebIDL 'interface'
26 }
27
28 abstract class Superclass {
29 // an abstract class can't have a non-abstract constructor
30 // an abstract class may have abstract constructors and methods
31 // an abstract class may have everything else a class can have
32
33 abstract constructor ();
34 // this indicates that non-abstract subclasses must have a constructor wit h the given arguments
35
36 abstract ReturnType methodCallback();
37 // this method does nothing, but is included to describe the interface tha t subclasses will implement
38 // a non-abstract class must have an explicit implementation of all inheri ted abstract methods
39
40 }
41
42 class Subclass : Superclass {
43 // properties
44 readonly attribute ReturnType attributeName; // getter
45 attribute ReturnType attributeName; // getter and setter
46
47 // methods and constructors
48 constructor ();
49 ReturnType method();
50 // When the platform calls this method, it always invokes the "real" metho d, even if it's been
51 // deleted from the prototypes (as if it took a reference to the method at startup, and stored
52 // state using Symbols)
53 // Calling a method with fewer arguments than defined will throw.
54 // Calling a method with more arguments ignores the extra arguments.
55 virtual ReturnType methodCallback();
56 // when the platform calls this, it actually calls it the way JS would, so author overrides do
57 // affect what gets called. Make sure if you override it that you call the superclass implementation!
58 // The default implementations of 'virtual' methods all end by calling the identically named method
59 // on the superclass, if there is such a method.
60
61 // non-abstract classes cannot have abstract constructors or methods, and in particular, must
62 // have explicit non-abstract versions of any inherited abstract constructor s or methods
63
64 // properties on the constructor
65 constructor readonly attribute ReturnType staticName;
66
67 // private APIs - see below
68 private void method();
69
70 // arguments and overloading are done as follows
71 // note that the argument names are only for documentation purposes
72 ReturnType method(ArgumentType argumentName1, ArgumentType argumentName2);
73 // the last argument's type can have "..." appended to it to indicate a vara rgs-like situation
74 ReturnType method(ArgumentType argumentName1, ArgumentType... allSubsequentA rguments);
75 // trailing arguments can have a default value, which must be a literal of t he given type
76 ReturnType method(ArgumentType argumentName1, ArgumentType argumentName2 = d efaultValue);
77 }
78
79 dictionary Options {
80 String foo; // if there's no default, the property must be specified or it's a TypeError
81 Integer bar = 4; // properties can have default values
82 }
83
84 // the module can have properties and methods also
85 attribute String Foo;
86 void method();
87
88 interface InterfaceName {
89 // describes a template of a prototype, in the same syntax as a class
90 // not actually exposed in the runtime
91 }
92
93 }
94 ```
95
96 ### Private APIs ###
97
98 Private APIs are only accessible via Symbol objects, which are then
99 exposed on the sky:debug module's exports object as the name of the
100 member given in the IDL.
101
102 For example, consider:
103
104 ```javascript
105 class Foo {
106 private void Bar();
107 }
108 ```
109
110 In a script with a ``foo`` object of type ``Foo``, ``foo.Bar`` is
111 undefined. However, it can be obtained as follows:
112
113 ```html
114 <import src="sky:debug" as="debug"/>
115 <!-- ... import whatever defines 'foo' ... -->
116 <script>
117 foo[debug.Bar]
118 </script>
119 ```
120
121 ### Types ###
122
123 The following types are available:
124
125 * ``Integer`` - WebIDL ``long long``
126 * ``Float`` - WebIDL ``double``
127 * ``Infinity`` - singleton type with value ``Infinity``
128 * ``String`` - WebIDL ``USVString``
129 * ``Boolean`` - WebIDL ``boolean``
130 * ``Object`` - WebIDL ``object`` (``ClassName`` can be used as a literal for thi s type)
131 * ``ClassName`` - an instance of the class ClassName
132 * ``Class<ClassName>`` - a class ClassName or one of its subclasses (not an inst ance)
133 * ``DictionaryName`` - an instance of the dictionary DictionaryName
134 * ``Promise<Type>`` - WebIDL ``Promise<T>``
135 * ``Generator<Type>`` - An ECMAScript generator function that returns data of th e given type
136 * ``Array<Type>`` - WebIDL ``sequence<T>``
137 * ``Dictionary<Type>`` - unordered set of name-value String-Type pairs with no d uplicate names
138 * ``Type?`` - union of Type and the singleton type with value ``null`` (WebIDL n ullable)
139 * ``(Type1 or Type2)`` - union of Type1 and Type2 (WebIDL union)
140 * ``any`` - union of all types (WebIDL ``any``)
141
142 Methods that return nothing (undefined, in JS) use the keyword "void"
143 instead of a type.
144
145
146 TODO(ianh): Define in detail how this actually works
147
148
149 Mojom IDL
150 ---------
151
152 The Mojom IDL language is used to describe the APIs exposed over Mojo
153 pipes.
154
155 Mojom IDL definitions are typically compiled to wrappers in each
156 language, which are then used as imports.
157
158 TODO(ianh): Define in detail how this actually works
OLDNEW
« no previous file with comments | « sky/specs/dom.md ('k') | sky/specs/markup.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698