OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """Generates JavaScript source files from a mojom.Module.""" | 5 """Generates JavaScript source files from a mojom.Module.""" |
6 | 6 |
7 import mojom.generate.generator as generator | 7 import mojom.generate.generator as generator |
8 import mojom.generate.module as mojom | 8 import mojom.generate.module as mojom |
9 import mojom.generate.pack as pack | 9 import mojom.generate.pack as pack |
10 from mojom.generate.template_expander import UseJinja | 10 from mojom.generate.template_expander import UseJinja |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 "unions": self.GetUnions(), | 378 "unions": self.GetUnions(), |
379 "interfaces": self.GetInterfaces(), | 379 "interfaces": self.GetInterfaces(), |
380 "imported_interfaces": self.GetImportedInterfaces(), | 380 "imported_interfaces": self.GetImportedInterfaces(), |
381 } | 381 } |
382 | 382 |
383 @UseJinja("js_templates/module.amd.tmpl", filters=js_filters) | 383 @UseJinja("js_templates/module.amd.tmpl", filters=js_filters) |
384 def GenerateAMDModule(self): | 384 def GenerateAMDModule(self): |
385 return self.GetParameters() | 385 return self.GetParameters() |
386 | 386 |
387 def GenerateFiles(self, args): | 387 def GenerateFiles(self, args): |
| 388 if self.variant: |
| 389 raise Exception("Variants not supported in JavaScript bindings.") |
| 390 |
388 self.Write(self.GenerateAMDModule(), | 391 self.Write(self.GenerateAMDModule(), |
389 self.MatchMojomFilePath("%s.js" % self.module.name)) | 392 self.MatchMojomFilePath("%s.js" % self.module.name)) |
390 | 393 |
391 def GetImports(self): | 394 def GetImports(self): |
392 used_names = set() | 395 used_names = set() |
393 for each_import in self.module.imports: | 396 for each_import in self.module.imports: |
394 simple_name = each_import["module_name"].split(".")[0] | 397 simple_name = each_import["module_name"].split(".")[0] |
395 | 398 |
396 # Since each import is assigned a variable in JS, they need to have unique | 399 # Since each import is assigned a variable in JS, they need to have unique |
397 # names. | 400 # names. |
398 unique_name = simple_name | 401 unique_name = simple_name |
399 counter = 0 | 402 counter = 0 |
400 while unique_name in used_names: | 403 while unique_name in used_names: |
401 counter += 1 | 404 counter += 1 |
402 unique_name = simple_name + str(counter) | 405 unique_name = simple_name + str(counter) |
403 | 406 |
404 used_names.add(unique_name) | 407 used_names.add(unique_name) |
405 each_import["unique_name"] = unique_name + "$" | 408 each_import["unique_name"] = unique_name + "$" |
406 counter += 1 | 409 counter += 1 |
407 return self.module.imports | 410 return self.module.imports |
408 | 411 |
409 def GetImportedInterfaces(self): | 412 def GetImportedInterfaces(self): |
410 interface_to_import = {}; | 413 interface_to_import = {}; |
411 for each_import in self.module.imports: | 414 for each_import in self.module.imports: |
412 for each_interface in each_import["module"].interfaces: | 415 for each_interface in each_import["module"].interfaces: |
413 name = each_interface.name | 416 name = each_interface.name |
414 interface_to_import[name] = each_import["unique_name"] + "." + name | 417 interface_to_import[name] = each_import["unique_name"] + "." + name |
415 return interface_to_import; | 418 return interface_to_import; |
416 | 419 |
OLD | NEW |