Coverage Report

Created: 2026-10-17 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/moddable/xs/sources/xsObject.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
void fxBuildObject(txMachine* the)
41
6.51k
{
42
6.51k
  txSlot* slot;
43
6.51k
  fxNewHostFunction(the, mxCallback(fx_Object_assign), 2, XS_NO_ID, XS_NO_ID);
44
6.51k
  mxAssignObjectFunction = *the->stack;
45
6.51k
  mxPop();
46
6.51k
  fxNewHostFunction(the, mxCallback(fx_Object_copy), 2, XS_NO_ID, XS_NO_ID);
47
6.51k
  mxCopyObjectFunction = *the->stack;
48
6.51k
  mxPop();
49
6.51k
  fxNewHostFunction(the, mxCallback(fxOrdinaryToPrimitive), 2, XS_NO_ID, XS_NO_ID);
50
6.51k
  mxOrdinaryToPrimitiveFunction = *the->stack;
51
6.51k
  mxPop();
52
  
53
6.51k
  mxPush(mxObjectPrototype);
54
6.51k
  slot = fxLastProperty(the, the->stack->value.reference);
55
6.51k
  slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_Object_prototype___proto__get), mxCallback(fx_Object_prototype___proto__set), mxID(___proto__), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
56
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype_hasOwnProperty), 1, mxID(_hasOwnProperty), XS_DONT_ENUM_FLAG);
57
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype___defineGetter__), 2, mxID(___defineGetter__), XS_DONT_ENUM_FLAG);
58
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype___defineSetter__), 2, mxID(___defineSetter__), XS_DONT_ENUM_FLAG);
59
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype___lookupGetter__), 1, mxID(___lookupGetter__), XS_DONT_ENUM_FLAG);
60
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype___lookupSetter__), 1, mxID(___lookupSetter__), XS_DONT_ENUM_FLAG);
61
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype_isPrototypeOf), 1, mxID(_isPrototypeOf), XS_DONT_ENUM_FLAG);
62
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype_propertyIsEnumerable), 1, mxID(_propertyIsEnumerable), XS_DONT_ENUM_FLAG);
63
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype_toLocaleString), 0, mxID(_toLocaleString), XS_DONT_ENUM_FLAG);
64
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype_toString), 0, mxID(_toString), XS_DONT_ENUM_FLAG);
65
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_prototype_valueOf), 0, mxID(_valueOf), XS_DONT_ENUM_FLAG);
66
6.51k
  slot = fxBuildHostConstructor(the, mxCallback(fx_Object), 1, mxID(_Object));
67
6.51k
  mxObjectConstructor = *the->stack;
68
6.51k
  slot = fxLastProperty(the, slot);
69
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_assign), 2, mxID(_assign), XS_DONT_ENUM_FLAG);
70
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_create), 2, mxID(_create), XS_DONT_ENUM_FLAG);
71
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_defineProperties), 2, mxID(_defineProperties), XS_DONT_ENUM_FLAG);
72
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_defineProperty), 3, mxID(_defineProperty), XS_DONT_ENUM_FLAG);
73
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_entries), 1, mxID(_entries), XS_DONT_ENUM_FLAG);
74
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_freeze), 1, mxID(_freeze), XS_DONT_ENUM_FLAG);
75
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_fromEntries), 1, mxID(_fromEntries), XS_DONT_ENUM_FLAG);
76
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_getOwnPropertyDescriptor), 2, mxID(_getOwnPropertyDescriptor), XS_DONT_ENUM_FLAG);
77
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_getOwnPropertyDescriptors), 1, mxID(_getOwnPropertyDescriptors), XS_DONT_ENUM_FLAG);
78
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_getOwnPropertyNames), 1, mxID(_getOwnPropertyNames), XS_DONT_ENUM_FLAG);
79
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_getOwnPropertySymbols), 1, mxID(_getOwnPropertySymbols), XS_DONT_ENUM_FLAG);
80
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_getPrototypeOf), 1, mxID(_getPrototypeOf), XS_DONT_ENUM_FLAG);
81
6.51k
#if mxECMAScript2024
82
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_groupBy), 2, mxID(_groupBy), XS_DONT_ENUM_FLAG);
83
6.51k
#endif
84
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_hasOwn), 2, mxID(_hasOwn), XS_DONT_ENUM_FLAG);
85
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_is), 2, mxID(_is), XS_DONT_ENUM_FLAG);
86
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_isExtensible), 1, mxID(_isExtensible), XS_DONT_ENUM_FLAG);
87
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_isFrozen), 1, mxID(_isFrozen), XS_DONT_ENUM_FLAG);
88
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_isSealed), 1, mxID(_isSealed), XS_DONT_ENUM_FLAG);
89
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_keys), 1, mxID(_keys), XS_DONT_ENUM_FLAG);
90
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_preventExtensions), 1, mxID(_preventExtensions), XS_DONT_ENUM_FLAG);
91
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_seal), 1, mxID(_seal), XS_DONT_ENUM_FLAG);
92
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_setPrototypeOf), 2, mxID(_setPrototypeOf), XS_DONT_ENUM_FLAG);
93
6.51k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Object_values), 1, mxID(_values), XS_DONT_ENUM_FLAG);
94
6.51k
  mxPop();
95
6.51k
}
96
97
98
txSlot* fxNewObjectInstance(txMachine* the)
99
9.17M
{
100
9.17M
  txSlot* instance;
101
9.17M
  instance = fxNewSlot(the);
102
9.17M
  instance->kind = XS_INSTANCE_KIND;
103
9.17M
  instance->value.instance.garbage = C_NULL;
104
9.17M
  instance->value.instance.prototype = the->stack->value.reference;
105
9.17M
  the->stack->value.reference = instance;
106
9.17M
  the->stack->kind = XS_REFERENCE_KIND;
107
9.17M
  return instance;
108
9.17M
}
109
110
void fx_Object(txMachine* the)
111
0
{
112
0
  if (mxHasTarget && !fxIsSameSlot(the, mxTarget, mxFunction)) {
113
0
    mxPushSlot(mxTarget);
114
0
    fxGetPrototypeFromConstructor(the, &mxObjectPrototype);
115
0
    fxNewObjectInstance(the);
116
0
    mxPullSlot(mxResult);
117
0
    return;
118
0
  }
119
0
  if ((mxArgc == 0) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND)) {
120
0
    mxPush(mxObjectPrototype);
121
0
    fxNewObjectInstance(the);
122
0
    mxPullSlot(mxResult);
123
0
    return;
124
0
  }
125
0
  *mxResult = *mxArgv(0);
126
0
  fxToInstance(the, mxResult);
127
0
}
128
129
void fx_Object_prototype___proto__get(txMachine* the)
130
0
{
131
0
  if ((mxThis->kind == XS_UNDEFINED_KIND) || (mxThis->kind == XS_NULL_KIND))
132
0
    mxTypeError("invalid this");
133
0
  mxBehaviorGetPrototype(the, fxToInstance(the, mxThis), mxResult);
134
0
}
135
136
void fx_Object_prototype___proto__set(txMachine* the)
137
0
{
138
0
  txSlot* instance;
139
0
  if ((mxThis->kind == XS_UNDEFINED_KIND) || (mxThis->kind == XS_NULL_KIND))
140
0
    mxTypeError("invalid this");
141
0
  if ((mxArgc < 1) || ((mxArgv(0)->kind != XS_NULL_KIND) && (mxArgv(0)->kind != XS_REFERENCE_KIND)))
142
0
    return;
143
0
  if (mxThis->kind == XS_REFERENCE_KIND) {
144
0
    instance = mxThis->value.reference;
145
0
    if (!mxBehaviorSetPrototype(the, instance, mxArgv(0)))
146
0
      mxTypeError("invalid prototype");
147
0
  }
148
0
}
149
150
void fx_Object_prototype___defineGetter__(txMachine* the)
151
0
{
152
0
  txSlot* instance = fxToInstance(the, mxThis);
153
0
  txSlot* at;
154
0
  txSlot* slot;
155
0
  if ((mxArgc < 2) || (!fxIsCallable(the, mxArgv(1))))
156
0
    mxTypeError("invalid getter");
157
0
  at = fxAt(the, mxArgv(0));
158
0
  mxPushUndefined();
159
0
  slot = the->stack;
160
0
  slot->value.accessor.getter = fxToInstance(the, mxArgv(1));
161
0
  slot->value.accessor.setter = C_NULL;
162
0
  slot->kind = XS_ACCESSOR_KIND;
163
0
  slot->flag = XS_NO_FLAG;
164
0
  if(!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, slot, XS_GETTER_FLAG | XS_DONT_DELETE_FLAG| XS_DONT_ENUM_FLAG))
165
0
    mxTypeError("invalid descriptor");
166
0
  mxPop();
167
0
}
168
169
void fx_Object_prototype___defineSetter__(txMachine* the)
170
0
{
171
0
  txSlot* instance = fxToInstance(the, mxThis);
172
0
  txSlot* at;
173
0
  txSlot* slot;
174
0
  if ((mxArgc < 2) || (!fxIsCallable(the, mxArgv(1))))
175
0
    mxTypeError("invalid setter");
176
0
  at = fxAt(the, mxArgv(0));
177
0
  mxPushUndefined();
178
0
  slot = the->stack;
179
0
  slot->value.accessor.getter = C_NULL;
180
0
  slot->value.accessor.setter = fxToInstance(the, mxArgv(1));
181
0
  slot->kind = XS_ACCESSOR_KIND;
182
0
  slot->flag = XS_NO_FLAG;
183
0
  if(!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, slot, XS_SETTER_FLAG | XS_DONT_DELETE_FLAG| XS_DONT_ENUM_FLAG))
184
0
    mxTypeError("invalid descriptor");
185
0
  mxPop();
186
0
}
187
188
void fx_Object_prototype___lookupGetter__(txMachine* the)
189
0
{
190
0
  txSlot* instance = fxToInstance(the, mxThis);
191
0
  txSlot* at;
192
0
  txSlot* slot;
193
0
  if (mxArgc < 1)
194
0
    mxPushUndefined();
195
0
  else
196
0
    mxPushSlot(mxArgv(0));
197
0
  at = fxAt(the, the->stack);
198
0
  mxPushUndefined();
199
0
  slot = the->stack;
200
0
again:
201
0
  if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, slot)) {
202
0
    if (slot->kind == XS_ACCESSOR_KIND) {
203
0
      if (slot->value.accessor.getter) {
204
0
        mxResult->kind = XS_REFERENCE_KIND;
205
0
        mxResult->value.reference = slot->value.accessor.getter;
206
0
      }
207
0
    }
208
0
    mxPop();
209
0
    return;
210
0
  }
211
0
  if (mxBehaviorGetPrototype(the, instance, slot)) {
212
0
    instance = slot->value.reference;
213
0
    goto again;
214
0
  }
215
0
  mxPop();
216
0
  mxPop();
217
0
}
218
219
void fx_Object_prototype___lookupSetter__(txMachine* the)
220
0
{
221
0
  txSlot* instance = fxToInstance(the, mxThis);
222
0
  txSlot* at;
223
0
  txSlot* slot;
224
0
  if (mxArgc < 1)
225
0
    mxPushUndefined();
226
0
  else
227
0
    mxPushSlot(mxArgv(0));
228
0
  at = fxAt(the, the->stack);
229
0
  mxPushUndefined();
230
0
  slot = the->stack;
231
0
again:
232
0
  if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, slot)) {
233
0
    if (slot->kind == XS_ACCESSOR_KIND) {
234
0
      if (slot->value.accessor.setter) {
235
0
        mxResult->kind = XS_REFERENCE_KIND;
236
0
        mxResult->value.reference = slot->value.accessor.setter;
237
0
      }
238
0
    }
239
0
    mxPop();
240
0
    return;
241
0
  }
242
0
  if (mxBehaviorGetPrototype(the, instance, slot)) {
243
0
    instance = slot->value.reference;
244
0
    goto again;
245
0
  }
246
0
  mxPop();
247
0
  mxPop();
248
0
}
249
250
void fx_Object_prototype_hasOwnProperty(txMachine* the)
251
0
{
252
0
  txSlot* at;
253
0
  txSlot* instance;
254
0
  if (mxArgc < 1)
255
0
    mxPushUndefined();
256
0
  else
257
0
    mxPushSlot(mxArgv(0));
258
0
  at = fxAt(the, the->stack);
259
0
  instance = fxToInstance(the, mxThis);
260
0
  mxPushUndefined();
261
0
  mxResult->value.boolean = mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack);
262
0
  mxResult->kind = XS_BOOLEAN_KIND;
263
0
  mxPop();
264
0
  mxPop();
265
0
}
266
267
void fx_Object_prototype_isPrototypeOf(txMachine* the)
268
0
{
269
0
  mxResult->kind = XS_BOOLEAN_KIND;
270
0
  mxResult->value.boolean = 0;
271
0
  if (mxArgc > 0) {
272
0
    txSlot* slot = mxArgv(0);
273
0
    if (slot->kind == XS_REFERENCE_KIND) {
274
0
      txSlot* prototype = fxToInstance(the, mxThis);
275
0
      while (mxBehaviorGetPrototype(the, slot->value.reference, slot)) {
276
0
        if (prototype == slot->value.reference) {
277
0
          mxResult->value.boolean = 1;
278
0
          break;
279
0
        }
280
0
      }
281
0
    }
282
0
  }
283
0
}
284
285
void fx_Object_prototype_propertyIsEnumerable(txMachine* the)
286
0
{
287
0
  txSlot* at;
288
0
  txSlot* instance;
289
0
  if (mxArgc < 1)
290
0
    mxPushUndefined();
291
0
  else
292
0
    mxPushSlot(mxArgv(0));
293
0
  at = fxAt(the, the->stack);
294
0
  instance = fxToInstance(the, mxThis);
295
0
  mxPushUndefined();
296
0
  mxResult->value.boolean = mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack) && ((the->stack->flag & XS_DONT_ENUM_FLAG) == 0);
297
0
  mxResult->kind = XS_BOOLEAN_KIND;
298
0
  mxPop();
299
0
  mxPop();
300
0
}
301
302
void fx_Object_prototype_toLocaleString(txMachine* the)
303
0
{
304
0
  mxPushSlot(mxThis);
305
0
  mxDub();
306
0
  mxGetID(mxID(_toString));
307
0
  mxCall();
308
0
  mxRunCount(0);
309
0
  mxPullSlot(mxResult);
310
0
}
311
312
void fx_Object_prototype_toString(txMachine* the)
313
0
{
314
0
  txString tag = C_NULL;
315
0
  txSlot* instance = C_NULL;
316
0
  txSlot* slot;
317
0
  switch (mxThis->kind) {
318
0
  case XS_UNDEFINED_KIND:
319
0
    tag = "Undefined";
320
0
    break;
321
0
  case XS_NULL_KIND:
322
0
    tag = "Null";
323
0
    break;
324
0
  case XS_BOOLEAN_KIND:
325
0
    instance = mxBooleanPrototype.value.reference;
326
0
    tag = "Boolean";
327
0
    break;
328
0
  case XS_INTEGER_KIND:
329
0
  case XS_NUMBER_KIND:
330
0
    instance = mxNumberPrototype.value.reference;
331
0
    tag = "Number";
332
0
    break;
333
0
  case XS_STRING_KIND:
334
0
  case XS_STRING_X_KIND:
335
0
    instance = mxStringPrototype.value.reference;
336
0
    tag = "String";
337
0
    break;
338
0
  case XS_SYMBOL_KIND:
339
0
    instance = mxSymbolPrototype.value.reference;
340
0
    tag = "Object";
341
0
    break;
342
0
  case XS_BIGINT_KIND:
343
0
  case XS_BIGINT_X_KIND:
344
0
    instance = mxBigIntPrototype.value.reference;
345
0
    tag = "Object";
346
0
    break;
347
0
  case XS_REFERENCE_KIND:
348
0
    instance = mxThis->value.reference;
349
0
    if (fxIsArray(the, instance))
350
0
      tag = "Array";
351
0
    else {
352
0
      slot = instance->next;
353
0
      if (slot) {
354
0
        if ((slot->ID == XS_ARGUMENTS_SLOPPY_BEHAVIOR) || (slot->ID == XS_ARGUMENTS_STRICT_BEHAVIOR))
355
0
          tag = "Arguments";
356
0
        else if (slot->flag & XS_INTERNAL_FLAG) {
357
0
          switch (slot->kind) {
358
0
          case XS_BOOLEAN_KIND:
359
0
            tag = "Boolean";
360
0
            break;
361
0
          case XS_CALLBACK_KIND:
362
0
          case XS_CALLBACK_X_KIND:
363
0
          case XS_CODE_KIND:
364
0
          case XS_CODE_X_KIND:
365
0
            tag = "Function";
366
0
            break;
367
0
          case XS_DATE_KIND:
368
0
            tag = "Date";
369
0
            break;
370
0
          case XS_ERROR_KIND:
371
0
            tag = "Error";
372
0
            break;
373
0
          case XS_GLOBAL_KIND:
374
0
            tag = "global";
375
0
            break;
376
0
          case XS_NUMBER_KIND:
377
0
            tag = "Number";
378
0
            break;
379
0
          case XS_REGEXP_KIND:
380
0
            tag = "RegExp";
381
0
            break;
382
0
          case XS_STRING_KIND:
383
0
          case XS_STRING_X_KIND:
384
0
            tag = "String";
385
0
            break;
386
0
          case XS_BIGINT_KIND:
387
0
          case XS_BIGINT_X_KIND:
388
0
            tag = "Object";
389
0
            break;
390
0
          case XS_PROXY_KIND:
391
0
            if (instance->flag & XS_CAN_CALL_FLAG)
392
0
              tag = "Function";
393
0
            else
394
0
              tag = "Object";
395
0
            break;
396
0
          default:
397
0
            tag = "Object";
398
0
            break;
399
0
          }
400
0
        }
401
0
        else
402
0
                tag = "Object";
403
0
      }
404
0
      else
405
0
              tag = "Object";
406
0
    }
407
0
    break;
408
#if mxHostFunctionPrimitive
409
  case XS_HOST_FUNCTION_KIND:
410
    instance = mxFunctionPrototype.value.reference;
411
    tag = "Function";
412
    break;
413
#endif
414
0
  default:
415
0
    tag = "Object";
416
0
    break;
417
0
  }
418
0
  fxStringX(the, mxResult, "[object ");
419
0
  if (instance) {
420
0
    mxPushReference(instance);
421
0
    mxGetID(mxID(_Symbol_toStringTag));
422
0
    if ((the->stack->kind == XS_STRING_KIND) || (the->stack->kind == XS_STRING_X_KIND))
423
0
      fxConcatString(the, mxResult, the->stack);
424
0
    else
425
0
      fxConcatStringC(the, mxResult, tag);
426
0
  }
427
0
  else
428
0
    fxConcatStringC(the, mxResult, tag);
429
0
  fxConcatStringC(the, mxResult, "]");
430
0
}
431
432
void fx_Object_prototype_valueOf(txMachine* the)
433
0
{
434
0
  fxToInstance(the, mxThis);
435
0
  *mxResult = *mxThis;
436
0
}
437
438
void fx_Object_assign(txMachine* the)
439
0
{
440
0
  txSlot* target;
441
0
  txInteger c, i;
442
0
  txSlot* instance;
443
0
  txSlot* at;
444
0
  txSlot* property;
445
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
446
0
    mxTypeError("invalid target");
447
0
  fxToInstance(the, mxArgv(0));
448
0
  target = mxArgv(0);
449
0
  c = mxArgc;
450
0
  for (i = 1; i < c; i++) {
451
0
    if ((mxArgv(i)->kind == XS_UNDEFINED_KIND) || (mxArgv(i)->kind == XS_NULL_KIND))
452
0
      continue;
453
0
    instance = fxToInstance(the, mxArgv(i));
454
0
    at = fxNewInstance(the);
455
0
    mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
456
0
    mxPushUndefined();
457
0
    property = the->stack;
458
0
    while ((at = at->next)) {
459
0
      if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
460
0
        mxPushReference(instance);
461
0
        mxGetAll(at->value.at.id, at->value.at.index);
462
0
        mxPushSlot(target);
463
0
        mxSetAll(at->value.at.id, at->value.at.index);
464
0
        mxPop();
465
0
      }
466
0
    }
467
0
    mxPop();
468
0
    mxPop();
469
0
  }
470
0
  *mxResult = *target;
471
0
}
472
473
void fx_Object_copy(txMachine* the)
474
0
{
475
0
  txInteger c = mxArgc, i;
476
0
  txSlot* target;
477
0
  txSlot* source;
478
0
  txSlot* at;
479
0
  txSlot* property;
480
0
  if ((c < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
481
0
    mxTypeError("invalid object");
482
0
  target = fxToInstance(the, mxArgv(0));
483
0
  *mxResult = *mxArgv(0);
484
0
  if ((c < 2) || (mxArgv(1)->kind == XS_UNDEFINED_KIND) || (mxArgv(1)->kind == XS_NULL_KIND))
485
0
    return;
486
0
  source = fxToInstance(the, mxArgv(1));
487
0
  at = fxNewInstance(the);
488
0
  mxBehaviorOwnKeys(the, source, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
489
0
  mxPushUndefined();
490
0
  property = the->stack;
491
0
  while ((at = at->next)) {
492
0
    for (i = 2; i < c; i++) {
493
0
      txSlot* exclude = mxArgv(i);
494
0
      if ((exclude->value.at.id == at->value.at.id) && (exclude->value.at.index == at->value.at.index))
495
0
        break;
496
0
    }
497
0
    if (i == c) {
498
0
      if (mxBehaviorGetOwnProperty(the, source, at->value.at.id, at->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
499
0
        mxPushReference(source);
500
0
        mxGetAll(at->value.at.id, at->value.at.index);
501
0
        the->stack->flag = 0;
502
0
        mxBehaviorDefineOwnProperty(the, target, at->value.at.id, at->value.at.index, the->stack, XS_GET_ONLY);
503
0
        mxPop();
504
0
      }
505
0
    }
506
0
    mxCheckMetering();
507
0
  }
508
0
  mxPop(); // property
509
0
  mxPop(); // at
510
0
}
511
512
void fx_Object_create(txMachine* the)
513
0
{
514
0
  txSlot* instance;
515
0
  txSlot* properties;
516
0
  txSlot* at;
517
0
  txSlot* property;
518
0
  txFlag mask;
519
0
  if ((mxArgc < 1) || ((mxArgv(0)->kind != XS_NULL_KIND) && (mxArgv(0)->kind != XS_REFERENCE_KIND)))
520
0
    mxTypeError("invalid prototype");
521
0
  if (mxArgv(0)->kind == XS_NULL_KIND)
522
0
    fxNewInstance(the);
523
0
  else {
524
0
    mxPushSlot(mxArgv(0));
525
0
    fxNewHostInstance(the);
526
0
  }
527
0
  mxPullSlot(mxResult);
528
0
  instance = fxGetInstance(the, mxResult);
529
0
  if ((mxArgc > 1) && (mxArgv(1)->kind != XS_UNDEFINED_KIND)) {
530
0
    properties = fxToInstance(the, mxArgv(1));
531
0
    at = fxNewInstance(the);
532
0
    mxBehaviorOwnKeys(the, properties, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
533
0
    mxPushUndefined();
534
0
    property = the->stack;
535
0
    while ((at = at->next)) {
536
0
      if (mxBehaviorGetOwnProperty(the, properties, at->value.at.id, at->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
537
0
        mxPushReference(properties);
538
0
        mxGetAll(at->value.at.id, at->value.at.index);
539
0
        mask = fxDescriptorToSlot(the, the->stack);
540
0
        if (!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack, mask))
541
0
          mxTypeError("invalid descriptor");
542
0
        mxPop();
543
0
      }
544
0
    }
545
0
    mxPop();
546
0
    mxPop();
547
0
  }
548
0
}
549
550
void fx_Object_defineProperties(txMachine* the)
551
0
{
552
0
  txSlot* instance;
553
0
  txSlot* properties;
554
0
  txSlot* keys;
555
0
  txSlot* former;
556
0
  txSlot* at;
557
0
  txSlot* property;
558
0
  txSlot* value;
559
0
  if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
560
0
    mxTypeError("invalid object");
561
0
  if ((mxArgc < 2) || (mxArgv(1)->kind == XS_UNDEFINED_KIND))
562
0
    mxTypeError("invalid properties");
563
0
  instance = fxGetInstance(the, mxArgv(0));
564
0
  properties = fxToInstance(the, mxArgv(1));
565
0
  keys = fxNewInstance(the);
566
0
  mxBehaviorOwnKeys(the, properties, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, keys);
567
0
  mxPushUndefined();
568
0
  property = the->stack;
569
0
  former = keys;
570
0
  while ((at = former->next)) {
571
0
    if (mxBehaviorGetOwnProperty(the, properties, at->value.at.id, at->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
572
0
      mxPushReference(properties);
573
0
      mxGetAll(at->value.at.id, at->value.at.index);
574
0
      at->flag = fxDescriptorToSlot(the, the->stack);
575
0
      former = at;
576
0
    }
577
0
    else
578
0
      former->next = at->next;
579
0
  }
580
0
  at = keys;
581
0
  value = property;
582
0
  while ((at = at->next)) {
583
0
    --value;
584
0
    if (!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, value, at->flag))
585
0
      mxTypeError("invalid descriptor");
586
0
  }
587
0
  the->stack = property;
588
0
  mxPop();
589
0
  mxPop();
590
0
  *mxResult = *mxArgv(0);
591
0
}
592
593
void fx_Object_defineProperty(txMachine* the)
594
0
{
595
0
  txSlot* at;
596
0
  txFlag mask;
597
0
  if ((mxArgc < 1) || (mxArgv(0)->kind != XS_REFERENCE_KIND))
598
0
    mxTypeError("invalid object");
599
0
  if (mxArgc < 2)
600
0
    mxTypeError("invalid key");
601
0
  at = fxAt(the, mxArgv(1));
602
0
  if ((mxArgc < 3) || (mxArgv(2)->kind != XS_REFERENCE_KIND))
603
0
    mxTypeError("invalid descriptor");
604
0
  mask = fxDescriptorToSlot(the, mxArgv(2));
605
0
  if (!mxBehaviorDefineOwnProperty(the, mxArgv(0)->value.reference, at->value.at.id, at->value.at.index, mxArgv(2), mask))
606
0
    mxTypeError("invalid descriptor");
607
0
  *mxResult = *mxArgv(0);
608
0
}
609
610
void fx_Object_entries(txMachine* the)
611
0
{
612
0
  txSlot* instance;
613
0
  txSlot* result;
614
0
  txSlot* array;
615
0
  txSlot* property;
616
0
  txSlot** address;
617
0
  txSlot* item;
618
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
619
0
    mxTypeError("invalid object");
620
0
  instance = fxToInstance(the, mxArgv(0));
621
0
  mxPush(mxArrayPrototype);
622
0
  result = fxNewArrayInstance(the);
623
0
  mxPullSlot(mxResult);
624
0
  array = result->next;
625
0
  mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG, array);
626
0
  mxPushUndefined();
627
0
  property = the->stack;
628
0
  address = &array->next;
629
0
  while ((item = *address)) {
630
0
    if (mxBehaviorGetOwnProperty(the, instance, item->value.at.id, item->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
631
0
      array->value.array.length++;
632
0
      mxPushUndefined();
633
0
      fxKeyAt(the, item->value.at.id, item->value.at.index, the->stack);
634
0
      mxPushReference(instance);
635
0
      mxGetAll(item->value.at.id, item->value.at.index);
636
0
      fxConstructArrayEntry(the, item);
637
0
      address = &(item->next);
638
0
    }
639
0
    else
640
0
      *address = item->next;
641
0
  }
642
0
  mxPop();
643
0
  fxCacheArray(the, result);
644
0
}
645
646
void fx_Object_freeze(txMachine* the)
647
0
{
648
0
  if (mxArgc > 0) {
649
0
    txSlot* slot = mxArgv(0);
650
0
    if (slot->kind == XS_REFERENCE_KIND) {
651
0
      txSlot* instance = slot->value.reference;
652
0
      txBoolean deep = 0;
653
0
      txSlot* at;
654
0
      txSlot* property;
655
0
      if (!mxBehaviorPreventExtensions(the, instance))
656
0
        mxTypeError("extensible object");
657
0
      if ((mxArgc > 1) && fxToBoolean(the, mxArgv(1)))
658
0
        deep = 1;
659
0
      at = fxNewInstance(the);
660
0
      mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
661
0
      mxPushUndefined();
662
0
      property = the->stack;
663
0
      while ((at = at->next)) {
664
0
        if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, property)) {
665
0
          txFlag mask = XS_DONT_DELETE_FLAG;
666
0
          property->flag |= XS_DONT_DELETE_FLAG;
667
0
          if (property->kind != XS_ACCESSOR_KIND) {
668
0
            mask |= XS_DONT_SET_FLAG;
669
0
            property->flag |= XS_DONT_SET_FLAG;
670
0
          }
671
0
          property->kind = XS_UNINITIALIZED_KIND;
672
0
          if (!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, property, mask)) {
673
0
            if (!deep)
674
0
              mxTypeError("cannot configure property");
675
0
          }
676
0
        }
677
0
      }
678
0
      mxPop();
679
0
      if (deep) {
680
0
        at = the->stack->value.reference;
681
0
        mxPushUndefined();
682
0
        property = the->stack;
683
0
        while ((at = at->next)) {
684
0
          if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, property)) {
685
0
            if (property->kind == XS_REFERENCE_KIND) {
686
0
              mxPushSlot(mxThis);
687
0
              mxDub();
688
0
              mxGetID(mxID(_isFrozen));
689
0
              mxCall();
690
0
              mxPushSlot(property);
691
0
              mxRunCount(1);
692
0
              if (!fxRunTest(the)) {
693
0
                mxPushSlot(mxThis);
694
0
                mxPushSlot(mxFunction);
695
0
                mxCall();
696
0
                mxPushSlot(property);
697
0
                mxPushBoolean(1);
698
0
                mxRunCount(2);
699
0
                mxPop();
700
0
              }
701
0
            }
702
0
            else if (property->kind == XS_ACCESSOR_KIND) {
703
0
              if (property->value.accessor.getter) {
704
0
                mxPushSlot(mxThis);
705
0
                mxDub();
706
0
                mxGetID(mxID(_isFrozen));
707
0
                mxCall();
708
0
                mxPushReference(property->value.accessor.getter);
709
0
                mxRunCount(1);
710
0
                if (!fxRunTest(the)) {
711
0
                  mxPushSlot(mxThis);
712
0
                  mxPushSlot(mxFunction);
713
0
                  mxCall();
714
0
                  mxPushReference(property->value.accessor.getter);
715
0
                  mxPushBoolean(1);
716
0
                  mxRunCount(2);
717
0
                  mxPop();
718
0
                }
719
0
              }
720
0
              if (property->value.accessor.setter) {
721
0
                mxPushSlot(mxThis);
722
0
                mxDub();
723
0
                mxGetID(mxID(_isFrozen));
724
0
                mxCall();
725
0
                mxPushReference(property->value.accessor.setter);
726
0
                mxRunCount(1);
727
0
                if (!fxRunTest(the)) {
728
0
                  mxPushSlot(mxThis);
729
0
                  mxPushSlot(mxFunction);
730
0
                  mxCall();
731
0
                  mxPushReference(property->value.accessor.setter);
732
0
                  mxPushBoolean(1);
733
0
                  mxRunCount(2);
734
0
                  mxPop();
735
0
                }
736
0
              }
737
0
            }
738
0
          }
739
0
        }
740
0
        mxPop();
741
0
      }
742
0
      mxPop();
743
0
    }
744
0
    *mxResult = *mxArgv(0);
745
0
  }
746
0
}
747
748
void fx_Object_fromEntries(txMachine* the)
749
0
{
750
0
  txSlot *instance, *iterator, *next, *value, *at;
751
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
752
0
    mxTypeError("invalid iterable");
753
0
  mxPush(mxObjectPrototype);
754
0
  instance = fxNewObjectInstance(the);
755
0
  mxPullSlot(mxResult);
756
0
  mxTemporary(iterator);
757
0
  mxTemporary(next);
758
0
  fxGetIterator(the, mxArgv(0), iterator, next, 0);  
759
0
  mxTemporary(value);
760
0
  while (fxIteratorNext(the, iterator, next, value)) {
761
0
    mxTry(the) {
762
0
      if (value->kind != XS_REFERENCE_KIND)
763
0
        mxTypeError("item: not an object");
764
0
      mxPushSlot(value);
765
0
      mxGetIndex(0);
766
0
      mxPushSlot(value);
767
0
      mxGetIndex(1);
768
0
      at = fxAt(the, the->stack + 1);
769
0
      mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack, XS_GET_ONLY);
770
0
      mxPop();
771
0
      mxPop();
772
0
    }
773
0
    mxCatch(the) {
774
0
      fxIteratorReturn(the, iterator, 1);
775
0
      fxJump(the);
776
0
    }
777
0
  }
778
0
  mxPop();
779
0
}
780
781
void fx_Object_getOwnPropertyDescriptor(txMachine* the)
782
0
{
783
0
  txSlot* instance;
784
0
  txSlot* at;
785
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
786
0
    mxTypeError("invalid object");
787
0
  instance = fxToInstance(the, mxArgv(0));
788
0
  if (mxArgc < 2)
789
0
    mxPushUndefined();
790
0
  else
791
0
    mxPushSlot(mxArgv(1));
792
0
  at = fxAt(the, the->stack);
793
0
  mxPushUndefined();
794
0
  if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack)) {
795
0
    fxDescribeProperty(the, the->stack, XS_GET_ONLY);
796
0
    mxPullSlot(mxResult);
797
0
  }
798
0
  mxPop();
799
0
  mxPop();
800
0
}
801
802
void fx_Object_getOwnPropertyDescriptors(txMachine* the)
803
0
{
804
0
  txSlot* instance;
805
0
  txSlot* result;
806
0
  txSlot* at;
807
0
  txSlot* property;
808
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
809
0
    mxTypeError("invalid object");
810
0
  instance = fxToInstance(the, mxArgv(0));
811
0
  mxPush(mxObjectPrototype);
812
0
  result = fxNewObjectInstance(the);
813
0
  mxPullSlot(mxResult);
814
0
  at = fxNewInstance(the);
815
0
  mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
816
0
  mxPushUndefined();
817
0
  property = the->stack;
818
0
  while ((at = at->next)) {
819
0
    if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, property)) {
820
0
      fxDescribeProperty(the, property, XS_GET_ONLY);
821
0
      mxBehaviorDefineOwnProperty(the, result, at->value.at.id, at->value.at.index, the->stack, XS_GET_ONLY);
822
0
      mxPop();
823
0
    }
824
0
  }
825
0
  mxPop();
826
0
}
827
828
void fx_Object_getOwnPropertyNames(txMachine* the)
829
0
{
830
0
  txSlot* instance;
831
0
  txSlot* result;
832
0
  txSlot* array;
833
0
  txSlot* item;
834
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
835
0
    mxTypeError("invalid object");
836
0
  instance = fxToInstance(the, mxArgv(0));
837
0
  mxPush(mxArrayPrototype);
838
0
  result = fxNewArrayInstance(the);
839
0
  mxPullSlot(mxResult);
840
0
  array = result->next;
841
0
  mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG, array);
842
0
  item = array;
843
0
  while ((item = item->next)) {
844
0
    array->value.array.length++;
845
0
    fxKeyAt(the, item->value.at.id, item->value.at.index, item);
846
0
  }
847
0
  fxCacheArray(the, result);
848
0
}
849
850
void fx_Object_getOwnPropertySymbols(txMachine* the)
851
0
{
852
0
  txSlot* instance;
853
0
  txSlot* result;
854
0
  txSlot* array;
855
0
  txSlot* item;
856
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
857
0
    mxTypeError("invalid object");
858
0
  instance = fxToInstance(the, mxArgv(0));
859
0
  mxPush(mxArrayPrototype);
860
0
  result = fxNewArrayInstance(the);
861
0
  mxPullSlot(mxResult);
862
0
  array = result->next;
863
0
  mxBehaviorOwnKeys(the, instance, XS_EACH_SYMBOL_FLAG, array);
864
0
  item = array;
865
0
  while ((item = item->next)) {
866
0
    array->value.array.length++;
867
0
    fxKeyAt(the, item->value.at.id, item->value.at.index, item);
868
0
  }
869
0
  fxCacheArray(the, result);
870
0
}
871
872
void fx_Object_getPrototypeOf(txMachine* the)
873
0
{
874
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
875
0
    mxTypeError("invalid object");
876
0
  mxBehaviorGetPrototype(the, fxToInstance(the, mxArgv(0)), mxResult);
877
0
}
878
879
static void fx_Object_groupByAux(txMachine* the)
880
0
{
881
0
  txSlot* instance = mxResult->value.reference;
882
0
  txSlot* at = the->stack;
883
0
  fxAt(the, at);
884
0
  mxPushUndefined();
885
0
  if (!mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack)) {
886
0
    mxPop();
887
0
    mxPush(mxArrayPrototype);
888
0
    fxNewArrayInstance(the);
889
0
    if (!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack, XS_GET_ONLY))
890
0
      mxTypeError("invalid descriptor");
891
0
  }
892
0
}
893
894
void fx_Object_groupBy(txMachine* the)
895
0
{
896
0
  txSlot *instance, *at, *property;
897
0
  instance = fxNewInstance(the);
898
0
  mxPullSlot(mxResult);
899
0
  fxGroupBy(the, fx_Object_groupByAux);
900
0
  at = fxNewInstance(the);
901
0
  mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
902
0
  mxPushUndefined();
903
0
  property = the->stack;
904
0
  while ((at = at->next)) {
905
0
    if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, property)) {
906
0
      fxCacheArray(the, property->value.reference);
907
0
    }
908
0
  }
909
0
  mxPop();
910
0
  mxPop();
911
0
}
912
913
void fx_Object_hasOwn(txMachine* the)
914
0
{
915
0
  txSlot* instance;
916
0
  txSlot* at;
917
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
918
0
    mxTypeError("invalid object");
919
0
  instance = fxToInstance(the, mxArgv(0));
920
0
  if (mxArgc < 2)
921
0
    mxPushUndefined();
922
0
  else
923
0
    mxPushSlot(mxArgv(1));
924
0
  at = fxAt(the, the->stack);
925
0
  mxPushUndefined();
926
0
  mxResult->value.boolean = mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack);
927
0
  mxResult->kind = XS_BOOLEAN_KIND;
928
0
  mxPop();
929
0
  mxPop();
930
0
}
931
932
void fx_Object_is(txMachine* the)
933
0
{
934
0
  if (mxArgc > 0)
935
0
    mxPushSlot(mxArgv(0));
936
0
  else
937
0
    mxPushUndefined();
938
0
  if (mxArgc > 1)
939
0
    mxPushSlot(mxArgv(1));
940
0
  else
941
0
    mxPushUndefined();
942
0
  mxResult->value.boolean = fxIsSameValue(the, the->stack + 1, the->stack, 0);
943
0
  mxResult->kind = XS_BOOLEAN_KIND;
944
0
  the->stack += 2;
945
0
}
946
947
void fx_Object_isExtensible(txMachine* the)
948
0
{
949
0
  mxResult->kind = XS_BOOLEAN_KIND;
950
0
  mxResult->value.boolean = 0;
951
0
  if (mxArgc > 0) {
952
0
    txSlot* slot = mxArgv(0);
953
0
    if (slot->kind == XS_REFERENCE_KIND) {
954
0
      slot = slot->value.reference;
955
0
      mxResult->value.boolean = mxBehaviorIsExtensible(the, slot);
956
0
    }
957
0
  }
958
0
}
959
960
void fx_Object_isFrozen(txMachine* the)
961
0
{
962
0
  mxResult->kind = XS_BOOLEAN_KIND;
963
0
  mxResult->value.boolean = 1;
964
0
  if (mxArgc > 0) {
965
0
    txSlot* slot = mxArgv(0);
966
0
    if (slot->kind == XS_REFERENCE_KIND) {
967
0
      txSlot* instance = slot->value.reference;
968
0
            mxResult->value.boolean = mxBehaviorIsExtensible(the, instance) ? 0 : 1;
969
0
      if (mxResult->value.boolean) {
970
0
        txSlot* at;
971
0
        txSlot* property;
972
0
        at = fxNewInstance(the);
973
0
        mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
974
0
        mxPushUndefined();
975
0
        property = the->stack;
976
0
        while ((at = at->next)) {
977
0
          if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, property)) {
978
0
            if (property->kind != XS_ACCESSOR_KIND) 
979
0
              if (!(property->flag & XS_DONT_SET_FLAG))
980
0
                mxResult->value.boolean = 0;
981
0
            if (!(property->flag & XS_DONT_DELETE_FLAG))
982
0
              mxResult->value.boolean = 0;
983
0
          }
984
0
        }
985
0
        mxPop();
986
0
        mxPop();
987
0
      }
988
0
    }
989
0
  }
990
0
}
991
992
void fx_Object_isSealed(txMachine* the)
993
0
{
994
0
  mxResult->kind = XS_BOOLEAN_KIND;
995
0
  mxResult->value.boolean = 1;
996
0
  if (mxArgc > 0) {
997
0
    txSlot* slot = mxArgv(0);
998
0
    if (slot->kind == XS_REFERENCE_KIND) {
999
0
      txSlot* instance = slot->value.reference;
1000
0
      mxResult->value.boolean = mxBehaviorIsExtensible(the, instance) ? 0 : 1;
1001
0
      if (mxResult->value.boolean) {
1002
0
        txSlot* at;
1003
0
        txSlot* property;
1004
0
        at = fxNewInstance(the);
1005
0
        mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
1006
0
        mxPushUndefined();
1007
0
        property = the->stack;
1008
0
        while ((at = at->next)) {
1009
0
          if (mxBehaviorGetOwnProperty(the, instance, at->value.at.id, at->value.at.index, property)) {
1010
0
            if (!(property->flag & XS_DONT_DELETE_FLAG))
1011
0
              mxResult->value.boolean = 0;
1012
0
          }
1013
0
        }
1014
0
        mxPop();
1015
0
        mxPop();
1016
0
      }   
1017
0
    }
1018
0
  }
1019
0
}
1020
1021
void fx_Object_keys(txMachine* the)
1022
0
{
1023
0
  txSlot* instance;
1024
0
  txSlot* result;
1025
0
  txSlot* array;
1026
0
  txSlot* property;
1027
0
  txSlot** address;
1028
0
  txSlot* item;
1029
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
1030
0
    mxTypeError("invalid object");
1031
0
  instance = fxToInstance(the, mxArgv(0));
1032
0
  mxPush(mxArrayPrototype);
1033
0
  result = fxNewArrayInstance(the);
1034
0
  mxPullSlot(mxResult);
1035
0
  array = result->next;
1036
0
  mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG, array);
1037
0
  mxPushUndefined();
1038
0
  property = the->stack;
1039
0
  address = &array->next;
1040
0
  while ((item = *address)) {
1041
0
    if (mxBehaviorGetOwnProperty(the, instance, item->value.at.id, item->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
1042
0
      array->value.array.length++;
1043
0
      fxKeyAt(the, item->value.at.id, item->value.at.index, item);
1044
0
      address = &(item->next);
1045
0
    }
1046
0
    else
1047
0
      *address = item->next;
1048
0
  }
1049
0
  mxPop();
1050
0
  fxCacheArray(the, result);
1051
0
}
1052
1053
void fx_Object_preventExtensions(txMachine* the)
1054
0
{
1055
0
  if (mxArgc > 0) {
1056
0
    txSlot* slot = mxArgv(0);
1057
0
    if (slot->kind == XS_REFERENCE_KIND) {
1058
0
      slot = slot->value.reference;
1059
0
      if (!mxBehaviorPreventExtensions(the, slot))
1060
0
        mxTypeError("extensible object");
1061
0
    }
1062
0
    *mxResult = *mxArgv(0);
1063
0
  }
1064
0
}
1065
1066
void fx_Object_seal(txMachine* the)
1067
0
{
1068
0
  if (mxArgc > 0) {
1069
0
    txSlot* slot = mxArgv(0);
1070
0
    if (slot->kind == XS_REFERENCE_KIND) {
1071
0
      txSlot* instance = slot->value.reference;
1072
0
      txSlot* at;
1073
0
      txSlot* property;
1074
0
      if (!mxBehaviorPreventExtensions(the, instance))
1075
0
        mxTypeError("extensible object");
1076
0
      at = fxNewInstance(the);
1077
0
      mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
1078
0
      mxPushUndefined();
1079
0
      property = the->stack;
1080
0
      property->flag |= XS_DONT_DELETE_FLAG;
1081
0
      property->kind = XS_UNINITIALIZED_KIND;
1082
0
      while ((at = at->next)) {
1083
0
        if (!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, property, XS_DONT_DELETE_FLAG))
1084
0
          mxTypeError("cannot configure property");
1085
0
      }
1086
0
      mxPop();
1087
0
      mxPop();
1088
0
    }
1089
0
    *mxResult = *mxArgv(0);
1090
0
  }
1091
0
}
1092
1093
void fx_Object_setPrototypeOf(txMachine* the)
1094
0
{
1095
0
  txSlot* instance;
1096
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
1097
0
    mxTypeError("invalid object");
1098
0
  if ((mxArgc < 2) || ((mxArgv(1)->kind != XS_NULL_KIND) && (mxArgv(1)->kind != XS_REFERENCE_KIND)))
1099
0
    mxTypeError("invalid prototype");
1100
0
  if (mxArgv(0)->kind == XS_REFERENCE_KIND) {
1101
0
    instance = mxArgv(0)->value.reference;
1102
0
    if (!mxBehaviorSetPrototype(the, instance, mxArgv(1)))
1103
0
      mxTypeError("invalid prototype");
1104
0
  }
1105
0
  *mxResult = *mxArgv(0);
1106
0
}
1107
1108
void fx_Object_values(txMachine* the)
1109
0
{
1110
0
  txSlot* instance;
1111
0
  txSlot* result;
1112
0
  txSlot* array;
1113
0
  txSlot* property;
1114
0
  txSlot** address;
1115
0
  txSlot* item;
1116
0
  if ((mxArgc < 1) || (mxArgv(0)->kind == XS_UNDEFINED_KIND) || (mxArgv(0)->kind == XS_NULL_KIND))
1117
0
    mxTypeError("invalid object");
1118
0
  instance = fxToInstance(the, mxArgv(0));
1119
0
  mxPush(mxArrayPrototype);
1120
0
  result = fxNewArrayInstance(the);
1121
0
  mxPullSlot(mxResult);
1122
0
  array = result->next;
1123
0
  mxBehaviorOwnKeys(the, instance, XS_EACH_NAME_FLAG, array);
1124
0
  mxPushUndefined();
1125
0
  property = the->stack;
1126
0
  address = &array->next;
1127
0
  while ((item = *address)) {
1128
0
    if (mxBehaviorGetOwnProperty(the, instance, item->value.at.id, item->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
1129
0
      array->value.array.length++;
1130
0
      mxPushReference(instance);
1131
0
      mxGetAll(item->value.at.id, item->value.at.index);
1132
0
      mxPullSlot(item);
1133
0
      address = &(item->next);
1134
0
    }
1135
0
    else
1136
0
      *address = item->next;
1137
0
  }
1138
0
  mxPop();
1139
0
  fxCacheArray(the, result);
1140
0
}