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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_js_generator.py

Issue 2796253002: Associated Message Validation (Closed)
Patch Set: Validate payloadInterfaceIds before getting it. Use [0] for dimensions for validateArrayPointer. Ca… Created 3 years, 8 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 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 import os 10 import os
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 if mojom.IsUnionKind(field.kind): 60 if mojom.IsUnionKind(field.kind):
61 return "null" 61 return "null"
62 if mojom.IsArrayKind(field.kind): 62 if mojom.IsArrayKind(field.kind):
63 return "null" 63 return "null"
64 if mojom.IsMapKind(field.kind): 64 if mojom.IsMapKind(field.kind):
65 return "null" 65 return "null"
66 if mojom.IsInterfaceKind(field.kind): 66 if mojom.IsInterfaceKind(field.kind):
67 return "new %sPtr()" % JavaScriptType(field.kind) 67 return "new %sPtr()" % JavaScriptType(field.kind)
68 if mojom.IsInterfaceRequestKind(field.kind): 68 if mojom.IsInterfaceRequestKind(field.kind):
69 return "new bindings.InterfaceRequest()" 69 return "new bindings.InterfaceRequest()"
70 if mojom.IsAssociatedKind(field.kind): 70 if mojom.IsAssociatedInterfaceKind(field.kind):
71 return "null" 71 return "new associatedBindings.AssociatedInterfacePtrInfo()"
72 if mojom.IsAssociatedInterfaceRequestKind(field.kind):
73 return "new associatedBindings.AssociatedInterfaceRequest()"
72 if mojom.IsEnumKind(field.kind): 74 if mojom.IsEnumKind(field.kind):
73 return "0" 75 return "0"
74 raise Exception("No valid default: %s" % field) 76 raise Exception("No valid default: %s" % field)
75 77
76 78
77 def JavaScriptPayloadSize(packed): 79 def JavaScriptPayloadSize(packed):
78 packed_fields = packed.packed_fields 80 packed_fields = packed.packed_fields
79 if not packed_fields: 81 if not packed_fields:
80 return 0 82 return 0
81 last_field = packed_fields[-1] 83 last_field = packed_fields[-1]
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return "new codec.%s(%s%s)" % (array_type, element_type, array_length) 129 return "new codec.%s(%s%s)" % (array_type, element_type, array_length)
128 if mojom.IsInterfaceKind(kind): 130 if mojom.IsInterfaceKind(kind):
129 return "new codec.%s(%sPtr)" % ( 131 return "new codec.%s(%sPtr)" % (
130 "NullableInterface" if mojom.IsNullableKind(kind) else "Interface", 132 "NullableInterface" if mojom.IsNullableKind(kind) else "Interface",
131 JavaScriptType(kind)) 133 JavaScriptType(kind))
132 if mojom.IsInterfaceRequestKind(kind): 134 if mojom.IsInterfaceRequestKind(kind):
133 return "codec.%s" % ( 135 return "codec.%s" % (
134 "NullableInterfaceRequest" if mojom.IsNullableKind(kind) 136 "NullableInterfaceRequest" if mojom.IsNullableKind(kind)
135 else "InterfaceRequest") 137 else "InterfaceRequest")
136 if mojom.IsAssociatedInterfaceKind(kind): 138 if mojom.IsAssociatedInterfaceKind(kind):
137 return "codec.AssociatedInterfaceNotSupported" 139 return "codec.%s" % (
140 "NullableAssociatedInterfacePtrInfo" if mojom.IsNullableKind(kind)
141 else "AssociatedInterfacePtrInfo")
138 if mojom.IsAssociatedInterfaceRequestKind(kind): 142 if mojom.IsAssociatedInterfaceRequestKind(kind):
139 return "codec.AssociatedInterfaceRequestNotSupported" 143 return "codec.%s" % (
144 "NullableAssociatedInterfaceRequest" if mojom.IsNullableKind(kind)
145 else "AssociatedInterfaceRequest")
140 if mojom.IsEnumKind(kind): 146 if mojom.IsEnumKind(kind):
141 return "new codec.Enum(%s)" % JavaScriptType(kind) 147 return "new codec.Enum(%s)" % JavaScriptType(kind)
142 if mojom.IsMapKind(kind): 148 if mojom.IsMapKind(kind):
143 map_type = "NullableMapOf" if mojom.IsNullableKind(kind) else "MapOf" 149 map_type = "NullableMapOf" if mojom.IsNullableKind(kind) else "MapOf"
144 key_type = ElementCodecType(kind.key_kind) 150 key_type = ElementCodecType(kind.key_kind)
145 value_type = ElementCodecType(kind.value_kind) 151 value_type = ElementCodecType(kind.value_kind)
146 return "new codec.%s(%s, %s)" % (map_type, key_type, value_type) 152 return "new codec.%s(%s, %s)" % (map_type, key_type, value_type)
147 raise Exception("No codec type for %s" % kind) 153 raise Exception("No codec type for %s" % kind)
148 154
149 155
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 309
304 def IsHandleField(field): 310 def IsHandleField(field):
305 return mojom.IsAnyHandleKind(field.kind) 311 return mojom.IsAnyHandleKind(field.kind)
306 312
307 def IsInterfaceField(field): 313 def IsInterfaceField(field):
308 return mojom.IsInterfaceKind(field.kind) 314 return mojom.IsInterfaceKind(field.kind)
309 315
310 def IsInterfaceRequestField(field): 316 def IsInterfaceRequestField(field):
311 return mojom.IsInterfaceRequestKind(field.kind) 317 return mojom.IsInterfaceRequestKind(field.kind)
312 318
319 def IsAssociatedInterfaceField(field):
320 return mojom.IsAssociatedInterfaceKind(field.kind)
321
322 def IsAssociatedInterfaceRequestField(field):
323 return mojom.IsAssociatedInterfaceRequestKind(field.kind)
324
313 def IsUnionField(field): 325 def IsUnionField(field):
314 return mojom.IsUnionKind(field.kind) 326 return mojom.IsUnionKind(field.kind)
315 327
316 def IsBoolField(field): 328 def IsBoolField(field):
317 return mojom.IsBoolKind(field.kind) 329 return mojom.IsBoolKind(field.kind)
318 330
319 def IsObjectField(field): 331 def IsObjectField(field):
320 return mojom.IsObjectKind(field.kind) 332 return mojom.IsObjectKind(field.kind)
321 333
322 def IsAnyHandleOrInterfaceField(field): 334 def IsAnyHandleOrInterfaceField(field):
(...skipping 10 matching lines...) Expand all
333 345
334 js_filters = { 346 js_filters = {
335 "decode_snippet": JavaScriptDecodeSnippet, 347 "decode_snippet": JavaScriptDecodeSnippet,
336 "default_value": JavaScriptDefaultValue, 348 "default_value": JavaScriptDefaultValue,
337 "encode_snippet": JavaScriptEncodeSnippet, 349 "encode_snippet": JavaScriptEncodeSnippet,
338 "expression_to_text": ExpressionToText, 350 "expression_to_text": ExpressionToText,
339 "field_offset": JavaScriptFieldOffset, 351 "field_offset": JavaScriptFieldOffset,
340 "has_callbacks": mojom.HasCallbacks, 352 "has_callbacks": mojom.HasCallbacks,
341 "is_any_handle_or_interface_field": IsAnyHandleOrInterfaceField, 353 "is_any_handle_or_interface_field": IsAnyHandleOrInterfaceField,
342 "is_array_pointer_field": IsArrayPointerField, 354 "is_array_pointer_field": IsArrayPointerField,
355 "is_associated_interface_field": IsAssociatedInterfaceField,
356 "is_associated_interface_request_field": IsAssociatedInterfaceRequestField,
343 "is_bool_field": IsBoolField, 357 "is_bool_field": IsBoolField,
344 "is_enum_field": IsEnumField, 358 "is_enum_field": IsEnumField,
345 "is_handle_field": IsHandleField, 359 "is_handle_field": IsHandleField,
346 "is_interface_field": IsInterfaceField, 360 "is_interface_field": IsInterfaceField,
347 "is_interface_request_field": IsInterfaceRequestField, 361 "is_interface_request_field": IsInterfaceRequestField,
348 "is_map_pointer_field": IsMapPointerField, 362 "is_map_pointer_field": IsMapPointerField,
349 "is_object_field": IsObjectField, 363 "is_object_field": IsObjectField,
350 "is_string_pointer_field": IsStringPointerField, 364 "is_string_pointer_field": IsStringPointerField,
351 "is_struct_pointer_field": IsStructPointerField, 365 "is_struct_pointer_field": IsStructPointerField,
352 "is_union_field": IsUnionField, 366 "is_union_field": IsUnionField,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 return self.module.imports 430 return self.module.imports
417 431
418 def GetImportedInterfaces(self): 432 def GetImportedInterfaces(self):
419 interface_to_import = {}; 433 interface_to_import = {};
420 for each_import in self.module.imports: 434 for each_import in self.module.imports:
421 for each_interface in each_import["module"].interfaces: 435 for each_interface in each_import["module"].interfaces:
422 name = each_interface.name 436 name = each_interface.name
423 interface_to_import[name] = each_import["unique_name"] + "." + name 437 interface_to_import[name] = each_import["unique_name"] + "." + name
424 return interface_to_import; 438 return interface_to_import;
425 439
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698