Coverage Report

Created: 2025-11-24 06:44

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