Coverage Report

Created: 2025-12-14 06:18

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