Skip to content

Built-in methods should reject nullish this consistently #699

@frostney

Description

@frostney

Summary

Several built-in prototype methods should immediately throw TypeError when called with this equal to null or undefined, but currently accept/coerce those nullish receivers or crash later.

Why

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

  • staging/sm/misc/builtin-methods-reject-null-undefined-this.js

The test loops over built-in method tables and checks .call(null), .apply(undefined), and bare calls. This is ordinary ECMAScript receiver-validation behavior, not a for...in semantics issue.

Current behavior

A targeted probe reports methods that do not throw the required TypeError, including:

Object.prototype.toLocaleString
Object.prototype.valueOf
Array.prototype.toLocaleString
Boolean.prototype.toString
Boolean.prototype.valueOf
Number.prototype.toLocaleString
Date.prototype.toLocaleString

The broader probe later hits an access violation while continuing through Date methods, which suggests there may be both missing RequireObjectCoercible/brand checks and native-method crash paths.

Reproduction through the pinned test262 runner:

./build.pas loaderbare
bun scripts/run_test262_suite.ts \
  --suite-dir /tmp/test262-suite-pinned \
  --categories staging \
  --filter 'staging/sm/misc/builtin-methods-reject-null-undefined-this.js' \
  --mode bytecode \
  --jobs 1 \
  --verbose

Current result is an ordinary conformance FAIL, not wrapper infra:

Error: Goccia VM throw

Interpreted mode reports [object Object], indicating the assertion failure is reaching the runner but the error formatting is not very diagnostic.

Expected behavior

Built-in prototype methods whose spec algorithms require object/primitive-wrapper receivers should reject null and undefined with TypeError before doing any later operation. Bare method calls should also reject because the receiver becomes undefined after de-referencing.

Scope notes

Likely fix areas include receiver validation in built-in prototype methods for Object, Array, Boolean, Number, Date, String, RegExp, and Error. The test intentionally includes some missing legacy methods; missing methods already throw via undefined.call(...), but implemented methods need correct receiver checks.

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