From 550c11163eb27965250f33e22785a53a66f37253 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Thu, 13 Jul 2023 16:04:33 +0200 Subject: [PATCH] add tests for tc39/proposal-iterator-helpers#281 (#3869) Co-authored-by: Ms2ger --- .../built-ins/Iterator/from/iterable-primitives.js | 14 ++++++++++++++ test/built-ins/Iterator/from/supports-iterable.js | 1 + 2 files changed, 15 insertions(+) diff --git a/test/built-ins/Iterator/from/iterable-primitives.js b/test/built-ins/Iterator/from/iterable-primitives.js index f162ee1cc0..a4df208556 100644 --- a/test/built-ins/Iterator/from/iterable-primitives.js +++ b/test/built-ins/Iterator/from/iterable-primitives.js @@ -37,3 +37,17 @@ assert.throws(TypeError, function () { assert.compareArray(Array.from(Iterator.from(new Number(5))), [0, 1, 2, 3, 4]); assert.compareArray(Array.from(Iterator.from('string')), ['s', 't', 'r', 'i', 'n', 'g']); + +const originalStringIterator = String.prototype[Symbol.iterator]; +let observedType; +Object.defineProperty(String.prototype, Symbol.iterator, { + get() { + 'use strict'; + observedType = typeof this; + return originalStringIterator; + } +}); +Iterator.from(''); +assert.sameValue(observedType, 'string'); +Iterator.from(new String('')); +assert.sameValue(observedType, 'object'); diff --git a/test/built-ins/Iterator/from/supports-iterable.js b/test/built-ins/Iterator/from/supports-iterable.js index 03e26258cb..abe7372dc3 100644 --- a/test/built-ins/Iterator/from/supports-iterable.js +++ b/test/built-ins/Iterator/from/supports-iterable.js @@ -12,3 +12,4 @@ features: [iterator-helpers] flags: [] ---*/ assert.compareArray(Array.from(Iterator.from([0, 1, 2, 3])), [0, 1, 2, 3]); +assert.compareArray(Array.from(Iterator.from(new String('str'))), ['s', 't', 'r']);