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

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

Issue 694843003: Specs: default arguments (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « no previous file | sky/specs/design.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 APIs 1 APIs
2 ==== 2 ====
3 3
4 The Sky core API 4 The Sky core API
5 ---------------- 5 ----------------
6 6
7 ```javascript 7 ```javascript
8 module 'sky:core' { 8 module 'sky:core' {
9 9
10 // EVENTS 10 // EVENTS
11 11
12 class Event { 12 class Event {
13 constructor (String type, Boolean bubbles, any data); // O(1) 13 constructor (String type, Boolean bubbles = true, any data = null); // O(1)
14 readonly attribute String type; // O(1) 14 readonly attribute String type; // O(1)
15 readonly attribute Boolean bubbles; // O(1) 15 readonly attribute Boolean bubbles; // O(1)
16 attribute any data; // O(1) 16 attribute any data; // O(1)
17 17
18 readonly attribute EventTarget target; // O(1) 18 readonly attribute EventTarget target; // O(1)
19 void preventDefault(); // O(1) 19 void preventDefault(); // O(1)
20 attribute any result; // O(1) // defaults to undefined 20 attribute any result; // O(1) // defaults to undefined
21 21
22 // TODO(ianh): do events get blocked at scope boundaries, e.g. focus events when both sides are in the scope? 22 // TODO(ianh): do events get blocked at scope boundaries, e.g. focus events when both sides are in the scope?
23 // TODO(ianh): do events ger retargetted, e.g. focus when leaving a custom e lement? 23 // TODO(ianh): do events ger retargetted, e.g. focus when leaving a custom e lement?
(...skipping 29 matching lines...) Expand all
53 readonly attribute ParentNode? parentNode; // O(1) 53 readonly attribute ParentNode? parentNode; // O(1)
54 readonly attribute Element? parentElement; // O(1) // if parentNode isn't an element, returns null 54 readonly attribute Element? parentElement; // O(1) // if parentNode isn't an element, returns null
55 readonly attribute ChildNode? previousSibling; // O(1) 55 readonly attribute ChildNode? previousSibling; // O(1)
56 readonly attribute ChildNode? nextSibling; // O(1) 56 readonly attribute ChildNode? nextSibling; // O(1)
57 57
58 // the following all throw if parentNode is null 58 // the following all throw if parentNode is null
59 void insertBefore(ChildArgument... nodes); // O(N) in number of arguments pl us all their descendants 59 void insertBefore(ChildArgument... nodes); // O(N) in number of arguments pl us all their descendants
60 void insertAfter(ChildArgument... nodes); // O(N) in number of arguments plu s all their descendants 60 void insertAfter(ChildArgument... nodes); // O(N) in number of arguments plu s all their descendants
61 void replaceWith(ChildArgument... nodes); // O(N) in number of descendants p lus arguments plus all their descendants 61 void replaceWith(ChildArgument... nodes); // O(N) in number of descendants p lus arguments plus all their descendants
62 void remove(); // O(N) in number of descendants 62 void remove(); // O(N) in number of descendants
63 Node cloneNode(Boolean deep); // O(1) if deep=false, O(N) in the number of d escendants if deep=true 63 Node cloneNode(Boolean deep = false); // O(1) if deep=false, O(N) in the num ber of descendants if deep=true
64 64
65 // called when parentNode changes 65 // called when parentNode changes
66 virtual void parentChangeCallback(ParentNode? oldParent, ParentNode? newPare nt, ChildNode? previousSibling, ChildNode? nextSibling); // O(N) in descendants (calls attached/detached) 66 virtual void parentChangeCallback(ParentNode? oldParent, ParentNode? newPare nt, ChildNode? previousSibling, ChildNode? nextSibling); // O(N) in descendants (calls attached/detached)
67 virtual void attachedCallback(); // noop 67 virtual void attachedCallback(); // noop
68 virtual void detachedCallback(); // noop 68 virtual void detachedCallback(); // noop
69 } 69 }
70 70
71 abstract class ParentNode : Node { 71 abstract class ParentNode : Node {
72 readonly attribute ChildNode? firstChild; // O(1) 72 readonly attribute ChildNode? firstChild; // O(1)
73 readonly attribute ChildNode? lastChild; // O(1) 73 readonly attribute ChildNode? lastChild; // O(1)
74 74
75 // Returns a new Array every time. 75 // Returns a new Array every time.
76 Array<ChildNode> getChildNodes(); // O(N) in number of child nodes 76 Array<ChildNode> getChildNodes(); // O(N) in number of child nodes
77 Array<Element> getChildElements(); // O(N) in number of child nodes // TODO( ianh): might not be necessary if we have the parser drop unnecessary whitespace text nodes 77 Array<Element> getChildElements(); // O(N) in number of child nodes // TODO( ianh): might not be necessary if we have the parser drop unnecessary whitespace text nodes
78 78
79 void append(ChildArgument... nodes); // O(N) in number of arguments plus all their descendants 79 void append(ChildArgument... nodes); // O(N) in number of arguments plus all their descendants
80 void prepend(ChildArgument... nodes); // O(N) in number of arguments plus al l their descendants 80 void prepend(ChildArgument... nodes); // O(N) in number of arguments plus al l their descendants
81 void replaceChildrenWith(ChildArgument... nodes); // O(N) in number of desce ndants plus arguments plus all their descendants 81 void replaceChildrenWith(ChildArgument... nodes); // O(N) in number of desce ndants plus arguments plus all their descendants
82 } 82 }
83 83
84 class Attr { 84 class Attr {
85 constructor (String name, String value); // O(1) 85 constructor (String name, String value = ''); // O(1)
86 readonly attribute String name; // O(1) 86 readonly attribute String name; // O(1)
87 readonly attribute String value; // O(1) 87 readonly attribute String value; // O(1)
88 } 88 }
89 89
90 abstract class Element : ParentNode { 90 abstract class Element : ParentNode {
91 readonly attribute String tagName; // O(1) 91 readonly attribute String tagName; // O(1)
92 92
93 Boolean hasAttribute(String name); // O(N) in arguments 93 Boolean hasAttribute(String name); // O(N) in arguments
94 String getAttribute(String name); // O(N) in arguments 94 String getAttribute(String name); // O(N) in arguments
95 void setAttribute(String name, String value); // O(N) in arguments 95 void setAttribute(String name, String value = ''); // O(N) in arguments
96 void removeAttribute(String name); // O(N) in arguments 96 void removeAttribute(String name); // O(N) in arguments
97 97
98 // Returns a new Array and new Attr instances every time. 98 // Returns a new Array and new Attr instances every time.
99 Array<Attr> getAttributes(); // O(N) in arguments 99 Array<Attr> getAttributes(); // O(N) in arguments
100 100
101 readonly attribute ShadowRoot? shadowRoot; // O(1) // returns the shadow roo t 101 readonly attribute ShadowRoot? shadowRoot; // O(1) // returns the shadow roo t
102 Array<ContentElement> getDestinationInsertionPoints(); // O(N) in number of insertion points the node is in 102 Array<ContentElement> getDestinationInsertionPoints(); // O(N) in number of insertion points the node is in
103 103
104 virtual void attributeChangeCallback(String name, String? oldValue, String? newValue); // noop 104 virtual void attributeChangeCallback(String name, String? oldValue, String? newValue); // noop
105 // TODO(ianh): does a node ever need to know when it's been redistributed? 105 // TODO(ianh): does a node ever need to know when it's been redistributed?
106 } 106 }
107 107
108 class Text : Node { 108 class Text : Node {
109 constructor (String value); // O(1) 109 constructor (String value = ''); // O(1)
110 attribute String value; // O(1) 110 attribute String value; // O(1)
111 111
112 void replaceWith(String node); // O(1) // special case override of Node.repl aceWith() 112 void replaceWith(String node); // O(1) // special case override of Node.repl aceWith()
113 113
114 virtual void valueChangeCallback(String? oldValue, String? newValue); // noo p 114 virtual void valueChangeCallback(String? oldValue, String? newValue); // noo p
115 } 115 }
116 116
117 class DocumentFragment : ParentNode { 117 class DocumentFragment : ParentNode {
118 constructor (ChildArguments... nodes); // O(N) in number of arguments plus a ll their descendants 118 constructor (ChildArguments... nodes); // O(N) in number of arguments plus a ll their descendants
119 } 119 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 constructor (Dictionary attributes, ChildArguments... nodes); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants 203 constructor (Dictionary attributes, ChildArguments... nodes); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants
204 constructor (ChildArguments... nodes); // shorthand 204 constructor (ChildArguments... nodes); // shorthand
205 constructor (Dictionary attributes); // shorthand 205 constructor (Dictionary attributes); // shorthand
206 constructor (); // shorthand 206 constructor (); // shorthand
207 } 207 }
208 208
209 209
210 210
211 dictionary ElementRegistration { 211 dictionary ElementRegistration {
212 String tagName; 212 String tagName;
213 Boolean shadow; 213 Boolean shadow = false;
214 Object prototype; 214 Object prototype = Element;
215 } 215 }
216 216
217 interface ElementConstructor { 217 interface ElementConstructor {
218 constructor (Dictionary attributes, ChildArguments... nodes); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants 218 constructor (Dictionary attributes, ChildArguments... nodes); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants
219 constructor (ChildArguments... nodes); // shorthand 219 constructor (ChildArguments... nodes); // shorthand
220 constructor (Dictionary attributes); // shorthand 220 constructor (Dictionary attributes); // shorthand
221 constructor (); // shorthand 221 constructor (); // shorthand
222 222
223 constructor attribute String tagName; 223 constructor attribute String tagName;
224 } 224 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // properties 308 // properties
309 readonly attribute ReturnType attributeName; // getter 309 readonly attribute ReturnType attributeName; // getter
310 attribute ReturnType attributeName; // getter and setter 310 attribute ReturnType attributeName; // getter and setter
311 311
312 // methods and constructors 312 // methods and constructors
313 constructor (); 313 constructor ();
314 ReturnType method(); 314 ReturnType method();
315 // When the platform calls this method, it always invokes the "real" metho d, even if it's been 315 // When the platform calls this method, it always invokes the "real" metho d, even if it's been
316 // deleted from the prototypes (as if it took a reference to the method at startup, and stored 316 // deleted from the prototypes (as if it took a reference to the method at startup, and stored
317 // state using Symbols) 317 // state using Symbols)
318 // Calling a method with fewer arguments than defined will throw.
319 // Calling a method with more arguments ignores the extra arguments.
318 virtual ReturnType methodCallback(); 320 virtual ReturnType methodCallback();
319 // when the platform calls this, it actually calls it the way JS would, so author overrides do 321 // when the platform calls this, it actually calls it the way JS would, so author overrides do
320 // affect what gets called. Make sure if you override it that you call the superclass implementation! 322 // affect what gets called. Make sure if you override it that you call the superclass implementation!
321 // The default implementations of 'virtual' methods all end by calling the identically named method 323 // The default implementations of 'virtual' methods all end by calling the identically named method
322 // on the superclass, if there is such a method. 324 // on the superclass, if there is such a method.
323 325
324 // properties on the constructor 326 // properties on the constructor
325 constructor readonly attribute ReturnType staticName; 327 constructor readonly attribute ReturnType staticName;
326 328
327 // private APIs - see below 329 // private APIs - see below
328 private void method(); 330 private void method();
329 331
330 // arguments and overloading are done as follows 332 // arguments and overloading are done as follows
331 // note that the argument names are only for documentation purposes 333 // note that the argument names are only for documentation purposes
332 ReturnType method(ArgumentType argumentName1, ArgumentType argumentName2); 334 ReturnType method(ArgumentType argumentName1, ArgumentType argumentName2);
333 // the last argument's type can have "..." appended to it to indicate a vara rgs-like situation 335 // the last argument's type can have "..." appended to it to indicate a vara rgs-like situation
334 ReturnType method(ArgumentType argumentName1, ArgumentType... allSubsequentA rguments); 336 ReturnType method(ArgumentType argumentName1, ArgumentType... allSubsequentA rguments);
337 // trailing arguments can have a default value, which must be a literal of t he given type
338 ReturnType method(ArgumentType argumentName1, ArgumentType argumentName2 = d efaultValue);
335 } 339 }
336 340
337 dictionary Options { 341 dictionary Options {
338 String foo; 342 String foo; // if there's no default, the property must be specified or it's a TypeError
339 Integer bar; 343 Integer bar = 4; // properties can have default values
340 } 344 }
341 345
342 // the module can have properties and methods also 346 // the module can have properties and methods also
343 attribute String Foo; 347 attribute String Foo;
344 void method(); 348 void method();
345 349
346 interface InterfaceName { 350 interface InterfaceName {
347 // describes a template of a prototype, in the same syntax as a class 351 // describes a template of a prototype, in the same syntax as a class
348 // not actually exposed in the runtime 352 // not actually exposed in the runtime
349 } 353 }
(...skipping 27 matching lines...) Expand all
377 ``` 381 ```
378 382
379 ### Types ### 383 ### Types ###
380 384
381 The following types are available: 385 The following types are available:
382 386
383 * ``Integer`` - WebIDL ``long long`` 387 * ``Integer`` - WebIDL ``long long``
384 * ``Float`` - WebIDL ``double`` 388 * ``Float`` - WebIDL ``double``
385 * ``String`` - WebIDL ``USVString`` 389 * ``String`` - WebIDL ``USVString``
386 * ``Boolean`` - WebIDL ``boolean`` 390 * ``Boolean`` - WebIDL ``boolean``
387 # ``Object`` - WebIDL ``object`` 391 # ``Object`` - WebIDL ``object`` (``ClassName`` can be used as a literal for thi s type)
388 * ``ClassName`` - an instance of the class ClassName 392 * ``ClassName`` - an instance of the class ClassName
389 * ``DictionaryName`` - an instance of the dictionary DictionaryName 393 * ``DictionaryName`` - an instance of the dictionary DictionaryName
390 * ``Promise<Type>`` - WebIDL ``Promise<T>`` 394 * ``Promise<Type>`` - WebIDL ``Promise<T>``
391 * ``Array<Type>`` - WebIDL ``sequence<T>`` 395 * ``Array<Type>`` - WebIDL ``sequence<T>``
392 * ``Dictionary`` - unordered set of name-value String-String pairs with no dupli cate names 396 * ``Dictionary`` - unordered set of name-value String-String pairs with no dupli cate names
393 * ``Type?`` - union of Type and the singleton type with value "null" (WebIDL nul lable) 397 * ``Type?`` - union of Type and the singleton type with value ``null`` (WebIDL n ullable)
394 * ``(Type1 or Type2)`` - union of Type1 and Type2 (WebIDL union) 398 * ``(Type1 or Type2)`` - union of Type1 and Type2 (WebIDL union)
395 * ``any`` - union of all types (WebIDL ``any``) 399 * ``any`` - union of all types (WebIDL ``any``)
396 400
397 Methods that return nothing (undefined, in JS) use the keyword "void" 401 Methods that return nothing (undefined, in JS) use the keyword "void"
398 instead of a type. 402 instead of a type.
399 403
400 TODO(ianh): Figure out what should happen with omitted and extraneous parameters
401 404
402 TODO(ianh): Define in detail how this actually works 405 TODO(ianh): Define in detail how this actually works
403 406
404 407
405 Mojom IDL 408 Mojom IDL
406 --------- 409 ---------
407 410
408 The Mojom IDL language is used to describe the APIs exposed over Mojo 411 The Mojom IDL language is used to describe the APIs exposed over Mojo
409 pipes. 412 pipes.
410 413
(...skipping 12 matching lines...) Expand all
423 the core mojo fabric JS API sky:mojo:fabric:core 426 the core mojo fabric JS API sky:mojo:fabric:core
424 the asyncWait/cancelWait mojo fabric JS API (interface to IPC thread) sky:moj o:fabric:ipc 427 the asyncWait/cancelWait mojo fabric JS API (interface to IPC thread) sky:moj o:fabric:ipc
425 the mojom for the shell, proxying through C++ so that the shell pipe isn't exp osed sky:mojo:shell 428 the mojom for the shell, proxying through C++ so that the shell pipe isn't exp osed sky:mojo:shell
426 the sky API sky:core 429 the sky API sky:core
427 the sky debug symbols for private APIs sky:debug 430 the sky debug symbols for private APIs sky:debug
428 ``` 431 ```
429 432
430 TODO(ianh): determine if we want to separate the "this" from the 433 TODO(ianh): determine if we want to separate the "this" from the
431 Document, especially for Modules, so that exposing a module's element 434 Document, especially for Modules, so that exposing a module's element
432 doesn't expose the module's exports attribute. 435 doesn't expose the module's exports attribute.
OLDNEW
« no previous file with comments | « no previous file | sky/specs/design.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698