@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,1135 @@
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 <math.h>
31
+ #include <string.h>
32
+
33
+ /*
34
+ * The DataView constructor, its prototype accessors, and the eleven get
35
+ * and eleven set element accessors.
36
+ *
37
+ * A view never owns a Data Block. It holds only its buffer's value, so
38
+ * every access rereads that buffer's current pointer, byte length, and
39
+ * detached flag, and the collector keeps the block alive through the
40
+ * buffer rather than through the view. Nothing here frees a block, and
41
+ * nothing here caches one across a safepoint.
42
+ */
43
+
44
+ /* Element Size for each element type, in bytes. */
45
+ static const size_t data_view_element_size[OSEO_DATA_VIEW_ELEMENT_COUNT] = {
46
+ 1u, 1u, 2u, 2u, 4u, 4u, 2u, 4u, 8u, 8u, 8u,
47
+ };
48
+
49
+ static const char *const data_view_get_names[OSEO_DATA_VIEW_ELEMENT_COUNT] = {
50
+ "getInt8",
51
+ "getUint8",
52
+ "getInt16",
53
+ "getUint16",
54
+ "getInt32",
55
+ "getUint32",
56
+ "getFloat16",
57
+ "getFloat32",
58
+ "getFloat64",
59
+ "getBigInt64",
60
+ "getBigUint64",
61
+ };
62
+
63
+ static const char *const data_view_set_names[OSEO_DATA_VIEW_ELEMENT_COUNT] = {
64
+ "setInt8",
65
+ "setUint8",
66
+ "setInt16",
67
+ "setUint16",
68
+ "setInt32",
69
+ "setUint32",
70
+ "setFloat16",
71
+ "setFloat32",
72
+ "setFloat64",
73
+ "setBigInt64",
74
+ "setBigUint64",
75
+ };
76
+
77
+ /* IsBigIntElementType(type). */
78
+ static bool data_view_element_is_bigint(OseoDataViewElement element) {
79
+ return element == OSEO_DATA_VIEW_BIGINT64 ||
80
+ element == OSEO_DATA_VIEW_BIGUINT64;
81
+ }
82
+
83
+ /*
84
+ * The IEEE 754 binary interchange encoding of `value` in the format with
85
+ * `significand_bits` stored significand bits and `exponent_bits`
86
+ * exponent bits, rounded to nearest with ties to even.
87
+ *
88
+ * The whole computation is exact integer arithmetic over the operand's
89
+ * own binary64 encoding, so no narrowing floating conversion happens and
90
+ * an operand outside the destination range cannot reach one. ECMA-262
91
+ * leaves the encoding of a NaN to the implementation for every format,
92
+ * so a NaN becomes this format's canonical quiet NaN. A zero keeps its
93
+ * sign.
94
+ */
95
+ static uint64_t encode_ieee(
96
+ double value,
97
+ unsigned significand_bits,
98
+ unsigned exponent_bits
99
+ ) {
100
+ uint64_t source;
101
+ memcpy(&source, &value, sizeof(source));
102
+ uint64_t sign = (source >> 63u) << (significand_bits + exponent_bits);
103
+ uint64_t exponent_mask = (UINT64_C(1) << exponent_bits) - 1u;
104
+ uint64_t infinity = exponent_mask << significand_bits;
105
+ uint64_t implicit = UINT64_C(1) << significand_bits;
106
+ uint64_t mantissa = source & UINT64_C(0x000fffffffffffff);
107
+ int source_exponent = (int)((source >> 52u) & UINT64_C(0x7ff));
108
+ if (source_exponent == 0x7ff) {
109
+ if (mantissa != 0u) return sign | infinity | (implicit >> 1u);
110
+ return sign | infinity;
111
+ }
112
+ /* |value| is exactly `magnitude` times 2**scale. */
113
+ uint64_t magnitude;
114
+ int scale;
115
+ if (source_exponent == 0) {
116
+ magnitude = mantissa;
117
+ scale = -1074;
118
+ } else {
119
+ magnitude = mantissa | (UINT64_C(1) << 52u);
120
+ scale = source_exponent - 1075;
121
+ }
122
+ if (magnitude == 0u) return sign;
123
+ int highest = 63;
124
+ while ((magnitude >> (unsigned)highest) == 0u) highest -= 1;
125
+ int exponent = highest + scale;
126
+ int bias = (int)(exponent_mask >> 1u);
127
+ if (exponent > bias) return sign | infinity;
128
+ /* A normal of this exponent has its own quantum; every subnormal
129
+ * shares one, and rounding a subnormal up can reach the smallest
130
+ * normal, which is why the two cases stay distinct below. */
131
+ int minimum = 1 - bias;
132
+ bool subnormal = exponent < minimum;
133
+ int quantum = (subnormal ? minimum : exponent) - (int)significand_bits;
134
+ int shift = quantum - scale;
135
+ uint64_t rounded;
136
+ if (shift <= 0) {
137
+ /* The operand is already a multiple of the quantum; the result
138
+ * stays below 2**(significand_bits + 1), so the shift is exact. */
139
+ rounded = magnitude << (unsigned)(-shift);
140
+ } else if (shift >= 64) {
141
+ /* The exact quotient is below one half, so nothing rounds up. */
142
+ rounded = 0u;
143
+ } else {
144
+ uint64_t truncated = magnitude >> (unsigned)shift;
145
+ uint64_t remainder =
146
+ magnitude & ((UINT64_C(1) << (unsigned)shift) - 1u);
147
+ uint64_t half = UINT64_C(1) << (unsigned)(shift - 1);
148
+ if (remainder > half || (remainder == half && (truncated & 1u) != 0u)) {
149
+ truncated += 1u;
150
+ }
151
+ rounded = truncated;
152
+ }
153
+ if (subnormal) {
154
+ /* A subnormal, or the smallest normal the rounding carried into. */
155
+ if (rounded < implicit) return sign | rounded;
156
+ return sign | implicit;
157
+ }
158
+ if (rounded == implicit << 1u) {
159
+ rounded >>= 1u;
160
+ exponent += 1;
161
+ if (exponent > bias) return sign | infinity;
162
+ }
163
+ return sign | ((uint64_t)(exponent + bias) << significand_bits) |
164
+ (rounded - implicit);
165
+ }
166
+
167
+ /* The exact Number one binary interchange encoding denotes. */
168
+ static double decode_ieee(
169
+ uint64_t bits,
170
+ unsigned significand_bits,
171
+ unsigned exponent_bits
172
+ ) {
173
+ uint64_t exponent_mask = (UINT64_C(1) << exponent_bits) - 1u;
174
+ uint64_t implicit = UINT64_C(1) << significand_bits;
175
+ bool negative =
176
+ ((bits >> (significand_bits + exponent_bits)) & 1u) != 0u;
177
+ uint64_t field = (bits >> significand_bits) & exponent_mask;
178
+ uint64_t fraction = bits & (implicit - 1u);
179
+ int bias = (int)(exponent_mask >> 1u);
180
+ double magnitude;
181
+ if (field == exponent_mask) {
182
+ magnitude = fraction == 0u ? (double)INFINITY : (double)NAN;
183
+ } else if (field == 0u) {
184
+ magnitude =
185
+ ldexp((double)fraction, 1 - bias - (int)significand_bits);
186
+ } else {
187
+ magnitude = ldexp(
188
+ (double)(fraction | implicit),
189
+ (int)field - bias - (int)significand_bits
190
+ );
191
+ }
192
+ return negative ? -magnitude : magnitude;
193
+ }
194
+
195
+ /*
196
+ * ToInt8, ToUint8, ToInt16, ToUint16, ToInt32, and ToUint32 over an
197
+ * already converted Number: the exact truncated value modulo 2**bits.
198
+ * `fmod` is exact for binary64 operands, so the wrapped value is the
199
+ * specified integer and its conversion to an unsigned host integer is
200
+ * in range.
201
+ */
202
+ static uint64_t number_to_wrapped(double value, size_t bytes) {
203
+ if (!isfinite(value)) return 0u;
204
+ double modulus = ldexp(1.0, (int)(bytes * 8u));
205
+ double wrapped = fmod(trunc(value), modulus);
206
+ if (wrapped < 0.0) wrapped += modulus;
207
+ return (uint64_t)wrapped;
208
+ }
209
+
210
+ /*
211
+ * The signed reading of a `bytes`-wide two's-complement encoding. Only
212
+ * the one, two, and four byte element types reach it, so the value and
213
+ * the modulus are both exact binary64 integers.
214
+ */
215
+ static double wrapped_to_signed(uint64_t bits, size_t bytes) {
216
+ double modulus = ldexp(1.0, (int)(bytes * 8u));
217
+ double magnitude = (double)bits;
218
+ return magnitude >= modulus / 2.0 ? magnitude - modulus : magnitude;
219
+ }
220
+
221
+ /* NumericToRawBytes for every element type whose value is a Number. */
222
+ static uint64_t number_to_raw_bytes(
223
+ double value,
224
+ OseoDataViewElement element
225
+ ) {
226
+ if (element == OSEO_DATA_VIEW_FLOAT16) return encode_ieee(value, 10u, 5u);
227
+ if (element == OSEO_DATA_VIEW_FLOAT32) return encode_ieee(value, 23u, 8u);
228
+ if (element == OSEO_DATA_VIEW_FLOAT64) {
229
+ uint64_t bits;
230
+ memcpy(&bits, &value, sizeof(bits));
231
+ return bits;
232
+ }
233
+ return number_to_wrapped(value, data_view_element_size[element]);
234
+ }
235
+
236
+ uint16_t oseo_internal_float16_bits(double value) {
237
+ return (uint16_t)encode_ieee(value, 10u, 5u);
238
+ }
239
+
240
+ double oseo_internal_float16_number(uint16_t bits) {
241
+ return decode_ieee(bits, 10u, 5u);
242
+ }
243
+
244
+ /* RawBytesToNumeric for every element type whose value is a Number. */
245
+ static double raw_bytes_to_number(
246
+ uint64_t bits,
247
+ OseoDataViewElement element
248
+ ) {
249
+ if (element == OSEO_DATA_VIEW_FLOAT16) return decode_ieee(bits, 10u, 5u);
250
+ if (element == OSEO_DATA_VIEW_FLOAT32) return decode_ieee(bits, 23u, 8u);
251
+ if (element == OSEO_DATA_VIEW_FLOAT64) {
252
+ double value;
253
+ memcpy(&value, &bits, sizeof(value));
254
+ return value;
255
+ }
256
+ if (element == OSEO_DATA_VIEW_INT8 || element == OSEO_DATA_VIEW_INT16 ||
257
+ element == OSEO_DATA_VIEW_INT32) {
258
+ return wrapped_to_signed(bits, data_view_element_size[element]);
259
+ }
260
+ return (double)bits;
261
+ }
262
+
263
+ /* RequireInternalSlot(this, [[DataView]]). */
264
+ static OseoResult data_view_receiver(
265
+ OseoContext *context,
266
+ OseoValue receiver
267
+ ) {
268
+ if (is_data_view(receiver)) return normal(receiver);
269
+ return oseo_internal_throw_error(
270
+ context,
271
+ OSEO_ERROR_TYPE,
272
+ "DataView method receiver is not a DataView."
273
+ );
274
+ }
275
+
276
+ /*
277
+ * IsViewOutOfBounds over a witness record taken now. A detached buffer
278
+ * is out of bounds, a length-tracking view only needs its offset to
279
+ * still be inside the buffer, and a zero-length view exactly at the end
280
+ * of the buffer is in bounds.
281
+ */
282
+ static bool data_view_out_of_bounds(const OseoDataView *view) {
283
+ const OseoArrayBuffer *buffer = array_buffer_object(view->buffer);
284
+ if (buffer->detached) return true;
285
+ size_t length = array_buffer_current_length(buffer);
286
+ if (view->byte_offset > length) return true;
287
+ if (view->track_length) return false;
288
+ return view->byte_length > length - view->byte_offset;
289
+ }
290
+
291
+ /*
292
+ * GetViewByteLength. The caller has already rejected an out-of-bounds
293
+ * view, so a tracking view's offset is inside its buffer and the
294
+ * subtraction cannot wrap.
295
+ */
296
+ static size_t data_view_length(const OseoDataView *view) {
297
+ if (!view->track_length) return view->byte_length;
298
+ return array_buffer_current_length(array_buffer_object(view->buffer)) -
299
+ view->byte_offset;
300
+ }
301
+
302
+ /*
303
+ * OrdinaryCreateFromConstructor(newTarget, "%DataView.prototype%"). The
304
+ * `prototype` read is the specified Get, so a new target whose property
305
+ * is an accessor runs it, and a non-object result falls back to the
306
+ * realm prototype.
307
+ */
308
+ static OseoResult data_view_prototype_from_target(
309
+ OseoContext *context,
310
+ OseoValue new_target,
311
+ OseoValue *prototype
312
+ ) {
313
+ OseoRootFrame frame = {NULL, NULL, 0u};
314
+ OseoResult result = oseo_roots_allocate(context, &frame, 2u);
315
+ if (result.status != OSEO_STATUS_NORMAL) return result;
316
+ frame.slots[0] = new_target;
317
+ result = oseo_internal_ascii_string(context, "prototype");
318
+ frame.slots[1] = result.value;
319
+ if (result.status == OSEO_STATUS_NORMAL) {
320
+ result = oseo_object_get(context, frame.slots[0], frame.slots[1]);
321
+ frame.slots[1] = result.value;
322
+ }
323
+ if (result.status == OSEO_STATUS_NORMAL && !is_object(frame.slots[1])) {
324
+ result = oseo_internal_constructor_realm_default(
325
+ context,
326
+ frame.slots[0],
327
+ OSEO_INTRINSIC_DATA_VIEW_PROTOTYPE
328
+ );
329
+ frame.slots[1] = result.value;
330
+ }
331
+ if (result.status == OSEO_STATUS_NORMAL) *prototype = frame.slots[1];
332
+ oseo_roots_release(context, &frame);
333
+ return result;
334
+ }
335
+
336
+ /*
337
+ * One DataView over `buffer`. The record is published with its final
338
+ * slots, so the collector traces the buffer from the moment the view
339
+ * exists and the view never appears with an untraced or absent buffer.
340
+ */
341
+ static OseoResult data_view_allocate(
342
+ OseoContext *context,
343
+ OseoValue prototype,
344
+ OseoValue buffer,
345
+ size_t byte_offset,
346
+ size_t byte_length,
347
+ bool track_length
348
+ ) {
349
+ OseoValue slots[2] = {prototype, buffer};
350
+ OseoRootFrame frame = {NULL, slots, 2u};
351
+ oseo_roots_push(context, &frame);
352
+ OseoDataView *view =
353
+ oseo_internal_allocate_heap_bytes(context, sizeof(*view));
354
+ if (view == NULL) {
355
+ oseo_roots_pop(context, &frame);
356
+ return failure(context, "OSEO2001", "DataView allocation failed.");
357
+ }
358
+ view->ordinary.prototype = slots[0];
359
+ view->ordinary.properties = NULL;
360
+ view->ordinary.property_capacity = 0u;
361
+ view->ordinary.property_count = 0u;
362
+ oseo_internal_init_dense_index(&view->ordinary);
363
+ view->ordinary.private_elements = NULL;
364
+ view->ordinary.private_element_capacity = 0u;
365
+ view->ordinary.private_element_count = 0u;
366
+ view->ordinary.shape_id = context->next_shape_id;
367
+ context->next_shape_id += 1u;
368
+ view->ordinary.array_length = 0u;
369
+ view->ordinary.dictionary = false;
370
+ view->ordinary.length_writable = false;
371
+ view->ordinary.extensible = true;
372
+ view->ordinary.module_namespace = false;
373
+ view->ordinary.immutable_prototype = false;
374
+ view->ordinary.global_object = false;
375
+ view->ordinary.error_data = false;
376
+ view->ordinary.number_data = false;
377
+ view->ordinary.number_value = oseo_undefined();
378
+ view->ordinary.primitive_data = false;
379
+ view->ordinary.primitive_value = oseo_undefined();
380
+ view->ordinary.primitive_wrapper_methods_initialized = false;
381
+ view->ordinary.virtual_string_iterator = false;
382
+ view->ordinary.virtual_string_iterator_configurable = false;
383
+ view->ordinary.virtual_string_iterator_enumerable = false;
384
+ view->ordinary.virtual_string_iterator_writable = false;
385
+ view->ordinary.iterator_kind = OSEO_ITERATOR_NONE;
386
+ view->ordinary.iterator_target = oseo_undefined();
387
+ view->ordinary.iterator_index = 0u;
388
+ view->ordinary.regexp_string_iterator = false;
389
+ view->ordinary.regexp_iterator_regexp = oseo_undefined();
390
+ view->ordinary.regexp_iterator_subject = oseo_undefined();
391
+ view->ordinary.regexp_iterator_global = false;
392
+ view->ordinary.regexp_iterator_unicode = false;
393
+ view->ordinary.regexp_iterator_complete = false;
394
+ view->ordinary.async_from_sync = false;
395
+ view->ordinary.async_sync_iterator = oseo_undefined();
396
+ view->ordinary.wrap_for_valid_iterator = false;
397
+ view->ordinary.wrapped_iterator = oseo_undefined();
398
+ view->ordinary.wrapped_next = oseo_undefined();
399
+ view->ordinary.generator = NULL;
400
+ view->ordinary.arguments_object = false;
401
+ view->ordinary.mapped_arguments = false;
402
+ view->buffer = slots[1];
403
+ view->byte_offset = byte_offset;
404
+ view->byte_length = byte_length;
405
+ view->track_length = track_length;
406
+ OseoResult published = oseo_internal_publish_heap(
407
+ context,
408
+ &view->ordinary.header,
409
+ OSEO_HEAP_DATA_VIEW
410
+ );
411
+ oseo_roots_pop(context, &frame);
412
+ return published;
413
+ }
414
+
415
+ /*
416
+ * The DataView constructor, 25.3.2.1. Both length arguments run through
417
+ * ToIndex before the buffer is inspected again, the new target's
418
+ * `prototype` read sits between the two validations the specification
419
+ * performs, and the second validation observes whatever that arbitrary
420
+ * code did to the buffer.
421
+ */
422
+ static OseoResult data_view_construct(
423
+ OseoContext *context,
424
+ size_t argument_count,
425
+ const OseoValue *arguments,
426
+ OseoValue new_target
427
+ ) {
428
+ if (tag_of(new_target) == OSEO_TAG_UNDEFINED) {
429
+ return oseo_internal_throw_error(
430
+ context,
431
+ OSEO_ERROR_TYPE,
432
+ "DataView requires new."
433
+ );
434
+ }
435
+ OseoValue buffer = argument_count == 0u ? oseo_undefined() : arguments[0];
436
+ if (!is_array_buffer(buffer)) {
437
+ return oseo_internal_throw_error(
438
+ context,
439
+ OSEO_ERROR_TYPE,
440
+ "DataView requires an ArrayBuffer."
441
+ );
442
+ }
443
+ OseoValue slots[3] = {new_target, buffer, oseo_undefined()};
444
+ OseoRootFrame frame = {NULL, slots, 3u};
445
+ oseo_roots_push(context, &frame);
446
+ double offset = 0.0;
447
+ OseoResult result = oseo_internal_to_index(
448
+ context,
449
+ argument_count < 2u ? oseo_undefined() : arguments[1],
450
+ "DataView byte offset is outside the admitted index range.",
451
+ &offset
452
+ );
453
+ /* The conversion is a safepoint and can run arbitrary code, so the
454
+ * buffer record is reacquired from the rooted value every time. */
455
+ if (result.status == OSEO_STATUS_NORMAL &&
456
+ array_buffer_object(slots[1])->detached) {
457
+ result = oseo_internal_throw_error(
458
+ context,
459
+ OSEO_ERROR_TYPE,
460
+ "DataView requires an attached ArrayBuffer."
461
+ );
462
+ }
463
+ double buffer_length = 0.0;
464
+ if (result.status == OSEO_STATUS_NORMAL) {
465
+ buffer_length = (double)array_buffer_current_length(
466
+ array_buffer_object(slots[1])
467
+ );
468
+ if (offset > buffer_length) {
469
+ result = oseo_internal_throw_error(
470
+ context,
471
+ OSEO_ERROR_RANGE,
472
+ "DataView byte offset is past the end of its buffer."
473
+ );
474
+ }
475
+ }
476
+ OseoValue requested =
477
+ argument_count < 3u ? oseo_undefined() : arguments[2];
478
+ bool track_length = false;
479
+ double length = 0.0;
480
+ if (result.status == OSEO_STATUS_NORMAL &&
481
+ tag_of(requested) == OSEO_TAG_UNDEFINED) {
482
+ /* A resizable buffer gives an absent length the specification's
483
+ * `auto`; a fixed-length buffer fixes it now. */
484
+ track_length = array_buffer_object(slots[1])->resizable;
485
+ length = track_length ? 0.0 : buffer_length - offset;
486
+ } else if (result.status == OSEO_STATUS_NORMAL) {
487
+ result = oseo_internal_to_index(
488
+ context,
489
+ requested,
490
+ "DataView byte length is outside the admitted index range.",
491
+ &length
492
+ );
493
+ /*
494
+ * The specification compares against the byte length it read
495
+ * before this conversion, not a fresh one, so a conversion that
496
+ * grows a resizable buffer still fails this bound.
497
+ */
498
+ if (result.status == OSEO_STATUS_NORMAL &&
499
+ offset + length > buffer_length) {
500
+ result = oseo_internal_throw_error(
501
+ context,
502
+ OSEO_ERROR_RANGE,
503
+ "DataView byte length is past the end of its buffer."
504
+ );
505
+ }
506
+ }
507
+ if (result.status == OSEO_STATUS_NORMAL) {
508
+ result = data_view_prototype_from_target(
509
+ context,
510
+ slots[0],
511
+ &slots[2]
512
+ );
513
+ }
514
+ /* The `prototype` read is arbitrary code, so the buffer may have
515
+ * been detached or resized while it ran. */
516
+ if (result.status == OSEO_STATUS_NORMAL &&
517
+ array_buffer_object(slots[1])->detached) {
518
+ result = oseo_internal_throw_error(
519
+ context,
520
+ OSEO_ERROR_TYPE,
521
+ "DataView buffer became detached."
522
+ );
523
+ }
524
+ if (result.status == OSEO_STATUS_NORMAL) {
525
+ double current = (double)array_buffer_current_length(
526
+ array_buffer_object(slots[1])
527
+ );
528
+ if (offset > current) {
529
+ result = oseo_internal_throw_error(
530
+ context,
531
+ OSEO_ERROR_RANGE,
532
+ "DataView byte offset is past the end of its buffer."
533
+ );
534
+ } else if (tag_of(requested) != OSEO_TAG_UNDEFINED &&
535
+ offset + length > current) {
536
+ result = oseo_internal_throw_error(
537
+ context,
538
+ OSEO_ERROR_RANGE,
539
+ "DataView byte length is past the end of its buffer."
540
+ );
541
+ }
542
+ }
543
+ if (result.status == OSEO_STATUS_NORMAL) {
544
+ /* Both values passed a comparison against a live byte length, so
545
+ * each is inside the reviewed Data Block limit and converts
546
+ * exactly. */
547
+ result = data_view_allocate(
548
+ context,
549
+ slots[2],
550
+ slots[1],
551
+ (size_t)offset,
552
+ (size_t)length,
553
+ track_length
554
+ );
555
+ }
556
+ oseo_roots_pop(context, &frame);
557
+ return result;
558
+ }
559
+
560
+ static OseoResult data_view_buffer_accessor(
561
+ OseoContext *context,
562
+ OseoValue receiver
563
+ ) {
564
+ OseoResult checked = data_view_receiver(context, receiver);
565
+ if (checked.status != OSEO_STATUS_NORMAL) return checked;
566
+ return normal(data_view_object(receiver)->buffer);
567
+ }
568
+
569
+ /*
570
+ * Both length accessors reject a view whose buffer detached or shrank
571
+ * out from under it, which is the one place a detached buffer is a
572
+ * TypeError rather than a reported zero.
573
+ */
574
+ static OseoResult data_view_measure(
575
+ OseoContext *context,
576
+ OseoValue receiver,
577
+ bool report_offset
578
+ ) {
579
+ OseoResult checked = data_view_receiver(context, receiver);
580
+ if (checked.status != OSEO_STATUS_NORMAL) return checked;
581
+ const OseoDataView *view = data_view_object(receiver);
582
+ if (data_view_out_of_bounds(view)) {
583
+ return oseo_internal_throw_error(
584
+ context,
585
+ OSEO_ERROR_TYPE,
586
+ "DataView is outside the bounds of its buffer."
587
+ );
588
+ }
589
+ return normal(oseo_number(
590
+ (double)(report_offset ? view->byte_offset : data_view_length(view))
591
+ ));
592
+ }
593
+
594
+ /*
595
+ * The bounds shared by GetViewValue and SetViewValue, run after every
596
+ * conversion the specification orders first. `offset` reports the index
597
+ * of the element inside the buffer's Data Block.
598
+ */
599
+ static OseoResult data_view_locate(
600
+ OseoContext *context,
601
+ OseoValue receiver,
602
+ double request,
603
+ OseoDataViewElement element,
604
+ size_t *offset
605
+ ) {
606
+ const OseoDataView *view = data_view_object(receiver);
607
+ if (data_view_out_of_bounds(view)) {
608
+ return oseo_internal_throw_error(
609
+ context,
610
+ OSEO_ERROR_TYPE,
611
+ "DataView is outside the bounds of its buffer."
612
+ );
613
+ }
614
+ size_t view_size = data_view_length(view);
615
+ size_t element_size = data_view_element_size[element];
616
+ /* The first comparison keeps the conversion below in range; the
617
+ * second is `request + elementSize > viewSize` written so that no
618
+ * host addition can wrap. */
619
+ if (!(request <= (double)view_size) ||
620
+ element_size > view_size - (size_t)request) {
621
+ return oseo_internal_throw_error(
622
+ context,
623
+ OSEO_ERROR_RANGE,
624
+ "DataView access is outside the bounds of its view."
625
+ );
626
+ }
627
+ *offset = view->byte_offset + (size_t)request;
628
+ return normal(oseo_undefined());
629
+ }
630
+
631
+ /*
632
+ * GetValueFromBuffer's byte order. The bytes are assembled through a
633
+ * local copy rather than a cast, so no access depends on the Data Block
634
+ * being aligned for the element type.
635
+ */
636
+ static uint64_t data_view_load(
637
+ const OseoDataView *view,
638
+ size_t offset,
639
+ size_t element_size,
640
+ bool little_endian
641
+ ) {
642
+ const OseoArrayBuffer *buffer = array_buffer_object(view->buffer);
643
+ uint8_t raw[8] = {0};
644
+ /* The bounds proved that `element_size` bytes lie inside the block,
645
+ * so the block exists and the copy stays in range. */
646
+ memcpy(raw, buffer->data + offset, element_size);
647
+ uint64_t bits = 0u;
648
+ for (size_t index = element_size; index > 0u; index -= 1u) {
649
+ size_t byte = little_endian ? index - 1u : element_size - index;
650
+ bits = (bits << 8u) | (uint64_t)raw[byte];
651
+ }
652
+ return bits;
653
+ }
654
+
655
+ /* SetValueInBuffer's byte order, with the same alignment independence. */
656
+ static void data_view_store(
657
+ const OseoDataView *view,
658
+ size_t offset,
659
+ size_t element_size,
660
+ bool little_endian,
661
+ uint64_t bits
662
+ ) {
663
+ OseoArrayBuffer *buffer = array_buffer_object(view->buffer);
664
+ uint8_t raw[8] = {0};
665
+ for (size_t index = 0u; index < element_size; index += 1u) {
666
+ size_t byte = little_endian ? index : element_size - 1u - index;
667
+ raw[byte] = (uint8_t)(bits & 0xffu);
668
+ bits >>= 8u;
669
+ }
670
+ memcpy(buffer->data + offset, raw, element_size);
671
+ }
672
+
673
+ /* GetViewValue(view, requestIndex, isLittleEndian, type), 25.3.1.1. */
674
+ static OseoResult data_view_get(
675
+ OseoContext *context,
676
+ OseoValue receiver,
677
+ size_t argument_count,
678
+ const OseoValue *arguments,
679
+ OseoDataViewElement element
680
+ ) {
681
+ OseoResult checked = data_view_receiver(context, receiver);
682
+ if (checked.status != OSEO_STATUS_NORMAL) return checked;
683
+ OseoValue slot = receiver;
684
+ OseoRootFrame frame = {NULL, &slot, 1u};
685
+ oseo_roots_push(context, &frame);
686
+ double request = 0.0;
687
+ OseoResult result = oseo_internal_to_index(
688
+ context,
689
+ argument_count == 0u ? oseo_undefined() : arguments[0],
690
+ "DataView byte offset is outside the admitted index range.",
691
+ &request
692
+ );
693
+ size_t element_size = data_view_element_size[element];
694
+ /* A one-byte element has no byte order, so the specification passes
695
+ * true rather than reading the argument. */
696
+ bool little_endian = element_size == 1u ||
697
+ (argument_count > 1u && oseo_to_boolean(arguments[1]));
698
+ size_t offset = 0u;
699
+ if (result.status == OSEO_STATUS_NORMAL) {
700
+ /* The conversion is a safepoint, so the view and its buffer are
701
+ * reread from the rooted receiver. */
702
+ result = data_view_locate(context, slot, request, element, &offset);
703
+ }
704
+ if (result.status == OSEO_STATUS_NORMAL) {
705
+ uint64_t bits = data_view_load(
706
+ data_view_object(slot),
707
+ offset,
708
+ element_size,
709
+ little_endian
710
+ );
711
+ if (element == OSEO_DATA_VIEW_BIGINT64) {
712
+ bool negative = (bits >> 63u) != 0u;
713
+ result = oseo_internal_bigint_from_uint64(
714
+ context,
715
+ negative ? UINT64_C(0) - bits : bits,
716
+ negative
717
+ );
718
+ } else if (element == OSEO_DATA_VIEW_BIGUINT64) {
719
+ result = oseo_internal_bigint_from_uint64(context, bits, false);
720
+ } else {
721
+ result = normal(
722
+ oseo_number(raw_bytes_to_number(bits, element))
723
+ );
724
+ }
725
+ }
726
+ oseo_roots_pop(context, &frame);
727
+ return result;
728
+ }
729
+
730
+ /* SetViewValue(view, requestIndex, isLittleEndian, type, value). */
731
+ static OseoResult data_view_set(
732
+ OseoContext *context,
733
+ OseoValue receiver,
734
+ size_t argument_count,
735
+ const OseoValue *arguments,
736
+ OseoDataViewElement element
737
+ ) {
738
+ OseoResult checked = data_view_receiver(context, receiver);
739
+ if (checked.status != OSEO_STATUS_NORMAL) return checked;
740
+ OseoValue slots[2] = {receiver, oseo_undefined()};
741
+ OseoRootFrame frame = {NULL, slots, 2u};
742
+ oseo_roots_push(context, &frame);
743
+ double request = 0.0;
744
+ OseoResult result = oseo_internal_to_index(
745
+ context,
746
+ argument_count == 0u ? oseo_undefined() : arguments[0],
747
+ "DataView byte offset is outside the admitted index range.",
748
+ &request
749
+ );
750
+ OseoValue value = argument_count < 2u ? oseo_undefined() : arguments[1];
751
+ /* The numeric conversion runs before every bounds check, so a value
752
+ * whose conversion detaches the buffer still observes the specified
753
+ * TypeError afterwards. */
754
+ if (result.status == OSEO_STATUS_NORMAL) {
755
+ result = data_view_element_is_bigint(element)
756
+ ? oseo_internal_to_bigint(context, value)
757
+ : oseo_internal_to_number(context, value);
758
+ slots[1] = result.value;
759
+ }
760
+ size_t element_size = data_view_element_size[element];
761
+ bool little_endian = element_size == 1u ||
762
+ (argument_count > 2u && oseo_to_boolean(arguments[2]));
763
+ size_t offset = 0u;
764
+ if (result.status == OSEO_STATUS_NORMAL) {
765
+ result = data_view_locate(
766
+ context,
767
+ slots[0],
768
+ request,
769
+ element,
770
+ &offset
771
+ );
772
+ }
773
+ if (result.status == OSEO_STATUS_NORMAL) {
774
+ uint64_t bits = data_view_element_is_bigint(element)
775
+ ? oseo_internal_bigint_to_raw_uint64(slots[1])
776
+ : number_to_raw_bytes(number_value(slots[1]), element);
777
+ data_view_store(
778
+ data_view_object(slots[0]),
779
+ offset,
780
+ element_size,
781
+ little_endian,
782
+ bits
783
+ );
784
+ result = normal(oseo_undefined());
785
+ }
786
+ oseo_roots_pop(context, &frame);
787
+ return result;
788
+ }
789
+
790
+ OseoResult oseo_internal_data_view_builtin_dispatch(
791
+ OseoContext *context,
792
+ size_t code_id,
793
+ OseoValue callee,
794
+ OseoValue receiver,
795
+ size_t argument_count,
796
+ const OseoValue *arguments,
797
+ OseoValue new_target
798
+ ) {
799
+ (void)callee;
800
+ if (code_id == OSEO_DATA_VIEW_CONSTRUCTOR_CODE_ID) {
801
+ return data_view_construct(
802
+ context,
803
+ argument_count,
804
+ arguments,
805
+ new_target
806
+ );
807
+ }
808
+ if (tag_of(new_target) != OSEO_TAG_UNDEFINED) {
809
+ return oseo_internal_throw_error(
810
+ context,
811
+ OSEO_ERROR_TYPE,
812
+ "DataView method is not a constructor."
813
+ );
814
+ }
815
+ if (code_id == OSEO_DATA_VIEW_BUFFER_CODE_ID) {
816
+ return data_view_buffer_accessor(context, receiver);
817
+ }
818
+ if (code_id == OSEO_DATA_VIEW_BYTE_LENGTH_CODE_ID) {
819
+ return data_view_measure(context, receiver, false);
820
+ }
821
+ if (code_id == OSEO_DATA_VIEW_BYTE_OFFSET_CODE_ID) {
822
+ return data_view_measure(context, receiver, true);
823
+ }
824
+ if (code_id >= OSEO_DATA_VIEW_GET_CODE_ID_FIRST &&
825
+ code_id <= OSEO_DATA_VIEW_GET_CODE_ID_LAST) {
826
+ return data_view_get(
827
+ context,
828
+ receiver,
829
+ argument_count,
830
+ arguments,
831
+ (OseoDataViewElement)(OSEO_DATA_VIEW_GET_CODE_ID_LAST - code_id)
832
+ );
833
+ }
834
+ if (code_id >= OSEO_DATA_VIEW_SET_CODE_ID_FIRST &&
835
+ code_id <= OSEO_DATA_VIEW_SET_CODE_ID_LAST) {
836
+ return data_view_set(
837
+ context,
838
+ receiver,
839
+ argument_count,
840
+ arguments,
841
+ (OseoDataViewElement)(OSEO_DATA_VIEW_SET_CODE_ID_LAST - code_id)
842
+ );
843
+ }
844
+ return oseo_unknown_function(context, code_id);
845
+ }
846
+
847
+ static OseoResult create_data_view_builtin(
848
+ OseoContext *context,
849
+ size_t code_id,
850
+ const char *name,
851
+ size_t length,
852
+ OseoFunctionKind kind,
853
+ OseoFunctionNamePrefix prefix
854
+ ) {
855
+ size_t name_length = strlen(name);
856
+ uint16_t units[32];
857
+ if (name_length > sizeof(units) / sizeof(*units)) {
858
+ return failure(context, "OSEO2001", "Built-in name is too long.");
859
+ }
860
+ for (size_t index = 0u; index < name_length; index += 1u) {
861
+ units[index] = (uint16_t)(unsigned char)name[index];
862
+ }
863
+ OseoValue environment = oseo_undefined();
864
+ OseoRootFrame frame = {NULL, &environment, 1u};
865
+ oseo_roots_push(context, &frame);
866
+ OseoResult result = oseo_environment_create(context, 0u);
867
+ environment = result.value;
868
+ if (result.status == OSEO_STATUS_NORMAL) {
869
+ result = oseo_function_create(
870
+ context,
871
+ code_id,
872
+ environment,
873
+ units,
874
+ name_length,
875
+ length,
876
+ kind,
877
+ oseo_undefined(),
878
+ oseo_undefined(),
879
+ prefix
880
+ );
881
+ }
882
+ oseo_roots_pop(context, &frame);
883
+ return result;
884
+ }
885
+
886
+ static OseoResult define_data_view_property(
887
+ OseoContext *context,
888
+ OseoValue object,
889
+ const char *name,
890
+ OseoValue value,
891
+ OseoPropertyAttributes attributes
892
+ ) {
893
+ OseoValue slots[3] = {object, value, oseo_undefined()};
894
+ OseoRootFrame frame = {NULL, slots, 3u};
895
+ oseo_roots_push(context, &frame);
896
+ OseoResult result = oseo_internal_ascii_string(context, name);
897
+ slots[2] = result.value;
898
+ if (result.status == OSEO_STATUS_NORMAL) {
899
+ result = oseo_object_define(
900
+ context,
901
+ slots[0],
902
+ slots[2],
903
+ slots[1],
904
+ attributes
905
+ );
906
+ }
907
+ oseo_roots_pop(context, &frame);
908
+ return result;
909
+ }
910
+
911
+ /* One getter-only own accessor of %DataView.prototype%. */
912
+ static OseoResult define_data_view_accessor(
913
+ OseoContext *context,
914
+ OseoValue object,
915
+ const char *name,
916
+ OseoValue getter
917
+ ) {
918
+ OseoValue slots[3] = {object, getter, oseo_undefined()};
919
+ OseoRootFrame frame = {NULL, slots, 3u};
920
+ oseo_roots_push(context, &frame);
921
+ OseoResult result = oseo_internal_ascii_string(context, name);
922
+ slots[2] = result.value;
923
+ if (result.status == OSEO_STATUS_NORMAL) {
924
+ result = oseo_object_define_accessor(
925
+ context,
926
+ slots[0],
927
+ slots[2],
928
+ slots[1],
929
+ oseo_undefined(),
930
+ true,
931
+ false,
932
+ (OseoPropertyAttributes){true, false, false, true}
933
+ );
934
+ }
935
+ oseo_roots_pop(context, &frame);
936
+ return result;
937
+ }
938
+
939
+ /*
940
+ * Materializes %DataView%, %DataView.prototype%, and every own property
941
+ * ECMA-262 gives them.
942
+ * `OSEO_INTRINSIC_DATA_VIEW_SET_BIG_UINT64` is filled last, so it
943
+ * doubles as the completion marker: a partially built cluster leaves it
944
+ * undefined and the failure path clears every slot the attempt filled.
945
+ * The marker holds the uninitialized sentinel while the attempt runs, so
946
+ * a dependency that reentered the build reports that instead of
947
+ * splitting the constructor and prototype identities across two
948
+ * attempts.
949
+ */
950
+ static OseoResult data_view_intrinsic_build(OseoContext *context) {
951
+ OseoValue *marker =
952
+ &context->realm->intrinsics[OSEO_INTRINSIC_DATA_VIEW_SET_BIG_UINT64];
953
+ if (tag_of(*marker) == OSEO_TAG_UNINITIALIZED) {
954
+ return failure(
955
+ context,
956
+ "OSEO2001",
957
+ "The DataView intrinsic cluster is already being built."
958
+ );
959
+ }
960
+ if (tag_of(*marker) != OSEO_TAG_UNDEFINED) return normal(*marker);
961
+ size_t entry_allocations = context->allocations;
962
+ OseoRootFrame frame = {NULL, NULL, 0u};
963
+ OseoResult result = oseo_roots_allocate(context, &frame, 5u);
964
+ if (result.status != OSEO_STATUS_NORMAL) return result;
965
+ *marker = oseo_uninitialized();
966
+ result = oseo_internal_intrinsic(
967
+ context,
968
+ OSEO_INTRINSIC_OBJECT_PROTOTYPE
969
+ );
970
+ frame.slots[0] = result.value;
971
+ if (result.status == OSEO_STATUS_NORMAL) {
972
+ result = oseo_object_create(context, frame.slots[0]);
973
+ frame.slots[0] = result.value;
974
+ }
975
+ if (result.status == OSEO_STATUS_NORMAL) {
976
+ context->realm->intrinsics[OSEO_INTRINSIC_DATA_VIEW_PROTOTYPE] =
977
+ frame.slots[0];
978
+ result = create_data_view_builtin(
979
+ context,
980
+ OSEO_DATA_VIEW_CONSTRUCTOR_CODE_ID,
981
+ "DataView",
982
+ 1u,
983
+ OSEO_FUNCTION_ORDINARY,
984
+ OSEO_FUNCTION_NAME_PREFIX_NONE
985
+ );
986
+ frame.slots[1] = result.value;
987
+ }
988
+ const OseoPropertyAttributes method = {true, false, true, false};
989
+ if (result.status == OSEO_STATUS_NORMAL) {
990
+ context->realm->intrinsics[OSEO_INTRINSIC_DATA_VIEW] = frame.slots[1];
991
+ OseoFunction *constructor = function_object(frame.slots[1]);
992
+ constructor->prototype_object = frame.slots[0];
993
+ constructor->prototype_writable = false;
994
+ result = define_data_view_property(
995
+ context,
996
+ frame.slots[0],
997
+ "constructor",
998
+ frame.slots[1],
999
+ method
1000
+ );
1001
+ }
1002
+ static const OseoIntrinsic accessor_intrinsics[] = {
1003
+ OSEO_INTRINSIC_DATA_VIEW_BUFFER,
1004
+ OSEO_INTRINSIC_DATA_VIEW_BYTE_LENGTH,
1005
+ OSEO_INTRINSIC_DATA_VIEW_BYTE_OFFSET,
1006
+ };
1007
+ static const size_t accessor_codes[] = {
1008
+ OSEO_DATA_VIEW_BUFFER_CODE_ID,
1009
+ OSEO_DATA_VIEW_BYTE_LENGTH_CODE_ID,
1010
+ OSEO_DATA_VIEW_BYTE_OFFSET_CODE_ID,
1011
+ };
1012
+ static const char *const accessor_names[] = {
1013
+ "buffer",
1014
+ "byteLength",
1015
+ "byteOffset",
1016
+ };
1017
+ for (size_t index = 0u;
1018
+ result.status == OSEO_STATUS_NORMAL && index < 3u;
1019
+ index += 1u) {
1020
+ result = create_data_view_builtin(
1021
+ context,
1022
+ accessor_codes[index],
1023
+ accessor_names[index],
1024
+ 0u,
1025
+ OSEO_FUNCTION_INTERNAL,
1026
+ OSEO_FUNCTION_NAME_PREFIX_GET
1027
+ );
1028
+ frame.slots[2] = result.value;
1029
+ if (result.status != OSEO_STATUS_NORMAL) break;
1030
+ context->realm->intrinsics[accessor_intrinsics[index]] = frame.slots[2];
1031
+ result = define_data_view_accessor(
1032
+ context,
1033
+ frame.slots[0],
1034
+ accessor_names[index],
1035
+ frame.slots[2]
1036
+ );
1037
+ }
1038
+ if (result.status == OSEO_STATUS_NORMAL) {
1039
+ result = oseo_internal_well_known_symbol(
1040
+ context,
1041
+ OSEO_WELL_KNOWN_TO_STRING_TAG
1042
+ );
1043
+ frame.slots[3] = result.value;
1044
+ }
1045
+ if (result.status == OSEO_STATUS_NORMAL) {
1046
+ result = oseo_internal_ascii_string(context, "DataView");
1047
+ frame.slots[4] = result.value;
1048
+ }
1049
+ if (result.status == OSEO_STATUS_NORMAL) {
1050
+ result = oseo_object_define(
1051
+ context,
1052
+ frame.slots[0],
1053
+ frame.slots[3],
1054
+ frame.slots[4],
1055
+ (OseoPropertyAttributes){true, false, false, false}
1056
+ );
1057
+ }
1058
+ /* The eleven get accessors and then the eleven set accessors, in
1059
+ * element order, so each intrinsic slot and code ID is its element
1060
+ * index away from the first of its group. */
1061
+ for (size_t index = 0u;
1062
+ result.status == OSEO_STATUS_NORMAL &&
1063
+ index < 2u * OSEO_DATA_VIEW_ELEMENT_COUNT;
1064
+ index += 1u) {
1065
+ bool setter = index >= OSEO_DATA_VIEW_ELEMENT_COUNT;
1066
+ size_t element =
1067
+ setter ? index - OSEO_DATA_VIEW_ELEMENT_COUNT : index;
1068
+ const char *name = setter
1069
+ ? data_view_set_names[element]
1070
+ : data_view_get_names[element];
1071
+ result = create_data_view_builtin(
1072
+ context,
1073
+ (setter ? OSEO_DATA_VIEW_SET_CODE_ID_LAST
1074
+ : OSEO_DATA_VIEW_GET_CODE_ID_LAST) - element,
1075
+ name,
1076
+ setter ? 2u : 1u,
1077
+ OSEO_FUNCTION_INTERNAL,
1078
+ OSEO_FUNCTION_NAME_PREFIX_NONE
1079
+ );
1080
+ frame.slots[2] = result.value;
1081
+ if (result.status != OSEO_STATUS_NORMAL) break;
1082
+ context->realm->intrinsics[
1083
+ (size_t)OSEO_INTRINSIC_DATA_VIEW_GET_INT8 + index
1084
+ ] = frame.slots[2];
1085
+ result = define_data_view_property(
1086
+ context,
1087
+ frame.slots[0],
1088
+ name,
1089
+ frame.slots[2],
1090
+ method
1091
+ );
1092
+ }
1093
+ if (result.status != OSEO_STATUS_NORMAL) {
1094
+ for (size_t index = OSEO_INTRINSIC_DATA_VIEW_PROTOTYPE;
1095
+ index <= OSEO_INTRINSIC_DATA_VIEW_SET_BIG_UINT64;
1096
+ index += 1u) {
1097
+ context->realm->intrinsics[index] = oseo_undefined();
1098
+ }
1099
+ oseo_roots_release(context, &frame);
1100
+ return result;
1101
+ }
1102
+ if (context->observe_specialization) {
1103
+ context->allocations = entry_allocations;
1104
+ }
1105
+ oseo_roots_release(context, &frame);
1106
+ return normal(context->realm->intrinsics[OSEO_INTRINSIC_DATA_VIEW]);
1107
+ }
1108
+
1109
+ OseoResult oseo_internal_data_view_intrinsic(OseoContext *context) {
1110
+ OseoResult built = data_view_intrinsic_build(context);
1111
+ if (built.status != OSEO_STATUS_NORMAL) return built;
1112
+ return normal(context->realm->intrinsics[OSEO_INTRINSIC_DATA_VIEW]);
1113
+ }
1114
+
1115
+ OseoResult oseo_internal_install_data_view_global(
1116
+ OseoContext *context,
1117
+ OseoValue global
1118
+ ) {
1119
+ OseoValue slots[2] = {global, oseo_undefined()};
1120
+ OseoRootFrame frame = {NULL, slots, 2u};
1121
+ oseo_roots_push(context, &frame);
1122
+ OseoResult result = oseo_internal_data_view_intrinsic(context);
1123
+ slots[1] = result.value;
1124
+ if (result.status == OSEO_STATUS_NORMAL) {
1125
+ result = define_data_view_property(
1126
+ context,
1127
+ slots[0],
1128
+ "DataView",
1129
+ slots[1],
1130
+ (OseoPropertyAttributes){true, false, true, false}
1131
+ );
1132
+ }
1133
+ oseo_roots_pop(context, &frame);
1134
+ return result.status == OSEO_STATUS_NORMAL ? normal(slots[0]) : result;
1135
+ }