Coverage Report

Created: 2026-07-16 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/moddable/xs/sources/xsProperty.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
txSlot* fxLastProperty(txMachine* the, txSlot* slot)
41
65.3M
{
42
65.3M
  txSlot* property;
43
215M
  while ((property = slot->next))
44
150M
    slot = property;
45
65.3M
  return slot;
46
65.3M
}
47
48
#ifndef mxLink
49
txSlot* fxNextHostAccessorProperty(txMachine* the, txSlot* property, txCallback get, txCallback set, txID id, txFlag flag)
50
1.22M
{
51
1.22M
  txSlot *getter = NULL, *setter = NULL, *home = the->stack, *slot;
52
1.22M
  if (get) {
53
1.22M
    getter = fxBuildHostFunction(the, get, 0, XS_NO_ID);
54
1.22M
    slot = mxFunctionInstanceHome(getter);
55
1.22M
    slot->value.home.object = home->value.reference;
56
1.22M
    fxRenameFunction(the, getter, id, 0, XS_NO_ID, "get ");
57
1.22M
  }
58
1.22M
  if (set) {
59
102k
    setter = fxBuildHostFunction(the, set, 1, XS_NO_ID);
60
102k
    slot = mxFunctionInstanceHome(setter);
61
102k
    slot->value.home.object = home->value.reference;
62
102k
    fxRenameFunction(the, setter, id, 0, XS_NO_ID, "set ");
63
102k
  }
64
1.22M
  property = property->next = fxNewSlot(the);
65
1.22M
  property->flag = flag;
66
1.22M
  property->ID = id;
67
1.22M
  property->kind = XS_ACCESSOR_KIND;
68
1.22M
  property->value.accessor.getter = getter;
69
1.22M
  property->value.accessor.setter = setter;
70
1.22M
  if (set)
71
102k
    mxPop();
72
1.22M
  if (get)
73
1.22M
    mxPop();
74
1.22M
  return property;
75
1.22M
}
76
77
txSlot* fxNextHostFunctionProperty(txMachine* the, txSlot* property, txCallback call, txInteger length, txID id, txFlag flag)
78
11.6M
{
79
11.6M
  txSlot *function, *home = the->stack, *slot;
80
11.6M
  function = fxNewHostFunction(the, call, length, id, XS_NO_ID);
81
11.6M
  slot = mxFunctionInstanceHome(function);
82
11.6M
  slot->value.home.object = home->value.reference;
83
11.6M
  property = property->next = fxNewSlot(the);
84
11.6M
  property->flag = flag;
85
11.6M
  property->ID = id;
86
11.6M
  property->kind = the->stack->kind;
87
11.6M
  property->value = the->stack->value;
88
11.6M
  mxPop();
89
11.6M
  return property;
90
11.6M
}
91
#endif
92
93
txSlot* fxNextUndefinedProperty(txMachine* the, txSlot* property, txID id, txFlag flag)
94
2.25M
{
95
2.25M
  property = property->next = fxNewSlot(the);
96
2.25M
  property->flag = flag;
97
2.25M
  property->ID = id;
98
2.25M
  property->kind = XS_UNDEFINED_KIND;
99
2.25M
  return property;
100
2.25M
}
101
102
txSlot* fxNextNullProperty(txMachine* the, txSlot* property, txID id, txFlag flag)
103
574k
{
104
574k
  property = property->next = fxNewSlot(the);
105
574k
  property->flag = flag;
106
574k
  property->ID = id;
107
574k
  property->kind = XS_NULL_KIND;
108
574k
  return property;
109
574k
}
110
111
txSlot* fxNextBooleanProperty(txMachine* the, txSlot* property, txBoolean boolean, txID id, txFlag flag)
112
2.54M
{
113
2.54M
  property = property->next = fxNewSlot(the);
114
2.54M
  property->flag = flag;
115
2.54M
  property->ID = id;
116
2.54M
  property->kind = XS_BOOLEAN_KIND;
117
2.54M
  property->value.boolean = boolean;
118
2.54M
  return property;
119
2.54M
}
120
121
txSlot* fxNextIntegerProperty(txMachine* the, txSlot* property, txInteger integer, txID id, txFlag flag)
122
27.7M
{
123
27.7M
  property = property->next = fxNewSlot(the);
124
27.7M
  property->flag = flag;
125
27.7M
  property->ID = id;
126
27.7M
  property->kind = XS_INTEGER_KIND;
127
27.7M
  property->value.integer = integer;
128
27.7M
  return property;
129
27.7M
}
130
131
txSlot* fxNextNumberProperty(txMachine* the, txSlot* property, txNumber number, txID id, txFlag flag)
132
13.4M
{
133
13.4M
  property = property->next = fxNewSlot(the);
134
13.4M
  property->flag = flag;
135
13.4M
  property->ID = id;
136
13.4M
  property->kind = XS_NUMBER_KIND;
137
13.4M
  property->value.number = number;
138
13.4M
  return property;
139
13.4M
}
140
141
txSlot* fxNextReferenceProperty(txMachine* the, txSlot* property, txSlot* slot, txID id, txFlag flag)
142
215k
{
143
215k
  property = property->next = fxNewSlot(the);
144
215k
  property->flag = flag;
145
215k
  property->ID = id;
146
215k
  property->kind = XS_REFERENCE_KIND;
147
215k
  property->value.reference = slot;
148
215k
  return property;
149
215k
}
150
151
txSlot* fxNextSlotProperty(txMachine* the, txSlot* property, txSlot* slot, txID id, txFlag flag)
152
81.1M
{
153
81.1M
  property = property->next = fxNewSlot(the);
154
81.1M
  property->flag = flag;
155
81.1M
  property->ID = id;
156
81.1M
  property->kind = slot->kind;
157
81.1M
  property->value = slot->value;
158
81.1M
  return property;
159
81.1M
}
160
161
txSlot* fxNextStringProperty(txMachine* the, txSlot* property, txString string, txID id, txFlag flag)
162
1.83M
{
163
1.83M
  property = property->next = fxNewSlot(the);
164
1.83M
  property->flag = flag;
165
1.83M
  property->ID = id;
166
1.83M
  fxCopyStringC(the, property, string);
167
1.83M
  return property;
168
1.83M
}
169
170
txSlot* fxNextStringXProperty(txMachine* the, txSlot* property, txString string, txID id, txFlag flag)
171
1.71M
{
172
1.71M
  property = property->next = fxNewSlot(the);
173
1.71M
  property->flag = flag;
174
1.71M
  property->ID = id;
175
1.71M
#ifdef mxSnapshot
176
1.71M
  fxCopyStringC(the, property, string);
177
#else
178
  property->kind = XS_STRING_X_KIND;
179
  property->value.string = string;
180
#endif
181
1.71M
  return property;
182
1.71M
}
183
184
185
txSlot* fxNextSymbolProperty(txMachine* the, txSlot* property, txID symbol, txID id, txFlag flag)
186
993k
{
187
993k
  property = property->next = fxNewSlot(the);
188
993k
  property->flag = flag;
189
993k
  property->ID = id;
190
993k
  property->kind = XS_SYMBOL_KIND;
191
993k
  property->value.symbol = symbol;
192
993k
  return property;
193
993k
}
194
195
txSlot* fxNextTypeDispatchProperty(txMachine* the, txSlot* property, txTypeDispatch* dispatch, txTypeAtomics* atomics, txID id, txFlag flag)
196
751k
{
197
751k
  property = property->next = fxNewSlot(the);
198
751k
  property->flag = flag;
199
751k
  property->ID = id;
200
751k
  property->kind = XS_TYPED_ARRAY_KIND;
201
751k
  property->value.typedArray.dispatch = dispatch;
202
751k
  property->value.typedArray.atomics = atomics;
203
751k
  return property;
204
751k
}
205
206
txSlot* fxQueueKey(txMachine* the, txID id, txIndex index, txSlot* keys)
207
69.6M
{
208
69.6M
  keys = keys->next = fxNewSlot(the);
209
69.6M
  keys->kind = XS_AT_KIND;
210
69.6M
  keys->value.at.id = id;
211
69.6M
  keys->value.at.index = index;
212
69.6M
  return keys;
213
69.6M
}
214
215
txSlot* fxQueueIDKeys(txMachine* the, txSlot* first, txFlag flag, txSlot* keys)
216
1.62M
{
217
1.62M
  if (flag & XS_EACH_NAME_FLAG) {
218
1.62M
    txSlot* property = first;
219
11.5M
    while (property) {
220
9.96M
      if (!(property->flag & XS_INTERNAL_FLAG) && fxIsKeyName(the, property->ID))
221
9.39M
        keys = fxQueueKey(the, property->ID, 0, keys);
222
9.96M
      property = property->next;
223
9.96M
    }
224
1.62M
  }
225
1.62M
  if (flag & XS_EACH_SYMBOL_FLAG) {
226
154k
    txSlot* property = first;
227
276k
    while (property) {
228
122k
      if (!(property->flag & XS_INTERNAL_FLAG) && fxIsKeySymbol(the, property->ID))
229
3.54k
        keys = fxQueueKey(the, property->ID, 0, keys);
230
122k
      property = property->next;
231
122k
    }
232
154k
  }
233
1.62M
  return keys;
234
1.62M
}
235
236
// INDEX
237
238
static txSize fxSizeToCapacity(txMachine* the, txSize size)
239
1.47M
{
240
1.47M
  return fxAddChunkSizes(the, size, size / 3);
241
1.47M
}
242
243
txBoolean fxDeleteIndexProperty(txMachine* the, txSlot* array, txIndex index) 
244
2.83M
{
245
2.83M
  txSlot* address = array->value.array.address;
246
2.83M
  if (address) {
247
2.75M
    txIndex length = array->value.array.length;
248
2.75M
    txIndex size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
249
2.75M
    txSlot* result = address;
250
2.75M
    txSlot* limit = result + size;
251
2.75M
    if (length == size)
252
1.34M
      result = address + index;
253
1.40M
    else {
254
1.40M
      txIndex at;
255
3.96M
      while (result < limit) {
256
2.69M
        at = *((txIndex*)result);
257
2.69M
        if (at == index)
258
669
          break;
259
2.69M
        if (at > index)
260
136k
          return 1;
261
2.55M
        result++;
262
2.55M
      }
263
1.40M
    }
264
2.61M
    if (result < limit) {
265
731
      if (result->flag & XS_DONT_DELETE_FLAG)
266
2
        return 0;
267
729
      index = (txIndex)(result - address);
268
729
      size--;
269
729
      if (size > 0) {
270
583
        txSlot* chunk = (txSlot*)fxNewChunk(the, size * sizeof(txSlot));
271
583
        address = array->value.array.address;
272
583
        if (index > 0)
273
434
          c_memcpy(chunk, address, index * sizeof(txSlot));
274
583
        if (index < size)
275
294
          c_memcpy(chunk + index, address + index + 1, (size - index) * sizeof(txSlot));
276
583
        array->value.array.address = chunk;
277
583
      }
278
146
      else
279
146
        array->value.array.address = C_NULL;
280
729
    }
281
2.61M
  }
282
2.70M
  return 1;
283
2.83M
}
284
285
txSlot* fxGetIndexProperty(txMachine* the, txSlot* array, txIndex index) 
286
202M
{
287
202M
  txSlot* address = array->value.array.address;
288
202M
  if (address) {
289
160M
    txIndex length = array->value.array.length;
290
160M
    txIndex size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
291
160M
    if (length == size) {
292
127M
      if (index < length)
293
95.0M
        return address + index;
294
127M
    }
295
33.1M
    else {
296
33.1M
      txSlot* result = address;
297
33.1M
      txSlot* limit = result + size;
298
33.1M
      txIndex at;
299
252M
      while (result < limit) {
300
222M
        at = *((txIndex*)result);
301
222M
        if (at == index)
302
3.97M
          return result;
303
218M
        result++;
304
218M
      }
305
33.1M
    }
306
160M
  }
307
103M
  return C_NULL;
308
202M
}
309
310
txIndex fxGetIndexSize(txMachine* the, txSlot* array)
311
0
{
312
0
  txSlot* address = array->value.array.address;
313
0
  if (address)
314
0
    return (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
315
0
  return 0;
316
0
}
317
318
txSlot* fxQueueIndexKeys(txMachine* the, txSlot* array, txFlag flag, txSlot* keys)
319
150k
{
320
150k
  if (flag & XS_EACH_NAME_FLAG) {
321
150k
    if (array->value.array.address) {
322
132k
      txSize offset = 0;
323
132k
      txSize size = (((txChunk*)(((txByte*)array->value.array.address) - sizeof(txChunk)))->size) / sizeof(txSlot);
324
34.4M
      while (offset < size) {
325
34.3M
        txSlot* slot = array->value.array.address + offset;
326
34.3M
        txIndex index = *((txIndex*)slot);
327
34.3M
        keys = fxQueueKey(the, 0, index, keys);
328
34.3M
        offset++;
329
34.3M
      }
330
132k
    }
331
150k
  }
332
150k
  return keys;
333
150k
}
334
335
txSlot* fxSetIndexProperty(txMachine* the, txSlot* instance, txSlot* array, txIndex index) 
336
23.2M
{
337
23.2M
  txSlot* address = array->value.array.address;
338
23.2M
  txSlot* chunk = address;
339
23.2M
  txIndex length = array->value.array.length;
340
23.2M
  txIndex current;
341
23.2M
  txSize size;
342
23.2M
  txSlot* result;
343
23.2M
  txSlot* limit;
344
23.2M
  txIndex at;
345
23.2M
  if (address) {
346
17.2M
    current = (((txChunk*)(((txByte*)chunk) - sizeof(txChunk)))->size) / sizeof(txSlot);
347
17.2M
    if (length == current) {
348
12.8M
      if (index < length) 
349
0
        return address + index;
350
12.8M
      if (instance->flag & XS_DONT_PATCH_FLAG)
351
0
        return C_NULL;
352
12.8M
      if (array->flag & XS_DONT_SET_FLAG)
353
1
        return C_NULL;
354
12.8M
      current++;
355
12.8M
      size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
356
12.8M
      chunk = (txSlot*)fxRenewChunk(the, address, size);
357
12.8M
      if (!chunk) {
358
3.67M
      #ifndef mxNoArrayOverallocation
359
3.67M
        if (array->ID == XS_ARRAY_BEHAVIOR) {
360
1.47M
          txSize capacity = fxSizeToCapacity(the, size);
361
1.47M
          chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
362
1.47M
        }
363
2.20M
        else
364
2.20M
      #endif
365
2.20M
          chunk = (txSlot*)fxNewChunk(the, size);
366
3.67M
        address = array->value.array.address;
367
3.67M
        c_memcpy(chunk, address, length * sizeof(txSlot));
368
3.67M
      }
369
12.8M
      result = chunk + length;
370
12.8M
    }
371
4.44M
    else {
372
4.44M
      result = address;
373
4.44M
      limit = result + current;
374
46.9M
      while (result < limit) {
375
42.9M
        at = *((txIndex*)result);
376
42.9M
        if (at == index)
377
0
          return result;
378
42.9M
        if (at > index)
379
434k
          break;
380
42.5M
        result++;
381
42.5M
      }
382
4.44M
      if (instance->flag & XS_DONT_PATCH_FLAG)
383
0
        return C_NULL;
384
4.44M
      if ((array->flag & XS_DONT_SET_FLAG) && (index >= length))
385
1
        return C_NULL;
386
4.44M
      at = mxPtrDiff(result - address);
387
4.44M
      current++;
388
4.44M
      size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
389
4.44M
      chunk = (txSlot*)fxNewChunk(the, size);
390
4.44M
      address = array->value.array.address;
391
4.44M
      result = address + at;
392
4.44M
      limit = address + current - 1;
393
4.44M
      if (result > address)
394
4.00M
        c_memcpy(chunk, address, (result - address) * sizeof(txSlot));
395
4.44M
      if (result < limit)
396
434k
        c_memcpy(chunk + (result - address) + 1, result, (limit - result) * sizeof(txSlot));
397
4.44M
      result = chunk + (result - address);
398
4.44M
    }
399
17.2M
  }
400
5.93M
  else {
401
5.93M
        if (instance->flag & XS_DONT_PATCH_FLAG)
402
0
            return C_NULL;
403
5.93M
    if ((array->flag & XS_DONT_SET_FLAG) && (index >= length))
404
0
      return C_NULL;
405
5.93M
    current = 1;
406
5.93M
    chunk = (txSlot*)fxNewChunk(the, sizeof(txSlot));
407
5.93M
    result = chunk;
408
5.93M
  }
409
23.2M
  result->next = C_NULL;
410
23.2M
  result->ID = XS_NO_ID;
411
23.2M
  result->flag = XS_NO_FLAG;
412
23.2M
  result->kind = XS_UNDEFINED_KIND;
413
23.2M
  *((txIndex*)result) = index;  
414
23.2M
  array->value.array.address = chunk;
415
23.2M
  if (index >= length) {
416
14.0M
    array->value.array.length = index + 1;
417
14.0M
  }
418
23.2M
  return result;
419
23.2M
}
420
421
void fxSetIndexSize(txMachine* the, txSlot* array, txIndex target, txBoolean growable)
422
8.44M
{
423
8.44M
  txSlot* address = array->value.array.address;
424
8.44M
  txSlot* chunk = C_NULL;
425
8.44M
  txIndex current = (address) ? (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot) : 0;
426
8.44M
  txSize size;
427
8.44M
  if (current != target) {
428
1.25M
    if (array->flag & XS_DONT_SET_FLAG)
429
0
      mxTypeError("set length: not writable");
430
1.25M
    size = fxMultiplyChunkSizes(the, target, sizeof(txSlot));
431
1.25M
    if (address) {
432
412k
      if (target) {
433
407k
        chunk = (txSlot*)fxRenewChunk(the, address, size);
434
407k
        if (!chunk) {
435
1.27k
        #ifndef mxNoArrayOverallocation
436
1.27k
          if (growable) {
437
1.26k
            txSize capacity = fxSizeToCapacity(the, size);
438
1.26k
            chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
439
1.26k
          }
440
6
          else
441
6
        #endif
442
6
            chunk = (txSlot*)fxNewChunk(the, size);
443
1.27k
          address = array->value.array.address;
444
1.27k
          if (current < target)
445
1.27k
            c_memcpy(chunk, address, current * sizeof(txSlot));
446
0
          else
447
0
            c_memcpy(chunk, address, size);
448
1.27k
        }
449
407k
      }
450
412k
    }
451
841k
    else {
452
841k
    #ifndef mxNoArrayOverallocation
453
841k
      if (growable) {
454
579
        txSize capacity = fxSizeToCapacity(the, size);
455
579
        chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
456
579
      }
457
840k
      else
458
840k
    #endif
459
840k
        chunk = (txSlot*)fxNewChunk(the, size);
460
841k
    }
461
1.25M
    if (current < target)
462
1.23M
      c_memset(chunk + current, 0, (target - current) * sizeof(txSlot));
463
1.25M
    array->value.array.length = target;
464
1.25M
    array->value.array.address = chunk;
465
1.25M
  }
466
8.44M
}
467
468
txBoolean fxDefinePrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id, txSlot* slot, txFlag mask) 
469
21.7k
{
470
21.7k
  txSlot** address;
471
21.7k
  txSlot* property;
472
21.7k
  mxCheck(the, instance->kind == XS_INSTANCE_KIND);
473
#if mxAliasInstance
474
  if (instance->ID) {
475
    txSlot* alias = the->aliasArray[instance->ID];
476
    if (alias)
477
      instance = alias;
478
    else
479
      instance = fxAliasInstance(the, instance);
480
  }
481
  if (instance->flag & XS_MARK_FLAG)
482
    return 0;
483
#else
484
21.7k
  if (instance->flag & XS_DONT_MARSHALL_FLAG)
485
1
    return 0;
486
21.7k
#endif
487
21.7k
  if (mxIsModule(instance)) {
488
0
    instance = mxModuleInstanceExports(instance)->value.reference;
489
0
  }
490
21.7k
  address = &(instance->next);
491
29.1k
  while ((property = *address)) {
492
10.9k
    if (!(property->flag & XS_INTERNAL_FLAG)) {
493
19
      property = C_NULL;
494
19
      break;
495
19
    }
496
10.9k
    if (property->kind == XS_PRIVATE_KIND) {
497
3.65k
      if (property->value.private.check == check) {
498
3.64k
        break;
499
3.64k
      }
500
3.65k
    }
501
7.30k
    address = &(property->next);
502
7.30k
  }
503
21.7k
  if (!property) {
504
18.1k
    property = fxNewSlot(the);
505
18.1k
    property->next = *address;
506
18.1k
    property->flag = XS_INTERNAL_FLAG;
507
18.1k
    property->kind = XS_PRIVATE_KIND;
508
18.1k
    property->value.private.check = check;
509
18.1k
    property->value.private.first = C_NULL;
510
18.1k
    *address = property;
511
18.1k
  }
512
21.7k
  address = &(property->value.private.first);
513
25.4k
  while ((property = *address)) {
514
3.65k
    if (property->ID == id)
515
0
      break;
516
3.65k
    address = &(property->next);
517
3.65k
  }
518
21.7k
  if (mask & XS_ACCESSOR_FLAG) {
519
1
    if (property) {
520
0
      if (property->kind != XS_ACCESSOR_KIND)
521
0
        return 0;
522
0
    }
523
1
    else {
524
1
      *address = property = fxNewSlot(the);
525
1
      property->ID = id;
526
1
      property->kind = XS_ACCESSOR_KIND;
527
1
      property->value.accessor.getter = C_NULL;
528
1
      property->value.accessor.setter = C_NULL;
529
1
    }
530
1
    if (mask & XS_GETTER_FLAG) {
531
1
      txSlot* function = slot->value.accessor.getter;
532
1
      if (property->value.accessor.getter)
533
0
        return 0;
534
1
      property->value.accessor.getter = function;
535
1
      if (mxIsFunction(function)) {
536
1
        if (((mask & XS_METHOD_FLAG) && (function->flag & XS_MARK_FLAG) == 0)) {
537
1
          txSlot* home = mxFunctionInstanceHome(function);
538
1
          home->value.home.object = instance;
539
1
        }
540
1
        if ((mask & XS_NAME_FLAG) && ((function->flag & XS_MARK_FLAG) == 0))
541
1
          fxRenameFunction(the, function, id, 0, mxID(_get), "get ");
542
1
      }
543
1
    }
544
0
    else {
545
0
      txSlot* function = slot->value.accessor.setter;
546
0
      if (property->value.accessor.setter)
547
0
        return 0;
548
0
      property->value.accessor.setter = function;
549
0
      if (mxIsFunction(function)) {
550
0
        if (((mask & XS_METHOD_FLAG) && (function->flag & XS_MARK_FLAG) == 0)) {
551
0
          txSlot* home = mxFunctionInstanceHome(function);
552
0
          home->value.home.object = instance;
553
0
        }
554
0
        if ((mask & XS_NAME_FLAG) && ((function->flag & XS_MARK_FLAG) == 0))
555
0
          fxRenameFunction(the, function, id, 0, mxID(_set), "set ");
556
0
      }
557
0
    }
558
1
  }
559
21.7k
  else {
560
21.7k
    if (property)
561
0
      return 0;
562
21.7k
    *address = property = fxNewSlot(the);
563
21.7k
    property->flag = (mask & XS_METHOD_FLAG) ? XS_DONT_SET_FLAG : XS_NO_FLAG;
564
21.7k
    property->ID = id;
565
21.7k
    property->kind = slot->kind;
566
21.7k
    property->value = slot->value;
567
21.7k
    if (property->kind == XS_REFERENCE_KIND) {
568
17
      txSlot* function = slot->value.reference;
569
17
      if (mxIsFunction(function)) {
570
14
        if ((mask & XS_METHOD_FLAG) && ((function->flag & XS_MARK_FLAG) == 0)) {
571
13
          txSlot* home = mxFunctionInstanceHome(function);
572
13
          home->value.home.object = instance;
573
13
        }
574
14
        if ((mask & XS_NAME_FLAG) && ((function->flag & XS_MARK_FLAG) == 0))
575
14
          fxRenameFunction(the, function, id, 0, mxID(_value), C_NULL);
576
14
      }
577
17
    }
578
21.7k
  }
579
21.7k
  return 1;
580
21.7k
}
581
582
txSlot* fxGetPrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id) 
583
9.03k
{
584
9.03k
    txSlot* result;
585
9.03k
  mxCheck(the, instance->kind == XS_INSTANCE_KIND);
586
#if mxAliasInstance
587
  if (instance->ID) {
588
    txSlot* alias = the->aliasArray[instance->ID];
589
    if (alias)
590
      instance = alias;
591
  }
592
#endif
593
9.03k
  if (mxIsModule(instance)) {
594
0
    instance = mxModuleInstanceExports(instance)->value.reference;
595
0
  }
596
9.03k
  result = instance->next;
597
9.07k
  while (result) {
598
9.07k
    if (result->kind == XS_PRIVATE_KIND) {
599
9.03k
      if (result->value.private.check == check)
600
9.03k
        break;
601
9.03k
    }
602
39
    result = result->next;
603
39
  }
604
9.03k
  if (result) {
605
9.03k
    result = result->value.private.first;
606
9.03k
    while (result) {
607
9.03k
      if (result->ID == id)
608
9.03k
        break;
609
0
      result = result->next;
610
0
    }
611
9.03k
  }
612
9.03k
  if (result) {
613
9.03k
    if ((result->kind == XS_ACCESSOR_KIND) && (result->value.accessor.getter == C_NULL))
614
0
      result = C_NULL;
615
9.03k
  }
616
9.03k
  return result;
617
9.03k
}
618
619
txSlot* fxSetPrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id) 
620
11
{
621
11
    txSlot* result;
622
11
  mxCheck(the, instance->kind == XS_INSTANCE_KIND);
623
#if mxAliasInstance
624
  if (instance->ID) {
625
    txSlot* alias = the->aliasArray[instance->ID];
626
    if (alias)
627
      instance = alias;
628
    else
629
      instance = fxAliasInstance(the, instance);
630
  }
631
#endif
632
11
  if (mxIsModule(instance)) {
633
0
    instance = mxModuleInstanceExports(instance)->value.reference;
634
0
  }
635
11
  result = instance->next;
636
15
  while (result) {
637
13
    if (result->kind == XS_PRIVATE_KIND) {
638
9
      if (result->value.private.check == check)
639
9
        break;
640
9
    }
641
4
    result = result->next;
642
4
  }
643
11
  if (result) {
644
9
    result = result->value.private.first;
645
9
    while (result) {
646
9
      if (result->ID == id)
647
9
        break;
648
0
      result = result->next;
649
0
    }
650
9
  }
651
11
  if (result) {
652
9
    if ((result->kind == XS_ACCESSOR_KIND) && (result->value.accessor.setter == C_NULL))
653
0
      result = C_NULL;
654
9
  }
655
11
  return result;
656
11
}
657
658
void fxGroupBy(txMachine* the, txCallback aux) 
659
3.99k
{
660
3.99k
  txSlot *function, *iterable, *iterator, *next, *value, *slot;
661
3.99k
  txNumber k = 0;
662
3.99k
  if ((mxArgc < 1) || mxIsUndefined(mxArgv(0)) || mxIsUndefined(mxArgv(1)))
663
1.32k
    mxTypeError("items: not an object");
664
2.67k
  if ((mxArgc < 2) || (!fxIsCallable(the, mxArgv(1))))
665
2.63k
    mxTypeError("callback: not a function");
666
39
  function = mxArgv(1);
667
39
  iterable = mxArgv(0);
668
39
  mxTemporary(iterator);
669
39
  mxTemporary(next);
670
39
  fxGetIterator(the, iterable, iterator, next, 0);
671
39
  mxTemporary(value);
672
16.9k
  while (fxIteratorNext(the, iterator, next, value)) {
673
16.9k
    mxTry(the) {
674
16.9k
      if (k > C_MAX_SAFE_INTEGER)
675
0
        mxTypeError("unsafe integer");
676
16.9k
      mxPushUndefined();
677
16.9k
      mxPushSlot(function);
678
16.9k
      mxCall();
679
16.9k
      mxPushSlot(value);
680
16.9k
      mxPushNumber(k);
681
16.9k
      mxRunCount(2);
682
16.9k
      aux(the);
683
16.9k
      slot = the->stack->value.reference->next;
684
16.9k
      slot->value.array.length++;
685
41.1k
      while (slot->next)
686
24.1k
        slot = slot->next;
687
16.9k
      slot->next = fxDuplicateSlot(the, value);
688
16.9k
      mxPop();
689
16.9k
      mxPop();
690
16.9k
      k++;
691
16.9k
    }
692
16.9k
    mxCatch(the) {
693
1
      fxIteratorReturn(the, iterator, 1);
694
1
      fxJump(the);
695
1
    }
696
16.9k
  }
697
38
  mxPop();
698
38
  mxPop();
699
38
  mxPop();
700
38
}
701
702
703
704
705
706