| OLD | NEW |
| 1 Sky Module System | 1 Sky Module System |
| 2 ================= | 2 ================= |
| 3 | 3 |
| 4 This document describes the Sky module system. | 4 This document describes the Sky module system. |
| 5 | 5 |
| 6 Overview | 6 Overview |
| 7 -------- | 7 -------- |
| 8 | 8 |
| 9 The Sky module system is based on the ``import`` element. In its | 9 The Sky module system is based on the ``import`` element. In its |
| 10 most basic form, you import a module as follows: | 10 most basic form, you import a module as follows: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 ### IDL ### | 50 ### IDL ### |
| 51 | 51 |
| 52 ```javascript | 52 ```javascript |
| 53 dictionary InternalElementOptions { | 53 dictionary InternalElementOptions { |
| 54 String tagName; | 54 String tagName; |
| 55 Boolean shadow = false; | 55 Boolean shadow = false; |
| 56 Object prototype = Element; | 56 Object prototype = Element; |
| 57 } | 57 } |
| 58 interface InternalElementConstructorWithoutShadow { | 58 interface InternalElementConstructorWithoutShadow { |
| 59 constructor (Module module); | 59 constructor (Module hostModule); |
| 60 attribute String tagName; | 60 attribute String tagName; |
| 61 } | 61 } |
| 62 interface InternalElementConstructorWithShadow { | 62 interface InternalElementConstructorWithShadow { |
| 63 constructor (Module module); | 63 constructor (Module hostModule); |
| 64 attribute String tagName; | 64 attribute String tagName; |
| 65 attribute Boolean shadow; | 65 attribute Boolean shadow; |
| 66 } | 66 } |
| 67 typedef ElementRegistrationOptions (InternalElementOptions or | 67 typedef ElementRegistrationOptions (InternalElementOptions or |
| 68 InternalElementConstructorWithoutShadow or | 68 InternalElementConstructorWithoutShadow or |
| 69 InternalElementConstructorWithShadow); | 69 InternalElementConstructorWithShadow); |
| 70 | 70 |
| 71 abstract class AbstractModule : EventTarget { | 71 abstract class AbstractModule : EventTarget { |
| 72 readonly attribute Document document; // O(1) // the Documentof the module or
application | 72 readonly attribute Document document; // O(1) // the Document of the module or
application |
| 73 Promise<any> import(String url); // O(Yikes) // returns the module's exports | 73 Promise<any> import(String url); // O(Yikes) // returns the module's exports |
| 74 private Array<Module> getImports(); O(N) // returns the Module objects of all
the imported modules | 74 private Array<Module> getImports(); O(N) // returns the Module objects of all
the imported modules |
| 75 | 75 |
| 76 readonly attribute String url; | 76 readonly attribute String url; |
| 77 | 77 |
| 78 ElementConstructor registerElement(Object options); // O(1) | 78 ElementConstructor registerElement(Object options); // O(1) |
| 79 // if you call registerElement() with an object that was created by | 79 // if you call registerElement() with an object that was created by |
| 80 // registerElement(), it just returns the object after registering it, | 80 // registerElement(), it just returns the object after registering it, |
| 81 // rather than creating a new constructor | 81 // rather than creating a new constructor |
| 82 // otherwise, it proceeds as follows: | 82 // otherwise, it proceeds as follows: |
| 83 // - if options is a Function (i.e. it is either an | 83 // - if options is a Function (i.e. it is either an |
| 84 // InternalElementConstructorWithoutShadow object or an | 84 // InternalElementConstructorWithoutShadow object or an |
| 85 // InternalElementConstructorWithShadow object), then let | 85 // InternalElementConstructorWithShadow object), then let |
| 86 // constructor be that function, and let prototype be that | 86 // constructor be that function, and let prototype be that |
| 87 // functions's prototype; otherwise, let constructor be a no-op | 87 // functions's prototype; otherwise, let constructor be a no-op |
| 88 // function and let prototype be the prototype property of the | 88 // function and let prototype be the prototype property of the |
| 89 // object passed in (the InternalElementOptions; prototype | 89 // object passed in (the InternalElementOptions; prototype |
| 90 // defaults to Element). | 90 // defaults to Element). |
| 91 // - let shadow be option's shadow property's value coerced to a | 91 // - let shadow be option's shadow property's value coerced to a |
| 92 // boolean, if the property is present, or else the value false. | 92 // boolean, if the property is present, or else the value false. |
| 93 // - let shadow be option's tagName property's value. | 93 // - let tagName be option's tagName property's value. |
| 94 // - create a new Function that: | 94 // - create a new Function that acts as if it had the signature of |
| 95 // - throws if not called as a constructor | 95 // the constructors in the ElementConstructor interface, and that |
| 96 // - creates an actual element object (the C++-backed object) | 96 // runs the follows steps when called: |
| 97 // - initialises the shadow tree if shadow on the options is | 97 // - throw if not called as a constructor |
| 98 // true | 98 // - create an actual element object (the C++-backed object) |
| 99 // - calls constructor, if it's not null, with the module as | 99 // called tagName, along with the specified attributes |
| 100 // the argument | 100 // - initialise the shadow tree if shadow is true |
| 101 // - is marked as created by registerElement() so that it can | 101 // - call constructor, if it's not null, with the module |
| 102 // be recognised if used as an argument to registerElement() | 102 // within which the new element is being constructed as the |
| 103 // argument |
| 104 // - append all the specified children |
| 105 // - mark that new Function as created by registerElement() so that |
| 106 // it can be recognised if used as an argument to |
| 107 // registerElement() |
| 103 // - let that new Function's prototype be the aforementioned prototype | 108 // - let that new Function's prototype be the aforementioned prototype |
| 104 // - let that new Function have tagName and shadow properties set to | 109 // - let that new Function have tagName and shadow properties set to |
| 105 // the aforementioned tagName and shadow | 110 // the aforementioned tagName and shadow |
| 106 // - register the new tagName with this constructor | 111 // - register the new tagName with this constructor |
| 107 // - return the new Function (which is, not coincidentally, an | 112 // - return the new Function (which is, not coincidentally, an |
| 108 // InternalElementConstructorWithShadow) | 113 // InternalElementConstructorWithShadow) |
| 109 | 114 |
| 110 readonly attribute ScriptElement? currentScript; // O(1) // returns the <scrip
t> element currently being executed if any, and if it's in this module; else nul
l | 115 readonly attribute ScriptElement? currentScript; // O(1) // returns the <scrip
t> element currently being executed if any, and if it's in this module; else nul
l |
| 111 } | 116 } |
| 112 | 117 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 Where ``name_1`` through ``name_n`` are the names bound to the | 150 Where ``name_1`` through ``name_n`` are the names bound to the |
| 146 various named imports in the script element's document, | 151 various named imports in the script element's document, |
| 147 ``source_code`` is the text content of the script element, | 152 ``source_code`` is the text content of the script element, |
| 148 ``source_module`` is the ``Module`` object of the script element's | 153 ``source_module`` is the ``Module`` object of the script element's |
| 149 module, and ``value_1`` through ``value_n`` are the values | 154 module, and ``value_1`` through ``value_n`` are the values |
| 150 exported by the various named imports in the script element's | 155 exported by the various named imports in the script element's |
| 151 document. | 156 document. |
| 152 | 157 |
| 153 When an import fails to load, the ``as`` name for the import gets | 158 When an import fails to load, the ``as`` name for the import gets |
| 154 bound to ``undefined``. | 159 bound to ``undefined``. |
| OLD | NEW |