Skip to content

Bug: Promise .then() treats non-function handlers as values instead of ignoring them (spec violation) #501

@MSNev

Description

@MSNev

Description

In lib/src/promise/base.ts (lines 92-113), when .then() receives a non-function argument for onFulfilled or onRejected, the implementation uses it as a value rather than ignoring it per the Promise/A+ spec.

Per the spec (section 2.2.1): ""If onFulfilled is not a function, it must be ignored"" — meaning the promise should pass through the resolved value unchanged.

Impact

Code that relies on .then(null, errorHandler) or .then(nonFunction) patterns may behave incorrectly:

  • Non-function values could be treated as resolved values
  • Promise chains may not properly propagate values through identity handlers

Steps to Reproduce

javascript const p = createAsyncPromise(resolve => resolve(42)); p.then(null).then(v => { console.log(v); // Should be 42 (identity pass-through), may not be });

Suggested Fix

Check typeof onFulfilled === 'function' before invoking; if not a function, use identity function v => v. Same for onRejected with reason => { throw reason; }.

Severity

High — violates Promise/A+ spec section 2.2.1, may cause silent data loss in promise chains.

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