Exemplo n.º 1
0
            public GlobalType(WebAssemblyType content_type, bool mutability)
            {
                if (!WebAssemblyHelper.IsValueType(content_type))
                {
                    throw new ArgumentException(nameof(content_type));
                }

                this.content_type = content_type;
                this.mutability   = mutability;
            }
Exemplo n.º 2
0
            public FuncType(WebAssemblyType[] param_types, WebAssemblyType?return_type)
            {
                this.param_types = param_types ?? throw new ArgumentException(nameof(param_types));
                this.return_type = return_type;

                if (param_types.Any(x => !WebAssemblyHelper.IsValueType(x)))
                {
                    throw new ArgumentException(nameof(param_types));
                }

                if (return_type != null && !WebAssemblyHelper.IsValueType((WebAssemblyType)this.return_type))
                {
                    throw new ArgumentException(nameof(return_type));
                }
            }
Exemplo n.º 3
0
            public GlobalType(BinaryReader reader)
            {
                content_type = (WebAssemblyType)LEB128.ReadUInt7(reader);

                if (!WebAssemblyHelper.IsValueType(content_type))
                {
                    throw new Exception($"File is invalid. Expected value type, received '{content_type}'.");
                }

                byte mut = LEB128.ReadUInt7(reader);

                if (mut != 0 && mut != 1)
                {
                    throw new Exception($"File is invalid. Expected 0 or 1, received '{mut}'.");
                }

                mutability = mut != 0;
            }
Exemplo n.º 4
0
            public FuncType(BinaryReader reader)
            {
                int form = LEB128.ReadInt7(reader);

                if (form != (int)WebAssemblyType.func)
                {
                    throw new Exception($"File is invalid. Expected byte '{WebAssemblyType.func}', received '{form}'.");
                }

                uint param_count = LEB128.ReadUInt32(reader);

                if (param_count > int.MaxValue)
                {
                    throw new NotImplementedException($"Count larger than {int.MaxValue} bytes not supported.");
                }
                param_types = new WebAssemblyType[param_count];

                for (uint i = 0; i < param_count; i++)
                {
                    param_types[i] = (WebAssemblyType)LEB128.ReadInt7(reader);
                    if (!WebAssemblyHelper.IsValueType(param_types[i]))
                    {
                        throw new Exception($"File is invalid. Expected valid value type, received '{param_types[i]}'.");
                    }
                }

                int return_count = LEB128.ReadInt7(reader);

                if (return_count != 0 && return_count != 1)
                {
                    throw new Exception($"File is invalid. Expected byte 0 or 1, received {return_count}.");
                }

                if (return_count == 1)
                {
                    return_type = (WebAssemblyType)LEB128.ReadInt7(reader);
                    if (!WebAssemblyHelper.IsValueType((WebAssemblyType)return_type))
                    {
                        throw new Exception($"File is invalid. Expected valid value type, received '{return_type}'.");
                    }
                }
            }