@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,355 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /* Copyright (c) 2026 Hong Minhee; see ../MIT-LICENSE.txt. */
3
+
4
+ #include "runtime_internal.h"
5
+
6
+ OseoResult oseo_internal_arguments_builtin_dispatch(
7
+ OseoContext *context,
8
+ size_t code_id,
9
+ OseoValue callee,
10
+ OseoValue receiver,
11
+ size_t argument_count,
12
+ const OseoValue *arguments,
13
+ OseoValue new_target
14
+ ) {
15
+ (void)callee;
16
+ (void)receiver;
17
+ (void)argument_count;
18
+ (void)arguments;
19
+ (void)new_target;
20
+ if (code_id != OSEO_THROW_TYPE_ERROR_CODE_ID) {
21
+ return oseo_unknown_function(context, code_id);
22
+ }
23
+ /* %ThrowTypeError%. Both accessor halves throw regardless of their
24
+ * receiver or argument. */
25
+ return oseo_internal_throw_error(
26
+ context,
27
+ OSEO_ERROR_TYPE,
28
+ "'callee' is not available on an unmapped arguments object."
29
+ );
30
+ }
31
+
32
+ /*
33
+ * The arguments exotic objects: the unmapped object 10.2.4 creates, the
34
+ * mapped object 10.4.4 creates from a simple parameter list, the
35
+ * `@@iterator` both shapes define, and the realm's single
36
+ * %ThrowTypeError% intrinsic their `callee` accessor reports.
37
+ */
38
+
39
+ /*
40
+ * %ThrowTypeError% (10.2.4.1). One anonymous, zero-parameter function
41
+ * per realm, so an unmapped arguments object's `callee` accessor reports
42
+ * the same [[Get]] and [[Set]] identity every time it is inspected. Its
43
+ * own body only throws, and the caller's arguments never reach it.
44
+ *
45
+ * 10.2.4.1 also hardens the intrinsic: its `length` and `name` are
46
+ * non-writable and non-configurable, and the function itself is
47
+ * non-extensible, so admitted reflection can neither reshape it nor
48
+ * replace its prototype. `oseo_function_create` leaves both properties
49
+ * configurable, so they are redefined before extensibility is dropped.
50
+ * The `prototype` object every internal function in this profile still
51
+ * carries is a separate boundary the intrinsics stream owns.
52
+ */
53
+ OseoResult oseo_internal_throw_type_error_function(OseoContext *context) {
54
+ OseoValue *cache =
55
+ &context->realm->intrinsics[OSEO_INTRINSIC_THROW_TYPE_ERROR];
56
+ if (tag_of(*cache) != OSEO_TAG_UNDEFINED) {
57
+ return normal(*cache);
58
+ }
59
+ OseoRootFrame frame = {NULL, NULL, 0u};
60
+ OseoResult result = oseo_roots_allocate(context, &frame, 2u);
61
+ if (result.status != OSEO_STATUS_NORMAL) return result;
62
+ result = oseo_environment_create(context, 0u);
63
+ frame.slots[0] = result.value;
64
+ if (result.status == OSEO_STATUS_NORMAL) {
65
+ result = oseo_function_create(
66
+ context,
67
+ OSEO_THROW_TYPE_ERROR_CODE_ID,
68
+ frame.slots[0],
69
+ NULL,
70
+ 0u,
71
+ 0u,
72
+ OSEO_FUNCTION_INTERNAL,
73
+ oseo_undefined(),
74
+ oseo_undefined(),
75
+ OSEO_FUNCTION_NAME_PREFIX_NONE
76
+ );
77
+ frame.slots[0] = result.value;
78
+ }
79
+ /* Materializing Function.prototype above may have requested and cached
80
+ * this intrinsic while the outer allocation was still in progress. Keep
81
+ * that completed function as the realm identity instead of replacing it
82
+ * with the outer allocation. */
83
+ if (result.status == OSEO_STATUS_NORMAL && is_function(*cache)) {
84
+ result = normal(*cache);
85
+ oseo_roots_release(context, &frame);
86
+ return result;
87
+ }
88
+ const OseoPropertyAttributes frozen =
89
+ (OseoPropertyAttributes){false, false, false, false};
90
+ const char *const hardened[] = {"length", "name"};
91
+ for (size_t index = 0u;
92
+ result.status == OSEO_STATUS_NORMAL && index < 2u;
93
+ index += 1u) {
94
+ result = oseo_internal_ascii_string(context, hardened[index]);
95
+ frame.slots[1] = result.value;
96
+ OseoValue existing = oseo_undefined();
97
+ if (result.status == OSEO_STATUS_NORMAL) {
98
+ result = oseo_object_get(context, frame.slots[0], frame.slots[1]);
99
+ existing = result.value;
100
+ }
101
+ if (result.status == OSEO_STATUS_NORMAL) {
102
+ result = oseo_object_define(
103
+ context,
104
+ frame.slots[0],
105
+ frame.slots[1],
106
+ existing,
107
+ frozen
108
+ );
109
+ }
110
+ }
111
+ if (result.status == OSEO_STATUS_NORMAL) {
112
+ ordinary_object(frame.slots[0])->extensible = false;
113
+ *cache = frame.slots[0];
114
+ result = normal(frame.slots[0]);
115
+ }
116
+ oseo_roots_release(context, &frame);
117
+ return result;
118
+ }
119
+
120
+ /*
121
+ * Both arguments object shapes define `@@iterator` as an ordinary
122
+ * writable, non-enumerable, configurable data property whose value is
123
+ * the same %Array.prototype.values% function an array's own
124
+ * `Symbol.iterator` resolves to, so spreading or iterating an arguments
125
+ * object walks its indices through the same array iterator, which reads
126
+ * a non-array target's `length` the way LengthOfArrayLike does.
127
+ */
128
+ static OseoResult arguments_define_iterator(
129
+ OseoContext *context,
130
+ OseoValue object
131
+ ) {
132
+ OseoRootFrame frame = {NULL, NULL, 0u};
133
+ OseoResult result = oseo_roots_allocate(context, &frame, 3u);
134
+ if (result.status != OSEO_STATUS_NORMAL) return result;
135
+ frame.slots[0] = object;
136
+ result = oseo_internal_well_known_symbol(context, OSEO_WELL_KNOWN_ITERATOR);
137
+ frame.slots[1] = result.value;
138
+ if (result.status == OSEO_STATUS_NORMAL) {
139
+ result =
140
+ oseo_internal_iterator_method(context, OSEO_ARRAY_VALUES_CODE_ID);
141
+ frame.slots[2] = result.value;
142
+ }
143
+ if (result.status == OSEO_STATUS_NORMAL) {
144
+ const OseoPropertyAttributes attributes =
145
+ (OseoPropertyAttributes){true, false, true, false};
146
+ result = oseo_object_define(
147
+ context,
148
+ frame.slots[0],
149
+ frame.slots[1],
150
+ frame.slots[2],
151
+ attributes
152
+ );
153
+ }
154
+ oseo_roots_release(context, &frame);
155
+ return result;
156
+ }
157
+
158
+ OseoResult oseo_arguments_create(
159
+ OseoContext *context,
160
+ size_t argument_count,
161
+ const OseoValue *arguments
162
+ ) {
163
+ if (argument_count > 0u && arguments == NULL) {
164
+ return failure(context, "OSEO2001", "Arguments are missing.");
165
+ }
166
+ OseoRootFrame frame = {NULL, NULL, 0u};
167
+ OseoResult result = oseo_roots_allocate(context, &frame, 3u);
168
+ if (result.status != OSEO_STATUS_NORMAL) return result;
169
+ result = oseo_object_literal_create(context);
170
+ frame.slots[0] = result.value;
171
+ if (result.status == OSEO_STATUS_NORMAL) {
172
+ ordinary_object(frame.slots[0])->arguments_object = true;
173
+ }
174
+ const OseoPropertyAttributes indexed =
175
+ (OseoPropertyAttributes){true, true, true, false};
176
+ for (size_t index = 0u;
177
+ result.status == OSEO_STATUS_NORMAL && index < argument_count;
178
+ index += 1u) {
179
+ result = oseo_property_key(context, oseo_number((double)index));
180
+ frame.slots[1] = result.value;
181
+ if (result.status == OSEO_STATUS_NORMAL) {
182
+ result = oseo_object_define(
183
+ context,
184
+ frame.slots[0],
185
+ frame.slots[1],
186
+ arguments[index],
187
+ indexed
188
+ );
189
+ }
190
+ }
191
+ const OseoPropertyAttributes metadata =
192
+ (OseoPropertyAttributes){true, false, true, false};
193
+ if (result.status == OSEO_STATUS_NORMAL) {
194
+ result = oseo_internal_ascii_string(context, "length");
195
+ frame.slots[1] = result.value;
196
+ }
197
+ if (result.status == OSEO_STATUS_NORMAL) {
198
+ result = oseo_object_define(
199
+ context,
200
+ frame.slots[0],
201
+ frame.slots[1],
202
+ oseo_number((double)argument_count),
203
+ metadata
204
+ );
205
+ }
206
+ /*
207
+ * CreateUnmappedArgumentsObject poisons `callee` unconditionally: it
208
+ * is a non-configurable accessor whose [[Get]] and [[Set]] are both
209
+ * %ThrowTypeError%, so the running function never leaks through an
210
+ * unmapped arguments object, whatever the caller's strictness. Only
211
+ * the mapped object still exposes the ordinary data property.
212
+ */
213
+ if (result.status == OSEO_STATUS_NORMAL) {
214
+ result = oseo_internal_throw_type_error_function(context);
215
+ frame.slots[2] = result.value;
216
+ }
217
+ if (result.status == OSEO_STATUS_NORMAL) {
218
+ result = oseo_internal_ascii_string(context, "callee");
219
+ frame.slots[1] = result.value;
220
+ }
221
+ if (result.status == OSEO_STATUS_NORMAL) {
222
+ const OseoPropertyAttributes poisoned =
223
+ (OseoPropertyAttributes){false, false, false, true};
224
+ result = oseo_object_define_accessor(
225
+ context,
226
+ frame.slots[0],
227
+ frame.slots[1],
228
+ frame.slots[2],
229
+ frame.slots[2],
230
+ true,
231
+ true,
232
+ poisoned
233
+ );
234
+ }
235
+ if (result.status == OSEO_STATUS_NORMAL) {
236
+ result = arguments_define_iterator(context, frame.slots[0]);
237
+ }
238
+ if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[0];
239
+ oseo_roots_release(context, &frame);
240
+ return result;
241
+ }
242
+
243
+ /*
244
+ * CreateMappedArgumentsObject (10.4.4.7), admitted only for a non-strict
245
+ * function whose parameter list is simple. `mapped_indices` names, in
246
+ * ascending order, exactly the indices that are the rightmost formal
247
+ * parameter of their name, and `mapped_binding_ids` gives each of those
248
+ * indices its parameter's own environment binding id at the same
249
+ * position; both are empty for a supplied index that is a duplicate
250
+ * name's non-rightmost occurrence, or at or beyond the parameter count,
251
+ * since ECMA-262 maps only the rightmost occurrence of a declared
252
+ * parameter position. Defining a mapped index's property with its
253
+ * parameter's own binding cell as the stored value, rather than the
254
+ * plain snapshot value an unmapped arguments object stores, is what
255
+ * makes oseo_internal_cell_backed_property recognize it afterward: every later
256
+ * [[Get]]/[[Set]]/[[GetOwnProperty]]/[[DefineOwnProperty]]/[[Delete]]
257
+ * on the index then reaches the parameter through the existing
258
+ * cell-backed property machinery with no exotic method table of its
259
+ * own.
260
+ */
261
+ OseoResult oseo_mapped_arguments_create(
262
+ OseoContext *context,
263
+ OseoValue environment,
264
+ OseoValue callee,
265
+ size_t argument_count,
266
+ const OseoValue *arguments,
267
+ const size_t *mapped_indices,
268
+ const size_t *mapped_binding_ids,
269
+ size_t mapped_count
270
+ ) {
271
+ if (argument_count > 0u && arguments == NULL) {
272
+ return failure(context, "OSEO2001", "Arguments are missing.");
273
+ }
274
+ if (mapped_count > 0u &&
275
+ (mapped_indices == NULL || mapped_binding_ids == NULL)) {
276
+ return failure(context, "OSEO2001", "Mapped parameters are missing.");
277
+ }
278
+ OseoRootFrame frame = {NULL, NULL, 0u};
279
+ OseoResult result = oseo_roots_allocate(context, &frame, 4u);
280
+ if (result.status != OSEO_STATUS_NORMAL) return result;
281
+ frame.slots[2] = callee;
282
+ result = oseo_object_literal_create(context);
283
+ frame.slots[0] = result.value;
284
+ if (result.status == OSEO_STATUS_NORMAL) {
285
+ ordinary_object(frame.slots[0])->arguments_object = true;
286
+ ordinary_object(frame.slots[0])->mapped_arguments = true;
287
+ }
288
+ const OseoPropertyAttributes indexed =
289
+ (OseoPropertyAttributes){true, true, true, false};
290
+ size_t mapped_position = 0u;
291
+ for (size_t index = 0u;
292
+ result.status == OSEO_STATUS_NORMAL && index < argument_count;
293
+ index += 1u) {
294
+ bool is_mapped = mapped_position < mapped_count &&
295
+ mapped_indices[mapped_position] == index;
296
+ if (is_mapped) {
297
+ result = oseo_environment_get(
298
+ context,
299
+ environment,
300
+ mapped_binding_ids[mapped_position]
301
+ );
302
+ mapped_position += 1u;
303
+ } else {
304
+ result = normal(arguments[index]);
305
+ }
306
+ frame.slots[3] = result.value;
307
+ if (result.status == OSEO_STATUS_NORMAL) {
308
+ result = oseo_property_key(context, oseo_number((double)index));
309
+ frame.slots[1] = result.value;
310
+ }
311
+ if (result.status == OSEO_STATUS_NORMAL) {
312
+ result = oseo_object_define(
313
+ context,
314
+ frame.slots[0],
315
+ frame.slots[1],
316
+ frame.slots[3],
317
+ indexed
318
+ );
319
+ }
320
+ }
321
+ const OseoPropertyAttributes metadata =
322
+ (OseoPropertyAttributes){true, false, true, false};
323
+ if (result.status == OSEO_STATUS_NORMAL) {
324
+ result = oseo_internal_ascii_string(context, "length");
325
+ frame.slots[1] = result.value;
326
+ }
327
+ if (result.status == OSEO_STATUS_NORMAL) {
328
+ result = oseo_object_define(
329
+ context,
330
+ frame.slots[0],
331
+ frame.slots[1],
332
+ oseo_number((double)argument_count),
333
+ metadata
334
+ );
335
+ }
336
+ if (result.status == OSEO_STATUS_NORMAL) {
337
+ result = oseo_internal_ascii_string(context, "callee");
338
+ frame.slots[1] = result.value;
339
+ }
340
+ if (result.status == OSEO_STATUS_NORMAL) {
341
+ result = oseo_object_define(
342
+ context,
343
+ frame.slots[0],
344
+ frame.slots[1],
345
+ frame.slots[2],
346
+ metadata
347
+ );
348
+ }
349
+ if (result.status == OSEO_STATUS_NORMAL) {
350
+ result = arguments_define_iterator(context, frame.slots[0]);
351
+ }
352
+ if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[0];
353
+ oseo_roots_release(context, &frame);
354
+ return result;
355
+ }