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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return JavaScriptDecodeSnippet(mojom.INT32) | 113 return JavaScriptDecodeSnippet(mojom.INT32) |
114 | 114 |
115 | 115 |
116 def JavaScriptEncodeSnippet(kind): | 116 def JavaScriptEncodeSnippet(kind): |
117 if kind in mojom.PRIMITIVES: | 117 if kind in mojom.PRIMITIVES: |
118 return "encodeStruct(%s, " % CodecType(kind) | 118 return "encodeStruct(%s, " % CodecType(kind) |
119 if isinstance(kind, mojom.Struct): | 119 if isinstance(kind, mojom.Struct): |
120 return "encodeStructPointer(%s, " % CodecType(kind.name) | 120 return "encodeStructPointer(%s, " % CodecType(kind.name) |
121 if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL: | 121 if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL: |
122 return "encodeBoolArrayPointer("; | 122 return "encodeBoolArrayPointer("; |
123 if isinstance(kind, mojom.Array): | 123 if isinstance(kind, (mojom.Array, mojom.FixedArray)): |
124 return "encodeArrayPointer(%s, " % CodecType(kind.kind) | 124 return "encodeArrayPointer(%s, " % CodecType(kind.kind) |
125 if isinstance(kind, mojom.Interface) or \ | 125 if isinstance(kind, mojom.Interface) or \ |
126 isinstance(kind, mojom.InterfaceRequest): | 126 isinstance(kind, mojom.InterfaceRequest): |
127 return JavaScriptEncodeSnippet(mojom.MSGPIPE) | 127 return JavaScriptEncodeSnippet(mojom.MSGPIPE) |
128 if isinstance(kind, mojom.Enum): | 128 if isinstance(kind, mojom.Enum): |
129 return JavaScriptEncodeSnippet(mojom.INT32) | 129 return JavaScriptEncodeSnippet(mojom.INT32) |
130 | 130 |
131 | 131 |
132 def TranslateConstants(token): | 132 def TranslateConstants(token): |
133 if isinstance(token, (mojom.EnumValue, mojom.NamedValue)): | 133 if isinstance(token, (mojom.EnumValue, mojom.NamedValue)): |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 self.Write(self.GenerateJsModule(), "%s.js" % self.module.name) | 183 self.Write(self.GenerateJsModule(), "%s.js" % self.module.name) |
184 | 184 |
185 def GetImports(self): | 185 def GetImports(self): |
186 # Since each import is assigned a variable in JS, they need to have unique | 186 # Since each import is assigned a variable in JS, they need to have unique |
187 # names. | 187 # names. |
188 counter = 1 | 188 counter = 1 |
189 for each in self.module.imports: | 189 for each in self.module.imports: |
190 each["unique_name"] = "import" + str(counter) | 190 each["unique_name"] = "import" + str(counter) |
191 counter += 1 | 191 counter += 1 |
192 return self.module.imports | 192 return self.module.imports |
OLD | NEW |