lib: handle Float16Array in node:v8 serdes
PR-URL: https://github.com/nodejs/node/pull/55996 Fixes: https://github.com/nodejs/node/issues/55574 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
This commit is contained in:
parent
7fdeeac4d3
commit
ac7fea6a12
@ -347,6 +347,11 @@ export default [
|
|||||||
name: 'SubtleCrypto',
|
name: 'SubtleCrypto',
|
||||||
message: "Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global.",
|
message: "Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global.",
|
||||||
},
|
},
|
||||||
|
// Float16Array is not available in primordials because it's only available with --js-float16array CLI flag.
|
||||||
|
{
|
||||||
|
name: 'Float16Array',
|
||||||
|
message: 'Use `const { Float16Array } = globalThis;` instead of the global.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
'no-restricted-modules': [
|
'no-restricted-modules': [
|
||||||
'error',
|
'error',
|
||||||
|
@ -31,6 +31,9 @@ const {
|
|||||||
Uint32Array,
|
Uint32Array,
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
Uint8ClampedArray,
|
Uint8ClampedArray,
|
||||||
|
globalThis: {
|
||||||
|
Float16Array,
|
||||||
|
},
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
@ -63,6 +66,7 @@ const {
|
|||||||
} = require('internal/heap_utils');
|
} = require('internal/heap_utils');
|
||||||
const promiseHooks = require('internal/promise_hooks');
|
const promiseHooks = require('internal/promise_hooks');
|
||||||
const { getOptionValue } = require('internal/options');
|
const { getOptionValue } = require('internal/options');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a snapshot of the current V8 heap
|
* Generates a snapshot of the current V8 heap
|
||||||
* and writes it to a JSON file.
|
* and writes it to a JSON file.
|
||||||
@ -289,6 +293,7 @@ function arrayBufferViewTypeToIndex(abView) {
|
|||||||
// Index 10 is FastBuffer.
|
// Index 10 is FastBuffer.
|
||||||
if (type === '[object BigInt64Array]') return 11;
|
if (type === '[object BigInt64Array]') return 11;
|
||||||
if (type === '[object BigUint64Array]') return 12;
|
if (type === '[object BigUint64Array]') return 12;
|
||||||
|
if (type === '[object Float16Array]') return 13;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,6 +311,7 @@ function arrayBufferViewIndexToType(index) {
|
|||||||
if (index === 10) return FastBuffer;
|
if (index === 10) return FastBuffer;
|
||||||
if (index === 11) return BigInt64Array;
|
if (index === 11) return BigInt64Array;
|
||||||
if (index === 12) return BigUint64Array;
|
if (index === 12) return BigUint64Array;
|
||||||
|
if (index === 13) return Float16Array;
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Flags: --expose-internals
|
// Flags: --expose-internals --js-float16array
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -7,6 +7,9 @@ const { internalBinding } = require('internal/test/binding');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const v8 = require('v8');
|
const v8 = require('v8');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
// TODO(bartlomieju): once `Float16Array` is available in stable V8,
|
||||||
|
// remove this line and `--js-float16array` flag up top
|
||||||
|
const { Float16Array } = globalThis;
|
||||||
|
|
||||||
const circular = {};
|
const circular = {};
|
||||||
circular.circular = circular;
|
circular.circular = circular;
|
||||||
@ -26,6 +29,7 @@ const objects = [
|
|||||||
Buffer.from([1, 2, 3, 4]),
|
Buffer.from([1, 2, 3, 4]),
|
||||||
new BigInt64Array([42n]),
|
new BigInt64Array([42n]),
|
||||||
new BigUint64Array([42n]),
|
new BigUint64Array([42n]),
|
||||||
|
new Float16Array([1, 2, 3, 4]),
|
||||||
undefined,
|
undefined,
|
||||||
null,
|
null,
|
||||||
42,
|
42,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user