| 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 59208328e54b4d44c410d3f29c881cb9cec020c0..20757336a69e86edfcb5b3063a9a0f6819353e40 100644
|
| --- a/mojo/public/tools/bindings/generators/mojom_js_generator.py
|
| +++ b/mojo/public/tools/bindings/generators/mojom_js_generator.py
|
| @@ -10,42 +10,48 @@ import mojom.generate.pack as pack
|
| from mojom.generate.template_expander import UseJinja
|
|
|
| _kind_to_javascript_default_value = {
|
| - mojom.BOOL: "false",
|
| - mojom.INT8: "0",
|
| - mojom.UINT8: "0",
|
| - mojom.INT16: "0",
|
| - mojom.UINT16: "0",
|
| - mojom.INT32: "0",
|
| - mojom.UINT32: "0",
|
| - mojom.FLOAT: "0",
|
| - mojom.HANDLE: "null",
|
| - mojom.DCPIPE: "null",
|
| - mojom.DPPIPE: "null",
|
| - mojom.MSGPIPE: "null",
|
| - mojom.SHAREDBUFFER: "null",
|
| - mojom.INT64: "0",
|
| - mojom.UINT64: "0",
|
| - mojom.DOUBLE: "0",
|
| - mojom.STRING: '""',
|
| + mojom.BOOL: "false",
|
| + mojom.INT8: "0",
|
| + mojom.UINT8: "0",
|
| + mojom.INT16: "0",
|
| + mojom.UINT16: "0",
|
| + mojom.INT32: "0",
|
| + mojom.UINT32: "0",
|
| + mojom.FLOAT: "0",
|
| + mojom.HANDLE: "null",
|
| + mojom.DCPIPE: "null",
|
| + mojom.DPPIPE: "null",
|
| + mojom.MSGPIPE: "null",
|
| + mojom.SHAREDBUFFER: "null",
|
| + mojom.NULLABLE_HANDLE: "null",
|
| + mojom.NULLABLE_DCPIPE: "null",
|
| + mojom.NULLABLE_DPPIPE: "null",
|
| + mojom.NULLABLE_MSGPIPE: "null",
|
| + mojom.NULLABLE_SHAREDBUFFER: "null",
|
| + mojom.INT64: "0",
|
| + mojom.UINT64: "0",
|
| + mojom.DOUBLE: "0",
|
| + mojom.STRING: '""',
|
| + mojom.NULLABLE_STRING: '""'
|
| }
|
|
|
|
|
| def JavaScriptDefaultValue(field):
|
| if field.default:
|
| - if isinstance(field.kind, mojom.Struct):
|
| + if mojom.IsStructKind(field.kind):
|
| assert field.default == "default"
|
| return "new %s()" % JavascriptType(field.kind)
|
| return ExpressionToText(field.default)
|
| if field.kind in mojom.PRIMITIVES:
|
| return _kind_to_javascript_default_value[field.kind]
|
| - if isinstance(field.kind, mojom.Struct):
|
| + if mojom.IsStructKind(field.kind):
|
| return "null"
|
| - if isinstance(field.kind, mojom.Array):
|
| + if mojom.IsArrayKind(field.kind):
|
| return "null"
|
| - if isinstance(field.kind, mojom.Interface) or \
|
| - isinstance(field.kind, mojom.InterfaceRequest):
|
| + if mojom.IsInterfaceKind(field.kind) or \
|
| + mojom.IsInterfaceRequestKind(field.kind):
|
| return _kind_to_javascript_default_value[mojom.MSGPIPE]
|
| - if isinstance(field.kind, mojom.Enum):
|
| + if mojom.IsEnumKind(field.kind):
|
| return "0"
|
|
|
|
|
| @@ -60,39 +66,44 @@ def JavaScriptPayloadSize(packed):
|
|
|
|
|
| _kind_to_codec_type = {
|
| - mojom.BOOL: "codec.Uint8",
|
| - mojom.INT8: "codec.Int8",
|
| - mojom.UINT8: "codec.Uint8",
|
| - mojom.INT16: "codec.Int16",
|
| - mojom.UINT16: "codec.Uint16",
|
| - mojom.INT32: "codec.Int32",
|
| - mojom.UINT32: "codec.Uint32",
|
| - mojom.FLOAT: "codec.Float",
|
| - mojom.HANDLE: "codec.Handle",
|
| - mojom.DCPIPE: "codec.Handle",
|
| - mojom.DPPIPE: "codec.Handle",
|
| - mojom.MSGPIPE: "codec.Handle",
|
| - mojom.SHAREDBUFFER: "codec.Handle",
|
| - mojom.INT64: "codec.Int64",
|
| - mojom.UINT64: "codec.Uint64",
|
| - mojom.DOUBLE: "codec.Double",
|
| - mojom.STRING: "codec.String",
|
| + mojom.BOOL: "codec.Uint8",
|
| + mojom.INT8: "codec.Int8",
|
| + mojom.UINT8: "codec.Uint8",
|
| + mojom.INT16: "codec.Int16",
|
| + mojom.UINT16: "codec.Uint16",
|
| + mojom.INT32: "codec.Int32",
|
| + mojom.UINT32: "codec.Uint32",
|
| + mojom.FLOAT: "codec.Float",
|
| + mojom.HANDLE: "codec.Handle",
|
| + mojom.DCPIPE: "codec.Handle",
|
| + mojom.DPPIPE: "codec.Handle",
|
| + mojom.MSGPIPE: "codec.Handle",
|
| + mojom.SHAREDBUFFER: "codec.Handle",
|
| + mojom.NULLABLE_HANDLE: "codec.Handle",
|
| + mojom.NULLABLE_DCPIPE: "codec.Handle",
|
| + mojom.NULLABLE_DPPIPE: "codec.Handle",
|
| + mojom.NULLABLE_MSGPIPE: "codec.Handle",
|
| + mojom.NULLABLE_SHAREDBUFFER: "codec.Handle",
|
| + mojom.INT64: "codec.Int64",
|
| + mojom.UINT64: "codec.Uint64",
|
| + mojom.DOUBLE: "codec.Double",
|
| + mojom.STRING: "codec.String",
|
| + mojom.NULLABLE_STRING: "codec.String",
|
| }
|
|
|
|
|
| def CodecType(kind):
|
| if kind in mojom.PRIMITIVES:
|
| return _kind_to_codec_type[kind]
|
| - if isinstance(kind, mojom.Struct):
|
| + if mojom.IsStructKind(kind):
|
| return "new codec.PointerTo(%s)" % CodecType(kind.name)
|
| - if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL:
|
| + if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
|
| return "new codec.ArrayOfBoolArrayPointers()"
|
| - if isinstance(kind, mojom.Array):
|
| + if mojom.IsArrayKind(kind):
|
| return "new codec.ArrayOf(%s)" % CodecType(kind.kind)
|
| - if isinstance(kind, mojom.Interface) or \
|
| - isinstance(kind, mojom.InterfaceRequest):
|
| + if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
|
| return CodecType(mojom.MSGPIPE)
|
| - if isinstance(kind, mojom.Enum):
|
| + if mojom.IsEnumKind(kind):
|
| return _kind_to_codec_type[mojom.INT32]
|
| return kind
|
|
|
| @@ -100,32 +111,30 @@ def CodecType(kind):
|
| def JavaScriptDecodeSnippet(kind):
|
| if kind in mojom.PRIMITIVES:
|
| return "decodeStruct(%s)" % CodecType(kind)
|
| - if isinstance(kind, mojom.Struct):
|
| + if mojom.IsStructKind(kind):
|
| return "decodeStructPointer(%s)" % CodecType(kind.name)
|
| - if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL:
|
| + if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
|
| return "decodeBoolArrayPointer()"
|
| - if isinstance(kind, mojom.Array):
|
| + if mojom.IsArrayKind(kind):
|
| return "decodeArrayPointer(%s)" % CodecType(kind.kind)
|
| - if isinstance(kind, mojom.Interface) or \
|
| - isinstance(kind, mojom.InterfaceRequest):
|
| + if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
|
| return JavaScriptDecodeSnippet(mojom.MSGPIPE)
|
| - if isinstance(kind, mojom.Enum):
|
| + if mojom.IsEnumKind(kind):
|
| return JavaScriptDecodeSnippet(mojom.INT32)
|
|
|
|
|
| def JavaScriptEncodeSnippet(kind):
|
| if kind in mojom.PRIMITIVES:
|
| return "encodeStruct(%s, " % CodecType(kind)
|
| - if isinstance(kind, mojom.Struct):
|
| + if mojom.IsStructKind(kind):
|
| return "encodeStructPointer(%s, " % CodecType(kind.name)
|
| - if isinstance(kind, mojom.Array) and kind.kind == mojom.BOOL:
|
| + if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind):
|
| return "encodeBoolArrayPointer(";
|
| - if isinstance(kind, mojom.Array):
|
| + if mojom.IsArrayKind(kind):
|
| return "encodeArrayPointer(%s, " % CodecType(kind.kind)
|
| - if isinstance(kind, mojom.Interface) or \
|
| - isinstance(kind, mojom.InterfaceRequest):
|
| + if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind):
|
| return JavaScriptEncodeSnippet(mojom.MSGPIPE)
|
| - if isinstance(kind, mojom.Enum):
|
| + if mojom.IsEnumKind(kind):
|
| return JavaScriptEncodeSnippet(mojom.INT32)
|
|
|
|
|
|
|