Skip to content

Array.fromAsync looks up call on the mapper and the iterator method #1795

Closed

Description

@d01c2

Reproduction

// sample.js
function mapper(x) { return x * 10; }
mapper.call = function () { return "hijacked"; };
var method = function () { return [1, 2].values(); };
method.call = function () { return ["hijacked"].values(); };
(async function () {
  print(await Array.fromAsync([1, 2], mapper));
  print(await Array.fromAsync({ length: 2, 0: 1, 1: 2 }, mapper));
  print(await Array.fromAsync({ [Symbol.iterator]: method }));
})().catch((e) => print(e));

Expected

V8 (15.6.20):

$ v8 sample.js
10,20
10,20
1,2

Actual (QuickJS-ng)

$ qjs sample.js
hijacked,hijacked
hijacked,hijacked
hijacked

Spec

Array.fromAsync calls the mapper directly with Call(mapper, thisArg, « value, 𝔽(k) ») (steps 8.d.ix.1 and 9.g.iv.1), and calls the iterator method through GetIteratorFromMethod, whose step 1 is Call(method, obj). Neither reads a call property. QuickJS-ng reads call from both functions, so an own or inherited call property replaces the call.

Versions

  • QuickJS-ng: 0.17.0
  • V8: 15.6.20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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