Coverage Report

Created: 2025-12-14 06:18

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
62.5M
{
42
62.5M
  txSlot* property;
43
196M
  while ((property = slot->next))
44
133M
    slot = property;
45
62.5M
  return slot;
46
62.5M
}
47
48
#ifndef mxLink
49
txSlot* fxNextHostAccessorProperty(txMachine* the, txSlot* property, txCallback get, txCallback set, txID id, txFlag flag)
50
1.15M
{
51
1.15M
  txSlot *getter = NULL, *setter = NULL, *home = the->stack, *slot;
52
1.15M
  if (get) {
53
1.15M
    getter = fxBuildHostFunction(the, get, 0, XS_NO_ID);
54
1.15M
    slot = mxFunctionInstanceHome(getter);
55
1.15M
    slot->value.home.object = home->value.reference;
56
1.15M
    fxRenameFunction(the, getter, id, 0, XS_NO_ID, "get ");
57
1.15M
  }
58
1.15M
  if (set) {
59
96.2k
    setter = fxBuildHostFunction(the, set, 1, XS_NO_ID);
60
96.2k
    slot = mxFunctionInstanceHome(setter);
61
96.2k
    slot->value.home.object = home->value.reference;
62
96.2k
    fxRenameFunction(the, setter, id, 0, XS_NO_ID, "set ");
63
96.2k
  }
64
1.15M
  property = property->next = fxNewSlot(the);
65
1.15M
  property->flag = flag;
66
1.15M
  property->ID = id;
67
1.15M
  property->kind = XS_ACCESSOR_KIND;
68
1.15M
  property->value.accessor.getter = getter;
69
1.15M
  property->value.accessor.setter = setter;
70
1.15M
  if (set)
71
96.2k
    mxPop();
72
1.15M
  if (get)
73
1.15M
    mxPop();
74
1.15M
  return property;
75
1.15M
}
76
77
txSlot* fxNextHostFunctionProperty(txMachine* the, txSlot* property, txCallback call, txInteger length, txID id, txFlag flag)
78
10.7M
{
79
10.7M
  txSlot *function, *home = the->stack, *slot;
80
10.7M
  function = fxNewHostFunction(the, call, length, id, XS_NO_ID);
81
10.7M
  slot = mxFunctionInstanceHome(function);
82
10.7M
  slot->value.home.object = home->value.reference;
83
10.7M
  property = property->next = fxNewSlot(the);
84
10.7M
  property->flag = flag;
85
10.7M
  property->ID = id;
86
10.7M
  property->kind = the->stack->kind;
87
10.7M
  property->value = the->stack->value;
88
10.7M
  mxPop();
89
10.7M
  return property;
90
10.7M
}
91
#endif
92
93
txSlot* fxNextUndefinedProperty(txMachine* the, txSlot* property, txID id, txFlag flag)
94
1.23M
{
95
1.23M
  property = property->next = fxNewSlot(the);
96
1.23M
  property->flag = flag;
97
1.23M
  property->ID = id;
98
1.23M
  property->kind = XS_UNDEFINED_KIND;
99
1.23M
  return property;
100
1.23M
}
101
102
txSlot* fxNextNullProperty(txMachine* the, txSlot* property, txID id, txFlag flag)
103
225k
{
104
225k
  property = property->next = fxNewSlot(the);
105
225k
  property->flag = flag;
106
225k
  property->ID = id;
107
225k
  property->kind = XS_NULL_KIND;
108
225k
  return property;
109
225k
}
110
111
txSlot* fxNextBooleanProperty(txMachine* the, txSlot* property, txBoolean boolean, txID id, txFlag flag)
112
1.48M
{
113
1.48M
  property = property->next = fxNewSlot(the);
114
1.48M
  property->flag = flag;
115
1.48M
  property->ID = id;
116
1.48M
  property->kind = XS_BOOLEAN_KIND;
117
1.48M
  property->value.boolean = boolean;
118
1.48M
  return property;
119
1.48M
}
120
121
txSlot* fxNextIntegerProperty(txMachine* the, txSlot* property, txInteger integer, txID id, txFlag flag)
122
23.0M
{
123
23.0M
  property = property->next = fxNewSlot(the);
124
23.0M
  property->flag = flag;
125
23.0M
  property->ID = id;
126
23.0M
  property->kind = XS_INTEGER_KIND;
127
23.0M
  property->value.integer = integer;
128
23.0M
  return property;
129
23.0M
}
130
131
txSlot* fxNextNumberProperty(txMachine* the, txSlot* property, txNumber number, txID id, txFlag flag)
132
9.63M
{
133
9.63M
  property = property->next = fxNewSlot(the);
134
9.63M
  property->flag = flag;
135
9.63M
  property->ID = id;
136
9.63M
  property->kind = XS_NUMBER_KIND;
137
9.63M
  property->value.number = number;
138
9.63M
  return property;
139
9.63M
}
140
141
txSlot* fxNextReferenceProperty(txMachine* the, txSlot* property, txSlot* slot, txID id, txFlag flag)
142
88.8k
{
143
88.8k
  property = property->next = fxNewSlot(the);
144
88.8k
  property->flag = flag;
145
88.8k
  property->ID = id;
146
88.8k
  property->kind = XS_REFERENCE_KIND;
147
88.8k
  property->value.reference = slot;
148
88.8k
  return property;
149
88.8k
}
150
151
txSlot* fxNextSlotProperty(txMachine* the, txSlot* property, txSlot* slot, txID id, txFlag flag)
152
75.4M
{
153
75.4M
  property = property->next = fxNewSlot(the);
154
75.4M
  property->flag = flag;
155
75.4M
  property->ID = id;
156
75.4M
  property->kind = slot->kind;
157
75.4M
  property->value = slot->value;
158
75.4M
  return property;
159
75.4M
}
160
161
txSlot* fxNextStringProperty(txMachine* the, txSlot* property, txString string, txID id, txFlag flag)
162
1.26M
{
163
1.26M
  property = property->next = fxNewSlot(the);
164
1.26M
  property->flag = flag;
165
1.26M
  property->ID = id;
166
1.26M
  fxCopyStringC(the, property, string);
167
1.26M
  return property;
168
1.26M
}
169
170
txSlot* fxNextStringXProperty(txMachine* the, txSlot* property, txString string, txID id, txFlag flag)
171
1.61M
{
172
1.61M
  property = property->next = fxNewSlot(the);
173
1.61M
  property->flag = flag;
174
1.61M
  property->ID = id;
175
1.61M
#ifdef mxSnapshot
176
1.61M
  fxCopyStringC(the, property, string);
177
#else
178
  property->kind = XS_STRING_X_KIND;
179
  property->value.string = string;
180
#endif
181
1.61M
  return property;
182
1.61M
}
183
184
185
txSlot* fxNextSymbolProperty(txMachine* the, txSlot* property, txID symbol, txID id, txFlag flag)
186
769k
{
187
769k
  property = property->next = fxNewSlot(the);
188
769k
  property->flag = flag;
189
769k
  property->ID = id;
190
769k
  property->kind = XS_SYMBOL_KIND;
191
769k
  property->value.symbol = symbol;
192
769k
  return property;
193
769k
}
194
195
txSlot* fxNextTypeDispatchProperty(txMachine* the, txSlot* property, txTypeDispatch* dispatch, txTypeAtomics* atomics, txID id, txFlag flag)
196
491k
{
197
491k
  property = property->next = fxNewSlot(the);
198
491k
  property->flag = flag;
199
491k
  property->ID = id;
200
491k
  property->kind = XS_TYPED_ARRAY_KIND;
201
491k
  property->value.typedArray.dispatch = dispatch;
202
491k
  property->value.typedArray.atomics = atomics;
203
491k
  return property;
204
491k
}
205
206
txSlot* fxQueueKey(txMachine* the, txID id, txIndex index, txSlot* keys)
207
35.2M
{
208
35.2M
  keys = keys->next = fxNewSlot(the);
209
35.2M
  keys->kind = XS_AT_KIND;
210
35.2M
  keys->value.at.id = id;
211
35.2M
  keys->value.at.index = index;
212
35.2M
  return keys;
213
35.2M
}
214
215
txSlot* fxQueueIDKeys(txMachine* the, txSlot* first, txFlag flag, txSlot* keys)
216
549k
{
217
549k
  if (flag & XS_EACH_NAME_FLAG) {
218
549k
    txSlot* property = first;
219
3.64M
    while (property) {
220
3.09M
      if (!(property->flag & XS_INTERNAL_FLAG) && fxIsKeyName(the, property->ID))
221
2.97M
        keys = fxQueueKey(the, property->ID, 0, keys);
222
3.09M
      property = property->next;
223
3.09M
    }
224
549k
  }
225
549k
  if (flag & XS_EACH_SYMBOL_FLAG) {
226
28.8k
    txSlot* property = first;
227
103k
    while (property) {
228
74.8k
      if (!(property->flag & XS_INTERNAL_FLAG) && fxIsKeySymbol(the, property->ID))
229
2.19k
        keys = fxQueueKey(the, property->ID, 0, keys);
230
74.8k
      property = property->next;
231
74.8k
    }
232
28.8k
  }
233
549k
  return keys;
234
549k
}
235
236
// INDEX
237
238
static txSize fxSizeToCapacity(txMachine* the, txSize size)
239
991k
{
240
991k
  return fxAddChunkSizes(the, size, size / 3);
241
991k
}
242
243
txBoolean fxDeleteIndexProperty(txMachine* the, txSlot* array, txIndex index) 
244
1.29M
{
245
1.29M
  txSlot* address = array->value.array.address;
246
1.29M
  if (address) {
247
1.12M
    txIndex length = array->value.array.length;
248
1.12M
    txIndex size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
249
1.12M
    txSlot* result = address;
250
1.12M
    txSlot* limit = result + size;
251
1.12M
    if (length == size)
252
881
      result = address + index;
253
1.12M
    else {
254
1.12M
      txIndex at;
255
5.30M
      while (result < limit) {
256
4.17M
        at = *((txIndex*)result);
257
4.17M
        if (at == index)
258
922
          break;
259
4.17M
        if (at > index)
260
218
          return 1;
261
4.17M
        result++;
262
4.17M
      }
263
1.12M
    }
264
1.12M
    if (result < limit) {
265
981
      if (result->flag & XS_DONT_DELETE_FLAG)
266
3
        return 0;
267
978
      index = (txIndex)(result - address);
268
978
      size--;
269
978
      if (size > 0) {
270
836
        txSlot* chunk = (txSlot*)fxNewChunk(the, size * sizeof(txSlot));
271
836
        address = array->value.array.address;
272
836
        if (index > 0)
273
705
          c_memcpy(chunk, address, index * sizeof(txSlot));
274
836
        if (index < size)
275
274
          c_memcpy(chunk + index, address + index + 1, (size - index) * sizeof(txSlot));
276
836
        array->value.array.address = chunk;
277
836
      }
278
142
      else
279
142
        array->value.array.address = C_NULL;
280
978
    }
281
1.12M
  }
282
1.29M
  return 1;
283
1.29M
}
284
285
txSlot* fxGetIndexProperty(txMachine* the, txSlot* array, txIndex index) 
286
158M
{
287
158M
  txSlot* address = array->value.array.address;
288
158M
  if (address) {
289
111M
    txIndex length = array->value.array.length;
290
111M
    txIndex size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
291
111M
    if (length == size) {
292
87.0M
      if (index < length)
293
67.3M
        return address + index;
294
87.0M
    }
295
24.6M
    else {
296
24.6M
      txSlot* result = address;
297
24.6M
      txSlot* limit = result + size;
298
24.6M
      txIndex at;
299
469M
      while (result < limit) {
300
447M
        at = *((txIndex*)result);
301
447M
        if (at == index)
302
2.97M
          return result;
303
444M
        result++;
304
444M
      }
305
24.6M
    }
306
111M
  }
307
87.9M
  return C_NULL;
308
158M
}
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
119k
{
320
119k
  if (flag & XS_EACH_NAME_FLAG) {
321
119k
    if (array->value.array.address) {
322
104k
      txSize offset = 0;
323
104k
      txSize size = (((txChunk*)(((txByte*)array->value.array.address) - sizeof(txChunk)))->size) / sizeof(txSlot);
324
23.5M
      while (offset < size) {
325
23.4M
        txSlot* slot = array->value.array.address + offset;
326
23.4M
        txIndex index = *((txIndex*)slot);
327
23.4M
        keys = fxQueueKey(the, 0, index, keys);
328
23.4M
        offset++;
329
23.4M
      }
330
104k
    }
331
119k
  }
332
119k
  return keys;
333
119k
}
334
335
txSlot* fxSetIndexProperty(txMachine* the, txSlot* instance, txSlot* array, txIndex index) 
336
16.9M
{
337
16.9M
  txSlot* address = array->value.array.address;
338
16.9M
  txSlot* chunk = address;
339
16.9M
  txIndex length = array->value.array.length;
340
16.9M
  txIndex current;
341
16.9M
  txSize size;
342
16.9M
  txSlot* result;
343
16.9M
  txSlot* limit;
344
16.9M
  txIndex at;
345
16.9M
  if (address) {
346
12.5M
    current = (((txChunk*)(((txByte*)chunk) - sizeof(txChunk)))->size) / sizeof(txSlot);
347
12.5M
    if (length == current) {
348
7.78M
      if (index < length) 
349
0
        return address + index;
350
7.78M
      if (instance->flag & XS_DONT_PATCH_FLAG)
351
0
        return C_NULL;
352
7.78M
      if (array->flag & XS_DONT_SET_FLAG)
353
1
        return C_NULL;
354
7.78M
      current++;
355
7.78M
      size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
356
7.78M
      chunk = (txSlot*)fxRenewChunk(the, address, size);
357
7.78M
      if (!chunk) {
358
1.90M
      #ifndef mxNoArrayOverallocation
359
1.90M
        if (array->ID == XS_ARRAY_BEHAVIOR) {
360
982k
          txSize capacity = fxSizeToCapacity(the, size);
361
982k
          chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
362
982k
        }
363
920k
        else
364
920k
      #endif
365
920k
          chunk = (txSlot*)fxNewChunk(the, size);
366
1.90M
        address = array->value.array.address;
367
1.90M
        c_memcpy(chunk, address, length * sizeof(txSlot));
368
1.90M
      }
369
7.78M
      result = chunk + length;
370
7.78M
    }
371
4.75M
    else {
372
4.75M
      result = address;
373
4.75M
      limit = result + current;
374
152M
      while (result < limit) {
375
150M
        at = *((txIndex*)result);
376
150M
        if (at == index)
377
0
          return result;
378
150M
        if (at > index)
379
2.12M
          break;
380
148M
        result++;
381
148M
      }
382
4.75M
      if (instance->flag & XS_DONT_PATCH_FLAG)
383
0
        return C_NULL;
384
4.75M
      if ((array->flag & XS_DONT_SET_FLAG) && (index >= length))
385
0
        return C_NULL;
386
4.75M
      at = mxPtrDiff(result - address);
387
4.75M
      current++;
388
4.75M
      size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
389
4.75M
      chunk = (txSlot*)fxNewChunk(the, size);
390
4.75M
      address = array->value.array.address;
391
4.75M
      result = address + at;
392
4.75M
      limit = address + current - 1;
393
4.75M
      if (result > address)
394
4.61M
        c_memcpy(chunk, address, (result - address) * sizeof(txSlot));
395
4.75M
      if (result < limit)
396
2.12M
        c_memcpy(chunk + (result - address) + 1, result, (limit - result) * sizeof(txSlot));
397
4.75M
      result = chunk + (result - address);
398
4.75M
    }
399
12.5M
  }
400
4.39M
  else {
401
4.39M
        if (instance->flag & XS_DONT_PATCH_FLAG)
402
0
            return C_NULL;
403
4.39M
    if ((array->flag & XS_DONT_SET_FLAG) && (index >= length))
404
0
      return C_NULL;
405
4.39M
    current = 1;
406
4.39M
    chunk = (txSlot*)fxNewChunk(the, sizeof(txSlot));
407
4.39M
    result = chunk;
408
4.39M
  }
409
16.9M
  result->next = C_NULL;
410
16.9M
  result->ID = XS_NO_ID;
411
16.9M
  result->flag = XS_NO_FLAG;
412
16.9M
  result->kind = XS_UNDEFINED_KIND;
413
16.9M
  *((txIndex*)result) = index;  
414
16.9M
  array->value.array.address = chunk;
415
16.9M
  if (index >= length) {
416
8.89M
    array->value.array.length = index + 1;
417
8.89M
  }
418
16.9M
  return result;
419
16.9M
}
420
421
void fxSetIndexSize(txMachine* the, txSlot* array, txIndex target, txBoolean growable)
422
5.43M
{
423
5.43M
  txSlot* address = array->value.array.address;
424
5.43M
  txSlot* chunk = C_NULL;
425
5.43M
  txIndex current = (address) ? (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot) : 0;
426
5.43M
  txSize size;
427
5.43M
  if (current != target) {
428
581k
    if (array->flag & XS_DONT_SET_FLAG)
429
0
      mxTypeError("set length: not writable");
430
581k
    size = fxMultiplyChunkSizes(the, target, sizeof(txSlot));
431
581k
    if (address) {
432
240k
      if (target) {
433
234k
        chunk = (txSlot*)fxRenewChunk(the, address, size);
434
234k
        if (!chunk) {
435
4.47k
        #ifndef mxNoArrayOverallocation
436
4.47k
          if (growable) {
437
4.47k
            txSize capacity = fxSizeToCapacity(the, size);
438
4.47k
            chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
439
4.47k
          }
440
1
          else
441
1
        #endif
442
1
            chunk = (txSlot*)fxNewChunk(the, size);
443
4.47k
          address = array->value.array.address;
444
4.47k
          if (current < target)
445
4.47k
            c_memcpy(chunk, address, current * sizeof(txSlot));
446
0
          else
447
0
            c_memcpy(chunk, address, size);
448
4.47k
        }
449
234k
      }
450
240k
    }
451
340k
    else {
452
340k
    #ifndef mxNoArrayOverallocation
453
340k
      if (growable) {
454
4.20k
        txSize capacity = fxSizeToCapacity(the, size);
455
4.20k
        chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
456
4.20k
      }
457
336k
      else
458
336k
    #endif
459
336k
        chunk = (txSlot*)fxNewChunk(the, size);
460
340k
    }
461
581k
    if (current < target)
462
556k
      c_memset(chunk + current, 0, (target - current) * sizeof(txSlot));
463
581k
    array->value.array.length = target;
464
581k
    array->value.array.address = chunk;
465
581k
  }
466
5.43M
}
467
468
txBoolean fxDefinePrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id, txSlot* slot, txFlag mask) 
469
29.4k
{
470
29.4k
  txSlot** address;
471
29.4k
  txSlot* property;
472
29.4k
  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
29.4k
  if (instance->flag & XS_DONT_MARSHALL_FLAG)
485
1
    return 0;
486
29.4k
#endif
487
29.4k
  address = &(instance->next);
488
35.6k
  while ((property = *address)) {
489
9.37k
    if (!(property->flag & XS_INTERNAL_FLAG)) {
490
9
      property = C_NULL;
491
9
      break;
492
9
    }
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
29.4k
  if (!property) {
501
26.2k
    property = fxNewSlot(the);
502
26.2k
    property->next = *address;
503
26.2k
    property->flag = XS_INTERNAL_FLAG;
504
26.2k
    property->kind = XS_PRIVATE_KIND;
505
26.2k
    property->value.private.check = check;
506
26.2k
    property->value.private.first = C_NULL;
507
26.2k
    *address = property;
508
26.2k
  }
509
29.4k
  address = &(property->value.private.first);
510
32.5k
  while ((property = *address)) {
511
3.12k
    if (property->ID == id)
512
0
      break;
513
3.12k
    address = &(property->next);
514
3.12k
  }
515
29.4k
  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
29.4k
  else {
557
29.4k
    if (property)
558
0
      return 0;
559
29.4k
    *address = property = fxNewSlot(the);
560
29.4k
    property->flag = (mask & XS_METHOD_FLAG) ? XS_DONT_SET_FLAG : XS_NO_FLAG;
561
29.4k
    property->ID = id;
562
29.4k
    property->kind = slot->kind;
563
29.4k
    property->value = slot->value;
564
29.4k
    if (property->kind == XS_REFERENCE_KIND) {
565
11
      txSlot* function = slot->value.reference;
566
11
      if (mxIsFunction(function)) {
567
8
        if ((mask & XS_METHOD_FLAG) && ((function->flag & XS_MARK_FLAG) == 0)) {
568
8
          txSlot* home = mxFunctionInstanceHome(function);
569
8
          home->value.home.object = instance;
570
8
        }
571
8
        if ((mask & XS_NAME_FLAG) && ((function->flag & XS_MARK_FLAG) == 0))
572
8
          fxRenameFunction(the, function, id, 0, mxID(_value), C_NULL);
573
8
      }
574
11
    }
575
29.4k
  }
576
29.4k
  return 1;
577
29.4k
}
578
579
txSlot* fxGetPrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id) 
580
18.1k
{
581
18.1k
    txSlot* result;
582
18.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
18.1k
  result = instance->next;
591
18.1k
  while (result) {
592
18.1k
    if (result->kind == XS_PRIVATE_KIND) {
593
18.1k
      if (result->value.private.check == check)
594
18.1k
        break;
595
18.1k
    }
596
8
    result = result->next;
597
8
  }
598
18.1k
  if (result) {
599
18.1k
    result = result->value.private.first;
600
18.1k
    while (result) {
601
18.1k
      if (result->ID == id)
602
18.1k
        break;
603
0
      result = result->next;
604
0
    }
605
18.1k
  }
606
18.1k
  if (result) {
607
18.1k
    if ((result->kind == XS_ACCESSOR_KIND) && (result->value.accessor.getter == C_NULL))
608
0
      result = C_NULL;
609
18.1k
  }
610
18.1k
  return result;
611
18.1k
}
612
613
txSlot* fxSetPrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id) 
614
6
{
615
6
    txSlot* result;
616
6
  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
6
  result = instance->next;
627
9
  while (result) {
628
8
    if (result->kind == XS_PRIVATE_KIND) {
629
5
      if (result->value.private.check == check)
630
5
        break;
631
5
    }
632
3
    result = result->next;
633
3
  }
634
6
  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
6
  if (result) {
643
5
    if ((result->kind == XS_ACCESSOR_KIND) && (result->value.accessor.setter == C_NULL))
644
0
      result = C_NULL;
645
5
  }
646
6
  return result;
647
6
}
648
649
void fxGroupBy(txMachine* the, txCallback aux) 
650
97
{
651
97
  txSlot *function, *iterable, *iterator, *next, *value, *slot;
652
97
  txNumber k = 0;
653
97
  if ((mxArgc < 1) || mxIsUndefined(mxArgv(0)) || mxIsUndefined(mxArgv(1)))
654
29
    mxTypeError("items: not an object");
655
68
  if ((mxArgc < 2) || (!fxIsCallable(the, mxArgv(1))))
656
40
    mxTypeError("callback: not a function");
657
28
  function = mxArgv(1);
658
28
  iterable = mxArgv(0);
659
28
  mxTemporary(iterator);
660
28
  mxTemporary(next);
661
28
  fxGetIterator(the, iterable, iterator, next, 0);
662
28
  mxTemporary(value);
663
826
  while (fxIteratorNext(the, iterator, next, value)) {
664
800
    mxTry(the) {
665
800
      if (k > C_MAX_SAFE_INTEGER)
666
0
        mxTypeError("unsafe integer");
667
800
      mxPushUndefined();
668
800
      mxPushSlot(function);
669
800
      mxCall();
670
800
      mxPushSlot(value);
671
800
      mxPushNumber(k);
672
800
      mxRunCount(2);
673
800
      aux(the);
674
800
      slot = the->stack->value.reference->next;
675
800
      slot->value.array.length++;
676
41.2k
      while (slot->next)
677
40.4k
        slot = slot->next;
678
800
      slot->next = fxDuplicateSlot(the, value);
679
800
      mxPop();
680
800
      mxPop();
681
800
      k++;
682
800
    }
683
800
    mxCatch(the) {
684
2
      fxIteratorReturn(the, iterator, 1);
685
2
      fxJump(the);
686
2
    }
687
800
  }
688
26
  mxPop();
689
26
  mxPop();
690
26
  mxPop();
691
26
}
692
693
694
695
696
697