Index: mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl |
diff --git a/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl b/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl |
index cf349765ac067c8edd81e84529b58ebfa96cec25..6532824c40434e9809daa4802efd8bb5c9b39afc 100644 |
--- a/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl |
+++ b/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl |
@@ -4,16 +4,32 @@ |
{%- if use_new_js_bindings %} |
-"use strict"; |
+'use strict'; |
(function() { |
+ var mojomId = '{{module.path}}'; |
+ if (mojoBindings.internal.isMojomLoaded(mojomId)) { |
+ console.warn('The following mojom is loaded multiple times: ' + mojomId); |
+ return; |
+ } |
+ mojoBindings.internal.markMojomLoaded(mojomId); |
+ |
// TODO(yzshen): Define these aliases to minimize the differences between the |
// old/new modes. Remove them when the old mode goes away. |
var bindings = mojoBindings; |
var codec = mojoBindings.internal; |
var validator = mojoBindings.internal; |
+ |
{%- for import in imports %} |
- var {{import.unique_name}} = {{import.module.namespace}}; |
+ var {{import.unique_name}} = |
+ mojoBindings.internal.exposeNamespace('{{import.module.namespace}}'); |
+ if (mojoBindings.config.auto_load_mojom_deps) { |
+ mojoBindings.internal.loadMojomIfNecessary( |
+ '{{import.module.path}}', |
+ new URL( |
+ '{{import.module|get_relative_path(module)}}.js', |
+ document.currentScript.src).href); |
+ } |
{%- endfor %} |
{% include "module_definition.tmpl" %} |
@@ -45,4 +61,4 @@ codec, core, validator |
return exports; |
}); |
-{%- endif %} |
+{%- endif %} |