Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/contributing/ffi-fast-api-internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ surface. It models the ABI categories that the generated trampoline knows how to
marshal directly:

* `kVoid`
* `kBool`
* signed and unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers
* `kFloat32`
* `kFloat64`
* `kPointer`
* `kBuffer`

Public aliases are normalized in `FastScalarTypeFromName()` and
`FastArgTypeFromName()`.
`FastArgTypeFromName()`. In particular, `bool` is normalized to `kUint8` to
match its documented 8-bit unsigned integer semantics.

`pointer`, `ptr`, `string`, `str`, `buffer`, and `arraybuffer` all represent
pointer-sized native values at the target ABI boundary. They differ in how
Expand Down
4 changes: 1 addition & 3 deletions src/ffi/fast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool FastScalarTypeFromName(std::string_view type, FastFFIType* out) {
if (type == "void") {
*out = FastFFIType::kVoid;
} else if (type == "bool") {
*out = FastFFIType::kBool;
*out = FastFFIType::kUint8;
} else if (IsTypeName(type, {"i8", "int8"})) {
*out = FastFFIType::kInt8;
} else if (IsTypeName(type, {"u8", "uint8"})) {
Expand Down Expand Up @@ -96,8 +96,6 @@ CTypeInfo::Type ToV8Type(FastFFIType type, bool is_return) {
switch (type) {
case FastFFIType::kVoid:
return CTypeInfo::Type::kVoid;
case FastFFIType::kBool:
return CTypeInfo::Type::kBool;
case FastFFIType::kUint8:
return CTypeInfo::Type::kUint32;
case FastFFIType::kInt8:
Expand Down
1 change: 0 additions & 1 deletion src/ffi/fast.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct FFIFunction;

enum class FastFFIType : uint8_t {
kVoid,
kBool,
kInt8,
kUint8,
kInt16,
Expand Down
1 change: 0 additions & 1 deletion src/ffi/platforms/arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ uint32_t UxthW(unsigned reg) {
// to the ABI width expected by the native target before the final call.
bool EmitNarrow(uint32_t** cursor, FastFFIType type, unsigned reg) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kUint8:
*(*cursor)++ = UxtbW(reg);
return true;
Expand Down
1 change: 0 additions & 1 deletion src/ffi/platforms/loong64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ bool IsFloatType(FastFFIType type) {

bool IsNarrowType(FastFFIType type) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kInt8:
case FastFFIType::kUint8:
case FastFFIType::kInt16:
Expand Down
1 change: 0 additions & 1 deletion src/ffi/platforms/ppc64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ bool IsFloatType(FastFFIType type) {

bool IsNarrowType(FastFFIType type) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kInt8:
case FastFFIType::kUint8:
case FastFFIType::kInt16:
Expand Down
1 change: 0 additions & 1 deletion src/ffi/platforms/riscv64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ bool IsFloatType(FastFFIType type) {

bool IsNarrowType(FastFFIType type) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kInt8:
case FastFFIType::kUint8:
case FastFFIType::kInt16:
Expand Down
1 change: 0 additions & 1 deletion src/ffi/platforms/s390x.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ bool IsFloatType(FastFFIType type) {

bool IsNarrowType(FastFFIType type) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kInt8:
case FastFFIType::kUint8:
case FastFFIType::kInt16:
Expand Down
4 changes: 0 additions & 4 deletions src/ffi/platforms/x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ void EmitNarrowInstruction(uint8_t** cursor, uint8_t opcode, unsigned reg) {
// consumes the declared low 8/16 bits.
bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kUint8:
EmitNarrowInstruction(cursor, 0xb6, reg);
return true;
Expand All @@ -252,7 +251,6 @@ bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {

bool NeedsNarrow(FastFFIType type) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kUint8:
case FastFFIType::kInt8:
case FastFFIType::kUint16:
Expand Down Expand Up @@ -655,7 +653,6 @@ void EmitNarrowInstruction(uint8_t** cursor, uint8_t opcode, unsigned reg) {

bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kUint8:
EmitNarrowInstruction(cursor, 0xb6, reg);
return true;
Expand All @@ -675,7 +672,6 @@ bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {

bool NeedsNarrow(FastFFIType type) {
switch (type) {
case FastFFIType::kBool:
case FastFFIType::kUint8:
case FastFFIType::kInt8:
case FastFFIType::kUint16:
Expand Down
14 changes: 11 additions & 3 deletions test/ffi/test-ffi-calls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-ffi --expose-gc
// Flags: --experimental-ffi --expose-gc --allow-natives-syntax
'use strict';
const common = require('../common');
common.skipIfFFIMissing();
Expand Down Expand Up @@ -62,8 +62,16 @@ test('ffi bool signatures use uint8 values', () => {
arguments: ['bool', 'bool'],
return: 'bool',
});
assert.strictEqual(boolAdder(1, 0), 1);
assert.throws(() => boolAdder(true, false), /Argument 0 must be a uint8/);
function callBoolAdder(a, b) {
return boolAdder(a, b);
}

eval('%PrepareFunctionForOptimization(callBoolAdder)');
assert.strictEqual(callBoolAdder(1, 0), 1);
eval('%OptimizeFunctionOnNextCall(callBoolAdder)');
assert.strictEqual(callBoolAdder(1, 0), 1);
assert.throws(
() => callBoolAdder(true, false), /Argument 0 must be a uint8/);
} finally {
lib.close();
}
Expand Down
Loading