@agoric/xsnap 0.14.3-u14.0 → 0.14.3-u16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/api.js +4 -2
- package/build.env +1 -1
- package/moddable/modules/data/base64/base64.js +28 -0
- package/moddable/modules/data/base64/manifest.json +11 -0
- package/moddable/modules/data/base64/modBase64.c +188 -0
- package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
- package/moddable/modules/data/crc/crc.c +205 -0
- package/moddable/modules/data/crc/crc.js +36 -0
- package/moddable/modules/data/crc/manifest.json +8 -0
- package/moddable/modules/data/hex/hex.js +28 -0
- package/moddable/modules/data/hex/manifest.json +11 -0
- package/moddable/modules/data/hex/modHex.c +139 -0
- package/moddable/modules/data/logical/logical.js +32 -0
- package/moddable/modules/data/logical/modLogical.c +98 -0
- package/moddable/modules/data/qrcode/manifest.json +9 -0
- package/moddable/modules/data/qrcode/qrcode.c +93 -0
- package/moddable/modules/data/qrcode/qrcode.js +23 -0
- package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
- package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
- package/moddable/modules/data/text/decoder/manifest.json +8 -0
- package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
- package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
- package/moddable/modules/data/text/encoder/manifest.json +8 -0
- package/moddable/modules/data/text/encoder/textencoder.c +232 -0
- package/moddable/modules/data/text/encoder/textencoder.js +24 -0
- package/moddable/modules/data/tinyint/tinyint.c +150 -0
- package/moddable/modules/data/tinyint/tinyint.js +53 -0
- package/moddable/modules/data/url/manifest.json +17 -0
- package/moddable/modules/data/url/url.c +1959 -0
- package/moddable/modules/data/url/url.js +210 -0
- package/moddable/modules/data/wavreader/manifest.json +8 -0
- package/moddable/modules/data/wavreader/wavreader.js +128 -0
- package/moddable/modules/data/zlib/deflate.c +161 -0
- package/moddable/modules/data/zlib/deflate.js +63 -0
- package/moddable/modules/data/zlib/inflate.c +145 -0
- package/moddable/modules/data/zlib/inflate.js +66 -0
- package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
- package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
- package/moddable/modules/data/zlib/miniz.c +4924 -0
- package/moddable/xs/includes/xs.d.ts +73 -0
- package/moddable/xs/includes/xs.h +1533 -0
- package/moddable/xs/includes/xsmc.h +206 -0
- package/moddable/xs/makefiles/lin/makefile +33 -0
- package/moddable/xs/makefiles/lin/xsc.mk +118 -0
- package/moddable/xs/makefiles/lin/xsid.mk +90 -0
- package/moddable/xs/makefiles/lin/xsl.mk +168 -0
- package/moddable/xs/makefiles/lin/xst.mk +201 -0
- package/moddable/xs/makefiles/mac/makefile +33 -0
- package/moddable/xs/makefiles/mac/xsc.mk +130 -0
- package/moddable/xs/makefiles/mac/xsid.mk +102 -0
- package/moddable/xs/makefiles/mac/xsl.mk +177 -0
- package/moddable/xs/makefiles/mac/xst.mk +203 -0
- package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
- package/moddable/xs/makefiles/win/build.bat +26 -0
- package/moddable/xs/makefiles/win/xsc.mak +142 -0
- package/moddable/xs/makefiles/win/xsid.mak +113 -0
- package/moddable/xs/makefiles/win/xsl.mak +186 -0
- package/moddable/xs/makefiles/win/xst.mak +195 -0
- package/moddable/xs/platforms/lin_xs.h +99 -0
- package/moddable/xs/platforms/mac_xs.h +97 -0
- package/moddable/xs/platforms/wasm_xs.h +79 -0
- package/moddable/xs/platforms/win_xs.h +104 -0
- package/moddable/xs/platforms/xsHost.h +63 -0
- package/moddable/xs/platforms/xsPlatform.h +618 -0
- package/moddable/xs/sources/xsAPI.c +2555 -0
- package/moddable/xs/sources/xsAll.c +294 -0
- package/moddable/xs/sources/xsAll.h +2741 -0
- package/moddable/xs/sources/xsArguments.c +222 -0
- package/moddable/xs/sources/xsArray.c +2657 -0
- package/moddable/xs/sources/xsAtomics.c +844 -0
- package/moddable/xs/sources/xsBigInt.c +1859 -0
- package/moddable/xs/sources/xsBoolean.c +109 -0
- package/moddable/xs/sources/xsCode.c +4493 -0
- package/moddable/xs/sources/xsCommon.c +1710 -0
- package/moddable/xs/sources/xsCommon.h +1142 -0
- package/moddable/xs/sources/xsDataView.c +2890 -0
- package/moddable/xs/sources/xsDate.c +1541 -0
- package/moddable/xs/sources/xsDebug.c +2710 -0
- package/moddable/xs/sources/xsDefaults.c +134 -0
- package/moddable/xs/sources/xsError.c +353 -0
- package/moddable/xs/sources/xsFunction.c +776 -0
- package/moddable/xs/sources/xsGenerator.c +865 -0
- package/moddable/xs/sources/xsGlobal.c +839 -0
- package/moddable/xs/sources/xsJSON.c +1091 -0
- package/moddable/xs/sources/xsLexical.c +1969 -0
- package/moddable/xs/sources/xsLockdown.c +933 -0
- package/moddable/xs/sources/xsMapSet.c +1649 -0
- package/moddable/xs/sources/xsMarshall.c +1020 -0
- package/moddable/xs/sources/xsMath.c +624 -0
- package/moddable/xs/sources/xsMemory.c +1941 -0
- package/moddable/xs/sources/xsModule.c +3101 -0
- package/moddable/xs/sources/xsNumber.c +560 -0
- package/moddable/xs/sources/xsObject.c +1102 -0
- package/moddable/xs/sources/xsPlatforms.c +480 -0
- package/moddable/xs/sources/xsProfile.c +577 -0
- package/moddable/xs/sources/xsPromise.c +1199 -0
- package/moddable/xs/sources/xsProperty.c +636 -0
- package/moddable/xs/sources/xsProxy.c +1014 -0
- package/moddable/xs/sources/xsRegExp.c +1168 -0
- package/moddable/xs/sources/xsRun.c +4889 -0
- package/moddable/xs/sources/xsScope.c +1293 -0
- package/moddable/xs/sources/xsScript.c +288 -0
- package/moddable/xs/sources/xsScript.h +1186 -0
- package/moddable/xs/sources/xsSnapshot.c +2161 -0
- package/moddable/xs/sources/xsSnapshot.h +51 -0
- package/moddable/xs/sources/xsSourceMap.c +218 -0
- package/moddable/xs/sources/xsString.c +3332 -0
- package/moddable/xs/sources/xsSymbol.c +503 -0
- package/moddable/xs/sources/xsSyntaxical.c +4193 -0
- package/moddable/xs/sources/xsTree.c +1893 -0
- package/moddable/xs/sources/xsType.c +1488 -0
- package/moddable/xs/sources/xsdtoa.c +6672 -0
- package/moddable/xs/sources/xsmc.c +340 -0
- package/moddable/xs/sources/xsre.c +7578 -0
- package/package.json +37 -20
- package/scripts/get_xsnap_version.sh +14 -0
- package/scripts/test-package.sh +21 -0
- package/src/avaAssertXS.js +6 -2
- package/src/avaHandler.cjs +2 -5
- package/src/avaXS.js +7 -8
- package/src/build.js +161 -28
- package/src/replay.js +0 -3
- package/src/xsnap.js +105 -91
- package/src/xsrepl.js +2 -3
- package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
- package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
- package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
- package/xsnap-native/xsnap/sources/xsnap.c +717 -0
- package/xsnap-native/xsnap/sources/xsnap.h +142 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
- package/CHANGELOG.md +0 -654
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-2017 Moddable Tech, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the Moddable SDK Runtime.
|
|
5
|
+
*
|
|
6
|
+
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* The Moddable SDK Runtime is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU Lesser General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
* along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*
|
|
19
|
+
* This file incorporates work covered by the following copyright and
|
|
20
|
+
* permission notice:
|
|
21
|
+
*
|
|
22
|
+
* Copyright (C) 2010-2016 Marvell International Ltd.
|
|
23
|
+
* Copyright (C) 2002-2010 Kinoma, Inc.
|
|
24
|
+
*
|
|
25
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
26
|
+
* you may not use this file except in compliance with the License.
|
|
27
|
+
* You may obtain a copy of the License at
|
|
28
|
+
*
|
|
29
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
30
|
+
*
|
|
31
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
32
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
33
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
34
|
+
* See the License for the specific language governing permissions and
|
|
35
|
+
* limitations under the License.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
#include "xsAll.h"
|
|
39
|
+
|
|
40
|
+
//#define mxPromisePrint 1
|
|
41
|
+
|
|
42
|
+
static void fxNewGeneratorResult(txMachine* the, txBoolean done);
|
|
43
|
+
|
|
44
|
+
static txSlot* fxCheckGeneratorInstance(txMachine* the, txSlot* slot);
|
|
45
|
+
static void fx_Generator_prototype_aux(txMachine* the, txFlag status);
|
|
46
|
+
|
|
47
|
+
static void fxAsyncGeneratorStep(txMachine* the, txSlot* generator, txFlag status);
|
|
48
|
+
static txSlot* fxCheckAsyncGeneratorInstance(txMachine* the, txSlot* slot);
|
|
49
|
+
static void fx_AsyncGenerator_prototype_aux(txMachine* the, txFlag status);
|
|
50
|
+
|
|
51
|
+
static txSlot* fxCheckAsyncFromSyncIteratorInstance(txMachine* the, txSlot* slot);
|
|
52
|
+
static void fx_AsyncFromSyncIterator_prototype_aux(txMachine* the, txFlag status);
|
|
53
|
+
|
|
54
|
+
void fxBuildGenerator(txMachine* the)
|
|
55
|
+
{
|
|
56
|
+
txSlot* slot;
|
|
57
|
+
txSlot* property;
|
|
58
|
+
|
|
59
|
+
mxPush(mxIteratorPrototype);
|
|
60
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
61
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Generator_prototype_next), 1, mxID(_next), XS_DONT_ENUM_FLAG);
|
|
62
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Generator_prototype_return), 1, mxID(_return), XS_DONT_ENUM_FLAG);
|
|
63
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Generator_prototype_throw), 1, mxID(_throw), XS_DONT_ENUM_FLAG);
|
|
64
|
+
slot = fxNextStringXProperty(the, slot, "Generator", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
65
|
+
mxGeneratorPrototype = *the->stack;
|
|
66
|
+
mxPop();
|
|
67
|
+
|
|
68
|
+
mxPush(mxFunctionPrototype);
|
|
69
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
70
|
+
slot = fxNextSlotProperty(the, slot, &mxGeneratorPrototype, mxID(_prototype), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
71
|
+
property = mxBehaviorSetProperty(the, mxGeneratorPrototype.value.reference, mxID(_constructor), 0, XS_OWN);
|
|
72
|
+
property->flag = XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
|
|
73
|
+
property->kind = the->stack->kind;
|
|
74
|
+
property->value = the->stack->value;
|
|
75
|
+
slot = fxNextStringXProperty(the, slot, "GeneratorFunction", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
76
|
+
mxGeneratorFunctionPrototype = *the->stack;
|
|
77
|
+
slot = fxBuildHostConstructor(the, mxCallback(fx_GeneratorFunction), 1, mxID(_GeneratorFunction));
|
|
78
|
+
slot = mxBehaviorGetProperty(the, mxGeneratorFunctionPrototype.value.reference, mxID(_constructor), 0, XS_OWN);
|
|
79
|
+
slot->flag |= XS_DONT_SET_FLAG;
|
|
80
|
+
mxPop();
|
|
81
|
+
|
|
82
|
+
mxPush(mxObjectPrototype);
|
|
83
|
+
slot = fxNewObjectInstance(the);
|
|
84
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_AsyncIterator_asyncIterator), 0, mxID(_Symbol_asyncIterator), XS_DONT_ENUM_FLAG);
|
|
85
|
+
mxPull(mxAsyncIteratorPrototype);
|
|
86
|
+
|
|
87
|
+
mxPush(mxAsyncIteratorPrototype);
|
|
88
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
89
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_AsyncGenerator_prototype_next), 1, mxID(_next), XS_DONT_ENUM_FLAG);
|
|
90
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_AsyncGenerator_prototype_return), 1, mxID(_return), XS_DONT_ENUM_FLAG);
|
|
91
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_AsyncGenerator_prototype_throw), 1, mxID(_throw), XS_DONT_ENUM_FLAG);
|
|
92
|
+
slot = fxNextStringXProperty(the, slot, "AsyncGenerator", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
93
|
+
mxAsyncGeneratorPrototype = *the->stack;
|
|
94
|
+
mxPop();
|
|
95
|
+
|
|
96
|
+
mxPush(mxFunctionPrototype);
|
|
97
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
98
|
+
slot = fxNextSlotProperty(the, slot, &mxAsyncGeneratorPrototype, mxID(_prototype), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
99
|
+
property = mxBehaviorSetProperty(the, mxAsyncGeneratorPrototype.value.reference, mxID(_constructor), 0, XS_OWN);
|
|
100
|
+
property->flag = XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
|
|
101
|
+
property->kind = the->stack->kind;
|
|
102
|
+
property->value = the->stack->value;
|
|
103
|
+
slot = fxNextStringXProperty(the, slot, "AsyncGeneratorFunction", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
104
|
+
mxAsyncGeneratorFunctionPrototype = *the->stack;
|
|
105
|
+
slot = fxBuildHostConstructor(the, mxCallback(fx_AsyncGeneratorFunction), 1, mxID(_AsyncGeneratorFunction));
|
|
106
|
+
slot = mxBehaviorGetProperty(the, mxAsyncGeneratorFunctionPrototype.value.reference, mxID(_constructor), 0, XS_OWN);
|
|
107
|
+
slot->flag |= XS_DONT_SET_FLAG;
|
|
108
|
+
mxPop();
|
|
109
|
+
|
|
110
|
+
mxPush(mxAsyncIteratorPrototype);
|
|
111
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
112
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_AsyncFromSyncIterator_prototype_next), 1, mxID(_next), XS_DONT_ENUM_FLAG);
|
|
113
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_AsyncFromSyncIterator_prototype_return), 1, mxID(_return), XS_DONT_ENUM_FLAG);
|
|
114
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_AsyncFromSyncIterator_prototype_throw), 1, mxID(_throw), XS_DONT_ENUM_FLAG);
|
|
115
|
+
slot = fxNextStringXProperty(the, slot, "Async-from-Sync Iterator", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
116
|
+
mxAsyncFromSyncIteratorPrototype = *the->stack;
|
|
117
|
+
mxPop();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
txSlot* fxCheckGeneratorInstance(txMachine* the, txSlot* slot)
|
|
121
|
+
{
|
|
122
|
+
if (slot->kind == XS_REFERENCE_KIND) {
|
|
123
|
+
txSlot* instance = slot->value.reference;
|
|
124
|
+
slot = instance->next;
|
|
125
|
+
if (slot && (slot->flag & XS_INTERNAL_FLAG) && (slot->kind == XS_STACK_KIND))
|
|
126
|
+
return instance;
|
|
127
|
+
}
|
|
128
|
+
mxTypeError("this is no Generator instance");
|
|
129
|
+
return C_NULL;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
txSlot* fxNewGeneratorInstance(txMachine* the)
|
|
133
|
+
{
|
|
134
|
+
txSlot* prototype;
|
|
135
|
+
txSlot* instance;
|
|
136
|
+
txSlot* property;
|
|
137
|
+
|
|
138
|
+
prototype = (the->stack->kind == XS_REFERENCE_KIND) ? the->stack->value.reference : mxGeneratorPrototype.value.reference;
|
|
139
|
+
|
|
140
|
+
instance = fxNewSlot(the);
|
|
141
|
+
instance->kind = XS_INSTANCE_KIND;
|
|
142
|
+
instance->value.instance.garbage = C_NULL;
|
|
143
|
+
instance->value.instance.prototype = prototype;
|
|
144
|
+
the->stack->value.reference = instance;
|
|
145
|
+
the->stack->kind = XS_REFERENCE_KIND;
|
|
146
|
+
|
|
147
|
+
property = instance->next = fxNewSlot(the);
|
|
148
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
149
|
+
property->kind = XS_STACK_KIND;
|
|
150
|
+
property->ID = XS_NO_ID;
|
|
151
|
+
property->value.stack.length = 0;
|
|
152
|
+
property->value.stack.address = C_NULL;
|
|
153
|
+
|
|
154
|
+
property = property->next = fxNewSlot(the);
|
|
155
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
156
|
+
property->kind = XS_INTEGER_KIND;
|
|
157
|
+
property->value.integer = XS_CODE_START_GENERATOR;
|
|
158
|
+
|
|
159
|
+
return instance;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
void fxNewGeneratorResult(txMachine* the, txBoolean done)
|
|
163
|
+
{
|
|
164
|
+
txSlot* value = the->stack;
|
|
165
|
+
txSlot* slot;
|
|
166
|
+
mxPush(mxObjectPrototype);
|
|
167
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
168
|
+
slot = fxNextSlotProperty(the, slot, value, mxID(_value), XS_DONT_DELETE_FLAG | XS_DONT_SET_FLAG);
|
|
169
|
+
slot = fxNextBooleanProperty(the, slot, done, mxID(_done), XS_DONT_DELETE_FLAG | XS_DONT_SET_FLAG);
|
|
170
|
+
mxPullSlot(value);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
void fx_Generator(txMachine* the)
|
|
174
|
+
{
|
|
175
|
+
if (mxTarget->kind != XS_UNDEFINED_KIND)
|
|
176
|
+
mxTypeError("new Generator");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
void fx_Generator_prototype_aux(txMachine* the, txFlag status)
|
|
180
|
+
{
|
|
181
|
+
txSlot* generator = fxCheckGeneratorInstance(the, mxThis);
|
|
182
|
+
txSlot* stack = generator->next;
|
|
183
|
+
txSlot* state = stack->next;
|
|
184
|
+
|
|
185
|
+
if (state->value.integer == XS_NO_CODE)
|
|
186
|
+
mxTypeError("generator is running");
|
|
187
|
+
if ((state->value.integer == XS_CODE_START_GENERATOR) && (status != XS_NO_STATUS))
|
|
188
|
+
state->value.integer = XS_CODE_END;
|
|
189
|
+
if (mxArgc > 0)
|
|
190
|
+
mxPushSlot(mxArgv(0));
|
|
191
|
+
else
|
|
192
|
+
mxPushUndefined();
|
|
193
|
+
if (state->value.integer == XS_CODE_END) {
|
|
194
|
+
if (status == XS_THROW_STATUS) {
|
|
195
|
+
mxException.kind = the->stack->kind;
|
|
196
|
+
mxException.value = the->stack->value;
|
|
197
|
+
fxJump(the);
|
|
198
|
+
}
|
|
199
|
+
if (status == XS_NO_STATUS)
|
|
200
|
+
the->stack->kind = XS_UNDEFINED_KIND;
|
|
201
|
+
fxNewGeneratorResult(the, 1);
|
|
202
|
+
mxPullSlot(mxResult);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
mxTry(the) {
|
|
206
|
+
the->scratch.kind = the->stack->kind;
|
|
207
|
+
the->scratch.value = the->stack->value;
|
|
208
|
+
the->status = status;
|
|
209
|
+
state->value.integer = XS_NO_CODE;
|
|
210
|
+
fxRunID(the, generator, XS_NO_ID);
|
|
211
|
+
if (state->value.integer == XS_NO_CODE) {
|
|
212
|
+
state->value.integer = XS_CODE_END;
|
|
213
|
+
fxNewGeneratorResult(the, 1);
|
|
214
|
+
}
|
|
215
|
+
mxPullSlot(mxResult);
|
|
216
|
+
}
|
|
217
|
+
mxCatch(the) {
|
|
218
|
+
state->value.integer = XS_CODE_END;
|
|
219
|
+
fxJump(the);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
void fx_Generator_prototype_next(txMachine* the)
|
|
225
|
+
{
|
|
226
|
+
fx_Generator_prototype_aux(the, XS_NO_STATUS);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
void fx_Generator_prototype_return(txMachine* the)
|
|
230
|
+
{
|
|
231
|
+
fx_Generator_prototype_aux(the, XS_RETURN_STATUS);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void fx_Generator_prototype_throw(txMachine* the)
|
|
235
|
+
{
|
|
236
|
+
fx_Generator_prototype_aux(the, XS_THROW_STATUS);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
txSlot* fxNewGeneratorFunctionInstance(txMachine* the, txID name)
|
|
240
|
+
{
|
|
241
|
+
txSlot* instance;
|
|
242
|
+
txSlot* property;
|
|
243
|
+
|
|
244
|
+
instance = fxNewFunctionInstance(the, name);
|
|
245
|
+
property = fxLastProperty(the, instance);
|
|
246
|
+
mxPush(mxGeneratorPrototype);
|
|
247
|
+
fxNewObjectInstance(the);
|
|
248
|
+
fxNextSlotProperty(the, property, the->stack, mxID(_prototype), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG);
|
|
249
|
+
mxPop();
|
|
250
|
+
|
|
251
|
+
return instance;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
void fx_GeneratorFunction(txMachine* the)
|
|
255
|
+
{
|
|
256
|
+
txInteger c, i;
|
|
257
|
+
txStringStream stream;
|
|
258
|
+
txSlot* module = mxFunctionInstanceHome(mxFunction->value.reference)->value.home.module;
|
|
259
|
+
if (!module) module = mxProgram.value.reference;
|
|
260
|
+
|
|
261
|
+
c = mxArgc;
|
|
262
|
+
i = 0;
|
|
263
|
+
mxPushStringX("(function* anonymous(");
|
|
264
|
+
while (c > 1) {
|
|
265
|
+
fxToString(the, mxArgv(i));
|
|
266
|
+
fxConcatString(the, the->stack, mxArgv(i));
|
|
267
|
+
if (c > 2)
|
|
268
|
+
fxConcatStringC(the, the->stack, ", ");
|
|
269
|
+
c--;
|
|
270
|
+
i++;
|
|
271
|
+
}
|
|
272
|
+
fxConcatStringC(the, the->stack, "\n){");
|
|
273
|
+
if (c > 0) {
|
|
274
|
+
fxToString(the, mxArgv(i));
|
|
275
|
+
fxConcatString(the, the->stack, mxArgv(i));
|
|
276
|
+
}
|
|
277
|
+
fxConcatStringC(the, the->stack, "\n})");
|
|
278
|
+
stream.slot = the->stack;
|
|
279
|
+
stream.offset = 0;
|
|
280
|
+
stream.size = mxStringLength(the->stack->value.string);
|
|
281
|
+
fxRunScript(the, fxParseScript(the, &stream, fxStringGetter, mxProgramFlag | mxGeneratorFlag), C_NULL, C_NULL, C_NULL, C_NULL, module);
|
|
282
|
+
mxPullSlot(mxResult);
|
|
283
|
+
if (!mxIsUndefined(mxTarget) && !fxIsSameSlot(the, mxTarget, mxFunction)) {
|
|
284
|
+
mxPushSlot(mxTarget);
|
|
285
|
+
fxGetPrototypeFromConstructor(the, &mxGeneratorFunctionPrototype);
|
|
286
|
+
mxResult->value.reference->value.instance.prototype = the->stack->value.reference;
|
|
287
|
+
mxPop();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
void fxAsyncGeneratorRejectAwait(txMachine* the)
|
|
292
|
+
{
|
|
293
|
+
txSlot* slot = mxFunctionInstanceHome(mxFunction->value.reference);
|
|
294
|
+
txSlot* generator = slot->value.home.object;
|
|
295
|
+
the->scratch.kind = mxArgv(0)->kind;
|
|
296
|
+
the->scratch.value = mxArgv(0)->value;
|
|
297
|
+
fxAsyncGeneratorStep(the, generator, XS_THROW_STATUS);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
void fxAsyncGeneratorRejectYield(txMachine* the)
|
|
301
|
+
{
|
|
302
|
+
txSlot* home = mxFunctionInstanceHome(mxFunction->value.reference);
|
|
303
|
+
txSlot* generator = home->value.home.object;
|
|
304
|
+
txSlot* stack = generator->next;
|
|
305
|
+
txSlot* state = stack->next;
|
|
306
|
+
if (state->value.integer == XS_CODE_END) {
|
|
307
|
+
txSlot* queue = state->next;
|
|
308
|
+
txSlot* current = queue->value.list.first;
|
|
309
|
+
txSlot* resolveFunction = current->value.reference->next;
|
|
310
|
+
txSlot* rejectFunction = resolveFunction->next;
|
|
311
|
+
|
|
312
|
+
mxPushUndefined();
|
|
313
|
+
mxPushSlot(rejectFunction);
|
|
314
|
+
mxCall();
|
|
315
|
+
mxPushSlot(mxArgv(0));
|
|
316
|
+
|
|
317
|
+
queue->value.list.first = current = current->next;
|
|
318
|
+
if (current == C_NULL)
|
|
319
|
+
queue->value.list.last = C_NULL;
|
|
320
|
+
|
|
321
|
+
mxRunCount(1);
|
|
322
|
+
mxPop();
|
|
323
|
+
|
|
324
|
+
if (current) {
|
|
325
|
+
txSlot* resolveFunction = current->value.reference->next;
|
|
326
|
+
txSlot* rejectFunction = resolveFunction->next;
|
|
327
|
+
txSlot* status = rejectFunction->next;
|
|
328
|
+
txSlot* value = status->next;
|
|
329
|
+
the->scratch.kind = value->kind;
|
|
330
|
+
the->scratch.value = value->value;
|
|
331
|
+
fxAsyncGeneratorStep(the, generator, status->value.integer);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
mxPushSlot(mxArgv(0));
|
|
336
|
+
mxPull(the->scratch);
|
|
337
|
+
fxAsyncGeneratorStep(the, generator, XS_THROW_STATUS);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
void fxAsyncGeneratorResolveAwait(txMachine* the)
|
|
342
|
+
{
|
|
343
|
+
txSlot* slot = mxFunctionInstanceHome(mxFunction->value.reference);
|
|
344
|
+
txSlot* generator = slot->value.home.object;
|
|
345
|
+
the->scratch.kind = mxArgv(0)->kind;
|
|
346
|
+
the->scratch.value = mxArgv(0)->value;
|
|
347
|
+
fxAsyncGeneratorStep(the, generator, XS_NO_STATUS);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
void fxAsyncGeneratorResolveYield(txMachine* the)
|
|
351
|
+
{
|
|
352
|
+
txSlot* home = mxFunctionInstanceHome(mxFunction->value.reference);
|
|
353
|
+
txSlot* generator = home->value.home.object;
|
|
354
|
+
txSlot* stack = generator->next;
|
|
355
|
+
txSlot* state = stack->next;
|
|
356
|
+
txSlot* queue = state->next;
|
|
357
|
+
txSlot* current = queue->value.list.first;
|
|
358
|
+
txSlot* resolveFunction = current->value.reference->next;
|
|
359
|
+
|
|
360
|
+
mxPushUndefined();
|
|
361
|
+
mxPushSlot(resolveFunction);
|
|
362
|
+
mxCall();
|
|
363
|
+
mxPushSlot(mxArgv(0));
|
|
364
|
+
fxNewGeneratorResult(the, (state->value.integer == XS_CODE_END) ? 1 : 0);
|
|
365
|
+
|
|
366
|
+
queue->value.list.first = current = current->next;
|
|
367
|
+
if (current == C_NULL)
|
|
368
|
+
queue->value.list.last = C_NULL;
|
|
369
|
+
|
|
370
|
+
mxRunCount(1);
|
|
371
|
+
mxPop();
|
|
372
|
+
|
|
373
|
+
if (current) {
|
|
374
|
+
txSlot* resolveFunction = current->value.reference->next;
|
|
375
|
+
txSlot* rejectFunction = resolveFunction->next;
|
|
376
|
+
txSlot* status = rejectFunction->next;
|
|
377
|
+
txSlot* value = status->next;
|
|
378
|
+
the->scratch.kind = value->kind;
|
|
379
|
+
the->scratch.value = value->value;
|
|
380
|
+
fxAsyncGeneratorStep(the, generator, status->value.integer);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
void fxAsyncGeneratorStep(txMachine* the, txSlot* generator, txFlag status)
|
|
385
|
+
{
|
|
386
|
+
txSlot* stack = generator->next;
|
|
387
|
+
txSlot* state = stack->next;
|
|
388
|
+
txSlot* queue = state->next;
|
|
389
|
+
txSlot* resolveAwaitFunction = queue->next;
|
|
390
|
+
txSlot* rejectAwaitFunction = resolveAwaitFunction->next;
|
|
391
|
+
txSlot* resolveYieldFunction = rejectAwaitFunction->next;
|
|
392
|
+
txSlot* rejectYieldFunction = resolveYieldFunction->next;
|
|
393
|
+
txSlot* resolveFunction;
|
|
394
|
+
txSlot* rejectFunction;
|
|
395
|
+
txSlot* value;
|
|
396
|
+
|
|
397
|
+
mxTry(the) {
|
|
398
|
+
if (state->value.integer == XS_CODE_END) {
|
|
399
|
+
mxPush(the->scratch);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
the->status = status;
|
|
403
|
+
status = XS_NO_STATUS;
|
|
404
|
+
state->value.integer = XS_NO_CODE;
|
|
405
|
+
fxRunID(the, generator, XS_NO_ID);
|
|
406
|
+
}
|
|
407
|
+
value = the->stack;
|
|
408
|
+
if (state->value.integer == XS_NO_CODE) {
|
|
409
|
+
state->value.integer = XS_CODE_END;
|
|
410
|
+
if (value->kind == XS_UNINITIALIZED_KIND)
|
|
411
|
+
value->kind = XS_UNDEFINED_KIND;
|
|
412
|
+
mxPushUndefined();
|
|
413
|
+
mxPushSlot(resolveYieldFunction);
|
|
414
|
+
mxCall();
|
|
415
|
+
mxPushSlot(value);
|
|
416
|
+
mxRunCount(1);
|
|
417
|
+
mxPop();
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
if (status != XS_THROW_STATUS) {
|
|
421
|
+
if (mxIsReference(value) && mxIsPromise(value->value.reference)) {
|
|
422
|
+
mxDub();
|
|
423
|
+
mxGetID(mxID(_constructor));
|
|
424
|
+
if (fxIsSameValue(the, &mxPromiseConstructor, the->stack, 0)) {
|
|
425
|
+
mxPop();
|
|
426
|
+
if (state->value.integer == XS_CODE_AWAIT) {
|
|
427
|
+
fxPromiseThen(the, value->value.reference, resolveAwaitFunction, rejectAwaitFunction, C_NULL, C_NULL);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
fxPromiseThen(the, value->value.reference, resolveYieldFunction, rejectYieldFunction, C_NULL, C_NULL);
|
|
431
|
+
}
|
|
432
|
+
goto exit;
|
|
433
|
+
}
|
|
434
|
+
mxPop();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
mxTemporary(resolveFunction);
|
|
438
|
+
mxTemporary(rejectFunction);
|
|
439
|
+
mxPush(mxPromiseConstructor);
|
|
440
|
+
fxNewPromiseCapability(the, resolveFunction, rejectFunction);
|
|
441
|
+
#ifdef mxPromisePrint
|
|
442
|
+
fprintf(stderr, "fxAsyncGeneratorStep %d\n", the->stack->value.reference->next->ID);
|
|
443
|
+
#endif
|
|
444
|
+
if (state->value.integer == XS_CODE_AWAIT) {
|
|
445
|
+
fxPromiseThen(the, the->stack->value.reference, resolveAwaitFunction, rejectAwaitFunction, C_NULL, C_NULL);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
fxPromiseThen(the, the->stack->value.reference, resolveYieldFunction, rejectYieldFunction, C_NULL, C_NULL);
|
|
449
|
+
}
|
|
450
|
+
/* THIS */
|
|
451
|
+
mxPushUndefined();
|
|
452
|
+
/* FUNCTION */
|
|
453
|
+
if (status == XS_THROW_STATUS)
|
|
454
|
+
mxPushSlot(rejectFunction);
|
|
455
|
+
else
|
|
456
|
+
mxPushSlot(resolveFunction);
|
|
457
|
+
mxCall();
|
|
458
|
+
/* ARGUMENTS */
|
|
459
|
+
mxPushSlot(value);
|
|
460
|
+
/* COUNT */
|
|
461
|
+
mxRunCount(1);
|
|
462
|
+
mxPop();
|
|
463
|
+
}
|
|
464
|
+
exit:
|
|
465
|
+
mxPop();
|
|
466
|
+
}
|
|
467
|
+
mxCatch(the) {
|
|
468
|
+
mxTemporary(resolveFunction);
|
|
469
|
+
mxTemporary(rejectFunction);
|
|
470
|
+
mxPush(mxPromiseConstructor);
|
|
471
|
+
fxNewPromiseCapability(the, resolveFunction, rejectFunction);
|
|
472
|
+
if (state->value.integer == XS_CODE_AWAIT) {
|
|
473
|
+
fxPromiseThen(the, the->stack->value.reference, resolveAwaitFunction, rejectAwaitFunction, C_NULL, C_NULL);
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
state->value.integer = XS_CODE_END;
|
|
477
|
+
fxPromiseThen(the, the->stack->value.reference, resolveYieldFunction, rejectYieldFunction, C_NULL, C_NULL);
|
|
478
|
+
}
|
|
479
|
+
fxRejectException(the, rejectFunction);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
txSlot* fxCheckAsyncGeneratorInstance(txMachine* the, txSlot* slot)
|
|
484
|
+
{
|
|
485
|
+
if (slot->kind == XS_REFERENCE_KIND) {
|
|
486
|
+
txSlot* instance = slot->value.reference;
|
|
487
|
+
slot = instance->next;
|
|
488
|
+
if (slot && (slot->flag & XS_INTERNAL_FLAG) && (slot->kind == XS_STACK_KIND)) {
|
|
489
|
+
slot = slot->next;
|
|
490
|
+
if (slot && (slot->flag & XS_INTERNAL_FLAG) && (slot->kind == XS_INTEGER_KIND)) {
|
|
491
|
+
slot = slot->next;
|
|
492
|
+
if (slot && (slot->flag & XS_INTERNAL_FLAG) && (slot->kind == XS_LIST_KIND)) {
|
|
493
|
+
return instance;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
mxTypeError("this is no AsyncGenerator instance");
|
|
499
|
+
return C_NULL;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
txSlot* fxNewAsyncGeneratorInstance(txMachine* the)
|
|
503
|
+
{
|
|
504
|
+
txSlot* prototype;
|
|
505
|
+
txSlot* instance;
|
|
506
|
+
txSlot* property;
|
|
507
|
+
txSlot* function;
|
|
508
|
+
txSlot* home;
|
|
509
|
+
|
|
510
|
+
prototype = (the->stack->kind == XS_REFERENCE_KIND) ? the->stack->value.reference : mxAsyncGeneratorPrototype.value.reference;
|
|
511
|
+
|
|
512
|
+
instance = fxNewSlot(the);
|
|
513
|
+
instance->kind = XS_INSTANCE_KIND;
|
|
514
|
+
instance->value.instance.garbage = C_NULL;
|
|
515
|
+
instance->value.instance.prototype = prototype;
|
|
516
|
+
the->stack->value.reference = instance;
|
|
517
|
+
the->stack->kind = XS_REFERENCE_KIND;
|
|
518
|
+
|
|
519
|
+
property = instance->next = fxNewSlot(the);
|
|
520
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
521
|
+
property->kind = XS_STACK_KIND;
|
|
522
|
+
property->ID = XS_NO_ID;
|
|
523
|
+
property->value.stack.length = 0;
|
|
524
|
+
property->value.stack.address = C_NULL;
|
|
525
|
+
|
|
526
|
+
property = property->next = fxNewSlot(the);
|
|
527
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
528
|
+
property->kind = XS_INTEGER_KIND;
|
|
529
|
+
property->value.integer = XS_CODE_START_ASYNC_GENERATOR;
|
|
530
|
+
|
|
531
|
+
property = property->next = fxNewSlot(the);
|
|
532
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
533
|
+
property->kind = XS_LIST_KIND;
|
|
534
|
+
property->value.list.first = C_NULL;
|
|
535
|
+
property->value.list.last = C_NULL;
|
|
536
|
+
|
|
537
|
+
function = fxNewHostFunction(the, fxAsyncGeneratorResolveAwait, 1, XS_NO_ID, mxAsyncGeneratorResolveAwaitProfileID);
|
|
538
|
+
home = mxFunctionInstanceHome(function);
|
|
539
|
+
home->value.home.object = instance;
|
|
540
|
+
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
541
|
+
mxPop();
|
|
542
|
+
|
|
543
|
+
function = fxNewHostFunction(the, fxAsyncGeneratorRejectAwait, 1, XS_NO_ID, mxAsyncGeneratorRejectAwaitProfileID);
|
|
544
|
+
home = mxFunctionInstanceHome(function);
|
|
545
|
+
home->value.home.object = instance;
|
|
546
|
+
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
547
|
+
mxPop();
|
|
548
|
+
|
|
549
|
+
function = fxNewHostFunction(the, fxAsyncGeneratorResolveYield, 1, XS_NO_ID, mxAsyncGeneratorResolveYieldProfileID);
|
|
550
|
+
home = mxFunctionInstanceHome(function);
|
|
551
|
+
home->value.home.object = instance;
|
|
552
|
+
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
553
|
+
mxPop();
|
|
554
|
+
|
|
555
|
+
function = fxNewHostFunction(the, fxAsyncGeneratorRejectYield, 1, XS_NO_ID, mxAsyncGeneratorRejectYieldProfileID);
|
|
556
|
+
home = mxFunctionInstanceHome(function);
|
|
557
|
+
home->value.home.object = instance;
|
|
558
|
+
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
559
|
+
mxPop();
|
|
560
|
+
|
|
561
|
+
return instance;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
void fx_AsyncGenerator(txMachine* the)
|
|
566
|
+
{
|
|
567
|
+
if (mxTarget->kind != XS_UNDEFINED_KIND)
|
|
568
|
+
mxTypeError("new AsyncGenerator");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
void fx_AsyncGenerator_prototype_aux(txMachine* the, txFlag status)
|
|
572
|
+
{
|
|
573
|
+
txSlot* stack = the->stack;
|
|
574
|
+
txSlot* resolveFunction;
|
|
575
|
+
txSlot* rejectFunction;
|
|
576
|
+
txSlot* slot;
|
|
577
|
+
txSlot* generator;
|
|
578
|
+
txSlot* state;
|
|
579
|
+
txSlot* queue;
|
|
580
|
+
txSlot* instance;
|
|
581
|
+
txSlot* property;
|
|
582
|
+
|
|
583
|
+
mxTemporary(resolveFunction);
|
|
584
|
+
mxTemporary(rejectFunction);
|
|
585
|
+
mxPush(mxPromiseConstructor);
|
|
586
|
+
fxNewPromiseCapability(the, resolveFunction, rejectFunction);
|
|
587
|
+
mxPullSlot(mxResult);
|
|
588
|
+
#ifdef mxPromisePrint
|
|
589
|
+
fprintf(stderr, "fx_AsyncGenerator_prototype_aux %d\n", mxResult->value.reference->next->ID);
|
|
590
|
+
#endif
|
|
591
|
+
{
|
|
592
|
+
mxTry(the) {
|
|
593
|
+
generator = fxCheckAsyncGeneratorInstance(the, mxThis);
|
|
594
|
+
state = generator->next->next;
|
|
595
|
+
queue = state->next;
|
|
596
|
+
if (((status == XS_RETURN_STATUS) || (status == XS_THROW_STATUS))
|
|
597
|
+
&& (
|
|
598
|
+
/*(state->value.integer == XS_CODE_AWAIT) ||*/ (state->value.integer == XS_CODE_START_ASYNC_GENERATOR)))
|
|
599
|
+
state->value.integer = XS_CODE_END;
|
|
600
|
+
instance = property = fxNewInstance(the);
|
|
601
|
+
property = fxNextSlotProperty(the, property, resolveFunction, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
602
|
+
property = fxNextSlotProperty(the, property, rejectFunction, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
603
|
+
property = fxNextIntegerProperty(the, property, status, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
604
|
+
if (mxArgc > 0)
|
|
605
|
+
property = fxNextSlotProperty(the, property, mxArgv(0), XS_NO_ID, XS_INTERNAL_FLAG);
|
|
606
|
+
else
|
|
607
|
+
property = fxNextUndefinedProperty(the, property, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
608
|
+
slot = fxNewSlot(the);
|
|
609
|
+
slot->kind = XS_REFERENCE_KIND;
|
|
610
|
+
slot->value.reference = instance;
|
|
611
|
+
if (queue->value.list.first) {
|
|
612
|
+
queue->value.list.last->next = slot;
|
|
613
|
+
queue->value.list.last = slot;
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
queue->value.list.first = slot;
|
|
617
|
+
queue->value.list.last = slot;
|
|
618
|
+
the->scratch.kind = property->kind;
|
|
619
|
+
the->scratch.value = property->value;
|
|
620
|
+
fxAsyncGeneratorStep(the, generator, status);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
mxCatch(the) {
|
|
624
|
+
fxRejectException(the, rejectFunction);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
the->stack = stack;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
void fx_AsyncGenerator_prototype_next(txMachine* the)
|
|
631
|
+
{
|
|
632
|
+
fx_AsyncGenerator_prototype_aux(the, XS_NO_STATUS);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
void fx_AsyncGenerator_prototype_return(txMachine* the)
|
|
636
|
+
{
|
|
637
|
+
fx_AsyncGenerator_prototype_aux(the, XS_RETURN_STATUS);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
void fx_AsyncGenerator_prototype_throw(txMachine* the)
|
|
641
|
+
{
|
|
642
|
+
fx_AsyncGenerator_prototype_aux(the, XS_THROW_STATUS);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
txSlot* fxNewAsyncGeneratorFunctionInstance(txMachine* the, txID name)
|
|
646
|
+
{
|
|
647
|
+
txSlot* instance;
|
|
648
|
+
txSlot* property;
|
|
649
|
+
|
|
650
|
+
instance = fxNewFunctionInstance(the, name);
|
|
651
|
+
property = fxLastProperty(the, instance);
|
|
652
|
+
mxPush(mxAsyncGeneratorPrototype);
|
|
653
|
+
fxNewObjectInstance(the);
|
|
654
|
+
fxNextSlotProperty(the, property, the->stack, mxID(_prototype), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG);
|
|
655
|
+
mxPop();
|
|
656
|
+
|
|
657
|
+
return instance;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
void fx_AsyncGeneratorFunction(txMachine* the)
|
|
661
|
+
{
|
|
662
|
+
txInteger c, i;
|
|
663
|
+
txStringStream stream;
|
|
664
|
+
txSlot* module = mxFunctionInstanceHome(mxFunction->value.reference)->value.home.module;
|
|
665
|
+
if (!module) module = mxProgram.value.reference;
|
|
666
|
+
|
|
667
|
+
c = mxArgc;
|
|
668
|
+
i = 0;
|
|
669
|
+
mxPushStringX("(async function* anonymous(");
|
|
670
|
+
while (c > 1) {
|
|
671
|
+
fxToString(the, mxArgv(i));
|
|
672
|
+
fxConcatString(the, the->stack, mxArgv(i));
|
|
673
|
+
if (c > 2)
|
|
674
|
+
fxConcatStringC(the, the->stack, ", ");
|
|
675
|
+
c--;
|
|
676
|
+
i++;
|
|
677
|
+
}
|
|
678
|
+
fxConcatStringC(the, the->stack, "\n){");
|
|
679
|
+
if (c > 0) {
|
|
680
|
+
fxToString(the, mxArgv(i));
|
|
681
|
+
fxConcatString(the, the->stack, mxArgv(i));
|
|
682
|
+
}
|
|
683
|
+
fxConcatStringC(the, the->stack, "\n})");
|
|
684
|
+
stream.slot = the->stack;
|
|
685
|
+
stream.offset = 0;
|
|
686
|
+
stream.size = mxStringLength(the->stack->value.string);
|
|
687
|
+
fxRunScript(the, fxParseScript(the, &stream, fxStringGetter, mxProgramFlag | mxGeneratorFlag), C_NULL, C_NULL, C_NULL, C_NULL, module);
|
|
688
|
+
mxPullSlot(mxResult);
|
|
689
|
+
if (!mxIsUndefined(mxTarget) && !fxIsSameSlot(the, mxTarget, mxFunction)) {
|
|
690
|
+
mxPushSlot(mxTarget);
|
|
691
|
+
fxGetPrototypeFromConstructor(the, &mxAsyncGeneratorFunctionPrototype);
|
|
692
|
+
mxResult->value.reference->value.instance.prototype = the->stack->value.reference;
|
|
693
|
+
mxPop();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
void fx_AsyncIterator_asyncIterator(txMachine* the)
|
|
698
|
+
{
|
|
699
|
+
*mxResult = *mxThis;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
void fxAsyncFromSyncIteratorDone(txMachine* the)
|
|
703
|
+
{
|
|
704
|
+
txSlot* slot = mxFunctionInstanceHome(mxFunction->value.reference);
|
|
705
|
+
txSlot* instance = slot->value.home.object;
|
|
706
|
+
txSlot* iterator = instance->next;
|
|
707
|
+
txSlot* nextFunction = iterator->next;
|
|
708
|
+
txSlot* doneFunction = nextFunction->next;
|
|
709
|
+
txSlot* doneFlag = doneFunction->next;
|
|
710
|
+
mxPushSlot(mxArgv(0));
|
|
711
|
+
fxNewGeneratorResult(the, doneFlag->value.boolean);
|
|
712
|
+
mxPullSlot(mxResult);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
txSlot* fxCheckAsyncFromSyncIteratorInstance(txMachine* the, txSlot* slot)
|
|
716
|
+
{
|
|
717
|
+
if (slot->kind == XS_REFERENCE_KIND) {
|
|
718
|
+
txSlot* instance = slot->value.reference;
|
|
719
|
+
slot = instance->next;
|
|
720
|
+
if (slot && (slot->flag & XS_INTERNAL_FLAG) && (slot->ID == mxID(_iterator)))
|
|
721
|
+
return instance;
|
|
722
|
+
}
|
|
723
|
+
mxTypeError("this is no AsyncFromSyncIterator instance");
|
|
724
|
+
return C_NULL;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
txSlot* fxNewAsyncFromSyncIteratorInstance(txMachine* the)
|
|
728
|
+
{
|
|
729
|
+
txSlot* iterator = the->stack;
|
|
730
|
+
txSlot* instance;
|
|
731
|
+
txSlot* slot;
|
|
732
|
+
txSlot* function;
|
|
733
|
+
txSlot* home;
|
|
734
|
+
mxPush(mxAsyncFromSyncIteratorPrototype);
|
|
735
|
+
instance = fxNewObjectInstance(the);
|
|
736
|
+
slot = fxLastProperty(the, instance);
|
|
737
|
+
|
|
738
|
+
slot = fxNextSlotProperty(the, slot, iterator, mxID(_iterator), XS_INTERNAL_FLAG);
|
|
739
|
+
|
|
740
|
+
mxPushSlot(iterator);
|
|
741
|
+
mxGetID(mxID(_next));
|
|
742
|
+
slot = fxNextSlotProperty(the, slot, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
743
|
+
mxPop();
|
|
744
|
+
|
|
745
|
+
function = fxNewHostFunction(the, fxAsyncFromSyncIteratorDone, 1, XS_NO_ID, mxAsyncFromSyncIteratorDoneProfileID);
|
|
746
|
+
home = mxFunctionInstanceHome(function);
|
|
747
|
+
home->value.home.object = instance;
|
|
748
|
+
slot = fxNextSlotProperty(the, slot, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
749
|
+
mxPop();
|
|
750
|
+
|
|
751
|
+
slot = fxNextBooleanProperty(the, slot, 0, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
752
|
+
|
|
753
|
+
mxPullSlot(iterator);
|
|
754
|
+
return instance;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
void fx_AsyncFromSyncIterator_prototype_aux(txMachine* the, txFlag status)
|
|
758
|
+
{
|
|
759
|
+
txSlot* stack = the->stack;
|
|
760
|
+
txSlot* resolveFunction;
|
|
761
|
+
txSlot* rejectFunction;
|
|
762
|
+
txSlot* slot;
|
|
763
|
+
txSlot* instance;
|
|
764
|
+
txSlot* iterator;
|
|
765
|
+
txSlot* stepFunction = C_NULL;
|
|
766
|
+
|
|
767
|
+
mxTemporary(resolveFunction);
|
|
768
|
+
mxTemporary(rejectFunction);
|
|
769
|
+
mxPush(mxPromiseConstructor);
|
|
770
|
+
fxNewPromiseCapability(the, resolveFunction, rejectFunction);
|
|
771
|
+
mxPullSlot(mxResult);
|
|
772
|
+
#ifdef mxPromisePrint
|
|
773
|
+
fprintf(stderr, "fx_AsyncFromSyncIterator_prototype_aux %d %d\n", mxResult->value.reference->next->ID, status);
|
|
774
|
+
#endif
|
|
775
|
+
{
|
|
776
|
+
mxTry(the) {
|
|
777
|
+
instance = fxCheckAsyncFromSyncIteratorInstance(the, mxThis);
|
|
778
|
+
iterator = instance->next;
|
|
779
|
+
if (status == XS_NO_STATUS) {
|
|
780
|
+
stepFunction = iterator->next;
|
|
781
|
+
}
|
|
782
|
+
else if (status == XS_RETURN_STATUS) {
|
|
783
|
+
mxPushSlot(iterator);
|
|
784
|
+
mxGetID(mxID(_return));
|
|
785
|
+
if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) {
|
|
786
|
+
mxPushUndefined();
|
|
787
|
+
mxPushSlot(resolveFunction);
|
|
788
|
+
mxCall();
|
|
789
|
+
mxPushUndefined();
|
|
790
|
+
fxNewGeneratorResult(the, 1);
|
|
791
|
+
mxRunCount(1);
|
|
792
|
+
}
|
|
793
|
+
else
|
|
794
|
+
stepFunction = the->stack;
|
|
795
|
+
}
|
|
796
|
+
else {
|
|
797
|
+
mxPushSlot(iterator);
|
|
798
|
+
mxGetID(mxID(_throw));
|
|
799
|
+
if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) {
|
|
800
|
+
mxPushUndefined();
|
|
801
|
+
mxPushSlot(rejectFunction);
|
|
802
|
+
mxCall();
|
|
803
|
+
if (mxArgc == 0)
|
|
804
|
+
mxPushUndefined();
|
|
805
|
+
else
|
|
806
|
+
mxPushSlot(mxArgv(0));
|
|
807
|
+
mxRunCount(1);
|
|
808
|
+
}
|
|
809
|
+
else
|
|
810
|
+
stepFunction = the->stack;
|
|
811
|
+
}
|
|
812
|
+
if (stepFunction) {
|
|
813
|
+
txSlot* doneFunction = iterator->next->next;
|
|
814
|
+
txSlot* doneFlag = doneFunction->next;
|
|
815
|
+
mxPushSlot(iterator);
|
|
816
|
+
mxPushSlot(stepFunction);
|
|
817
|
+
mxCall();
|
|
818
|
+
if (mxArgc == 0)
|
|
819
|
+
mxRunCount(0);
|
|
820
|
+
else {
|
|
821
|
+
mxPushSlot(mxArgv(0));
|
|
822
|
+
mxRunCount(1);
|
|
823
|
+
}
|
|
824
|
+
slot = the->stack;
|
|
825
|
+
if (!mxIsReference(slot)) {
|
|
826
|
+
mxTypeError("no object");
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
mxPushSlot(slot);
|
|
830
|
+
mxGetID(mxID(_done));
|
|
831
|
+
doneFlag->value.boolean = fxToBoolean(the, the->stack);
|
|
832
|
+
|
|
833
|
+
mxPushUndefined();
|
|
834
|
+
mxPush(mxPromiseConstructor);
|
|
835
|
+
mxPushSlot(slot);
|
|
836
|
+
mxGetID(mxID(_value));
|
|
837
|
+
fx_Promise_resolveAux(the);
|
|
838
|
+
mxPop();
|
|
839
|
+
mxPop();
|
|
840
|
+
fxPromiseThen(the, the->stack->value.reference, doneFunction, C_NULL, resolveFunction, rejectFunction);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
mxCatch(the) {
|
|
844
|
+
fxRejectException(the, rejectFunction);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
the->stack = stack;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
void fx_AsyncFromSyncIterator_prototype_next(txMachine* the)
|
|
851
|
+
{
|
|
852
|
+
fx_AsyncFromSyncIterator_prototype_aux(the, XS_NO_STATUS);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
void fx_AsyncFromSyncIterator_prototype_return(txMachine* the)
|
|
856
|
+
{
|
|
857
|
+
fx_AsyncFromSyncIterator_prototype_aux(the, XS_RETURN_STATUS);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
void fx_AsyncFromSyncIterator_prototype_throw(txMachine* the)
|
|
861
|
+
{
|
|
862
|
+
fx_AsyncFromSyncIterator_prototype_aux(the, XS_THROW_STATUS);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
|