Commit ee2630a9 authored by Scott Graham's avatar Scott Graham Committed by Commit Bot

Fuchsia: Add missing FIDL/JS vector cases for bool, float32, float64

This also required implementing the type tables for int64/uint64 as
BigInt. Additionally, some test support code to pull BigInt out of V8 as
64-bit types because gin assumes always-Number.

Bug: 883496
Change-Id: I10d07124e59f0fdde8f053007eca30508751b211
Reviewed-on: https://chromium-review.googlesource.com/c/1318729
Commit-Queue: Scott Graham <scottmg@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606261}
parent 1d6d1129
......@@ -119,6 +119,9 @@ class Compiler(object):
def _InlineSizeOfType(self, t):
if t.kind == fidl.TypeKind.PRIMITIVE:
return {
'bool': 1,
'float32': 4,
'float64': 8,
'int16': 2,
'int32': 4,
'int64': 8,
......
......@@ -130,6 +130,16 @@ const _kTT_bool = {
dec: function(d, o) { return d.data.getInt8(o) != 0; },
};
const _kTT_float32 = {
enc: function(e, o, v) { e.data.setFloat32(o, v, $fidl__kLE); },
dec: function(d, o) { return d.data.getFloat32(o, $fidl__kLE); },
};
const _kTT_float64 = {
enc: function(e, o, v) { e.data.setFloat64(o, v, $fidl__kLE); },
dec: function(d, o) { return d.data.getFloat64(o, $fidl__kLE); },
};
const _kTT_int8 = {
enc: function(e, o, v) { e.data.setInt8(o, v); },
dec: function(d, o) { return d.data.getInt8(o); },
......@@ -145,6 +155,21 @@ const _kTT_int32 = {
dec: function(d, o) { return d.data.getInt32(o, $fidl__kLE); },
};
const _kTT_int64 = {
enc: function(e, o, v) {
var bi = BigInt.asIntN(64, BigInt(v));
var x = Number(bi & 0xffffffffn);
var y = Number((bi >> 32n) & 0xffffffffn);
e.data.setInt32(o, x, $fidl__kLE);
e.data.setInt32(o + 4, y, $fidl__kLE);
},
dec: function(d, o) {
var x = BigInt.asIntN(64, BigInt(d.data.getInt32(o, $fidl__kLE)));
var y = BigInt.asIntN(64, BigInt(d.data.getInt32(o + 4, $fidl__kLE)));
return x | (y << 32n);
},
};
const _kTT_uint8 = {
enc: function(e, o, v) { e.data.setUint8(o, v); },
dec: function(d, o) { return d.data.getUint8(o); },
......@@ -160,6 +185,21 @@ const _kTT_uint32 = {
dec: function(d, o) { return d.data.getUint32(o, $fidl__kLE); },
};
const _kTT_uint64 = {
enc: function(e, o, v) {
var bi = BigInt.asUintN(64, BigInt(v));
var x = Number(bi & 0xffffffffn);
var y = Number((bi >> 32n) & 0xffffffffn);
e.data.setUint32(o, x, $fidl__kLE);
e.data.setUint32(o + 4, y, $fidl__kLE);
},
dec: function(d, o) {
var x = BigInt.asUintN(64, BigInt(d.data.getUint32(o, $fidl__kLE)));
var y = BigInt.asUintN(64, BigInt(d.data.getUint32(o + 4, $fidl__kLE)));
return x | (y << 32n);
},
};
const _kTT_Handle = {
enc: function(e, o, v) {
if (v === null || v === undefined) {
......
......@@ -61,6 +61,20 @@ struct DefaultUsingIdentifier {
Blorp blorp_defaulting_to_beta = BETA;
};
struct VectorsOfPrimitives {
vector<bool> v_bool;
vector<uint8> v_uint8;
vector<uint16> v_uint16;
vector<uint32> v_uint32;
vector<uint64> v_uint64;
vector<int8> v_int8;
vector<int16> v_int16;
vector<int32> v_int32;
vector<int64> v_int64;
vector<float32> v_float32;
vector<float64> v_float64;
};
interface Testola {
1: DoSomething();
......@@ -88,4 +102,7 @@ interface Testola {
12: VectorOfStruct(vector<StructWithUint> stuff)
-> (vector<StructWithUint> result);
13: PassVectorOfPrimitives(VectorsOfPrimitives input)
-> (VectorsOfPrimitives output);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment