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

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 +28 -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 +2618 -0
  10. package/native/runtime_agent.c +1717 -0
  11. package/native/runtime_arguments.c +379 -0
  12. package/native/runtime_array.c +5766 -0
  13. package/native/runtime_array_buffer.c +1748 -0
  14. package/native/runtime_async_generator.c +972 -0
  15. package/native/runtime_atomics.c +1283 -0
  16. package/native/runtime_bigint.c +1387 -0
  17. package/native/runtime_bigint_object.c +626 -0
  18. package/native/runtime_binding.c +1029 -0
  19. package/native/runtime_boolean.c +320 -0
  20. package/native/runtime_clock.c +181 -0
  21. package/native/runtime_clock_posix.c +599 -0
  22. package/native/runtime_core.c +488 -0
  23. package/native/runtime_data_view.c +1135 -0
  24. package/native/runtime_date.c +1997 -0
  25. package/native/runtime_descriptor.c +1104 -0
  26. package/native/runtime_disposal.c +1667 -0
  27. package/native/runtime_enumeration.c +636 -0
  28. package/native/runtime_error.c +997 -0
  29. package/native/runtime_event_loop.c +653 -0
  30. package/native/runtime_function.c +3667 -0
  31. package/native/runtime_generator.c +1120 -0
  32. package/native/runtime_internal.h +5578 -0
  33. package/native/runtime_iterator.c +5379 -0
  34. package/native/runtime_json.c +1992 -0
  35. package/native/runtime_map.c +1563 -0
  36. package/native/runtime_math.c +918 -0
  37. package/native/runtime_memory.c +1365 -0
  38. package/native/runtime_module.c +884 -0
  39. package/native/runtime_number.c +2077 -0
  40. package/native/runtime_object.c +423 -0
  41. package/native/runtime_object_builtin.c +3901 -0
  42. package/native/runtime_primitive.c +2268 -0
  43. package/native/runtime_process.c +744 -0
  44. package/native/runtime_promise.c +3378 -0
  45. package/native/runtime_property.c +815 -0
  46. package/native/runtime_proxy.c +1557 -0
  47. package/native/runtime_realm.c +435 -0
  48. package/native/runtime_reflect.c +648 -0
  49. package/native/runtime_regexp.c +3519 -0
  50. package/native/runtime_regexp_matcher.c +3559 -0
  51. package/native/runtime_regexp_symbol.c +1495 -0
  52. package/native/runtime_set.c +1775 -0
  53. package/native/runtime_string.c +2886 -0
  54. package/native/runtime_string_match.c +1185 -0
  55. package/native/runtime_symbol.c +1010 -0
  56. package/native/runtime_typed_array.c +5137 -0
  57. package/native/runtime_unicode_tables.h +14670 -0
  58. package/native/runtime_uri.c +700 -0
  59. package/native/runtime_weak_collection.c +1299 -0
  60. package/package.json +38 -3
@@ -0,0 +1,648 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Oseo C runtime library.
4
+ *
5
+ * MIT License
6
+ *
7
+ * Copyright (c) 2026 Hong Minhee <https://hongminhee.org/>
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in
17
+ * all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #include "runtime_internal.h"
29
+
30
+ #include <string.h>
31
+
32
+ /*
33
+ * The Reflect namespace object of 28.1: the thirteen function
34
+ * properties that expose one essential internal method each, and the
35
+ * @@toStringTag value property. Reflect is an ordinary object, not a
36
+ * function, so it has neither [[Call]] nor [[Construct]], and its
37
+ * function properties are ordinary built-in functions that are not
38
+ * constructors either.
39
+ *
40
+ * Every function here requires an object target and reports the
41
+ * specification's boolean instead of raising the language error the
42
+ * matching `Object` static raises. The refusal rules stay in the
43
+ * descriptor, property, and object components, which report a refusal
44
+ * through a message the throwing forms turn back into a TypeError.
45
+ */
46
+
47
+ /*
48
+ * One Reflect function property. The array order is the order the
49
+ * namespace object creates its properties in and the order the code IDs
50
+ * count down from `OSEO_REFLECT_FUNCTION_CODE_ID_LAST`, so an entry's
51
+ * index is the only identity the builder and the dispatcher share.
52
+ */
53
+ typedef enum {
54
+ OSEO_REFLECT_APPLY = 0,
55
+ OSEO_REFLECT_CONSTRUCT = 1,
56
+ OSEO_REFLECT_DEFINE_PROPERTY = 2,
57
+ OSEO_REFLECT_DELETE_PROPERTY = 3,
58
+ OSEO_REFLECT_GET = 4,
59
+ OSEO_REFLECT_GET_OWN_PROPERTY_DESCRIPTOR = 5,
60
+ OSEO_REFLECT_GET_PROTOTYPE_OF = 6,
61
+ OSEO_REFLECT_HAS = 7,
62
+ OSEO_REFLECT_IS_EXTENSIBLE = 8,
63
+ OSEO_REFLECT_OWN_KEYS = 9,
64
+ OSEO_REFLECT_PREVENT_EXTENSIONS = 10,
65
+ OSEO_REFLECT_SET = 11,
66
+ OSEO_REFLECT_SET_PROTOTYPE_OF = 12,
67
+ } OseoReflectOperation;
68
+
69
+ typedef struct {
70
+ const char *name;
71
+ size_t length;
72
+ } OseoReflectFunction;
73
+
74
+ static const OseoReflectFunction reflect_functions[] = {
75
+ {"apply", 3u},
76
+ {"construct", 2u},
77
+ {"defineProperty", 3u},
78
+ {"deleteProperty", 2u},
79
+ {"get", 2u},
80
+ {"getOwnPropertyDescriptor", 2u},
81
+ {"getPrototypeOf", 1u},
82
+ {"has", 2u},
83
+ {"isExtensible", 1u},
84
+ {"ownKeys", 1u},
85
+ {"preventExtensions", 1u},
86
+ {"set", 3u},
87
+ {"setPrototypeOf", 2u},
88
+ };
89
+
90
+ _Static_assert(
91
+ sizeof(reflect_functions) / sizeof(reflect_functions[0]) ==
92
+ OSEO_REFLECT_FUNCTION_COUNT,
93
+ "The Reflect function table must match its reviewed code-ID range."
94
+ );
95
+
96
+ static OseoValue reflect_argument(
97
+ size_t argument_count,
98
+ const OseoValue *arguments,
99
+ size_t index
100
+ ) {
101
+ return index < argument_count ? arguments[index] : oseo_undefined();
102
+ }
103
+
104
+ static OseoResult type_error(OseoContext *context, const char *message) {
105
+ return oseo_internal_throw_error(context, OSEO_ERROR_TYPE, message);
106
+ }
107
+
108
+ /*
109
+ * The shared first step of every Reflect function but `apply` and
110
+ * `construct`: a target that is not an object is a TypeError rather
111
+ * than a coercion or a `false` result. `reflect_call` applies it once
112
+ * for all eleven, so no individual body repeats it.
113
+ */
114
+ static OseoResult reflect_object_target(
115
+ OseoContext *context,
116
+ OseoValue target
117
+ ) {
118
+ if (is_object(target)) return normal(target);
119
+ return type_error(context, "A Reflect target must be an object.");
120
+ }
121
+
122
+ /* Reflect.apply(target, thisArgument, argumentsList). */
123
+ static OseoResult reflect_apply(
124
+ OseoContext *context,
125
+ size_t argument_count,
126
+ const OseoValue *arguments
127
+ ) {
128
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
129
+ if (!is_callable(target)) {
130
+ return type_error(context, "Reflect.apply requires a callable target.");
131
+ }
132
+ OseoValue slots[4] = {
133
+ target,
134
+ reflect_argument(argument_count, arguments, 1u),
135
+ reflect_argument(argument_count, arguments, 2u),
136
+ oseo_undefined(),
137
+ };
138
+ OseoRootFrame frame = {NULL, slots, 4u};
139
+ oseo_roots_push(context, &frame);
140
+ OseoResult result = oseo_internal_array_like_list(
141
+ context,
142
+ slots[2],
143
+ &slots[3]
144
+ );
145
+ size_t forwarded_count = 0u;
146
+ const OseoValue *forwarded = NULL;
147
+ if (result.status == OSEO_STATUS_NORMAL) {
148
+ result = oseo_argument_list_view(
149
+ context,
150
+ slots[3],
151
+ &forwarded_count,
152
+ &forwarded
153
+ );
154
+ }
155
+ /* Reflect.apply step 3 performs PrepareForTailCall. */
156
+ if (result.status == OSEO_STATUS_NORMAL) {
157
+ result = oseo_internal_tail_call(
158
+ context,
159
+ slots[0],
160
+ slots[1],
161
+ forwarded_count,
162
+ forwarded
163
+ );
164
+ }
165
+ oseo_roots_pop(context, &frame);
166
+ return result;
167
+ }
168
+
169
+ /* Reflect.construct(target, argumentsList [, newTarget]). */
170
+ static OseoResult reflect_construct(
171
+ OseoContext *context,
172
+ size_t argument_count,
173
+ const OseoValue *arguments
174
+ ) {
175
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
176
+ if (!function_is_constructible(target)) {
177
+ return type_error(
178
+ context,
179
+ "Reflect.construct requires a constructor target."
180
+ );
181
+ }
182
+ OseoValue new_target = argument_count > 2u ? arguments[2] : target;
183
+ if (!function_is_constructible(new_target)) {
184
+ return type_error(
185
+ context,
186
+ "Reflect.construct requires a constructor new target."
187
+ );
188
+ }
189
+ /*
190
+ * Slots: 0 target, 1 new target, 2 the array-like source, 3 the
191
+ * collected argument list, 4 the receiver
192
+ * OrdinaryCreateFromConstructor builds from the new target's
193
+ * `prototype`, undefined when the target's own clause creates it.
194
+ */
195
+ OseoValue slots[5] = {
196
+ target,
197
+ new_target,
198
+ reflect_argument(argument_count, arguments, 1u),
199
+ oseo_undefined(),
200
+ oseo_undefined(),
201
+ };
202
+ OseoRootFrame frame = {NULL, slots, 5u};
203
+ oseo_roots_push(context, &frame);
204
+ OseoResult result = oseo_internal_array_like_list(
205
+ context,
206
+ slots[2],
207
+ &slots[3]
208
+ );
209
+ if (result.status == OSEO_STATUS_NORMAL) {
210
+ /* OrdinaryCreateFromConstructor on the target's behalf, which
211
+ * reads nothing and creates nothing when the target is a
212
+ * derived class constructor, because its own `super()` does
213
+ * both once the body reaches it. */
214
+ result = oseo_internal_construct_receiver(
215
+ context,
216
+ slots[0],
217
+ slots[1]
218
+ );
219
+ slots[4] = result.value;
220
+ }
221
+ size_t forwarded_count = 0u;
222
+ const OseoValue *forwarded = NULL;
223
+ if (result.status == OSEO_STATUS_NORMAL) {
224
+ result = oseo_argument_list_view(
225
+ context,
226
+ slots[3],
227
+ &forwarded_count,
228
+ &forwarded
229
+ );
230
+ }
231
+ if (result.status == OSEO_STATUS_NORMAL) {
232
+ result = oseo_call_function(
233
+ context,
234
+ slots[0],
235
+ slots[4],
236
+ forwarded_count,
237
+ forwarded,
238
+ slots[1]
239
+ );
240
+ }
241
+ if (result.status == OSEO_STATUS_NORMAL) {
242
+ result = oseo_constructor_result(context, result.value, slots[4]);
243
+ }
244
+ oseo_roots_pop(context, &frame);
245
+ return result;
246
+ }
247
+
248
+ /* Reflect.defineProperty(target, propertyKey, attributes). */
249
+ static OseoResult reflect_define_property(
250
+ OseoContext *context,
251
+ size_t argument_count,
252
+ const OseoValue *arguments
253
+ ) {
254
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
255
+ OseoValue slots[3] = {
256
+ target,
257
+ reflect_argument(argument_count, arguments, 2u),
258
+ oseo_undefined(),
259
+ };
260
+ OseoRootFrame frame = {NULL, slots, 3u};
261
+ oseo_roots_push(context, &frame);
262
+ OseoResult result = oseo_property_key(
263
+ context,
264
+ reflect_argument(argument_count, arguments, 1u)
265
+ );
266
+ slots[2] = result.value;
267
+ const char *refusal = NULL;
268
+ if (result.status == OSEO_STATUS_NORMAL) {
269
+ result = oseo_internal_define_from_descriptor(
270
+ context,
271
+ slots[0],
272
+ slots[2],
273
+ slots[1],
274
+ &refusal
275
+ );
276
+ }
277
+ if (result.status == OSEO_STATUS_NORMAL) {
278
+ result = normal(oseo_boolean(refusal == NULL));
279
+ }
280
+ oseo_roots_pop(context, &frame);
281
+ return result;
282
+ }
283
+
284
+ /* Reflect.deleteProperty(target, propertyKey). */
285
+ static OseoResult reflect_delete_property(
286
+ OseoContext *context,
287
+ size_t argument_count,
288
+ const OseoValue *arguments
289
+ ) {
290
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
291
+ OseoValue slots[2] = {target, oseo_undefined()};
292
+ OseoRootFrame frame = {NULL, slots, 2u};
293
+ oseo_roots_push(context, &frame);
294
+ OseoResult result = oseo_property_key(
295
+ context,
296
+ reflect_argument(argument_count, arguments, 1u)
297
+ );
298
+ slots[1] = result.value;
299
+ if (result.status == OSEO_STATUS_NORMAL) {
300
+ /* The non-strict delete is the one that reports the
301
+ * specification's boolean instead of raising a TypeError. */
302
+ result = oseo_object_delete(context, slots[0], slots[1], false);
303
+ }
304
+ oseo_roots_pop(context, &frame);
305
+ return result;
306
+ }
307
+
308
+ /* Reflect.get(target, propertyKey [, receiver]). */
309
+ static OseoResult reflect_get(
310
+ OseoContext *context,
311
+ size_t argument_count,
312
+ const OseoValue *arguments
313
+ ) {
314
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
315
+ OseoValue slots[3] = {
316
+ target,
317
+ argument_count > 2u ? arguments[2] : target,
318
+ oseo_undefined(),
319
+ };
320
+ OseoRootFrame frame = {NULL, slots, 3u};
321
+ oseo_roots_push(context, &frame);
322
+ OseoResult result = oseo_property_key(
323
+ context,
324
+ reflect_argument(argument_count, arguments, 1u)
325
+ );
326
+ slots[2] = result.value;
327
+ if (result.status == OSEO_STATUS_NORMAL) {
328
+ result = oseo_super_get(context, slots[0], slots[2], slots[1]);
329
+ }
330
+ oseo_roots_pop(context, &frame);
331
+ return result;
332
+ }
333
+
334
+ /* Reflect.set(target, propertyKey, V [, receiver]). */
335
+ static OseoResult reflect_set(
336
+ OseoContext *context,
337
+ size_t argument_count,
338
+ const OseoValue *arguments
339
+ ) {
340
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
341
+ OseoValue slots[4] = {
342
+ target,
343
+ reflect_argument(argument_count, arguments, 2u),
344
+ argument_count > 3u ? arguments[3] : target,
345
+ oseo_undefined(),
346
+ };
347
+ OseoRootFrame frame = {NULL, slots, 4u};
348
+ oseo_roots_push(context, &frame);
349
+ OseoResult result = oseo_property_key(
350
+ context,
351
+ reflect_argument(argument_count, arguments, 1u)
352
+ );
353
+ slots[3] = result.value;
354
+ const char *refusal = NULL;
355
+ if (result.status == OSEO_STATUS_NORMAL) {
356
+ result = oseo_internal_set_with_receiver(
357
+ context,
358
+ slots[0],
359
+ slots[3],
360
+ slots[1],
361
+ slots[2],
362
+ &refusal
363
+ );
364
+ }
365
+ if (result.status == OSEO_STATUS_NORMAL) {
366
+ result = normal(oseo_boolean(refusal == NULL));
367
+ }
368
+ oseo_roots_pop(context, &frame);
369
+ return result;
370
+ }
371
+
372
+ /* Reflect.setPrototypeOf(target, proto). */
373
+ static OseoResult reflect_set_prototype_of(
374
+ OseoContext *context,
375
+ size_t argument_count,
376
+ const OseoValue *arguments
377
+ ) {
378
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
379
+ OseoValue prototype = reflect_argument(argument_count, arguments, 1u);
380
+ if (tag_of(prototype) != OSEO_TAG_NULL && !is_object(prototype)) {
381
+ return type_error(
382
+ context,
383
+ "Reflect.setPrototypeOf requires an object or null prototype."
384
+ );
385
+ }
386
+ const char *refusal = NULL;
387
+ OseoResult result = oseo_internal_set_prototype_reported(
388
+ context,
389
+ target,
390
+ prototype,
391
+ &refusal
392
+ );
393
+ if (result.status != OSEO_STATUS_NORMAL) return result;
394
+ return normal(oseo_boolean(refusal == NULL));
395
+ }
396
+
397
+ static OseoResult reflect_call(
398
+ OseoContext *context,
399
+ size_t operation,
400
+ size_t argument_count,
401
+ const OseoValue *arguments
402
+ ) {
403
+ if (operation == OSEO_REFLECT_APPLY) {
404
+ return reflect_apply(context, argument_count, arguments);
405
+ }
406
+ if (operation == OSEO_REFLECT_CONSTRUCT) {
407
+ return reflect_construct(context, argument_count, arguments);
408
+ }
409
+ /* The eleven remaining functions share one first step: an object
410
+ * target, checked before any key or descriptor conversion. */
411
+ OseoValue target = reflect_argument(argument_count, arguments, 0u);
412
+ OseoResult checked = reflect_object_target(context, target);
413
+ if (checked.status != OSEO_STATUS_NORMAL) return checked;
414
+ switch (operation) {
415
+ case OSEO_REFLECT_DEFINE_PROPERTY:
416
+ return reflect_define_property(context, argument_count, arguments);
417
+ case OSEO_REFLECT_DELETE_PROPERTY:
418
+ return reflect_delete_property(context, argument_count, arguments);
419
+ case OSEO_REFLECT_GET:
420
+ return reflect_get(context, argument_count, arguments);
421
+ case OSEO_REFLECT_SET:
422
+ return reflect_set(context, argument_count, arguments);
423
+ case OSEO_REFLECT_SET_PROTOTYPE_OF:
424
+ return reflect_set_prototype_of(
425
+ context,
426
+ argument_count,
427
+ arguments
428
+ );
429
+ case OSEO_REFLECT_GET_OWN_PROPERTY_DESCRIPTOR:
430
+ return oseo_object_builtin_get_own_property_descriptor(
431
+ context,
432
+ argument_count,
433
+ arguments
434
+ );
435
+ case OSEO_REFLECT_GET_PROTOTYPE_OF:
436
+ return oseo_internal_get_prototype(context, target);
437
+ case OSEO_REFLECT_HAS: {
438
+ OseoValue slots[2] = {target, oseo_undefined()};
439
+ OseoRootFrame frame = {NULL, slots, 2u};
440
+ oseo_roots_push(context, &frame);
441
+ OseoResult result = oseo_property_key(
442
+ context,
443
+ reflect_argument(argument_count, arguments, 1u)
444
+ );
445
+ slots[1] = result.value;
446
+ if (result.status == OSEO_STATUS_NORMAL) {
447
+ result = oseo_has_property(context, slots[1], slots[0]);
448
+ }
449
+ oseo_roots_pop(context, &frame);
450
+ return result;
451
+ }
452
+ case OSEO_REFLECT_IS_EXTENSIBLE:
453
+ return oseo_internal_is_extensible(context, target);
454
+ case OSEO_REFLECT_OWN_KEYS:
455
+ return oseo_internal_own_key_array(
456
+ context,
457
+ target,
458
+ OSEO_OWN_KEY_ALL
459
+ );
460
+ case OSEO_REFLECT_PREVENT_EXTENSIONS:
461
+ {
462
+ const char *refusal = NULL;
463
+ OseoResult result = oseo_internal_prevent_extensions_reported(
464
+ context, target, &refusal);
465
+ if (result.status != OSEO_STATUS_NORMAL) return result;
466
+ return normal(oseo_boolean(refusal == NULL));
467
+ }
468
+ default: break;
469
+ }
470
+ return failure(context, "OSEO2001", "Unknown Reflect operation.");
471
+ }
472
+
473
+ OseoResult oseo_internal_reflect_builtin_dispatch(
474
+ OseoContext *context,
475
+ size_t code_id,
476
+ OseoValue callee,
477
+ OseoValue receiver,
478
+ size_t argument_count,
479
+ const OseoValue *arguments,
480
+ OseoValue new_target
481
+ ) {
482
+ (void)callee;
483
+ (void)receiver;
484
+ if (code_id < OSEO_REFLECT_FUNCTION_CODE_ID_FIRST ||
485
+ code_id > OSEO_REFLECT_FUNCTION_CODE_ID_LAST) {
486
+ return oseo_unknown_function(context, code_id);
487
+ }
488
+ if (tag_of(new_target) != OSEO_TAG_UNDEFINED) {
489
+ return type_error(context, "Reflect method is not a constructor.");
490
+ }
491
+ size_t operation = OSEO_REFLECT_FUNCTION_CODE_ID_LAST - code_id;
492
+ return reflect_call(context, operation, argument_count, arguments);
493
+ }
494
+
495
+ /* One Reflect function property, created without a `prototype`. */
496
+ static OseoResult create_reflect_function(
497
+ OseoContext *context,
498
+ size_t operation
499
+ ) {
500
+ const OseoReflectFunction *entry = &reflect_functions[operation];
501
+ size_t name_length = strlen(entry->name);
502
+ uint16_t units[32];
503
+ if (name_length > sizeof(units) / sizeof(*units)) {
504
+ return failure(context, "OSEO2001", "Built-in name is too long.");
505
+ }
506
+ for (size_t index = 0u; index < name_length; index += 1u) {
507
+ units[index] = (uint16_t)(unsigned char)entry->name[index];
508
+ }
509
+ OseoValue environment = oseo_undefined();
510
+ OseoRootFrame frame = {NULL, &environment, 1u};
511
+ oseo_roots_push(context, &frame);
512
+ OseoResult result = oseo_environment_create(context, 0u);
513
+ environment = result.value;
514
+ if (result.status == OSEO_STATUS_NORMAL) {
515
+ result = oseo_function_create(
516
+ context,
517
+ OSEO_REFLECT_FUNCTION_CODE_ID_LAST - operation,
518
+ environment,
519
+ units,
520
+ name_length,
521
+ entry->length,
522
+ OSEO_FUNCTION_INTERNAL,
523
+ oseo_undefined(),
524
+ oseo_undefined(),
525
+ OSEO_FUNCTION_NAME_PREFIX_NONE
526
+ );
527
+ }
528
+ oseo_roots_pop(context, &frame);
529
+ return result;
530
+ }
531
+
532
+ static OseoResult define_reflect_property(
533
+ OseoContext *context,
534
+ OseoValue object,
535
+ OseoValue key,
536
+ OseoValue value,
537
+ OseoPropertyAttributes attributes
538
+ ) {
539
+ OseoValue slots[3] = {object, key, value};
540
+ OseoRootFrame frame = {NULL, slots, 3u};
541
+ oseo_roots_push(context, &frame);
542
+ OseoResult result = oseo_object_define(
543
+ context,
544
+ slots[0],
545
+ slots[1],
546
+ slots[2],
547
+ attributes
548
+ );
549
+ oseo_roots_pop(context, &frame);
550
+ return result;
551
+ }
552
+
553
+ OseoResult oseo_internal_reflect_intrinsic(OseoContext *context) {
554
+ OseoValue *slot = &context->realm->intrinsics[OSEO_INTRINSIC_REFLECT];
555
+ if (is_object(*slot)) return normal(*slot);
556
+ size_t entry_allocations = context->allocations;
557
+ OseoRootFrame frame = {NULL, NULL, 0u};
558
+ OseoResult result = oseo_roots_allocate(context, &frame, 3u);
559
+ if (result.status != OSEO_STATUS_NORMAL) return result;
560
+ result = oseo_internal_intrinsic(
561
+ context,
562
+ OSEO_INTRINSIC_OBJECT_PROTOTYPE
563
+ );
564
+ frame.slots[0] = result.value;
565
+ if (result.status == OSEO_STATUS_NORMAL) {
566
+ result = oseo_object_create(context, frame.slots[0]);
567
+ frame.slots[0] = result.value;
568
+ }
569
+ if (result.status == OSEO_STATUS_NORMAL) {
570
+ *slot = frame.slots[0];
571
+ }
572
+ static const OseoPropertyAttributes method_attributes =
573
+ {true, false, true, false};
574
+ for (size_t index = 0u;
575
+ result.status == OSEO_STATUS_NORMAL &&
576
+ index < OSEO_REFLECT_FUNCTION_COUNT;
577
+ index += 1u) {
578
+ result = create_reflect_function(context, index);
579
+ frame.slots[1] = result.value;
580
+ if (result.status != OSEO_STATUS_NORMAL) break;
581
+ result = oseo_internal_ascii_string(
582
+ context,
583
+ reflect_functions[index].name
584
+ );
585
+ frame.slots[2] = result.value;
586
+ if (result.status != OSEO_STATUS_NORMAL) break;
587
+ result = define_reflect_property(
588
+ context,
589
+ frame.slots[0],
590
+ frame.slots[2],
591
+ frame.slots[1],
592
+ method_attributes
593
+ );
594
+ }
595
+ if (result.status == OSEO_STATUS_NORMAL) {
596
+ result = oseo_internal_well_known_symbol(
597
+ context,
598
+ OSEO_WELL_KNOWN_TO_STRING_TAG
599
+ );
600
+ frame.slots[1] = result.value;
601
+ }
602
+ if (result.status == OSEO_STATUS_NORMAL) {
603
+ result = oseo_internal_ascii_string(context, "Reflect");
604
+ frame.slots[2] = result.value;
605
+ }
606
+ if (result.status == OSEO_STATUS_NORMAL) {
607
+ result = define_reflect_property(
608
+ context,
609
+ frame.slots[0],
610
+ frame.slots[1],
611
+ frame.slots[2],
612
+ (OseoPropertyAttributes){true, false, false, false}
613
+ );
614
+ }
615
+ if (result.status != OSEO_STATUS_NORMAL) {
616
+ *slot = oseo_undefined();
617
+ } else if (context->observe_specialization) {
618
+ context->allocations = entry_allocations;
619
+ }
620
+ oseo_roots_release(context, &frame);
621
+ return result.status == OSEO_STATUS_NORMAL ? normal(*slot) : result;
622
+ }
623
+
624
+ OseoResult oseo_internal_install_reflect_global(
625
+ OseoContext *context,
626
+ OseoValue global
627
+ ) {
628
+ OseoValue slots[3] = {global, oseo_undefined(), oseo_undefined()};
629
+ OseoRootFrame frame = {NULL, slots, 3u};
630
+ oseo_roots_push(context, &frame);
631
+ OseoResult result = oseo_internal_reflect_intrinsic(context);
632
+ slots[1] = result.value;
633
+ if (result.status == OSEO_STATUS_NORMAL) {
634
+ result = oseo_internal_ascii_string(context, "Reflect");
635
+ slots[2] = result.value;
636
+ }
637
+ if (result.status == OSEO_STATUS_NORMAL) {
638
+ result = oseo_object_define(
639
+ context,
640
+ slots[0],
641
+ slots[2],
642
+ slots[1],
643
+ (OseoPropertyAttributes){true, false, true, false}
644
+ );
645
+ }
646
+ oseo_roots_pop(context, &frame);
647
+ return result.status == OSEO_STATUS_NORMAL ? normal(slots[0]) : result;
648
+ }