@agoric/xsnap 0.14.3-u13.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 +39 -22
- 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 -646
|
@@ -0,0 +1,1014 @@
|
|
|
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
|
+
static txSlot* fxNewProxyInstance(txMachine* the);
|
|
41
|
+
static txSlot* fxCheckProxyFunction(txMachine* the, txSlot* proxy, txID index);
|
|
42
|
+
|
|
43
|
+
static void fxProxyCall(txMachine* the, txSlot* instance, txSlot* _this, txSlot* arguments);
|
|
44
|
+
static void fxProxyConstruct(txMachine* the, txSlot* instance, txSlot* arguments, txSlot* target);
|
|
45
|
+
static txBoolean fxProxyDefineOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot, txFlag mask);
|
|
46
|
+
static txBoolean fxProxyDeleteProperty(txMachine* the, txSlot* instance, txID id, txIndex index);
|
|
47
|
+
static txBoolean fxProxyGetOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot);
|
|
48
|
+
static txSlot* fxProxyGetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag);
|
|
49
|
+
static txBoolean fxProxyGetPropertyValue(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* receiver, txSlot* value);
|
|
50
|
+
static txBoolean fxProxyGetPrototype(txMachine* the, txSlot* instance, txSlot* result);
|
|
51
|
+
static txBoolean fxProxyHasProperty(txMachine* the, txSlot* instance, txID id, txIndex index);
|
|
52
|
+
static txBoolean fxProxyIsExtensible(txMachine* the, txSlot* instance);
|
|
53
|
+
static void fxProxyOwnKeys(txMachine* the, txSlot* instance, txFlag flag, txSlot* list);
|
|
54
|
+
static txBoolean fxProxyPreventExtensions(txMachine* the, txSlot* instance);
|
|
55
|
+
static txSlot* fxProxySetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag);
|
|
56
|
+
static txBoolean fxProxySetPropertyValue(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* value, txSlot* receiver);
|
|
57
|
+
static txBoolean fxProxySetPrototype(txMachine* the, txSlot* instance, txSlot* prototype);
|
|
58
|
+
|
|
59
|
+
const txBehavior ICACHE_FLASH_ATTR gxProxyBehavior = {
|
|
60
|
+
fxProxyGetProperty,
|
|
61
|
+
fxProxySetProperty,
|
|
62
|
+
fxProxyCall,
|
|
63
|
+
fxProxyConstruct,
|
|
64
|
+
fxProxyDefineOwnProperty,
|
|
65
|
+
fxProxyDeleteProperty,
|
|
66
|
+
fxProxyGetOwnProperty,
|
|
67
|
+
fxProxyGetPropertyValue,
|
|
68
|
+
fxProxyGetPrototype,
|
|
69
|
+
fxProxyHasProperty,
|
|
70
|
+
fxProxyIsExtensible,
|
|
71
|
+
fxProxyOwnKeys,
|
|
72
|
+
fxProxyPreventExtensions,
|
|
73
|
+
fxProxySetPropertyValue,
|
|
74
|
+
fxProxySetPrototype,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
void fxBuildProxy(txMachine* the)
|
|
78
|
+
{
|
|
79
|
+
txSlot* slot;
|
|
80
|
+
|
|
81
|
+
fxNewHostFunction(the, mxCallback(fxProxyGetter), 0, XS_NO_ID, XS_NO_ID);
|
|
82
|
+
fxNewHostFunction(the, mxCallback(fxProxySetter), 1, XS_NO_ID, XS_NO_ID);
|
|
83
|
+
mxPushUndefined();
|
|
84
|
+
the->stack->flag = XS_DONT_DELETE_FLAG;
|
|
85
|
+
the->stack->kind = XS_ACCESSOR_KIND;
|
|
86
|
+
the->stack->value.accessor.getter = (the->stack + 2)->value.reference;
|
|
87
|
+
the->stack->value.accessor.setter = (the->stack + 1)->value.reference;
|
|
88
|
+
mxPull(mxProxyAccessor);
|
|
89
|
+
the->stack += 2;
|
|
90
|
+
|
|
91
|
+
slot = fxBuildHostFunction(the, mxCallback(fx_Proxy), 2, mxID(_Proxy));
|
|
92
|
+
slot->flag |= XS_CAN_CONSTRUCT_FLAG;
|
|
93
|
+
mxProxyConstructor = *the->stack;
|
|
94
|
+
slot = fxLastProperty(the, slot);
|
|
95
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Proxy_revocable), 2, mxID(_revocable), XS_DONT_ENUM_FLAG);
|
|
96
|
+
mxPop();
|
|
97
|
+
|
|
98
|
+
mxPush(mxObjectPrototype);
|
|
99
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
100
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_apply), 3, mxID(_apply), XS_DONT_ENUM_FLAG);
|
|
101
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_construct), 2, mxID(_construct), XS_DONT_ENUM_FLAG);
|
|
102
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_defineProperty), 3, mxID(_defineProperty), XS_DONT_ENUM_FLAG);
|
|
103
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_deleteProperty), 2, mxID(_deleteProperty), XS_DONT_ENUM_FLAG);
|
|
104
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_get), 2, mxID(_get), XS_DONT_ENUM_FLAG);
|
|
105
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_getOwnPropertyDescriptor), 2, mxID(_getOwnPropertyDescriptor), XS_DONT_ENUM_FLAG);
|
|
106
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_getPrototypeOf), 1, mxID(_getPrototypeOf), XS_DONT_ENUM_FLAG);
|
|
107
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_has), 2, mxID(_has), XS_DONT_ENUM_FLAG);
|
|
108
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_isExtensible), 1, mxID(_isExtensible), XS_DONT_ENUM_FLAG);
|
|
109
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_ownKeys), 1, mxID(_ownKeys), XS_DONT_ENUM_FLAG);
|
|
110
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_preventExtensions), 1, mxID(_preventExtensions), XS_DONT_ENUM_FLAG);
|
|
111
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_set), 3, mxID(_set), XS_DONT_ENUM_FLAG);
|
|
112
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Reflect_setPrototypeOf), 2, mxID(_setPrototypeOf), XS_DONT_ENUM_FLAG);
|
|
113
|
+
slot = fxNextStringXProperty(the, slot, "Reflect", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
114
|
+
mxPull(mxReflectObject);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
txSlot* fxNewProxyInstance(txMachine* the)
|
|
118
|
+
{
|
|
119
|
+
txSlot* prototype;
|
|
120
|
+
txSlot* instance;
|
|
121
|
+
txSlot* property;
|
|
122
|
+
txSlot* slot;
|
|
123
|
+
|
|
124
|
+
prototype = mxIsReference(the->stack) ? the->stack->value.reference : C_NULL;
|
|
125
|
+
|
|
126
|
+
instance = fxNewSlot(the);
|
|
127
|
+
instance->flag = XS_EXOTIC_FLAG;
|
|
128
|
+
instance->kind = XS_INSTANCE_KIND;
|
|
129
|
+
instance->value.instance.garbage = C_NULL;
|
|
130
|
+
instance->value.instance.prototype = C_NULL;
|
|
131
|
+
the->stack->kind = XS_REFERENCE_KIND;
|
|
132
|
+
the->stack->value.reference = instance;
|
|
133
|
+
|
|
134
|
+
property = instance->next = fxNewSlot(the);
|
|
135
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
136
|
+
property->kind = XS_PROXY_KIND;
|
|
137
|
+
property->ID = XS_PROXY_BEHAVIOR;
|
|
138
|
+
if (prototype && ((slot = prototype->next)) && (slot->kind = XS_PROXY_KIND)) {
|
|
139
|
+
property->value.proxy.handler = slot->value.proxy.handler;
|
|
140
|
+
property->value.proxy.target = slot->value.proxy.target;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
property->value.proxy.handler = C_NULL;
|
|
144
|
+
property->value.proxy.target = C_NULL;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return instance;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#define mxProxyDeclarations(ID) \
|
|
151
|
+
txSlot* proxy = instance->next; \
|
|
152
|
+
txSlot* function = fxCheckProxyFunction(the, proxy, ID); \
|
|
153
|
+
txSlot* handler = the->stack + 1; \
|
|
154
|
+
txSlot* target = the->stack + 2
|
|
155
|
+
|
|
156
|
+
#define mxProxyPop() \
|
|
157
|
+
mxPop(); \
|
|
158
|
+
mxPop(); \
|
|
159
|
+
mxPop()
|
|
160
|
+
|
|
161
|
+
txSlot* fxCheckProxyFunction(txMachine* the, txSlot* proxy, txID index)
|
|
162
|
+
{
|
|
163
|
+
txSlot* function;
|
|
164
|
+
mxCheckCStack();
|
|
165
|
+
if (!proxy->value.proxy.handler)
|
|
166
|
+
mxTypeError("(proxy).%s: handler is no object", fxName(the, mxID(index)));
|
|
167
|
+
if (!proxy->value.proxy.target)
|
|
168
|
+
mxTypeError("(proxy).%s: target is no object", fxName(the, mxID(index)));
|
|
169
|
+
mxPushReference(proxy->value.proxy.target);
|
|
170
|
+
mxPushReference(proxy->value.proxy.handler);
|
|
171
|
+
mxDub();
|
|
172
|
+
mxGetID(mxID(index));
|
|
173
|
+
function = the->stack;
|
|
174
|
+
if (mxIsUndefined(function) || (mxIsNull(function)))
|
|
175
|
+
function = C_NULL;
|
|
176
|
+
else if (!fxIsCallable(the, function))
|
|
177
|
+
mxTypeError("(proxy).%s: no function", fxName(the, mxID(index)));
|
|
178
|
+
return function;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
void fxProxyGetter(txMachine* the)
|
|
182
|
+
{
|
|
183
|
+
txSlot* instance = fxToInstance(the, mxThis);
|
|
184
|
+
while (instance) {
|
|
185
|
+
if (mxIsProxy(instance))
|
|
186
|
+
break;
|
|
187
|
+
instance = fxGetPrototype(the, instance);
|
|
188
|
+
}
|
|
189
|
+
if (instance) {
|
|
190
|
+
txID id = the->scratch.value.at.id;
|
|
191
|
+
txIndex index = the->scratch.value.at.index;
|
|
192
|
+
fxProxyGetPropertyValue(the, instance, id, index, mxThis, mxResult);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
void fxProxySetter(txMachine* the)
|
|
197
|
+
{
|
|
198
|
+
txSlot* instance = fxToInstance(the, mxThis);
|
|
199
|
+
while (instance) {
|
|
200
|
+
if (mxIsProxy(instance))
|
|
201
|
+
break;
|
|
202
|
+
instance = fxGetPrototype(the, instance);
|
|
203
|
+
}
|
|
204
|
+
if (instance) {
|
|
205
|
+
txID id = the->scratch.value.at.id;
|
|
206
|
+
txIndex index = the->scratch.value.at.index;
|
|
207
|
+
txBoolean result = fxProxySetPropertyValue(the, instance, id, index, mxArgv(0), mxThis);
|
|
208
|
+
if (!result) {
|
|
209
|
+
if (the->frame->next->flag & XS_STRICT_FLAG)
|
|
210
|
+
mxTypeError("(proxy).set: not extensible or not writable");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void fxProxyCall(txMachine* the, txSlot* instance, txSlot* _this, txSlot* arguments)
|
|
216
|
+
{
|
|
217
|
+
mxProxyDeclarations(_apply);
|
|
218
|
+
if (function) {
|
|
219
|
+
/* THIS */
|
|
220
|
+
mxPushSlot(handler);
|
|
221
|
+
/* FUNCTION */
|
|
222
|
+
mxPushSlot(function);
|
|
223
|
+
mxCall();
|
|
224
|
+
/* ARGUMENTS */
|
|
225
|
+
mxPushSlot(target);
|
|
226
|
+
mxPushSlot(_this);
|
|
227
|
+
mxPushSlot(arguments);
|
|
228
|
+
mxRunCount(3);
|
|
229
|
+
mxPullSlot(mxResult);
|
|
230
|
+
}
|
|
231
|
+
else
|
|
232
|
+
mxBehaviorCall(the, target->value.reference, _this, arguments);
|
|
233
|
+
mxProxyPop();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
void fxProxyConstruct(txMachine* the, txSlot* instance, txSlot* arguments, txSlot* newTarget)
|
|
237
|
+
{
|
|
238
|
+
mxProxyDeclarations(_construct);
|
|
239
|
+
if (function) {
|
|
240
|
+
/* THIS */
|
|
241
|
+
mxPushSlot(handler);
|
|
242
|
+
/* FUNCTION */
|
|
243
|
+
mxPushSlot(function);
|
|
244
|
+
mxCall();
|
|
245
|
+
/* ARGUMENTS */
|
|
246
|
+
mxPushSlot(target);
|
|
247
|
+
mxPushSlot(arguments);
|
|
248
|
+
mxPushSlot(newTarget);
|
|
249
|
+
mxRunCount(3);
|
|
250
|
+
mxPullSlot(mxResult);
|
|
251
|
+
if (!mxIsReference(mxResult))
|
|
252
|
+
mxTypeError("(proxy).construct: no object");
|
|
253
|
+
}
|
|
254
|
+
else
|
|
255
|
+
mxBehaviorConstruct(the, target->value.reference, arguments, newTarget);
|
|
256
|
+
mxProxyPop();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
txBoolean fxProxyDefineOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot, txFlag mask)
|
|
260
|
+
{
|
|
261
|
+
txBoolean result;
|
|
262
|
+
mxProxyDeclarations(_defineProperty);
|
|
263
|
+
if (function) {
|
|
264
|
+
/* THIS */
|
|
265
|
+
mxPushSlot(handler);
|
|
266
|
+
/* FUNCTION */
|
|
267
|
+
mxPushSlot(function);
|
|
268
|
+
mxCall();
|
|
269
|
+
/* ARGUMENTS */
|
|
270
|
+
mxPushSlot(target);
|
|
271
|
+
mxPushUndefined();
|
|
272
|
+
fxKeyAt(the, id, index, the->stack);
|
|
273
|
+
fxDescribeProperty(the, slot, mask);
|
|
274
|
+
mxRunCount(3);
|
|
275
|
+
result = fxToBoolean(the, the->stack);
|
|
276
|
+
mxPop();
|
|
277
|
+
if (result) {
|
|
278
|
+
mxPushUndefined();
|
|
279
|
+
if (mxBehaviorGetOwnProperty(the, target->value.reference, id, index, the->stack)) {
|
|
280
|
+
if (fxIsPropertyCompatible(the, the->stack, slot, mask)) {
|
|
281
|
+
if ((mask & XS_DONT_DELETE_FLAG) && (slot->flag & XS_DONT_DELETE_FLAG)) {
|
|
282
|
+
if (!(the->stack->flag & XS_DONT_DELETE_FLAG))
|
|
283
|
+
mxTypeError("(proxy).defineProperty: true with non-configurable descriptor for configurable property");
|
|
284
|
+
}
|
|
285
|
+
if (the->stack->flag & XS_DONT_DELETE_FLAG) {
|
|
286
|
+
if ((mask & XS_DONT_SET_FLAG) && (slot->flag & XS_DONT_SET_FLAG) && !(the->stack->flag & XS_DONT_SET_FLAG))
|
|
287
|
+
mxTypeError("(proxy).defineProperty: true with non-writable descriptor for non-configurable writable property");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else
|
|
291
|
+
mxTypeError("(proxy).defineProperty: true with incompatible descriptor for existent property");
|
|
292
|
+
}
|
|
293
|
+
else if (mxBehaviorIsExtensible(the, target->value.reference)) {
|
|
294
|
+
if ((mask & XS_DONT_DELETE_FLAG) && (slot->flag & XS_DONT_DELETE_FLAG))
|
|
295
|
+
mxTypeError("(proxy).defineProperty: true with non-configurable descriptor for non-existent property");
|
|
296
|
+
}
|
|
297
|
+
else
|
|
298
|
+
mxTypeError("(proxy).defineProperty: true with descriptor for non-existent property of non-extensible object");
|
|
299
|
+
mxPop();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else
|
|
303
|
+
result = mxBehaviorDefineOwnProperty(the, target->value.reference, id, index, slot, mask);
|
|
304
|
+
mxProxyPop();
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
txBoolean fxProxyDeleteProperty(txMachine* the, txSlot* instance, txID id, txIndex index)
|
|
309
|
+
{
|
|
310
|
+
txBoolean result;
|
|
311
|
+
mxProxyDeclarations(_deleteProperty);
|
|
312
|
+
if (function) {
|
|
313
|
+
/* THIS */
|
|
314
|
+
mxPushSlot(handler);
|
|
315
|
+
/* FUNCTION */
|
|
316
|
+
mxPushSlot(function);
|
|
317
|
+
mxCall();
|
|
318
|
+
/* ARGUMENTS */
|
|
319
|
+
mxPushSlot(target);
|
|
320
|
+
mxPushUndefined();
|
|
321
|
+
fxKeyAt(the, id, index, the->stack);
|
|
322
|
+
mxRunCount(2);
|
|
323
|
+
result = fxToBoolean(the, the->stack);
|
|
324
|
+
mxPop();
|
|
325
|
+
if (result) {
|
|
326
|
+
mxPushUndefined();
|
|
327
|
+
if (mxBehaviorGetOwnProperty(the, target->value.reference, id, index, the->stack)) {
|
|
328
|
+
if (the->stack->flag & XS_DONT_DELETE_FLAG)
|
|
329
|
+
mxTypeError("(proxy).deleteProperty: true for non-configurable property");
|
|
330
|
+
if (!mxBehaviorIsExtensible(the, target->value.reference))
|
|
331
|
+
mxTypeError("(proxy).deleteProperty: true for non-extensible object");
|
|
332
|
+
}
|
|
333
|
+
mxPop();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
else
|
|
337
|
+
result = mxBehaviorDeleteProperty(the, target->value.reference, id, index);
|
|
338
|
+
mxProxyPop();
|
|
339
|
+
return result;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
txBoolean fxProxyGetOwnProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot)
|
|
343
|
+
{
|
|
344
|
+
txBoolean result;
|
|
345
|
+
mxProxyDeclarations(_getOwnPropertyDescriptor);
|
|
346
|
+
if (function) {
|
|
347
|
+
txFlag mask;
|
|
348
|
+
/* THIS */
|
|
349
|
+
mxPushSlot(handler);
|
|
350
|
+
/* FUNCTION */
|
|
351
|
+
mxPushSlot(function);
|
|
352
|
+
mxCall();
|
|
353
|
+
/* ARGUMENTS */
|
|
354
|
+
mxPushSlot(target);
|
|
355
|
+
mxPushUndefined();
|
|
356
|
+
fxKeyAt(the, id, index, the->stack);
|
|
357
|
+
mxRunCount(2);
|
|
358
|
+
mxPullSlot(slot);
|
|
359
|
+
mxPushUndefined();
|
|
360
|
+
if (slot->kind == XS_UNDEFINED_KIND) {
|
|
361
|
+
if (mxBehaviorGetOwnProperty(the, target->value.reference, id, index, the->stack)) {
|
|
362
|
+
if (the->stack->flag & XS_DONT_DELETE_FLAG)
|
|
363
|
+
mxTypeError("(proxy).getOwnPropertyDescriptor: no descriptor for non-configurable property");
|
|
364
|
+
if (!mxBehaviorIsExtensible(the, target->value.reference))
|
|
365
|
+
mxTypeError("(proxy).getOwnPropertyDescriptor: no descriptor for existent property of non-extensible object");
|
|
366
|
+
}
|
|
367
|
+
result = 0;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
mask = fxDescriptorToSlot(the, slot);
|
|
371
|
+
if (!(mask & XS_DONT_DELETE_FLAG)) {
|
|
372
|
+
mask |= XS_DONT_DELETE_FLAG;
|
|
373
|
+
slot->flag |= XS_DONT_DELETE_FLAG;
|
|
374
|
+
}
|
|
375
|
+
if (!(mask & XS_DONT_ENUM_FLAG)) {
|
|
376
|
+
mask |= XS_DONT_ENUM_FLAG;
|
|
377
|
+
slot->flag |= XS_DONT_ENUM_FLAG;
|
|
378
|
+
}
|
|
379
|
+
if (!(mask & (XS_GETTER_FLAG | XS_SETTER_FLAG))) {
|
|
380
|
+
if (!(mask & XS_DONT_SET_FLAG)) {
|
|
381
|
+
mask |= XS_DONT_SET_FLAG;
|
|
382
|
+
slot->flag |= XS_DONT_SET_FLAG;
|
|
383
|
+
}
|
|
384
|
+
if (slot->kind == XS_UNINITIALIZED_KIND)
|
|
385
|
+
slot->kind = XS_UNDEFINED_KIND;
|
|
386
|
+
}
|
|
387
|
+
if (mxBehaviorGetOwnProperty(the, target->value.reference, id, index, the->stack)) {
|
|
388
|
+
if (fxIsPropertyCompatible(the, the->stack, slot, mask)) {
|
|
389
|
+
if ((mask & XS_DONT_DELETE_FLAG) && (slot->flag & XS_DONT_DELETE_FLAG)) {
|
|
390
|
+
if (!(the->stack->flag & XS_DONT_DELETE_FLAG))
|
|
391
|
+
mxTypeError("(proxy).getOwnPropertyDescriptor: non-configurable descriptor for configurable property");
|
|
392
|
+
}
|
|
393
|
+
if (the->stack->flag & XS_DONT_DELETE_FLAG) {
|
|
394
|
+
if ((mask & XS_DONT_SET_FLAG) && (slot->flag & XS_DONT_SET_FLAG) && !(the->stack->flag & XS_DONT_SET_FLAG))
|
|
395
|
+
mxTypeError("(proxy).getOwnPropertyDescriptor: true with non-writable descriptor for non-configurable writable property");
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else
|
|
399
|
+
mxTypeError("(proxy).getOwnPropertyDescriptor: incompatible descriptor for existent property");
|
|
400
|
+
}
|
|
401
|
+
else if (mxBehaviorIsExtensible(the, target->value.reference)) {
|
|
402
|
+
if ((mask & XS_DONT_DELETE_FLAG) && (slot->flag & XS_DONT_DELETE_FLAG))
|
|
403
|
+
mxTypeError("(proxy).getOwnPropertyDescriptor: non-configurable descriptor for non-existent property");
|
|
404
|
+
}
|
|
405
|
+
else
|
|
406
|
+
mxTypeError("(proxy).getOwnPropertyDescriptor: descriptor for non-existent property of non-extensible object");
|
|
407
|
+
result = 1;
|
|
408
|
+
}
|
|
409
|
+
mxPop();
|
|
410
|
+
}
|
|
411
|
+
else
|
|
412
|
+
result = mxBehaviorGetOwnProperty(the, target->value.reference, id, index, slot);
|
|
413
|
+
mxProxyPop();
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
txSlot* fxProxyGetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag)
|
|
418
|
+
{
|
|
419
|
+
the->scratch.value.at.id = id;
|
|
420
|
+
the->scratch.value.at.index = index;
|
|
421
|
+
return &mxProxyAccessor;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
txBoolean fxProxyGetPropertyValue(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* receiver, txSlot* slot)
|
|
425
|
+
{
|
|
426
|
+
txBoolean result;
|
|
427
|
+
mxProxyDeclarations(_get);
|
|
428
|
+
if (function) {
|
|
429
|
+
/* THIS */
|
|
430
|
+
mxPushSlot(handler);
|
|
431
|
+
/* FUNCTION */
|
|
432
|
+
mxPushSlot(function);
|
|
433
|
+
mxCall();
|
|
434
|
+
/* ARGUMENTS */
|
|
435
|
+
mxPushSlot(target);
|
|
436
|
+
mxPushUndefined();
|
|
437
|
+
fxKeyAt(the, id, index, the->stack);
|
|
438
|
+
mxPushSlot(receiver);
|
|
439
|
+
mxRunCount(3);
|
|
440
|
+
mxPullSlot(slot);
|
|
441
|
+
mxPushUndefined();
|
|
442
|
+
if (mxBehaviorGetOwnProperty(the, target->value.reference, id, index, the->stack)) {
|
|
443
|
+
txSlot* property = the->stack;
|
|
444
|
+
if (property->flag & XS_DONT_DELETE_FLAG) {
|
|
445
|
+
if (property->kind == XS_ACCESSOR_KIND) {
|
|
446
|
+
if ((property->value.accessor.getter == C_NULL) && (slot->kind != XS_UNDEFINED_KIND))
|
|
447
|
+
mxTypeError("(proxy).get: different getter for non-configurable property");
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
if ((property->flag & XS_DONT_SET_FLAG) && (!fxIsSameValue(the, property, slot, 0)))
|
|
451
|
+
mxTypeError("(proxy).get: different value for non-configurable, non-writable property");
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
result = 1;
|
|
456
|
+
mxPop();
|
|
457
|
+
}
|
|
458
|
+
else
|
|
459
|
+
result = mxBehaviorGetPropertyValue(the, target->value.reference, id, index, receiver, slot);
|
|
460
|
+
mxProxyPop();
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
txBoolean fxProxyGetPrototype(txMachine* the, txSlot* instance, txSlot* slot)
|
|
465
|
+
{
|
|
466
|
+
txBoolean result;
|
|
467
|
+
mxProxyDeclarations(_getPrototypeOf);
|
|
468
|
+
if (function) {
|
|
469
|
+
/* THIS */
|
|
470
|
+
mxPushSlot(handler);
|
|
471
|
+
/* FUNCTION */
|
|
472
|
+
mxPushSlot(function);
|
|
473
|
+
mxCall();
|
|
474
|
+
/* ARGUMENTS */
|
|
475
|
+
mxPushSlot(target);
|
|
476
|
+
mxRunCount(1);
|
|
477
|
+
mxPullSlot(slot);
|
|
478
|
+
if ((slot->kind == XS_NULL_KIND) || (slot->kind == XS_REFERENCE_KIND)) {
|
|
479
|
+
if (!mxBehaviorIsExtensible(the, target->value.reference)) {
|
|
480
|
+
mxPushUndefined();
|
|
481
|
+
mxBehaviorGetPrototype(the, target->value.reference, the->stack);
|
|
482
|
+
if (!fxIsSameValue(the, slot, the->stack, 0))
|
|
483
|
+
mxTypeError("(proxy).getPrototypeOf: different prototype for non-extensible object");
|
|
484
|
+
mxPop();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else
|
|
488
|
+
mxTypeError("(proxy).getPrototypeOf: neither object nor null");
|
|
489
|
+
result = (slot->kind == XS_NULL_KIND) ? 0 : 1;
|
|
490
|
+
}
|
|
491
|
+
else
|
|
492
|
+
result = mxBehaviorGetPrototype(the, target->value.reference, slot);
|
|
493
|
+
mxProxyPop();
|
|
494
|
+
return result;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
txBoolean fxProxyHasProperty(txMachine* the, txSlot* instance, txID id, txIndex index)
|
|
498
|
+
{
|
|
499
|
+
txBoolean result;
|
|
500
|
+
mxProxyDeclarations(_has);
|
|
501
|
+
if (function) {
|
|
502
|
+
/* THIS */
|
|
503
|
+
mxPushSlot(handler);
|
|
504
|
+
/* FUNCTION */
|
|
505
|
+
mxPushSlot(function);
|
|
506
|
+
mxCall();
|
|
507
|
+
/* ARGUMENTS */
|
|
508
|
+
mxPushSlot(target);
|
|
509
|
+
mxPushUndefined();
|
|
510
|
+
fxKeyAt(the, id, index, the->stack);
|
|
511
|
+
mxRunCount(2);
|
|
512
|
+
result = fxToBoolean(the, the->stack);
|
|
513
|
+
mxPop();
|
|
514
|
+
if (!result) {
|
|
515
|
+
mxPushUndefined();
|
|
516
|
+
if (mxBehaviorGetOwnProperty(the, target->value.reference, id, index, the->stack)) {
|
|
517
|
+
if (the->stack->flag & XS_DONT_DELETE_FLAG)
|
|
518
|
+
mxTypeError("(proxy).has: false for non-configurable property");
|
|
519
|
+
if (!mxBehaviorIsExtensible(the, target->value.reference))
|
|
520
|
+
mxTypeError("(proxy).has: false for property of not extensible object");
|
|
521
|
+
}
|
|
522
|
+
mxPop();
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
else
|
|
526
|
+
result = mxBehaviorHasProperty(the, target->value.reference, id, index);
|
|
527
|
+
mxProxyPop();
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
txBoolean fxProxyIsExtensible(txMachine* the, txSlot* instance)
|
|
532
|
+
{
|
|
533
|
+
txBoolean result;
|
|
534
|
+
mxProxyDeclarations(_isExtensible);
|
|
535
|
+
if (function) {
|
|
536
|
+
/* THIS */
|
|
537
|
+
mxPushSlot(handler);
|
|
538
|
+
/* FUNCTION */
|
|
539
|
+
mxPushSlot(function);
|
|
540
|
+
mxCall();
|
|
541
|
+
/* ARGUMENTS */
|
|
542
|
+
mxPushSlot(target);
|
|
543
|
+
mxRunCount(1);
|
|
544
|
+
result = fxToBoolean(the, the->stack);
|
|
545
|
+
mxPop();
|
|
546
|
+
if (mxBehaviorIsExtensible(the, target->value.reference)) {
|
|
547
|
+
if (!result)
|
|
548
|
+
mxTypeError("(proxy).isExtensible: false for extensible object");
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
if (result)
|
|
552
|
+
mxTypeError("(proxy).isExtensible: true for non-extensible object");
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
else
|
|
556
|
+
result = mxBehaviorIsExtensible(the, target->value.reference);
|
|
557
|
+
mxProxyPop();
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
void fxProxyOwnKeys(txMachine* the, txSlot* instance, txFlag flag, txSlot* list)
|
|
562
|
+
{
|
|
563
|
+
mxProxyDeclarations(_ownKeys);
|
|
564
|
+
if (function) {
|
|
565
|
+
txIndex length;
|
|
566
|
+
txSlot* reference;
|
|
567
|
+
txSlot* item;
|
|
568
|
+
txIndex index;
|
|
569
|
+
txSlot* at;
|
|
570
|
+
txBoolean test;
|
|
571
|
+
txSlot* property;
|
|
572
|
+
/* THIS */
|
|
573
|
+
mxPushSlot(handler);
|
|
574
|
+
/* FUNCTION */
|
|
575
|
+
mxPushSlot(function);
|
|
576
|
+
mxCall();
|
|
577
|
+
/* ARGUMENTS */
|
|
578
|
+
mxPushSlot(target);
|
|
579
|
+
mxRunCount(1);
|
|
580
|
+
reference = the->stack;
|
|
581
|
+
mxPushSlot(reference);
|
|
582
|
+
mxGetID(mxID(_length));
|
|
583
|
+
length = fxToInteger(the, the->stack++);
|
|
584
|
+
item = list;
|
|
585
|
+
index = 0;
|
|
586
|
+
while (index < length) {
|
|
587
|
+
mxPushSlot(reference);
|
|
588
|
+
mxGetIndex(index);
|
|
589
|
+
at = the->stack;
|
|
590
|
+
test = (at->kind == XS_SYMBOL_KIND) ? 1 : 0;
|
|
591
|
+
if (test || (at->kind == XS_STRING_KIND) || (at->kind == XS_STRING_X_KIND)) {
|
|
592
|
+
fxAt(the, at);
|
|
593
|
+
property = list;
|
|
594
|
+
while ((property = property->next)) {
|
|
595
|
+
if ((at->value.at.id == property->value.at.id) && (at->value.at.index == property->value.at.index))
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
if (property)
|
|
599
|
+
mxTypeError("(proxy).ownKeys: duplicate key");
|
|
600
|
+
item = item->next = fxNewSlot(the);
|
|
601
|
+
mxPullSlot(item);
|
|
602
|
+
if (test)
|
|
603
|
+
item->flag |= XS_INTERNAL_FLAG;
|
|
604
|
+
}
|
|
605
|
+
else
|
|
606
|
+
mxTypeError("(proxy).ownKeys: key is neither string nor symbol");
|
|
607
|
+
index++;
|
|
608
|
+
}
|
|
609
|
+
mxPop();
|
|
610
|
+
|
|
611
|
+
test = mxBehaviorIsExtensible(the, target->value.reference) ? 1 : 0;
|
|
612
|
+
at = fxNewInstance(the);
|
|
613
|
+
mxBehaviorOwnKeys(the, target->value.reference, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
|
|
614
|
+
mxPushUndefined();
|
|
615
|
+
property = the->stack;
|
|
616
|
+
while ((at = at->next)) {
|
|
617
|
+
mxBehaviorGetOwnProperty(the, target->value.reference, at->value.at.id, at->value.at.index, property);
|
|
618
|
+
item = list;
|
|
619
|
+
while ((item = item->next)) {
|
|
620
|
+
if ((at->value.at.id == item->value.at.id) && (at->value.at.index == item->value.at.index)) {
|
|
621
|
+
length--;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (!item) {
|
|
626
|
+
if (property->flag & XS_DONT_DELETE_FLAG)
|
|
627
|
+
mxTypeError("(proxy).ownKeys: no key for non-configurable property");
|
|
628
|
+
if (!test)
|
|
629
|
+
mxTypeError("(proxy).ownKeys: no key for property of non-extensible object");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if (!test && length)
|
|
633
|
+
mxTypeError("(proxy).ownKeys: key for non-existent property of non-extensible object");
|
|
634
|
+
mxPop();
|
|
635
|
+
mxPop();
|
|
636
|
+
|
|
637
|
+
item = list;
|
|
638
|
+
while ((property = item->next)) {
|
|
639
|
+
if (property->flag & XS_INTERNAL_FLAG) {
|
|
640
|
+
property->flag &= ~XS_INTERNAL_FLAG;
|
|
641
|
+
if (flag & XS_EACH_SYMBOL_FLAG)
|
|
642
|
+
item = property;
|
|
643
|
+
else
|
|
644
|
+
item->next = property->next;
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
if (flag & XS_EACH_NAME_FLAG)
|
|
648
|
+
item = property;
|
|
649
|
+
else
|
|
650
|
+
item->next = property->next;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
else
|
|
655
|
+
mxBehaviorOwnKeys(the, target->value.reference, flag, list);
|
|
656
|
+
mxProxyPop();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
txBoolean fxProxyPreventExtensions(txMachine* the, txSlot* instance)
|
|
660
|
+
{
|
|
661
|
+
txBoolean result;
|
|
662
|
+
mxProxyDeclarations(_preventExtensions);
|
|
663
|
+
if (function) {
|
|
664
|
+
/* THIS */
|
|
665
|
+
mxPushSlot(handler);
|
|
666
|
+
/* FUNCTION */
|
|
667
|
+
mxPushSlot(function);
|
|
668
|
+
mxCall();
|
|
669
|
+
/* ARGUMENTS */
|
|
670
|
+
mxPushSlot(target);
|
|
671
|
+
mxRunCount(1);
|
|
672
|
+
result = fxToBoolean(the, the->stack);
|
|
673
|
+
mxPop();
|
|
674
|
+
if (result) {
|
|
675
|
+
if (mxBehaviorIsExtensible(the, target->value.reference))
|
|
676
|
+
mxTypeError("(proxy).preventExtensions: true for extensible object");
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
else
|
|
680
|
+
result = mxBehaviorPreventExtensions(the, target->value.reference);
|
|
681
|
+
mxProxyPop();
|
|
682
|
+
return result;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
txSlot* fxProxySetProperty(txMachine* the, txSlot* instance, txID id, txIndex index, txFlag flag)
|
|
686
|
+
{
|
|
687
|
+
the->scratch.value.at.id = id;
|
|
688
|
+
the->scratch.value.at.index = index;
|
|
689
|
+
return &mxProxyAccessor;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
txBoolean fxProxySetPropertyValue(txMachine* the, txSlot* instance, txID id, txIndex index, txSlot* slot, txSlot* receiver)
|
|
693
|
+
{
|
|
694
|
+
txBoolean result;
|
|
695
|
+
mxProxyDeclarations(_set);
|
|
696
|
+
if (function) {
|
|
697
|
+
/* THIS */
|
|
698
|
+
mxPushSlot(handler);
|
|
699
|
+
/* FUNCTION */
|
|
700
|
+
mxPushSlot(function);
|
|
701
|
+
mxCall();
|
|
702
|
+
/* ARGUMENTS */
|
|
703
|
+
mxPushSlot(target);
|
|
704
|
+
mxPushUndefined();
|
|
705
|
+
fxKeyAt(the, id, index, the->stack);
|
|
706
|
+
mxPushSlot(slot);
|
|
707
|
+
mxPushSlot(receiver);
|
|
708
|
+
mxRunCount(4);
|
|
709
|
+
result = fxToBoolean(the, the->stack);
|
|
710
|
+
mxPop();
|
|
711
|
+
if (result) {
|
|
712
|
+
mxPushUndefined();
|
|
713
|
+
if (mxBehaviorGetOwnProperty(the, target->value.reference, id, index, the->stack)) {
|
|
714
|
+
txSlot* property = the->stack;
|
|
715
|
+
if (property->flag & XS_DONT_DELETE_FLAG) {
|
|
716
|
+
if (property->kind == XS_ACCESSOR_KIND) {
|
|
717
|
+
if (property->value.accessor.setter == C_NULL)
|
|
718
|
+
mxTypeError("(proxy).set: true for non-configurable property with different setter");
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
if ((property->flag & XS_DONT_SET_FLAG) && (!fxIsSameValue(the, property, slot, 0)))
|
|
722
|
+
mxTypeError("(proxy).set: true for non-configurable, non-writable property with different value");
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
mxPop();
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
else
|
|
730
|
+
result = mxBehaviorSetPropertyValue(the, target->value.reference, id, index, slot, receiver);
|
|
731
|
+
mxProxyPop();
|
|
732
|
+
return result;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
txBoolean fxProxySetPrototype(txMachine* the, txSlot* instance, txSlot* prototype)
|
|
736
|
+
{
|
|
737
|
+
txBoolean result;
|
|
738
|
+
mxProxyDeclarations(_setPrototypeOf);
|
|
739
|
+
if (function) {
|
|
740
|
+
/* THIS */
|
|
741
|
+
mxPushSlot(handler);
|
|
742
|
+
/* FUNCTION */
|
|
743
|
+
mxPushSlot(function);
|
|
744
|
+
mxCall();
|
|
745
|
+
/* ARGUMENTS */
|
|
746
|
+
mxPushSlot(target);
|
|
747
|
+
mxPushSlot(prototype);
|
|
748
|
+
mxRunCount(2);
|
|
749
|
+
result = fxToBoolean(the, the->stack);
|
|
750
|
+
mxPop();
|
|
751
|
+
if (result) {
|
|
752
|
+
if (!mxBehaviorIsExtensible(the, target->value.reference)) {
|
|
753
|
+
mxPushUndefined();
|
|
754
|
+
mxBehaviorGetPrototype(the, target->value.reference, the->stack);
|
|
755
|
+
if (!fxIsSameValue(the, prototype, the->stack, 0))
|
|
756
|
+
mxTypeError("(proxy).setPrototypeOf: true for non-extensible object with different prototype");
|
|
757
|
+
mxPop();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
else
|
|
762
|
+
result = mxBehaviorSetPrototype(the, target->value.reference, prototype);
|
|
763
|
+
mxProxyPop();
|
|
764
|
+
return result;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
void fx_Proxy(txMachine* the)
|
|
768
|
+
{
|
|
769
|
+
txSlot* instance;
|
|
770
|
+
txSlot* proxy;
|
|
771
|
+
txSlot* target;
|
|
772
|
+
txSlot* handler;
|
|
773
|
+
if (mxIsUndefined(mxTarget))
|
|
774
|
+
mxTypeError("call: Proxy");
|
|
775
|
+
mxPushUndefined();
|
|
776
|
+
instance = fxNewProxyInstance(the);
|
|
777
|
+
mxPullSlot(mxResult);
|
|
778
|
+
proxy = instance->next;
|
|
779
|
+
if (!proxy || (proxy->kind != XS_PROXY_KIND))
|
|
780
|
+
mxTypeError("this is no proxy");
|
|
781
|
+
#ifdef mxHostFunctionPrimitive
|
|
782
|
+
if ((mxArgc > 0) && (mxArgv(0)->kind == XS_HOST_FUNCTION_KIND))
|
|
783
|
+
fxToInstance(the, mxArgv(0));
|
|
784
|
+
if ((mxArgc > 1) && (mxArgv(1)->kind == XS_HOST_FUNCTION_KIND))
|
|
785
|
+
fxToInstance(the, mxArgv(1));
|
|
786
|
+
#endif
|
|
787
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
788
|
+
mxTypeError("target is no object");
|
|
789
|
+
target = mxArgv(0)->value.reference;
|
|
790
|
+
if ((mxArgc < 2) || (mxArgv(1)->kind != XS_REFERENCE_KIND))
|
|
791
|
+
mxTypeError("handler is no object");
|
|
792
|
+
handler = mxArgv(1)->value.reference;
|
|
793
|
+
instance->flag |= target->flag & (XS_CAN_CALL_FLAG | XS_CAN_CONSTRUCT_FLAG);
|
|
794
|
+
proxy->value.proxy.target = target;
|
|
795
|
+
proxy->value.proxy.handler = handler;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
void fx_Proxy_revocable(txMachine* the)
|
|
799
|
+
{
|
|
800
|
+
txSlot* target;
|
|
801
|
+
txSlot* handler;
|
|
802
|
+
txSlot* property;
|
|
803
|
+
txSlot* instance;
|
|
804
|
+
txSlot* slot;
|
|
805
|
+
|
|
806
|
+
#ifdef mxHostFunctionPrimitive
|
|
807
|
+
if ((mxArgc > 0) && (mxArgv(0)->kind == XS_HOST_FUNCTION_KIND))
|
|
808
|
+
fxToInstance(the, mxArgv(0));
|
|
809
|
+
if ((mxArgc > 1) && (mxArgv(1)->kind == XS_HOST_FUNCTION_KIND))
|
|
810
|
+
fxToInstance(the, mxArgv(1));
|
|
811
|
+
#endif
|
|
812
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
813
|
+
mxTypeError("target is no object");
|
|
814
|
+
target = mxArgv(0)->value.reference;
|
|
815
|
+
if ((mxArgc < 2) || (mxArgv(1)->kind != XS_REFERENCE_KIND))
|
|
816
|
+
mxTypeError("handler is no object");
|
|
817
|
+
handler = mxArgv(1)->value.reference;
|
|
818
|
+
|
|
819
|
+
mxPush(mxObjectPrototype);
|
|
820
|
+
property = fxLastProperty(the, fxNewObjectInstance(the));
|
|
821
|
+
mxPullSlot(mxResult);
|
|
822
|
+
|
|
823
|
+
mxPushUndefined();
|
|
824
|
+
instance = fxNewProxyInstance(the);
|
|
825
|
+
instance->flag |= target->flag & (XS_CAN_CALL_FLAG | XS_CAN_CONSTRUCT_FLAG);
|
|
826
|
+
slot = instance->next;
|
|
827
|
+
slot->value.proxy.target = target;
|
|
828
|
+
slot->value.proxy.handler = handler;
|
|
829
|
+
property = fxNextSlotProperty(the, property, the->stack, mxID(_proxy), XS_GET_ONLY);
|
|
830
|
+
|
|
831
|
+
slot = fxLastProperty(the, fxNewHostFunction(the, mxCallback(fx_Proxy_revoke), 0, XS_NO_ID, XS_NO_ID));
|
|
832
|
+
slot = fxNextSlotProperty(the, slot, the->stack + 1, mxID(_proxy), XS_GET_ONLY);
|
|
833
|
+
property = fxNextSlotProperty(the, property, the->stack, mxID(_revoke), XS_GET_ONLY);
|
|
834
|
+
|
|
835
|
+
the->stack += 2;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
void fx_Proxy_revoke(txMachine* the)
|
|
839
|
+
{
|
|
840
|
+
txSlot* property = mxBehaviorGetProperty(the, mxFunction->value.reference, mxID(_proxy), 0, XS_ANY);
|
|
841
|
+
if (property && (property->kind == XS_REFERENCE_KIND)) {
|
|
842
|
+
txSlot* instance = property->value.reference;
|
|
843
|
+
txSlot* proxy = instance->next;
|
|
844
|
+
if (!proxy || (proxy->kind != XS_PROXY_KIND))
|
|
845
|
+
mxTypeError("no proxy");
|
|
846
|
+
if (proxy->flag & XS_MARK_FLAG)
|
|
847
|
+
mxTypeError("Proxy instance is read-only");
|
|
848
|
+
proxy->value.proxy.target = C_NULL;
|
|
849
|
+
proxy->value.proxy.handler = C_NULL;
|
|
850
|
+
property->kind = XS_NULL_KIND;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
void fx_Reflect_apply(txMachine* the)
|
|
855
|
+
{
|
|
856
|
+
if ((mxArgc < 1) || !(fxIsCallable(the, mxArgv(0))))
|
|
857
|
+
mxTypeError("target is no function");
|
|
858
|
+
if ((mxArgc < 3) || (mxArgv(2)->kind != XS_REFERENCE_KIND))
|
|
859
|
+
mxTypeError("argumentsList is no object");
|
|
860
|
+
mxBehaviorCall(the, fxToInstance(the, mxArgv(0)), mxArgv(1), mxArgv(2));
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
void fx_Reflect_construct(txMachine* the)
|
|
864
|
+
{
|
|
865
|
+
txSlot* target;
|
|
866
|
+
if ((mxArgc < 1) || !mxIsReference(mxArgv(0)) || !mxIsConstructor(mxArgv(0)->value.reference))
|
|
867
|
+
mxTypeError("target is no constructor");
|
|
868
|
+
if ((mxArgc < 2) || (mxArgv(1)->kind != XS_REFERENCE_KIND))
|
|
869
|
+
mxTypeError("argumentsList is no object");
|
|
870
|
+
if (mxArgc < 3)
|
|
871
|
+
target = mxArgv(0);
|
|
872
|
+
else if (!mxIsReference(mxArgv(2)) || !mxIsConstructor(mxArgv(2)->value.reference))
|
|
873
|
+
mxTypeError("newTarget is no constructor");
|
|
874
|
+
else
|
|
875
|
+
target = mxArgv(2);
|
|
876
|
+
mxBehaviorConstruct(the, fxToInstance(the, mxArgv(0)), mxArgv(1), target);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
void fx_Reflect_defineProperty(txMachine* the)
|
|
880
|
+
{
|
|
881
|
+
txSlot* at;
|
|
882
|
+
txFlag mask;
|
|
883
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
884
|
+
mxTypeError("target is no object");
|
|
885
|
+
if (mxArgc < 2)
|
|
886
|
+
mxTypeError("no key");
|
|
887
|
+
at = fxAt(the, mxArgv(1));
|
|
888
|
+
if ((mxArgc < 3) || (mxArgv(2)->kind != XS_REFERENCE_KIND))
|
|
889
|
+
mxTypeError("invalid descriptor");
|
|
890
|
+
mask = fxDescriptorToSlot(the, mxArgv(2));
|
|
891
|
+
mxResult->value.boolean = mxBehaviorDefineOwnProperty(the, mxArgv(0)->value.reference, at->value.at.id, at->value.at.index, mxArgv(2), mask);
|
|
892
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
void fx_Reflect_deleteProperty(txMachine* the)
|
|
896
|
+
{
|
|
897
|
+
txSlot* at;
|
|
898
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
899
|
+
mxTypeError("target is no object");
|
|
900
|
+
if (mxArgc < 2)
|
|
901
|
+
mxTypeError("no key");
|
|
902
|
+
at = fxAt(the, mxArgv(1));
|
|
903
|
+
mxResult->value.boolean = mxBehaviorDeleteProperty(the, mxArgv(0)->value.reference, at->value.at.id, at->value.at.index);
|
|
904
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
void fx_Reflect_get(txMachine* the)
|
|
908
|
+
{
|
|
909
|
+
txSlot* at;
|
|
910
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
911
|
+
mxTypeError("target is no object");
|
|
912
|
+
if (mxArgc < 2)
|
|
913
|
+
mxTypeError("no key");
|
|
914
|
+
at = fxAt(the, mxArgv(1));
|
|
915
|
+
mxBehaviorGetPropertyValue(the, mxArgv(0)->value.reference, at->value.at.id, at->value.at.index, mxArgc < 3 ? mxArgv(0) : mxArgv(2), mxResult);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
void fx_Reflect_getOwnPropertyDescriptor(txMachine* the)
|
|
919
|
+
{
|
|
920
|
+
txSlot* at;
|
|
921
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
922
|
+
mxTypeError("target is no object");
|
|
923
|
+
if (mxArgc < 2)
|
|
924
|
+
mxTypeError("no key");
|
|
925
|
+
at = fxAt(the, mxArgv(1));
|
|
926
|
+
mxPushUndefined();
|
|
927
|
+
if (mxBehaviorGetOwnProperty(the, mxArgv(0)->value.reference, at->value.at.id, at->value.at.index, the->stack)) {
|
|
928
|
+
fxDescribeProperty(the, the->stack, XS_GET_ONLY);
|
|
929
|
+
mxPullSlot(mxResult);
|
|
930
|
+
}
|
|
931
|
+
mxPop();
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
void fx_Reflect_getPrototypeOf(txMachine* the)
|
|
935
|
+
{
|
|
936
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
937
|
+
mxTypeError("target is no object");
|
|
938
|
+
mxBehaviorGetPrototype(the, mxArgv(0)->value.reference, mxResult);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
void fx_Reflect_has(txMachine* the)
|
|
942
|
+
{
|
|
943
|
+
txSlot* at;
|
|
944
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
945
|
+
mxTypeError("target is no object");
|
|
946
|
+
if (mxArgc < 2)
|
|
947
|
+
mxTypeError("no key");
|
|
948
|
+
at = fxAt(the, mxArgv(1));
|
|
949
|
+
mxResult->value.boolean = mxBehaviorHasProperty(the, mxArgv(0)->value.reference, at->value.at.id, at->value.at.index);
|
|
950
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
void fx_Reflect_isExtensible(txMachine* the)
|
|
954
|
+
{
|
|
955
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
956
|
+
mxTypeError("target is no object");
|
|
957
|
+
mxResult->value.boolean = mxBehaviorIsExtensible(the, mxArgv(0)->value.reference);
|
|
958
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
void fx_Reflect_ownKeys(txMachine* the)
|
|
962
|
+
{
|
|
963
|
+
txSlot* result;
|
|
964
|
+
txSlot* array;
|
|
965
|
+
txSlot* item;
|
|
966
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
967
|
+
mxTypeError("target is no object");
|
|
968
|
+
mxPush(mxArrayPrototype);
|
|
969
|
+
result = fxNewArrayInstance(the);
|
|
970
|
+
mxPullSlot(mxResult);
|
|
971
|
+
array = result->next;
|
|
972
|
+
mxBehaviorOwnKeys(the, mxArgv(0)->value.reference, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, array);
|
|
973
|
+
item = array;
|
|
974
|
+
while ((item = item->next)) {
|
|
975
|
+
array->value.array.length++;
|
|
976
|
+
fxKeyAt(the, item->value.at.id, item->value.at.index, item);
|
|
977
|
+
}
|
|
978
|
+
fxCacheArray(the, result);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
void fx_Reflect_preventExtensions(txMachine* the)
|
|
982
|
+
{
|
|
983
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
984
|
+
mxTypeError("target is no object");
|
|
985
|
+
mxResult->value.boolean = mxBehaviorPreventExtensions(the, mxArgv(0)->value.reference);
|
|
986
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
void fx_Reflect_set(txMachine* the)
|
|
990
|
+
{
|
|
991
|
+
txSlot* at;
|
|
992
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
993
|
+
mxTypeError("target is no object");
|
|
994
|
+
if (mxArgc < 2)
|
|
995
|
+
mxTypeError("no key");
|
|
996
|
+
at = fxAt(the, mxArgv(1));
|
|
997
|
+
if (mxArgc < 3)
|
|
998
|
+
mxPushUndefined();
|
|
999
|
+
else
|
|
1000
|
+
mxPushSlot(mxArgv(2));
|
|
1001
|
+
mxResult->value.boolean = mxBehaviorSetPropertyValue(the, mxArgv(0)->value.reference, at->value.at.id, at->value.at.index, the->stack, mxArgc < 4 ? mxArgv(0) : mxArgv(3));
|
|
1002
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
1003
|
+
mxPop();
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
void fx_Reflect_setPrototypeOf(txMachine* the)
|
|
1007
|
+
{
|
|
1008
|
+
if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
|
|
1009
|
+
mxTypeError("target is no object");
|
|
1010
|
+
if ((mxArgc < 2) || ((mxArgv(1)->kind != XS_NULL_KIND) && (mxArgv(1)->kind != XS_REFERENCE_KIND)))
|
|
1011
|
+
mxTypeError("invalid prototype");
|
|
1012
|
+
mxResult->value.boolean = mxBehaviorSetPrototype(the, mxArgv(0)->value.reference, mxArgv(1));
|
|
1013
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
1014
|
+
}
|