@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.
- package/LICENSE +674 -0
- package/MIT-LICENSE.txt +21 -0
- package/README.md +28 -2
- package/UNICODE-LICENSE.txt +39 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +269 -0
- package/dist/index.js.map +1 -0
- package/native/oseo_runtime.h +2618 -0
- package/native/runtime_agent.c +1717 -0
- package/native/runtime_arguments.c +379 -0
- package/native/runtime_array.c +5766 -0
- package/native/runtime_array_buffer.c +1748 -0
- package/native/runtime_async_generator.c +972 -0
- package/native/runtime_atomics.c +1283 -0
- package/native/runtime_bigint.c +1387 -0
- package/native/runtime_bigint_object.c +626 -0
- package/native/runtime_binding.c +1029 -0
- package/native/runtime_boolean.c +320 -0
- package/native/runtime_clock.c +181 -0
- package/native/runtime_clock_posix.c +599 -0
- package/native/runtime_core.c +488 -0
- package/native/runtime_data_view.c +1135 -0
- package/native/runtime_date.c +1997 -0
- package/native/runtime_descriptor.c +1104 -0
- package/native/runtime_disposal.c +1667 -0
- package/native/runtime_enumeration.c +636 -0
- package/native/runtime_error.c +997 -0
- package/native/runtime_event_loop.c +653 -0
- package/native/runtime_function.c +3667 -0
- package/native/runtime_generator.c +1120 -0
- package/native/runtime_internal.h +5578 -0
- package/native/runtime_iterator.c +5379 -0
- package/native/runtime_json.c +1992 -0
- package/native/runtime_map.c +1563 -0
- package/native/runtime_math.c +918 -0
- package/native/runtime_memory.c +1365 -0
- package/native/runtime_module.c +884 -0
- package/native/runtime_number.c +2077 -0
- package/native/runtime_object.c +423 -0
- package/native/runtime_object_builtin.c +3901 -0
- package/native/runtime_primitive.c +2268 -0
- package/native/runtime_process.c +744 -0
- package/native/runtime_promise.c +3378 -0
- package/native/runtime_property.c +815 -0
- package/native/runtime_proxy.c +1557 -0
- package/native/runtime_realm.c +435 -0
- package/native/runtime_reflect.c +648 -0
- package/native/runtime_regexp.c +3519 -0
- package/native/runtime_regexp_matcher.c +3559 -0
- package/native/runtime_regexp_symbol.c +1495 -0
- package/native/runtime_set.c +1775 -0
- package/native/runtime_string.c +2886 -0
- package/native/runtime_string_match.c +1185 -0
- package/native/runtime_symbol.c +1010 -0
- package/native/runtime_typed_array.c +5137 -0
- package/native/runtime_unicode_tables.h +14670 -0
- package/native/runtime_uri.c +700 -0
- package/native/runtime_weak_collection.c +1299 -0
- package/package.json +38 -3
|
@@ -0,0 +1,1104 @@
|
|
|
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
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Property descriptors: [[GetOwnProperty]], [[DefineOwnProperty]] for
|
|
34
|
+
* data and accessor descriptors, [[Delete]], and the SameValue
|
|
35
|
+
* comparison ValidateAndApplyPropertyDescriptor performs.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
static OseoResult type_error(OseoContext *context, const char *message) {
|
|
39
|
+
return oseo_internal_throw_error(context, OSEO_ERROR_TYPE, message);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Routes a canonical numeric key of a TypedArray to the view's
|
|
44
|
+
* [[DefineOwnProperty]]. `*handled` stays false for every
|
|
45
|
+
* other key and object, which keeps the ordinary definition below.
|
|
46
|
+
*/
|
|
47
|
+
static OseoResult define_typed_array_key(
|
|
48
|
+
OseoContext *context,
|
|
49
|
+
OseoValue object_value,
|
|
50
|
+
OseoValue key,
|
|
51
|
+
const OseoConvertedDescriptor *descriptor,
|
|
52
|
+
OseoValue value,
|
|
53
|
+
bool *handled,
|
|
54
|
+
const char **refusal
|
|
55
|
+
) {
|
|
56
|
+
*handled = false;
|
|
57
|
+
if (!is_typed_array(object_value)) return normal(object_value);
|
|
58
|
+
size_t index = SIZE_MAX;
|
|
59
|
+
OseoResult result = oseo_internal_typed_array_numeric_key(
|
|
60
|
+
context,
|
|
61
|
+
key,
|
|
62
|
+
handled,
|
|
63
|
+
&index
|
|
64
|
+
);
|
|
65
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
66
|
+
if (!*handled) return normal(object_value);
|
|
67
|
+
return oseo_internal_typed_array_define_index(
|
|
68
|
+
context,
|
|
69
|
+
object_value,
|
|
70
|
+
index,
|
|
71
|
+
descriptor,
|
|
72
|
+
value,
|
|
73
|
+
refusal
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* A concrete descriptor replacing the virtual String iterator keeps the
|
|
78
|
+
* virtual property's original position before every user-created symbol.
|
|
79
|
+
* The property vector already owns creation order, so inserting the
|
|
80
|
+
* replacement at its first symbol slot lets ordinary deletion and later
|
|
81
|
+
* redefinition recover the usual append-at-creation behavior. */
|
|
82
|
+
static OseoProperty *append_property_slot(
|
|
83
|
+
OseoOrdinaryObject *object,
|
|
84
|
+
bool replaces_virtual
|
|
85
|
+
) {
|
|
86
|
+
size_t insertion = object->property_count;
|
|
87
|
+
if (replaces_virtual) {
|
|
88
|
+
for (size_t index = 0u;
|
|
89
|
+
index < object->property_count;
|
|
90
|
+
index += 1u) {
|
|
91
|
+
if (is_symbol(object->properties[index].key)) {
|
|
92
|
+
insertion = index;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (size_t index = object->property_count;
|
|
98
|
+
index > insertion;
|
|
99
|
+
index -= 1u) {
|
|
100
|
+
object->properties[index] = object->properties[index - 1u];
|
|
101
|
+
}
|
|
102
|
+
object->property_count += 1u;
|
|
103
|
+
return &object->properties[insertion];
|
|
104
|
+
}
|
|
105
|
+
OseoResult oseo_internal_legacy_materialize(
|
|
106
|
+
OseoContext *context,
|
|
107
|
+
OseoValue object_value,
|
|
108
|
+
OseoValue key
|
|
109
|
+
) {
|
|
110
|
+
uint8_t live = oseo_internal_legacy_live_key(object_value, key);
|
|
111
|
+
if (live == 0u) return normal(oseo_undefined());
|
|
112
|
+
OseoValue current = oseo_undefined();
|
|
113
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
114
|
+
(void)oseo_internal_legacy_descriptor(
|
|
115
|
+
context, object_value, key, ¤t, &attributes);
|
|
116
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
117
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 3u);
|
|
118
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
119
|
+
frame.slots[0] = object_value;
|
|
120
|
+
frame.slots[1] = key;
|
|
121
|
+
result = oseo_internal_legacy_value(context, object_value, key, current);
|
|
122
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
123
|
+
frame.slots[2] = result.value;
|
|
124
|
+
result = oseo_internal_grow_properties(context, frame.slots[0]);
|
|
125
|
+
}
|
|
126
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
127
|
+
oseo_roots_release(context, &frame);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
OseoFunction *function = function_object(frame.slots[0]);
|
|
131
|
+
OseoOrdinaryObject *object = ordinary_object(frame.slots[0]);
|
|
132
|
+
size_t target = live == OSEO_LEGACY_ARGUMENTS_LIVE
|
|
133
|
+
? function->legacy_arguments_position
|
|
134
|
+
: function->prototype_key_position;
|
|
135
|
+
size_t insertion = object->property_count;
|
|
136
|
+
size_t rank = 0u;
|
|
137
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
138
|
+
uint32_t ignored = 0u;
|
|
139
|
+
OseoValue scanned = object->properties[index].key;
|
|
140
|
+
if (is_symbol(scanned) ||
|
|
141
|
+
oseo_internal_array_index(scanned, &ignored)) continue;
|
|
142
|
+
if (rank == target) {
|
|
143
|
+
insertion = index;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
rank += 1u;
|
|
147
|
+
}
|
|
148
|
+
for (size_t index = object->property_count;
|
|
149
|
+
index > insertion;
|
|
150
|
+
index -= 1u) {
|
|
151
|
+
object->properties[index] = object->properties[index - 1u];
|
|
152
|
+
}
|
|
153
|
+
object->property_count += 1u;
|
|
154
|
+
OseoProperty *property = &object->properties[insertion];
|
|
155
|
+
property->attributes = (OseoPropertyAttributes){true, false, false, false};
|
|
156
|
+
property->key = frame.slots[1];
|
|
157
|
+
property->value = frame.slots[2];
|
|
158
|
+
property->getter = oseo_undefined();
|
|
159
|
+
property->setter = oseo_undefined();
|
|
160
|
+
oseo_internal_note_property_inserted(object, insertion);
|
|
161
|
+
/* Both live keys sit in front of `prototype`, so the new slot always
|
|
162
|
+
* moves it one place later; a live `arguments` stays in front of a
|
|
163
|
+
* moved `caller` at its unchanged rank. */
|
|
164
|
+
function->prototype_key_position += 1u;
|
|
165
|
+
function->legacy_live &= (uint8_t)~live;
|
|
166
|
+
object->dictionary = true;
|
|
167
|
+
object->shape_id = context->next_shape_id;
|
|
168
|
+
context->next_shape_id += 1u;
|
|
169
|
+
oseo_roots_release(context, &frame);
|
|
170
|
+
return normal(oseo_undefined());
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
bool oseo_internal_same_value(OseoValue left, OseoValue right) {
|
|
174
|
+
if (is_number(left) && is_number(right)) {
|
|
175
|
+
double left_number = number_value(left);
|
|
176
|
+
double right_number = number_value(right);
|
|
177
|
+
if (isnan(left_number) && isnan(right_number)) return true;
|
|
178
|
+
if (left_number == 0.0 && right_number == 0.0) {
|
|
179
|
+
return signbit(left_number) == signbit(right_number);
|
|
180
|
+
}
|
|
181
|
+
return left_number == right_number;
|
|
182
|
+
}
|
|
183
|
+
if (is_string(left) && is_string(right)) {
|
|
184
|
+
return oseo_internal_string_equal(left, right);
|
|
185
|
+
}
|
|
186
|
+
if (is_bigint(left) && is_bigint(right)) {
|
|
187
|
+
return oseo_internal_bigint_equal(left, right);
|
|
188
|
+
}
|
|
189
|
+
return left == right || same_registered_symbol(left, right);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
bool oseo_internal_same_value_zero(OseoValue left, OseoValue right) {
|
|
193
|
+
if (is_number(left) && is_number(right)) {
|
|
194
|
+
double left_number = number_value(left);
|
|
195
|
+
double right_number = number_value(right);
|
|
196
|
+
if (isnan(left_number) && isnan(right_number)) return true;
|
|
197
|
+
return left_number == right_number;
|
|
198
|
+
}
|
|
199
|
+
if (is_string(left) && is_string(right)) {
|
|
200
|
+
return oseo_internal_string_equal(left, right);
|
|
201
|
+
}
|
|
202
|
+
if (is_bigint(left) && is_bigint(right)) {
|
|
203
|
+
return oseo_internal_bigint_equal(left, right);
|
|
204
|
+
}
|
|
205
|
+
return left == right || same_registered_symbol(left, right);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
bool oseo_internal_virtual_string_iterator_descriptor(
|
|
209
|
+
OseoContext *context,
|
|
210
|
+
OseoValue object_value,
|
|
211
|
+
OseoValue key,
|
|
212
|
+
OseoPropertyAttributes *attributes
|
|
213
|
+
) {
|
|
214
|
+
if (!is_object(object_value) ||
|
|
215
|
+
object_value !=
|
|
216
|
+
context->realm->intrinsics[OSEO_INTRINSIC_STRING_PROTOTYPE] ||
|
|
217
|
+
key != context->well_known_symbols[OSEO_WELL_KNOWN_ITERATOR]) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
OseoOrdinaryObject *object = ordinary_object(object_value);
|
|
221
|
+
if (!object->virtual_string_iterator) return false;
|
|
222
|
+
*attributes = (OseoPropertyAttributes){
|
|
223
|
+
object->virtual_string_iterator_configurable,
|
|
224
|
+
object->virtual_string_iterator_enumerable,
|
|
225
|
+
object->virtual_string_iterator_writable,
|
|
226
|
+
false,
|
|
227
|
+
};
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
bool oseo_internal_own_descriptor(
|
|
232
|
+
OseoValue object_value,
|
|
233
|
+
OseoValue key,
|
|
234
|
+
OseoValue *value,
|
|
235
|
+
OseoPropertyAttributes *attributes,
|
|
236
|
+
OseoValue *getter,
|
|
237
|
+
OseoValue *setter
|
|
238
|
+
) {
|
|
239
|
+
*getter = oseo_undefined();
|
|
240
|
+
*setter = oseo_undefined();
|
|
241
|
+
/* Without the context, the legacy `caller` and `arguments` values
|
|
242
|
+
* are unknown; oseo_internal_own_property_descriptor answers them.
|
|
243
|
+
* Every context-free caller reads only presence and attributes. */
|
|
244
|
+
if (oseo_internal_legacy_live_key(object_value, key) != 0u) {
|
|
245
|
+
*value = oseo_null();
|
|
246
|
+
*attributes = (OseoPropertyAttributes){true, false, false, false};
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
if (function_has_prototype_property(object_value) &&
|
|
250
|
+
oseo_internal_string_is_ascii(key, "prototype")) {
|
|
251
|
+
*value = function_object(object_value)->prototype_object;
|
|
252
|
+
*attributes = (OseoPropertyAttributes){
|
|
253
|
+
false,
|
|
254
|
+
false,
|
|
255
|
+
function_object(object_value)->prototype_writable,
|
|
256
|
+
false,
|
|
257
|
+
};
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
if (is_array(object_value) &&
|
|
261
|
+
oseo_internal_string_is_ascii(key, "length")) {
|
|
262
|
+
OseoOrdinaryObject *array = ordinary_object(object_value);
|
|
263
|
+
*value = oseo_number(array->array_length);
|
|
264
|
+
*attributes = (OseoPropertyAttributes){
|
|
265
|
+
false,
|
|
266
|
+
false,
|
|
267
|
+
array->length_writable,
|
|
268
|
+
false,
|
|
269
|
+
};
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
OseoOrdinaryObject *object = ordinary_object(object_value);
|
|
273
|
+
size_t index = oseo_internal_own_property_index(object, key);
|
|
274
|
+
if (index == SIZE_MAX) return false;
|
|
275
|
+
OseoProperty *property = &object->properties[index];
|
|
276
|
+
*attributes = property->attributes;
|
|
277
|
+
if (property->attributes.accessor) {
|
|
278
|
+
*value = oseo_undefined();
|
|
279
|
+
*getter = property->getter;
|
|
280
|
+
*setter = property->setter;
|
|
281
|
+
} else {
|
|
282
|
+
*value = property->value;
|
|
283
|
+
}
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
bool oseo_internal_own_property_descriptor(
|
|
288
|
+
OseoContext *context,
|
|
289
|
+
OseoValue object_value,
|
|
290
|
+
OseoValue key,
|
|
291
|
+
OseoValue *value,
|
|
292
|
+
OseoPropertyAttributes *attributes,
|
|
293
|
+
OseoValue *getter,
|
|
294
|
+
OseoValue *setter
|
|
295
|
+
) {
|
|
296
|
+
if (oseo_internal_legacy_descriptor(
|
|
297
|
+
context, object_value, key, value, attributes)) {
|
|
298
|
+
*getter = oseo_undefined();
|
|
299
|
+
*setter = oseo_undefined();
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
if (oseo_internal_own_descriptor(
|
|
303
|
+
object_value,
|
|
304
|
+
key,
|
|
305
|
+
value,
|
|
306
|
+
attributes,
|
|
307
|
+
getter,
|
|
308
|
+
setter
|
|
309
|
+
)) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
*value = oseo_undefined();
|
|
313
|
+
*getter = oseo_undefined();
|
|
314
|
+
*setter = oseo_undefined();
|
|
315
|
+
return oseo_internal_virtual_string_iterator_descriptor(
|
|
316
|
+
context,
|
|
317
|
+
object_value,
|
|
318
|
+
key,
|
|
319
|
+
attributes
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
OseoResult oseo_internal_namespace_export_ready(
|
|
324
|
+
OseoContext *context,
|
|
325
|
+
OseoValue object_value,
|
|
326
|
+
OseoValue stored
|
|
327
|
+
) {
|
|
328
|
+
if (!is_object(object_value) ||
|
|
329
|
+
!ordinary_object(object_value)->module_namespace ||
|
|
330
|
+
!is_cell(stored)) {
|
|
331
|
+
return normal(oseo_undefined());
|
|
332
|
+
}
|
|
333
|
+
OseoResult read = oseo_cell_get(context, stored);
|
|
334
|
+
if (read.status != OSEO_STATUS_NORMAL) return read;
|
|
335
|
+
return normal(oseo_undefined());
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
static OseoResult define_data_property(
|
|
339
|
+
OseoContext *context,
|
|
340
|
+
OseoValue object_value,
|
|
341
|
+
OseoValue key,
|
|
342
|
+
OseoValue value,
|
|
343
|
+
OseoPropertyAttributes attributes,
|
|
344
|
+
bool has_value,
|
|
345
|
+
bool absent_writable,
|
|
346
|
+
const char **refusal
|
|
347
|
+
) {
|
|
348
|
+
*refusal = NULL;
|
|
349
|
+
OseoResult valid = oseo_internal_require_property_key(context, key);
|
|
350
|
+
if (valid.status != OSEO_STATUS_NORMAL) return valid;
|
|
351
|
+
if (!is_object(object_value)) {
|
|
352
|
+
return type_error(
|
|
353
|
+
context,
|
|
354
|
+
"Object.defineProperty requires an object."
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
const OseoConvertedDescriptor typed_descriptor = {
|
|
358
|
+
!absent_writable,
|
|
359
|
+
attributes.enumerable,
|
|
360
|
+
!absent_writable,
|
|
361
|
+
attributes.configurable,
|
|
362
|
+
!absent_writable,
|
|
363
|
+
attributes.writable,
|
|
364
|
+
has_value,
|
|
365
|
+
false,
|
|
366
|
+
false,
|
|
367
|
+
};
|
|
368
|
+
bool typed_array_key = false;
|
|
369
|
+
OseoResult typed_array_result = define_typed_array_key(
|
|
370
|
+
context,
|
|
371
|
+
object_value,
|
|
372
|
+
key,
|
|
373
|
+
&typed_descriptor,
|
|
374
|
+
value,
|
|
375
|
+
&typed_array_key,
|
|
376
|
+
refusal
|
|
377
|
+
);
|
|
378
|
+
if (typed_array_result.status != OSEO_STATUS_NORMAL || typed_array_key) {
|
|
379
|
+
return typed_array_result;
|
|
380
|
+
}
|
|
381
|
+
OseoResult legacy = oseo_internal_legacy_materialize(
|
|
382
|
+
context, object_value, key);
|
|
383
|
+
if (legacy.status != OSEO_STATUS_NORMAL) return legacy;
|
|
384
|
+
if (function_has_prototype_property(object_value) &&
|
|
385
|
+
oseo_internal_string_is_ascii(key, "prototype")) {
|
|
386
|
+
if (attributes.configurable || attributes.enumerable) {
|
|
387
|
+
*refusal =
|
|
388
|
+
"Cannot redefine the prototype property.";
|
|
389
|
+
return normal(object_value);
|
|
390
|
+
}
|
|
391
|
+
OseoFunction *function = function_object(object_value);
|
|
392
|
+
if (!function->prototype_writable &&
|
|
393
|
+
(attributes.writable ||
|
|
394
|
+
!oseo_internal_same_value(function->prototype_object, value))) {
|
|
395
|
+
*refusal =
|
|
396
|
+
"Cannot redefine the prototype property.";
|
|
397
|
+
return normal(object_value);
|
|
398
|
+
}
|
|
399
|
+
function->prototype_object = value;
|
|
400
|
+
function->prototype_writable = attributes.writable;
|
|
401
|
+
return normal(object_value);
|
|
402
|
+
}
|
|
403
|
+
OseoOrdinaryObject *object = ordinary_object(object_value);
|
|
404
|
+
OseoPropertyAttributes virtual_attributes = {false, false, false, false};
|
|
405
|
+
bool replaces_virtual =
|
|
406
|
+
oseo_internal_virtual_string_iterator_descriptor(
|
|
407
|
+
context,
|
|
408
|
+
object_value,
|
|
409
|
+
key,
|
|
410
|
+
&virtual_attributes
|
|
411
|
+
);
|
|
412
|
+
if (replaces_virtual) {
|
|
413
|
+
/* During intrinsic bootstrap the virtual property models an
|
|
414
|
+
* undefined value. The successful String initializer replaces it
|
|
415
|
+
* with the concrete iterator before user code can observe it. */
|
|
416
|
+
if (!virtual_attributes.configurable &&
|
|
417
|
+
(attributes.configurable ||
|
|
418
|
+
attributes.enumerable != virtual_attributes.enumerable ||
|
|
419
|
+
(!virtual_attributes.writable && attributes.writable) ||
|
|
420
|
+
(!virtual_attributes.writable && has_value &&
|
|
421
|
+
!oseo_internal_same_value(value, oseo_undefined())))) {
|
|
422
|
+
*refusal =
|
|
423
|
+
"Cannot redefine a non-configurable property.";
|
|
424
|
+
return normal(object_value);
|
|
425
|
+
}
|
|
426
|
+
/* A non-configurable, non-writable bootstrap property cannot change:
|
|
427
|
+
* validation rejected every descriptor that would alter it, and a
|
|
428
|
+
* SameValue undefined leaves the placeholder representation intact. */
|
|
429
|
+
bool read_only_no_op = !virtual_attributes.configurable &&
|
|
430
|
+
!virtual_attributes.writable;
|
|
431
|
+
if (!has_value || read_only_no_op) {
|
|
432
|
+
object->virtual_string_iterator_configurable =
|
|
433
|
+
attributes.configurable;
|
|
434
|
+
object->virtual_string_iterator_enumerable =
|
|
435
|
+
attributes.enumerable;
|
|
436
|
+
object->virtual_string_iterator_writable = attributes.writable;
|
|
437
|
+
object->dictionary = true;
|
|
438
|
+
object->shape_id = context->next_shape_id;
|
|
439
|
+
context->next_shape_id += 1u;
|
|
440
|
+
return normal(object_value);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (is_array(object_value) &&
|
|
444
|
+
oseo_internal_string_is_ascii(key, "length")) {
|
|
445
|
+
uint32_t requested = object->array_length;
|
|
446
|
+
if (has_value) {
|
|
447
|
+
OseoResult converted = oseo_internal_to_array_length(
|
|
448
|
+
context,
|
|
449
|
+
value,
|
|
450
|
+
&requested
|
|
451
|
+
);
|
|
452
|
+
if (converted.status != OSEO_STATUS_NORMAL) return converted;
|
|
453
|
+
}
|
|
454
|
+
if (absent_writable) {
|
|
455
|
+
/* A descriptor without a [[Writable]] field keeps the
|
|
456
|
+
* property's current one, and ToArrayLength above is the
|
|
457
|
+
* one step of a definition that runs user code, so that
|
|
458
|
+
* field is read here rather than by the caller. Array
|
|
459
|
+
* `length` is always non-configurable and non-enumerable,
|
|
460
|
+
* so no other field can have gone stale. */
|
|
461
|
+
attributes.writable = object->length_writable;
|
|
462
|
+
}
|
|
463
|
+
if (attributes.configurable || attributes.enumerable) {
|
|
464
|
+
*refusal =
|
|
465
|
+
"Cannot redefine the array length property.";
|
|
466
|
+
return normal(object_value);
|
|
467
|
+
}
|
|
468
|
+
if (!object->length_writable && attributes.writable) {
|
|
469
|
+
*refusal =
|
|
470
|
+
"Cannot redefine the array length property.";
|
|
471
|
+
return normal(object_value);
|
|
472
|
+
}
|
|
473
|
+
if (!has_value) {
|
|
474
|
+
object->length_writable = attributes.writable;
|
|
475
|
+
return normal(object_value);
|
|
476
|
+
}
|
|
477
|
+
/* ArraySetLength runs with the already converted length, so it
|
|
478
|
+
* reaches no user code and cannot report a conversion error.
|
|
479
|
+
* Its non-strict form leaves the array length above the
|
|
480
|
+
* requested one exactly when the specification returns false,
|
|
481
|
+
* which is the refusal this reports and the partial truncation
|
|
482
|
+
* it keeps. */
|
|
483
|
+
bool valid_length = false;
|
|
484
|
+
OseoResult changed = oseo_internal_set_array_length(
|
|
485
|
+
context,
|
|
486
|
+
object,
|
|
487
|
+
oseo_number(requested),
|
|
488
|
+
false,
|
|
489
|
+
true,
|
|
490
|
+
&valid_length
|
|
491
|
+
);
|
|
492
|
+
if (changed.status != OSEO_STATUS_NORMAL) return changed;
|
|
493
|
+
object = ordinary_object(object_value);
|
|
494
|
+
if (object->array_length != requested) {
|
|
495
|
+
const char *cause = object->length_writable
|
|
496
|
+
? "Cannot truncate past a non-configurable element."
|
|
497
|
+
: "Cannot redefine the array length property.";
|
|
498
|
+
if (valid_length && !attributes.writable) {
|
|
499
|
+
object->length_writable = false;
|
|
500
|
+
}
|
|
501
|
+
*refusal = cause;
|
|
502
|
+
return normal(object_value);
|
|
503
|
+
}
|
|
504
|
+
object->length_writable = attributes.writable;
|
|
505
|
+
return normal(object_value);
|
|
506
|
+
}
|
|
507
|
+
uint32_t defined_index = 0u;
|
|
508
|
+
bool extends_array = is_array(object_value) &&
|
|
509
|
+
oseo_internal_array_index(key, &defined_index) &&
|
|
510
|
+
defined_index >= object->array_length;
|
|
511
|
+
if (extends_array && !object->length_writable) {
|
|
512
|
+
*refusal =
|
|
513
|
+
"Cannot extend an array with a read-only length.";
|
|
514
|
+
return normal(object_value);
|
|
515
|
+
}
|
|
516
|
+
size_t index = oseo_internal_own_property_index(object, key);
|
|
517
|
+
if (object->module_namespace) {
|
|
518
|
+
if (index == SIZE_MAX) {
|
|
519
|
+
*refusal =
|
|
520
|
+
"Cannot define a module namespace property.";
|
|
521
|
+
return normal(object_value);
|
|
522
|
+
}
|
|
523
|
+
OseoProperty *property = &object->properties[index];
|
|
524
|
+
OseoValue current_value = property->value;
|
|
525
|
+
if (oseo_internal_cell_backed_property(
|
|
526
|
+
object_value,
|
|
527
|
+
current_value
|
|
528
|
+
)) {
|
|
529
|
+
OseoResult current = oseo_cell_get(context, current_value);
|
|
530
|
+
if (current.status != OSEO_STATUS_NORMAL) return current;
|
|
531
|
+
current_value = current.value;
|
|
532
|
+
}
|
|
533
|
+
if (attributes.accessor || attributes.configurable ||
|
|
534
|
+
attributes.enumerable != property->attributes.enumerable ||
|
|
535
|
+
attributes.writable != property->attributes.writable ||
|
|
536
|
+
!oseo_internal_same_value(current_value, value)) {
|
|
537
|
+
*refusal =
|
|
538
|
+
"Cannot define a module namespace property.";
|
|
539
|
+
return normal(object_value);
|
|
540
|
+
}
|
|
541
|
+
return normal(object_value);
|
|
542
|
+
}
|
|
543
|
+
if (index != SIZE_MAX) {
|
|
544
|
+
OseoProperty *property = &object->properties[index];
|
|
545
|
+
/* ValidateAndApplyPropertyDescriptor compares the property's
|
|
546
|
+
* current value, which a cell-backed property keeps in its
|
|
547
|
+
* binding cell. Reading it allocates nothing on the normal path,
|
|
548
|
+
* so the property pointer stays valid. */
|
|
549
|
+
bool cell_backed = oseo_internal_cell_backed_property(
|
|
550
|
+
object_value, property->value);
|
|
551
|
+
OseoValue current_value = property->value;
|
|
552
|
+
if (cell_backed) {
|
|
553
|
+
OseoResult read = oseo_cell_get(context, property->value);
|
|
554
|
+
if (read.status != OSEO_STATUS_NORMAL) return read;
|
|
555
|
+
current_value = read.value;
|
|
556
|
+
}
|
|
557
|
+
if (!property->attributes.configurable &&
|
|
558
|
+
(property->attributes.accessor ||
|
|
559
|
+
attributes.configurable ||
|
|
560
|
+
attributes.enumerable != property->attributes.enumerable ||
|
|
561
|
+
(!property->attributes.writable && attributes.writable) ||
|
|
562
|
+
(!property->attributes.writable &&
|
|
563
|
+
!oseo_internal_same_value(current_value, value)))) {
|
|
564
|
+
*refusal =
|
|
565
|
+
"Cannot redefine a non-configurable property.";
|
|
566
|
+
return normal(object_value);
|
|
567
|
+
}
|
|
568
|
+
if (cell_backed) {
|
|
569
|
+
/* The binding stays the one storage location the property
|
|
570
|
+
* views, so the accepted redefinition writes through the
|
|
571
|
+
* cell. A global or namespace binding also records the new
|
|
572
|
+
* [[Writable]] on the cell, so a later binding assignment
|
|
573
|
+
* fails exactly where a property assignment would. */
|
|
574
|
+
OseoValue cell = property->value;
|
|
575
|
+
OseoResult written = oseo_cell_set(context, cell, value);
|
|
576
|
+
if (written.status != OSEO_STATUS_NORMAL) return written;
|
|
577
|
+
property->attributes = attributes;
|
|
578
|
+
if (object->mapped_arguments) {
|
|
579
|
+
/* CreateMappedArgumentsObject's [[DefineOwnProperty]]
|
|
580
|
+
* (10.4.4.2) severs the alias exactly when the accepted
|
|
581
|
+
* descriptor is an explicit non-writable data
|
|
582
|
+
* descriptor: this property stops forwarding to the
|
|
583
|
+
* cell and keeps the value just written as its own
|
|
584
|
+
* plain snapshot, while the parameter itself keeps its
|
|
585
|
+
* own cell and stays an ordinary mutable binding. */
|
|
586
|
+
if (!attributes.writable) property->value = value;
|
|
587
|
+
} else {
|
|
588
|
+
cell_object(cell)->writable = attributes.writable;
|
|
589
|
+
}
|
|
590
|
+
object->dictionary = true;
|
|
591
|
+
object->shape_id = context->next_shape_id;
|
|
592
|
+
context->next_shape_id += 1u;
|
|
593
|
+
return normal(object_value);
|
|
594
|
+
}
|
|
595
|
+
property->attributes = attributes;
|
|
596
|
+
property->value = value;
|
|
597
|
+
property->getter = oseo_undefined();
|
|
598
|
+
property->setter = oseo_undefined();
|
|
599
|
+
object->dictionary = true;
|
|
600
|
+
object->shape_id = context->next_shape_id;
|
|
601
|
+
context->next_shape_id += 1u;
|
|
602
|
+
if (extends_array) object->array_length = defined_index + 1u;
|
|
603
|
+
return normal(object_value);
|
|
604
|
+
}
|
|
605
|
+
if (!object->extensible && !replaces_virtual) {
|
|
606
|
+
*refusal =
|
|
607
|
+
"Cannot define a property on a non-extensible object.";
|
|
608
|
+
return normal(object_value);
|
|
609
|
+
}
|
|
610
|
+
/* A stored key is this realm's own representative of a registered
|
|
611
|
+
* symbol, so the property vector never holds a value another realm
|
|
612
|
+
* owns. The caller already roots `key`, and the representative is
|
|
613
|
+
* rooted by `registered_symbols`. */
|
|
614
|
+
OseoResult local_key = oseo_internal_local_symbol(context, key);
|
|
615
|
+
if (local_key.status != OSEO_STATUS_NORMAL) return local_key;
|
|
616
|
+
key = local_key.value;
|
|
617
|
+
OseoResult grown = oseo_internal_grow_properties(context, object_value);
|
|
618
|
+
if (grown.status != OSEO_STATUS_NORMAL) return grown;
|
|
619
|
+
object = ordinary_object(object_value);
|
|
620
|
+
if (replaces_virtual) object->virtual_string_iterator = false;
|
|
621
|
+
OseoProperty *property = append_property_slot(object, replaces_virtual);
|
|
622
|
+
property->attributes = attributes;
|
|
623
|
+
property->key = key;
|
|
624
|
+
property->value = value;
|
|
625
|
+
property->getter = oseo_undefined();
|
|
626
|
+
property->setter = oseo_undefined();
|
|
627
|
+
oseo_internal_note_property_inserted(
|
|
628
|
+
object, (size_t)(property - object->properties));
|
|
629
|
+
object->shape_id = context->next_shape_id;
|
|
630
|
+
context->next_shape_id += 1u;
|
|
631
|
+
if (extends_array) object->array_length = defined_index + 1u;
|
|
632
|
+
return normal(object_value);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
OseoResult oseo_internal_append_own_property(
|
|
636
|
+
OseoContext *context,
|
|
637
|
+
OseoValue object_value,
|
|
638
|
+
OseoValue key,
|
|
639
|
+
OseoValue value,
|
|
640
|
+
OseoPropertyAttributes attributes
|
|
641
|
+
) {
|
|
642
|
+
/* The growth step is a safepoint, so key and value must already be
|
|
643
|
+
* rooted by the caller, exactly as they must be for a definition
|
|
644
|
+
* that reaches the same step through define_data_property. A stored
|
|
645
|
+
* key is this realm's own representative of a registered symbol, so
|
|
646
|
+
* the property vector never holds a value another realm owns; the
|
|
647
|
+
* representative itself is rooted by `registered_symbols`. */
|
|
648
|
+
OseoResult local_key = oseo_internal_local_symbol(context, key);
|
|
649
|
+
if (local_key.status != OSEO_STATUS_NORMAL) return local_key;
|
|
650
|
+
key = local_key.value;
|
|
651
|
+
OseoResult grown = oseo_internal_grow_properties(context, object_value);
|
|
652
|
+
if (grown.status != OSEO_STATUS_NORMAL) return grown;
|
|
653
|
+
OseoOrdinaryObject *object = ordinary_object(object_value);
|
|
654
|
+
OseoProperty *property = &object->properties[object->property_count];
|
|
655
|
+
property->attributes = attributes;
|
|
656
|
+
property->key = key;
|
|
657
|
+
property->value = value;
|
|
658
|
+
property->getter = oseo_undefined();
|
|
659
|
+
property->setter = oseo_undefined();
|
|
660
|
+
object->property_count += 1u;
|
|
661
|
+
oseo_internal_note_property_inserted(object, object->property_count - 1u);
|
|
662
|
+
object->shape_id = context->next_shape_id;
|
|
663
|
+
context->next_shape_id += 1u;
|
|
664
|
+
return normal(object_value);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
OseoResult oseo_object_define(
|
|
668
|
+
OseoContext *context,
|
|
669
|
+
OseoValue object_value,
|
|
670
|
+
OseoValue key,
|
|
671
|
+
OseoValue value,
|
|
672
|
+
OseoPropertyAttributes attributes
|
|
673
|
+
) {
|
|
674
|
+
return oseo_internal_object_define_data(
|
|
675
|
+
context,
|
|
676
|
+
object_value,
|
|
677
|
+
key,
|
|
678
|
+
value,
|
|
679
|
+
attributes,
|
|
680
|
+
true
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
OseoResult oseo_internal_object_define_data(
|
|
685
|
+
OseoContext *context,
|
|
686
|
+
OseoValue object_value,
|
|
687
|
+
OseoValue key,
|
|
688
|
+
OseoValue value,
|
|
689
|
+
OseoPropertyAttributes attributes,
|
|
690
|
+
bool has_value
|
|
691
|
+
) {
|
|
692
|
+
const char *refusal = NULL;
|
|
693
|
+
OseoResult result = oseo_internal_define_data_reported(
|
|
694
|
+
context,
|
|
695
|
+
object_value,
|
|
696
|
+
key,
|
|
697
|
+
value,
|
|
698
|
+
attributes,
|
|
699
|
+
has_value,
|
|
700
|
+
false,
|
|
701
|
+
&refusal
|
|
702
|
+
);
|
|
703
|
+
if (result.status != OSEO_STATUS_NORMAL || refusal == NULL) return result;
|
|
704
|
+
return type_error(context, refusal);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
OseoResult oseo_internal_define_data_reported(
|
|
708
|
+
OseoContext *context,
|
|
709
|
+
OseoValue object_value,
|
|
710
|
+
OseoValue key,
|
|
711
|
+
OseoValue value,
|
|
712
|
+
OseoPropertyAttributes attributes,
|
|
713
|
+
bool has_value,
|
|
714
|
+
bool absent_writable,
|
|
715
|
+
const char **refusal
|
|
716
|
+
) {
|
|
717
|
+
if (is_proxy(object_value)) {
|
|
718
|
+
OseoConvertedDescriptor descriptor = {
|
|
719
|
+
!absent_writable,
|
|
720
|
+
attributes.enumerable,
|
|
721
|
+
!absent_writable,
|
|
722
|
+
attributes.configurable,
|
|
723
|
+
!absent_writable,
|
|
724
|
+
attributes.writable,
|
|
725
|
+
has_value,
|
|
726
|
+
false,
|
|
727
|
+
false,
|
|
728
|
+
};
|
|
729
|
+
return oseo_internal_proxy_define_own_property(
|
|
730
|
+
context,
|
|
731
|
+
object_value,
|
|
732
|
+
key,
|
|
733
|
+
&descriptor,
|
|
734
|
+
value,
|
|
735
|
+
oseo_undefined(),
|
|
736
|
+
oseo_undefined(),
|
|
737
|
+
refusal
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
return define_data_property(
|
|
741
|
+
context,
|
|
742
|
+
object_value,
|
|
743
|
+
key,
|
|
744
|
+
value,
|
|
745
|
+
attributes,
|
|
746
|
+
has_value,
|
|
747
|
+
absent_writable,
|
|
748
|
+
refusal
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
static OseoResult define_accessor_property(
|
|
753
|
+
OseoContext *context,
|
|
754
|
+
OseoValue object_value,
|
|
755
|
+
OseoValue key,
|
|
756
|
+
OseoValue getter,
|
|
757
|
+
OseoValue setter,
|
|
758
|
+
bool has_getter,
|
|
759
|
+
bool has_setter,
|
|
760
|
+
OseoPropertyAttributes attributes,
|
|
761
|
+
const char **refusal
|
|
762
|
+
) {
|
|
763
|
+
*refusal = NULL;
|
|
764
|
+
OseoResult valid = oseo_internal_require_property_key(context, key);
|
|
765
|
+
if (valid.status != OSEO_STATUS_NORMAL) return valid;
|
|
766
|
+
if (!is_object(object_value)) {
|
|
767
|
+
return type_error(
|
|
768
|
+
context,
|
|
769
|
+
"Cannot define an accessor property on a non-object."
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
const OseoConvertedDescriptor typed_descriptor = {
|
|
773
|
+
true,
|
|
774
|
+
attributes.enumerable,
|
|
775
|
+
true,
|
|
776
|
+
attributes.configurable,
|
|
777
|
+
false,
|
|
778
|
+
false,
|
|
779
|
+
false,
|
|
780
|
+
has_getter,
|
|
781
|
+
has_setter,
|
|
782
|
+
};
|
|
783
|
+
bool typed_array_key = false;
|
|
784
|
+
OseoResult typed_array_result = define_typed_array_key(
|
|
785
|
+
context,
|
|
786
|
+
object_value,
|
|
787
|
+
key,
|
|
788
|
+
&typed_descriptor,
|
|
789
|
+
oseo_undefined(),
|
|
790
|
+
&typed_array_key,
|
|
791
|
+
refusal
|
|
792
|
+
);
|
|
793
|
+
if (typed_array_result.status != OSEO_STATUS_NORMAL || typed_array_key) {
|
|
794
|
+
return typed_array_result;
|
|
795
|
+
}
|
|
796
|
+
if (ordinary_object(object_value)->module_namespace) {
|
|
797
|
+
*refusal =
|
|
798
|
+
"Cannot define a module namespace property.";
|
|
799
|
+
return normal(object_value);
|
|
800
|
+
}
|
|
801
|
+
if (function_has_prototype_property(object_value) &&
|
|
802
|
+
oseo_internal_string_is_ascii(key, "prototype")) {
|
|
803
|
+
*refusal =
|
|
804
|
+
"Cannot redefine the prototype property.";
|
|
805
|
+
return normal(object_value);
|
|
806
|
+
}
|
|
807
|
+
OseoResult legacy = oseo_internal_legacy_materialize(
|
|
808
|
+
context, object_value, key);
|
|
809
|
+
if (legacy.status != OSEO_STATUS_NORMAL) return legacy;
|
|
810
|
+
OseoOrdinaryObject *object = ordinary_object(object_value);
|
|
811
|
+
OseoPropertyAttributes virtual_attributes = {false, false, false, false};
|
|
812
|
+
bool replaces_virtual =
|
|
813
|
+
oseo_internal_virtual_string_iterator_descriptor(
|
|
814
|
+
context,
|
|
815
|
+
object_value,
|
|
816
|
+
key,
|
|
817
|
+
&virtual_attributes
|
|
818
|
+
);
|
|
819
|
+
if (replaces_virtual) {
|
|
820
|
+
if (!virtual_attributes.configurable) {
|
|
821
|
+
*refusal =
|
|
822
|
+
"Cannot redefine a non-configurable property.";
|
|
823
|
+
return normal(object_value);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if (is_array(object_value) &&
|
|
827
|
+
oseo_internal_string_is_ascii(key, "length")) {
|
|
828
|
+
*refusal =
|
|
829
|
+
"Cannot redefine the array length property.";
|
|
830
|
+
return normal(object_value);
|
|
831
|
+
}
|
|
832
|
+
uint32_t defined_index = 0u;
|
|
833
|
+
bool extends_array = is_array(object_value) &&
|
|
834
|
+
oseo_internal_array_index(key, &defined_index) &&
|
|
835
|
+
defined_index >= object->array_length;
|
|
836
|
+
if (extends_array && !object->length_writable) {
|
|
837
|
+
*refusal =
|
|
838
|
+
"Cannot extend an array with a read-only length.";
|
|
839
|
+
return normal(object_value);
|
|
840
|
+
}
|
|
841
|
+
size_t index = oseo_internal_own_property_index(object, key);
|
|
842
|
+
OseoValue new_getter = has_getter ? getter : oseo_undefined();
|
|
843
|
+
OseoValue new_setter = has_setter ? setter : oseo_undefined();
|
|
844
|
+
if (index != SIZE_MAX) {
|
|
845
|
+
OseoProperty *property = &object->properties[index];
|
|
846
|
+
OseoValue existing_getter = property->attributes.accessor
|
|
847
|
+
? property->getter : oseo_undefined();
|
|
848
|
+
OseoValue existing_setter = property->attributes.accessor
|
|
849
|
+
? property->setter : oseo_undefined();
|
|
850
|
+
if (!has_getter) new_getter = existing_getter;
|
|
851
|
+
if (!has_setter) new_setter = existing_setter;
|
|
852
|
+
if (!property->attributes.configurable &&
|
|
853
|
+
(!property->attributes.accessor ||
|
|
854
|
+
attributes.configurable ||
|
|
855
|
+
attributes.enumerable != property->attributes.enumerable ||
|
|
856
|
+
(has_getter &&
|
|
857
|
+
!oseo_internal_same_value(existing_getter, new_getter)) ||
|
|
858
|
+
(has_setter &&
|
|
859
|
+
!oseo_internal_same_value(existing_setter, new_setter)))) {
|
|
860
|
+
*refusal =
|
|
861
|
+
"Cannot redefine a non-configurable property.";
|
|
862
|
+
return normal(object_value);
|
|
863
|
+
}
|
|
864
|
+
property->attributes = attributes;
|
|
865
|
+
property->value = oseo_undefined();
|
|
866
|
+
property->getter = new_getter;
|
|
867
|
+
property->setter = new_setter;
|
|
868
|
+
object->dictionary = true;
|
|
869
|
+
object->shape_id = context->next_shape_id;
|
|
870
|
+
context->next_shape_id += 1u;
|
|
871
|
+
if (extends_array) object->array_length = defined_index + 1u;
|
|
872
|
+
return normal(object_value);
|
|
873
|
+
}
|
|
874
|
+
if (!object->extensible && !replaces_virtual) {
|
|
875
|
+
*refusal =
|
|
876
|
+
"Cannot define a property on a non-extensible object.";
|
|
877
|
+
return normal(object_value);
|
|
878
|
+
}
|
|
879
|
+
/* A stored key is this realm's own representative of a registered
|
|
880
|
+
* symbol, so the property vector never holds a value another realm
|
|
881
|
+
* owns. The caller already roots `key`, and the representative is
|
|
882
|
+
* rooted by `registered_symbols`. */
|
|
883
|
+
OseoResult local_key = oseo_internal_local_symbol(context, key);
|
|
884
|
+
if (local_key.status != OSEO_STATUS_NORMAL) return local_key;
|
|
885
|
+
key = local_key.value;
|
|
886
|
+
OseoResult grown = oseo_internal_grow_properties(context, object_value);
|
|
887
|
+
if (grown.status != OSEO_STATUS_NORMAL) return grown;
|
|
888
|
+
object = ordinary_object(object_value);
|
|
889
|
+
if (replaces_virtual) object->virtual_string_iterator = false;
|
|
890
|
+
OseoProperty *property = append_property_slot(object, replaces_virtual);
|
|
891
|
+
property->attributes = attributes;
|
|
892
|
+
property->key = key;
|
|
893
|
+
property->value = oseo_undefined();
|
|
894
|
+
property->getter = new_getter;
|
|
895
|
+
property->setter = new_setter;
|
|
896
|
+
oseo_internal_note_property_inserted(
|
|
897
|
+
object, (size_t)(property - object->properties));
|
|
898
|
+
object->shape_id = context->next_shape_id;
|
|
899
|
+
context->next_shape_id += 1u;
|
|
900
|
+
if (extends_array) object->array_length = defined_index + 1u;
|
|
901
|
+
return normal(object_value);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
OseoResult oseo_object_define_accessor(
|
|
905
|
+
OseoContext *context,
|
|
906
|
+
OseoValue object_value,
|
|
907
|
+
OseoValue key,
|
|
908
|
+
OseoValue getter,
|
|
909
|
+
OseoValue setter,
|
|
910
|
+
bool has_getter,
|
|
911
|
+
bool has_setter,
|
|
912
|
+
OseoPropertyAttributes attributes
|
|
913
|
+
) {
|
|
914
|
+
const char *refusal = NULL;
|
|
915
|
+
OseoResult result = oseo_internal_define_accessor_reported(
|
|
916
|
+
context,
|
|
917
|
+
object_value,
|
|
918
|
+
key,
|
|
919
|
+
getter,
|
|
920
|
+
setter,
|
|
921
|
+
has_getter,
|
|
922
|
+
has_setter,
|
|
923
|
+
attributes,
|
|
924
|
+
&refusal
|
|
925
|
+
);
|
|
926
|
+
if (result.status != OSEO_STATUS_NORMAL || refusal == NULL) return result;
|
|
927
|
+
return type_error(context, refusal);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
OseoResult oseo_internal_define_accessor_reported(
|
|
931
|
+
OseoContext *context,
|
|
932
|
+
OseoValue object_value,
|
|
933
|
+
OseoValue key,
|
|
934
|
+
OseoValue getter,
|
|
935
|
+
OseoValue setter,
|
|
936
|
+
bool has_getter,
|
|
937
|
+
bool has_setter,
|
|
938
|
+
OseoPropertyAttributes attributes,
|
|
939
|
+
const char **refusal
|
|
940
|
+
) {
|
|
941
|
+
if (is_proxy(object_value)) {
|
|
942
|
+
OseoConvertedDescriptor descriptor = {
|
|
943
|
+
true,
|
|
944
|
+
attributes.enumerable,
|
|
945
|
+
true,
|
|
946
|
+
attributes.configurable,
|
|
947
|
+
false,
|
|
948
|
+
false,
|
|
949
|
+
false,
|
|
950
|
+
has_getter,
|
|
951
|
+
has_setter,
|
|
952
|
+
};
|
|
953
|
+
return oseo_internal_proxy_define_own_property(
|
|
954
|
+
context,
|
|
955
|
+
object_value,
|
|
956
|
+
key,
|
|
957
|
+
&descriptor,
|
|
958
|
+
oseo_undefined(),
|
|
959
|
+
getter,
|
|
960
|
+
setter,
|
|
961
|
+
refusal
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
return define_accessor_property(
|
|
965
|
+
context,
|
|
966
|
+
object_value,
|
|
967
|
+
key,
|
|
968
|
+
getter,
|
|
969
|
+
setter,
|
|
970
|
+
has_getter,
|
|
971
|
+
has_setter,
|
|
972
|
+
attributes,
|
|
973
|
+
refusal
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
OseoResult oseo_object_delete(
|
|
978
|
+
OseoContext *context,
|
|
979
|
+
OseoValue object_value,
|
|
980
|
+
OseoValue key,
|
|
981
|
+
bool strict
|
|
982
|
+
) {
|
|
983
|
+
OseoResult valid = oseo_internal_require_property_key(context, key);
|
|
984
|
+
if (valid.status != OSEO_STATUS_NORMAL) return valid;
|
|
985
|
+
if (!is_object(object_value)) {
|
|
986
|
+
if (is_nullish(object_value)) {
|
|
987
|
+
return type_error(
|
|
988
|
+
context,
|
|
989
|
+
"Cannot delete properties of a nullish value."
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
if (oseo_internal_string_own_property(object_value, key, NULL)) {
|
|
993
|
+
return strict
|
|
994
|
+
? type_error(context, "Cannot delete a string index property.")
|
|
995
|
+
: normal(oseo_boolean(false));
|
|
996
|
+
}
|
|
997
|
+
return normal(oseo_boolean(true));
|
|
998
|
+
}
|
|
999
|
+
if (is_proxy(object_value)) {
|
|
1000
|
+
return oseo_internal_proxy_delete(
|
|
1001
|
+
context, object_value, key, strict);
|
|
1002
|
+
}
|
|
1003
|
+
if (is_typed_array(object_value)) {
|
|
1004
|
+
/* A view's [[Delete]] refuses exactly the valid
|
|
1005
|
+
* indices and succeeds for every other numeric key. */
|
|
1006
|
+
bool numeric = false;
|
|
1007
|
+
size_t typed_index = SIZE_MAX;
|
|
1008
|
+
OseoResult classified = oseo_internal_typed_array_numeric_key(
|
|
1009
|
+
context,
|
|
1010
|
+
key,
|
|
1011
|
+
&numeric,
|
|
1012
|
+
&typed_index
|
|
1013
|
+
);
|
|
1014
|
+
if (classified.status != OSEO_STATUS_NORMAL) return classified;
|
|
1015
|
+
if (numeric &&
|
|
1016
|
+
oseo_internal_typed_array_has_index(object_value, typed_index)) {
|
|
1017
|
+
return strict
|
|
1018
|
+
? type_error(context, "Cannot delete a TypedArray element.")
|
|
1019
|
+
: normal(oseo_boolean(false));
|
|
1020
|
+
}
|
|
1021
|
+
if (numeric) return normal(oseo_boolean(true));
|
|
1022
|
+
}
|
|
1023
|
+
if (function_has_prototype_property(object_value) &&
|
|
1024
|
+
oseo_internal_string_is_ascii(key, "prototype")) {
|
|
1025
|
+
return strict
|
|
1026
|
+
? type_error(context, "Cannot delete the prototype property.")
|
|
1027
|
+
: normal(oseo_boolean(false));
|
|
1028
|
+
}
|
|
1029
|
+
uint8_t legacy_live = oseo_internal_legacy_live_key(object_value, key);
|
|
1030
|
+
if (legacy_live != 0u) {
|
|
1031
|
+
/* A live `arguments` or `caller` is configurable (ADR 0034). */
|
|
1032
|
+
function_object(object_value)->legacy_live &=
|
|
1033
|
+
(uint8_t)~legacy_live;
|
|
1034
|
+
ordinary_object(object_value)->dictionary = true;
|
|
1035
|
+
ordinary_object(object_value)->shape_id = context->next_shape_id;
|
|
1036
|
+
context->next_shape_id += 1u;
|
|
1037
|
+
return normal(oseo_boolean(true));
|
|
1038
|
+
}
|
|
1039
|
+
if (is_array(object_value) &&
|
|
1040
|
+
oseo_internal_string_is_ascii(key, "length")) {
|
|
1041
|
+
return strict
|
|
1042
|
+
? type_error(context, "Cannot delete the array length property.")
|
|
1043
|
+
: normal(oseo_boolean(false));
|
|
1044
|
+
}
|
|
1045
|
+
OseoOrdinaryObject *object = ordinary_object(object_value);
|
|
1046
|
+
bool string_iterator =
|
|
1047
|
+
object_value ==
|
|
1048
|
+
context->realm->intrinsics[OSEO_INTRINSIC_STRING_PROTOTYPE] &&
|
|
1049
|
+
key == context->well_known_symbols[OSEO_WELL_KNOWN_ITERATOR];
|
|
1050
|
+
size_t index = oseo_internal_own_property_index(object, key);
|
|
1051
|
+
if (index == SIZE_MAX) {
|
|
1052
|
+
if (string_iterator && object->virtual_string_iterator) {
|
|
1053
|
+
if (!object->virtual_string_iterator_configurable) {
|
|
1054
|
+
return strict
|
|
1055
|
+
? type_error(
|
|
1056
|
+
context,
|
|
1057
|
+
"Cannot delete a non-configurable property."
|
|
1058
|
+
)
|
|
1059
|
+
: normal(oseo_boolean(false));
|
|
1060
|
+
}
|
|
1061
|
+
object->virtual_string_iterator = false;
|
|
1062
|
+
object->dictionary = true;
|
|
1063
|
+
object->shape_id = context->next_shape_id;
|
|
1064
|
+
context->next_shape_id += 1u;
|
|
1065
|
+
}
|
|
1066
|
+
return normal(oseo_boolean(true));
|
|
1067
|
+
}
|
|
1068
|
+
if (!object->properties[index].attributes.configurable) {
|
|
1069
|
+
return strict
|
|
1070
|
+
? type_error(context, "Cannot delete a non-configurable property.")
|
|
1071
|
+
: normal(oseo_boolean(false));
|
|
1072
|
+
}
|
|
1073
|
+
/* Removing one of the properties a function was created with moves
|
|
1074
|
+
* the synthetic `prototype` one place earlier in own-key order, and
|
|
1075
|
+
* removal alone can tell the original from a property later
|
|
1076
|
+
* recreated under the same name: only an original still sits inside
|
|
1077
|
+
* the leading run the position counts. */
|
|
1078
|
+
if (function_has_prototype_property(object_value)) {
|
|
1079
|
+
OseoFunction *function = function_object(object_value);
|
|
1080
|
+
size_t rank = 0u;
|
|
1081
|
+
for (size_t scan = 0u; scan < index; scan += 1u) {
|
|
1082
|
+
uint32_t ignored = 0u;
|
|
1083
|
+
OseoValue scanned = object->properties[scan].key;
|
|
1084
|
+
if (is_symbol(scanned) ||
|
|
1085
|
+
oseo_internal_array_index(scanned, &ignored)) continue;
|
|
1086
|
+
rank += 1u;
|
|
1087
|
+
}
|
|
1088
|
+
uint32_t ignored = 0u;
|
|
1089
|
+
if (!is_symbol(key) && !oseo_internal_array_index(key, &ignored) &&
|
|
1090
|
+
rank < function->prototype_key_position) {
|
|
1091
|
+
function->prototype_key_position -= 1u;
|
|
1092
|
+
}
|
|
1093
|
+
if (!is_symbol(key) && !oseo_internal_array_index(key, &ignored) &&
|
|
1094
|
+
rank < function->legacy_arguments_position) {
|
|
1095
|
+
function->legacy_arguments_position -= 1u;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
(void)oseo_internal_remove_property(object, index);
|
|
1099
|
+
if (string_iterator) object->virtual_string_iterator = false;
|
|
1100
|
+
object->dictionary = true;
|
|
1101
|
+
object->shape_id = context->next_shape_id;
|
|
1102
|
+
context->next_shape_id += 1u;
|
|
1103
|
+
return normal(oseo_boolean(true));
|
|
1104
|
+
}
|