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

Unified Diff: mojo/public/tools/bindings/generators/mojom_js_generator.py

Issue 654843005: Mojo JS Bindings: add support for associative arrays (Mojo map type) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/mojom_js_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_js_generator.py b/mojo/public/tools/bindings/generators/mojom_js_generator.py
index d05b7d3b77b54e687517cce1f7a98528a57d5a3f..7bb4b5da91ee189003c58c844f368f6e20f64658 100644
--- a/mojo/public/tools/bindings/generators/mojom_js_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_js_generator.py
@@ -54,6 +54,8 @@ def JavaScriptDefaultValue(field):
return "null"
if mojom.IsAnyArrayKind(field.kind):
return "null"
+ if mojom.IsMapKind(field.kind):
+ return "null"
if mojom.IsInterfaceKind(field.kind) or \
mojom.IsInterfaceRequestKind(field.kind):
return _kind_to_javascript_default_value[mojom.MSGPIPE]
@@ -116,12 +118,17 @@ def CodecType(kind):
return _kind_to_codec_type[mojom.INT32]
return kind
+def MapCodecType(kind):
+ return "codec.PackedBool" if mojom.IsBoolKind(kind) else CodecType(kind)
def JavaScriptDecodeSnippet(kind):
if kind in mojom.PRIMITIVES:
return "decodeStruct(%s)" % CodecType(kind)
if mojom.IsStructKind(kind):
return "decodeStructPointer(%s)" % JavaScriptType(kind)
+ if mojom.IsMapKind(kind):
+ return "decodeMapPointer(%s, %s)" % \
+ (MapCodecType(kind.key_kind), MapCodecType(kind.value_kind))
if mojom.IsAnyArrayKind(kind) and mojom.IsBoolKind(kind.kind):
return "decodeArrayPointer(codec.PackedBool)"
if mojom.IsAnyArrayKind(kind):
@@ -137,6 +144,9 @@ def JavaScriptEncodeSnippet(kind):
return "encodeStruct(%s, " % CodecType(kind)
if mojom.IsStructKind(kind):
return "encodeStructPointer(%s, " % JavaScriptType(kind)
+ if mojom.IsMapKind(kind):
+ return "encodeMapPointer(%s, %s, " % \
+ (MapCodecType(kind.key_kind), MapCodecType(kind.value_kind))
if mojom.IsAnyArrayKind(kind) and mojom.IsBoolKind(kind.kind):
return "encodeArrayPointer(codec.PackedBool, ";
if mojom.IsAnyArrayKind(kind):
« mojo/public/js/bindings/codec.js ('K') | « mojo/public/js/bindings/struct_unittests.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698