Skip to content

TypedArray built-in members are enumerable and leak into for-in #698

@frostney

Description

@frostney

Summary

TypedArray constructor and prototype built-in members should be non-enumerable. Today several members are enumerable, so for...in over a typed array yields inherited built-in names such as BYTES_PER_ELEMENT, toBase64, and toHex.

Why

Enabling --compat-for-in-loop surfaced newly failing test262 coverage:

  • built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js
  • built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js

Those tests expect detached typed arrays to enumerate zero keys. Goccia correctly skips numeric indexed elements after detachment, but inherited enumerable TypedArray built-ins still leak through enumeration.

Current behavior

With the current branch:

printf 'const sample = new Uint8Array(3); sample.buffer.transfer(); for (const k in sample) print(k);\n' | \
  ./build/GocciaScriptLoaderBare \
    --compat-for-in-loop --compat-var --compat-function \
    --compat-traditional-for-loop --compat-while-loops \
    --compat-loose-equality --compat-label --compat-non-strict-mode \
    --unsafe-function-constructor --mode=bytecode -

prints:

BYTES_PER_ELEMENT
toBase64
toHex
setFromBase64
setFromHex

A descriptor probe also shows TypedArray built-ins are enumerable:

Object.getOwnPropertyDescriptor(Uint8Array.prototype, "toHex").enumerable // true
Object.getOwnPropertyDescriptor(Uint8Array, "BYTES_PER_ELEMENT").enumerable // true

Expected behavior

TypedArray constructor and prototype built-in properties should use ECMAScript descriptor attributes, with built-in methods and constants non-enumerable. for...in over a detached typed array should not yield inherited TypedArray built-in names.

Scope notes

Likely fix area: source/units/Goccia.Values.TypedArrayValue.pas and shared object-model member installation paths. Check both constructor properties (BYTES_PER_ELEMENT, from, of, base64/hex helpers) and prototype properties (BYTES_PER_ELEMENT, toBase64, toHex, setFromBase64, setFromHex) across numeric and BigInt typed arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingengineTGocciaEngine: language semantics, ECMAScript built-ins, parser, interpreter, bytecode VMspec complianceMismatch against official JavaScript/TypeScript specification

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions