Coverage Report

Created: 2026-06-10 07:01

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