Coverage Report

Created: 2026-01-29 06:33

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