Skip to content

Float16Array not working in node:v8 serde #55574

Description

@bartlomieju

Version

23.1.0

Platform

22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64

Subsystem

node:v8

What steps will reproduce the bug?

import { serialize } from "node:v8";

const float16Data = new Float16Array([1.0, 2.5, 3.14]);

try {
  const serialized = serialize(float16Data);
  console.log("Serialization successful!");
  console.log("Serialized data:", serialized);
} catch (error) {
  console.error("Serialization failed:", error.message);
}

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

serialize calls finishes successfuly.

What do you see instead?

const float16Data = new Float16Array([1.0, 2.5, 3.14]);
                    ^

ReferenceError: Float16Array is not defined
    at file:///Users/ib/dev/deno/index.js:3:21

Additional information

While I understand that Float16Array is not yet supported (eg. #52416) as it requires upgrade to V8 12.4, maybe there's a chance we could agree that arrayBufferViewTypeToIndex will return 13 for the Float16Array?

node/lib/v8.js

Lines 277 to 293 in 5633c62

function arrayBufferViewTypeToIndex(abView) {
const type = ObjectPrototypeToString(abView);
if (type === '[object Int8Array]') return 0;
if (type === '[object Uint8Array]') return 1;
if (type === '[object Uint8ClampedArray]') return 2;
if (type === '[object Int16Array]') return 3;
if (type === '[object Uint16Array]') return 4;
if (type === '[object Int32Array]') return 5;
if (type === '[object Uint32Array]') return 6;
if (type === '[object Float32Array]') return 7;
if (type === '[object Float64Array]') return 8;
if (type === '[object DataView]') return 9;
// Index 10 is FastBuffer.
if (type === '[object BigInt64Array]') return 11;
if (type === '[object BigUint64Array]') return 12;
return -1;
}

Thanks!

Activity

  1. added
    web-standardsIssues and PRs related to web-platform APIs and standards compliance.
    v8 engineIssues and PRs related to the V8 dependency.
    and removed
    v8 engineIssues and PRs related to the V8 dependency.
    web-standardsIssues and PRs related to web-platform APIs and standards compliance.
    on Oct 28, 2024
  2. avivkeller commented on Oct 28, 2024

    @avivkeller
    Member

    This doesn't have anything to do with the serialize function. Node.js doesn't provide a Float16Array:

    $ node -p "Float16Array"                                     
    [eval]:1
    Float16Array
    ^
    
    ReferenceError: Float16Array is not defined
  3. bartlomieju commented on Oct 28, 2024

    @bartlomieju
    ContributorAuthor

    Well, yeah, at the moment it doesn't. But once Float16Array is added I think the support in node:v8 will follow?

  4. richardlau commented on Oct 28, 2024

    @richardlau
    Member

    As noted in #52416 (comment), support for Float16Array is in-progress in V8. It's currently behind a --js-float16array V8 runtime flag.

  5. bnoordhuis commented on Oct 30, 2024

    @bnoordhuis
    Member

    Hiya, Bartek.

    maybe there's a chance we could agree that arrayBufferViewTypeToIndex will return 13 for the Float16Array?

    Seems uncontroversial to me. The one thing is that arrayBufferViewIndexToType(13) is going to fail with a "Float16Array is not defined" ReferenceError but everything else will work just fine though.

  6. bartlomieju commented on Nov 4, 2024

    @bartlomieju
    ContributorAuthor

    Hiya, Bartek.

    maybe there's a chance we could agree that arrayBufferViewTypeToIndex will return 13 for the Float16Array?

    Seems uncontroversial to me. The one thing is that arrayBufferViewIndexToType(13) is going to fail with a "Float16Array is not defined" ReferenceError but everything else will work just fine though.

    Hey Ben, thanks for commenting. Should I open a PR that updates these function already? As you said they would fail with ReferenceErrors for now, but once Float16Array support lands they would start working.

  7. targos commented on Nov 4, 2024

    @targos
    Member

    I guess we can update the functions and add the --js-float16array flag in the test to validate it works.

  8. added a commit that references this issue on Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions