Skip to content

Commit 1175bb3

Browse files
committed
Implement Array.fromAsync
Signed-off-by: Seonghyun Kim <[email protected]>
1 parent d06a31a commit 1175bb3

File tree

6 files changed

+439
-14
lines changed

6 files changed

+439
-14
lines changed

src/builtins/BuiltinArray.cpp

Lines changed: 405 additions & 0 deletions
Large diffs are not rendered by default.

src/runtime/Object.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,29 +1333,29 @@ Value Object::call(ExecutionState& state, const Value& callee, const Value& this
13331333
}
13341334

13351335
// https://www.ecma-international.org/ecma-262/10.0/#sec-construct
1336-
Value Object::construct(ExecutionState& state, const Value& constructor, const size_t argc, Value* argv, Object* newTarget)
1336+
Value Object::construct(ExecutionState& state, const Value& constructor, const size_t argc, Value* argv, Optional<Object*> newTarget)
13371337
{
13381338
// If newTarget was not passed, let newTarget be F.
1339-
if (newTarget == nullptr) {
1339+
if (!newTarget) {
13401340
newTarget = constructor.asObject();
13411341
}
13421342

13431343
ASSERT(constructor.isConstructor());
13441344
ASSERT(newTarget->isConstructor());
13451345

1346-
return constructor.asPointerValue()->construct(state, argc, argv, newTarget);
1346+
return constructor.asPointerValue()->construct(state, argc, argv, newTarget.value());
13471347
}
13481348

1349-
void Object::callConstructor(ExecutionState& state, const Value& constructor, Object* receiver, const size_t argc, Value* argv, Object* newTarget)
1349+
void Object::callConstructor(ExecutionState& state, const Value& constructor, Object* receiver, const size_t argc, Value* argv, Optional<Object*> newTarget)
13501350
{
1351-
if (newTarget == nullptr) {
1351+
if (!newTarget) {
13521352
newTarget = constructor.asObject();
13531353
}
13541354

13551355
ASSERT(constructor.isConstructor());
13561356
ASSERT(newTarget->isConstructor());
13571357

1358-
return constructor.asPointerValue()->callConstructor(state, receiver, argc, argv, newTarget);
1358+
return constructor.asPointerValue()->callConstructor(state, receiver, argc, argv, newTarget.value());
13591359
}
13601360

13611361
// https://www.ecma-international.org/ecma-262/#sec-setintegritylevel

src/runtime/Object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,9 @@ class Object : public PointerValue {
11001100
}
11011101

11021102
static Value call(ExecutionState& state, const Value& callee, const Value& thisValue, const size_t argc, Value* argv);
1103-
static Value construct(ExecutionState& state, const Value& constructor, const size_t argc, Value* argv, Object* newTarget = nullptr);
1103+
static Value construct(ExecutionState& state, const Value& constructor, const size_t argc, Value* argv, Optional<Object*> newTarget = NullOption);
11041104
// call constructor with already created object(some clients need this)
1105-
static void callConstructor(ExecutionState& state, const Value& constructor, Object* receiver, const size_t argc, Value* argv, Object* newTarget = nullptr);
1105+
static void callConstructor(ExecutionState& state, const Value& constructor, Object* receiver, const size_t argc, Value* argv, Optional<Object*> newTarget = NullOption);
11061106

11071107
static bool setIntegrityLevel(ExecutionState& state, Object* O, bool isSealed);
11081108
static bool testIntegrityLevel(ExecutionState& state, Object* O, bool isSealed);

src/runtime/PointerValue.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class GlobalObjectProxyObject;
7676
class DisposableStackObject;
7777
class AsyncDisposableStackObject;
7878
struct DisposableResourceRecord;
79+
struct ArrayFromAsyncRecord;
80+
struct ArrayFromAsyncSyncRecord;
7981
#if defined(ENABLE_TEMPORAL)
8082
class TemporalObject;
8183
class TemporalPlainTimeObject;
@@ -532,6 +534,16 @@ class PointerValue : public gc {
532534
return false;
533535
}
534536

537+
virtual bool isArrayFromAsyncRecord() const
538+
{
539+
return false;
540+
}
541+
542+
virtual bool isArrayFromAsyncSyncRecord() const
543+
{
544+
return false;
545+
}
546+
535547
#if defined(ENABLE_INTL)
536548
virtual bool isIntlLocaleObject() const
537549
{
@@ -1009,6 +1021,18 @@ class PointerValue : public gc {
10091021
return (AsyncDisposableStackObject*)this;
10101022
}
10111023

1024+
ArrayFromAsyncRecord* asArrayFromAsyncRecord()
1025+
{
1026+
ASSERT(isArrayFromAsyncRecord());
1027+
return (ArrayFromAsyncRecord*)this;
1028+
}
1029+
1030+
ArrayFromAsyncSyncRecord* asArrayFromAsyncSyncRecord()
1031+
{
1032+
ASSERT(isArrayFromAsyncSyncRecord());
1033+
return (ArrayFromAsyncSyncRecord*)this;
1034+
}
1035+
10121036
#if defined(ENABLE_THREADING)
10131037
SharedArrayBufferObject* asSharedArrayBufferObject()
10141038
{

src/runtime/StaticStrings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ namespace Escargot {
232232
F(forEach) \
233233
F(freeze) \
234234
F(from) \
235+
F(fromAsync) \
235236
F(fromBase64) \
236237
F(fromCharCode) \
237238
F(fromCodePoint) \

tools/test/test262/excludelist.orig.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
<test id="built-ins/AbstractModuleSource/prototype/constructor"><reason>TODO</reason></test>
2121
<test id="built-ins/AbstractModuleSource/prototype/proto"><reason>TODO</reason></test>
2222
<test id="built-ins/AbstractModuleSource/throw-from-constructor"><reason>TODO</reason></test>
23-
<test id="built-ins/Array/fromAsync/builtin"><reason>TODO</reason></test>
24-
<test id="built-ins/Array/fromAsync/length"><reason>TODO</reason></test>
25-
<test id="built-ins/Array/fromAsync/name"><reason>TODO</reason></test>
26-
<test id="built-ins/Array/fromAsync/not-a-constructor"><reason>TODO</reason></test>
27-
<test id="built-ins/Array/fromAsync/prop-desc"><reason>TODO</reason></test>
2823
<test id="built-ins/Array/prototype/join/coerced-separator-shrink"><reason>TODO</reason></test>
2924
<test id="built-ins/ArrayBuffer/prototype/resizable/detached-buffer"><reason>TODO</reason></test>
3025
<test id="built-ins/ArrayBuffer/prototype/resize/coerced-new-length-detach"><reason>TODO</reason></test>
@@ -1206,4 +1201,4 @@
12061201
<test id="staging/sm/syntax/yield-as-identifier"><reason>TODO</reason></test>
12071202
<test id="staging/sm/types/8.12.5-01"><reason>TODO</reason></test>
12081203
<test id="staging/source-phase-imports/import-source-source-text-module"><reason>TODO</reason></test>
1209-
</excludeList>
1204+
</excludeList>

0 commit comments

Comments
 (0)