Coverage Report

Created: 2025-11-24 06:44

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