Skip to content

node:perf_hooks: validate PerformanceObserver.observe options #3010

@andrewtdiz

Description

@andrewtdiz

Summary

Node PerformanceObserver.prototype.observe() validates its options object: either options.entryTypes or options.type must be specified, entryTypes must be an array when present, and entryTypes cannot be combined with type. Perry currently accepts missing/non-object options and silently ignores invalid shapes.

Node 25.9.0 behavior

const { PerformanceObserver } = require("node:perf_hooks");
const obs = new PerformanceObserver(() => {});

obs.observe();
// TypeError ERR_MISSING_ARGS

obs.observe(null);
// TypeError ERR_INVALID_ARG_TYPE

obs.observe({});
// TypeError ERR_MISSING_ARGS

obs.observe({ entryTypes: "mark" });
// TypeError ERR_INVALID_ARG_TYPE: options.entryTypes must be string[]

obs.observe({ type: "mark", entryTypes: ["measure"] });
// TypeError ERR_INVALID_ARG_VALUE

obs.observe({ entryTypes: [] });        // ok
obs.observe({ entryTypes: ["bogus"] }); // ok, just observes nothing
obs.observe({ type: "bogus" });         // ok, just observes nothing

Perry source evidence

  • crates/perry-runtime/src/perf_hooks.rs::js_perf_observer_observe() starts with empty types and buffered = false; if opts is not an object, it simply leaves those values and marks the observer active.
  • The function reads entryTypes and only checks arr_v.is_pointer() before treating it as an ArrayHeader; it does not validate that the value is actually an array.
  • The function reads type independently and appends it to types; it does not reject the case where both entryTypes and type are present.
  • No missing-argument / missing-options validation is performed before activating the observer.

Expected

PerformanceObserver.observe() should match Node's option validation while preserving the current lenient behavior for unsupported but well-typed entry names (bogus observes nothing).

Duplicate checks

  • PerformanceObserver observe options validation
  • perf_hooks observer observe entryTypes type invalid
  • PR search for PerformanceObserver observe

I found merged observer behavior PRs for buffered delivery and callback args, but no issue for observe-option validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions