Coverage Report

Created: 2025-10-10 06:16

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