| OLD | NEW |
| 1 JavaScript Mojo Example Applications | 1 JavaScript Mojo Example Applications |
| 2 ===================== | 2 ===================== |
| 3 | 3 |
| 4 hello.js, world.js - A minimal application that connects to another. | 4 hello.js, world.js - A minimal application that connects to another. |
| 5 | 5 |
| 6 wget.js - Uses the network service to load a URL. | 6 wget.js - Uses the network service to load a URL. |
| 7 | 7 |
| 8 cube.js - A JS version of examples/sample_app. |
| 8 | 9 |
| 9 --- Running Mojo Applications --- | 10 --- Running Mojo Applications --- |
| 10 | 11 |
| 11 A Mojo application written in JavaScript is launched with mojo_shell like this: | 12 A Mojo application written in JavaScript is launched with mojo_shell like this: |
| 12 | 13 |
| 13 mojo_shell <js-application-url> | 14 mojo_shell <js-application-url> |
| 14 | 15 |
| 15 Where js-application-url is either a file or an http URL that names a JS source | 16 Where js-application-url is a URL understood by the shell. For example |
| 16 file. The JS file itself must begin with a Mojo "shebang" that specifies the | 17 a file or an http URL that names a JS source file. The JS file itself |
| 17 Mojo URL of the JS content handler. In other words, the first line of the JS | 18 must begin with a Mojo "shebang" that specifies the Mojo URL of the JS |
| 18 source file must be: | 19 content handler. In other words, the first line of the JS source file |
| 20 must be: |
| 19 | 21 |
| 20 #!mojo:js_content_handler | 22 #!mojo:js_content_handler |
| 21 | 23 |
| 22 Following the shebang should be a single AMD module called "main" whose value | 24 Following the shebang should be a single AMD module called "main" whose value |
| 23 is an Application subclass. The JS content handler will create an instance of | 25 is an Application subclass. The JS content handler will create an instance of |
| 24 the Application and make it the client of the Mojo shell. The JS content handler | 26 the Application and make it the client of the Mojo shell. The JS content handler |
| 25 is itself a Mojo application and it's responsible for creating an instance of V8 | 27 is itself a Mojo application and it's responsible for creating an instance of V8 |
| 26 and loading the "main" JS module and all of the modules the main module | 28 and loading the "main" JS module and all of the modules the main module |
| 27 depends on. | 29 depends on. |
| 28 | 30 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 response parameter. In the EchoString case that would be something like | 190 response parameter. In the EchoString case that would be something like |
| 189 {value: "foo"}. | 191 {value: "foo"}. |
| 190 | 192 |
| 191 Similarly, the implementation of a Mojo interface functions that specify a | 193 Similarly, the implementation of a Mojo interface functions that specify a |
| 192 response, must return a Promise. The implementation of EchoString() could | 194 response, must return a Promise. The implementation of EchoString() could |
| 193 be written like this: | 195 be written like this: |
| 194 | 196 |
| 195 MyEchoStringImpl.prototype.EchoString = function(s) { | 197 MyEchoStringImpl.prototype.EchoString = function(s) { |
| 196 return Promise.resolve({value: s}); | 198 return Promise.resolve({value: s}); |
| 197 }; | 199 }; |
| OLD | NEW |