Skip to content

Commit

Permalink
Bug 1931350: Add initial implementation for the Iterator Sequencing p…
Browse files Browse the repository at this point in the history
…roposal. r=mgaudet

Test PR: tc39/test262#4326

Differential Revision: https://phabricator.services.mozilla.com/D229014

UltraBlame original commit: 8d892ee60eeedad56dde64e3aa91c63abd10e8e0
  • Loading branch information
marco-c committed Dec 1, 2024
1 parent 17581a7 commit 759bd5c
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 0 deletions.
259 changes: 259 additions & 0 deletions js/src/builtin/Iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,265 @@ value
ifdef
NIGHTLY_BUILD
function
IteratorConcat
(
)
{
var
index
=
ArgumentsLength
(
)
*
2
;
var
iterables
=
std_Array
(
index
)
;
for
(
var
i
=
0
;
i
<
ArgumentsLength
(
)
;
i
+
+
)
{
var
item
=
GetArgument
(
i
)
;
if
(
!
IsObject
(
item
)
)
{
ThrowTypeError
(
JSMSG_OBJECT_REQUIRED
typeof
item
)
;
}
var
method
=
item
[
GetBuiltinSymbol
(
"
iterator
"
)
]
;
if
(
!
IsCallable
(
method
)
)
{
ThrowTypeError
(
JSMSG_NOT_ITERABLE
ToSource
(
item
)
)
;
}
DefineDataProperty
(
iterables
-
-
index
item
)
;
DefineDataProperty
(
iterables
-
-
index
method
)
;
}
assert
(
index
=
=
=
0
"
all
items
stored
"
)
;
var
result
=
NewIteratorHelper
(
)
;
var
generator
=
IteratorConcatGenerator
(
iterables
)
;
UnsafeSetReservedSlot
(
result
ITERATOR_HELPER_GENERATOR_SLOT
generator
)
;
return
result
;
}
function
*
IteratorConcatGenerator
(
iterables
)
{
assert
(
IsArray
(
iterables
)
"
iterables
is
an
array
"
)
;
assert
(
iterables
.
length
%
2
=
=
=
0
"
iterables
contains
pairs
(
item
method
)
"
)
;
for
(
var
i
=
iterables
.
length
;
i
>
0
;
)
{
var
item
=
iterables
[
-
-
i
]
;
var
method
=
iterables
[
-
-
i
]
;
iterables
.
length
-
=
2
;
for
(
var
innerValue
of
allowContentIterWith
(
item
method
)
)
{
yield
innerValue
;
}
}
}
function
IteratorZip
(
predicate
Expand Down
8 changes: 8 additions & 0 deletions js/src/vm/CommonPropertyNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,14 @@ compare
\
MACRO_
(
concat
"
concat
"
)
\
MACRO_
(
configurable
"
configurable
Expand Down
11 changes: 11 additions & 0 deletions js/src/vm/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9316,6 +9316,17 @@ NIGHTLY_BUILD
JS_SELF_HOSTED_FN
(
"
concat
"
"
IteratorConcat
"
0
0
)
JS_SELF_HOSTED_FN
(
"
range
"
"
Expand Down
40 changes: 40 additions & 0 deletions js/src/vm/JSObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12963,6 +12963,46 @@ if
key
=
=
JSProto_Function
&
&
!
JS
:
:
Prefs
:
:
experimental_iterator_sequencing
(
)
&
&
id
=
=
NameToId
(
cx
-
>
names
(
)
.
concat
)
)
{
return
true
;
}
if
(
key
=
=
JSProto_Atomics
&
&
Expand Down

0 comments on commit 759bd5c

Please sign in to comment.