Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal: Add coverage for modified Array iteration when called from CalendarFields/GetPossibleInstantsFor #3851

Open
anba opened this issue Jun 12, 2023 · 2 comments

Comments

@anba
Copy link
Contributor

anba commented Jun 12, 2023

It'd be nice to have coverage when the built-in Array iteration has been modified to ensure implementations correctly handle this case in CalendarFields and GetPossibleInstantsFor.

CalendarFields:

let observed = [];
let ArrayIterProto = Object.getPrototypeOf([][Symbol.iterator]());
let oldNext = ArrayIterProto.next;
ArrayIterProto.next = function() {
  var r = oldNext.call(this);
  if (!r.done) {
    observed.push(r.value);
  }
  return r;
};

// No overridden `fields` methods, but calling CalendarFields is still observable through
// modified Array iteration.
let calendar = new Temporal.Calendar("iso8601");

let pd = new Temporal.PlainDate(2000, 1, 1, calendar).with({year: 2001});

// Should output: day,month,monthCode,year,day,month,monthCode,year
console.log(observed);

GetPossibleInstantsFor:

let observed = [];
let ArrayIterProto = Object.getPrototypeOf([][Symbol.iterator]());
let oldNext = ArrayIterProto.next;
ArrayIterProto.next = function() {
  var r = oldNext.call(this);
  if (!r.done) {
    observed.push(r.value);
  }
  return r;
};

// No overridden `getPossibleInstantsFor` methods, but calling GetPossibleInstantsFor is still
// observable through modified Array iteration.
let timeZone = new Temporal.TimeZone("UTC");

let pd = new Temporal.PlainDate(2000, 1, 1);
let zdt = pd.toZonedDateTime(timeZone);

// Should print: 2000-01-01T00:00:00Z
// Note: `observed[0]` is a Temporal.Instant value.
console.log(observed);
@ptomato
Copy link
Contributor

ptomato commented Jun 13, 2023

This may be obsoleted by tc39/proposal-temporal#2519? I haven't checked yet.

@ptomato
Copy link
Contributor

ptomato commented Sep 11, 2023

After tc39/proposal-temporal#2657 we'll have no observable array iteration if the called fields method is from a built-in calendar. It's already the case that we have no observable array iteration if the called getPossibleInstantsFor method is from a built-in time zone.

ed3a092 adds coverage for builtin fields not observably calling Array.prototype[Symbol.iterator].

So, to fulfill this issue we would still need to add coverage for:

  • builtin getPossibleInstantsFor not observably calling Array.prototype[Symbol.iterator]
  • return value of custom calendar fields being observably iterated
  • return value of custom time zone getPossibleInstantsFor being observably iterated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants