| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 # NamespaceUid.Struct[.Enum].CONSTANT_NAME | 191 # NamespaceUid.Struct[.Enum].CONSTANT_NAME |
| 192 name = [] | 192 name = [] |
| 193 if token.imported_from: | 193 if token.imported_from: |
| 194 name.append(token.imported_from["unique_name"]) | 194 name.append(token.imported_from["unique_name"]) |
| 195 if token.parent_kind: | 195 if token.parent_kind: |
| 196 name.append(token.parent_kind.name) | 196 name.append(token.parent_kind.name) |
| 197 if isinstance(token, mojom.EnumValue): | 197 if isinstance(token, mojom.EnumValue): |
| 198 name.append(token.enum_name) | 198 name.append(token.enum_name) |
| 199 name.append(token.name) | 199 name.append(token.name) |
| 200 return ".".join(name) | 200 return ".".join(name) |
| 201 |
| 202 if isinstance(token, mojom.BuiltinValue): |
| 203 if token.value == "double.INFINITY" or token.value == "float.INFINITY": |
| 204 return "Infinity"; |
| 205 if token.value == "double.NEGATIVE_INFINITY" or \ |
| 206 token.value == "float.NEGATIVE_INFINITY": |
| 207 return "-Infinity"; |
| 208 if token.value == "double.NAN" or token.value == "float.NAN": |
| 209 return "NaN"; |
| 210 |
| 201 return token | 211 return token |
| 202 | 212 |
| 203 | 213 |
| 204 def ExpressionToText(value): | 214 def ExpressionToText(value): |
| 205 return TranslateConstants(value) | 215 return TranslateConstants(value) |
| 206 | 216 |
| 207 | 217 |
| 208 def IsArrayPointerField(field): | 218 def IsArrayPointerField(field): |
| 209 return mojom.IsAnyArrayKind(field.kind) | 219 return mojom.IsAnyArrayKind(field.kind) |
| 210 | 220 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 self.Write(self.GenerateJsModule(), "%s.js" % self.module.name) | 266 self.Write(self.GenerateJsModule(), "%s.js" % self.module.name) |
| 257 | 267 |
| 258 def GetImports(self): | 268 def GetImports(self): |
| 259 # Since each import is assigned a variable in JS, they need to have unique | 269 # Since each import is assigned a variable in JS, they need to have unique |
| 260 # names. | 270 # names. |
| 261 counter = 1 | 271 counter = 1 |
| 262 for each in self.module.imports: | 272 for each in self.module.imports: |
| 263 each["unique_name"] = "import" + str(counter) | 273 each["unique_name"] = "import" + str(counter) |
| 264 counter += 1 | 274 counter += 1 |
| 265 return self.module.imports | 275 return self.module.imports |
| OLD | NEW |