Skip to content

Safer way to set object prototype #1691

@ruochenjia

Description

@ruochenjia

Currently there is no direct equivalent API to v8::Object::SetPrototype in NAPI, so to set the prototype of an object you have to get and invoke Object.setPrototypeOf from the global object. This is unsafe as it is configurable so can be overridden by other JS code, leading to potential crashes. The Node.js built-in APIs use the primordials module to address this issue, but it is inaccessible to user code. I think there should be a direct API for setting object prototype, as napi_get_prototype already exists, and it is needed for classes created with napi_define_class to extend each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Need Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions