Coverage Report

Created: 2026-03-16 06:17

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
84.7M
{
42
84.7M
  txSlot* property;
43
250M
  while ((property = slot->next))
44
165M
    slot = property;
45
84.7M
  return slot;
46
84.7M
}
47
48
#ifndef mxLink
49
txSlot* fxNextHostAccessorProperty(txMachine* the, txSlot* property, txCallback get, txCallback set, txID id, txFlag flag)
50
1.28M
{
51
1.28M
  txSlot *getter = NULL, *setter = NULL, *home = the->stack, *slot;
52
1.28M
  if (get) {
53
1.28M
    getter = fxBuildHostFunction(the, get, 0, XS_NO_ID);
54
1.28M
    slot = mxFunctionInstanceHome(getter);
55
1.28M
    slot->value.home.object = home->value.reference;
56
1.28M
    fxRenameFunction(the, getter, id, 0, XS_NO_ID, "get ");
57
1.28M
  }
58
1.28M
  if (set) {
59
107k
    setter = fxBuildHostFunction(the, set, 1, XS_NO_ID);
60
107k
    slot = mxFunctionInstanceHome(setter);
61
107k
    slot->value.home.object = home->value.reference;
62
107k
    fxRenameFunction(the, setter, id, 0, XS_NO_ID, "set ");
63
107k
  }
64
1.28M
  property = property->next = fxNewSlot(the);
65
1.28M
  property->flag = flag;
66
1.28M
  property->ID = id;
67
1.28M
  property->kind = XS_ACCESSOR_KIND;
68
1.28M
  property->value.accessor.getter = getter;
69
1.28M
  property->value.accessor.setter = setter;
70
1.28M
  if (set)
71
107k
    mxPop();
72
1.28M
  if (get)
73
1.28M
    mxPop();
74
1.28M
  return property;
75
1.28M
}
76
77
txSlot* fxNextHostFunctionProperty(txMachine* the, txSlot* property, txCallback call, txInteger length, txID id, txFlag flag)
78
12.1M
{
79
12.1M
  txSlot *function, *home = the->stack, *slot;
80
12.1M
  function = fxNewHostFunction(the, call, length, id, XS_NO_ID);
81
12.1M
  slot = mxFunctionInstanceHome(function);
82
12.1M
  slot->value.home.object = home->value.reference;
83
12.1M
  property = property->next = fxNewSlot(the);
84
12.1M
  property->flag = flag;
85
12.1M
  property->ID = id;
86
12.1M
  property->kind = the->stack->kind;
87
12.1M
  property->value = the->stack->value;
88
12.1M
  mxPop();
89
12.1M
  return property;
90
12.1M
}
91
#endif
92
93
txSlot* fxNextUndefinedProperty(txMachine* the, txSlot* property, txID id, txFlag flag)
94
1.83M
{
95
1.83M
  property = property->next = fxNewSlot(the);
96
1.83M
  property->flag = flag;
97
1.83M
  property->ID = id;
98
1.83M
  property->kind = XS_UNDEFINED_KIND;
99
1.83M
  return property;
100
1.83M
}
101
102
txSlot* fxNextNullProperty(txMachine* the, txSlot* property, txID id, txFlag flag)
103
184k
{
104
184k
  property = property->next = fxNewSlot(the);
105
184k
  property->flag = flag;
106
184k
  property->ID = id;
107
184k
  property->kind = XS_NULL_KIND;
108
184k
  return property;
109
184k
}
110
111
txSlot* fxNextBooleanProperty(txMachine* the, txSlot* property, txBoolean boolean, txID id, txFlag flag)
112
2.15M
{
113
2.15M
  property = property->next = fxNewSlot(the);
114
2.15M
  property->flag = flag;
115
2.15M
  property->ID = id;
116
2.15M
  property->kind = XS_BOOLEAN_KIND;
117
2.15M
  property->value.boolean = boolean;
118
2.15M
  return property;
119
2.15M
}
120
121
txSlot* fxNextIntegerProperty(txMachine* the, txSlot* property, txInteger integer, txID id, txFlag flag)
122
26.1M
{
123
26.1M
  property = property->next = fxNewSlot(the);
124
26.1M
  property->flag = flag;
125
26.1M
  property->ID = id;
126
26.1M
  property->kind = XS_INTEGER_KIND;
127
26.1M
  property->value.integer = integer;
128
26.1M
  return property;
129
26.1M
}
130
131
txSlot* fxNextNumberProperty(txMachine* the, txSlot* property, txNumber number, txID id, txFlag flag)
132
10.9M
{
133
10.9M
  property = property->next = fxNewSlot(the);
134
10.9M
  property->flag = flag;
135
10.9M
  property->ID = id;
136
10.9M
  property->kind = XS_NUMBER_KIND;
137
10.9M
  property->value.number = number;
138
10.9M
  return property;
139
10.9M
}
140
141
txSlot* fxNextReferenceProperty(txMachine* the, txSlot* property, txSlot* slot, txID id, txFlag flag)
142
113k
{
143
113k
  property = property->next = fxNewSlot(the);
144
113k
  property->flag = flag;
145
113k
  property->ID = id;
146
113k
  property->kind = XS_REFERENCE_KIND;
147
113k
  property->value.reference = slot;
148
113k
  return property;
149
113k
}
150
151
txSlot* fxNextSlotProperty(txMachine* the, txSlot* property, txSlot* slot, txID id, txFlag flag)
152
76.4M
{
153
76.4M
  property = property->next = fxNewSlot(the);
154
76.4M
  property->flag = flag;
155
76.4M
  property->ID = id;
156
76.4M
  property->kind = slot->kind;
157
76.4M
  property->value = slot->value;
158
76.4M
  return property;
159
76.4M
}
160
161
txSlot* fxNextStringProperty(txMachine* the, txSlot* property, txString string, txID id, txFlag flag)
162
1.37M
{
163
1.37M
  property = property->next = fxNewSlot(the);
164
1.37M
  property->flag = flag;
165
1.37M
  property->ID = id;
166
1.37M
  fxCopyStringC(the, property, string);
167
1.37M
  return property;
168
1.37M
}
169
170
txSlot* fxNextStringXProperty(txMachine* the, txSlot* property, txString string, txID id, txFlag flag)
171
1.79M
{
172
1.79M
  property = property->next = fxNewSlot(the);
173
1.79M
  property->flag = flag;
174
1.79M
  property->ID = id;
175
1.79M
#ifdef mxSnapshot
176
1.79M
  fxCopyStringC(the, property, string);
177
#else
178
  property->kind = XS_STRING_X_KIND;
179
  property->value.string = string;
180
#endif
181
1.79M
  return property;
182
1.79M
}
183
184
185
txSlot* fxNextSymbolProperty(txMachine* the, txSlot* property, txID symbol, txID id, txFlag flag)
186
935k
{
187
935k
  property = property->next = fxNewSlot(the);
188
935k
  property->flag = flag;
189
935k
  property->ID = id;
190
935k
  property->kind = XS_SYMBOL_KIND;
191
935k
  property->value.symbol = symbol;
192
935k
  return property;
193
935k
}
194
195
txSlot* fxNextTypeDispatchProperty(txMachine* the, txSlot* property, txTypeDispatch* dispatch, txTypeAtomics* atomics, txID id, txFlag flag)
196
469k
{
197
469k
  property = property->next = fxNewSlot(the);
198
469k
  property->flag = flag;
199
469k
  property->ID = id;
200
469k
  property->kind = XS_TYPED_ARRAY_KIND;
201
469k
  property->value.typedArray.dispatch = dispatch;
202
469k
  property->value.typedArray.atomics = atomics;
203
469k
  return property;
204
469k
}
205
206
txSlot* fxQueueKey(txMachine* the, txID id, txIndex index, txSlot* keys)
207
48.0M
{
208
48.0M
  keys = keys->next = fxNewSlot(the);
209
48.0M
  keys->kind = XS_AT_KIND;
210
48.0M
  keys->value.at.id = id;
211
48.0M
  keys->value.at.index = index;
212
48.0M
  return keys;
213
48.0M
}
214
215
txSlot* fxQueueIDKeys(txMachine* the, txSlot* first, txFlag flag, txSlot* keys)
216
950k
{
217
950k
  if (flag & XS_EACH_NAME_FLAG) {
218
950k
    txSlot* property = first;
219
7.20M
    while (property) {
220
6.25M
      if (!(property->flag & XS_INTERNAL_FLAG) && fxIsKeyName(the, property->ID))
221
5.92M
        keys = fxQueueKey(the, property->ID, 0, keys);
222
6.25M
      property = property->next;
223
6.25M
    }
224
950k
  }
225
950k
  if (flag & XS_EACH_SYMBOL_FLAG) {
226
40.7k
    txSlot* property = first;
227
143k
    while (property) {
228
103k
      if (!(property->flag & XS_INTERNAL_FLAG) && fxIsKeySymbol(the, property->ID))
229
2.96k
        keys = fxQueueKey(the, property->ID, 0, keys);
230
103k
      property = property->next;
231
103k
    }
232
40.7k
  }
233
950k
  return keys;
234
950k
}
235
236
// INDEX
237
238
static txSize fxSizeToCapacity(txMachine* the, txSize size)
239
2.42M
{
240
2.42M
  return fxAddChunkSizes(the, size, size / 3);
241
2.42M
}
242
243
txBoolean fxDeleteIndexProperty(txMachine* the, txSlot* array, txIndex index) 
244
1.22M
{
245
1.22M
  txSlot* address = array->value.array.address;
246
1.22M
  if (address) {
247
942k
    txIndex length = array->value.array.length;
248
942k
    txIndex size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
249
942k
    txSlot* result = address;
250
942k
    txSlot* limit = result + size;
251
942k
    if (length == size)
252
437
      result = address + index;
253
942k
    else {
254
942k
      txIndex at;
255
2.50M
      while (result < limit) {
256
1.69M
        at = *((txIndex*)result);
257
1.69M
        if (at == index)
258
557
          break;
259
1.69M
        if (at > index)
260
136k
          return 1;
261
1.56M
        result++;
262
1.56M
      }
263
942k
    }
264
805k
    if (result < limit) {
265
618
      if (result->flag & XS_DONT_DELETE_FLAG)
266
3
        return 0;
267
615
      index = (txIndex)(result - address);
268
615
      size--;
269
615
      if (size > 0) {
270
481
        txSlot* chunk = (txSlot*)fxNewChunk(the, size * sizeof(txSlot));
271
481
        address = array->value.array.address;
272
481
        if (index > 0)
273
357
          c_memcpy(chunk, address, index * sizeof(txSlot));
274
481
        if (index < size)
275
260
          c_memcpy(chunk + index, address + index + 1, (size - index) * sizeof(txSlot));
276
481
        array->value.array.address = chunk;
277
481
      }
278
134
      else
279
134
        array->value.array.address = C_NULL;
280
615
    }
281
805k
  }
282
1.09M
  return 1;
283
1.22M
}
284
285
txSlot* fxGetIndexProperty(txMachine* the, txSlot* array, txIndex index) 
286
186M
{
287
186M
  txSlot* address = array->value.array.address;
288
186M
  if (address) {
289
146M
    txIndex length = array->value.array.length;
290
146M
    txIndex size = (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot);
291
146M
    if (length == size) {
292
119M
      if (index < length)
293
83.5M
        return address + index;
294
119M
    }
295
26.5M
    else {
296
26.5M
      txSlot* result = address;
297
26.5M
      txSlot* limit = result + size;
298
26.5M
      txIndex at;
299
516M
      while (result < limit) {
300
492M
        at = *((txIndex*)result);
301
492M
        if (at == index)
302
3.12M
          return result;
303
489M
        result++;
304
489M
      }
305
26.5M
    }
306
146M
  }
307
99.7M
  return C_NULL;
308
186M
}
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
102k
      txSize offset = 0;
323
102k
      txSize size = (((txChunk*)(((txByte*)array->value.array.address) - sizeof(txChunk)))->size) / sizeof(txSlot);
324
27.6M
      while (offset < size) {
325
27.5M
        txSlot* slot = array->value.array.address + offset;
326
27.5M
        txIndex index = *((txIndex*)slot);
327
27.5M
        keys = fxQueueKey(the, 0, index, keys);
328
27.5M
        offset++;
329
27.5M
      }
330
102k
    }
331
119k
  }
332
119k
  return keys;
333
119k
}
334
335
txSlot* fxSetIndexProperty(txMachine* the, txSlot* instance, txSlot* array, txIndex index) 
336
26.6M
{
337
26.6M
  txSlot* address = array->value.array.address;
338
26.6M
  txSlot* chunk = address;
339
26.6M
  txIndex length = array->value.array.length;
340
26.6M
  txIndex current;
341
26.6M
  txSize size;
342
26.6M
  txSlot* result;
343
26.6M
  txSlot* limit;
344
26.6M
  txIndex at;
345
26.6M
  if (address) {
346
21.6M
    current = (((txChunk*)(((txByte*)chunk) - sizeof(txChunk)))->size) / sizeof(txSlot);
347
21.6M
    if (length == current) {
348
16.8M
      if (index < length) 
349
0
        return address + index;
350
16.8M
      if (instance->flag & XS_DONT_PATCH_FLAG)
351
0
        return C_NULL;
352
16.8M
      if (array->flag & XS_DONT_SET_FLAG)
353
1
        return C_NULL;
354
16.8M
      current++;
355
16.8M
      size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
356
16.8M
      chunk = (txSlot*)fxRenewChunk(the, address, size);
357
16.8M
      if (!chunk) {
358
4.12M
      #ifndef mxNoArrayOverallocation
359
4.12M
        if (array->ID == XS_ARRAY_BEHAVIOR) {
360
2.41M
          txSize capacity = fxSizeToCapacity(the, size);
361
2.41M
          chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
362
2.41M
        }
363
1.71M
        else
364
1.71M
      #endif
365
1.71M
          chunk = (txSlot*)fxNewChunk(the, size);
366
4.12M
        address = array->value.array.address;
367
4.12M
        c_memcpy(chunk, address, length * sizeof(txSlot));
368
4.12M
      }
369
16.8M
      result = chunk + length;
370
16.8M
    }
371
4.81M
    else {
372
4.81M
      result = address;
373
4.81M
      limit = result + current;
374
250M
      while (result < limit) {
375
248M
        at = *((txIndex*)result);
376
248M
        if (at == index)
377
0
          return result;
378
248M
        if (at > index)
379
2.17M
          break;
380
245M
        result++;
381
245M
      }
382
4.81M
      if (instance->flag & XS_DONT_PATCH_FLAG)
383
0
        return C_NULL;
384
4.81M
      if ((array->flag & XS_DONT_SET_FLAG) && (index >= length))
385
0
        return C_NULL;
386
4.81M
      at = mxPtrDiff(result - address);
387
4.81M
      current++;
388
4.81M
      size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
389
4.81M
      chunk = (txSlot*)fxNewChunk(the, size);
390
4.81M
      address = array->value.array.address;
391
4.81M
      result = address + at;
392
4.81M
      limit = address + current - 1;
393
4.81M
      if (result > address)
394
4.17M
        c_memcpy(chunk, address, (result - address) * sizeof(txSlot));
395
4.81M
      if (result < limit)
396
2.17M
        c_memcpy(chunk + (result - address) + 1, result, (limit - result) * sizeof(txSlot));
397
4.81M
      result = chunk + (result - address);
398
4.81M
    }
399
21.6M
  }
400
5.00M
  else {
401
5.00M
        if (instance->flag & XS_DONT_PATCH_FLAG)
402
0
            return C_NULL;
403
5.00M
    if ((array->flag & XS_DONT_SET_FLAG) && (index >= length))
404
0
      return C_NULL;
405
5.00M
    current = 1;
406
5.00M
    chunk = (txSlot*)fxNewChunk(the, sizeof(txSlot));
407
5.00M
    result = chunk;
408
5.00M
  }
409
26.6M
  result->next = C_NULL;
410
26.6M
  result->ID = XS_NO_ID;
411
26.6M
  result->flag = XS_NO_FLAG;
412
26.6M
  result->kind = XS_UNDEFINED_KIND;
413
26.6M
  *((txIndex*)result) = index;  
414
26.6M
  array->value.array.address = chunk;
415
26.6M
  if (index >= length) {
416
18.0M
    array->value.array.length = index + 1;
417
18.0M
  }
418
26.6M
  return result;
419
26.6M
}
420
421
void fxSetIndexSize(txMachine* the, txSlot* array, txIndex target, txBoolean growable)
422
6.82M
{
423
6.82M
  txSlot* address = array->value.array.address;
424
6.82M
  txSlot* chunk = C_NULL;
425
6.82M
  txIndex current = (address) ? (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot) : 0;
426
6.82M
  txSize size;
427
6.82M
  if (current != target) {
428
977k
    if (array->flag & XS_DONT_SET_FLAG)
429
0
      mxTypeError("set length: not writable");
430
977k
    size = fxMultiplyChunkSizes(the, target, sizeof(txSlot));
431
977k
    if (address) {
432
213k
      if (target) {
433
208k
        chunk = (txSlot*)fxRenewChunk(the, address, size);
434
208k
        if (!chunk) {
435
4.71k
        #ifndef mxNoArrayOverallocation
436
4.71k
          if (growable) {
437
4.71k
            txSize capacity = fxSizeToCapacity(the, size);
438
4.71k
            chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
439
4.71k
          }
440
3
          else
441
3
        #endif
442
3
            chunk = (txSlot*)fxNewChunk(the, size);
443
4.71k
          address = array->value.array.address;
444
4.71k
          if (current < target)
445
4.71k
            c_memcpy(chunk, address, current * sizeof(txSlot));
446
0
          else
447
0
            c_memcpy(chunk, address, size);
448
4.71k
        }
449
208k
      }
450
213k
    }
451
763k
    else {
452
763k
    #ifndef mxNoArrayOverallocation
453
763k
      if (growable) {
454
4.41k
        txSize capacity = fxSizeToCapacity(the, size);
455
4.41k
        chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
456
4.41k
      }
457
759k
      else
458
759k
    #endif
459
759k
        chunk = (txSlot*)fxNewChunk(the, size);
460
763k
    }
461
977k
    if (current < target)
462
958k
      c_memset(chunk + current, 0, (target - current) * sizeof(txSlot));
463
977k
    array->value.array.length = target;
464
977k
    array->value.array.address = chunk;
465
977k
  }
466
6.82M
}
467
468
txBoolean fxDefinePrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id, txSlot* slot, txFlag mask) 
469
29.8k
{
470
29.8k
  txSlot** address;
471
29.8k
  txSlot* property;
472
29.8k
  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.8k
  if (instance->flag & XS_DONT_MARSHALL_FLAG)
485
1
    return 0;
486
29.8k
#endif
487
29.8k
  address = &(instance->next);
488
36.0k
  while ((property = *address)) {
489
9.39k
    if (!(property->flag & XS_INTERNAL_FLAG)) {
490
17
      property = C_NULL;
491
17
      break;
492
17
    }
493
9.37k
    if (property->kind == XS_PRIVATE_KIND) {
494
3.12k
      if (property->value.private.check == check) {
495
3.12k
        break;
496
3.12k
      }
497
3.12k
    }
498
6.25k
    address = &(property->next);
499
6.25k
  }
500
29.8k
  if (!property) {
501
26.7k
    property = fxNewSlot(the);
502
26.7k
    property->next = *address;
503
26.7k
    property->flag = XS_INTERNAL_FLAG;
504
26.7k
    property->kind = XS_PRIVATE_KIND;
505
26.7k
    property->value.private.check = check;
506
26.7k
    property->value.private.first = C_NULL;
507
26.7k
    *address = property;
508
26.7k
  }
509
29.8k
  address = &(property->value.private.first);
510
32.9k
  while ((property = *address)) {
511
3.12k
    if (property->ID == id)
512
0
      break;
513
3.12k
    address = &(property->next);
514
3.12k
  }
515
29.8k
  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.8k
  else {
557
29.8k
    if (property)
558
0
      return 0;
559
29.8k
    *address = property = fxNewSlot(the);
560
29.8k
    property->flag = (mask & XS_METHOD_FLAG) ? XS_DONT_SET_FLAG : XS_NO_FLAG;
561
29.8k
    property->ID = id;
562
29.8k
    property->kind = slot->kind;
563
29.8k
    property->value = slot->value;
564
29.8k
    if (property->kind == XS_REFERENCE_KIND) {
565
14
      txSlot* function = slot->value.reference;
566
14
      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
14
    }
575
29.8k
  }
576
29.8k
  return 1;
577
29.8k
}
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
37
    result = result->next;
597
37
  }
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
48
{
651
48
  txSlot *function, *iterable, *iterator, *next, *value, *slot;
652
48
  txNumber k = 0;
653
48
  if ((mxArgc < 1) || mxIsUndefined(mxArgv(0)) || mxIsUndefined(mxArgv(1)))
654
9
    mxTypeError("items: not an object");
655
39
  if ((mxArgc < 2) || (!fxIsCallable(the, mxArgv(1))))
656
16
    mxTypeError("callback: not a function");
657
23
  function = mxArgv(1);
658
23
  iterable = mxArgv(0);
659
23
  mxTemporary(iterator);
660
23
  mxTemporary(next);
661
23
  fxGetIterator(the, iterable, iterator, next, 0);
662
23
  mxTemporary(value);
663
275
  while (fxIteratorNext(the, iterator, next, value)) {
664
253
    mxTry(the) {
665
253
      if (k > C_MAX_SAFE_INTEGER)
666
0
        mxTypeError("unsafe integer");
667
253
      mxPushUndefined();
668
253
      mxPushSlot(function);
669
253
      mxCall();
670
253
      mxPushSlot(value);
671
253
      mxPushNumber(k);
672
253
      mxRunCount(2);
673
253
      aux(the);
674
253
      slot = the->stack->value.reference->next;
675
253
      slot->value.array.length++;
676
10.5k
      while (slot->next)
677
10.2k
        slot = slot->next;
678
253
      slot->next = fxDuplicateSlot(the, value);
679
253
      mxPop();
680
253
      mxPop();
681
253
      k++;
682
253
    }
683
253
    mxCatch(the) {
684
1
      fxIteratorReturn(the, iterator, 1);
685
1
      fxJump(the);
686
1
    }
687
253
  }
688
22
  mxPop();
689
22
  mxPop();
690
22
  mxPop();
691
22
}
692
693
694
695
696
697