Coverage Report

Created: 2026-03-30 06:33

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