@agoric/xsnap 0.14.3-u14.0 → 0.14.3-u16.1
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,1488 @@
|
|
|
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
|
+
const txBehavior ICACHE_FLASH_ATTR gxOrdinaryBehavior = {
|
|
41
|
+
fxOrdinaryGetProperty,
|
|
42
|
+
fxOrdinarySetProperty,
|
|
43
|
+
fxOrdinaryCall,
|
|
44
|
+
fxOrdinaryConstruct,
|
|
45
|
+
fxOrdinaryDefineOwnProperty,
|
|
46
|
+
fxOrdinaryDeleteProperty,
|
|
47
|
+
fxOrdinaryGetOwnProperty,
|
|
48
|
+
fxOrdinaryGetPropertyValue,
|
|
49
|
+
fxOrdinaryGetPrototype,
|
|
50
|
+
fxOrdinaryHasProperty,
|
|
51
|
+
fxOrdinaryIsExtensible,
|
|
52
|
+
fxOrdinaryOwnKeys,
|
|
53
|
+
fxOrdinaryPreventExtensions,
|
|
54
|
+
fxOrdinarySetPropertyValue,
|
|
55
|
+
fxOrdinarySetPrototype,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
txSlot* fxAliasInstance(txMachine* the, txSlot* instance)
|
|
59
|
+
{
|
|
60
|
+
txSlot* alias;
|
|
61
|
+
txSlot* from;
|
|
62
|
+
txSlot* to;
|
|
63
|
+
the->aliasArray[instance->ID] = alias = fxNewSlot(the);
|
|
64
|
+
alias->flag = instance->flag & ~(XS_MARK_FLAG | XS_DONT_MARSHALL_FLAG);
|
|
65
|
+
alias->kind = XS_INSTANCE_KIND;
|
|
66
|
+
alias->value.instance.garbage = instance->value.instance.garbage;
|
|
67
|
+
alias->value.instance.prototype = instance->value.instance.prototype;
|
|
68
|
+
from = instance->next;
|
|
69
|
+
to = alias;
|
|
70
|
+
while (from) {
|
|
71
|
+
to = to->next = fxDuplicateSlot(the, from);
|
|
72
|
+
if (to->kind == XS_ARRAY_KIND) {
|
|
73
|
+
txSlot* address = to->value.array.address;
|
|
74
|
+
if (address) {
|
|
75
|
+
txSize size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
|
|
76
|
+
txSlot* chunk = (txSlot*)fxNewChunk(the, size * sizeof(txSlot));
|
|
77
|
+
c_memcpy(chunk, address, size * sizeof(txSlot));
|
|
78
|
+
to->value.array.address = chunk;
|
|
79
|
+
while (size) {
|
|
80
|
+
chunk->flag &= ~XS_MARK_FLAG;
|
|
81
|
+
chunk++;
|
|
82
|
+
size--;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (to->kind == XS_DATE_KIND) {
|
|
87
|
+
to->flag &= ~XS_DONT_SET_FLAG;
|
|
88
|
+
}
|
|
89
|
+
else if (to->kind == XS_PRIVATE_KIND) {
|
|
90
|
+
txSlot** address = &to->value.private.first;
|
|
91
|
+
txSlot* slot;
|
|
92
|
+
while ((slot = *address)) {
|
|
93
|
+
*address = slot = fxDuplicateSlot(the, slot);
|
|
94
|
+
address = &slot->next;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
from = from->next;
|
|
98
|
+
}
|
|
99
|
+
return alias;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
txSlot* fxDuplicateInstance(txMachine* the, txSlot* instance)
|
|
103
|
+
{
|
|
104
|
+
txSlot* result;
|
|
105
|
+
txSlot* from;
|
|
106
|
+
txSlot* to;
|
|
107
|
+
result = fxNewInstance(the);
|
|
108
|
+
result->flag = instance->flag & ~XS_MARK_FLAG;
|
|
109
|
+
result->value.instance.garbage = C_NULL;
|
|
110
|
+
result->value.instance.prototype = instance->value.instance.prototype;
|
|
111
|
+
from = instance->next;
|
|
112
|
+
to = result;
|
|
113
|
+
while (from) {
|
|
114
|
+
if (from->kind != XS_WEAK_ENTRY_KIND) {
|
|
115
|
+
to = to->next = fxDuplicateSlot(the, from);
|
|
116
|
+
if (from->kind == XS_ARRAY_KIND) {
|
|
117
|
+
txSlot* address = from->value.array.address;
|
|
118
|
+
to->value.array.address = C_NULL;
|
|
119
|
+
if (address) {
|
|
120
|
+
txSize size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
|
|
121
|
+
txSlot* chunk = (txSlot*)fxNewChunk(the, size * sizeof(txSlot));
|
|
122
|
+
address = from->value.array.address;
|
|
123
|
+
c_memcpy(chunk, address, size * sizeof(txSlot));
|
|
124
|
+
to->value.array.address = chunk;
|
|
125
|
+
while (size) {
|
|
126
|
+
chunk->flag &= ~XS_MARK_FLAG;
|
|
127
|
+
chunk++;
|
|
128
|
+
size--;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
from = from->next;
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
txSlot* fxGetInstance(txMachine* the, txSlot* theSlot)
|
|
139
|
+
{
|
|
140
|
+
if (theSlot->kind == XS_REFERENCE_KIND)
|
|
141
|
+
return theSlot->value.reference;
|
|
142
|
+
return C_NULL;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
txSlot* fxGetPrototype(txMachine* the, txSlot* instance)
|
|
146
|
+
{
|
|
147
|
+
txSlot* prototype = instance->value.instance.prototype;
|
|
148
|
+
if (prototype) {
|
|
149
|
+
if (prototype->ID) {
|
|
150
|
+
txSlot* alias = the->aliasArray[prototype->ID];
|
|
151
|
+
if (alias)
|
|
152
|
+
prototype = alias;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return prototype;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
txSlot* fxNewInstance(txMachine* the)
|
|
159
|
+
{
|
|
160
|
+
txSlot* instance = fxNewSlot(the);
|
|
161
|
+
instance->kind = XS_INSTANCE_KIND;
|
|
162
|
+
instance->value.instance.garbage = C_NULL;
|
|
163
|
+
instance->value.instance.prototype = C_NULL;
|
|
164
|
+
mxPushReference(instance);
|
|
165
|
+
return instance;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
txBoolean fxIsSameInstance(txMachine* the, txSlot* a, txSlot* b)
|
|
169
|
+
{
|
|
170
|
+
if (a == b)
|
|
171
|
+
return 1;
|
|
172
|
+
if (a->ID) {
|
|
173
|
+
txSlot* alias = the->aliasArray[a->ID];
|
|
174
|
+
if (alias) {
|
|
175
|
+
a = alias;
|
|
176
|
+
if (a == b)
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (b->ID) {
|
|
181
|
+
txSlot* alias = the->aliasArray[b->ID];
|
|
182
|
+
if (alias) {
|
|
183
|
+
b = alias;
|
|
184
|
+
if (a == b)
|
|
185
|
+
return 1;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
txSlot* fxToInstance(txMachine* the, txSlot* theSlot)
|
|
192
|
+
{
|
|
193
|
+
txSlot* anInstance = C_NULL;
|
|
194
|
+
switch (theSlot->kind) {
|
|
195
|
+
case XS_UNDEFINED_KIND:
|
|
196
|
+
mxTypeError("cannot coerce undefined to object");
|
|
197
|
+
break;
|
|
198
|
+
case XS_NULL_KIND:
|
|
199
|
+
mxTypeError("cannot coerce null to object");
|
|
200
|
+
break;
|
|
201
|
+
case XS_BOOLEAN_KIND:
|
|
202
|
+
mxPush(mxBooleanPrototype);
|
|
203
|
+
anInstance = fxNewBooleanInstance(the);
|
|
204
|
+
anInstance->next->value.boolean = theSlot->value.boolean;
|
|
205
|
+
if (the->frame->flag & XS_STRICT_FLAG)
|
|
206
|
+
anInstance->flag |= XS_DONT_PATCH_FLAG;
|
|
207
|
+
mxPullSlot(theSlot);
|
|
208
|
+
break;
|
|
209
|
+
case XS_INTEGER_KIND:
|
|
210
|
+
mxPush(mxNumberPrototype);
|
|
211
|
+
anInstance = fxNewNumberInstance(the);
|
|
212
|
+
anInstance->next->value.number = theSlot->value.integer;
|
|
213
|
+
if (the->frame->flag & XS_STRICT_FLAG)
|
|
214
|
+
anInstance->flag |= XS_DONT_PATCH_FLAG;
|
|
215
|
+
mxPullSlot(theSlot);
|
|
216
|
+
break;
|
|
217
|
+
case XS_NUMBER_KIND:
|
|
218
|
+
mxPush(mxNumberPrototype);
|
|
219
|
+
anInstance = fxNewNumberInstance(the);
|
|
220
|
+
anInstance->next->value.number = theSlot->value.number;
|
|
221
|
+
if (the->frame->flag & XS_STRICT_FLAG)
|
|
222
|
+
anInstance->flag |= XS_DONT_PATCH_FLAG;
|
|
223
|
+
mxPullSlot(theSlot);
|
|
224
|
+
break;
|
|
225
|
+
case XS_STRING_KIND:
|
|
226
|
+
case XS_STRING_X_KIND:
|
|
227
|
+
mxPush(mxStringPrototype);
|
|
228
|
+
anInstance = fxNewStringInstance(the);
|
|
229
|
+
anInstance->next->kind = theSlot->kind;
|
|
230
|
+
anInstance->next->value.string = theSlot->value.string;
|
|
231
|
+
if (the->frame->flag & XS_STRICT_FLAG)
|
|
232
|
+
anInstance->flag |= XS_DONT_PATCH_FLAG;
|
|
233
|
+
mxPullSlot(theSlot);
|
|
234
|
+
break;
|
|
235
|
+
case XS_SYMBOL_KIND:
|
|
236
|
+
mxPush(mxSymbolPrototype);
|
|
237
|
+
anInstance = fxNewSymbolInstance(the);
|
|
238
|
+
anInstance->next->value.symbol = theSlot->value.symbol;
|
|
239
|
+
if (the->frame->flag & XS_STRICT_FLAG)
|
|
240
|
+
anInstance->flag |= XS_DONT_PATCH_FLAG;
|
|
241
|
+
mxPullSlot(theSlot);
|
|
242
|
+
break;
|
|
243
|
+
case XS_BIGINT_KIND:
|
|
244
|
+
case XS_BIGINT_X_KIND:
|
|
245
|
+
anInstance = gxTypeBigInt.toInstance(the, theSlot);
|
|
246
|
+
break;
|
|
247
|
+
case XS_REFERENCE_KIND:
|
|
248
|
+
anInstance = theSlot->value.reference;
|
|
249
|
+
break;
|
|
250
|
+
#ifdef mxHostFunctionPrimitive
|
|
251
|
+
case XS_HOST_FUNCTION_KIND: {
|
|
252
|
+
const txHostFunctionBuilder* builder = theSlot->value.hostFunction.builder;
|
|
253
|
+
anInstance = fxNewHostFunction(the, builder->callback, builder->length, builder->id, theSlot->value.hostFunction.profileID);
|
|
254
|
+
mxPullSlot(theSlot);
|
|
255
|
+
} break;
|
|
256
|
+
#endif
|
|
257
|
+
default:
|
|
258
|
+
mxTypeError("cannot coerce to instance");
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
return anInstance;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
void fxToPrimitive(txMachine* the, txSlot* theSlot, txInteger theHint)
|
|
265
|
+
{
|
|
266
|
+
if (mxIsReference(theSlot)) {
|
|
267
|
+
fxBeginHost(the);
|
|
268
|
+
mxPushSlot(theSlot);
|
|
269
|
+
mxPushSlot(theSlot);
|
|
270
|
+
mxGetID(mxID(_Symbol_toPrimitive));
|
|
271
|
+
if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) {
|
|
272
|
+
mxPop();
|
|
273
|
+
mxPush(mxOrdinaryToPrimitiveFunction);
|
|
274
|
+
}
|
|
275
|
+
mxCall();
|
|
276
|
+
if (theHint == XS_NO_HINT)
|
|
277
|
+
mxPushSlot(&mxDefaultString);
|
|
278
|
+
else if (theHint == XS_NUMBER_HINT)
|
|
279
|
+
mxPushSlot(&mxNumberString);
|
|
280
|
+
else
|
|
281
|
+
mxPushSlot(&mxStringString);
|
|
282
|
+
mxRunCount(1);
|
|
283
|
+
theSlot->kind = the->stack->kind;
|
|
284
|
+
theSlot->value = the->stack->value;
|
|
285
|
+
if (mxIsReference(the->stack)) {
|
|
286
|
+
mxTypeError("cannot coerce to primitive");
|
|
287
|
+
}
|
|
288
|
+
mxPullSlot(theSlot);
|
|
289
|
+
fxEndHost(the);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
void fxToSpeciesConstructor(txMachine* the, txSlot* constructor)
|
|
294
|
+
{
|
|
295
|
+
if (mxIsUndefined(the->stack)) {
|
|
296
|
+
mxPop();
|
|
297
|
+
mxPushSlot(constructor);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!mxIsReference(the->stack)) {
|
|
301
|
+
mxTypeError("no constructor");
|
|
302
|
+
}
|
|
303
|
+
mxGetID(mxID(_Symbol_species));
|
|
304
|
+
if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) {
|
|
305
|
+
mxPop();
|
|
306
|
+
mxPushSlot(constructor);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (!mxIsReference(the->stack) || !mxIsConstructor(the->stack->value.reference))
|
|
310
|
+
mxTypeError("no constructor");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
void fxOrdinaryCall(txMachine* the, txSlot* instance, txSlot* _this, txSlot* arguments)
|
|
314
|
+
{
|
|
315
|
+
txIndex c, i;
|
|
316
|
+
/* THIS */
|
|
317
|
+
mxPushSlot(_this);
|
|
318
|
+
/* FUNCTION */
|
|
319
|
+
mxPushReference(instance);
|
|
320
|
+
/* TARGET */
|
|
321
|
+
mxPushUndefined();
|
|
322
|
+
/* RESULT */
|
|
323
|
+
mxPushUndefined();
|
|
324
|
+
/* FRAME */
|
|
325
|
+
mxPushUninitialized();
|
|
326
|
+
/* COUNT */
|
|
327
|
+
mxPushUninitialized();
|
|
328
|
+
/* ARGUMENTS */
|
|
329
|
+
mxPushSlot(arguments);
|
|
330
|
+
mxGetID(mxID(_length));
|
|
331
|
+
c = (txIndex)fxToLength(the, the->stack);
|
|
332
|
+
mxPop();
|
|
333
|
+
for (i = 0; i < c; i++) {
|
|
334
|
+
mxPushSlot(arguments);
|
|
335
|
+
mxGetIndex(i);
|
|
336
|
+
}
|
|
337
|
+
mxRunCount(c);
|
|
338
|
+
mxPullSlot(mxResult);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
void fxOrdinaryConstruct(txMachine* the, txSlot* instance, txSlot* arguments, txSlot* target)
|
|
342
|
+
{
|
|
343
|
+
txIndex c, i;
|
|
344
|
+
/* THIS */
|
|
345
|
+
mxPushUninitialized();
|
|
346
|
+
/* FUNCTION */
|
|
347
|
+
mxPushReference(instance);
|
|
348
|
+
/* TARGET */
|
|
349
|
+
mxPushSlot(target);
|
|
350
|
+
/* RESULT */
|
|
351
|
+
mxPushUndefined();
|
|
352
|
+
/* FRAME */
|
|
353
|
+
mxPushUninitialized();
|
|
354
|
+
/* COUNT */
|
|
355
|
+
mxPushUninitialized();
|
|
356
|
+
/* ARGUMENTS */
|
|
357
|
+
mxPushSlot(arguments);
|
|
358
|
+
mxGetID(mxID(_length));
|
|
359
|
+
c = (txIndex)fxToLength(the, the->stack);
|
|
360
|
+
mxPop();
|
|
361
|
+
for (i = 0; i < c; i++) {
|
|
362
|
+
mxPushSlot(arguments);
|
|
363
|
+
mxGetIndex(i);
|
|
364
|
+
}
|
|
365
|
+
mxRunCount(c);
|
|
366
|
+
mxPullSlot(mxResult);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
txBoolean fxOrdinaryDefineOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot, txFlag mask)
|
|
370
|
+
{
|
|
371
|
+
txSlot* property = mxBehaviorGetProperty(the, instance, id, index, XS_OWN);
|
|
372
|
+
if (property) {
|
|
373
|
+
if (property->flag & XS_DONT_DELETE_FLAG) {
|
|
374
|
+
if ((mask & XS_DONT_DELETE_FLAG) && !(slot->flag & XS_DONT_DELETE_FLAG))
|
|
375
|
+
return 0;
|
|
376
|
+
if ((mask & XS_DONT_ENUM_FLAG) && ((property->flag & XS_DONT_ENUM_FLAG) != (slot->flag & XS_DONT_ENUM_FLAG)))
|
|
377
|
+
return 0;
|
|
378
|
+
if (mask & XS_ACCESSOR_FLAG) {
|
|
379
|
+
if (property->kind != XS_ACCESSOR_KIND)
|
|
380
|
+
return 0;
|
|
381
|
+
if (mask & XS_GETTER_FLAG) {
|
|
382
|
+
if (property->value.accessor.getter != slot->value.accessor.getter)
|
|
383
|
+
return 0;
|
|
384
|
+
}
|
|
385
|
+
if (mask & XS_SETTER_FLAG) {
|
|
386
|
+
if (property->value.accessor.setter != slot->value.accessor.setter)
|
|
387
|
+
return 0;
|
|
388
|
+
}
|
|
389
|
+
return 1;
|
|
390
|
+
}
|
|
391
|
+
else if ((mask & XS_DONT_SET_FLAG) || (slot->kind != XS_UNINITIALIZED_KIND)) {
|
|
392
|
+
if (property->kind == XS_ACCESSOR_KIND)
|
|
393
|
+
return 0;
|
|
394
|
+
if (property->flag & XS_DONT_SET_FLAG) {
|
|
395
|
+
if ((mask & XS_DONT_SET_FLAG) && !(slot->flag & XS_DONT_SET_FLAG))
|
|
396
|
+
return 0;
|
|
397
|
+
if ((slot->kind != XS_UNINITIALIZED_KIND) && !fxIsSameValue(the, property, slot, 0))
|
|
398
|
+
return 0;
|
|
399
|
+
return 1;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (instance->ID) {
|
|
404
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
405
|
+
if (!alias) {
|
|
406
|
+
alias = fxAliasInstance(the, instance);
|
|
407
|
+
property = mxBehaviorGetProperty(the, instance, id, index, XS_OWN);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
property = mxBehaviorSetProperty(the, instance, id, index, XS_OWN);
|
|
413
|
+
if (!property)
|
|
414
|
+
return 0;
|
|
415
|
+
property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
|
|
416
|
+
}
|
|
417
|
+
if (mask & XS_DONT_DELETE_FLAG) {
|
|
418
|
+
if (slot->flag & XS_DONT_DELETE_FLAG)
|
|
419
|
+
property->flag |= XS_DONT_DELETE_FLAG;
|
|
420
|
+
else
|
|
421
|
+
property->flag &= ~XS_DONT_DELETE_FLAG;
|
|
422
|
+
}
|
|
423
|
+
if (mask & XS_DONT_ENUM_FLAG) {
|
|
424
|
+
if (slot->flag & XS_DONT_ENUM_FLAG)
|
|
425
|
+
property->flag |= XS_DONT_ENUM_FLAG;
|
|
426
|
+
else
|
|
427
|
+
property->flag &= ~XS_DONT_ENUM_FLAG;
|
|
428
|
+
}
|
|
429
|
+
if (mask & XS_ACCESSOR_FLAG) {
|
|
430
|
+
txSlot* getter = C_NULL;
|
|
431
|
+
txSlot* setter = C_NULL;
|
|
432
|
+
if (property->kind != XS_ACCESSOR_KIND) {
|
|
433
|
+
property->kind = XS_ACCESSOR_KIND;
|
|
434
|
+
property->value.accessor.getter = C_NULL;
|
|
435
|
+
property->value.accessor.setter = C_NULL;
|
|
436
|
+
}
|
|
437
|
+
if (mask & XS_GETTER_FLAG)
|
|
438
|
+
getter = property->value.accessor.getter = slot->value.accessor.getter;
|
|
439
|
+
if (mask & XS_SETTER_FLAG)
|
|
440
|
+
setter = property->value.accessor.setter = slot->value.accessor.setter;
|
|
441
|
+
if (getter) {
|
|
442
|
+
if (mxIsFunction(getter)) {
|
|
443
|
+
if ((mask & XS_METHOD_FLAG) && ((getter->flag & XS_MARK_FLAG) == 0)) {
|
|
444
|
+
txSlot* home = mxFunctionInstanceHome(getter);
|
|
445
|
+
home->value.home.object = instance;
|
|
446
|
+
}
|
|
447
|
+
if ((mask & XS_NAME_FLAG) && ((getter->flag & XS_MARK_FLAG) == 0))
|
|
448
|
+
fxRenameFunction(the, getter, id, index, mxID(_get), "get ");
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (setter) {
|
|
452
|
+
if (mxIsFunction(setter)) {
|
|
453
|
+
if ((mask & XS_METHOD_FLAG) && ((setter->flag & XS_MARK_FLAG) == 0)) {
|
|
454
|
+
txSlot* home = mxFunctionInstanceHome(setter);
|
|
455
|
+
home->value.home.object = instance;
|
|
456
|
+
}
|
|
457
|
+
if ((mask & XS_NAME_FLAG) && ((setter->flag & XS_MARK_FLAG) == 0))
|
|
458
|
+
fxRenameFunction(the, setter, id, index, mxID(_set), "set ");
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else if ((mask & XS_DONT_SET_FLAG) || (slot->kind != XS_UNINITIALIZED_KIND)) {
|
|
463
|
+
if (mask & XS_DONT_SET_FLAG) {
|
|
464
|
+
if (slot->flag & XS_DONT_SET_FLAG) {
|
|
465
|
+
property->flag |= XS_DONT_SET_FLAG;
|
|
466
|
+
}
|
|
467
|
+
else
|
|
468
|
+
property->flag &= ~XS_DONT_SET_FLAG;
|
|
469
|
+
}
|
|
470
|
+
if (slot->kind != XS_UNINITIALIZED_KIND) {
|
|
471
|
+
property->kind = slot->kind;
|
|
472
|
+
property->value = slot->value;
|
|
473
|
+
if (slot->kind == XS_REFERENCE_KIND) {
|
|
474
|
+
txSlot* function = slot->value.reference;
|
|
475
|
+
if (mxIsFunction(function)) {
|
|
476
|
+
if ((mask & XS_METHOD_FLAG) && ((function->flag & XS_MARK_FLAG) == 0)) {
|
|
477
|
+
txSlot* home = mxFunctionInstanceHome(function);
|
|
478
|
+
home->value.home.object = instance;
|
|
479
|
+
}
|
|
480
|
+
if ((mask & XS_NAME_FLAG) && ((function->flag & XS_MARK_FLAG) == 0))
|
|
481
|
+
fxRenameFunction(the, function, id, index, mxID(_value), C_NULL);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return 1;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
txBoolean fxOrdinaryDeleteProperty(txMachine* the, txSlot* instance, txID id, txIndex index)
|
|
491
|
+
{
|
|
492
|
+
txSlot** address = &(instance->next);
|
|
493
|
+
txSlot* property;
|
|
494
|
+
if (instance->ID) {
|
|
495
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
496
|
+
if (alias)
|
|
497
|
+
instance = alias;
|
|
498
|
+
}
|
|
499
|
+
address = &(instance->next);
|
|
500
|
+
if (id) {
|
|
501
|
+
while ((property = *address) && (property->flag & XS_INTERNAL_FLAG))
|
|
502
|
+
address = &(property->next);
|
|
503
|
+
while ((property = *address)) {
|
|
504
|
+
if (property->ID == id) {
|
|
505
|
+
if (property->flag & XS_DONT_DELETE_FLAG)
|
|
506
|
+
return 0;
|
|
507
|
+
if (instance->ID)
|
|
508
|
+
return fxOrdinaryDeleteProperty(the, fxAliasInstance(the, instance), id, index);
|
|
509
|
+
*address = property->next;
|
|
510
|
+
property->next = C_NULL;
|
|
511
|
+
return 1;
|
|
512
|
+
}
|
|
513
|
+
address = &(property->next);
|
|
514
|
+
}
|
|
515
|
+
return 1;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
while ((property = *address) && (property->flag & XS_INTERNAL_FLAG)) {
|
|
519
|
+
if (property->kind == XS_ARRAY_KIND)
|
|
520
|
+
return fxDeleteIndexProperty(the, property, index);
|
|
521
|
+
address = &(property->next);
|
|
522
|
+
}
|
|
523
|
+
return 1;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
txBoolean fxOrdinaryGetOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot)
|
|
528
|
+
{
|
|
529
|
+
txSlot* property = mxBehaviorGetProperty(the, instance, id, index, XS_OWN);
|
|
530
|
+
if (property) {
|
|
531
|
+
slot->flag = property->flag;
|
|
532
|
+
slot->kind = property->kind;
|
|
533
|
+
slot->value = property->value;
|
|
534
|
+
return 1;
|
|
535
|
+
}
|
|
536
|
+
slot->flag = XS_NO_FLAG;
|
|
537
|
+
slot->kind = XS_UNDEFINED_KIND;
|
|
538
|
+
return 0;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
txSlot* fxOrdinaryGetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag)
|
|
542
|
+
{
|
|
543
|
+
txSlot* result;
|
|
544
|
+
mxCheck(the, instance->kind == XS_INSTANCE_KIND);
|
|
545
|
+
again:
|
|
546
|
+
if (instance->ID) {
|
|
547
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
548
|
+
if (alias)
|
|
549
|
+
instance = alias;
|
|
550
|
+
}
|
|
551
|
+
if (id) {
|
|
552
|
+
if (the->colors && (instance->flag & XS_DONT_MARSHALL_FLAG)) {
|
|
553
|
+
if (id < the->keyOffset) {
|
|
554
|
+
txID color = the->colors[id];
|
|
555
|
+
if (color) {
|
|
556
|
+
result = instance + color;
|
|
557
|
+
if ((result->ID == id) && (result->kind != XS_INSTANCE_KIND))
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
result = instance->next;
|
|
563
|
+
while (result && (result->flag & XS_INTERNAL_FLAG))
|
|
564
|
+
result = result->next;
|
|
565
|
+
while (result) {
|
|
566
|
+
if (result->ID == id)
|
|
567
|
+
return result;
|
|
568
|
+
result = result->next;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
result = instance->next;
|
|
573
|
+
while (result && (result->flag & XS_INTERNAL_FLAG)) {
|
|
574
|
+
if (result->kind == XS_ARRAY_KIND) {
|
|
575
|
+
result = fxGetIndexProperty(the, result, index);
|
|
576
|
+
if (result)
|
|
577
|
+
return result;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
result = result->next;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if (flag) {
|
|
584
|
+
txSlot* prototype = fxGetPrototype(the, instance);
|
|
585
|
+
if (prototype) {
|
|
586
|
+
if (prototype->flag & XS_EXOTIC_FLAG)
|
|
587
|
+
return mxBehaviorGetProperty(the, prototype, id, index, flag);
|
|
588
|
+
instance = prototype;
|
|
589
|
+
goto again;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return C_NULL;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
txBoolean fxOrdinaryGetPropertyValue(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* receiver, txSlot* value)
|
|
596
|
+
{
|
|
597
|
+
txBoolean result = 0;
|
|
598
|
+
txSlot* property;
|
|
599
|
+
txSlot* prototype;
|
|
600
|
+
mxPushUndefined();
|
|
601
|
+
property = the->stack;
|
|
602
|
+
mxPushNull();
|
|
603
|
+
prototype = the->stack;
|
|
604
|
+
if (!mxBehaviorGetOwnProperty(the, instance, id, index, property)) {
|
|
605
|
+
if (mxBehaviorGetPrototype(the, instance, the->stack))
|
|
606
|
+
result = mxBehaviorGetPropertyValue(the, prototype->value.reference, id, index, receiver, value);
|
|
607
|
+
goto bail;
|
|
608
|
+
}
|
|
609
|
+
if (property->kind == XS_ACCESSOR_KIND) {
|
|
610
|
+
txSlot* function = property->value.accessor.getter;
|
|
611
|
+
if (!mxIsFunction(function))
|
|
612
|
+
goto bail;
|
|
613
|
+
/* THIS */
|
|
614
|
+
mxPushSlot(receiver);
|
|
615
|
+
/* FUNCTION */
|
|
616
|
+
mxPushReference(function);
|
|
617
|
+
mxCall();
|
|
618
|
+
mxRunCount(0);
|
|
619
|
+
mxPullSlot(value);
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
value->kind = property->kind;
|
|
623
|
+
value->value = property->value;
|
|
624
|
+
}
|
|
625
|
+
result = 1;
|
|
626
|
+
bail:
|
|
627
|
+
mxPop();
|
|
628
|
+
mxPop();
|
|
629
|
+
return result;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
txBoolean fxOrdinaryGetPrototype(txMachine* the, txSlot* instance, txSlot* result)
|
|
633
|
+
{
|
|
634
|
+
txSlot* prototype;
|
|
635
|
+
if (instance->ID) {
|
|
636
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
637
|
+
if (alias)
|
|
638
|
+
instance = alias;
|
|
639
|
+
}
|
|
640
|
+
prototype = fxGetPrototype(the, instance);
|
|
641
|
+
if (prototype) {
|
|
642
|
+
result->kind = XS_REFERENCE_KIND;
|
|
643
|
+
result->value.reference = prototype;
|
|
644
|
+
return 1;
|
|
645
|
+
}
|
|
646
|
+
result->kind = XS_NULL_KIND;
|
|
647
|
+
return 0;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
txBoolean fxOrdinaryHasProperty(txMachine* the, txSlot* instance, txID id, txIndex index)
|
|
651
|
+
{
|
|
652
|
+
txBoolean result;
|
|
653
|
+
txSlot* property = mxBehaviorGetProperty(the, instance, id, index, XS_OWN);
|
|
654
|
+
if (property)
|
|
655
|
+
return 1;
|
|
656
|
+
mxPushUndefined();
|
|
657
|
+
if (mxBehaviorGetPrototype(the, instance, the->stack))
|
|
658
|
+
result = mxBehaviorHasProperty(the, the->stack->value.reference, id, index);
|
|
659
|
+
else
|
|
660
|
+
result = 0;
|
|
661
|
+
mxPop();
|
|
662
|
+
return result;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
txBoolean fxOrdinaryIsExtensible(txMachine* the, txSlot* instance)
|
|
666
|
+
{
|
|
667
|
+
if (instance->ID) {
|
|
668
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
669
|
+
if (alias)
|
|
670
|
+
instance = alias;
|
|
671
|
+
}
|
|
672
|
+
return (instance->flag & XS_DONT_PATCH_FLAG) ? 0 : 1;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
void fxOrdinaryOwnKeys(txMachine* the, txSlot* instance, txFlag flag, txSlot* keys)
|
|
676
|
+
{
|
|
677
|
+
txSlot* property;
|
|
678
|
+
if (instance->ID) {
|
|
679
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
680
|
+
if (alias)
|
|
681
|
+
instance = alias;
|
|
682
|
+
}
|
|
683
|
+
property = instance->next;
|
|
684
|
+
while (property && (property->flag & XS_INTERNAL_FLAG)) {
|
|
685
|
+
if (property->kind == XS_ARRAY_KIND)
|
|
686
|
+
keys = fxQueueIndexKeys(the, property, flag, keys);
|
|
687
|
+
property = property->next;
|
|
688
|
+
}
|
|
689
|
+
fxQueueIDKeys(the, property, flag, keys);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
txBoolean fxOrdinaryPreventExtensions(txMachine* the, txSlot* instance)
|
|
693
|
+
{
|
|
694
|
+
if (instance->ID) {
|
|
695
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
696
|
+
if (alias)
|
|
697
|
+
instance = alias;
|
|
698
|
+
}
|
|
699
|
+
if (instance->flag & XS_DONT_PATCH_FLAG)
|
|
700
|
+
return 1;
|
|
701
|
+
if (instance->ID)
|
|
702
|
+
instance = fxAliasInstance(the, instance);
|
|
703
|
+
instance->flag |= XS_DONT_PATCH_FLAG;
|
|
704
|
+
return 1;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
txSlot* fxOrdinarySetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag)
|
|
708
|
+
{
|
|
709
|
+
txSlot** address;
|
|
710
|
+
txSlot* property;
|
|
711
|
+
txSlot* result;
|
|
712
|
+
if (instance->ID) {
|
|
713
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
714
|
+
if (alias)
|
|
715
|
+
instance = alias;
|
|
716
|
+
else {
|
|
717
|
+
property = mxBehaviorGetProperty(the, instance, id, index, flag);
|
|
718
|
+
if (property) {
|
|
719
|
+
if (property->kind == XS_ACCESSOR_KIND)
|
|
720
|
+
return property;
|
|
721
|
+
if (property->flag & XS_DONT_SET_FLAG)
|
|
722
|
+
return property;
|
|
723
|
+
}
|
|
724
|
+
if (instance->flag & XS_DONT_PATCH_FLAG)
|
|
725
|
+
return C_NULL;
|
|
726
|
+
instance = fxAliasInstance(the, instance);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
if (id) {
|
|
730
|
+
if (the->colors && (instance->flag & XS_DONT_MARSHALL_FLAG)) {
|
|
731
|
+
if (id < the->keyOffset) {
|
|
732
|
+
txID color = the->colors[id];
|
|
733
|
+
if (color) {
|
|
734
|
+
property = instance + color;
|
|
735
|
+
if (property->ID == id)
|
|
736
|
+
return property;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
address = &(instance->next);
|
|
741
|
+
while ((property = *address) && (property->flag & XS_INTERNAL_FLAG))
|
|
742
|
+
address = &(property->next);
|
|
743
|
+
while ((property = *address)) {
|
|
744
|
+
if (property->ID == id)
|
|
745
|
+
return property;
|
|
746
|
+
address = &(property->next);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
address = &(instance->next);
|
|
751
|
+
while ((property = *address) && (property->flag & XS_INTERNAL_FLAG)) {
|
|
752
|
+
if (property->kind == XS_ARRAY_KIND) {
|
|
753
|
+
result = fxGetIndexProperty(the, property, index);
|
|
754
|
+
if (result)
|
|
755
|
+
return result;
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
address = &(property->next);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (flag) {
|
|
762
|
+
txSlot* prototype = fxGetPrototype(the, instance);
|
|
763
|
+
if (prototype) {
|
|
764
|
+
result = mxBehaviorGetProperty(the, prototype, id, index, flag);
|
|
765
|
+
if (result) {
|
|
766
|
+
if (result->kind == XS_ACCESSOR_KIND)
|
|
767
|
+
return result;
|
|
768
|
+
if (result->flag & XS_DONT_SET_FLAG)
|
|
769
|
+
return result;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (instance->flag & XS_DONT_PATCH_FLAG)
|
|
774
|
+
return C_NULL;
|
|
775
|
+
if (id) {
|
|
776
|
+
*address = result = fxNewSlot(the);
|
|
777
|
+
result->ID = id;
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
if (property && (property->kind == XS_ARRAY_KIND)) {
|
|
781
|
+
result = fxSetIndexProperty(the, instance, property, index);
|
|
782
|
+
}
|
|
783
|
+
else {
|
|
784
|
+
property = fxNewSlot(the);
|
|
785
|
+
property->next = *address;
|
|
786
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
787
|
+
property->ID = 0;
|
|
788
|
+
property->kind = XS_ARRAY_KIND;
|
|
789
|
+
property->value.array.address = C_NULL;
|
|
790
|
+
property->value.array.length = 0;
|
|
791
|
+
*address = property;
|
|
792
|
+
result = fxSetIndexProperty(the, instance, property, index);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
return result;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
txBoolean fxOrdinarySetPropertyValue(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* value, txSlot* receiver)
|
|
799
|
+
{
|
|
800
|
+
txBoolean result = 0;
|
|
801
|
+
txSlot* property;
|
|
802
|
+
txSlot* prototype;
|
|
803
|
+
mxPushUndefined();
|
|
804
|
+
property = the->stack;
|
|
805
|
+
mxPushNull();
|
|
806
|
+
prototype = the->stack;
|
|
807
|
+
if (!mxBehaviorGetOwnProperty(the, instance, id, index, property)) {
|
|
808
|
+
if (mxBehaviorGetPrototype(the, instance, prototype)) {
|
|
809
|
+
result = mxBehaviorSetPropertyValue(the, prototype->value.reference, id, index, value, receiver);
|
|
810
|
+
goto bail;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (property->kind == XS_ACCESSOR_KIND) {
|
|
814
|
+
txSlot* function = property->value.accessor.setter;
|
|
815
|
+
if (!mxIsFunction(function))
|
|
816
|
+
goto bail;
|
|
817
|
+
/* THIS */
|
|
818
|
+
mxPushSlot(receiver);
|
|
819
|
+
/* FUNCTION */
|
|
820
|
+
mxPushReference(function);
|
|
821
|
+
mxCall();
|
|
822
|
+
mxPushSlot(value);
|
|
823
|
+
mxRunCount(1);
|
|
824
|
+
mxPop();
|
|
825
|
+
result = 1;
|
|
826
|
+
goto bail;
|
|
827
|
+
}
|
|
828
|
+
if (property->flag & XS_DONT_SET_FLAG)
|
|
829
|
+
goto bail;
|
|
830
|
+
value->flag = property->flag;
|
|
831
|
+
if (receiver->kind != XS_REFERENCE_KIND)
|
|
832
|
+
goto bail;
|
|
833
|
+
if (mxBehaviorGetOwnProperty(the, receiver->value.reference, id, index, property)) {
|
|
834
|
+
if (property->kind == XS_ACCESSOR_KIND)
|
|
835
|
+
goto bail;
|
|
836
|
+
if (property->flag & XS_DONT_SET_FLAG)
|
|
837
|
+
goto bail;
|
|
838
|
+
}
|
|
839
|
+
result = mxBehaviorDefineOwnProperty(the, receiver->value.reference, id, index, value, XS_GET_ONLY);
|
|
840
|
+
bail:
|
|
841
|
+
mxPop();
|
|
842
|
+
mxPop();
|
|
843
|
+
return result;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
txBoolean fxOrdinarySetPrototype(txMachine* the, txSlot* instance, txSlot* slot)
|
|
847
|
+
{
|
|
848
|
+
txSlot* prototype = (slot->kind == XS_NULL_KIND) ? C_NULL : slot->value.reference;
|
|
849
|
+
if (instance->ID) {
|
|
850
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
851
|
+
if (alias)
|
|
852
|
+
instance = alias;
|
|
853
|
+
}
|
|
854
|
+
if (instance->value.instance.prototype != prototype) {
|
|
855
|
+
if (instance->flag & XS_DONT_PATCH_FLAG)
|
|
856
|
+
return 0;
|
|
857
|
+
slot = prototype;
|
|
858
|
+
while (slot) {
|
|
859
|
+
if (instance == slot)
|
|
860
|
+
return 0;
|
|
861
|
+
slot = fxGetPrototype(the, slot);
|
|
862
|
+
}
|
|
863
|
+
if (instance->ID)
|
|
864
|
+
instance = fxAliasInstance(the, instance);
|
|
865
|
+
instance->value.instance.prototype = prototype;
|
|
866
|
+
}
|
|
867
|
+
return 1;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
void fxOrdinaryToPrimitive(txMachine* the)
|
|
871
|
+
{
|
|
872
|
+
if (mxIsReference(mxThis)) {
|
|
873
|
+
txInteger hint = XS_NO_HINT;
|
|
874
|
+
txInteger ids[2], i;
|
|
875
|
+
if (mxArgc > 0) {
|
|
876
|
+
txSlot* slot = mxArgv(0);
|
|
877
|
+
if ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) {
|
|
878
|
+
if (!c_strcmp(slot->value.string, "default"))
|
|
879
|
+
hint = XS_NUMBER_HINT;
|
|
880
|
+
else if (!c_strcmp(slot->value.string, "number"))
|
|
881
|
+
hint = XS_NUMBER_HINT;
|
|
882
|
+
else if (!c_strcmp(slot->value.string, "string"))
|
|
883
|
+
hint = XS_STRING_HINT;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (hint == XS_STRING_HINT) {
|
|
887
|
+
ids[0] = mxID(_toString);
|
|
888
|
+
ids[1] = mxID(_valueOf);
|
|
889
|
+
}
|
|
890
|
+
else if (hint == XS_NUMBER_HINT) {
|
|
891
|
+
ids[0] = mxID(_valueOf);
|
|
892
|
+
ids[1] = mxID(_toString);
|
|
893
|
+
}
|
|
894
|
+
else
|
|
895
|
+
mxTypeError("invalid hint");
|
|
896
|
+
for (i = 0; i < 2; i++) {
|
|
897
|
+
mxPushSlot(mxThis);
|
|
898
|
+
mxPushSlot(mxThis);
|
|
899
|
+
mxGetID(ids[i]);
|
|
900
|
+
if (fxIsCallable(the, the->stack)) {
|
|
901
|
+
mxCall();
|
|
902
|
+
mxRunCount(0);
|
|
903
|
+
if (mxIsReference(the->stack))
|
|
904
|
+
mxPop();
|
|
905
|
+
else {
|
|
906
|
+
mxPullSlot(mxResult);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
mxPop();
|
|
912
|
+
mxPop();
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
if (hint == XS_STRING_HINT)
|
|
916
|
+
mxTypeError("cannot coerce object to string");
|
|
917
|
+
else
|
|
918
|
+
mxTypeError("cannot coerce object to number");
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
mxResult->kind = mxThis->kind;
|
|
922
|
+
mxResult->value = mxThis->value;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
void fx_species_get(txMachine* the)
|
|
927
|
+
{
|
|
928
|
+
*mxResult = *mxThis;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
txFlag fxDescriptorToSlot(txMachine* the, txSlot* descriptor)
|
|
932
|
+
{
|
|
933
|
+
txSlot* stack = the->stack;
|
|
934
|
+
txSlot* configurable = C_NULL;
|
|
935
|
+
txSlot* enumerable = C_NULL;
|
|
936
|
+
txSlot* get = C_NULL;
|
|
937
|
+
txSlot* set = C_NULL;
|
|
938
|
+
txSlot* value = C_NULL;
|
|
939
|
+
txSlot* writable = C_NULL;
|
|
940
|
+
txSlot* getFunction = C_NULL;
|
|
941
|
+
txSlot* setFunction = C_NULL;
|
|
942
|
+
txFlag mask = 0;
|
|
943
|
+
if (!mxIsReference(descriptor))
|
|
944
|
+
mxTypeError("descriptor is no object");
|
|
945
|
+
mxPushSlot(descriptor);
|
|
946
|
+
if (mxHasID(mxID(_enumerable))) {
|
|
947
|
+
mxPushSlot(descriptor);
|
|
948
|
+
mxGetID(mxID(_enumerable));
|
|
949
|
+
enumerable = the->stack;
|
|
950
|
+
}
|
|
951
|
+
mxPushSlot(descriptor);
|
|
952
|
+
if (mxHasID(mxID(_configurable))) {
|
|
953
|
+
mxPushSlot(descriptor);
|
|
954
|
+
mxGetID(mxID(_configurable));
|
|
955
|
+
configurable = the->stack;
|
|
956
|
+
}
|
|
957
|
+
mxPushSlot(descriptor);
|
|
958
|
+
if (mxHasID(mxID(_value))) {
|
|
959
|
+
mxPushSlot(descriptor);
|
|
960
|
+
mxGetID(mxID(_value));
|
|
961
|
+
value = the->stack;
|
|
962
|
+
}
|
|
963
|
+
mxPushSlot(descriptor);
|
|
964
|
+
if (mxHasID(mxID(_writable))) {
|
|
965
|
+
mxPushSlot(descriptor);
|
|
966
|
+
mxGetID(mxID(_writable));
|
|
967
|
+
writable = the->stack;
|
|
968
|
+
}
|
|
969
|
+
mxPushSlot(descriptor);
|
|
970
|
+
if (mxHasID(mxID(_get))) {
|
|
971
|
+
mxPushSlot(descriptor);
|
|
972
|
+
mxGetID(mxID(_get));
|
|
973
|
+
get = the->stack;
|
|
974
|
+
}
|
|
975
|
+
mxPushSlot(descriptor);
|
|
976
|
+
if (mxHasID(mxID(_set))) {
|
|
977
|
+
mxPushSlot(descriptor);
|
|
978
|
+
mxGetID(mxID(_set));
|
|
979
|
+
set = the->stack;
|
|
980
|
+
}
|
|
981
|
+
if (get) {
|
|
982
|
+
if (value)
|
|
983
|
+
mxTypeError("get and value");
|
|
984
|
+
if (writable)
|
|
985
|
+
mxTypeError("get and writable");
|
|
986
|
+
if (get->kind != XS_UNDEFINED_KIND) {
|
|
987
|
+
getFunction = fxToInstance(the, get);
|
|
988
|
+
if (!getFunction || !mxIsFunction(getFunction))
|
|
989
|
+
mxTypeError("get is no function");
|
|
990
|
+
}
|
|
991
|
+
mask |= XS_GETTER_FLAG;
|
|
992
|
+
}
|
|
993
|
+
if (set) {
|
|
994
|
+
if (value)
|
|
995
|
+
mxTypeError("set and value");
|
|
996
|
+
if (writable)
|
|
997
|
+
mxTypeError("set and writable");
|
|
998
|
+
if (set->kind != XS_UNDEFINED_KIND) {
|
|
999
|
+
setFunction = fxToInstance(the, set);
|
|
1000
|
+
if (!setFunction || !mxIsFunction(setFunction))
|
|
1001
|
+
mxTypeError("set is no function");
|
|
1002
|
+
}
|
|
1003
|
+
mask |= XS_SETTER_FLAG;
|
|
1004
|
+
}
|
|
1005
|
+
descriptor->flag = 0;
|
|
1006
|
+
if (configurable) {
|
|
1007
|
+
mask |= XS_DONT_DELETE_FLAG;
|
|
1008
|
+
if (!fxToBoolean(the, configurable))
|
|
1009
|
+
descriptor->flag |= XS_DONT_DELETE_FLAG;
|
|
1010
|
+
}
|
|
1011
|
+
if (enumerable) {
|
|
1012
|
+
mask |= XS_DONT_ENUM_FLAG;
|
|
1013
|
+
if (!fxToBoolean(the, enumerable))
|
|
1014
|
+
descriptor->flag |= XS_DONT_ENUM_FLAG;
|
|
1015
|
+
}
|
|
1016
|
+
if (get || set) {
|
|
1017
|
+
descriptor->kind = XS_ACCESSOR_KIND;
|
|
1018
|
+
descriptor->value.accessor.getter = getFunction;
|
|
1019
|
+
descriptor->value.accessor.setter = setFunction;
|
|
1020
|
+
}
|
|
1021
|
+
else {
|
|
1022
|
+
if (writable) {
|
|
1023
|
+
mask |= XS_DONT_SET_FLAG;
|
|
1024
|
+
if (!fxToBoolean(the, writable))
|
|
1025
|
+
descriptor->flag |= XS_DONT_SET_FLAG;
|
|
1026
|
+
}
|
|
1027
|
+
if (value) {
|
|
1028
|
+
descriptor->kind = value->kind;
|
|
1029
|
+
descriptor->value = value->value;
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
descriptor->kind = XS_UNINITIALIZED_KIND;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
the->stack = stack;
|
|
1036
|
+
return mask;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
void fxDescribeProperty(txMachine* the, txSlot* property, txFlag mask)
|
|
1040
|
+
{
|
|
1041
|
+
txSlot* slot;
|
|
1042
|
+
mxPush(mxObjectPrototype);
|
|
1043
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
1044
|
+
if (property->kind == XS_ACCESSOR_KIND) {
|
|
1045
|
+
slot = fxNextUndefinedProperty(the, slot, mxID(_get), XS_NO_FLAG);
|
|
1046
|
+
if (property->value.accessor.getter) {
|
|
1047
|
+
slot->kind = XS_REFERENCE_KIND;
|
|
1048
|
+
slot->value.reference = property->value.accessor.getter;
|
|
1049
|
+
}
|
|
1050
|
+
slot = fxNextUndefinedProperty(the, slot, mxID(_set), XS_NO_FLAG);
|
|
1051
|
+
if (property->value.accessor.setter) {
|
|
1052
|
+
slot->kind = XS_REFERENCE_KIND;
|
|
1053
|
+
slot->value.reference = property->value.accessor.setter;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
else {
|
|
1057
|
+
if (property->kind != XS_UNINITIALIZED_KIND)
|
|
1058
|
+
slot = fxNextSlotProperty(the, slot, property, mxID(_value), XS_NO_FLAG);
|
|
1059
|
+
if (mask & XS_DONT_SET_FLAG)
|
|
1060
|
+
slot = fxNextBooleanProperty(the, slot, (property->flag & XS_DONT_SET_FLAG) ? 0 : 1, mxID(_writable), XS_NO_FLAG);
|
|
1061
|
+
}
|
|
1062
|
+
if (mask & XS_DONT_ENUM_FLAG)
|
|
1063
|
+
slot= fxNextBooleanProperty(the, slot, (property->flag & XS_DONT_ENUM_FLAG) ? 0 : 1, mxID(_enumerable), XS_NO_FLAG);
|
|
1064
|
+
if (mask & XS_DONT_DELETE_FLAG)
|
|
1065
|
+
slot= fxNextBooleanProperty(the, slot, (property->flag & XS_DONT_DELETE_FLAG) ? 0 : 1, mxID(_configurable), XS_NO_FLAG);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
txBoolean fxIsPropertyCompatible(txMachine* the, txSlot* property, txSlot* slot, txFlag mask)
|
|
1069
|
+
{
|
|
1070
|
+
if (property->flag & XS_DONT_DELETE_FLAG) {
|
|
1071
|
+
if ((mask & XS_DONT_DELETE_FLAG) && !(slot->flag & XS_DONT_DELETE_FLAG))
|
|
1072
|
+
return 0;
|
|
1073
|
+
if ((mask & XS_DONT_ENUM_FLAG) && ((property->flag & XS_DONT_ENUM_FLAG) != (slot->flag & XS_DONT_ENUM_FLAG)))
|
|
1074
|
+
return 0;
|
|
1075
|
+
if (mask & XS_ACCESSOR_FLAG) {
|
|
1076
|
+
if (property->kind != XS_ACCESSOR_KIND)
|
|
1077
|
+
return 0;
|
|
1078
|
+
if (mask & XS_GETTER_FLAG) {
|
|
1079
|
+
if (property->value.accessor.getter != slot->value.accessor.getter)
|
|
1080
|
+
return 0;
|
|
1081
|
+
}
|
|
1082
|
+
if (mask & XS_SETTER_FLAG) {
|
|
1083
|
+
if (property->value.accessor.setter != slot->value.accessor.setter)
|
|
1084
|
+
return 0;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
else if ((mask & XS_DONT_SET_FLAG) || (slot->kind != XS_UNINITIALIZED_KIND)) {
|
|
1088
|
+
if (property->kind == XS_ACCESSOR_KIND)
|
|
1089
|
+
return 0;
|
|
1090
|
+
if (property->flag & XS_DONT_SET_FLAG) {
|
|
1091
|
+
if ((mask & XS_DONT_SET_FLAG) && !(slot->flag & XS_DONT_SET_FLAG))
|
|
1092
|
+
return 0;
|
|
1093
|
+
if ((slot->kind != XS_UNINITIALIZED_KIND) && !fxIsSameValue(the, property, slot, 0))
|
|
1094
|
+
return 0;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
return 1;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
static txBoolean fxEnvironmentDefineOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot, txFlag mask);
|
|
1102
|
+
static txBoolean fxEnvironmentDeleteProperty(txMachine* the, txSlot* instance, txID id, txIndex index);
|
|
1103
|
+
static txSlot* fxEnvironmentGetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag);
|
|
1104
|
+
static txBoolean fxEnvironmentHasProperty(txMachine* the, txSlot* instance, txID id, txIndex index);
|
|
1105
|
+
static txSlot* fxEnvironmentSetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag);
|
|
1106
|
+
|
|
1107
|
+
const txBehavior ICACHE_FLASH_ATTR gxEnvironmentBehavior = {
|
|
1108
|
+
fxEnvironmentGetProperty,
|
|
1109
|
+
fxEnvironmentSetProperty,
|
|
1110
|
+
fxOrdinaryCall,
|
|
1111
|
+
fxOrdinaryConstruct,
|
|
1112
|
+
fxEnvironmentDefineOwnProperty,
|
|
1113
|
+
fxEnvironmentDeleteProperty,
|
|
1114
|
+
fxOrdinaryGetOwnProperty,
|
|
1115
|
+
fxOrdinaryGetPropertyValue,
|
|
1116
|
+
fxOrdinaryGetPrototype,
|
|
1117
|
+
fxEnvironmentHasProperty,
|
|
1118
|
+
fxOrdinaryIsExtensible,
|
|
1119
|
+
fxOrdinaryOwnKeys,
|
|
1120
|
+
fxOrdinaryPreventExtensions,
|
|
1121
|
+
fxOrdinarySetPropertyValue,
|
|
1122
|
+
fxOrdinarySetPrototype,
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
txSlot* fxNewEnvironmentInstance(txMachine* the, txSlot* environment)
|
|
1126
|
+
{
|
|
1127
|
+
txSlot* with = the->stack;
|
|
1128
|
+
txSlot* instance = fxNewSlot(the);
|
|
1129
|
+
txSlot* slot;
|
|
1130
|
+
instance->flag = XS_EXOTIC_FLAG;
|
|
1131
|
+
instance->kind = XS_INSTANCE_KIND;
|
|
1132
|
+
instance->value.instance.garbage = C_NULL;
|
|
1133
|
+
instance->value.instance.prototype = (environment && (environment->kind == XS_REFERENCE_KIND)) ? environment->value.reference : C_NULL;
|
|
1134
|
+
mxPushReference(instance);
|
|
1135
|
+
slot = instance->next = fxNewSlot(the);
|
|
1136
|
+
slot->flag = XS_INTERNAL_FLAG;
|
|
1137
|
+
slot->ID = XS_ENVIRONMENT_BEHAVIOR;
|
|
1138
|
+
slot->kind = with->kind;
|
|
1139
|
+
slot->value = with->value;
|
|
1140
|
+
mxPop();
|
|
1141
|
+
the->stack->value.reference = instance;
|
|
1142
|
+
the->stack->kind = XS_REFERENCE_KIND;
|
|
1143
|
+
return instance;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
txBoolean fxEnvironmentDefineOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot, txFlag mask)
|
|
1147
|
+
{
|
|
1148
|
+
txSlot* property = fxOrdinarySetProperty(the, instance, id, index, XS_OWN);
|
|
1149
|
+
if (!property)
|
|
1150
|
+
return 0;
|
|
1151
|
+
property->flag = slot->flag & mask;
|
|
1152
|
+
property->kind = slot->kind;
|
|
1153
|
+
property->value = slot->value;
|
|
1154
|
+
return 1;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
txBoolean fxEnvironmentDeleteProperty(txMachine* the, txSlot* instance, txID id, txIndex index)
|
|
1158
|
+
{
|
|
1159
|
+
if (id) {
|
|
1160
|
+
txSlot** address = &(instance->next->next);
|
|
1161
|
+
txSlot* property;
|
|
1162
|
+
while ((property = *address)) {
|
|
1163
|
+
if (property->ID == id) {
|
|
1164
|
+
if (property->flag & XS_DONT_DELETE_FLAG)
|
|
1165
|
+
return 0;
|
|
1166
|
+
*address = property->next;
|
|
1167
|
+
property->next = C_NULL;
|
|
1168
|
+
return 1;
|
|
1169
|
+
}
|
|
1170
|
+
address = &(property->next);
|
|
1171
|
+
}
|
|
1172
|
+
return 1;
|
|
1173
|
+
}
|
|
1174
|
+
return 0;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
txSlot* fxEnvironmentGetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag)
|
|
1178
|
+
{
|
|
1179
|
+
txID alias;
|
|
1180
|
+
if (id) {
|
|
1181
|
+
txSlot* result = instance->next->next;
|
|
1182
|
+
while (result) {
|
|
1183
|
+
if (result->ID == id) {
|
|
1184
|
+
if (result->kind == XS_CLOSURE_KIND) {
|
|
1185
|
+
result = result->value.closure;
|
|
1186
|
+
if (result) {
|
|
1187
|
+
alias = result->ID;
|
|
1188
|
+
if (alias) {
|
|
1189
|
+
txSlot* slot = the->aliasArray[alias];
|
|
1190
|
+
if (slot)
|
|
1191
|
+
result = slot;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return result;
|
|
1196
|
+
}
|
|
1197
|
+
result = result->next;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return C_NULL;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
txBoolean fxEnvironmentHasProperty(txMachine* the, txSlot* instance, txID id, txIndex index)
|
|
1204
|
+
{
|
|
1205
|
+
if (id) {
|
|
1206
|
+
txSlot* result = instance->next->next;
|
|
1207
|
+
while (result) {
|
|
1208
|
+
if (result->ID == id) {
|
|
1209
|
+
return 1;
|
|
1210
|
+
}
|
|
1211
|
+
result = result->next;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
return 0;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
txSlot* fxEnvironmentSetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag)
|
|
1218
|
+
{
|
|
1219
|
+
txID alias;
|
|
1220
|
+
if (id) {
|
|
1221
|
+
txSlot* result = instance->next->next;
|
|
1222
|
+
while (result) {
|
|
1223
|
+
if (result->ID == id) {
|
|
1224
|
+
if (result->kind == XS_CLOSURE_KIND) {
|
|
1225
|
+
result = result->value.closure;
|
|
1226
|
+
if (result->flag & XS_DONT_SET_FLAG)
|
|
1227
|
+
mxDebugID(XS_TYPE_ERROR, "set %s: const", id);
|
|
1228
|
+
alias = result->ID;
|
|
1229
|
+
if (alias) {
|
|
1230
|
+
result = the->aliasArray[alias];
|
|
1231
|
+
if (!result) {
|
|
1232
|
+
result = fxNewSlot(the);
|
|
1233
|
+
the->aliasArray[alias] = result;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
return result;
|
|
1238
|
+
}
|
|
1239
|
+
result = result->next;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return C_NULL;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
void fxRunEvalEnvironment(txMachine* the)
|
|
1246
|
+
{
|
|
1247
|
+
txSlot* function = mxFunction;
|
|
1248
|
+
txSlot* module = mxFunctionInstanceHome(function->value.reference)->value.home.module;
|
|
1249
|
+
txSlot* realm = mxModuleInstanceInternal(module)->value.module.realm;
|
|
1250
|
+
txSlot* global = mxRealmGlobal(realm)->value.reference;
|
|
1251
|
+
txSlot* top = mxFrameToEnvironment(the->frame);
|
|
1252
|
+
txSlot* bottom = the->scope;
|
|
1253
|
+
txSlot* slot;
|
|
1254
|
+
txSlot* property;
|
|
1255
|
+
txSlot* currentEnvironment = top->value.reference;
|
|
1256
|
+
txSlot* varEnvironment = currentEnvironment;
|
|
1257
|
+
top--;
|
|
1258
|
+
while (varEnvironment) {
|
|
1259
|
+
property = varEnvironment->next;
|
|
1260
|
+
if (property->kind == XS_NULL_KIND)
|
|
1261
|
+
break;
|
|
1262
|
+
varEnvironment = varEnvironment->value.instance.prototype;
|
|
1263
|
+
}
|
|
1264
|
+
slot = top;
|
|
1265
|
+
while (slot >= bottom) {
|
|
1266
|
+
txSlot* environment = currentEnvironment;
|
|
1267
|
+
while (environment != varEnvironment) {
|
|
1268
|
+
if (mxBehaviorHasProperty(the, environment, slot->ID, 0))
|
|
1269
|
+
mxDebugID(XS_SYNTAX_ERROR, "%s: duplicate variable", slot->ID);
|
|
1270
|
+
environment = environment->value.instance.prototype;
|
|
1271
|
+
}
|
|
1272
|
+
slot--;
|
|
1273
|
+
}
|
|
1274
|
+
if (varEnvironment) {
|
|
1275
|
+
slot = top;
|
|
1276
|
+
while (slot >= bottom) {
|
|
1277
|
+
property = mxBehaviorGetProperty(the, varEnvironment, slot->ID, 0, XS_OWN);
|
|
1278
|
+
if (!property) {
|
|
1279
|
+
slot->value.closure = fxNewSlot(the);
|
|
1280
|
+
slot->kind = XS_CLOSURE_KIND;
|
|
1281
|
+
mxBehaviorDefineOwnProperty(the, varEnvironment, slot->ID, 0, slot, XS_NO_FLAG); // configurable variable!
|
|
1282
|
+
}
|
|
1283
|
+
slot--;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
else {
|
|
1287
|
+
mxPushUndefined();
|
|
1288
|
+
slot = bottom;
|
|
1289
|
+
while (slot <= top) {
|
|
1290
|
+
if (slot->kind == XS_NULL_KIND) {
|
|
1291
|
+
property = the->stack;
|
|
1292
|
+
if (!mxBehaviorGetOwnProperty(the, global, slot->ID, 0, property)) {
|
|
1293
|
+
if (!mxBehaviorIsExtensible(the, global))
|
|
1294
|
+
mxDebugID(XS_TYPE_ERROR, "%s: global object not extensible", slot->ID);
|
|
1295
|
+
}
|
|
1296
|
+
else if (property->flag & XS_DONT_DELETE_FLAG) {
|
|
1297
|
+
if (property->flag & (XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG))
|
|
1298
|
+
mxDebugID(XS_TYPE_ERROR, "%s: global property not configurable and not enumerable or writable", slot->ID);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
slot++;
|
|
1302
|
+
}
|
|
1303
|
+
slot = top;
|
|
1304
|
+
while (slot >= bottom) {
|
|
1305
|
+
if (slot->kind == XS_UNDEFINED_KIND) {
|
|
1306
|
+
property = the->stack;
|
|
1307
|
+
if (!mxBehaviorGetOwnProperty(the, global, slot->ID, 0, property)) {
|
|
1308
|
+
if (!mxBehaviorIsExtensible(the, global))
|
|
1309
|
+
mxDebugID(XS_TYPE_ERROR, "%s: global object not extensible", slot->ID);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
slot--;
|
|
1313
|
+
}
|
|
1314
|
+
mxPop();
|
|
1315
|
+
slot = bottom;
|
|
1316
|
+
while (slot <= top) {
|
|
1317
|
+
if (slot->kind == XS_NULL_KIND) {
|
|
1318
|
+
property = mxBehaviorSetProperty(the, global, slot->ID, 0, XS_OWN);
|
|
1319
|
+
if (!(property->flag & XS_DONT_DELETE_FLAG))
|
|
1320
|
+
property->flag = XS_NO_FLAG;
|
|
1321
|
+
}
|
|
1322
|
+
slot++;
|
|
1323
|
+
}
|
|
1324
|
+
slot = top;
|
|
1325
|
+
while (slot >= bottom) {
|
|
1326
|
+
if (slot->kind == XS_UNDEFINED_KIND) {
|
|
1327
|
+
property = mxBehaviorSetProperty(the, global, slot->ID, 0, XS_OWN);
|
|
1328
|
+
}
|
|
1329
|
+
slot--;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
the->stack = the->scope = top + 1;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
void fxRunProgramEnvironment(txMachine* the)
|
|
1336
|
+
{
|
|
1337
|
+
txSlot* function = mxFunction;
|
|
1338
|
+
txSlot* module = mxFunctionInstanceHome(function->value.reference)->value.home.module;
|
|
1339
|
+
txSlot* realm = mxModuleInstanceInternal(module)->value.module.realm;
|
|
1340
|
+
txSlot* environment = mxRealmClosures(realm)->value.reference;
|
|
1341
|
+
txSlot* global = mxRealmGlobal(realm)->value.reference;
|
|
1342
|
+
txSlot* top = mxFrameToEnvironment(the->frame);
|
|
1343
|
+
txSlot* middle = C_NULL;
|
|
1344
|
+
txSlot* bottom = the->scope;
|
|
1345
|
+
txSlot* slot;
|
|
1346
|
+
txSlot* property;
|
|
1347
|
+
top--;
|
|
1348
|
+
slot = top;
|
|
1349
|
+
while (slot >= bottom) {
|
|
1350
|
+
if (slot->kind == XS_CLOSURE_KIND) {
|
|
1351
|
+
property = mxBehaviorGetProperty(the, environment, slot->ID, 0, XS_OWN);
|
|
1352
|
+
if (property)
|
|
1353
|
+
mxDebugID(XS_SYNTAX_ERROR, "%s: duplicate variable", slot->ID);
|
|
1354
|
+
property = mxBehaviorGetProperty(the, global, slot->ID, 0, XS_OWN);
|
|
1355
|
+
if (property && (property->flag & XS_DONT_DELETE_FLAG))
|
|
1356
|
+
mxDebugID(XS_SYNTAX_ERROR, "%s: restricted variable", slot->ID);
|
|
1357
|
+
}
|
|
1358
|
+
else
|
|
1359
|
+
break;
|
|
1360
|
+
|
|
1361
|
+
slot--;
|
|
1362
|
+
}
|
|
1363
|
+
middle = slot;
|
|
1364
|
+
while (slot >= bottom) {
|
|
1365
|
+
property = mxBehaviorGetProperty(the, environment, slot->ID, 0, XS_OWN);
|
|
1366
|
+
if (property)
|
|
1367
|
+
mxDebugID(XS_SYNTAX_ERROR, "%s: duplicate variable", slot->ID);
|
|
1368
|
+
slot--;
|
|
1369
|
+
}
|
|
1370
|
+
mxPushUndefined();
|
|
1371
|
+
slot = bottom;
|
|
1372
|
+
while (slot <= middle) {
|
|
1373
|
+
if (slot->kind == XS_NULL_KIND) {
|
|
1374
|
+
property = the->stack;
|
|
1375
|
+
if (!mxBehaviorGetOwnProperty(the, global, slot->ID, 0, property)) {
|
|
1376
|
+
if (!mxBehaviorIsExtensible(the, global))
|
|
1377
|
+
mxDebugID(XS_TYPE_ERROR, "%s: global object not extensible", slot->ID);
|
|
1378
|
+
}
|
|
1379
|
+
else if (property->flag & XS_DONT_DELETE_FLAG) {
|
|
1380
|
+
if (property->flag & (XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG))
|
|
1381
|
+
mxDebugID(XS_TYPE_ERROR, "%s: global property not configurable and not enumerable or writable", slot->ID);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
slot++;
|
|
1385
|
+
}
|
|
1386
|
+
while (slot >= bottom) {
|
|
1387
|
+
if (slot->kind == XS_UNDEFINED_KIND) {
|
|
1388
|
+
property = the->stack;
|
|
1389
|
+
if (!mxBehaviorGetOwnProperty(the, global, slot->ID, 0, property)) {
|
|
1390
|
+
if (!mxBehaviorIsExtensible(the, global))
|
|
1391
|
+
mxDebugID(XS_TYPE_ERROR, "%s: global object not extensible", slot->ID);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
slot--;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
slot = top;
|
|
1398
|
+
while (slot > middle) {
|
|
1399
|
+
mxBehaviorDefineOwnProperty(the, environment, slot->ID, 0, slot, XS_GET_ONLY);
|
|
1400
|
+
slot--;
|
|
1401
|
+
}
|
|
1402
|
+
slot = bottom;
|
|
1403
|
+
while (slot <= middle) {
|
|
1404
|
+
if (slot->kind == XS_NULL_KIND) {
|
|
1405
|
+
property = mxBehaviorSetProperty(the, global, slot->ID, 0, XS_OWN);
|
|
1406
|
+
if (!(property->flag & XS_DONT_DELETE_FLAG))
|
|
1407
|
+
property->flag = XS_DONT_DELETE_FLAG;
|
|
1408
|
+
slot->value.closure = property;
|
|
1409
|
+
slot->kind = XS_CLOSURE_KIND;
|
|
1410
|
+
}
|
|
1411
|
+
slot++;
|
|
1412
|
+
}
|
|
1413
|
+
while (slot >= bottom) {
|
|
1414
|
+
if (slot->kind == XS_UNDEFINED_KIND) {
|
|
1415
|
+
property = mxBehaviorGetProperty(the, global, slot->ID, 0, XS_OWN);
|
|
1416
|
+
if (!property) {
|
|
1417
|
+
property = mxBehaviorSetProperty(the, global, slot->ID, 0, XS_OWN);
|
|
1418
|
+
property->flag = XS_DONT_DELETE_FLAG;
|
|
1419
|
+
}
|
|
1420
|
+
slot->value.closure = property;
|
|
1421
|
+
slot->kind = XS_CLOSURE_KIND;
|
|
1422
|
+
}
|
|
1423
|
+
slot--;
|
|
1424
|
+
}
|
|
1425
|
+
mxPop();
|
|
1426
|
+
the->stack = the->scope = middle + 1;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
txSlot* fxNewRealmInstance(txMachine* the)
|
|
1431
|
+
{
|
|
1432
|
+
txSlot* parent = the->stack + 9;
|
|
1433
|
+
txSlot* global = the->stack + 8;
|
|
1434
|
+
txSlot* moduleMap = the->stack + 7;
|
|
1435
|
+
txSlot* own = the->stack + 6;
|
|
1436
|
+
txSlot* closures = the->stack + 5;
|
|
1437
|
+
txSlot* resolveHook = the->stack + 4;
|
|
1438
|
+
txSlot* moduleMapHook = the->stack + 3;
|
|
1439
|
+
txSlot* loadHook = the->stack + 2;
|
|
1440
|
+
txSlot* loadNowHook = the->stack + 1;
|
|
1441
|
+
txSlot* importMetaHook = the->stack;
|
|
1442
|
+
txSlot* realm = fxNewInstance(the);
|
|
1443
|
+
txSlot* slot;
|
|
1444
|
+
/* mxRealmGlobal */
|
|
1445
|
+
slot = fxNextSlotProperty(the, realm, global, XS_NO_ID, XS_GET_ONLY);
|
|
1446
|
+
/* mxRealmClosures */
|
|
1447
|
+
slot = fxNextSlotProperty(the, slot, closures, XS_NO_ID, XS_GET_ONLY);
|
|
1448
|
+
/* mxRealmTemplateCache */
|
|
1449
|
+
slot = fxNextReferenceProperty(the, slot, fxNewInstance(the), XS_NO_ID, XS_GET_ONLY);
|
|
1450
|
+
mxPop();
|
|
1451
|
+
/* mxOwnModules */
|
|
1452
|
+
slot = fxNextSlotProperty(the, slot, own, XS_NO_ID, XS_GET_ONLY);
|
|
1453
|
+
/* mxResolveHook */
|
|
1454
|
+
slot = fxNextSlotProperty(the, slot, resolveHook, XS_NO_ID, XS_GET_ONLY);
|
|
1455
|
+
/* mxModuleMap */
|
|
1456
|
+
slot = fxNextSlotProperty(the, slot, moduleMap, XS_NO_ID, XS_GET_ONLY);
|
|
1457
|
+
/* mxModuleMapHook */
|
|
1458
|
+
slot = fxNextSlotProperty(the, slot, moduleMapHook, XS_NO_ID, XS_GET_ONLY);
|
|
1459
|
+
/* mxLoadHook */
|
|
1460
|
+
slot = fxNextSlotProperty(the, slot, loadHook, XS_NO_ID, XS_GET_ONLY);
|
|
1461
|
+
/* mxLoadNowHook */
|
|
1462
|
+
slot = fxNextSlotProperty(the, slot, loadNowHook, XS_NO_ID, XS_GET_ONLY);
|
|
1463
|
+
/* mxImportMetaHook */
|
|
1464
|
+
slot = fxNextSlotProperty(the, slot, importMetaHook, XS_NO_ID, XS_GET_ONLY);
|
|
1465
|
+
/* mxRealmParent */
|
|
1466
|
+
slot = fxNextSlotProperty(the, slot, parent, XS_NO_ID, XS_GET_ONLY);
|
|
1467
|
+
parent->value.reference = realm;
|
|
1468
|
+
the->stack = parent;
|
|
1469
|
+
return realm;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
txSlot* fxNewProgramInstance(txMachine* the)
|
|
1473
|
+
{
|
|
1474
|
+
txSlot* instance;
|
|
1475
|
+
txSlot* slot;
|
|
1476
|
+
instance = fxNewSlot(the);
|
|
1477
|
+
instance->kind = XS_INSTANCE_KIND;
|
|
1478
|
+
instance->value.instance.garbage = C_NULL;
|
|
1479
|
+
instance->value.instance.prototype = mxIsReference(the->stack) ? the->stack->value.reference : C_NULL;
|
|
1480
|
+
the->stack->value.reference = instance;
|
|
1481
|
+
the->stack->kind = XS_REFERENCE_KIND;
|
|
1482
|
+
slot = instance->next = fxNewSlot(the);
|
|
1483
|
+
slot->flag = XS_INTERNAL_FLAG;
|
|
1484
|
+
slot->kind = XS_PROGRAM_KIND;
|
|
1485
|
+
slot->value.module.realm = C_NULL;
|
|
1486
|
+
slot->value.module.id = XS_NO_ID;
|
|
1487
|
+
return instance;
|
|
1488
|
+
}
|