Coverage Report

Created: 2025-11-24 06:36

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