Coverage Report

Created: 2026-10-31 07:05

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