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

Side by Side Diff: mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl

Issue 2965803003: Mojo JS bindings: add support to generate "dual-mode" code. (Closed)
Patch Set: . Created 3 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 {%- if use_new_js_bindings %} 5 {%- if js_bindings_mode == "both" or js_bindings_mode == "new" %}
6 {{"new"|set_current_mode}}
6 7
7 'use strict'; 8 'use strict';
8 9
10 {%- if js_bindings_mode == "both" %}
11 if ((typeof mojo !== 'undefined') && mojo.internal && mojo.config) {
12 {%- endif %}
13
9 (function() { 14 (function() {
10 var mojomId = '{{module.path}}'; 15 var mojomId = '{{module.path}}';
11 if (mojo.internal.isMojomLoaded(mojomId)) { 16 if (mojo.internal.isMojomLoaded(mojomId)) {
12 console.warn('The following mojom is loaded multiple times: ' + mojomId); 17 console.warn('The following mojom is loaded multiple times: ' + mojomId);
13 return; 18 return;
14 } 19 }
15 mojo.internal.markMojomLoaded(mojomId); 20 mojo.internal.markMojomLoaded(mojomId);
16 21
17 // TODO(yzshen): Define these aliases to minimize the differences between the 22 // TODO(yzshen): Define these aliases to minimize the differences between the
18 // old/new modes. Remove them when the old mode goes away. 23 // old/new modes. Remove them when the old mode goes away.
19 var bindings = mojo; 24 var bindings = mojo;
20 var associatedBindings = mojo; 25 var associatedBindings = mojo;
21 var codec = mojo.internal; 26 var codec = mojo.internal;
22 var validator = mojo.internal; 27 var validator = mojo.internal;
23 28
29 var exports = mojo.internal.exposeNamespace('{{module.namespace}}');
30
24 {%- for import in imports %} 31 {%- for import in imports %}
25 var {{import.unique_name}} = 32 var {{import.unique_name}} =
26 mojo.internal.exposeNamespace('{{import.namespace}}'); 33 mojo.internal.exposeNamespace('{{import.namespace}}');
27 if (mojo.config.autoLoadMojomDeps) { 34 if (mojo.config.autoLoadMojomDeps) {
28 mojo.internal.loadMojomIfNecessary( 35 mojo.internal.loadMojomIfNecessary(
29 '{{import.path}}', 36 '{{import.path}}',
30 new URL('{{import|get_relative_url(module)}}.js', 37 new URL('{{import|get_relative_url(module)}}.js',
31 document.currentScript.src).href); 38 document.currentScript.src).href);
32 } 39 }
33 {%- endfor %} 40 {%- endfor %}
34 41
35 {% include "module_definition.tmpl" %} 42 {% include "module_definition.tmpl" %}
36 })(); 43 })();
37 44
38 {%- else %} 45 {%- if js_bindings_mode == "both" %}
46 }
47 {%- endif %}
48
49 {%- endif %}
50
51 {%- if js_bindings_mode == "both" or js_bindings_mode == "old" %}
52 {{"old"|set_current_mode}}
53
54 {%- if js_bindings_mode == "both" %}
55 if ((typeof mojo === 'undefined') || !mojo.internal || !mojo.config) {
56 {%- endif %}
39 57
40 define("{{module.path}}", [ 58 define("{{module.path}}", [
41 {%- if module.path != 59 {%- if module.path !=
42 "mojo/public/interfaces/bindings/interface_control_messages.mojom" and 60 "mojo/public/interfaces/bindings/interface_control_messages.mojom" and
43 module.path != 61 module.path !=
44 "mojo/public/interfaces/bindings/pipe_control_messages.mojom" %} 62 "mojo/public/interfaces/bindings/pipe_control_messages.mojom" %}
45 "mojo/public/js/associated_bindings", 63 "mojo/public/js/associated_bindings",
46 "mojo/public/js/bindings", 64 "mojo/public/js/bindings",
47 {%- endif %} 65 {%- endif %}
48 "mojo/public/js/codec", 66 "mojo/public/js/codec",
49 "mojo/public/js/core", 67 "mojo/public/js/core",
50 "mojo/public/js/validator", 68 "mojo/public/js/validator",
51 {%- for import in imports %} 69 {%- for import in imports %}
52 "{{import.path}}", 70 "{{import.path}}",
53 {%- endfor %} 71 {%- endfor %}
54 ], function( 72 ], function(
55 {%- if module.path != 73 {%- if module.path !=
56 "mojo/public/interfaces/bindings/interface_control_messages.mojom" and 74 "mojo/public/interfaces/bindings/interface_control_messages.mojom" and
57 module.path != 75 module.path !=
58 "mojo/public/interfaces/bindings/pipe_control_messages.mojom" -%} 76 "mojo/public/interfaces/bindings/pipe_control_messages.mojom" -%}
59 associatedBindings, bindings, {% endif -%} 77 associatedBindings, bindings, {% endif -%}
60 codec, core, validator 78 codec, core, validator
61 {%- for import in imports -%} 79 {%- for import in imports -%}
62 , {{import.unique_name}} 80 , {{import.unique_name}}
63 {%- endfor -%} 81 {%- endfor -%}
64 ) { 82 ) {
83 var exports = {};
65 84
66 {%- include "module_definition.tmpl" %} 85 {%- include "module_definition.tmpl" %}
67 86
68 return exports; 87 return exports;
69 }); 88 });
70 89
90 {%- if js_bindings_mode == "both" %}
91 }
92 {%- endif %}
93
71 {%- endif %} 94 {%- endif %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698