@oseo/runtime-c 0.0.0-stage → 0.1.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +674 -0
  2. package/MIT-LICENSE.txt +21 -0
  3. package/README.md +1677 -2
  4. package/UNICODE-LICENSE.txt +39 -0
  5. package/dist/index.d.ts +7 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +269 -0
  8. package/dist/index.js.map +1 -0
  9. package/native/oseo_runtime.h +2594 -0
  10. package/native/runtime_agent.c +1693 -0
  11. package/native/runtime_arguments.c +355 -0
  12. package/native/runtime_array.c +5742 -0
  13. package/native/runtime_array_buffer.c +1724 -0
  14. package/native/runtime_async_generator.c +948 -0
  15. package/native/runtime_atomics.c +1259 -0
  16. package/native/runtime_bigint.c +1363 -0
  17. package/native/runtime_bigint_object.c +602 -0
  18. package/native/runtime_binding.c +1005 -0
  19. package/native/runtime_boolean.c +296 -0
  20. package/native/runtime_clock.c +157 -0
  21. package/native/runtime_clock_posix.c +575 -0
  22. package/native/runtime_core.c +464 -0
  23. package/native/runtime_data_view.c +1111 -0
  24. package/native/runtime_date.c +1973 -0
  25. package/native/runtime_descriptor.c +1080 -0
  26. package/native/runtime_disposal.c +1643 -0
  27. package/native/runtime_enumeration.c +612 -0
  28. package/native/runtime_error.c +973 -0
  29. package/native/runtime_event_loop.c +629 -0
  30. package/native/runtime_function.c +3643 -0
  31. package/native/runtime_generator.c +1096 -0
  32. package/native/runtime_internal.h +5554 -0
  33. package/native/runtime_iterator.c +5355 -0
  34. package/native/runtime_json.c +1968 -0
  35. package/native/runtime_map.c +1539 -0
  36. package/native/runtime_math.c +894 -0
  37. package/native/runtime_memory.c +1341 -0
  38. package/native/runtime_module.c +860 -0
  39. package/native/runtime_number.c +2053 -0
  40. package/native/runtime_object.c +399 -0
  41. package/native/runtime_object_builtin.c +3877 -0
  42. package/native/runtime_primitive.c +2244 -0
  43. package/native/runtime_process.c +720 -0
  44. package/native/runtime_promise.c +3354 -0
  45. package/native/runtime_property.c +791 -0
  46. package/native/runtime_proxy.c +1533 -0
  47. package/native/runtime_realm.c +411 -0
  48. package/native/runtime_reflect.c +624 -0
  49. package/native/runtime_regexp.c +3495 -0
  50. package/native/runtime_regexp_matcher.c +3535 -0
  51. package/native/runtime_regexp_symbol.c +1471 -0
  52. package/native/runtime_set.c +1751 -0
  53. package/native/runtime_string.c +2862 -0
  54. package/native/runtime_string_match.c +1161 -0
  55. package/native/runtime_symbol.c +986 -0
  56. package/native/runtime_typed_array.c +5113 -0
  57. package/native/runtime_unicode_tables.h +14647 -0
  58. package/native/runtime_uri.c +676 -0
  59. package/native/runtime_weak_collection.c +1275 -0
  60. package/package.json +38 -3
@@ -0,0 +1,791 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /* Copyright (c) 2026 Hong Minhee; see ../MIT-LICENSE.txt. */
3
+
4
+ #include "runtime_internal.h"
5
+
6
+ /*
7
+ * The generic property access paths: [[Get]] and its `super` form,
8
+ * [[Set]] and its `super` form, and HasOwnProperty.
9
+ */
10
+
11
+ static OseoResult type_error(OseoContext *context, const char *message) {
12
+ return oseo_internal_throw_error(context, OSEO_ERROR_TYPE, message);
13
+ }
14
+
15
+ /*
16
+ * The TypedArray [[Set]] prelude for a view reached on
17
+ * a set walk, whether the view is the receiver itself or a prototype of
18
+ * an ordinary receiver. `*answered` reports that the view settled the
19
+ * write: a canonical numeric key performs TypedArraySetElement when the
20
+ * view is the receiver, and an invalid index with a foreign receiver
21
+ * reports true without writing anywhere. `*element` reports a valid
22
+ * index with a foreign receiver, whose ordinary descriptor is always a
23
+ * writable data property, so the caller stops the walk and writes to the
24
+ * receiver. Any other key leaves both flags clear and the walk continues
25
+ * ordinarily.
26
+ */
27
+ static OseoResult typed_array_set_step(
28
+ OseoContext *context,
29
+ OseoValue view,
30
+ OseoValue key,
31
+ OseoValue value,
32
+ OseoValue receiver,
33
+ bool *answered,
34
+ bool *element
35
+ ) {
36
+ *answered = false;
37
+ *element = false;
38
+ bool numeric = false;
39
+ size_t typed_index = SIZE_MAX;
40
+ OseoResult classified = oseo_internal_typed_array_numeric_key(
41
+ context,
42
+ key,
43
+ &numeric,
44
+ &typed_index
45
+ );
46
+ if (classified.status != OSEO_STATUS_NORMAL || !numeric) {
47
+ return classified.status == OSEO_STATUS_NORMAL
48
+ ? normal(value)
49
+ : classified;
50
+ }
51
+ if (view == receiver) {
52
+ bool present = false;
53
+ OseoResult stored = oseo_internal_typed_array_set_index(
54
+ context,
55
+ view,
56
+ typed_index,
57
+ value,
58
+ &present
59
+ );
60
+ if (stored.status != OSEO_STATUS_NORMAL) return stored;
61
+ *answered = true;
62
+ return normal(value);
63
+ }
64
+ if (!oseo_internal_typed_array_has_index(view, typed_index)) {
65
+ *answered = true;
66
+ return normal(value);
67
+ }
68
+ *element = true;
69
+ return normal(value);
70
+ }
71
+
72
+ OseoResult oseo_internal_require_property_key(
73
+ OseoContext *context,
74
+ OseoValue key
75
+ ) {
76
+ if (!is_string(key) && !is_symbol(key)) {
77
+ return failure(
78
+ context,
79
+ "OSEO2001",
80
+ "Property key is not a string or symbol."
81
+ );
82
+ }
83
+ return normal(key);
84
+ }
85
+
86
+ /*
87
+ * The shared body of Get and its `super` form. `object_value` is where
88
+ * the lookup starts and `receiver` is what a getter receives as `this`;
89
+ * the two differ only for a `super` reference.
90
+ */
91
+
92
+ static OseoResult object_get(
93
+ OseoContext *context,
94
+ OseoValue object_value,
95
+ OseoValue key,
96
+ OseoValue receiver
97
+ ) {
98
+ OseoResult valid = oseo_internal_require_property_key(context, key);
99
+ if (valid.status != OSEO_STATUS_NORMAL) return valid;
100
+ if (!is_object(object_value)) {
101
+ if (is_nullish(object_value)) {
102
+ return type_error(
103
+ context,
104
+ "Cannot read properties of a nullish value."
105
+ );
106
+ }
107
+ if (is_string(object_value) &&
108
+ oseo_internal_string_is_ascii(key, "length")) {
109
+ return normal(oseo_number(string_object(object_value)->length));
110
+ }
111
+ uint32_t index = 0u;
112
+ if (oseo_internal_string_own_property(object_value, key, &index)) {
113
+ uint16_t unit = string_object(object_value)->units[index];
114
+ return oseo_internal_allocate_string(context, &unit, 1u);
115
+ }
116
+ OseoValue slots[3] = {object_value, key, receiver};
117
+ OseoRootFrame frame = {NULL, slots, 3u};
118
+ oseo_roots_push(context, &frame);
119
+ OseoResult boxed = oseo_internal_to_object_for_property(
120
+ context,
121
+ slots[0]
122
+ );
123
+ slots[0] = boxed.value;
124
+ if (boxed.status == OSEO_STATUS_NORMAL) {
125
+ boxed = object_get(context, slots[0], slots[1], slots[2]);
126
+ }
127
+ oseo_roots_pop(context, &frame);
128
+ return boxed;
129
+ }
130
+ OseoValue current = object_value;
131
+ while (is_object(current)) {
132
+ if (is_proxy(current)) {
133
+ return oseo_internal_proxy_get(
134
+ context, current, key, receiver);
135
+ }
136
+ if (is_typed_array(current)) {
137
+ /* A view's [[Get]] answers every canonical numeric
138
+ * key itself, so an invalid index never reaches the prototype. */
139
+ bool numeric = false;
140
+ bool present = false;
141
+ OseoResult element = oseo_internal_typed_array_own_property(
142
+ context,
143
+ current,
144
+ key,
145
+ &numeric,
146
+ &present
147
+ );
148
+ if (element.status != OSEO_STATUS_NORMAL || numeric) {
149
+ return element;
150
+ }
151
+ }
152
+ OseoOrdinaryObject *object = ordinary_object(current);
153
+ OseoValue value = oseo_undefined();
154
+ OseoPropertyAttributes attributes = {false, false, false, false};
155
+ OseoValue getter = oseo_undefined();
156
+ OseoValue setter = oseo_undefined();
157
+ if (oseo_internal_own_property_descriptor(
158
+ context, current, key, &value, &attributes,
159
+ &getter, &setter)) {
160
+ if (attributes.accessor) {
161
+ if (!is_callable(getter)) return normal(oseo_undefined());
162
+ OseoRootFrame frame = {NULL, NULL, 0u};
163
+ OseoResult result = oseo_roots_allocate(context, &frame, 1u);
164
+ if (result.status != OSEO_STATUS_NORMAL) return result;
165
+ frame.slots[0] = getter;
166
+ result = oseo_call_function(
167
+ context,
168
+ frame.slots[0],
169
+ receiver,
170
+ 0u,
171
+ NULL,
172
+ oseo_undefined()
173
+ );
174
+ oseo_roots_release(context, &frame);
175
+ return result;
176
+ }
177
+ if (oseo_internal_cell_backed_property(current, value)) {
178
+ return oseo_cell_get(context, value);
179
+ }
180
+ return oseo_internal_legacy_value(context, current, key, value);
181
+ }
182
+ current = object->prototype;
183
+ }
184
+ return normal(oseo_undefined());
185
+ }
186
+
187
+ OseoResult oseo_object_get(
188
+ OseoContext *context,
189
+ OseoValue object_value,
190
+ OseoValue key
191
+ ) {
192
+ return object_get(context, object_value, key, object_value);
193
+ }
194
+
195
+ OseoResult oseo_super_get(
196
+ OseoContext *context,
197
+ OseoValue base,
198
+ OseoValue key,
199
+ OseoValue receiver
200
+ ) {
201
+ return object_get(context, base, key, receiver);
202
+ }
203
+
204
+ OseoResult oseo_object_has_own(
205
+ OseoContext *context,
206
+ OseoValue object_value,
207
+ OseoValue key
208
+ ) {
209
+ OseoResult valid = oseo_internal_require_property_key(context, key);
210
+ if (valid.status != OSEO_STATUS_NORMAL) return valid;
211
+ if (!is_object(object_value)) {
212
+ if (is_nullish(object_value)) {
213
+ return type_error(
214
+ context,
215
+ "Cannot convert a nullish value to an object."
216
+ );
217
+ }
218
+ return normal(oseo_boolean(oseo_internal_string_own_property(
219
+ object_value,
220
+ key,
221
+ NULL
222
+ )));
223
+ }
224
+ if (is_typed_array(object_value)) {
225
+ bool numeric = false;
226
+ size_t index = SIZE_MAX;
227
+ OseoResult classified = oseo_internal_typed_array_numeric_key(
228
+ context,
229
+ key,
230
+ &numeric,
231
+ &index
232
+ );
233
+ if (classified.status != OSEO_STATUS_NORMAL) return classified;
234
+ if (numeric) {
235
+ return normal(oseo_boolean(
236
+ oseo_internal_typed_array_has_index(object_value, index)
237
+ ));
238
+ }
239
+ }
240
+ /* The shared descriptor primitive already reports a function's
241
+ * `prototype`, an array's `length`, and the virtual String iterator,
242
+ * so the ownership answer never needs a separate synthetic case. */
243
+ OseoValue value = oseo_undefined();
244
+ OseoPropertyAttributes attributes = {false, false, false, false};
245
+ OseoValue getter = oseo_undefined();
246
+ OseoValue setter = oseo_undefined();
247
+ if (is_proxy(object_value)) {
248
+ bool found = false;
249
+ OseoResult result = oseo_internal_proxy_get_own_property(
250
+ context,
251
+ object_value,
252
+ key,
253
+ &found,
254
+ &value,
255
+ &attributes,
256
+ &getter,
257
+ &setter
258
+ );
259
+ if (result.status != OSEO_STATUS_NORMAL) return result;
260
+ return normal(oseo_boolean(found));
261
+ }
262
+ bool exists = oseo_internal_own_property_descriptor(
263
+ context,
264
+ object_value,
265
+ key,
266
+ &value,
267
+ &attributes,
268
+ &getter,
269
+ &setter
270
+ );
271
+ if (!exists) return normal(oseo_boolean(false));
272
+ OseoResult ready = oseo_internal_namespace_export_ready(
273
+ context, object_value, value);
274
+ if (ready.status != OSEO_STATUS_NORMAL) return ready;
275
+ return normal(oseo_boolean(true));
276
+ }
277
+
278
+ OseoResult oseo_object_set(
279
+ OseoContext *context,
280
+ OseoValue object_value,
281
+ OseoValue key,
282
+ OseoValue value,
283
+ bool strict
284
+ ) {
285
+ if (object_value == context->realm->global_lexicals &&
286
+ is_object(object_value)) {
287
+ size_t index = oseo_internal_own_property_index(
288
+ ordinary_object(object_value), key);
289
+ if (index != SIZE_MAX) {
290
+ OseoProperty *property =
291
+ &ordinary_object(object_value)->properties[index];
292
+ OseoResult read = oseo_cell_get(context, property->value);
293
+ if (read.status != OSEO_STATUS_NORMAL) return read;
294
+ if (!property->attributes.writable) {
295
+ return type_error(context, "Assignment to a constant binding.");
296
+ }
297
+ return oseo_cell_set(context, property->value, value);
298
+ }
299
+ }
300
+ OseoResult valid = oseo_internal_require_property_key(context, key);
301
+ if (valid.status != OSEO_STATUS_NORMAL) return valid;
302
+ if (!is_object(object_value)) {
303
+ if (is_nullish(object_value)) {
304
+ return type_error(
305
+ context,
306
+ "Cannot set properties of a nullish or primitive value."
307
+ );
308
+ }
309
+ /* PutValue uses ToObject only for lookup. Keep GetThisValue's
310
+ * primitive receiver, including across Proxy dispatch and a
311
+ * setter's call into its own realm. Full String wrappers retain
312
+ * the non-writable own index and length descriptors. */
313
+ OseoValue slots[4] = {object_value, key, value, oseo_undefined()};
314
+ OseoRootFrame frame = {NULL, slots, 4u};
315
+ oseo_roots_push(context, &frame);
316
+ OseoResult result = oseo_internal_to_object(context, slots[0]);
317
+ slots[3] = result.value;
318
+ const char *refusal = NULL;
319
+ if (result.status == OSEO_STATUS_NORMAL) {
320
+ result = oseo_internal_set_with_receiver(
321
+ context, slots[3], slots[1], slots[2], slots[0], &refusal
322
+ );
323
+ }
324
+ if (result.status == OSEO_STATUS_NORMAL) {
325
+ result = strict && refusal != NULL
326
+ ? type_error(context, refusal)
327
+ : normal(slots[2]);
328
+ }
329
+ oseo_roots_pop(context, &frame);
330
+ return result;
331
+ }
332
+ if (is_proxy(object_value)) {
333
+ const char *refusal = NULL;
334
+ OseoResult result = oseo_internal_proxy_set(
335
+ context, object_value, key, value, object_value, &refusal);
336
+ if (result.status != OSEO_STATUS_NORMAL || refusal == NULL) {
337
+ return result;
338
+ }
339
+ return strict ? type_error(context, refusal) : normal(value);
340
+ }
341
+ if (ordinary_object(object_value)->module_namespace) {
342
+ if (strict) {
343
+ return type_error(
344
+ context,
345
+ "Cannot assign to a module namespace property."
346
+ );
347
+ }
348
+ return normal(value);
349
+ }
350
+ if (function_has_prototype_property(object_value) &&
351
+ oseo_internal_string_is_ascii(key, "prototype")) {
352
+ OseoFunction *function = function_object(object_value);
353
+ if (!function->prototype_writable) {
354
+ if (strict) {
355
+ return type_error(
356
+ context,
357
+ "Cannot assign to the read-only prototype property."
358
+ );
359
+ }
360
+ return normal(value);
361
+ }
362
+ function->prototype_object = value;
363
+ return normal(value);
364
+ }
365
+ OseoOrdinaryObject *receiver = ordinary_object(object_value);
366
+ if (is_array(object_value) &&
367
+ oseo_internal_string_is_ascii(key, "length")) {
368
+ return oseo_internal_set_array_length(
369
+ context,
370
+ receiver,
371
+ value,
372
+ strict,
373
+ false,
374
+ NULL
375
+ );
376
+ }
377
+ uint32_t receiver_index = 0u;
378
+ bool extends_array = is_array(object_value) &&
379
+ oseo_internal_array_index(key, &receiver_index) &&
380
+ receiver_index >= receiver->array_length;
381
+ OseoValue current = object_value;
382
+ while (is_object(current)) {
383
+ if (is_proxy(current)) {
384
+ const char *refusal = NULL;
385
+ OseoResult result = oseo_internal_proxy_set(
386
+ context,
387
+ current,
388
+ key,
389
+ value,
390
+ object_value,
391
+ &refusal
392
+ );
393
+ if (result.status != OSEO_STATUS_NORMAL || refusal == NULL) {
394
+ return result;
395
+ }
396
+ return strict ? type_error(context, refusal) : normal(value);
397
+ }
398
+ OseoOrdinaryObject *owner = ordinary_object(current);
399
+ if (owner->module_namespace) {
400
+ /* The receiver itself was answered above; a namespace
401
+ * reached later on the walk owns the [[Set]] the absent own
402
+ * property hands the parent, and it refuses every key. */
403
+ if (strict) {
404
+ return type_error(
405
+ context,
406
+ "Cannot assign to a module namespace property."
407
+ );
408
+ }
409
+ return normal(value);
410
+ }
411
+ if (is_typed_array(current)) {
412
+ /* A view anywhere on the walk owns the [[Set]] for a
413
+ * canonical numeric key, so an ordinary receiver inheriting
414
+ * from a TypedArray never materializes an invalid index as
415
+ * its own property. */
416
+ bool answered = false;
417
+ bool element = false;
418
+ OseoResult stepped = typed_array_set_step(
419
+ context,
420
+ current,
421
+ key,
422
+ value,
423
+ object_value,
424
+ &answered,
425
+ &element
426
+ );
427
+ if (stepped.status != OSEO_STATUS_NORMAL || answered) {
428
+ return stepped;
429
+ }
430
+ if (element) break;
431
+ }
432
+ OseoValue own_value = oseo_undefined();
433
+ OseoPropertyAttributes attributes = {false, false, false, false};
434
+ OseoValue getter = oseo_undefined();
435
+ OseoValue setter = oseo_undefined();
436
+ if (oseo_internal_own_property_descriptor(
437
+ context, current, key, &own_value, &attributes, &getter,
438
+ &setter)) {
439
+ if (attributes.accessor) {
440
+ if (!is_callable(setter)) {
441
+ if (strict) {
442
+ return type_error(
443
+ context,
444
+ "Cannot set a property that has only a getter."
445
+ );
446
+ }
447
+ return normal(value);
448
+ }
449
+ OseoRootFrame frame = {NULL, NULL, 0u};
450
+ OseoResult result = oseo_roots_allocate(context, &frame, 2u);
451
+ if (result.status != OSEO_STATUS_NORMAL) return result;
452
+ frame.slots[0] = setter;
453
+ frame.slots[1] = value;
454
+ result = oseo_call_function(
455
+ context,
456
+ frame.slots[0],
457
+ object_value,
458
+ 1u,
459
+ &frame.slots[1],
460
+ oseo_undefined()
461
+ );
462
+ oseo_roots_release(context, &frame);
463
+ if (result.status != OSEO_STATUS_NORMAL) return result;
464
+ return normal(value);
465
+ }
466
+ if (!attributes.writable) {
467
+ if (strict) {
468
+ return type_error(
469
+ context,
470
+ "Cannot assign to a read-only property."
471
+ );
472
+ }
473
+ return normal(value);
474
+ }
475
+ size_t index = oseo_internal_own_property_index(owner, key);
476
+ if (index == SIZE_MAX) {
477
+ /* An own property outside the property vector is either a
478
+ * synthetic descriptor a dedicated branch above already
479
+ * answered or the virtual String iterator, which an
480
+ * assignment to its own object replaces in place. */
481
+ OseoPropertyAttributes virtual_attributes = attributes;
482
+ if (current == object_value &&
483
+ oseo_internal_virtual_string_iterator_descriptor(
484
+ context,
485
+ current,
486
+ key,
487
+ &virtual_attributes
488
+ )) {
489
+ OseoResult assigned = oseo_object_define(
490
+ context,
491
+ object_value,
492
+ key,
493
+ value,
494
+ virtual_attributes
495
+ );
496
+ if (assigned.status != OSEO_STATUS_NORMAL) {
497
+ return assigned;
498
+ }
499
+ return normal(value);
500
+ }
501
+ break;
502
+ }
503
+ OseoProperty *property = &owner->properties[index];
504
+ if (current == object_value) {
505
+ /* A cell-backed property is a view of a binding, so the
506
+ * assignment updates the binding rather than replacing
507
+ * the view with a plain value. */
508
+ if (oseo_internal_cell_backed_property(
509
+ current, property->value)) {
510
+ return oseo_cell_set(context, property->value, value);
511
+ }
512
+ property->value = value;
513
+ if (extends_array) receiver->array_length = receiver_index + 1u;
514
+ return normal(value);
515
+ }
516
+ break;
517
+ }
518
+ current = owner->prototype;
519
+ }
520
+ if (!receiver->extensible) {
521
+ if (strict) {
522
+ return type_error(
523
+ context,
524
+ "Cannot add a property to a non-extensible object."
525
+ );
526
+ }
527
+ return normal(value);
528
+ }
529
+ if (extends_array && !receiver->length_writable) {
530
+ if (strict) {
531
+ return type_error(
532
+ context,
533
+ "Cannot extend an array with a read-only length."
534
+ );
535
+ }
536
+ return normal(value);
537
+ }
538
+ /* A stored key is this realm's own representative of a registered
539
+ * symbol, so the property vector never holds a value another realm
540
+ * owns. The caller already roots `key`, and the representative is
541
+ * rooted by `registered_symbols`. */
542
+ OseoResult local_key = oseo_internal_local_symbol(context, key);
543
+ if (local_key.status != OSEO_STATUS_NORMAL) return local_key;
544
+ key = local_key.value;
545
+ OseoResult grown = oseo_internal_grow_properties(context, object_value);
546
+ if (grown.status != OSEO_STATUS_NORMAL) return grown;
547
+ OseoOrdinaryObject *object = ordinary_object(object_value);
548
+ OseoProperty *property = &object->properties[object->property_count];
549
+ property->attributes = (OseoPropertyAttributes){true, true, true, false};
550
+ property->key = key;
551
+ property->value = value;
552
+ property->getter = oseo_undefined();
553
+ property->setter = oseo_undefined();
554
+ object->property_count += 1u;
555
+ oseo_internal_note_property_inserted(object, object->property_count - 1u);
556
+ object->shape_id = context->next_shape_id;
557
+ context->next_shape_id += 1u;
558
+ if (extends_array) object->array_length = receiver_index + 1u;
559
+ return normal(value);
560
+ }
561
+
562
+ OseoResult oseo_internal_set_with_receiver(
563
+ OseoContext *context,
564
+ OseoValue base,
565
+ OseoValue key,
566
+ OseoValue value,
567
+ OseoValue receiver,
568
+ const char **refusal
569
+ ) {
570
+ *refusal = NULL;
571
+ OseoResult valid = oseo_internal_require_property_key(context, key);
572
+ if (valid.status != OSEO_STATUS_NORMAL) return valid;
573
+ /* The lookup walks `base` only to decide whether a setter runs.
574
+ * Every other outcome, including a data property found on the walk,
575
+ * leaves the write to the receiver. */
576
+ OseoValue current = base;
577
+ while (is_object(current)) {
578
+ if (is_proxy(current)) {
579
+ return oseo_internal_proxy_set(
580
+ context, current, key, value, receiver, refusal);
581
+ }
582
+ if (ordinary_object(current)->module_namespace) {
583
+ /* OrdinarySetWithOwnDescriptor hands an absent own property
584
+ * to the parent's own [[Set]], so a module namespace
585
+ * anywhere on the walk answers with its exotic [[Set]]
586
+ * (10.4.6.9) rather than with this ordinary continuation.
587
+ * That reports false for every key and every receiver, so
588
+ * no write reaches either object. */
589
+ *refusal = "Cannot assign to a module namespace property.";
590
+ return normal(value);
591
+ }
592
+ if (is_typed_array(current)) {
593
+ bool answered = false;
594
+ bool element = false;
595
+ OseoResult stepped = typed_array_set_step(
596
+ context,
597
+ current,
598
+ key,
599
+ value,
600
+ receiver,
601
+ &answered,
602
+ &element
603
+ );
604
+ if (stepped.status != OSEO_STATUS_NORMAL || answered) {
605
+ return stepped;
606
+ }
607
+ if (element) break;
608
+ }
609
+ OseoValue own_value = oseo_undefined();
610
+ OseoPropertyAttributes attributes = {false, false, false, false};
611
+ OseoValue getter = oseo_undefined();
612
+ OseoValue setter = oseo_undefined();
613
+ if (oseo_internal_own_property_descriptor(
614
+ context, current, key, &own_value, &attributes, &getter,
615
+ &setter)) {
616
+ if (attributes.accessor) {
617
+ if (!is_callable(setter)) {
618
+ *refusal = "Cannot set a property that has only a getter.";
619
+ return normal(value);
620
+ }
621
+ OseoRootFrame frame = {NULL, NULL, 0u};
622
+ OseoResult result = oseo_roots_allocate(context, &frame, 2u);
623
+ if (result.status != OSEO_STATUS_NORMAL) return result;
624
+ frame.slots[0] = setter;
625
+ frame.slots[1] = value;
626
+ result = oseo_call_function(
627
+ context,
628
+ frame.slots[0],
629
+ receiver,
630
+ 1u,
631
+ &frame.slots[1],
632
+ oseo_undefined()
633
+ );
634
+ oseo_roots_release(context, &frame);
635
+ if (result.status != OSEO_STATUS_NORMAL) return result;
636
+ return normal(value);
637
+ }
638
+ if (!attributes.writable) {
639
+ *refusal = "Cannot assign to a read-only property.";
640
+ return normal(value);
641
+ }
642
+ break;
643
+ }
644
+ current = ordinary_object(current)->prototype;
645
+ }
646
+ if (!is_object(receiver)) {
647
+ *refusal = "Cannot set properties of a nullish or primitive value.";
648
+ return normal(value);
649
+ }
650
+ OseoValue receiver_value = oseo_undefined();
651
+ OseoPropertyAttributes receiver_attributes = {false, false, false, false};
652
+ OseoValue receiver_getter = oseo_undefined();
653
+ OseoValue receiver_setter = oseo_undefined();
654
+ bool receiver_found = false;
655
+ OseoResult receiver_result = is_proxy(receiver)
656
+ ? oseo_internal_proxy_get_own_property(
657
+ context,
658
+ receiver,
659
+ key,
660
+ &receiver_found,
661
+ &receiver_value,
662
+ &receiver_attributes,
663
+ &receiver_getter,
664
+ &receiver_setter
665
+ )
666
+ : normal(oseo_boolean(
667
+ (receiver_found = oseo_internal_own_property_descriptor(
668
+ context,
669
+ receiver,
670
+ key,
671
+ &receiver_value,
672
+ &receiver_attributes,
673
+ &receiver_getter,
674
+ &receiver_setter
675
+ ))
676
+ ));
677
+ if (receiver_result.status == OSEO_STATUS_NORMAL && receiver_found) {
678
+ receiver_result = oseo_internal_namespace_export_ready(
679
+ context, receiver, receiver_value);
680
+ }
681
+ if (receiver_result.status != OSEO_STATUS_NORMAL) return receiver_result;
682
+ if (receiver_found) {
683
+ if (receiver_attributes.accessor) {
684
+ *refusal = "Cannot assign to an accessor property of the receiver.";
685
+ return normal(value);
686
+ }
687
+ if (!receiver_attributes.writable) {
688
+ *refusal = "Cannot assign to a read-only property.";
689
+ return normal(value);
690
+ }
691
+ /* OrdinarySetWithOwnDescriptor finishes with
692
+ * Receiver.[[DefineOwnProperty]](P, { [[Value]]: V }), which
693
+ * keeps every other attribute the property already has and
694
+ * routes an array `length` write through ArraySetLength. That
695
+ * definition can still report a refusal, because coercing the
696
+ * written value runs user code that may make the property
697
+ * non-writable. */
698
+ OseoPropertyAttributes attributes = receiver_attributes;
699
+ attributes.accessor = false;
700
+ OseoResult assigned = oseo_internal_define_data_reported(
701
+ context,
702
+ receiver,
703
+ key,
704
+ value,
705
+ attributes,
706
+ true,
707
+ true,
708
+ refusal
709
+ );
710
+ if (assigned.status != OSEO_STATUS_NORMAL) return assigned;
711
+ return normal(value);
712
+ }
713
+ /* CreateDataProperty on the receiver, which reports false rather
714
+ * than throwing when the receiver refuses a new own property. */
715
+ OseoResult created = oseo_internal_define_data_reported(
716
+ context,
717
+ receiver,
718
+ key,
719
+ value,
720
+ (OseoPropertyAttributes){true, true, true, false},
721
+ true,
722
+ false,
723
+ refusal
724
+ );
725
+ if (created.status != OSEO_STATUS_NORMAL) return created;
726
+ return normal(value);
727
+ }
728
+
729
+ OseoResult oseo_super_set(
730
+ OseoContext *context,
731
+ OseoValue base,
732
+ OseoValue key,
733
+ OseoValue value,
734
+ OseoValue receiver,
735
+ bool strict
736
+ ) {
737
+ OseoResult valid = oseo_internal_require_property_key(context, key);
738
+ if (valid.status != OSEO_STATUS_NORMAL) return valid;
739
+ if (!is_object(base)) {
740
+ return type_error(
741
+ context,
742
+ "Cannot set properties of a nullish or primitive value."
743
+ );
744
+ }
745
+ const char *refusal = NULL;
746
+ OseoResult result = oseo_internal_set_with_receiver(
747
+ context,
748
+ base,
749
+ key,
750
+ value,
751
+ receiver,
752
+ &refusal
753
+ );
754
+ if (result.status != OSEO_STATUS_NORMAL || refusal == NULL) return result;
755
+ return strict ? type_error(context, refusal) : normal(value);
756
+ }
757
+
758
+ /* Inputs remain in the generated frame until the operation completes. */
759
+ void oseo_generated_property_key(
760
+ OseoContext *context, OseoValue input,
761
+ OseoResult *result, OseoValue *output
762
+ ) {
763
+ *result = oseo_property_key(context, input);
764
+ *output = result->value;
765
+ }
766
+
767
+ void oseo_generated_property_get(
768
+ OseoContext *context, OseoValue object, OseoValue key,
769
+ OseoResult *result, OseoValue *output
770
+ ) {
771
+ *result = oseo_object_get(context, object, key);
772
+ *output = result->value;
773
+ }
774
+
775
+ void oseo_generated_property_key_at(
776
+ OseoContext *context, OseoValue *roots,
777
+ const OseoGeneratedOperation *operation, OseoResult *result
778
+ ) {
779
+ oseo_generated_operation_location(context, operation);
780
+ oseo_generated_property_key(context, roots[operation->first],
781
+ result, &roots[operation->output]);
782
+ }
783
+
784
+ void oseo_generated_property_get_at(
785
+ OseoContext *context, OseoValue *roots,
786
+ const OseoGeneratedOperation *operation, OseoResult *result
787
+ ) {
788
+ oseo_generated_operation_location(context, operation);
789
+ oseo_generated_property_get(context, roots[operation->first],
790
+ roots[operation->second], result, &roots[operation->output]);
791
+ }