@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,3901 @@
|
|
|
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 <stdio.h>
|
|
31
|
+
#include <stdlib.h>
|
|
32
|
+
#include <string.h>
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* The `Object` built-ins, the `Object.prototype` methods, and the own-key
|
|
36
|
+
* operations they share with object rest and spread: ToPropertyDescriptor,
|
|
37
|
+
* FromPropertyDescriptor, CopyDataProperties, own-key ordering, and the
|
|
38
|
+
* `Object.create`, `Object.defineProperty`, `Object.defineProperties`,
|
|
39
|
+
* `Object.getOwnPropertyDescriptor`,
|
|
40
|
+
* `Object.getOwnPropertyDescriptors`, `Object.keys`, and
|
|
41
|
+
* `Object.setPrototypeOf` entry points.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
static OseoResult type_error(OseoContext *context, const char *message) {
|
|
45
|
+
return oseo_internal_throw_error(context, OSEO_ERROR_TYPE, message);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* [[GetOwnProperty]] for a non-Proxy object. A TypedArray answers its
|
|
50
|
+
* canonical numeric keys from the view, whose elements live outside the
|
|
51
|
+
* property vector; every other key reads the stored descriptor. A BigInt
|
|
52
|
+
* element is freshly allocated, so a caller that keeps `*value` across a
|
|
53
|
+
* safepoint roots it.
|
|
54
|
+
*/
|
|
55
|
+
static OseoResult own_property_query(
|
|
56
|
+
OseoContext *context,
|
|
57
|
+
OseoValue object_value,
|
|
58
|
+
OseoValue key,
|
|
59
|
+
bool *found,
|
|
60
|
+
OseoValue *value,
|
|
61
|
+
OseoPropertyAttributes *attributes,
|
|
62
|
+
OseoValue *getter,
|
|
63
|
+
OseoValue *setter
|
|
64
|
+
) {
|
|
65
|
+
bool numeric = false;
|
|
66
|
+
OseoResult result = oseo_internal_typed_array_own_property(
|
|
67
|
+
context,
|
|
68
|
+
object_value,
|
|
69
|
+
key,
|
|
70
|
+
&numeric,
|
|
71
|
+
found
|
|
72
|
+
);
|
|
73
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
74
|
+
if (numeric) {
|
|
75
|
+
*value = result.value;
|
|
76
|
+
*attributes = (OseoPropertyAttributes){true, true, true, false};
|
|
77
|
+
*getter = oseo_undefined();
|
|
78
|
+
*setter = oseo_undefined();
|
|
79
|
+
return normal(oseo_undefined());
|
|
80
|
+
}
|
|
81
|
+
*found = oseo_internal_own_property_descriptor(
|
|
82
|
+
context,
|
|
83
|
+
object_value,
|
|
84
|
+
key,
|
|
85
|
+
value,
|
|
86
|
+
attributes,
|
|
87
|
+
getter,
|
|
88
|
+
setter
|
|
89
|
+
);
|
|
90
|
+
if (!*found) return normal(oseo_undefined());
|
|
91
|
+
result = oseo_internal_legacy_value(context, object_value, key, *value);
|
|
92
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
93
|
+
*value = result.value;
|
|
94
|
+
return oseo_internal_namespace_export_ready(
|
|
95
|
+
context, object_value, *value);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static OseoValue builtin_argument(
|
|
99
|
+
size_t argument_count,
|
|
100
|
+
const OseoValue *arguments,
|
|
101
|
+
size_t index
|
|
102
|
+
) {
|
|
103
|
+
return index < argument_count ? arguments[index] : oseo_undefined();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static OseoResult create_object_prototype_function(
|
|
107
|
+
OseoContext *context,
|
|
108
|
+
size_t code_id,
|
|
109
|
+
const char *name,
|
|
110
|
+
size_t length
|
|
111
|
+
);
|
|
112
|
+
static OseoResult object_get_own_property_descriptors(
|
|
113
|
+
OseoContext *context,
|
|
114
|
+
size_t argument_count,
|
|
115
|
+
const OseoValue *arguments
|
|
116
|
+
);
|
|
117
|
+
static OseoResult object_define_properties(
|
|
118
|
+
OseoContext *context,
|
|
119
|
+
size_t argument_count,
|
|
120
|
+
const OseoValue *arguments
|
|
121
|
+
);
|
|
122
|
+
static OseoResult object_assign(
|
|
123
|
+
OseoContext *context,
|
|
124
|
+
size_t argument_count,
|
|
125
|
+
const OseoValue *arguments
|
|
126
|
+
);
|
|
127
|
+
static OseoResult object_entries(
|
|
128
|
+
OseoContext *context,
|
|
129
|
+
size_t argument_count,
|
|
130
|
+
const OseoValue *arguments
|
|
131
|
+
);
|
|
132
|
+
static OseoResult object_from_entries(
|
|
133
|
+
OseoContext *context,
|
|
134
|
+
size_t argument_count,
|
|
135
|
+
const OseoValue *arguments
|
|
136
|
+
);
|
|
137
|
+
static OseoResult object_get_own_property_names(
|
|
138
|
+
OseoContext *context,
|
|
139
|
+
size_t argument_count,
|
|
140
|
+
const OseoValue *arguments
|
|
141
|
+
);
|
|
142
|
+
static OseoResult object_get_own_property_symbols(
|
|
143
|
+
OseoContext *context,
|
|
144
|
+
size_t argument_count,
|
|
145
|
+
const OseoValue *arguments
|
|
146
|
+
);
|
|
147
|
+
static OseoResult object_group_by(
|
|
148
|
+
OseoContext *context,
|
|
149
|
+
size_t argument_count,
|
|
150
|
+
const OseoValue *arguments
|
|
151
|
+
);
|
|
152
|
+
static OseoResult object_has_own(
|
|
153
|
+
OseoContext *context,
|
|
154
|
+
size_t argument_count,
|
|
155
|
+
const OseoValue *arguments
|
|
156
|
+
);
|
|
157
|
+
static OseoResult object_values(
|
|
158
|
+
OseoContext *context,
|
|
159
|
+
size_t argument_count,
|
|
160
|
+
const OseoValue *arguments
|
|
161
|
+
);
|
|
162
|
+
static OseoResult object_prototype_has_own_property(
|
|
163
|
+
OseoContext *context,
|
|
164
|
+
OseoValue receiver,
|
|
165
|
+
size_t argument_count,
|
|
166
|
+
const OseoValue *arguments
|
|
167
|
+
) {
|
|
168
|
+
OseoResult key = oseo_property_key(
|
|
169
|
+
context,
|
|
170
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
171
|
+
);
|
|
172
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
173
|
+
return oseo_object_has_own(context, receiver, key.value);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static OseoResult object_prototype_property_is_enumerable(
|
|
177
|
+
OseoContext *context,
|
|
178
|
+
OseoValue receiver,
|
|
179
|
+
size_t argument_count,
|
|
180
|
+
const OseoValue *arguments
|
|
181
|
+
) {
|
|
182
|
+
OseoResult key = oseo_property_key(
|
|
183
|
+
context,
|
|
184
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
185
|
+
);
|
|
186
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
187
|
+
if (is_nullish(receiver)) {
|
|
188
|
+
return type_error(context, "Cannot convert a nullish value to object.");
|
|
189
|
+
}
|
|
190
|
+
if (is_string(receiver)) {
|
|
191
|
+
bool own = oseo_internal_string_own_property(
|
|
192
|
+
receiver,
|
|
193
|
+
key.value,
|
|
194
|
+
NULL
|
|
195
|
+
);
|
|
196
|
+
bool enumerable = own &&
|
|
197
|
+
!oseo_internal_string_is_ascii(key.value, "length");
|
|
198
|
+
return normal(oseo_boolean(enumerable));
|
|
199
|
+
}
|
|
200
|
+
if (!is_object(receiver)) return normal(oseo_boolean(false));
|
|
201
|
+
OseoValue ignored = oseo_undefined();
|
|
202
|
+
OseoValue ignored_getter = oseo_undefined();
|
|
203
|
+
OseoValue ignored_setter = oseo_undefined();
|
|
204
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
205
|
+
bool own = false;
|
|
206
|
+
OseoResult result = is_proxy(receiver)
|
|
207
|
+
? oseo_internal_proxy_get_own_property(
|
|
208
|
+
context,
|
|
209
|
+
receiver,
|
|
210
|
+
key.value,
|
|
211
|
+
&own,
|
|
212
|
+
&ignored,
|
|
213
|
+
&attributes,
|
|
214
|
+
&ignored_getter,
|
|
215
|
+
&ignored_setter
|
|
216
|
+
)
|
|
217
|
+
: own_property_query(
|
|
218
|
+
context,
|
|
219
|
+
receiver,
|
|
220
|
+
key.value,
|
|
221
|
+
&own,
|
|
222
|
+
&ignored,
|
|
223
|
+
&attributes,
|
|
224
|
+
&ignored_getter,
|
|
225
|
+
&ignored_setter
|
|
226
|
+
);
|
|
227
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
228
|
+
return normal(oseo_boolean(own && attributes.enumerable));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static OseoResult object_prototype_is_prototype_of(
|
|
232
|
+
OseoContext *context,
|
|
233
|
+
OseoValue receiver,
|
|
234
|
+
size_t argument_count,
|
|
235
|
+
const OseoValue *arguments
|
|
236
|
+
) {
|
|
237
|
+
OseoValue value = builtin_argument(argument_count, arguments, 0u);
|
|
238
|
+
if (!is_object(value)) return normal(oseo_boolean(false));
|
|
239
|
+
if (is_nullish(receiver)) {
|
|
240
|
+
return type_error(context, "Cannot convert a nullish value to object.");
|
|
241
|
+
}
|
|
242
|
+
if (!is_object(receiver)) return normal(oseo_boolean(false));
|
|
243
|
+
OseoResult prototype = oseo_internal_get_prototype(context, value);
|
|
244
|
+
if (prototype.status != OSEO_STATUS_NORMAL) return prototype;
|
|
245
|
+
OseoValue current = prototype.value;
|
|
246
|
+
while (is_object(current)) {
|
|
247
|
+
if (current == receiver) return normal(oseo_boolean(true));
|
|
248
|
+
prototype = oseo_internal_get_prototype(context, current);
|
|
249
|
+
if (prototype.status != OSEO_STATUS_NORMAL) return prototype;
|
|
250
|
+
current = prototype.value;
|
|
251
|
+
}
|
|
252
|
+
return normal(oseo_boolean(false));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
static const char *object_builtin_tag(OseoValue receiver) {
|
|
256
|
+
if (is_array(receiver)) return "Array";
|
|
257
|
+
if (is_regexp(receiver)) return "RegExp";
|
|
258
|
+
if (is_callable(receiver)) return "Function";
|
|
259
|
+
if (is_object(receiver) && ordinary_object(receiver)->arguments_object) {
|
|
260
|
+
return "Arguments";
|
|
261
|
+
}
|
|
262
|
+
if (is_object(receiver) && ordinary_object(receiver)->error_data) {
|
|
263
|
+
return "Error";
|
|
264
|
+
}
|
|
265
|
+
if (is_object(receiver) && ordinary_object(receiver)->number_data) {
|
|
266
|
+
return "Number";
|
|
267
|
+
}
|
|
268
|
+
if (is_object(receiver) && ordinary_object(receiver)->primitive_data) {
|
|
269
|
+
OseoValue primitive = ordinary_object(receiver)->primitive_value;
|
|
270
|
+
if (is_string(primitive)) return "String";
|
|
271
|
+
if (is_symbol(primitive)) return "Object";
|
|
272
|
+
if (tag_of(primitive) == OSEO_TAG_BOOLEAN) return "Boolean";
|
|
273
|
+
}
|
|
274
|
+
if (is_date(receiver)) return "Date";
|
|
275
|
+
if (is_string(receiver)) return "String";
|
|
276
|
+
if (is_symbol(receiver)) return "Object";
|
|
277
|
+
if (is_number(receiver)) return "Number";
|
|
278
|
+
if (tag_of(receiver) == OSEO_TAG_BOOLEAN) return "Boolean";
|
|
279
|
+
return "Object";
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
static OseoResult object_tag_text(
|
|
283
|
+
OseoContext *context,
|
|
284
|
+
OseoValue tag_value,
|
|
285
|
+
const char *fallback
|
|
286
|
+
) {
|
|
287
|
+
static const uint16_t prefix[] = {
|
|
288
|
+
'[', 'o', 'b', 'j', 'e', 'c', 't', ' '
|
|
289
|
+
};
|
|
290
|
+
size_t tag_length = is_string(tag_value)
|
|
291
|
+
? string_object(tag_value)->length
|
|
292
|
+
: strlen(fallback);
|
|
293
|
+
if (tag_length > SIZE_MAX - 9u ||
|
|
294
|
+
tag_length + 9u > SIZE_MAX / sizeof(uint16_t)) {
|
|
295
|
+
return failure(context, "OSEO2001", "Object tag is too long.");
|
|
296
|
+
}
|
|
297
|
+
size_t length = tag_length + 9u;
|
|
298
|
+
OseoResult valid = oseo_internal_validate_string_length(context, length);
|
|
299
|
+
if (valid.status != OSEO_STATUS_NORMAL) return valid;
|
|
300
|
+
uint16_t *units = malloc(length * sizeof(*units));
|
|
301
|
+
if (units == NULL) {
|
|
302
|
+
return failure(context, "OSEO2001", "Object tag allocation failed.");
|
|
303
|
+
}
|
|
304
|
+
memcpy(units, prefix, sizeof(prefix));
|
|
305
|
+
if (is_string(tag_value)) {
|
|
306
|
+
memcpy(
|
|
307
|
+
units + 8u,
|
|
308
|
+
string_object(tag_value)->units,
|
|
309
|
+
tag_length * sizeof(*units)
|
|
310
|
+
);
|
|
311
|
+
} else {
|
|
312
|
+
for (size_t index = 0u; index < tag_length; index += 1u) {
|
|
313
|
+
units[index + 8u] = (uint16_t)(unsigned char)fallback[index];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
units[length - 1u] = ']';
|
|
317
|
+
OseoValue slot = tag_value;
|
|
318
|
+
OseoRootFrame frame = {NULL, &slot, 1u};
|
|
319
|
+
oseo_roots_push(context, &frame);
|
|
320
|
+
OseoResult result = oseo_internal_allocate_string(context, units, length);
|
|
321
|
+
oseo_roots_pop(context, &frame);
|
|
322
|
+
free(units);
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
static OseoResult object_prototype_to_string(
|
|
327
|
+
OseoContext *context,
|
|
328
|
+
OseoValue receiver
|
|
329
|
+
) {
|
|
330
|
+
if (tag_of(receiver) == OSEO_TAG_UNDEFINED) {
|
|
331
|
+
return object_tag_text(context, oseo_undefined(), "Undefined");
|
|
332
|
+
}
|
|
333
|
+
if (tag_of(receiver) == OSEO_TAG_NULL) {
|
|
334
|
+
return object_tag_text(context, oseo_undefined(), "Null");
|
|
335
|
+
}
|
|
336
|
+
OseoValue tag_target = receiver;
|
|
337
|
+
bool proxy_array = false;
|
|
338
|
+
while (is_proxy(tag_target)) {
|
|
339
|
+
if (proxy_object(tag_target)->revoked) {
|
|
340
|
+
return type_error(context, "Cannot inspect a revoked Proxy.");
|
|
341
|
+
}
|
|
342
|
+
tag_target = proxy_object(tag_target)->target;
|
|
343
|
+
}
|
|
344
|
+
if (is_proxy(receiver)) proxy_array = is_array(tag_target);
|
|
345
|
+
const char *fallback = proxy_array
|
|
346
|
+
? "Array"
|
|
347
|
+
: is_callable(receiver)
|
|
348
|
+
? "Function"
|
|
349
|
+
: object_builtin_tag(is_proxy(receiver) ? receiver : tag_target);
|
|
350
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
351
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 4u);
|
|
352
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
353
|
+
frame.slots[0] = receiver;
|
|
354
|
+
if (is_object(frame.slots[0])) {
|
|
355
|
+
frame.slots[1] = frame.slots[0];
|
|
356
|
+
} else {
|
|
357
|
+
result = oseo_internal_to_object(context, frame.slots[0]);
|
|
358
|
+
frame.slots[1] = result.value;
|
|
359
|
+
}
|
|
360
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
361
|
+
result = oseo_internal_well_known_symbol(
|
|
362
|
+
context,
|
|
363
|
+
OSEO_WELL_KNOWN_TO_STRING_TAG
|
|
364
|
+
);
|
|
365
|
+
frame.slots[2] = result.value;
|
|
366
|
+
}
|
|
367
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
368
|
+
/* This is Get(O, @@toStringTag) after ToObject, not GetV on the
|
|
369
|
+
* original primitive. A strict getter must receive the box. */
|
|
370
|
+
result = oseo_object_get(context, frame.slots[1], frame.slots[2]);
|
|
371
|
+
frame.slots[3] = result.value;
|
|
372
|
+
}
|
|
373
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
374
|
+
result = object_tag_text(context, frame.slots[3], fallback);
|
|
375
|
+
}
|
|
376
|
+
oseo_roots_release(context, &frame);
|
|
377
|
+
return result;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
static OseoResult object_prototype_to_locale_string(
|
|
381
|
+
OseoContext *context,
|
|
382
|
+
OseoValue receiver
|
|
383
|
+
) {
|
|
384
|
+
if (is_nullish(receiver)) {
|
|
385
|
+
return type_error(context, "Cannot convert a nullish value to object.");
|
|
386
|
+
}
|
|
387
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
388
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 3u);
|
|
389
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
390
|
+
frame.slots[0] = receiver;
|
|
391
|
+
result = oseo_internal_to_object(context, frame.slots[0]);
|
|
392
|
+
frame.slots[1] = result.value;
|
|
393
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
394
|
+
result = oseo_internal_ascii_string(context, "toString");
|
|
395
|
+
}
|
|
396
|
+
frame.slots[2] = result.value;
|
|
397
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
398
|
+
result = oseo_super_get(
|
|
399
|
+
context,
|
|
400
|
+
frame.slots[1],
|
|
401
|
+
frame.slots[2],
|
|
402
|
+
frame.slots[0]
|
|
403
|
+
);
|
|
404
|
+
frame.slots[2] = result.value;
|
|
405
|
+
}
|
|
406
|
+
if (result.status == OSEO_STATUS_NORMAL && !is_callable(frame.slots[2])) {
|
|
407
|
+
result = type_error(context, "The toString property is not callable.");
|
|
408
|
+
}
|
|
409
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
410
|
+
result = oseo_call_function(
|
|
411
|
+
context,
|
|
412
|
+
frame.slots[2],
|
|
413
|
+
frame.slots[0],
|
|
414
|
+
0u,
|
|
415
|
+
NULL,
|
|
416
|
+
oseo_undefined()
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
oseo_roots_release(context, &frame);
|
|
420
|
+
return result;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
static OseoResult object_prototype_value_of(
|
|
424
|
+
OseoContext *context,
|
|
425
|
+
OseoValue receiver
|
|
426
|
+
) {
|
|
427
|
+
return oseo_internal_to_object(context, receiver);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/* get Object.prototype.__proto__ (20.1.3.8.1). */
|
|
431
|
+
static OseoResult object_prototype_get_proto(
|
|
432
|
+
OseoContext *context,
|
|
433
|
+
OseoValue receiver
|
|
434
|
+
) {
|
|
435
|
+
OseoResult object = oseo_internal_to_object_for_property(
|
|
436
|
+
context, receiver);
|
|
437
|
+
if (object.status != OSEO_STATUS_NORMAL) return object;
|
|
438
|
+
return oseo_internal_get_prototype(context, object.value);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/*
|
|
442
|
+
* set Object.prototype.__proto__ (20.1.3.8.2). A primitive receiver and
|
|
443
|
+
* a prototype that is neither an object nor null leave everything
|
|
444
|
+
* unchanged; a refused [[SetPrototypeOf]] throws the TypeError that
|
|
445
|
+
* oseo_object_set_prototype raises.
|
|
446
|
+
*/
|
|
447
|
+
static OseoResult object_prototype_set_proto(
|
|
448
|
+
OseoContext *context,
|
|
449
|
+
OseoValue receiver,
|
|
450
|
+
size_t argument_count,
|
|
451
|
+
const OseoValue *arguments
|
|
452
|
+
) {
|
|
453
|
+
OseoValue prototype = builtin_argument(argument_count, arguments, 0u);
|
|
454
|
+
if (is_nullish(receiver)) {
|
|
455
|
+
return type_error(
|
|
456
|
+
context,
|
|
457
|
+
"Object.prototype.__proto__ requires a non-nullish receiver."
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
if (tag_of(prototype) != OSEO_TAG_NULL && !is_object(prototype)) {
|
|
461
|
+
return normal(oseo_undefined());
|
|
462
|
+
}
|
|
463
|
+
if (!is_object(receiver)) return normal(oseo_undefined());
|
|
464
|
+
OseoResult result = oseo_object_set_prototype(
|
|
465
|
+
context, receiver, prototype);
|
|
466
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
467
|
+
return normal(oseo_undefined());
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/*
|
|
471
|
+
* Object.prototype.__defineGetter__ and __defineSetter__ (20.1.3.9 and
|
|
472
|
+
* 20.1.3.10). The callability check precedes ToPropertyKey, and the
|
|
473
|
+
* definition is DefinePropertyOrThrow of an enumerable, configurable
|
|
474
|
+
* accessor half, so an existing other half survives and a Proxy sees
|
|
475
|
+
* its defineProperty trap.
|
|
476
|
+
*/
|
|
477
|
+
static OseoResult object_prototype_define_accessor(
|
|
478
|
+
OseoContext *context,
|
|
479
|
+
OseoValue receiver,
|
|
480
|
+
size_t argument_count,
|
|
481
|
+
const OseoValue *arguments,
|
|
482
|
+
bool setter_half
|
|
483
|
+
) {
|
|
484
|
+
/* Slots: 0 object, 1 function, 2 key. */
|
|
485
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
486
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 3u);
|
|
487
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
488
|
+
frame.slots[1] = builtin_argument(argument_count, arguments, 1u);
|
|
489
|
+
result = oseo_internal_to_object(context, receiver);
|
|
490
|
+
frame.slots[0] = result.value;
|
|
491
|
+
if (result.status == OSEO_STATUS_NORMAL && !is_callable(frame.slots[1])) {
|
|
492
|
+
result = type_error(
|
|
493
|
+
context,
|
|
494
|
+
setter_half
|
|
495
|
+
? "Object.prototype.__defineSetter__ requires a function."
|
|
496
|
+
: "Object.prototype.__defineGetter__ requires a function."
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
500
|
+
result = oseo_property_key(
|
|
501
|
+
context,
|
|
502
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
503
|
+
);
|
|
504
|
+
frame.slots[2] = result.value;
|
|
505
|
+
}
|
|
506
|
+
const char *refusal = NULL;
|
|
507
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
508
|
+
const OseoConvertedDescriptor descriptor = {
|
|
509
|
+
.has_enumerable = true,
|
|
510
|
+
.enumerable = true,
|
|
511
|
+
.has_configurable = true,
|
|
512
|
+
.configurable = true,
|
|
513
|
+
.has_getter = !setter_half,
|
|
514
|
+
.has_setter = setter_half,
|
|
515
|
+
};
|
|
516
|
+
result = oseo_internal_define_converted_property(
|
|
517
|
+
context,
|
|
518
|
+
frame.slots[0],
|
|
519
|
+
frame.slots[2],
|
|
520
|
+
&descriptor,
|
|
521
|
+
oseo_undefined(),
|
|
522
|
+
setter_half ? oseo_undefined() : frame.slots[1],
|
|
523
|
+
setter_half ? frame.slots[1] : oseo_undefined(),
|
|
524
|
+
&refusal
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
if (result.status == OSEO_STATUS_NORMAL && refusal != NULL) {
|
|
528
|
+
result = type_error(context, refusal);
|
|
529
|
+
}
|
|
530
|
+
oseo_roots_release(context, &frame);
|
|
531
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
532
|
+
return normal(oseo_undefined());
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/*
|
|
536
|
+
* Object.prototype.__lookupGetter__ and __lookupSetter__ (20.1.3.11 and
|
|
537
|
+
* 20.1.3.12). The walk asks each object's [[GetOwnProperty]] and
|
|
538
|
+
* [[GetPrototypeOf]], so Proxy traps on the chain run in that order, and
|
|
539
|
+
* the first own property found answers even when it is a data property.
|
|
540
|
+
*/
|
|
541
|
+
static OseoResult object_prototype_lookup_accessor(
|
|
542
|
+
OseoContext *context,
|
|
543
|
+
OseoValue receiver,
|
|
544
|
+
size_t argument_count,
|
|
545
|
+
const OseoValue *arguments,
|
|
546
|
+
bool setter_half
|
|
547
|
+
) {
|
|
548
|
+
/* Slots: 0 current object, 1 key. */
|
|
549
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
550
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 2u);
|
|
551
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
552
|
+
result = oseo_internal_to_object(context, receiver);
|
|
553
|
+
frame.slots[0] = result.value;
|
|
554
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
555
|
+
result = oseo_property_key(
|
|
556
|
+
context,
|
|
557
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
558
|
+
);
|
|
559
|
+
frame.slots[1] = result.value;
|
|
560
|
+
}
|
|
561
|
+
OseoValue answer = oseo_undefined();
|
|
562
|
+
while (result.status == OSEO_STATUS_NORMAL) {
|
|
563
|
+
OseoValue value = oseo_undefined();
|
|
564
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
565
|
+
OseoValue getter = oseo_undefined();
|
|
566
|
+
OseoValue setter = oseo_undefined();
|
|
567
|
+
bool exists = false;
|
|
568
|
+
result = is_proxy(frame.slots[0])
|
|
569
|
+
? oseo_internal_proxy_get_own_property(
|
|
570
|
+
context,
|
|
571
|
+
frame.slots[0],
|
|
572
|
+
frame.slots[1],
|
|
573
|
+
&exists,
|
|
574
|
+
&value,
|
|
575
|
+
&attributes,
|
|
576
|
+
&getter,
|
|
577
|
+
&setter
|
|
578
|
+
)
|
|
579
|
+
: own_property_query(
|
|
580
|
+
context,
|
|
581
|
+
frame.slots[0],
|
|
582
|
+
frame.slots[1],
|
|
583
|
+
&exists,
|
|
584
|
+
&value,
|
|
585
|
+
&attributes,
|
|
586
|
+
&getter,
|
|
587
|
+
&setter
|
|
588
|
+
);
|
|
589
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
590
|
+
if (exists) {
|
|
591
|
+
if (attributes.accessor) answer = setter_half ? setter : getter;
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
result = oseo_internal_get_prototype(context, frame.slots[0]);
|
|
595
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
596
|
+
if (tag_of(result.value) == OSEO_TAG_NULL) break;
|
|
597
|
+
frame.slots[0] = result.value;
|
|
598
|
+
}
|
|
599
|
+
oseo_roots_release(context, &frame);
|
|
600
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
601
|
+
return normal(answer);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
OseoResult oseo_internal_install_primitive_wrapper_methods(
|
|
605
|
+
OseoContext *context,
|
|
606
|
+
OseoValue prototype,
|
|
607
|
+
bool include_index_of
|
|
608
|
+
) {
|
|
609
|
+
if (ordinary_object(prototype)->primitive_wrapper_methods_initialized) {
|
|
610
|
+
return normal(prototype);
|
|
611
|
+
}
|
|
612
|
+
static const struct {
|
|
613
|
+
const char *name;
|
|
614
|
+
size_t length;
|
|
615
|
+
} methods[] = {
|
|
616
|
+
{"toString", 0u},
|
|
617
|
+
{"valueOf", 0u},
|
|
618
|
+
{"indexOf", 1u},
|
|
619
|
+
};
|
|
620
|
+
size_t method_count = include_index_of ? 3u : 2u;
|
|
621
|
+
OseoValue slots[3] = {
|
|
622
|
+
prototype,
|
|
623
|
+
oseo_undefined(),
|
|
624
|
+
oseo_undefined(),
|
|
625
|
+
};
|
|
626
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
627
|
+
oseo_roots_push(context, &frame);
|
|
628
|
+
OseoResult result = normal(slots[0]);
|
|
629
|
+
for (size_t index = 0u; index < method_count; index += 1u) {
|
|
630
|
+
result = create_object_prototype_function(
|
|
631
|
+
context,
|
|
632
|
+
OSEO_OBJECT_PRIMITIVE_WRAPPER_METHOD_CODE_ID,
|
|
633
|
+
methods[index].name,
|
|
634
|
+
methods[index].length
|
|
635
|
+
);
|
|
636
|
+
slots[1] = result.value;
|
|
637
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
638
|
+
result = oseo_internal_ascii_string(
|
|
639
|
+
context,
|
|
640
|
+
methods[index].name
|
|
641
|
+
);
|
|
642
|
+
slots[2] = result.value;
|
|
643
|
+
}
|
|
644
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
645
|
+
result = oseo_object_define(
|
|
646
|
+
context,
|
|
647
|
+
slots[0],
|
|
648
|
+
slots[2],
|
|
649
|
+
slots[1],
|
|
650
|
+
(OseoPropertyAttributes){true, false, true, false}
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
654
|
+
}
|
|
655
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
656
|
+
ordinary_object(slots[0])->primitive_wrapper_methods_initialized =
|
|
657
|
+
true;
|
|
658
|
+
result.value = slots[0];
|
|
659
|
+
}
|
|
660
|
+
oseo_roots_pop(context, &frame);
|
|
661
|
+
return result;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
OseoResult oseo_internal_primitive_wrapper_prototype(
|
|
665
|
+
OseoContext *context,
|
|
666
|
+
OseoIntrinsic intrinsic
|
|
667
|
+
) {
|
|
668
|
+
OseoResult result;
|
|
669
|
+
bool created = false;
|
|
670
|
+
/*
|
|
671
|
+
* A prototype whose own constructor node materializes it, including
|
|
672
|
+
* the exotic own properties and the `constructor` property, is
|
|
673
|
+
* reached through the realm intrinsic table rather than built here.
|
|
674
|
+
*/
|
|
675
|
+
if (intrinsic == OSEO_INTRINSIC_BOOLEAN_PROTOTYPE ||
|
|
676
|
+
intrinsic == OSEO_INTRINSIC_BIGINT_PROTOTYPE ||
|
|
677
|
+
intrinsic == OSEO_INTRINSIC_NUMBER_PROTOTYPE ||
|
|
678
|
+
intrinsic == OSEO_INTRINSIC_STRING_PROTOTYPE ||
|
|
679
|
+
intrinsic == OSEO_INTRINSIC_SYMBOL_PROTOTYPE) {
|
|
680
|
+
result = oseo_internal_intrinsic(context, intrinsic);
|
|
681
|
+
} else if (is_object(context->realm->intrinsics[intrinsic])) {
|
|
682
|
+
result = normal(context->realm->intrinsics[intrinsic]);
|
|
683
|
+
} else {
|
|
684
|
+
result = oseo_internal_intrinsic(
|
|
685
|
+
context,
|
|
686
|
+
OSEO_INTRINSIC_OBJECT_PROTOTYPE
|
|
687
|
+
);
|
|
688
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
689
|
+
result = oseo_object_create(context, result.value);
|
|
690
|
+
}
|
|
691
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
692
|
+
context->realm->intrinsics[intrinsic] = result.value;
|
|
693
|
+
created = true;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
697
|
+
if (intrinsic == OSEO_INTRINSIC_BOOLEAN_PROTOTYPE ||
|
|
698
|
+
intrinsic == OSEO_INTRINSIC_BIGINT_PROTOTYPE ||
|
|
699
|
+
intrinsic == OSEO_INTRINSIC_NUMBER_PROTOTYPE ||
|
|
700
|
+
intrinsic == OSEO_INTRINSIC_STRING_PROTOTYPE ||
|
|
701
|
+
intrinsic == OSEO_INTRINSIC_SYMBOL_PROTOTYPE) {
|
|
702
|
+
return result;
|
|
703
|
+
}
|
|
704
|
+
if (created) {
|
|
705
|
+
OseoOrdinaryObject *prototype = ordinary_object(result.value);
|
|
706
|
+
prototype->primitive_data = true;
|
|
707
|
+
prototype->primitive_value = oseo_boolean(false);
|
|
708
|
+
}
|
|
709
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
710
|
+
result = oseo_internal_install_primitive_wrapper_methods(
|
|
711
|
+
context,
|
|
712
|
+
context->realm->intrinsics[intrinsic],
|
|
713
|
+
false
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
if (result.status != OSEO_STATUS_NORMAL && created) {
|
|
717
|
+
context->realm->intrinsics[intrinsic] = oseo_undefined();
|
|
718
|
+
}
|
|
719
|
+
return result;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
static OseoResult primitive_wrapper_prototype(
|
|
723
|
+
OseoContext *context,
|
|
724
|
+
OseoValue value
|
|
725
|
+
) {
|
|
726
|
+
OseoIntrinsic intrinsic;
|
|
727
|
+
if (is_number(value)) {
|
|
728
|
+
intrinsic = OSEO_INTRINSIC_NUMBER_PROTOTYPE;
|
|
729
|
+
} else if (is_symbol(value)) {
|
|
730
|
+
intrinsic = OSEO_INTRINSIC_SYMBOL_PROTOTYPE;
|
|
731
|
+
} else if (is_string(value)) {
|
|
732
|
+
intrinsic = OSEO_INTRINSIC_STRING_PROTOTYPE;
|
|
733
|
+
} else if (is_bigint(value)) {
|
|
734
|
+
intrinsic = OSEO_INTRINSIC_BIGINT_PROTOTYPE;
|
|
735
|
+
} else {
|
|
736
|
+
intrinsic = OSEO_INTRINSIC_BOOLEAN_PROTOTYPE;
|
|
737
|
+
}
|
|
738
|
+
return oseo_internal_primitive_wrapper_prototype(context, intrinsic);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
static OseoResult to_object(
|
|
742
|
+
OseoContext *context,
|
|
743
|
+
OseoValue value,
|
|
744
|
+
bool define_string_properties
|
|
745
|
+
) {
|
|
746
|
+
if (is_nullish(value)) {
|
|
747
|
+
return type_error(context, "Cannot convert a nullish value to object.");
|
|
748
|
+
}
|
|
749
|
+
if (is_object(value)) return normal(value);
|
|
750
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
751
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 4u);
|
|
752
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
753
|
+
frame.slots[0] = value;
|
|
754
|
+
result = primitive_wrapper_prototype(context, frame.slots[0]);
|
|
755
|
+
frame.slots[1] = result.value;
|
|
756
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
757
|
+
result = oseo_object_create(context, frame.slots[1]);
|
|
758
|
+
frame.slots[1] = result.value;
|
|
759
|
+
}
|
|
760
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
761
|
+
OseoOrdinaryObject *wrapper = ordinary_object(frame.slots[1]);
|
|
762
|
+
wrapper->primitive_data = true;
|
|
763
|
+
wrapper->primitive_value = frame.slots[0];
|
|
764
|
+
if (is_number(frame.slots[0])) {
|
|
765
|
+
wrapper->number_data = true;
|
|
766
|
+
wrapper->number_value = frame.slots[0];
|
|
767
|
+
}
|
|
768
|
+
if (define_string_properties && is_string(frame.slots[0])) {
|
|
769
|
+
result = oseo_internal_string_wrapper_properties(
|
|
770
|
+
context,
|
|
771
|
+
frame.slots[0],
|
|
772
|
+
frame.slots[1]
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[1];
|
|
777
|
+
oseo_roots_release(context, &frame);
|
|
778
|
+
return result;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
OseoResult oseo_to_object(OseoContext *context, OseoValue value) {
|
|
782
|
+
return to_object(context, value, true);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
OseoResult oseo_internal_to_object(OseoContext *context, OseoValue value) {
|
|
786
|
+
return to_object(context, value, true);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
OseoResult oseo_internal_to_object_for_property(
|
|
790
|
+
OseoContext *context,
|
|
791
|
+
OseoValue value
|
|
792
|
+
) {
|
|
793
|
+
return to_object(context, value, false);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/*
|
|
797
|
+
* OrdinaryCreateFromConstructor(newTarget, "%Object.prototype%").
|
|
798
|
+
* GetPrototypeFromConstructor is a real Get rather than a read of the
|
|
799
|
+
* synthetic `prototype` slot, because `Reflect.construct` can hand this
|
|
800
|
+
* a bound function whose own `prototype` a program defined as an
|
|
801
|
+
* accessor. `Object` performs no argument validation before this step,
|
|
802
|
+
* so the read is at the position 20.1.1.1 gives it.
|
|
803
|
+
*/
|
|
804
|
+
static OseoResult object_create_from_constructor(
|
|
805
|
+
OseoContext *context,
|
|
806
|
+
OseoValue new_target
|
|
807
|
+
) {
|
|
808
|
+
OseoValue slots[2] = {new_target, oseo_undefined()};
|
|
809
|
+
OseoRootFrame frame = {NULL, slots, 2u};
|
|
810
|
+
oseo_roots_push(context, &frame);
|
|
811
|
+
OseoResult result = oseo_internal_constructor_prototype(
|
|
812
|
+
context,
|
|
813
|
+
slots[0]
|
|
814
|
+
);
|
|
815
|
+
slots[1] = result.value;
|
|
816
|
+
if (result.status == OSEO_STATUS_NORMAL && !is_object(slots[1])) {
|
|
817
|
+
result = oseo_internal_constructor_realm_default(
|
|
818
|
+
context,
|
|
819
|
+
slots[0],
|
|
820
|
+
OSEO_INTRINSIC_OBJECT_PROTOTYPE
|
|
821
|
+
);
|
|
822
|
+
slots[1] = result.value;
|
|
823
|
+
}
|
|
824
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
825
|
+
result = oseo_object_create(context, slots[1]);
|
|
826
|
+
}
|
|
827
|
+
oseo_roots_pop(context, &frame);
|
|
828
|
+
return result;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
static OseoResult object_constructor(
|
|
832
|
+
OseoContext *context,
|
|
833
|
+
OseoValue callee,
|
|
834
|
+
size_t argument_count,
|
|
835
|
+
const OseoValue *arguments,
|
|
836
|
+
OseoValue new_target
|
|
837
|
+
) {
|
|
838
|
+
if (tag_of(new_target) != OSEO_TAG_UNDEFINED && new_target != callee) {
|
|
839
|
+
return object_create_from_constructor(context, new_target);
|
|
840
|
+
}
|
|
841
|
+
OseoValue value = builtin_argument(argument_count, arguments, 0u);
|
|
842
|
+
if (!is_nullish(value)) return oseo_internal_to_object(context, value);
|
|
843
|
+
/* The new target is absent or the active function itself, so
|
|
844
|
+
* 20.1.1.1 step 2 creates an ordinary object over the realm
|
|
845
|
+
* prototype rather than reading anything. A built-in [[Construct]]
|
|
846
|
+
* never adopts the receiver its caller made, so this creates one
|
|
847
|
+
* even when the caller already had. */
|
|
848
|
+
OseoResult prototype = oseo_internal_intrinsic(
|
|
849
|
+
context,
|
|
850
|
+
OSEO_INTRINSIC_OBJECT_PROTOTYPE
|
|
851
|
+
);
|
|
852
|
+
if (prototype.status != OSEO_STATUS_NORMAL) return prototype;
|
|
853
|
+
return oseo_object_create(context, prototype.value);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
static OseoResult object_get_prototype_of(
|
|
857
|
+
OseoContext *context,
|
|
858
|
+
size_t argument_count,
|
|
859
|
+
const OseoValue *arguments
|
|
860
|
+
) {
|
|
861
|
+
OseoResult object = oseo_internal_to_object_for_property(
|
|
862
|
+
context,
|
|
863
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
864
|
+
);
|
|
865
|
+
if (object.status != OSEO_STATUS_NORMAL) return object;
|
|
866
|
+
return oseo_internal_get_prototype(context, object.value);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
static OseoResult object_is(
|
|
870
|
+
size_t argument_count,
|
|
871
|
+
const OseoValue *arguments
|
|
872
|
+
) {
|
|
873
|
+
OseoValue left = builtin_argument(argument_count, arguments, 0u);
|
|
874
|
+
OseoValue right = builtin_argument(argument_count, arguments, 1u);
|
|
875
|
+
return normal(oseo_boolean(oseo_internal_same_value(left, right)));
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/*
|
|
879
|
+
* SetIntegrityLevel (7.3.15) over the ordinary and currently admitted exotic
|
|
880
|
+
* object representations. The descriptor component remains authoritative for
|
|
881
|
+
* applying every stored property change, including mapped arguments aliases
|
|
882
|
+
* and module namespace compatibility. Array `length` and function `prototype`
|
|
883
|
+
* are the two own data properties held outside the property vector.
|
|
884
|
+
*/
|
|
885
|
+
static OseoResult object_set_integrity_level(
|
|
886
|
+
OseoContext *context,
|
|
887
|
+
OseoValue object_value,
|
|
888
|
+
bool frozen
|
|
889
|
+
) {
|
|
890
|
+
if (is_proxy(object_value)) {
|
|
891
|
+
OseoValue slots[3] = {
|
|
892
|
+
object_value, oseo_undefined(), oseo_undefined(),
|
|
893
|
+
};
|
|
894
|
+
OseoRootFrame proxy_frame = {NULL, slots, 3u};
|
|
895
|
+
oseo_roots_push(context, &proxy_frame);
|
|
896
|
+
const char *refusal = NULL;
|
|
897
|
+
OseoResult proxy_result = oseo_internal_prevent_extensions_reported(
|
|
898
|
+
context, slots[0], &refusal);
|
|
899
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL && refusal != NULL) {
|
|
900
|
+
proxy_result = type_error(context, refusal);
|
|
901
|
+
}
|
|
902
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
903
|
+
proxy_result = oseo_internal_proxy_own_keys(
|
|
904
|
+
context, slots[0], OSEO_OWN_KEY_ALL);
|
|
905
|
+
slots[1] = proxy_result.value;
|
|
906
|
+
}
|
|
907
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
908
|
+
proxy_result = oseo_internal_array_like_list(
|
|
909
|
+
context, slots[1], &slots[2]);
|
|
910
|
+
}
|
|
911
|
+
size_t key_count = 0u;
|
|
912
|
+
const OseoValue *keys = NULL;
|
|
913
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
914
|
+
proxy_result = oseo_argument_list_view(
|
|
915
|
+
context, slots[2], &key_count, &keys);
|
|
916
|
+
}
|
|
917
|
+
for (size_t index = 0u;
|
|
918
|
+
proxy_result.status == OSEO_STATUS_NORMAL && index < key_count;
|
|
919
|
+
index += 1u) {
|
|
920
|
+
bool found = true;
|
|
921
|
+
OseoValue value = oseo_undefined();
|
|
922
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
923
|
+
OseoValue getter = oseo_undefined();
|
|
924
|
+
OseoValue setter = oseo_undefined();
|
|
925
|
+
if (frozen) {
|
|
926
|
+
proxy_result = oseo_internal_proxy_get_own_property(
|
|
927
|
+
context, slots[0], keys[index], &found, &value,
|
|
928
|
+
&attributes, &getter, &setter);
|
|
929
|
+
}
|
|
930
|
+
if (proxy_result.status != OSEO_STATUS_NORMAL || !found) continue;
|
|
931
|
+
OseoConvertedDescriptor descriptor = {
|
|
932
|
+
false, false, true, false,
|
|
933
|
+
frozen && !attributes.accessor, false,
|
|
934
|
+
false, false, false,
|
|
935
|
+
};
|
|
936
|
+
refusal = NULL;
|
|
937
|
+
proxy_result = oseo_internal_proxy_define_own_property(
|
|
938
|
+
context, slots[0], keys[index], &descriptor,
|
|
939
|
+
oseo_undefined(), oseo_undefined(), oseo_undefined(),
|
|
940
|
+
&refusal);
|
|
941
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL && refusal != NULL) {
|
|
942
|
+
proxy_result = type_error(context, refusal);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
946
|
+
proxy_result.value = slots[0];
|
|
947
|
+
}
|
|
948
|
+
oseo_roots_pop(context, &proxy_frame);
|
|
949
|
+
return proxy_result;
|
|
950
|
+
}
|
|
951
|
+
if (is_typed_array(object_value)) {
|
|
952
|
+
/* A view's [[PreventExtensions]] refuses a length that can still
|
|
953
|
+
* change, and each valid index then refuses the non-configurable
|
|
954
|
+
* redefinition DefinePropertyOrThrow asks for. The
|
|
955
|
+
* indices lead the own keys, so no ordinary property changes. */
|
|
956
|
+
const char *refusal = NULL;
|
|
957
|
+
OseoResult prevented = oseo_internal_prevent_extensions_reported(
|
|
958
|
+
context, object_value, &refusal);
|
|
959
|
+
if (prevented.status != OSEO_STATUS_NORMAL) return prevented;
|
|
960
|
+
if (refusal != NULL) return type_error(context, refusal);
|
|
961
|
+
if (oseo_internal_typed_array_index_key_count(object_value) > 0u) {
|
|
962
|
+
return type_error(
|
|
963
|
+
context,
|
|
964
|
+
"A TypedArray element must stay a writable, enumerable, "
|
|
965
|
+
"and configurable data property."
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
OseoOrdinaryObject *object = ordinary_object(object_value);
|
|
970
|
+
object->extensible = false;
|
|
971
|
+
if (object->virtual_string_iterator) {
|
|
972
|
+
object->virtual_string_iterator_configurable = false;
|
|
973
|
+
if (frozen) object->virtual_string_iterator_writable = false;
|
|
974
|
+
}
|
|
975
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
976
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 3u);
|
|
977
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
978
|
+
frame.slots[0] = object_value;
|
|
979
|
+
/* SetIntegrityLevel redefines a live `arguments` or `caller` like
|
|
980
|
+
* any other own property, which fixes its present value. */
|
|
981
|
+
if (is_function(object_value) &&
|
|
982
|
+
function_object(object_value)->legacy_live != 0u) {
|
|
983
|
+
result = oseo_internal_legacy_function_keys(context);
|
|
984
|
+
for (size_t index = 0u;
|
|
985
|
+
result.status == OSEO_STATUS_NORMAL && index < 2u;
|
|
986
|
+
index += 1u) {
|
|
987
|
+
result = oseo_internal_legacy_materialize(
|
|
988
|
+
context,
|
|
989
|
+
frame.slots[0],
|
|
990
|
+
context->legacy_function_keys[index]
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
994
|
+
oseo_roots_release(context, &frame);
|
|
995
|
+
return result;
|
|
996
|
+
}
|
|
997
|
+
object = ordinary_object(frame.slots[0]);
|
|
998
|
+
}
|
|
999
|
+
size_t property_count = object->property_count;
|
|
1000
|
+
for (size_t index = 0u;
|
|
1001
|
+
result.status == OSEO_STATUS_NORMAL && index < property_count;
|
|
1002
|
+
index += 1u) {
|
|
1003
|
+
object = ordinary_object(frame.slots[0]);
|
|
1004
|
+
OseoProperty property = object->properties[index];
|
|
1005
|
+
frame.slots[1] = property.key;
|
|
1006
|
+
frame.slots[2] = property.attributes.accessor
|
|
1007
|
+
? property.getter
|
|
1008
|
+
: property.value;
|
|
1009
|
+
if (!property.attributes.accessor &&
|
|
1010
|
+
oseo_internal_cell_backed_property(
|
|
1011
|
+
frame.slots[0], frame.slots[2])) {
|
|
1012
|
+
result = oseo_cell_get(context, frame.slots[2]);
|
|
1013
|
+
frame.slots[2] = result.value;
|
|
1014
|
+
}
|
|
1015
|
+
OseoPropertyAttributes attributes = property.attributes;
|
|
1016
|
+
attributes.configurable = false;
|
|
1017
|
+
if (frozen && !attributes.accessor) attributes.writable = false;
|
|
1018
|
+
if (result.status == OSEO_STATUS_NORMAL && attributes.accessor) {
|
|
1019
|
+
OseoConvertedDescriptor seal = {
|
|
1020
|
+
false, false, true, false, false, false, false, false, false,
|
|
1021
|
+
};
|
|
1022
|
+
const char *refusal = NULL;
|
|
1023
|
+
result = oseo_internal_define_converted_property(
|
|
1024
|
+
context, frame.slots[0], frame.slots[1], &seal,
|
|
1025
|
+
oseo_undefined(), oseo_undefined(), oseo_undefined(),
|
|
1026
|
+
&refusal);
|
|
1027
|
+
if (result.status == OSEO_STATUS_NORMAL && refusal != NULL) {
|
|
1028
|
+
result = type_error(context, refusal);
|
|
1029
|
+
}
|
|
1030
|
+
} else if (result.status == OSEO_STATUS_NORMAL) {
|
|
1031
|
+
result = oseo_internal_object_define_data(
|
|
1032
|
+
context,
|
|
1033
|
+
frame.slots[0],
|
|
1034
|
+
frame.slots[1],
|
|
1035
|
+
frame.slots[2],
|
|
1036
|
+
attributes,
|
|
1037
|
+
true
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
if (result.status == OSEO_STATUS_NORMAL && frozen) {
|
|
1042
|
+
object = ordinary_object(frame.slots[0]);
|
|
1043
|
+
if (is_array(frame.slots[0])) object->length_writable = false;
|
|
1044
|
+
if (function_has_prototype_property(frame.slots[0])) {
|
|
1045
|
+
function_object(frame.slots[0])->prototype_writable = false;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[0];
|
|
1049
|
+
oseo_roots_release(context, &frame);
|
|
1050
|
+
return result;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/* TestIntegrityLevel (7.3.16), including the two virtual own properties. */
|
|
1054
|
+
static OseoResult object_test_integrity_level(
|
|
1055
|
+
OseoContext *context,
|
|
1056
|
+
OseoValue value,
|
|
1057
|
+
bool frozen
|
|
1058
|
+
) {
|
|
1059
|
+
if (is_proxy(value)) {
|
|
1060
|
+
OseoValue slots[3] = {value, oseo_undefined(), oseo_undefined()};
|
|
1061
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
1062
|
+
oseo_roots_push(context, &frame);
|
|
1063
|
+
OseoResult result = oseo_internal_is_extensible(context, slots[0]);
|
|
1064
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
1065
|
+
oseo_to_boolean(result.value)) {
|
|
1066
|
+
oseo_roots_pop(context, &frame);
|
|
1067
|
+
return normal(oseo_boolean(false));
|
|
1068
|
+
}
|
|
1069
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1070
|
+
result = oseo_internal_proxy_own_keys(
|
|
1071
|
+
context, slots[0], OSEO_OWN_KEY_ALL);
|
|
1072
|
+
slots[1] = result.value;
|
|
1073
|
+
}
|
|
1074
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1075
|
+
result = oseo_internal_array_like_list(
|
|
1076
|
+
context, slots[1], &slots[2]);
|
|
1077
|
+
}
|
|
1078
|
+
size_t key_count = 0u;
|
|
1079
|
+
const OseoValue *keys = NULL;
|
|
1080
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1081
|
+
result = oseo_argument_list_view(
|
|
1082
|
+
context, slots[2], &key_count, &keys);
|
|
1083
|
+
}
|
|
1084
|
+
bool intact = true;
|
|
1085
|
+
for (size_t index = 0u;
|
|
1086
|
+
result.status == OSEO_STATUS_NORMAL && intact &&
|
|
1087
|
+
index < key_count;
|
|
1088
|
+
index += 1u) {
|
|
1089
|
+
bool found = false;
|
|
1090
|
+
OseoValue property = oseo_undefined();
|
|
1091
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
1092
|
+
OseoValue getter = oseo_undefined();
|
|
1093
|
+
OseoValue setter = oseo_undefined();
|
|
1094
|
+
result = oseo_internal_proxy_get_own_property(
|
|
1095
|
+
context, slots[0], keys[index], &found, &property, &attributes,
|
|
1096
|
+
&getter, &setter);
|
|
1097
|
+
if (result.status == OSEO_STATUS_NORMAL && found &&
|
|
1098
|
+
(attributes.configurable ||
|
|
1099
|
+
(frozen && !attributes.accessor && attributes.writable))) {
|
|
1100
|
+
intact = false;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1104
|
+
result = normal(oseo_boolean(intact));
|
|
1105
|
+
}
|
|
1106
|
+
oseo_roots_pop(context, &frame);
|
|
1107
|
+
return result;
|
|
1108
|
+
}
|
|
1109
|
+
OseoOrdinaryObject *object = ordinary_object(value);
|
|
1110
|
+
if (object->extensible) return normal(oseo_boolean(false));
|
|
1111
|
+
/* Every valid TypedArray element is configurable and writable. */
|
|
1112
|
+
if (oseo_internal_typed_array_index_key_count(value) > 0u) {
|
|
1113
|
+
return normal(oseo_boolean(false));
|
|
1114
|
+
}
|
|
1115
|
+
if (frozen && is_array(value) && object->length_writable) {
|
|
1116
|
+
return normal(oseo_boolean(false));
|
|
1117
|
+
}
|
|
1118
|
+
if (frozen && function_has_prototype_property(value) &&
|
|
1119
|
+
function_object(value)->prototype_writable) {
|
|
1120
|
+
return normal(oseo_boolean(false));
|
|
1121
|
+
}
|
|
1122
|
+
/* A live `arguments` or `caller` is configurable (ADR 0034). */
|
|
1123
|
+
if (is_function(value) && function_object(value)->legacy_live != 0u) {
|
|
1124
|
+
return normal(oseo_boolean(false));
|
|
1125
|
+
}
|
|
1126
|
+
if (object->virtual_string_iterator &&
|
|
1127
|
+
(object->virtual_string_iterator_configurable ||
|
|
1128
|
+
(frozen && object->virtual_string_iterator_writable))) {
|
|
1129
|
+
return normal(oseo_boolean(false));
|
|
1130
|
+
}
|
|
1131
|
+
/* A module namespace lists its exports in [[OwnPropertyKeys]] order,
|
|
1132
|
+
* so this walk reads each export's binding exactly where
|
|
1133
|
+
* TestIntegrityLevel's [[GetOwnProperty]] would. */
|
|
1134
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
1135
|
+
OseoResult ready = oseo_internal_namespace_export_ready(
|
|
1136
|
+
context, value, ordinary_object(value)->properties[index].value);
|
|
1137
|
+
if (ready.status != OSEO_STATUS_NORMAL) return ready;
|
|
1138
|
+
object = ordinary_object(value);
|
|
1139
|
+
OseoPropertyAttributes attributes =
|
|
1140
|
+
object->properties[index].attributes;
|
|
1141
|
+
if (attributes.configurable ||
|
|
1142
|
+
(frozen && !attributes.accessor && attributes.writable)) {
|
|
1143
|
+
return normal(oseo_boolean(false));
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return normal(oseo_boolean(true));
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
static OseoResult object_integrity_transition(
|
|
1150
|
+
OseoContext *context,
|
|
1151
|
+
size_t argument_count,
|
|
1152
|
+
const OseoValue *arguments,
|
|
1153
|
+
bool frozen
|
|
1154
|
+
) {
|
|
1155
|
+
OseoValue value = builtin_argument(argument_count, arguments, 0u);
|
|
1156
|
+
if (!is_object(value)) return normal(value);
|
|
1157
|
+
return object_set_integrity_level(context, value, frozen);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
static OseoResult object_integrity_query(
|
|
1161
|
+
OseoContext *context,
|
|
1162
|
+
size_t argument_count,
|
|
1163
|
+
const OseoValue *arguments,
|
|
1164
|
+
bool frozen
|
|
1165
|
+
) {
|
|
1166
|
+
OseoValue value = builtin_argument(argument_count, arguments, 0u);
|
|
1167
|
+
return !is_object(value)
|
|
1168
|
+
? normal(oseo_boolean(true))
|
|
1169
|
+
: object_test_integrity_level(context, value, frozen);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
static OseoResult object_is_extensible(
|
|
1173
|
+
OseoContext *context,
|
|
1174
|
+
size_t argument_count,
|
|
1175
|
+
const OseoValue *arguments
|
|
1176
|
+
) {
|
|
1177
|
+
OseoValue value = builtin_argument(argument_count, arguments, 0u);
|
|
1178
|
+
return is_object(value)
|
|
1179
|
+
? oseo_internal_is_extensible(context, value)
|
|
1180
|
+
: normal(oseo_boolean(false));
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
static OseoResult object_prevent_extensions(
|
|
1184
|
+
OseoContext *context,
|
|
1185
|
+
size_t argument_count,
|
|
1186
|
+
const OseoValue *arguments
|
|
1187
|
+
) {
|
|
1188
|
+
OseoValue value = builtin_argument(argument_count, arguments, 0u);
|
|
1189
|
+
if (!is_object(value)) return normal(value);
|
|
1190
|
+
const char *refusal = NULL;
|
|
1191
|
+
OseoResult result = oseo_internal_prevent_extensions_reported(
|
|
1192
|
+
context, value, &refusal);
|
|
1193
|
+
if (result.status != OSEO_STATUS_NORMAL || refusal == NULL) return result;
|
|
1194
|
+
return type_error(context, refusal);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
OseoResult oseo_internal_object_builtin_dispatch(
|
|
1198
|
+
OseoContext *context,
|
|
1199
|
+
size_t code_id,
|
|
1200
|
+
OseoValue callee,
|
|
1201
|
+
OseoValue receiver,
|
|
1202
|
+
size_t argument_count,
|
|
1203
|
+
const OseoValue *arguments,
|
|
1204
|
+
OseoValue new_target
|
|
1205
|
+
) {
|
|
1206
|
+
if (code_id == OSEO_OBJECT_CONSTRUCTOR_CODE_ID) {
|
|
1207
|
+
return object_constructor(
|
|
1208
|
+
context,
|
|
1209
|
+
callee,
|
|
1210
|
+
argument_count,
|
|
1211
|
+
arguments,
|
|
1212
|
+
new_target
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
if (code_id == OSEO_OBJECT_PRIMITIVE_WRAPPER_METHOD_CODE_ID) {
|
|
1216
|
+
return failure(
|
|
1217
|
+
context,
|
|
1218
|
+
"OSEO2001",
|
|
1219
|
+
"Primitive wrapper prototype methods are not admitted yet."
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
if (tag_of(new_target) != OSEO_TAG_UNDEFINED) {
|
|
1223
|
+
return type_error(
|
|
1224
|
+
context,
|
|
1225
|
+
"Object static method is not a constructor."
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
if (code_id == OSEO_OBJECT_PROTO_GET_CODE_ID) {
|
|
1229
|
+
return object_prototype_get_proto(context, receiver);
|
|
1230
|
+
}
|
|
1231
|
+
if (code_id == OSEO_OBJECT_PROTO_SET_CODE_ID) {
|
|
1232
|
+
return object_prototype_set_proto(
|
|
1233
|
+
context, receiver, argument_count, arguments);
|
|
1234
|
+
}
|
|
1235
|
+
if (code_id == OSEO_OBJECT_DEFINE_GETTER_CODE_ID ||
|
|
1236
|
+
code_id == OSEO_OBJECT_DEFINE_SETTER_CODE_ID) {
|
|
1237
|
+
return object_prototype_define_accessor(
|
|
1238
|
+
context, receiver, argument_count, arguments,
|
|
1239
|
+
code_id == OSEO_OBJECT_DEFINE_SETTER_CODE_ID);
|
|
1240
|
+
}
|
|
1241
|
+
if (code_id == OSEO_OBJECT_LOOKUP_GETTER_CODE_ID ||
|
|
1242
|
+
code_id == OSEO_OBJECT_LOOKUP_SETTER_CODE_ID) {
|
|
1243
|
+
return object_prototype_lookup_accessor(
|
|
1244
|
+
context, receiver, argument_count, arguments,
|
|
1245
|
+
code_id == OSEO_OBJECT_LOOKUP_SETTER_CODE_ID);
|
|
1246
|
+
}
|
|
1247
|
+
if (code_id == OSEO_OBJECT_GET_PROTOTYPE_OF_CODE_ID) {
|
|
1248
|
+
return object_get_prototype_of(context, argument_count, arguments);
|
|
1249
|
+
}
|
|
1250
|
+
if (code_id == OSEO_OBJECT_IS_CODE_ID) {
|
|
1251
|
+
return object_is(argument_count, arguments);
|
|
1252
|
+
}
|
|
1253
|
+
if (code_id == OSEO_OBJECT_SET_PROTOTYPE_OF_CODE_ID) {
|
|
1254
|
+
return oseo_object_builtin_set_prototype_of(
|
|
1255
|
+
context,
|
|
1256
|
+
argument_count,
|
|
1257
|
+
arguments
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
if (code_id == OSEO_OBJECT_CREATE_CODE_ID) {
|
|
1261
|
+
return oseo_object_builtin_create(
|
|
1262
|
+
context,
|
|
1263
|
+
argument_count,
|
|
1264
|
+
arguments
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1267
|
+
if (code_id == OSEO_OBJECT_DEFINE_PROPERTY_CODE_ID) {
|
|
1268
|
+
return oseo_object_builtin_define_property(
|
|
1269
|
+
context,
|
|
1270
|
+
argument_count,
|
|
1271
|
+
arguments
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1274
|
+
if (code_id == OSEO_OBJECT_DEFINE_PROPERTIES_CODE_ID) {
|
|
1275
|
+
return object_define_properties(
|
|
1276
|
+
context,
|
|
1277
|
+
argument_count,
|
|
1278
|
+
arguments
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
if (code_id == OSEO_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_CODE_ID) {
|
|
1282
|
+
return oseo_object_builtin_get_own_property_descriptor(
|
|
1283
|
+
context,
|
|
1284
|
+
argument_count,
|
|
1285
|
+
arguments
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
if (code_id == OSEO_OBJECT_GET_OWN_PROPERTY_DESCRIPTORS_CODE_ID) {
|
|
1289
|
+
return object_get_own_property_descriptors(
|
|
1290
|
+
context,
|
|
1291
|
+
argument_count,
|
|
1292
|
+
arguments
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
if (code_id == OSEO_OBJECT_FREEZE_CODE_ID) {
|
|
1296
|
+
return object_integrity_transition(
|
|
1297
|
+
context, argument_count, arguments, true);
|
|
1298
|
+
}
|
|
1299
|
+
if (code_id == OSEO_OBJECT_IS_EXTENSIBLE_CODE_ID) {
|
|
1300
|
+
return object_is_extensible(context, argument_count, arguments);
|
|
1301
|
+
}
|
|
1302
|
+
if (code_id == OSEO_OBJECT_IS_FROZEN_CODE_ID) {
|
|
1303
|
+
return object_integrity_query(
|
|
1304
|
+
context, argument_count, arguments, true);
|
|
1305
|
+
}
|
|
1306
|
+
if (code_id == OSEO_OBJECT_IS_SEALED_CODE_ID) {
|
|
1307
|
+
return object_integrity_query(
|
|
1308
|
+
context, argument_count, arguments, false);
|
|
1309
|
+
}
|
|
1310
|
+
if (code_id == OSEO_OBJECT_PREVENT_EXTENSIONS_CODE_ID) {
|
|
1311
|
+
return object_prevent_extensions(context, argument_count, arguments);
|
|
1312
|
+
}
|
|
1313
|
+
if (code_id == OSEO_OBJECT_SEAL_CODE_ID) {
|
|
1314
|
+
return object_integrity_transition(
|
|
1315
|
+
context, argument_count, arguments, false);
|
|
1316
|
+
}
|
|
1317
|
+
if (code_id == OSEO_OBJECT_ASSIGN_CODE_ID) {
|
|
1318
|
+
return object_assign(context, argument_count, arguments);
|
|
1319
|
+
}
|
|
1320
|
+
if (code_id == OSEO_OBJECT_ENTRIES_CODE_ID) {
|
|
1321
|
+
return object_entries(context, argument_count, arguments);
|
|
1322
|
+
}
|
|
1323
|
+
if (code_id == OSEO_OBJECT_FROM_ENTRIES_CODE_ID) {
|
|
1324
|
+
return object_from_entries(context, argument_count, arguments);
|
|
1325
|
+
}
|
|
1326
|
+
if (code_id == OSEO_OBJECT_GET_OWN_PROPERTY_NAMES_CODE_ID) {
|
|
1327
|
+
return object_get_own_property_names(
|
|
1328
|
+
context, argument_count, arguments);
|
|
1329
|
+
}
|
|
1330
|
+
if (code_id == OSEO_OBJECT_GET_OWN_PROPERTY_SYMBOLS_CODE_ID) {
|
|
1331
|
+
return object_get_own_property_symbols(
|
|
1332
|
+
context, argument_count, arguments);
|
|
1333
|
+
}
|
|
1334
|
+
if (code_id == OSEO_OBJECT_GROUP_BY_CODE_ID) {
|
|
1335
|
+
return object_group_by(context, argument_count, arguments);
|
|
1336
|
+
}
|
|
1337
|
+
if (code_id == OSEO_OBJECT_HAS_OWN_CODE_ID) {
|
|
1338
|
+
return object_has_own(context, argument_count, arguments);
|
|
1339
|
+
}
|
|
1340
|
+
if (code_id == OSEO_OBJECT_KEYS_CODE_ID) {
|
|
1341
|
+
return oseo_object_builtin_keys(context, argument_count, arguments);
|
|
1342
|
+
}
|
|
1343
|
+
if (code_id == OSEO_OBJECT_VALUES_CODE_ID) {
|
|
1344
|
+
return object_values(context, argument_count, arguments);
|
|
1345
|
+
}
|
|
1346
|
+
if (code_id == OSEO_OBJECT_HAS_OWN_PROPERTY_CODE_ID) {
|
|
1347
|
+
return object_prototype_has_own_property(
|
|
1348
|
+
context,
|
|
1349
|
+
receiver,
|
|
1350
|
+
argument_count,
|
|
1351
|
+
arguments
|
|
1352
|
+
);
|
|
1353
|
+
}
|
|
1354
|
+
if (code_id == OSEO_OBJECT_IS_PROTOTYPE_OF_CODE_ID) {
|
|
1355
|
+
return object_prototype_is_prototype_of(
|
|
1356
|
+
context,
|
|
1357
|
+
receiver,
|
|
1358
|
+
argument_count,
|
|
1359
|
+
arguments
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
if (code_id == OSEO_OBJECT_PROPERTY_IS_ENUMERABLE_CODE_ID) {
|
|
1363
|
+
return object_prototype_property_is_enumerable(
|
|
1364
|
+
context,
|
|
1365
|
+
receiver,
|
|
1366
|
+
argument_count,
|
|
1367
|
+
arguments
|
|
1368
|
+
);
|
|
1369
|
+
}
|
|
1370
|
+
if (code_id == OSEO_OBJECT_TO_STRING_CODE_ID) {
|
|
1371
|
+
return object_prototype_to_string(context, receiver);
|
|
1372
|
+
}
|
|
1373
|
+
if (code_id == OSEO_OBJECT_TO_LOCALE_STRING_CODE_ID) {
|
|
1374
|
+
return object_prototype_to_locale_string(context, receiver);
|
|
1375
|
+
}
|
|
1376
|
+
if (code_id == OSEO_OBJECT_VALUE_OF_CODE_ID) {
|
|
1377
|
+
return object_prototype_value_of(context, receiver);
|
|
1378
|
+
}
|
|
1379
|
+
return oseo_unknown_function(context, code_id);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
static OseoResult create_object_prototype_function(
|
|
1383
|
+
OseoContext *context,
|
|
1384
|
+
size_t code_id,
|
|
1385
|
+
const char *name,
|
|
1386
|
+
size_t length
|
|
1387
|
+
) {
|
|
1388
|
+
size_t name_length = strlen(name);
|
|
1389
|
+
if (name_length > 31u) {
|
|
1390
|
+
return failure(context, "OSEO2001", "Built-in name is too long.");
|
|
1391
|
+
}
|
|
1392
|
+
uint16_t units[31];
|
|
1393
|
+
for (size_t index = 0u; index < name_length; index += 1u) {
|
|
1394
|
+
units[index] = (uint16_t)(unsigned char)name[index];
|
|
1395
|
+
}
|
|
1396
|
+
OseoValue environment = oseo_undefined();
|
|
1397
|
+
OseoRootFrame frame = {NULL, &environment, 1u};
|
|
1398
|
+
oseo_roots_push(context, &frame);
|
|
1399
|
+
OseoResult result = oseo_environment_create(context, 0u);
|
|
1400
|
+
environment = result.value;
|
|
1401
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1402
|
+
result = oseo_function_create(
|
|
1403
|
+
context,
|
|
1404
|
+
code_id,
|
|
1405
|
+
environment,
|
|
1406
|
+
units,
|
|
1407
|
+
name_length,
|
|
1408
|
+
length,
|
|
1409
|
+
OSEO_FUNCTION_INTERNAL,
|
|
1410
|
+
oseo_undefined(),
|
|
1411
|
+
oseo_undefined(),
|
|
1412
|
+
OSEO_FUNCTION_NAME_PREFIX_NONE
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
oseo_roots_pop(context, &frame);
|
|
1416
|
+
return result;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
static OseoResult object_prototype_function(
|
|
1420
|
+
OseoContext *context,
|
|
1421
|
+
OseoIntrinsic intrinsic,
|
|
1422
|
+
size_t code_id,
|
|
1423
|
+
const char *name,
|
|
1424
|
+
size_t length
|
|
1425
|
+
) {
|
|
1426
|
+
OseoValue *cache = &context->realm->intrinsics[intrinsic];
|
|
1427
|
+
if (is_function(*cache)) return normal(*cache);
|
|
1428
|
+
OseoResult result = create_object_prototype_function(
|
|
1429
|
+
context,
|
|
1430
|
+
code_id,
|
|
1431
|
+
name,
|
|
1432
|
+
length
|
|
1433
|
+
);
|
|
1434
|
+
if (result.status == OSEO_STATUS_NORMAL) *cache = result.value;
|
|
1435
|
+
return result;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
static OseoResult object_constructor_function(OseoContext *context) {
|
|
1439
|
+
static const uint16_t name[] = {'O', 'b', 'j', 'e', 'c', 't'};
|
|
1440
|
+
OseoValue environment = oseo_undefined();
|
|
1441
|
+
OseoRootFrame frame = {NULL, &environment, 1u};
|
|
1442
|
+
oseo_roots_push(context, &frame);
|
|
1443
|
+
OseoResult result = oseo_environment_create(context, 0u);
|
|
1444
|
+
environment = result.value;
|
|
1445
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1446
|
+
result = oseo_function_create(
|
|
1447
|
+
context,
|
|
1448
|
+
OSEO_OBJECT_CONSTRUCTOR_CODE_ID,
|
|
1449
|
+
environment,
|
|
1450
|
+
name,
|
|
1451
|
+
sizeof(name) / sizeof(*name),
|
|
1452
|
+
1u,
|
|
1453
|
+
OSEO_FUNCTION_ORDINARY,
|
|
1454
|
+
oseo_undefined(),
|
|
1455
|
+
oseo_undefined(),
|
|
1456
|
+
OSEO_FUNCTION_NAME_PREFIX_NONE
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
oseo_roots_pop(context, &frame);
|
|
1460
|
+
return result;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
OseoResult oseo_internal_object_prototype(OseoContext *context) {
|
|
1464
|
+
OseoValue prototype =
|
|
1465
|
+
context->realm->intrinsics[OSEO_INTRINSIC_OBJECT_PROTOTYPE];
|
|
1466
|
+
OseoValue *marker =
|
|
1467
|
+
&context->realm->intrinsics[OSEO_INTRINSIC_OBJECT_SET_PROTOTYPE_OF];
|
|
1468
|
+
if (is_function(*marker)) return normal(prototype);
|
|
1469
|
+
if (is_object(*marker)) return normal(prototype);
|
|
1470
|
+
if (!is_object(prototype)) {
|
|
1471
|
+
return failure(context, "OSEO2001", "Object prototype is unavailable.");
|
|
1472
|
+
}
|
|
1473
|
+
size_t entry_allocations = context->allocations;
|
|
1474
|
+
*marker = prototype;
|
|
1475
|
+
OseoResult result = object_constructor_function(context);
|
|
1476
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1477
|
+
context->realm->intrinsics[OSEO_INTRINSIC_OBJECT] = result.value;
|
|
1478
|
+
OseoFunction *constructor = function_object(result.value);
|
|
1479
|
+
constructor->prototype_object = prototype;
|
|
1480
|
+
constructor->prototype_writable = false;
|
|
1481
|
+
}
|
|
1482
|
+
static const OseoIntrinsic intrinsics[] = {
|
|
1483
|
+
OSEO_INTRINSIC_OBJECT_HAS_OWN_PROPERTY,
|
|
1484
|
+
OSEO_INTRINSIC_OBJECT_IS_PROTOTYPE_OF,
|
|
1485
|
+
OSEO_INTRINSIC_OBJECT_PROPERTY_IS_ENUMERABLE,
|
|
1486
|
+
OSEO_INTRINSIC_OBJECT_TO_LOCALE_STRING,
|
|
1487
|
+
OSEO_INTRINSIC_OBJECT_TO_STRING,
|
|
1488
|
+
};
|
|
1489
|
+
static const size_t codes[] = {
|
|
1490
|
+
OSEO_OBJECT_HAS_OWN_PROPERTY_CODE_ID,
|
|
1491
|
+
OSEO_OBJECT_IS_PROTOTYPE_OF_CODE_ID,
|
|
1492
|
+
OSEO_OBJECT_PROPERTY_IS_ENUMERABLE_CODE_ID,
|
|
1493
|
+
OSEO_OBJECT_TO_LOCALE_STRING_CODE_ID,
|
|
1494
|
+
OSEO_OBJECT_TO_STRING_CODE_ID,
|
|
1495
|
+
};
|
|
1496
|
+
static const char *const names[] = {
|
|
1497
|
+
"hasOwnProperty",
|
|
1498
|
+
"isPrototypeOf",
|
|
1499
|
+
"propertyIsEnumerable",
|
|
1500
|
+
"toLocaleString",
|
|
1501
|
+
"toString",
|
|
1502
|
+
};
|
|
1503
|
+
static const size_t lengths[] = {1u, 1u, 1u, 0u, 0u};
|
|
1504
|
+
for (size_t index = 0u;
|
|
1505
|
+
result.status == OSEO_STATUS_NORMAL &&
|
|
1506
|
+
index < sizeof(intrinsics) / sizeof(*intrinsics);
|
|
1507
|
+
index += 1u) {
|
|
1508
|
+
result = object_prototype_function(
|
|
1509
|
+
context,
|
|
1510
|
+
intrinsics[index],
|
|
1511
|
+
codes[index],
|
|
1512
|
+
names[index],
|
|
1513
|
+
lengths[index]
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1517
|
+
result = create_object_prototype_function(
|
|
1518
|
+
context,
|
|
1519
|
+
OSEO_OBJECT_VALUE_OF_CODE_ID,
|
|
1520
|
+
"valueOf",
|
|
1521
|
+
0u
|
|
1522
|
+
);
|
|
1523
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1524
|
+
context->realm->intrinsics[OSEO_INTRINSIC_OBJECT_VALUE_OF] =
|
|
1525
|
+
result.value;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
static const OseoIntrinsic properties[] = {
|
|
1529
|
+
OSEO_INTRINSIC_OBJECT,
|
|
1530
|
+
OSEO_INTRINSIC_OBJECT_HAS_OWN_PROPERTY,
|
|
1531
|
+
OSEO_INTRINSIC_OBJECT_IS_PROTOTYPE_OF,
|
|
1532
|
+
OSEO_INTRINSIC_OBJECT_PROPERTY_IS_ENUMERABLE,
|
|
1533
|
+
OSEO_INTRINSIC_OBJECT_TO_LOCALE_STRING,
|
|
1534
|
+
OSEO_INTRINSIC_OBJECT_TO_STRING,
|
|
1535
|
+
OSEO_INTRINSIC_OBJECT_VALUE_OF,
|
|
1536
|
+
};
|
|
1537
|
+
static const char *const property_names[] = {
|
|
1538
|
+
"constructor",
|
|
1539
|
+
"hasOwnProperty",
|
|
1540
|
+
"isPrototypeOf",
|
|
1541
|
+
"propertyIsEnumerable",
|
|
1542
|
+
"toLocaleString",
|
|
1543
|
+
"toString",
|
|
1544
|
+
"valueOf",
|
|
1545
|
+
};
|
|
1546
|
+
const OseoPropertyAttributes attributes = {true, false, true, false};
|
|
1547
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1548
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1549
|
+
result = oseo_roots_allocate(context, &frame, 4u);
|
|
1550
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1551
|
+
frame.slots[0] = prototype;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
for (size_t index = 0u;
|
|
1555
|
+
result.status == OSEO_STATUS_NORMAL &&
|
|
1556
|
+
index < sizeof(properties) / sizeof(*properties);
|
|
1557
|
+
index += 1u) {
|
|
1558
|
+
result = oseo_internal_ascii_string(context, property_names[index]);
|
|
1559
|
+
frame.slots[1] = result.value;
|
|
1560
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1561
|
+
result = oseo_object_define(
|
|
1562
|
+
context,
|
|
1563
|
+
frame.slots[0],
|
|
1564
|
+
frame.slots[1],
|
|
1565
|
+
context->realm->intrinsics[properties[index]],
|
|
1566
|
+
attributes
|
|
1567
|
+
);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
static const OseoIntrinsic static_intrinsics[] = {
|
|
1571
|
+
OSEO_INTRINSIC_OBJECT_GET_PROTOTYPE_OF,
|
|
1572
|
+
OSEO_INTRINSIC_OBJECT_IS,
|
|
1573
|
+
OSEO_INTRINSIC_OBJECT_SET_PROTOTYPE_OF,
|
|
1574
|
+
};
|
|
1575
|
+
static const size_t static_codes[] = {
|
|
1576
|
+
OSEO_OBJECT_GET_PROTOTYPE_OF_CODE_ID,
|
|
1577
|
+
OSEO_OBJECT_IS_CODE_ID,
|
|
1578
|
+
OSEO_OBJECT_SET_PROTOTYPE_OF_CODE_ID,
|
|
1579
|
+
};
|
|
1580
|
+
static const char *const static_names[] = {
|
|
1581
|
+
"getPrototypeOf",
|
|
1582
|
+
"is",
|
|
1583
|
+
"setPrototypeOf",
|
|
1584
|
+
};
|
|
1585
|
+
static const size_t static_lengths[] = {1u, 2u, 2u};
|
|
1586
|
+
for (size_t index = 0u;
|
|
1587
|
+
result.status == OSEO_STATUS_NORMAL && index < 3u;
|
|
1588
|
+
index += 1u) {
|
|
1589
|
+
result = object_prototype_function(
|
|
1590
|
+
context,
|
|
1591
|
+
static_intrinsics[index],
|
|
1592
|
+
static_codes[index],
|
|
1593
|
+
static_names[index],
|
|
1594
|
+
static_lengths[index]
|
|
1595
|
+
);
|
|
1596
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1597
|
+
result = oseo_internal_ascii_string(context, static_names[index]);
|
|
1598
|
+
frame.slots[1] = result.value;
|
|
1599
|
+
}
|
|
1600
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1601
|
+
result = oseo_object_define(
|
|
1602
|
+
context,
|
|
1603
|
+
context->realm->intrinsics[OSEO_INTRINSIC_OBJECT],
|
|
1604
|
+
frame.slots[1],
|
|
1605
|
+
context->realm->intrinsics[static_intrinsics[index]],
|
|
1606
|
+
attributes
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
static const size_t owned_static_codes[] = {
|
|
1611
|
+
OSEO_OBJECT_ASSIGN_CODE_ID,
|
|
1612
|
+
OSEO_OBJECT_CREATE_CODE_ID,
|
|
1613
|
+
OSEO_OBJECT_DEFINE_PROPERTIES_CODE_ID,
|
|
1614
|
+
OSEO_OBJECT_DEFINE_PROPERTY_CODE_ID,
|
|
1615
|
+
OSEO_OBJECT_ENTRIES_CODE_ID,
|
|
1616
|
+
OSEO_OBJECT_FREEZE_CODE_ID,
|
|
1617
|
+
OSEO_OBJECT_FROM_ENTRIES_CODE_ID,
|
|
1618
|
+
OSEO_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_CODE_ID,
|
|
1619
|
+
OSEO_OBJECT_GET_OWN_PROPERTY_DESCRIPTORS_CODE_ID,
|
|
1620
|
+
OSEO_OBJECT_GET_OWN_PROPERTY_NAMES_CODE_ID,
|
|
1621
|
+
OSEO_OBJECT_GET_OWN_PROPERTY_SYMBOLS_CODE_ID,
|
|
1622
|
+
OSEO_OBJECT_GROUP_BY_CODE_ID,
|
|
1623
|
+
OSEO_OBJECT_HAS_OWN_CODE_ID,
|
|
1624
|
+
OSEO_OBJECT_IS_EXTENSIBLE_CODE_ID,
|
|
1625
|
+
OSEO_OBJECT_IS_FROZEN_CODE_ID,
|
|
1626
|
+
OSEO_OBJECT_IS_SEALED_CODE_ID,
|
|
1627
|
+
OSEO_OBJECT_KEYS_CODE_ID,
|
|
1628
|
+
OSEO_OBJECT_PREVENT_EXTENSIONS_CODE_ID,
|
|
1629
|
+
OSEO_OBJECT_SEAL_CODE_ID,
|
|
1630
|
+
OSEO_OBJECT_VALUES_CODE_ID,
|
|
1631
|
+
};
|
|
1632
|
+
static const char *const owned_static_names[] = {
|
|
1633
|
+
"assign",
|
|
1634
|
+
"create",
|
|
1635
|
+
"defineProperties",
|
|
1636
|
+
"defineProperty",
|
|
1637
|
+
"entries",
|
|
1638
|
+
"freeze",
|
|
1639
|
+
"fromEntries",
|
|
1640
|
+
"getOwnPropertyDescriptor",
|
|
1641
|
+
"getOwnPropertyDescriptors",
|
|
1642
|
+
"getOwnPropertyNames",
|
|
1643
|
+
"getOwnPropertySymbols",
|
|
1644
|
+
"groupBy",
|
|
1645
|
+
"hasOwn",
|
|
1646
|
+
"isExtensible",
|
|
1647
|
+
"isFrozen",
|
|
1648
|
+
"isSealed",
|
|
1649
|
+
"keys",
|
|
1650
|
+
"preventExtensions",
|
|
1651
|
+
"seal",
|
|
1652
|
+
"values",
|
|
1653
|
+
};
|
|
1654
|
+
static const size_t owned_static_lengths[] = {
|
|
1655
|
+
2u, 2u, 2u, 3u, 1u, 1u, 1u, 2u, 1u, 1u, 1u, 2u, 2u,
|
|
1656
|
+
1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
|
1657
|
+
};
|
|
1658
|
+
for (size_t index = 0u;
|
|
1659
|
+
result.status == OSEO_STATUS_NORMAL &&
|
|
1660
|
+
index < sizeof(owned_static_codes) / sizeof(*owned_static_codes);
|
|
1661
|
+
index += 1u) {
|
|
1662
|
+
result = create_object_prototype_function(
|
|
1663
|
+
context,
|
|
1664
|
+
owned_static_codes[index],
|
|
1665
|
+
owned_static_names[index],
|
|
1666
|
+
owned_static_lengths[index]
|
|
1667
|
+
);
|
|
1668
|
+
frame.slots[2] = result.value;
|
|
1669
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1670
|
+
result = oseo_internal_ascii_string(
|
|
1671
|
+
context,
|
|
1672
|
+
owned_static_names[index]
|
|
1673
|
+
);
|
|
1674
|
+
frame.slots[1] = result.value;
|
|
1675
|
+
}
|
|
1676
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1677
|
+
result = oseo_object_define(
|
|
1678
|
+
context,
|
|
1679
|
+
context->realm->intrinsics[OSEO_INTRINSIC_OBJECT],
|
|
1680
|
+
frame.slots[1],
|
|
1681
|
+
frame.slots[2],
|
|
1682
|
+
attributes
|
|
1683
|
+
);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
/* The Annex B accessor and methods of 20.1.3.8 through 20.1.3.12
|
|
1687
|
+
* follow the seven core properties in that clause order. */
|
|
1688
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1689
|
+
result = create_object_prototype_function(context,
|
|
1690
|
+
OSEO_OBJECT_PROTO_GET_CODE_ID, "get __proto__", 0u);
|
|
1691
|
+
frame.slots[2] = result.value;
|
|
1692
|
+
}
|
|
1693
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1694
|
+
result = create_object_prototype_function(context,
|
|
1695
|
+
OSEO_OBJECT_PROTO_SET_CODE_ID, "set __proto__", 1u);
|
|
1696
|
+
frame.slots[3] = result.value;
|
|
1697
|
+
}
|
|
1698
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1699
|
+
result = oseo_internal_ascii_string(context, "__proto__");
|
|
1700
|
+
frame.slots[1] = result.value;
|
|
1701
|
+
}
|
|
1702
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1703
|
+
result = oseo_object_define_accessor(context, frame.slots[0],
|
|
1704
|
+
frame.slots[1], frame.slots[2], frame.slots[3], true, true,
|
|
1705
|
+
(OseoPropertyAttributes){true, false, false, true});
|
|
1706
|
+
}
|
|
1707
|
+
static const size_t legacy_codes[] = {
|
|
1708
|
+
OSEO_OBJECT_DEFINE_GETTER_CODE_ID,
|
|
1709
|
+
OSEO_OBJECT_DEFINE_SETTER_CODE_ID,
|
|
1710
|
+
OSEO_OBJECT_LOOKUP_GETTER_CODE_ID,
|
|
1711
|
+
OSEO_OBJECT_LOOKUP_SETTER_CODE_ID,
|
|
1712
|
+
};
|
|
1713
|
+
static const char *const legacy_names[] = {
|
|
1714
|
+
"__defineGetter__",
|
|
1715
|
+
"__defineSetter__",
|
|
1716
|
+
"__lookupGetter__",
|
|
1717
|
+
"__lookupSetter__",
|
|
1718
|
+
};
|
|
1719
|
+
static const size_t legacy_lengths[] = {2u, 2u, 1u, 1u};
|
|
1720
|
+
for (size_t index = 0u;
|
|
1721
|
+
result.status == OSEO_STATUS_NORMAL &&
|
|
1722
|
+
index < sizeof(legacy_codes) / sizeof(*legacy_codes);
|
|
1723
|
+
index += 1u) {
|
|
1724
|
+
result = create_object_prototype_function(context,
|
|
1725
|
+
legacy_codes[index], legacy_names[index], legacy_lengths[index]);
|
|
1726
|
+
frame.slots[2] = result.value;
|
|
1727
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1728
|
+
result = oseo_internal_ascii_string(context, legacy_names[index]);
|
|
1729
|
+
frame.slots[1] = result.value;
|
|
1730
|
+
}
|
|
1731
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1732
|
+
result = oseo_object_define(context, frame.slots[0],
|
|
1733
|
+
frame.slots[1], frame.slots[2], attributes);
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
if (frame.slots != NULL) oseo_roots_release(context, &frame);
|
|
1737
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
1738
|
+
*marker = oseo_undefined();
|
|
1739
|
+
context->realm->intrinsics[OSEO_INTRINSIC_OBJECT] = oseo_undefined();
|
|
1740
|
+
return result;
|
|
1741
|
+
}
|
|
1742
|
+
if (context->observe_specialization) {
|
|
1743
|
+
context->allocations = entry_allocations;
|
|
1744
|
+
}
|
|
1745
|
+
return normal(prototype);
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
OseoResult oseo_internal_install_object_global(
|
|
1749
|
+
OseoContext *context,
|
|
1750
|
+
OseoValue global
|
|
1751
|
+
) {
|
|
1752
|
+
OseoValue slots[3] = {global, oseo_undefined(), oseo_undefined()};
|
|
1753
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
1754
|
+
oseo_roots_push(context, &frame);
|
|
1755
|
+
OseoResult result = oseo_internal_intrinsic(context, OSEO_INTRINSIC_OBJECT);
|
|
1756
|
+
slots[1] = result.value;
|
|
1757
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1758
|
+
result = oseo_internal_ascii_string(context, "Object");
|
|
1759
|
+
slots[2] = result.value;
|
|
1760
|
+
}
|
|
1761
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1762
|
+
result = oseo_object_define(
|
|
1763
|
+
context,
|
|
1764
|
+
slots[0],
|
|
1765
|
+
slots[2],
|
|
1766
|
+
slots[1],
|
|
1767
|
+
(OseoPropertyAttributes){true, false, true, false}
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
oseo_roots_pop(context, &frame);
|
|
1771
|
+
return result.status == OSEO_STATUS_NORMAL ? normal(slots[0]) : result;
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
/* Mirrors HasProperty followed by Get for one ToPropertyDescriptor field:
|
|
1775
|
+
* an accessor field on the descriptor argument must be invoked with the
|
|
1776
|
+
* original descriptor object as the receiver, and a thrown exception must
|
|
1777
|
+
* propagate instead of being read as a raw stored value. */
|
|
1778
|
+
static OseoResult descriptor_field(
|
|
1779
|
+
OseoContext *context,
|
|
1780
|
+
OseoValue descriptor_value,
|
|
1781
|
+
const char *name,
|
|
1782
|
+
bool *has_field,
|
|
1783
|
+
OseoValue *value
|
|
1784
|
+
) {
|
|
1785
|
+
*has_field = false;
|
|
1786
|
+
*value = oseo_undefined();
|
|
1787
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1788
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 2u);
|
|
1789
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
1790
|
+
frame.slots[0] = descriptor_value;
|
|
1791
|
+
result = oseo_internal_ascii_string(context, name);
|
|
1792
|
+
frame.slots[1] = result.value;
|
|
1793
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1794
|
+
result = oseo_has_property(
|
|
1795
|
+
context,
|
|
1796
|
+
frame.slots[1],
|
|
1797
|
+
frame.slots[0]
|
|
1798
|
+
);
|
|
1799
|
+
*has_field = result.status == OSEO_STATUS_NORMAL &&
|
|
1800
|
+
oseo_to_boolean(result.value);
|
|
1801
|
+
}
|
|
1802
|
+
if (result.status == OSEO_STATUS_NORMAL && *has_field) {
|
|
1803
|
+
result = oseo_object_get(
|
|
1804
|
+
context,
|
|
1805
|
+
frame.slots[0],
|
|
1806
|
+
frame.slots[1]
|
|
1807
|
+
);
|
|
1808
|
+
*value = result.value;
|
|
1809
|
+
}
|
|
1810
|
+
oseo_roots_release(context, &frame);
|
|
1811
|
+
return result.status == OSEO_STATUS_NORMAL ? normal(*value) : result;
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
static bool rest_key_is_excluded(
|
|
1815
|
+
OseoValue key,
|
|
1816
|
+
size_t excluded_count,
|
|
1817
|
+
const OseoValue *excluded_keys
|
|
1818
|
+
) {
|
|
1819
|
+
for (size_t index = 0u; index < excluded_count; index += 1u) {
|
|
1820
|
+
if (oseo_internal_property_key_equal(key, excluded_keys[index])) {
|
|
1821
|
+
return true;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return false;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
/* Materialize a Proxy [[OwnPropertyKeys]] result in the frame shape used
|
|
1828
|
+
* by the ordinary own-key consumers below. */
|
|
1829
|
+
static OseoResult proxy_own_key_frame(
|
|
1830
|
+
OseoContext *context,
|
|
1831
|
+
OseoValue proxy,
|
|
1832
|
+
OseoRootFrame *frame,
|
|
1833
|
+
size_t *key_count
|
|
1834
|
+
) {
|
|
1835
|
+
OseoValue slots[3] = {
|
|
1836
|
+
proxy, oseo_undefined(), oseo_undefined(),
|
|
1837
|
+
};
|
|
1838
|
+
OseoRootFrame temporary = {NULL, slots, 3u};
|
|
1839
|
+
oseo_roots_push(context, &temporary);
|
|
1840
|
+
OseoResult result = oseo_internal_proxy_own_keys(
|
|
1841
|
+
context, slots[0], OSEO_OWN_KEY_ALL);
|
|
1842
|
+
slots[1] = result.value;
|
|
1843
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1844
|
+
result = oseo_internal_array_like_list(
|
|
1845
|
+
context, slots[1], &slots[2]);
|
|
1846
|
+
}
|
|
1847
|
+
const OseoValue *keys = NULL;
|
|
1848
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1849
|
+
result = oseo_argument_list_view(
|
|
1850
|
+
context, slots[2], key_count, &keys);
|
|
1851
|
+
}
|
|
1852
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
1853
|
+
*key_count > SIZE_MAX - 3u) {
|
|
1854
|
+
result = failure(
|
|
1855
|
+
context, "OSEO2001", "Own-key snapshot is too large.");
|
|
1856
|
+
}
|
|
1857
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1858
|
+
result = oseo_roots_allocate(context, frame, *key_count + 3u);
|
|
1859
|
+
}
|
|
1860
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1861
|
+
frame->slots[0] = slots[0];
|
|
1862
|
+
for (size_t index = 0u; index < *key_count; index += 1u) {
|
|
1863
|
+
frame->slots[3u + index] = keys[index];
|
|
1864
|
+
}
|
|
1865
|
+
/* The dynamic frame was pushed above the temporary roots. The
|
|
1866
|
+
* copied key values let it replace those roots in the chain. */
|
|
1867
|
+
frame->previous = temporary.previous;
|
|
1868
|
+
temporary.previous = NULL;
|
|
1869
|
+
} else {
|
|
1870
|
+
oseo_roots_pop(context, &temporary);
|
|
1871
|
+
}
|
|
1872
|
+
return result;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
/*
|
|
1876
|
+
* The own-key order CopyDataProperties walks. Of the own properties that
|
|
1877
|
+
* live outside the property vector, only the virtual
|
|
1878
|
+
* %String.prototype%[@@iterator] can become enumerable, so this snapshot
|
|
1879
|
+
* places it; an array's `length` and a
|
|
1880
|
+
* function's `prototype` are permanently non-enumerable and the copy
|
|
1881
|
+
* would skip them anyway. A TypedArray's valid integer indices lead its
|
|
1882
|
+
* keys, as they do in the ordinary snapshot. A module namespace keeps
|
|
1883
|
+
* its export names in [[Exports]] order, integer-like names included,
|
|
1884
|
+
* as it does in that snapshot.
|
|
1885
|
+
*/
|
|
1886
|
+
static OseoResult snapshot_rest_keys(
|
|
1887
|
+
OseoContext *context,
|
|
1888
|
+
OseoRootFrame *frame,
|
|
1889
|
+
size_t key_count
|
|
1890
|
+
) {
|
|
1891
|
+
OseoValue source = frame->slots[0];
|
|
1892
|
+
size_t output = 0u;
|
|
1893
|
+
if (is_string(source)) {
|
|
1894
|
+
for (size_t index = 0u; index < key_count; index += 1u) {
|
|
1895
|
+
char key_text[24];
|
|
1896
|
+
(void)snprintf(key_text, sizeof(key_text), "%zu", index);
|
|
1897
|
+
OseoResult key = oseo_internal_ascii_string(context, key_text);
|
|
1898
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
1899
|
+
frame->slots[3u + output] = key.value;
|
|
1900
|
+
output += 1u;
|
|
1901
|
+
}
|
|
1902
|
+
return normal(oseo_undefined());
|
|
1903
|
+
}
|
|
1904
|
+
if (!is_object(source)) return normal(oseo_undefined());
|
|
1905
|
+
size_t index_count = oseo_internal_typed_array_index_key_count(source);
|
|
1906
|
+
for (; output < index_count && output < key_count; output += 1u) {
|
|
1907
|
+
OseoResult key = oseo_internal_typed_array_index_key(context, output);
|
|
1908
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
1909
|
+
frame->slots[3u + output] = key.value;
|
|
1910
|
+
}
|
|
1911
|
+
bool index_keys_lead = !ordinary_object(source)->module_namespace;
|
|
1912
|
+
uint64_t previous = UINT64_MAX;
|
|
1913
|
+
while (index_keys_lead && output < key_count) {
|
|
1914
|
+
OseoOrdinaryObject *object = ordinary_object(frame->slots[0]);
|
|
1915
|
+
size_t selected = SIZE_MAX;
|
|
1916
|
+
uint32_t selected_number = 0u;
|
|
1917
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
1918
|
+
uint32_t number = 0u;
|
|
1919
|
+
if (!oseo_internal_array_index(
|
|
1920
|
+
object->properties[index].key, &number) ||
|
|
1921
|
+
(previous != UINT64_MAX && number <= previous)) continue;
|
|
1922
|
+
if (selected == SIZE_MAX || number < selected_number) {
|
|
1923
|
+
selected = index;
|
|
1924
|
+
selected_number = number;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
if (selected == SIZE_MAX) break;
|
|
1928
|
+
frame->slots[3u + output] = object->properties[selected].key;
|
|
1929
|
+
output += 1u;
|
|
1930
|
+
previous = selected_number;
|
|
1931
|
+
}
|
|
1932
|
+
OseoOrdinaryObject *object = ordinary_object(frame->slots[0]);
|
|
1933
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
1934
|
+
uint32_t ignored = 0u;
|
|
1935
|
+
OseoValue key = object->properties[index].key;
|
|
1936
|
+
if (is_symbol(key) ||
|
|
1937
|
+
(index_keys_lead &&
|
|
1938
|
+
oseo_internal_array_index(key, &ignored))) continue;
|
|
1939
|
+
frame->slots[3u + output] = key;
|
|
1940
|
+
output += 1u;
|
|
1941
|
+
}
|
|
1942
|
+
if (ordinary_object(frame->slots[0])->virtual_string_iterator) {
|
|
1943
|
+
/* The untouched String iterator leads every symbol a program can
|
|
1944
|
+
* add, exactly as it does in the ordinary own-key snapshot. */
|
|
1945
|
+
OseoResult key = oseo_internal_well_known_symbol(
|
|
1946
|
+
context,
|
|
1947
|
+
OSEO_WELL_KNOWN_ITERATOR
|
|
1948
|
+
);
|
|
1949
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
1950
|
+
frame->slots[3u + output] = key.value;
|
|
1951
|
+
output += 1u;
|
|
1952
|
+
}
|
|
1953
|
+
/* The virtual-key lookup above may allocate, so reacquire the object
|
|
1954
|
+
* before reading its property vector. */
|
|
1955
|
+
object = ordinary_object(frame->slots[0]);
|
|
1956
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
1957
|
+
OseoValue key = object->properties[index].key;
|
|
1958
|
+
if (!is_symbol(key)) continue;
|
|
1959
|
+
frame->slots[3u + output] = key;
|
|
1960
|
+
output += 1u;
|
|
1961
|
+
}
|
|
1962
|
+
if (output != key_count) {
|
|
1963
|
+
return failure(context, "OSEO2001", "Own-key snapshot changed.");
|
|
1964
|
+
}
|
|
1965
|
+
return normal(oseo_undefined());
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
/**
|
|
1969
|
+
* CopyDataProperties: adds every own enumerable property of `source` that is
|
|
1970
|
+
* not an excluded key to `target` as a writable, enumerable, configurable
|
|
1971
|
+
* data property, in own-key order. `source` must not be nullish; the two
|
|
1972
|
+
* callers apply the nullish rule their own syntax requires. The result value
|
|
1973
|
+
* is `target` so a caller can return it directly.
|
|
1974
|
+
*/
|
|
1975
|
+
static OseoResult copy_data_properties(
|
|
1976
|
+
OseoContext *context,
|
|
1977
|
+
OseoValue target,
|
|
1978
|
+
OseoValue source,
|
|
1979
|
+
size_t excluded_count,
|
|
1980
|
+
const OseoValue *excluded_keys
|
|
1981
|
+
) {
|
|
1982
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1983
|
+
size_t key_count = 0u;
|
|
1984
|
+
OseoResult result = normal(oseo_undefined());
|
|
1985
|
+
if (is_proxy(source)) {
|
|
1986
|
+
result = proxy_own_key_frame(context, source, &frame, &key_count);
|
|
1987
|
+
} else {
|
|
1988
|
+
key_count = is_string(source)
|
|
1989
|
+
? string_object(source)->length
|
|
1990
|
+
: is_object(source)
|
|
1991
|
+
? ordinary_object(source)->property_count +
|
|
1992
|
+
(ordinary_object(source)->virtual_string_iterator
|
|
1993
|
+
? 1u
|
|
1994
|
+
: 0u) +
|
|
1995
|
+
oseo_internal_typed_array_index_key_count(source)
|
|
1996
|
+
: 0u;
|
|
1997
|
+
if (key_count > SIZE_MAX - 3u) {
|
|
1998
|
+
return failure(
|
|
1999
|
+
context, "OSEO2001", "Own-key snapshot is too large.");
|
|
2000
|
+
}
|
|
2001
|
+
result = oseo_roots_allocate(context, &frame, key_count + 3u);
|
|
2002
|
+
}
|
|
2003
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2004
|
+
frame.slots[0] = source;
|
|
2005
|
+
frame.slots[1] = target;
|
|
2006
|
+
if (!is_proxy(frame.slots[0])) {
|
|
2007
|
+
result = snapshot_rest_keys(context, &frame, key_count);
|
|
2008
|
+
}
|
|
2009
|
+
for (size_t index = 0u;
|
|
2010
|
+
result.status == OSEO_STATUS_NORMAL && index < key_count;
|
|
2011
|
+
index += 1u) {
|
|
2012
|
+
OseoValue key = frame.slots[3u + index];
|
|
2013
|
+
if (rest_key_is_excluded(key, excluded_count, excluded_keys)) {
|
|
2014
|
+
continue;
|
|
2015
|
+
}
|
|
2016
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
2017
|
+
OseoValue ignored = oseo_undefined();
|
|
2018
|
+
OseoValue ignored_getter = oseo_undefined();
|
|
2019
|
+
OseoValue ignored_setter = oseo_undefined();
|
|
2020
|
+
bool exists = false;
|
|
2021
|
+
if (is_string(frame.slots[0])) {
|
|
2022
|
+
exists = oseo_internal_string_own_property(
|
|
2023
|
+
frame.slots[0], key, NULL);
|
|
2024
|
+
} else if (is_proxy(frame.slots[0])) {
|
|
2025
|
+
result = oseo_internal_proxy_get_own_property(
|
|
2026
|
+
context,
|
|
2027
|
+
frame.slots[0],
|
|
2028
|
+
key,
|
|
2029
|
+
&exists,
|
|
2030
|
+
&ignored,
|
|
2031
|
+
&attributes,
|
|
2032
|
+
&ignored_getter,
|
|
2033
|
+
&ignored_setter
|
|
2034
|
+
);
|
|
2035
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
2036
|
+
} else {
|
|
2037
|
+
result = own_property_query(
|
|
2038
|
+
context,
|
|
2039
|
+
frame.slots[0],
|
|
2040
|
+
key,
|
|
2041
|
+
&exists,
|
|
2042
|
+
&ignored,
|
|
2043
|
+
&attributes,
|
|
2044
|
+
&ignored_getter,
|
|
2045
|
+
&ignored_setter
|
|
2046
|
+
);
|
|
2047
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
2048
|
+
}
|
|
2049
|
+
bool enumerable = is_string(frame.slots[0])
|
|
2050
|
+
? exists && !oseo_internal_string_is_ascii(key, "length")
|
|
2051
|
+
: exists && attributes.enumerable;
|
|
2052
|
+
if (!enumerable) continue;
|
|
2053
|
+
result = oseo_object_get(context, frame.slots[0], key);
|
|
2054
|
+
frame.slots[2] = result.value;
|
|
2055
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2056
|
+
result = oseo_object_define(
|
|
2057
|
+
context,
|
|
2058
|
+
frame.slots[1],
|
|
2059
|
+
key,
|
|
2060
|
+
frame.slots[2],
|
|
2061
|
+
(OseoPropertyAttributes){true, true, true, false}
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[1];
|
|
2066
|
+
oseo_roots_release(context, &frame);
|
|
2067
|
+
return result;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
OseoResult oseo_object_rest(
|
|
2071
|
+
OseoContext *context,
|
|
2072
|
+
OseoValue source,
|
|
2073
|
+
size_t excluded_count,
|
|
2074
|
+
const OseoValue *excluded_keys
|
|
2075
|
+
) {
|
|
2076
|
+
if (is_nullish(source)) {
|
|
2077
|
+
return type_error(context, "Cannot destructure a nullish value.");
|
|
2078
|
+
}
|
|
2079
|
+
/* Slot 1 keeps the fresh target alive while Proxy traps can collect. */
|
|
2080
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
2081
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 2u);
|
|
2082
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2083
|
+
frame.slots[0] = source;
|
|
2084
|
+
result = oseo_object_literal_create(context);
|
|
2085
|
+
frame.slots[1] = result.value;
|
|
2086
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2087
|
+
result = copy_data_properties(
|
|
2088
|
+
context,
|
|
2089
|
+
frame.slots[1],
|
|
2090
|
+
frame.slots[0],
|
|
2091
|
+
excluded_count,
|
|
2092
|
+
excluded_keys
|
|
2093
|
+
);
|
|
2094
|
+
}
|
|
2095
|
+
oseo_roots_release(context, &frame);
|
|
2096
|
+
return result;
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
OseoResult oseo_object_spread(
|
|
2100
|
+
OseoContext *context,
|
|
2101
|
+
OseoValue target,
|
|
2102
|
+
OseoValue source
|
|
2103
|
+
) {
|
|
2104
|
+
/* An object literal spread of null or undefined copies nothing rather
|
|
2105
|
+
* than throwing, unlike an object binding rest. */
|
|
2106
|
+
if (is_nullish(source)) return normal(target);
|
|
2107
|
+
return copy_data_properties(context, target, source, 0u, NULL);
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
static OseoResult define_ascii_value(
|
|
2111
|
+
OseoContext *context,
|
|
2112
|
+
OseoRootFrame *frame,
|
|
2113
|
+
const char *name,
|
|
2114
|
+
OseoValue value
|
|
2115
|
+
) {
|
|
2116
|
+
OseoResult result = oseo_internal_ascii_string(context, name);
|
|
2117
|
+
frame->slots[1] = result.value;
|
|
2118
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2119
|
+
return oseo_object_define(
|
|
2120
|
+
context,
|
|
2121
|
+
frame->slots[0],
|
|
2122
|
+
frame->slots[1],
|
|
2123
|
+
value,
|
|
2124
|
+
(OseoPropertyAttributes){true, true, true, false}
|
|
2125
|
+
);
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
/*
|
|
2129
|
+
* Object.create (20.1.2.2). The prototype check precedes every read of
|
|
2130
|
+
* the properties argument, so a non-object non-null prototype throws
|
|
2131
|
+
* before a poisoned properties getter can run. An undefined properties
|
|
2132
|
+
* argument returns the fresh object directly; any other value flows
|
|
2133
|
+
* through the ObjectDefineProperties body `Object.defineProperties`
|
|
2134
|
+
* owns, so descriptor collection, ordering, and abrupt completions
|
|
2135
|
+
* behave identically over the freshly created target.
|
|
2136
|
+
*/
|
|
2137
|
+
OseoResult oseo_object_builtin_create(
|
|
2138
|
+
OseoContext *context,
|
|
2139
|
+
size_t argument_count,
|
|
2140
|
+
const OseoValue *arguments
|
|
2141
|
+
) {
|
|
2142
|
+
OseoValue prototype = builtin_argument(argument_count, arguments, 0u);
|
|
2143
|
+
if (tag_of(prototype) != OSEO_TAG_NULL && !is_object(prototype)) {
|
|
2144
|
+
return type_error(
|
|
2145
|
+
context,
|
|
2146
|
+
"Object.create requires an object or null prototype."
|
|
2147
|
+
);
|
|
2148
|
+
}
|
|
2149
|
+
OseoValue properties = builtin_argument(argument_count, arguments, 1u);
|
|
2150
|
+
if (tag_of(properties) == OSEO_TAG_UNDEFINED) {
|
|
2151
|
+
return oseo_object_create(context, prototype);
|
|
2152
|
+
}
|
|
2153
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
2154
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 2u);
|
|
2155
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2156
|
+
frame.slots[0] = properties;
|
|
2157
|
+
result = oseo_object_create(context, prototype);
|
|
2158
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2159
|
+
frame.slots[1] = result.value;
|
|
2160
|
+
const OseoValue define_arguments[2] = {
|
|
2161
|
+
frame.slots[1],
|
|
2162
|
+
frame.slots[0],
|
|
2163
|
+
};
|
|
2164
|
+
result = object_define_properties(context, 2u, define_arguments);
|
|
2165
|
+
}
|
|
2166
|
+
oseo_roots_release(context, &frame);
|
|
2167
|
+
return result;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
/*
|
|
2171
|
+
* The presence flags and converted attribute fields of one
|
|
2172
|
+
* ToPropertyDescriptor result. The `value`, `get`, and `set` fields are
|
|
2173
|
+
* heap values, so they stay in caller-rooted slots rather than in this
|
|
2174
|
+
* record; ToBoolean runs no user code, so the three attribute fields
|
|
2175
|
+
* hold their converted results directly.
|
|
2176
|
+
*/
|
|
2177
|
+
/*
|
|
2178
|
+
* ToPropertyDescriptor (6.2.6.5) over a descriptor object the caller has
|
|
2179
|
+
* already checked and rooted. The fields are read in ECMA-262's fixed
|
|
2180
|
+
* order: enumerable, configurable, value, writable, get, set. Every heap
|
|
2181
|
+
* field is stored into its caller-rooted slot as soon as it is read,
|
|
2182
|
+
* because reading a later field can invoke a descriptor accessor that
|
|
2183
|
+
* allocates and collects; an unrooted C local holding an earlier field's
|
|
2184
|
+
* freshly returned heap value would not survive that collection. An
|
|
2185
|
+
* accessor field that is neither undefined nor callable and a
|
|
2186
|
+
* descriptor mixing accessor and data fields throw the specified
|
|
2187
|
+
* TypeError.
|
|
2188
|
+
*/
|
|
2189
|
+
OseoResult oseo_internal_to_property_descriptor(
|
|
2190
|
+
OseoContext *context,
|
|
2191
|
+
OseoValue descriptor_value,
|
|
2192
|
+
OseoValue *value_slot,
|
|
2193
|
+
OseoValue *getter_slot,
|
|
2194
|
+
OseoValue *setter_slot,
|
|
2195
|
+
OseoConvertedDescriptor *descriptor
|
|
2196
|
+
) {
|
|
2197
|
+
OseoValue attribute = oseo_undefined();
|
|
2198
|
+
OseoResult result = descriptor_field(
|
|
2199
|
+
context, descriptor_value, "enumerable",
|
|
2200
|
+
&descriptor->has_enumerable, &attribute);
|
|
2201
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2202
|
+
descriptor->enumerable =
|
|
2203
|
+
descriptor->has_enumerable && oseo_to_boolean(attribute);
|
|
2204
|
+
result = descriptor_field(
|
|
2205
|
+
context, descriptor_value, "configurable",
|
|
2206
|
+
&descriptor->has_configurable, &attribute);
|
|
2207
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2208
|
+
descriptor->configurable =
|
|
2209
|
+
descriptor->has_configurable && oseo_to_boolean(attribute);
|
|
2210
|
+
result = descriptor_field(
|
|
2211
|
+
context, descriptor_value, "value",
|
|
2212
|
+
&descriptor->has_value, value_slot);
|
|
2213
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2214
|
+
result = descriptor_field(
|
|
2215
|
+
context, descriptor_value, "writable",
|
|
2216
|
+
&descriptor->has_writable, &attribute);
|
|
2217
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2218
|
+
descriptor->writable =
|
|
2219
|
+
descriptor->has_writable && oseo_to_boolean(attribute);
|
|
2220
|
+
result = descriptor_field(
|
|
2221
|
+
context, descriptor_value, "get",
|
|
2222
|
+
&descriptor->has_getter, getter_slot);
|
|
2223
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2224
|
+
if (descriptor->has_getter &&
|
|
2225
|
+
tag_of(*getter_slot) != OSEO_TAG_UNDEFINED &&
|
|
2226
|
+
!is_callable(*getter_slot)) {
|
|
2227
|
+
return type_error(context, "A property descriptor 'get' field must "
|
|
2228
|
+
"be undefined or callable.");
|
|
2229
|
+
}
|
|
2230
|
+
result = descriptor_field(
|
|
2231
|
+
context, descriptor_value, "set",
|
|
2232
|
+
&descriptor->has_setter, setter_slot);
|
|
2233
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2234
|
+
if (descriptor->has_setter &&
|
|
2235
|
+
tag_of(*setter_slot) != OSEO_TAG_UNDEFINED &&
|
|
2236
|
+
!is_callable(*setter_slot)) {
|
|
2237
|
+
return type_error(context, "A property descriptor 'set' field must "
|
|
2238
|
+
"be undefined or callable.");
|
|
2239
|
+
}
|
|
2240
|
+
if ((descriptor->has_getter || descriptor->has_setter) &&
|
|
2241
|
+
(descriptor->has_value || descriptor->has_writable)) {
|
|
2242
|
+
return type_error(
|
|
2243
|
+
context,
|
|
2244
|
+
"A property descriptor cannot mix accessor and data fields."
|
|
2245
|
+
);
|
|
2246
|
+
}
|
|
2247
|
+
return normal(oseo_undefined());
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
/*
|
|
2251
|
+
* DefinePropertyOrThrow (7.3.8) over one converted descriptor. The
|
|
2252
|
+
* caller roots the target, the key, and the three heap descriptor
|
|
2253
|
+
* fields. The current property state supplies every absent field, a
|
|
2254
|
+
* cell-backed current value reads through its binding cell, and the
|
|
2255
|
+
* descriptor component stays authoritative for compatibility and
|
|
2256
|
+
* mutation.
|
|
2257
|
+
*/
|
|
2258
|
+
OseoResult oseo_internal_define_converted_property(
|
|
2259
|
+
OseoContext *context,
|
|
2260
|
+
OseoValue object_value,
|
|
2261
|
+
OseoValue key,
|
|
2262
|
+
const OseoConvertedDescriptor *descriptor,
|
|
2263
|
+
OseoValue value,
|
|
2264
|
+
OseoValue getter,
|
|
2265
|
+
OseoValue setter,
|
|
2266
|
+
const char **refusal
|
|
2267
|
+
) {
|
|
2268
|
+
*refusal = NULL;
|
|
2269
|
+
if (is_proxy(object_value)) {
|
|
2270
|
+
return oseo_internal_proxy_define_own_property(
|
|
2271
|
+
context,
|
|
2272
|
+
object_value,
|
|
2273
|
+
key,
|
|
2274
|
+
descriptor,
|
|
2275
|
+
value,
|
|
2276
|
+
getter,
|
|
2277
|
+
setter,
|
|
2278
|
+
refusal
|
|
2279
|
+
);
|
|
2280
|
+
}
|
|
2281
|
+
bool typed_array_key = false;
|
|
2282
|
+
size_t typed_index = SIZE_MAX;
|
|
2283
|
+
if (is_typed_array(object_value)) {
|
|
2284
|
+
OseoResult classified = oseo_internal_typed_array_numeric_key(
|
|
2285
|
+
context,
|
|
2286
|
+
key,
|
|
2287
|
+
&typed_array_key,
|
|
2288
|
+
&typed_index
|
|
2289
|
+
);
|
|
2290
|
+
if (classified.status != OSEO_STATUS_NORMAL) return classified;
|
|
2291
|
+
}
|
|
2292
|
+
if (typed_array_key) {
|
|
2293
|
+
return oseo_internal_typed_array_define_index(
|
|
2294
|
+
context,
|
|
2295
|
+
object_value,
|
|
2296
|
+
typed_index,
|
|
2297
|
+
descriptor,
|
|
2298
|
+
value,
|
|
2299
|
+
refusal
|
|
2300
|
+
);
|
|
2301
|
+
}
|
|
2302
|
+
/* A live `arguments` or `caller` moves into the property vector with
|
|
2303
|
+
* its present value first, which a descriptor without a value field
|
|
2304
|
+
* then keeps (ADR 0034). */
|
|
2305
|
+
OseoResult legacy =
|
|
2306
|
+
oseo_internal_legacy_materialize(context, object_value, key);
|
|
2307
|
+
if (legacy.status != OSEO_STATUS_NORMAL) return legacy;
|
|
2308
|
+
OseoValue current_value = oseo_undefined();
|
|
2309
|
+
OseoPropertyAttributes current_attributes = {false, false, false, false};
|
|
2310
|
+
OseoValue current_getter = oseo_undefined();
|
|
2311
|
+
OseoValue current_setter = oseo_undefined();
|
|
2312
|
+
bool exists = oseo_internal_own_property_descriptor(
|
|
2313
|
+
context,
|
|
2314
|
+
object_value,
|
|
2315
|
+
key,
|
|
2316
|
+
¤t_value,
|
|
2317
|
+
¤t_attributes,
|
|
2318
|
+
¤t_getter,
|
|
2319
|
+
¤t_setter
|
|
2320
|
+
);
|
|
2321
|
+
/* A descriptor with no value field keeps the property's current
|
|
2322
|
+
* value, which a cell-backed property holds in its binding cell. */
|
|
2323
|
+
if (exists &&
|
|
2324
|
+
oseo_internal_cell_backed_property(object_value, current_value)) {
|
|
2325
|
+
OseoResult cell = oseo_cell_get(context, current_value);
|
|
2326
|
+
if (cell.status != OSEO_STATUS_NORMAL) return cell;
|
|
2327
|
+
current_value = cell.value;
|
|
2328
|
+
}
|
|
2329
|
+
if (descriptor->has_getter || descriptor->has_setter ||
|
|
2330
|
+
(!descriptor->has_value && !descriptor->has_writable &&
|
|
2331
|
+
exists && current_attributes.accessor)) {
|
|
2332
|
+
OseoPropertyAttributes attributes = {
|
|
2333
|
+
!descriptor->has_configurable
|
|
2334
|
+
? exists && current_attributes.configurable
|
|
2335
|
+
: descriptor->configurable,
|
|
2336
|
+
!descriptor->has_enumerable
|
|
2337
|
+
? exists && current_attributes.enumerable
|
|
2338
|
+
: descriptor->enumerable,
|
|
2339
|
+
false,
|
|
2340
|
+
true,
|
|
2341
|
+
};
|
|
2342
|
+
return oseo_internal_define_accessor_reported(
|
|
2343
|
+
context,
|
|
2344
|
+
object_value,
|
|
2345
|
+
key,
|
|
2346
|
+
descriptor->has_getter ? getter : oseo_undefined(),
|
|
2347
|
+
descriptor->has_setter ? setter : oseo_undefined(),
|
|
2348
|
+
descriptor->has_getter,
|
|
2349
|
+
descriptor->has_setter,
|
|
2350
|
+
attributes,
|
|
2351
|
+
refusal
|
|
2352
|
+
);
|
|
2353
|
+
}
|
|
2354
|
+
OseoPropertyAttributes attributes = {
|
|
2355
|
+
!descriptor->has_configurable
|
|
2356
|
+
? exists && current_attributes.configurable
|
|
2357
|
+
: descriptor->configurable,
|
|
2358
|
+
!descriptor->has_enumerable
|
|
2359
|
+
? exists && current_attributes.enumerable
|
|
2360
|
+
: descriptor->enumerable,
|
|
2361
|
+
!descriptor->has_writable
|
|
2362
|
+
? exists && current_attributes.writable
|
|
2363
|
+
: descriptor->writable,
|
|
2364
|
+
false,
|
|
2365
|
+
};
|
|
2366
|
+
return oseo_internal_define_data_reported(
|
|
2367
|
+
context,
|
|
2368
|
+
object_value,
|
|
2369
|
+
key,
|
|
2370
|
+
descriptor->has_value ? value : current_value,
|
|
2371
|
+
attributes,
|
|
2372
|
+
descriptor->has_value,
|
|
2373
|
+
!descriptor->has_writable,
|
|
2374
|
+
refusal
|
|
2375
|
+
);
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
OseoResult oseo_internal_define_from_descriptor(
|
|
2379
|
+
OseoContext *context,
|
|
2380
|
+
OseoValue object_value,
|
|
2381
|
+
OseoValue key,
|
|
2382
|
+
OseoValue descriptor_value,
|
|
2383
|
+
const char **refusal
|
|
2384
|
+
) {
|
|
2385
|
+
*refusal = NULL;
|
|
2386
|
+
if (!is_object(descriptor_value)) {
|
|
2387
|
+
return type_error(
|
|
2388
|
+
context,
|
|
2389
|
+
"A property definition requires an object descriptor."
|
|
2390
|
+
);
|
|
2391
|
+
}
|
|
2392
|
+
/* Slots: 0 target, 1 key, 2 value, 3 get, 4 set. */
|
|
2393
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
2394
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 5u);
|
|
2395
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2396
|
+
frame.slots[0] = object_value;
|
|
2397
|
+
frame.slots[1] = key;
|
|
2398
|
+
OseoConvertedDescriptor descriptor;
|
|
2399
|
+
result = oseo_internal_to_property_descriptor(
|
|
2400
|
+
context,
|
|
2401
|
+
descriptor_value,
|
|
2402
|
+
&frame.slots[2],
|
|
2403
|
+
&frame.slots[3],
|
|
2404
|
+
&frame.slots[4],
|
|
2405
|
+
&descriptor
|
|
2406
|
+
);
|
|
2407
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2408
|
+
result = oseo_internal_define_converted_property(
|
|
2409
|
+
context,
|
|
2410
|
+
frame.slots[0],
|
|
2411
|
+
frame.slots[1],
|
|
2412
|
+
&descriptor,
|
|
2413
|
+
frame.slots[2],
|
|
2414
|
+
frame.slots[3],
|
|
2415
|
+
frame.slots[4],
|
|
2416
|
+
refusal
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
oseo_roots_release(context, &frame);
|
|
2420
|
+
return result;
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
OseoResult oseo_object_builtin_define_property(
|
|
2424
|
+
OseoContext *context,
|
|
2425
|
+
size_t argument_count,
|
|
2426
|
+
const OseoValue *arguments
|
|
2427
|
+
) {
|
|
2428
|
+
OseoValue object_value = builtin_argument(argument_count, arguments, 0u);
|
|
2429
|
+
OseoValue descriptor_value =
|
|
2430
|
+
builtin_argument(argument_count, arguments, 2u);
|
|
2431
|
+
if (!is_object(object_value)) {
|
|
2432
|
+
return type_error(
|
|
2433
|
+
context,
|
|
2434
|
+
"Object.defineProperty requires an object target."
|
|
2435
|
+
);
|
|
2436
|
+
}
|
|
2437
|
+
/* Slot 0 holds the converted key across the descriptor conversion. */
|
|
2438
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
2439
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 1u);
|
|
2440
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2441
|
+
result = oseo_property_key(
|
|
2442
|
+
context,
|
|
2443
|
+
builtin_argument(argument_count, arguments, 1u)
|
|
2444
|
+
);
|
|
2445
|
+
frame.slots[0] = result.value;
|
|
2446
|
+
if (result.status == OSEO_STATUS_NORMAL && !is_object(descriptor_value)) {
|
|
2447
|
+
result = type_error(
|
|
2448
|
+
context,
|
|
2449
|
+
"Object.defineProperty requires an object descriptor."
|
|
2450
|
+
);
|
|
2451
|
+
}
|
|
2452
|
+
const char *refusal = NULL;
|
|
2453
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2454
|
+
result = oseo_internal_define_from_descriptor(
|
|
2455
|
+
context,
|
|
2456
|
+
object_value,
|
|
2457
|
+
frame.slots[0],
|
|
2458
|
+
descriptor_value,
|
|
2459
|
+
&refusal
|
|
2460
|
+
);
|
|
2461
|
+
}
|
|
2462
|
+
if (result.status == OSEO_STATUS_NORMAL && refusal != NULL) {
|
|
2463
|
+
result = type_error(context, refusal);
|
|
2464
|
+
}
|
|
2465
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = object_value;
|
|
2466
|
+
oseo_roots_release(context, &frame);
|
|
2467
|
+
return result;
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
/*
|
|
2471
|
+
* FromPropertyDescriptor (6.2.6.4). The caller owns a root frame of at
|
|
2472
|
+
* least four slots and stores the described property's data value or
|
|
2473
|
+
* getter in slot 2 and its setter in slot 3 before calling. The created
|
|
2474
|
+
* object lands in slot 0, slot 1 is the field-name scratch every
|
|
2475
|
+
* define_ascii_value call uses, and the fields are defined in the order
|
|
2476
|
+
* the abstract operation specifies, so an own-key walk of the result
|
|
2477
|
+
* reports `value, writable, enumerable, configurable` for a data
|
|
2478
|
+
* property and `get, set, enumerable, configurable` for an accessor.
|
|
2479
|
+
*/
|
|
2480
|
+
static OseoResult from_property_descriptor(
|
|
2481
|
+
OseoContext *context,
|
|
2482
|
+
OseoRootFrame *frame,
|
|
2483
|
+
OseoPropertyAttributes attributes
|
|
2484
|
+
) {
|
|
2485
|
+
OseoResult result = oseo_object_literal_create(context);
|
|
2486
|
+
frame->slots[0] = result.value;
|
|
2487
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2488
|
+
result = attributes.accessor
|
|
2489
|
+
? define_ascii_value(context, frame, "get", frame->slots[2])
|
|
2490
|
+
: define_ascii_value(context, frame, "value", frame->slots[2]);
|
|
2491
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2492
|
+
result = attributes.accessor
|
|
2493
|
+
? define_ascii_value(context, frame, "set", frame->slots[3])
|
|
2494
|
+
: define_ascii_value(
|
|
2495
|
+
context,
|
|
2496
|
+
frame,
|
|
2497
|
+
"writable",
|
|
2498
|
+
oseo_boolean(attributes.writable)
|
|
2499
|
+
);
|
|
2500
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2501
|
+
result = define_ascii_value(
|
|
2502
|
+
context,
|
|
2503
|
+
frame,
|
|
2504
|
+
"enumerable",
|
|
2505
|
+
oseo_boolean(attributes.enumerable)
|
|
2506
|
+
);
|
|
2507
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2508
|
+
result = define_ascii_value(
|
|
2509
|
+
context,
|
|
2510
|
+
frame,
|
|
2511
|
+
"configurable",
|
|
2512
|
+
oseo_boolean(attributes.configurable)
|
|
2513
|
+
);
|
|
2514
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2515
|
+
return normal(frame->slots[0]);
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
OseoResult oseo_object_builtin_get_own_property_descriptor(
|
|
2519
|
+
OseoContext *context,
|
|
2520
|
+
size_t argument_count,
|
|
2521
|
+
const OseoValue *arguments
|
|
2522
|
+
) {
|
|
2523
|
+
OseoValue object_value = builtin_argument(argument_count, arguments, 0u);
|
|
2524
|
+
if (is_nullish(object_value)) {
|
|
2525
|
+
return type_error(
|
|
2526
|
+
context,
|
|
2527
|
+
"Cannot convert a nullish value to an object."
|
|
2528
|
+
);
|
|
2529
|
+
}
|
|
2530
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
2531
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 4u);
|
|
2532
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2533
|
+
result = oseo_property_key(
|
|
2534
|
+
context,
|
|
2535
|
+
builtin_argument(argument_count, arguments, 1u)
|
|
2536
|
+
);
|
|
2537
|
+
frame.slots[1] = result.value;
|
|
2538
|
+
OseoValue value = oseo_undefined();
|
|
2539
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
2540
|
+
OseoValue getter = oseo_undefined();
|
|
2541
|
+
OseoValue setter = oseo_undefined();
|
|
2542
|
+
bool exists = false;
|
|
2543
|
+
if (result.status == OSEO_STATUS_NORMAL && is_object(object_value)) {
|
|
2544
|
+
result = is_proxy(object_value)
|
|
2545
|
+
? oseo_internal_proxy_get_own_property(
|
|
2546
|
+
context,
|
|
2547
|
+
object_value,
|
|
2548
|
+
frame.slots[1],
|
|
2549
|
+
&exists,
|
|
2550
|
+
&value,
|
|
2551
|
+
&attributes,
|
|
2552
|
+
&getter,
|
|
2553
|
+
&setter
|
|
2554
|
+
)
|
|
2555
|
+
: own_property_query(
|
|
2556
|
+
context,
|
|
2557
|
+
object_value,
|
|
2558
|
+
frame.slots[1],
|
|
2559
|
+
&exists,
|
|
2560
|
+
&value,
|
|
2561
|
+
&attributes,
|
|
2562
|
+
&getter,
|
|
2563
|
+
&setter
|
|
2564
|
+
);
|
|
2565
|
+
/* The normal value is ignored; only the abrupt completion and
|
|
2566
|
+
* the descriptor outputs are observable here. */
|
|
2567
|
+
(void)result.value;
|
|
2568
|
+
} else if (result.status == OSEO_STATUS_NORMAL &&
|
|
2569
|
+
is_string(object_value)) {
|
|
2570
|
+
if (oseo_internal_string_is_ascii(frame.slots[1], "length")) {
|
|
2571
|
+
value = oseo_number(string_object(object_value)->length);
|
|
2572
|
+
exists = true;
|
|
2573
|
+
} else {
|
|
2574
|
+
uint32_t index = 0u;
|
|
2575
|
+
if (oseo_internal_array_index(frame.slots[1], &index) &&
|
|
2576
|
+
index < string_object(object_value)->length) {
|
|
2577
|
+
uint16_t unit = string_object(object_value)->units[index];
|
|
2578
|
+
result = oseo_internal_allocate_string(context, &unit, 1u);
|
|
2579
|
+
value = result.value;
|
|
2580
|
+
attributes.enumerable = true;
|
|
2581
|
+
exists = result.status == OSEO_STATUS_NORMAL;
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
if (result.status == OSEO_STATUS_NORMAL && exists &&
|
|
2586
|
+
oseo_internal_cell_backed_property(object_value, value)) {
|
|
2587
|
+
result = oseo_cell_get(context, value);
|
|
2588
|
+
value = result.value;
|
|
2589
|
+
}
|
|
2590
|
+
frame.slots[2] = attributes.accessor ? getter : value;
|
|
2591
|
+
frame.slots[3] = setter;
|
|
2592
|
+
if (result.status == OSEO_STATUS_NORMAL && !exists) {
|
|
2593
|
+
oseo_roots_release(context, &frame);
|
|
2594
|
+
return normal(oseo_undefined());
|
|
2595
|
+
}
|
|
2596
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2597
|
+
result = from_property_descriptor(
|
|
2598
|
+
context, &frame, attributes);
|
|
2599
|
+
}
|
|
2600
|
+
oseo_roots_release(context, &frame);
|
|
2601
|
+
return result;
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
/*
|
|
2605
|
+
* OrdinaryOwnPropertyKeys (10.1.11.1) over the representations this
|
|
2606
|
+
* profile stores. Integer-index keys come first in ascending numeric
|
|
2607
|
+
* order, then the remaining string keys in creation order, then the
|
|
2608
|
+
* symbol keys in creation order. A module namespace's [[OwnPropertyKeys]]
|
|
2609
|
+
* (10.4.6.11) instead lists every export name in the code-unit order its
|
|
2610
|
+
* [[Exports]] list has, integer-like names included; the namespace is
|
|
2611
|
+
* created with its exports in that order, so creation order is that list.
|
|
2612
|
+
*
|
|
2613
|
+
* Three own properties are not in the property vector: an array's
|
|
2614
|
+
* `length`, a function's `prototype`, and the untouched virtual
|
|
2615
|
+
* %String.prototype%[Symbol.iterator]. An array's `length` is created
|
|
2616
|
+
* before any property a program can add, so it leads the array's string
|
|
2617
|
+
* keys. A function's `prototype` follows the leading string keys its
|
|
2618
|
+
* `prototype_key_position` still counts. The untouched String iterator
|
|
2619
|
+
* leads every symbol a program can add. A concrete replacement occupies
|
|
2620
|
+
* that same position in the property vector. Slot 0 of `frame` holds
|
|
2621
|
+
* the object, slot 2 holds whichever synthesized string key this object
|
|
2622
|
+
* needs, and the keys fill the `key_count` slots from index 3.
|
|
2623
|
+
*/
|
|
2624
|
+
/*
|
|
2625
|
+
* Writes `prototype`, preceded by `caller` while it is still live. A
|
|
2626
|
+
* live `caller` always sits right in front of `prototype`; a live
|
|
2627
|
+
* `arguments` is written separately at its own rank (ADR 0034).
|
|
2628
|
+
*/
|
|
2629
|
+
static size_t place_prototype_keys(
|
|
2630
|
+
const OseoContext *context,
|
|
2631
|
+
OseoRootFrame *frame,
|
|
2632
|
+
size_t output,
|
|
2633
|
+
uint8_t legacy_live
|
|
2634
|
+
) {
|
|
2635
|
+
if ((legacy_live & OSEO_LEGACY_CALLER_LIVE) != 0u) {
|
|
2636
|
+
frame->slots[3u + output++] = context->legacy_function_keys[1];
|
|
2637
|
+
}
|
|
2638
|
+
frame->slots[3u + output++] = frame->slots[2];
|
|
2639
|
+
return output;
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
static OseoResult snapshot_own_keys(
|
|
2643
|
+
OseoContext *context,
|
|
2644
|
+
OseoRootFrame *frame,
|
|
2645
|
+
size_t key_count
|
|
2646
|
+
) {
|
|
2647
|
+
/* A TypedArray's valid integer indices lead its keys. */
|
|
2648
|
+
size_t output = 0u;
|
|
2649
|
+
size_t index_count =
|
|
2650
|
+
oseo_internal_typed_array_index_key_count(frame->slots[0]);
|
|
2651
|
+
for (; output < index_count && output < key_count; output += 1u) {
|
|
2652
|
+
OseoResult key = oseo_internal_typed_array_index_key(context, output);
|
|
2653
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
2654
|
+
frame->slots[3u + output] = key.value;
|
|
2655
|
+
}
|
|
2656
|
+
bool virtual_length = is_array(frame->slots[0]);
|
|
2657
|
+
bool virtual_prototype =
|
|
2658
|
+
function_has_prototype_property(frame->slots[0]);
|
|
2659
|
+
bool virtual_string_iterator =
|
|
2660
|
+
ordinary_object(frame->slots[0])->virtual_string_iterator;
|
|
2661
|
+
bool index_keys_lead = !ordinary_object(frame->slots[0])->module_namespace;
|
|
2662
|
+
uint64_t previous = UINT64_MAX;
|
|
2663
|
+
while (index_keys_lead && output < key_count) {
|
|
2664
|
+
OseoOrdinaryObject *object = ordinary_object(frame->slots[0]);
|
|
2665
|
+
size_t selected = SIZE_MAX;
|
|
2666
|
+
uint32_t selected_number = 0u;
|
|
2667
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
2668
|
+
uint32_t number = 0u;
|
|
2669
|
+
if (!oseo_internal_array_index(
|
|
2670
|
+
object->properties[index].key, &number) ||
|
|
2671
|
+
(previous != UINT64_MAX && number <= previous)) continue;
|
|
2672
|
+
if (selected == SIZE_MAX || number < selected_number) {
|
|
2673
|
+
selected = index;
|
|
2674
|
+
selected_number = number;
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
if (selected == SIZE_MAX) break;
|
|
2678
|
+
frame->slots[3u + output] = object->properties[selected].key;
|
|
2679
|
+
output += 1u;
|
|
2680
|
+
previous = selected_number;
|
|
2681
|
+
}
|
|
2682
|
+
if (virtual_length || virtual_prototype) {
|
|
2683
|
+
OseoResult key = oseo_internal_ascii_string(
|
|
2684
|
+
context,
|
|
2685
|
+
virtual_length ? "length" : "prototype"
|
|
2686
|
+
);
|
|
2687
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
2688
|
+
frame->slots[2] = key.value;
|
|
2689
|
+
}
|
|
2690
|
+
if (virtual_length) {
|
|
2691
|
+
frame->slots[3u + output] = frame->slots[2];
|
|
2692
|
+
output += 1u;
|
|
2693
|
+
}
|
|
2694
|
+
uint8_t legacy_live = is_function(frame->slots[0])
|
|
2695
|
+
? function_object(frame->slots[0])->legacy_live
|
|
2696
|
+
: 0u;
|
|
2697
|
+
if (legacy_live != 0u) {
|
|
2698
|
+
OseoResult keys = oseo_internal_legacy_function_keys(context);
|
|
2699
|
+
if (keys.status != OSEO_STATUS_NORMAL) return keys;
|
|
2700
|
+
}
|
|
2701
|
+
bool pending_arguments =
|
|
2702
|
+
(legacy_live & OSEO_LEGACY_ARGUMENTS_LIVE) != 0u;
|
|
2703
|
+
size_t arguments_position = pending_arguments
|
|
2704
|
+
? function_object(frame->slots[0])->legacy_arguments_position
|
|
2705
|
+
: 0u;
|
|
2706
|
+
/* No allocation happens through the remaining string-key pass, so
|
|
2707
|
+
* the property vector cannot move under this loop. */
|
|
2708
|
+
bool pending_prototype = virtual_prototype;
|
|
2709
|
+
size_t prototype_position = virtual_prototype
|
|
2710
|
+
? function_object(frame->slots[0])->prototype_key_position
|
|
2711
|
+
: 0u;
|
|
2712
|
+
size_t string_rank = 0u;
|
|
2713
|
+
OseoOrdinaryObject *object = ordinary_object(frame->slots[0]);
|
|
2714
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
2715
|
+
uint32_t ignored = 0u;
|
|
2716
|
+
OseoValue key = object->properties[index].key;
|
|
2717
|
+
if (is_symbol(key) ||
|
|
2718
|
+
(index_keys_lead &&
|
|
2719
|
+
oseo_internal_array_index(key, &ignored))) continue;
|
|
2720
|
+
if (pending_arguments && string_rank == arguments_position) {
|
|
2721
|
+
frame->slots[3u + output++] = context->legacy_function_keys[0];
|
|
2722
|
+
pending_arguments = false;
|
|
2723
|
+
}
|
|
2724
|
+
if (pending_prototype && string_rank == prototype_position) {
|
|
2725
|
+
output = place_prototype_keys(
|
|
2726
|
+
context, frame, output, legacy_live);
|
|
2727
|
+
pending_prototype = false;
|
|
2728
|
+
}
|
|
2729
|
+
frame->slots[3u + output] = key;
|
|
2730
|
+
output += 1u;
|
|
2731
|
+
string_rank += 1u;
|
|
2732
|
+
}
|
|
2733
|
+
if (pending_arguments) {
|
|
2734
|
+
frame->slots[3u + output++] = context->legacy_function_keys[0];
|
|
2735
|
+
}
|
|
2736
|
+
if (pending_prototype) {
|
|
2737
|
+
output = place_prototype_keys(context, frame, output, legacy_live);
|
|
2738
|
+
}
|
|
2739
|
+
if (virtual_string_iterator) {
|
|
2740
|
+
OseoResult key = oseo_internal_well_known_symbol(
|
|
2741
|
+
context,
|
|
2742
|
+
OSEO_WELL_KNOWN_ITERATOR
|
|
2743
|
+
);
|
|
2744
|
+
if (key.status != OSEO_STATUS_NORMAL) return key;
|
|
2745
|
+
frame->slots[3u + output] = key.value;
|
|
2746
|
+
output += 1u;
|
|
2747
|
+
}
|
|
2748
|
+
/* The virtual-key lookup above may allocate, so reacquire the object
|
|
2749
|
+
* before reading its property vector. No allocation happens during
|
|
2750
|
+
* the stored-symbol pass. */
|
|
2751
|
+
object = ordinary_object(frame->slots[0]);
|
|
2752
|
+
for (size_t index = 0u; index < object->property_count; index += 1u) {
|
|
2753
|
+
OseoValue key = object->properties[index].key;
|
|
2754
|
+
if (!is_symbol(key)) continue;
|
|
2755
|
+
frame->slots[3u + output] = key;
|
|
2756
|
+
output += 1u;
|
|
2757
|
+
}
|
|
2758
|
+
if (output != key_count) {
|
|
2759
|
+
return failure(context, "OSEO2001", "Own-key snapshot changed.");
|
|
2760
|
+
}
|
|
2761
|
+
return normal(oseo_undefined());
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
static size_t own_key_count(OseoValue object_value) {
|
|
2765
|
+
size_t virtual_count = is_array(object_value) ||
|
|
2766
|
+
function_has_prototype_property(object_value) ? 1u : 0u;
|
|
2767
|
+
if (is_function(object_value)) {
|
|
2768
|
+
uint8_t live = function_object(object_value)->legacy_live;
|
|
2769
|
+
if ((live & OSEO_LEGACY_ARGUMENTS_LIVE) != 0u) virtual_count += 1u;
|
|
2770
|
+
if ((live & OSEO_LEGACY_CALLER_LIVE) != 0u) virtual_count += 1u;
|
|
2771
|
+
}
|
|
2772
|
+
if (ordinary_object(object_value)->virtual_string_iterator) {
|
|
2773
|
+
virtual_count += 1u;
|
|
2774
|
+
}
|
|
2775
|
+
/* A view's length is bounded by its buffer's byte length, so adding
|
|
2776
|
+
* it to the property count cannot overflow. */
|
|
2777
|
+
return ordinary_object(object_value)->property_count + virtual_count +
|
|
2778
|
+
oseo_internal_typed_array_index_key_count(object_value);
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
static OseoResult object_close_after_abrupt(
|
|
2782
|
+
OseoContext *context,
|
|
2783
|
+
OseoValue iterator,
|
|
2784
|
+
OseoResult abrupt
|
|
2785
|
+
) {
|
|
2786
|
+
if (abrupt.status != OSEO_STATUS_THROW || context->has_diagnostic) {
|
|
2787
|
+
return abrupt;
|
|
2788
|
+
}
|
|
2789
|
+
OseoValue slots[2] = {iterator, abrupt.value};
|
|
2790
|
+
OseoRootFrame frame = {NULL, slots, 2u};
|
|
2791
|
+
oseo_roots_push(context, &frame);
|
|
2792
|
+
oseo_context_clear_language_error(context);
|
|
2793
|
+
OseoResult closed = oseo_iterator_close(context, slots[0], true);
|
|
2794
|
+
OseoResult result = closed.status == OSEO_STATUS_NORMAL
|
|
2795
|
+
? (OseoResult){OSEO_STATUS_THROW, slots[1]}
|
|
2796
|
+
: closed;
|
|
2797
|
+
oseo_roots_pop(context, &frame);
|
|
2798
|
+
return result;
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
OseoResult oseo_internal_own_property_enumerable(
|
|
2802
|
+
OseoContext *context,
|
|
2803
|
+
OseoValue object_value,
|
|
2804
|
+
OseoValue key,
|
|
2805
|
+
bool *enumerable
|
|
2806
|
+
) {
|
|
2807
|
+
*enumerable = false;
|
|
2808
|
+
OseoValue value = oseo_undefined();
|
|
2809
|
+
OseoValue getter = oseo_undefined();
|
|
2810
|
+
OseoValue setter = oseo_undefined();
|
|
2811
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
2812
|
+
bool exists = false;
|
|
2813
|
+
OseoResult result = is_proxy(object_value)
|
|
2814
|
+
? oseo_internal_proxy_get_own_property(
|
|
2815
|
+
context,
|
|
2816
|
+
object_value,
|
|
2817
|
+
key,
|
|
2818
|
+
&exists,
|
|
2819
|
+
&value,
|
|
2820
|
+
&attributes,
|
|
2821
|
+
&getter,
|
|
2822
|
+
&setter
|
|
2823
|
+
)
|
|
2824
|
+
: own_property_query(
|
|
2825
|
+
context,
|
|
2826
|
+
object_value,
|
|
2827
|
+
key,
|
|
2828
|
+
&exists,
|
|
2829
|
+
&value,
|
|
2830
|
+
&attributes,
|
|
2831
|
+
&getter,
|
|
2832
|
+
&setter
|
|
2833
|
+
);
|
|
2834
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
2835
|
+
*enumerable = exists && attributes.enumerable;
|
|
2836
|
+
return normal(oseo_undefined());
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
OseoResult oseo_internal_own_key_array(
|
|
2840
|
+
OseoContext *context,
|
|
2841
|
+
OseoValue object_value,
|
|
2842
|
+
OseoOwnKeyFilter filter
|
|
2843
|
+
) {
|
|
2844
|
+
if (is_proxy(object_value)) {
|
|
2845
|
+
return oseo_internal_proxy_own_keys(context, object_value, filter);
|
|
2846
|
+
}
|
|
2847
|
+
OseoValue rooted = object_value;
|
|
2848
|
+
OseoRootFrame root = {NULL, &rooted, 1u};
|
|
2849
|
+
oseo_roots_push(context, &root);
|
|
2850
|
+
size_t key_count = own_key_count(rooted);
|
|
2851
|
+
if (key_count > SIZE_MAX - 3u) {
|
|
2852
|
+
oseo_roots_pop(context, &root);
|
|
2853
|
+
return failure(context, "OSEO2001", "Own-key snapshot is too large.");
|
|
2854
|
+
}
|
|
2855
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
2856
|
+
OseoResult result = oseo_roots_allocate(context, &frame, key_count + 3u);
|
|
2857
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2858
|
+
frame.slots[0] = rooted;
|
|
2859
|
+
result = snapshot_own_keys(context, &frame, key_count);
|
|
2860
|
+
}
|
|
2861
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
2862
|
+
result = oseo_array_create(context, 0u);
|
|
2863
|
+
frame.slots[1] = result.value;
|
|
2864
|
+
}
|
|
2865
|
+
for (size_t index = 0u;
|
|
2866
|
+
result.status == OSEO_STATUS_NORMAL && index < key_count;
|
|
2867
|
+
index += 1u) {
|
|
2868
|
+
OseoValue key = frame.slots[3u + index];
|
|
2869
|
+
if ((filter == OSEO_OWN_KEY_STRINGS && is_symbol(key)) ||
|
|
2870
|
+
(filter == OSEO_OWN_KEY_SYMBOLS && !is_symbol(key))) {
|
|
2871
|
+
continue;
|
|
2872
|
+
}
|
|
2873
|
+
result = oseo_array_append(context, frame.slots[1], key);
|
|
2874
|
+
}
|
|
2875
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[1];
|
|
2876
|
+
oseo_roots_release(context, &frame);
|
|
2877
|
+
oseo_roots_pop(context, &root);
|
|
2878
|
+
return result;
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
static OseoResult object_filtered_own_keys(
|
|
2882
|
+
OseoContext *context,
|
|
2883
|
+
size_t argument_count,
|
|
2884
|
+
const OseoValue *arguments,
|
|
2885
|
+
bool symbols
|
|
2886
|
+
) {
|
|
2887
|
+
OseoResult converted = oseo_internal_to_object(
|
|
2888
|
+
context,
|
|
2889
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
2890
|
+
);
|
|
2891
|
+
if (converted.status != OSEO_STATUS_NORMAL) return converted;
|
|
2892
|
+
return oseo_internal_own_key_array(
|
|
2893
|
+
context,
|
|
2894
|
+
converted.value,
|
|
2895
|
+
symbols ? OSEO_OWN_KEY_SYMBOLS : OSEO_OWN_KEY_STRINGS
|
|
2896
|
+
);
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
typedef enum {
|
|
2900
|
+
OSEO_ENUMERABLE_KEYS,
|
|
2901
|
+
OSEO_ENUMERABLE_VALUES,
|
|
2902
|
+
OSEO_ENUMERABLE_ENTRIES,
|
|
2903
|
+
} OseoEnumerableOwnPropertyKind;
|
|
2904
|
+
|
|
2905
|
+
static OseoResult object_enumerable_own_properties(
|
|
2906
|
+
OseoContext *context,
|
|
2907
|
+
size_t argument_count,
|
|
2908
|
+
const OseoValue *arguments,
|
|
2909
|
+
OseoEnumerableOwnPropertyKind kind
|
|
2910
|
+
) {
|
|
2911
|
+
OseoResult converted = oseo_internal_to_object(
|
|
2912
|
+
context,
|
|
2913
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
2914
|
+
);
|
|
2915
|
+
if (converted.status != OSEO_STATUS_NORMAL) return converted;
|
|
2916
|
+
if (is_proxy(converted.value)) {
|
|
2917
|
+
OseoValue slots[5] = {
|
|
2918
|
+
converted.value,
|
|
2919
|
+
oseo_undefined(),
|
|
2920
|
+
oseo_undefined(),
|
|
2921
|
+
oseo_undefined(),
|
|
2922
|
+
oseo_undefined(),
|
|
2923
|
+
};
|
|
2924
|
+
OseoRootFrame proxy_frame = {NULL, slots, 5u};
|
|
2925
|
+
oseo_roots_push(context, &proxy_frame);
|
|
2926
|
+
OseoResult proxy_result = oseo_internal_proxy_own_keys(
|
|
2927
|
+
context, slots[0], OSEO_OWN_KEY_STRINGS);
|
|
2928
|
+
slots[1] = proxy_result.value;
|
|
2929
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
2930
|
+
proxy_result = oseo_internal_array_like_list(
|
|
2931
|
+
context, slots[1], &slots[2]);
|
|
2932
|
+
}
|
|
2933
|
+
size_t proxy_count = 0u;
|
|
2934
|
+
const OseoValue *proxy_keys = NULL;
|
|
2935
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
2936
|
+
proxy_result = oseo_argument_list_view(
|
|
2937
|
+
context, slots[2], &proxy_count, &proxy_keys);
|
|
2938
|
+
}
|
|
2939
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
2940
|
+
proxy_result = oseo_array_create(context, 0u);
|
|
2941
|
+
slots[3] = proxy_result.value;
|
|
2942
|
+
}
|
|
2943
|
+
for (size_t index = 0u;
|
|
2944
|
+
proxy_result.status == OSEO_STATUS_NORMAL &&
|
|
2945
|
+
index < proxy_count;
|
|
2946
|
+
index += 1u) {
|
|
2947
|
+
bool found = false;
|
|
2948
|
+
OseoValue descriptor_value = oseo_undefined();
|
|
2949
|
+
OseoValue descriptor_getter = oseo_undefined();
|
|
2950
|
+
OseoValue descriptor_setter = oseo_undefined();
|
|
2951
|
+
OseoPropertyAttributes descriptor = {false, false, false, false};
|
|
2952
|
+
proxy_result = oseo_internal_proxy_get_own_property(
|
|
2953
|
+
context,
|
|
2954
|
+
slots[0],
|
|
2955
|
+
proxy_keys[index],
|
|
2956
|
+
&found,
|
|
2957
|
+
&descriptor_value,
|
|
2958
|
+
&descriptor,
|
|
2959
|
+
&descriptor_getter,
|
|
2960
|
+
&descriptor_setter
|
|
2961
|
+
);
|
|
2962
|
+
if (proxy_result.status != OSEO_STATUS_NORMAL ||
|
|
2963
|
+
!found || !descriptor.enumerable) continue;
|
|
2964
|
+
if (kind == OSEO_ENUMERABLE_KEYS) {
|
|
2965
|
+
proxy_result = oseo_array_append(
|
|
2966
|
+
context, slots[3], proxy_keys[index]);
|
|
2967
|
+
continue;
|
|
2968
|
+
}
|
|
2969
|
+
proxy_result = oseo_object_get(
|
|
2970
|
+
context, slots[0], proxy_keys[index]);
|
|
2971
|
+
slots[4] = proxy_result.value;
|
|
2972
|
+
if (proxy_result.status != OSEO_STATUS_NORMAL) break;
|
|
2973
|
+
if (kind == OSEO_ENUMERABLE_VALUES) {
|
|
2974
|
+
proxy_result = oseo_array_append(
|
|
2975
|
+
context, slots[3], slots[4]);
|
|
2976
|
+
continue;
|
|
2977
|
+
}
|
|
2978
|
+
OseoResult pair = oseo_array_create(context, 0u);
|
|
2979
|
+
slots[1] = pair.value;
|
|
2980
|
+
if (pair.status == OSEO_STATUS_NORMAL) {
|
|
2981
|
+
pair = oseo_array_append(
|
|
2982
|
+
context, slots[1], proxy_keys[index]);
|
|
2983
|
+
}
|
|
2984
|
+
if (pair.status == OSEO_STATUS_NORMAL) {
|
|
2985
|
+
pair = oseo_array_append(context, slots[1], slots[4]);
|
|
2986
|
+
}
|
|
2987
|
+
if (pair.status == OSEO_STATUS_NORMAL) {
|
|
2988
|
+
pair = oseo_array_append(context, slots[3], slots[1]);
|
|
2989
|
+
}
|
|
2990
|
+
proxy_result = pair;
|
|
2991
|
+
}
|
|
2992
|
+
if (proxy_result.status == OSEO_STATUS_NORMAL) {
|
|
2993
|
+
proxy_result.value = slots[3];
|
|
2994
|
+
}
|
|
2995
|
+
oseo_roots_pop(context, &proxy_frame);
|
|
2996
|
+
return proxy_result;
|
|
2997
|
+
}
|
|
2998
|
+
OseoValue rooted = converted.value;
|
|
2999
|
+
OseoRootFrame root = {NULL, &rooted, 1u};
|
|
3000
|
+
oseo_roots_push(context, &root);
|
|
3001
|
+
size_t key_count = own_key_count(rooted);
|
|
3002
|
+
if (key_count > SIZE_MAX - 3u) {
|
|
3003
|
+
oseo_roots_pop(context, &root);
|
|
3004
|
+
return failure(context, "OSEO2001", "Own-key snapshot is too large.");
|
|
3005
|
+
}
|
|
3006
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
3007
|
+
OseoResult result = oseo_roots_allocate(context, &frame, key_count + 3u);
|
|
3008
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3009
|
+
frame.slots[0] = rooted;
|
|
3010
|
+
result = snapshot_own_keys(context, &frame, key_count);
|
|
3011
|
+
}
|
|
3012
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3013
|
+
result = oseo_array_create(context, 0u);
|
|
3014
|
+
frame.slots[1] = result.value;
|
|
3015
|
+
}
|
|
3016
|
+
OseoValue scratch_slots[2] = {oseo_undefined(), oseo_undefined()};
|
|
3017
|
+
OseoRootFrame scratch = {NULL, scratch_slots, 2u};
|
|
3018
|
+
oseo_roots_push(context, &scratch);
|
|
3019
|
+
for (size_t index = 0u;
|
|
3020
|
+
result.status == OSEO_STATUS_NORMAL && index < key_count;
|
|
3021
|
+
index += 1u) {
|
|
3022
|
+
OseoValue key = frame.slots[3u + index];
|
|
3023
|
+
if (is_symbol(key)) continue;
|
|
3024
|
+
OseoValue ignored = oseo_undefined();
|
|
3025
|
+
OseoValue ignored_getter = oseo_undefined();
|
|
3026
|
+
OseoValue ignored_setter = oseo_undefined();
|
|
3027
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
3028
|
+
bool exists = false;
|
|
3029
|
+
result = own_property_query(
|
|
3030
|
+
context,
|
|
3031
|
+
frame.slots[0],
|
|
3032
|
+
key,
|
|
3033
|
+
&exists,
|
|
3034
|
+
&ignored,
|
|
3035
|
+
&attributes,
|
|
3036
|
+
&ignored_getter,
|
|
3037
|
+
&ignored_setter
|
|
3038
|
+
);
|
|
3039
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3040
|
+
if (!exists || !attributes.enumerable) continue;
|
|
3041
|
+
if (kind == OSEO_ENUMERABLE_KEYS) {
|
|
3042
|
+
result = oseo_array_append(context, frame.slots[1], key);
|
|
3043
|
+
continue;
|
|
3044
|
+
}
|
|
3045
|
+
result = oseo_object_get(context, frame.slots[0], key);
|
|
3046
|
+
scratch_slots[0] = result.value;
|
|
3047
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3048
|
+
if (kind == OSEO_ENUMERABLE_VALUES) {
|
|
3049
|
+
result = oseo_array_append(
|
|
3050
|
+
context, frame.slots[1], scratch_slots[0]);
|
|
3051
|
+
continue;
|
|
3052
|
+
}
|
|
3053
|
+
result = oseo_array_create(context, 0u);
|
|
3054
|
+
scratch_slots[1] = result.value;
|
|
3055
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3056
|
+
result = oseo_array_append(context, scratch_slots[1], key);
|
|
3057
|
+
}
|
|
3058
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3059
|
+
result = oseo_array_append(
|
|
3060
|
+
context, scratch_slots[1], scratch_slots[0]);
|
|
3061
|
+
}
|
|
3062
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3063
|
+
result = oseo_array_append(
|
|
3064
|
+
context, frame.slots[1], scratch_slots[1]);
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[1];
|
|
3068
|
+
oseo_roots_pop(context, &scratch);
|
|
3069
|
+
oseo_roots_release(context, &frame);
|
|
3070
|
+
oseo_roots_pop(context, &root);
|
|
3071
|
+
return result;
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
static OseoResult object_assign(
|
|
3075
|
+
OseoContext *context,
|
|
3076
|
+
size_t argument_count,
|
|
3077
|
+
const OseoValue *arguments
|
|
3078
|
+
) {
|
|
3079
|
+
OseoResult converted = oseo_internal_to_object(
|
|
3080
|
+
context,
|
|
3081
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
3082
|
+
);
|
|
3083
|
+
if (converted.status != OSEO_STATUS_NORMAL) return converted;
|
|
3084
|
+
OseoValue target = converted.value;
|
|
3085
|
+
OseoRootFrame target_root = {NULL, &target, 1u};
|
|
3086
|
+
oseo_roots_push(context, &target_root);
|
|
3087
|
+
OseoResult result = normal(target);
|
|
3088
|
+
for (size_t source_index = 1u;
|
|
3089
|
+
result.status == OSEO_STATUS_NORMAL && source_index < argument_count;
|
|
3090
|
+
source_index += 1u) {
|
|
3091
|
+
if (is_nullish(arguments[source_index])) continue;
|
|
3092
|
+
converted = oseo_internal_to_object(context, arguments[source_index]);
|
|
3093
|
+
if (converted.status != OSEO_STATUS_NORMAL) {
|
|
3094
|
+
result = converted;
|
|
3095
|
+
break;
|
|
3096
|
+
}
|
|
3097
|
+
OseoValue source = converted.value;
|
|
3098
|
+
OseoRootFrame source_root = {NULL, &source, 1u};
|
|
3099
|
+
oseo_roots_push(context, &source_root);
|
|
3100
|
+
size_t key_count = 0u;
|
|
3101
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
3102
|
+
if (is_proxy(source)) {
|
|
3103
|
+
result = proxy_own_key_frame(
|
|
3104
|
+
context, source, &frame, &key_count);
|
|
3105
|
+
} else {
|
|
3106
|
+
key_count = own_key_count(source);
|
|
3107
|
+
if (key_count > SIZE_MAX - 3u) {
|
|
3108
|
+
result = failure(
|
|
3109
|
+
context, "OSEO2001", "Own-key snapshot is too large.");
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
if (result.status == OSEO_STATUS_NORMAL && !is_proxy(source)) {
|
|
3113
|
+
result = oseo_roots_allocate(context, &frame, key_count + 3u);
|
|
3114
|
+
}
|
|
3115
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3116
|
+
frame.slots[0] = source;
|
|
3117
|
+
frame.slots[1] = target;
|
|
3118
|
+
if (!is_proxy(frame.slots[0])) {
|
|
3119
|
+
result = snapshot_own_keys(context, &frame, key_count);
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
for (size_t index = 0u;
|
|
3123
|
+
result.status == OSEO_STATUS_NORMAL && index < key_count;
|
|
3124
|
+
index += 1u) {
|
|
3125
|
+
OseoValue key = frame.slots[3u + index];
|
|
3126
|
+
OseoValue ignored = oseo_undefined();
|
|
3127
|
+
OseoValue ignored_getter = oseo_undefined();
|
|
3128
|
+
OseoValue ignored_setter = oseo_undefined();
|
|
3129
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
3130
|
+
bool exists = false;
|
|
3131
|
+
if (is_proxy(frame.slots[0])) {
|
|
3132
|
+
result = oseo_internal_proxy_get_own_property(
|
|
3133
|
+
context,
|
|
3134
|
+
frame.slots[0],
|
|
3135
|
+
key,
|
|
3136
|
+
&exists,
|
|
3137
|
+
&ignored,
|
|
3138
|
+
&attributes,
|
|
3139
|
+
&ignored_getter,
|
|
3140
|
+
&ignored_setter
|
|
3141
|
+
);
|
|
3142
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3143
|
+
} else {
|
|
3144
|
+
result = own_property_query(
|
|
3145
|
+
context,
|
|
3146
|
+
frame.slots[0],
|
|
3147
|
+
key,
|
|
3148
|
+
&exists,
|
|
3149
|
+
&ignored,
|
|
3150
|
+
&attributes,
|
|
3151
|
+
&ignored_getter,
|
|
3152
|
+
&ignored_setter
|
|
3153
|
+
);
|
|
3154
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3155
|
+
}
|
|
3156
|
+
if (!exists || !attributes.enumerable) {
|
|
3157
|
+
continue;
|
|
3158
|
+
}
|
|
3159
|
+
result = oseo_object_get(context, frame.slots[0], key);
|
|
3160
|
+
frame.slots[2] = result.value;
|
|
3161
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3162
|
+
result = oseo_object_set(
|
|
3163
|
+
context,
|
|
3164
|
+
frame.slots[1],
|
|
3165
|
+
key,
|
|
3166
|
+
frame.slots[2],
|
|
3167
|
+
true
|
|
3168
|
+
);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
oseo_roots_release(context, &frame);
|
|
3172
|
+
oseo_roots_pop(context, &source_root);
|
|
3173
|
+
}
|
|
3174
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = target;
|
|
3175
|
+
oseo_roots_pop(context, &target_root);
|
|
3176
|
+
return result;
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
static OseoResult object_entries(
|
|
3180
|
+
OseoContext *context,
|
|
3181
|
+
size_t argument_count,
|
|
3182
|
+
const OseoValue *arguments
|
|
3183
|
+
) {
|
|
3184
|
+
return object_enumerable_own_properties(
|
|
3185
|
+
context, argument_count, arguments, OSEO_ENUMERABLE_ENTRIES);
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
static OseoResult object_values(
|
|
3189
|
+
OseoContext *context,
|
|
3190
|
+
size_t argument_count,
|
|
3191
|
+
const OseoValue *arguments
|
|
3192
|
+
) {
|
|
3193
|
+
return object_enumerable_own_properties(
|
|
3194
|
+
context, argument_count, arguments, OSEO_ENUMERABLE_VALUES);
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3197
|
+
static OseoResult object_get_own_property_names(
|
|
3198
|
+
OseoContext *context,
|
|
3199
|
+
size_t argument_count,
|
|
3200
|
+
const OseoValue *arguments
|
|
3201
|
+
) {
|
|
3202
|
+
return object_filtered_own_keys(context, argument_count, arguments, false);
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
static OseoResult object_get_own_property_symbols(
|
|
3206
|
+
OseoContext *context,
|
|
3207
|
+
size_t argument_count,
|
|
3208
|
+
const OseoValue *arguments
|
|
3209
|
+
) {
|
|
3210
|
+
return object_filtered_own_keys(context, argument_count, arguments, true);
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
static OseoResult object_has_own(
|
|
3214
|
+
OseoContext *context,
|
|
3215
|
+
size_t argument_count,
|
|
3216
|
+
const OseoValue *arguments
|
|
3217
|
+
) {
|
|
3218
|
+
OseoResult converted = oseo_internal_to_object(
|
|
3219
|
+
context,
|
|
3220
|
+
builtin_argument(argument_count, arguments, 0u)
|
|
3221
|
+
);
|
|
3222
|
+
if (converted.status != OSEO_STATUS_NORMAL) return converted;
|
|
3223
|
+
OseoValue slots[2] = {
|
|
3224
|
+
converted.value,
|
|
3225
|
+
builtin_argument(argument_count, arguments, 1u),
|
|
3226
|
+
};
|
|
3227
|
+
OseoRootFrame frame = {NULL, slots, 2u};
|
|
3228
|
+
oseo_roots_push(context, &frame);
|
|
3229
|
+
OseoResult result = oseo_property_key(context, slots[1]);
|
|
3230
|
+
slots[1] = result.value;
|
|
3231
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3232
|
+
result = oseo_object_has_own(context, slots[0], slots[1]);
|
|
3233
|
+
}
|
|
3234
|
+
oseo_roots_pop(context, &frame);
|
|
3235
|
+
return result;
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
/* Recover the String value a primitive or [[StringData]] wrapper stores. */
|
|
3239
|
+
static bool object_string_value(OseoValue source, OseoValue *string_value) {
|
|
3240
|
+
if (is_string(source)) {
|
|
3241
|
+
*string_value = source;
|
|
3242
|
+
return true;
|
|
3243
|
+
}
|
|
3244
|
+
if (!oseo_internal_string_data(source)) return false;
|
|
3245
|
+
*string_value = ordinary_object(source)->primitive_value;
|
|
3246
|
+
return true;
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
/*
|
|
3250
|
+
* Decide whether a value iterates as a String through the realm's
|
|
3251
|
+
* untouched virtual %String.prototype%[Symbol.iterator] bootstrap slot. A
|
|
3252
|
+
* primitive String or a [[StringData]] wrapper that still reaches that
|
|
3253
|
+
* slot has no iterator object to acquire, so the caller walks code points
|
|
3254
|
+
* itself. Once the String iterator intrinsic materializes the property,
|
|
3255
|
+
* the ordinary own slot makes this branch dormant.
|
|
3256
|
+
* Anything else, including an own, inherited, replaced, or deleted
|
|
3257
|
+
* iterator, reports false and goes through observable iterator
|
|
3258
|
+
* acquisition. Both intrinsic lookups can allocate, so the frame roots
|
|
3259
|
+
* the source and its [[StringData]] rather than relying on the caller to
|
|
3260
|
+
* keep them reachable, and `string_value` is written after the last
|
|
3261
|
+
* allocation so the caller's rooted slot receives a live value.
|
|
3262
|
+
*/
|
|
3263
|
+
static OseoResult object_virtual_string_iteration(
|
|
3264
|
+
OseoContext *context,
|
|
3265
|
+
OseoValue source,
|
|
3266
|
+
OseoValue *string_value,
|
|
3267
|
+
bool *direct
|
|
3268
|
+
) {
|
|
3269
|
+
*direct = false;
|
|
3270
|
+
OseoValue candidate = oseo_undefined();
|
|
3271
|
+
if (!object_string_value(source, &candidate)) {
|
|
3272
|
+
return normal(oseo_undefined());
|
|
3273
|
+
}
|
|
3274
|
+
OseoValue slots[3] = {source, candidate, oseo_undefined()};
|
|
3275
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
3276
|
+
oseo_roots_push(context, &frame);
|
|
3277
|
+
OseoResult result = oseo_internal_well_known_symbol(
|
|
3278
|
+
context,
|
|
3279
|
+
OSEO_WELL_KNOWN_ITERATOR
|
|
3280
|
+
);
|
|
3281
|
+
slots[2] = result.value;
|
|
3282
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3283
|
+
result = oseo_internal_primitive_wrapper_prototype(
|
|
3284
|
+
context,
|
|
3285
|
+
OSEO_INTRINSIC_STRING_PROTOTYPE
|
|
3286
|
+
);
|
|
3287
|
+
}
|
|
3288
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3289
|
+
/* The prototype is used before the next allocation, so it needs
|
|
3290
|
+
* no slot of its own. */
|
|
3291
|
+
*direct = oseo_internal_uses_virtual_string_iterator(
|
|
3292
|
+
slots[0],
|
|
3293
|
+
result.value,
|
|
3294
|
+
slots[2]
|
|
3295
|
+
);
|
|
3296
|
+
*string_value = slots[1];
|
|
3297
|
+
}
|
|
3298
|
+
oseo_roots_pop(context, &frame);
|
|
3299
|
+
return result;
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
/*
|
|
3303
|
+
* Code-unit length of the code point the default String iterator yields
|
|
3304
|
+
* at `offset`, pairing a leading surrogate with a following trailing one
|
|
3305
|
+
* and reporting a lone surrogate as a single unit. Each caller reacquires
|
|
3306
|
+
* its OseoString from a rooted slot on every step, so the interior
|
|
3307
|
+
* `units` pointer it then hands to oseo_string_from_units stays valid:
|
|
3308
|
+
* the collector sweeps unreachable objects in place and never relocates a
|
|
3309
|
+
* reachable one.
|
|
3310
|
+
*/
|
|
3311
|
+
static size_t object_string_element_length(
|
|
3312
|
+
const OseoString *source,
|
|
3313
|
+
size_t offset
|
|
3314
|
+
) {
|
|
3315
|
+
uint16_t first = source->units[offset];
|
|
3316
|
+
if (first < UINT16_C(0xd800) || first > UINT16_C(0xdbff)) return 1u;
|
|
3317
|
+
if (offset + 1u >= source->length) return 1u;
|
|
3318
|
+
uint16_t second = source->units[offset + 1u];
|
|
3319
|
+
if (second < UINT16_C(0xdc00) || second > UINT16_C(0xdfff)) return 1u;
|
|
3320
|
+
return 2u;
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
/*
|
|
3324
|
+
* CreateDataPropertyOnObject (20.1.2.7 step 5.c onward) for the entry now
|
|
3325
|
+
* in slots[4], defining its "0" key and "1" value on the target object in
|
|
3326
|
+
* slots[3]. slots[5] through slots[7] are the caller's rooted scratch.
|
|
3327
|
+
*/
|
|
3328
|
+
static OseoResult object_define_entry(OseoContext *context, OseoValue *slots) {
|
|
3329
|
+
if (!is_object(slots[4])) {
|
|
3330
|
+
return type_error(context, "Iterator value is not an entry object.");
|
|
3331
|
+
}
|
|
3332
|
+
OseoResult result = oseo_internal_ascii_string(context, "0");
|
|
3333
|
+
slots[5] = result.value;
|
|
3334
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3335
|
+
result = oseo_object_get(context, slots[4], slots[5]);
|
|
3336
|
+
slots[5] = result.value;
|
|
3337
|
+
}
|
|
3338
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3339
|
+
result = oseo_internal_ascii_string(context, "1");
|
|
3340
|
+
slots[6] = result.value;
|
|
3341
|
+
}
|
|
3342
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3343
|
+
result = oseo_object_get(context, slots[4], slots[6]);
|
|
3344
|
+
slots[6] = result.value;
|
|
3345
|
+
}
|
|
3346
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3347
|
+
result = oseo_property_key(context, slots[5]);
|
|
3348
|
+
slots[7] = result.value;
|
|
3349
|
+
}
|
|
3350
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3351
|
+
result = oseo_object_define(
|
|
3352
|
+
context,
|
|
3353
|
+
slots[3],
|
|
3354
|
+
slots[7],
|
|
3355
|
+
slots[6],
|
|
3356
|
+
(OseoPropertyAttributes){true, true, true, false}
|
|
3357
|
+
);
|
|
3358
|
+
}
|
|
3359
|
+
return result;
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
static OseoResult object_from_entries(
|
|
3363
|
+
OseoContext *context,
|
|
3364
|
+
size_t argument_count,
|
|
3365
|
+
const OseoValue *arguments
|
|
3366
|
+
) {
|
|
3367
|
+
OseoValue slots[9] = {
|
|
3368
|
+
builtin_argument(argument_count, arguments, 0u),
|
|
3369
|
+
oseo_undefined(),
|
|
3370
|
+
oseo_undefined(),
|
|
3371
|
+
oseo_undefined(),
|
|
3372
|
+
oseo_undefined(),
|
|
3373
|
+
oseo_undefined(),
|
|
3374
|
+
oseo_undefined(),
|
|
3375
|
+
oseo_undefined(),
|
|
3376
|
+
oseo_undefined(),
|
|
3377
|
+
};
|
|
3378
|
+
OseoRootFrame frame = {NULL, slots, 9u};
|
|
3379
|
+
oseo_roots_push(context, &frame);
|
|
3380
|
+
bool direct_string = false;
|
|
3381
|
+
OseoResult result = object_virtual_string_iteration(
|
|
3382
|
+
context,
|
|
3383
|
+
slots[0],
|
|
3384
|
+
&slots[8],
|
|
3385
|
+
&direct_string
|
|
3386
|
+
);
|
|
3387
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3388
|
+
result = oseo_object_literal_create(context);
|
|
3389
|
+
slots[3] = result.value;
|
|
3390
|
+
}
|
|
3391
|
+
if (result.status == OSEO_STATUS_NORMAL && !direct_string) {
|
|
3392
|
+
result = oseo_iterator_get(context, slots[0], &slots[2]);
|
|
3393
|
+
slots[1] = result.value;
|
|
3394
|
+
}
|
|
3395
|
+
if (result.status == OSEO_STATUS_NORMAL && direct_string) {
|
|
3396
|
+
/*
|
|
3397
|
+
* The bootstrap virtual default has no iterator object, so walk
|
|
3398
|
+
* the default code-point sequence here as Object.groupBy and
|
|
3399
|
+
* Array.from do. An empty String
|
|
3400
|
+
* yields nothing and produces an empty object; every element a
|
|
3401
|
+
* non-empty String yields is a primitive, so the first one
|
|
3402
|
+
* reaches the entry-object TypeError below. There is no iterator
|
|
3403
|
+
* object to close on that abrupt completion.
|
|
3404
|
+
*/
|
|
3405
|
+
size_t offset = 0u;
|
|
3406
|
+
while (result.status == OSEO_STATUS_NORMAL) {
|
|
3407
|
+
OseoString *source = string_object(slots[8]);
|
|
3408
|
+
if (offset >= source->length) break;
|
|
3409
|
+
size_t element_length =
|
|
3410
|
+
object_string_element_length(source, offset);
|
|
3411
|
+
result = oseo_string_from_units(
|
|
3412
|
+
context,
|
|
3413
|
+
&source->units[offset],
|
|
3414
|
+
element_length
|
|
3415
|
+
);
|
|
3416
|
+
slots[4] = result.value;
|
|
3417
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3418
|
+
result = object_define_entry(context, slots);
|
|
3419
|
+
}
|
|
3420
|
+
offset += element_length;
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
bool done = false;
|
|
3424
|
+
while (result.status == OSEO_STATUS_NORMAL && !direct_string && !done) {
|
|
3425
|
+
result = oseo_iterator_next(
|
|
3426
|
+
context, slots[1], slots[2], &slots[4], &done);
|
|
3427
|
+
if (result.status != OSEO_STATUS_NORMAL || done) break;
|
|
3428
|
+
result = object_define_entry(context, slots);
|
|
3429
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
3430
|
+
result = object_close_after_abrupt(context, slots[1], result);
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = slots[3];
|
|
3434
|
+
oseo_roots_pop(context, &frame);
|
|
3435
|
+
return result;
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
static OseoResult object_add_grouped_value(
|
|
3439
|
+
OseoContext *context,
|
|
3440
|
+
OseoValue *slots,
|
|
3441
|
+
double index
|
|
3442
|
+
) {
|
|
3443
|
+
OseoValue callback_arguments[2] = {
|
|
3444
|
+
slots[5],
|
|
3445
|
+
oseo_number(index),
|
|
3446
|
+
};
|
|
3447
|
+
OseoResult result = oseo_call_function(
|
|
3448
|
+
context,
|
|
3449
|
+
slots[1],
|
|
3450
|
+
oseo_undefined(),
|
|
3451
|
+
2u,
|
|
3452
|
+
callback_arguments,
|
|
3453
|
+
oseo_undefined()
|
|
3454
|
+
);
|
|
3455
|
+
slots[6] = result.value;
|
|
3456
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3457
|
+
result = oseo_property_key(context, slots[6]);
|
|
3458
|
+
slots[6] = result.value;
|
|
3459
|
+
}
|
|
3460
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3461
|
+
result = oseo_object_has_own(context, slots[4], slots[6]);
|
|
3462
|
+
}
|
|
3463
|
+
bool exists = result.status == OSEO_STATUS_NORMAL &&
|
|
3464
|
+
oseo_to_boolean(result.value);
|
|
3465
|
+
if (result.status == OSEO_STATUS_NORMAL && exists) {
|
|
3466
|
+
result = oseo_object_get(context, slots[4], slots[6]);
|
|
3467
|
+
slots[7] = result.value;
|
|
3468
|
+
} else if (result.status == OSEO_STATUS_NORMAL) {
|
|
3469
|
+
result = oseo_array_create(context, 0u);
|
|
3470
|
+
slots[7] = result.value;
|
|
3471
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3472
|
+
result = oseo_object_define(
|
|
3473
|
+
context,
|
|
3474
|
+
slots[4],
|
|
3475
|
+
slots[6],
|
|
3476
|
+
slots[7],
|
|
3477
|
+
(OseoPropertyAttributes){true, true, true, false}
|
|
3478
|
+
);
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3482
|
+
result = oseo_array_append(context, slots[7], slots[5]);
|
|
3483
|
+
}
|
|
3484
|
+
return result;
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3487
|
+
static OseoResult object_group_by(
|
|
3488
|
+
OseoContext *context,
|
|
3489
|
+
size_t argument_count,
|
|
3490
|
+
const OseoValue *arguments
|
|
3491
|
+
) {
|
|
3492
|
+
OseoValue slots[9] = {
|
|
3493
|
+
builtin_argument(argument_count, arguments, 0u),
|
|
3494
|
+
builtin_argument(argument_count, arguments, 1u),
|
|
3495
|
+
oseo_undefined(),
|
|
3496
|
+
oseo_undefined(),
|
|
3497
|
+
oseo_undefined(),
|
|
3498
|
+
oseo_undefined(),
|
|
3499
|
+
oseo_undefined(),
|
|
3500
|
+
oseo_undefined(),
|
|
3501
|
+
oseo_undefined(),
|
|
3502
|
+
};
|
|
3503
|
+
OseoRootFrame frame = {NULL, slots, 9u};
|
|
3504
|
+
oseo_roots_push(context, &frame);
|
|
3505
|
+
OseoResult result = normal(oseo_undefined());
|
|
3506
|
+
if (is_nullish(slots[0])) {
|
|
3507
|
+
result = type_error(context, "Object.groupBy requires an iterable.");
|
|
3508
|
+
} else if (!is_callable(slots[1])) {
|
|
3509
|
+
result = type_error(
|
|
3510
|
+
context,
|
|
3511
|
+
"Object.groupBy callback is not callable."
|
|
3512
|
+
);
|
|
3513
|
+
}
|
|
3514
|
+
bool direct_string = false;
|
|
3515
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3516
|
+
result = object_virtual_string_iteration(
|
|
3517
|
+
context,
|
|
3518
|
+
slots[0],
|
|
3519
|
+
&slots[8],
|
|
3520
|
+
&direct_string
|
|
3521
|
+
);
|
|
3522
|
+
}
|
|
3523
|
+
if (result.status == OSEO_STATUS_NORMAL && !direct_string) {
|
|
3524
|
+
result = oseo_iterator_get(context, slots[0], &slots[3]);
|
|
3525
|
+
slots[2] = result.value;
|
|
3526
|
+
}
|
|
3527
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3528
|
+
result = oseo_object_create(context, oseo_null());
|
|
3529
|
+
slots[4] = result.value;
|
|
3530
|
+
}
|
|
3531
|
+
double index = 0.0;
|
|
3532
|
+
if (result.status == OSEO_STATUS_NORMAL && direct_string) {
|
|
3533
|
+
/*
|
|
3534
|
+
* The bootstrap virtual default has no iterator object. Preserve
|
|
3535
|
+
* its default code-point iteration here, just as Array.from does.
|
|
3536
|
+
* The materialized String iterator makes this branch dormant.
|
|
3537
|
+
*/
|
|
3538
|
+
size_t offset = 0u;
|
|
3539
|
+
while (result.status == OSEO_STATUS_NORMAL) {
|
|
3540
|
+
OseoString *source = string_object(slots[8]);
|
|
3541
|
+
if (offset >= source->length) break;
|
|
3542
|
+
size_t element_length =
|
|
3543
|
+
object_string_element_length(source, offset);
|
|
3544
|
+
result = oseo_string_from_units(
|
|
3545
|
+
context,
|
|
3546
|
+
&source->units[offset],
|
|
3547
|
+
element_length
|
|
3548
|
+
);
|
|
3549
|
+
slots[5] = result.value;
|
|
3550
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3551
|
+
result = object_add_grouped_value(context, slots, index);
|
|
3552
|
+
}
|
|
3553
|
+
offset += element_length;
|
|
3554
|
+
index += 1.0;
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
bool done = false;
|
|
3558
|
+
while (result.status == OSEO_STATUS_NORMAL && !direct_string && !done) {
|
|
3559
|
+
result = oseo_iterator_next(
|
|
3560
|
+
context, slots[2], slots[3], &slots[5], &done);
|
|
3561
|
+
if (result.status != OSEO_STATUS_NORMAL || done) break;
|
|
3562
|
+
if (index >= 9007199254740991.0) {
|
|
3563
|
+
result = oseo_internal_throw_error(
|
|
3564
|
+
context,
|
|
3565
|
+
OSEO_ERROR_RANGE,
|
|
3566
|
+
"Object.groupBy index is too large."
|
|
3567
|
+
);
|
|
3568
|
+
}
|
|
3569
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3570
|
+
result = object_add_grouped_value(context, slots, index);
|
|
3571
|
+
}
|
|
3572
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
3573
|
+
result = object_close_after_abrupt(context, slots[2], result);
|
|
3574
|
+
}
|
|
3575
|
+
index += 1.0;
|
|
3576
|
+
}
|
|
3577
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = slots[4];
|
|
3578
|
+
oseo_roots_pop(context, &frame);
|
|
3579
|
+
return result;
|
|
3580
|
+
}
|
|
3581
|
+
|
|
3582
|
+
/*
|
|
3583
|
+
* Object.getOwnPropertyDescriptors (20.1.2.9). ToObject runs before
|
|
3584
|
+
* anything else, so a nullish argument throws and a primitive is
|
|
3585
|
+
* reported through the wrapper object it converts to, including a
|
|
3586
|
+
* String wrapper's index and `length` properties. Every own key the
|
|
3587
|
+
* conversion result reports contributes one FromPropertyDescriptor
|
|
3588
|
+
* object, created as a writable, enumerable, configurable data property
|
|
3589
|
+
* of an ordinary object.
|
|
3590
|
+
*/
|
|
3591
|
+
static OseoResult object_get_own_property_descriptors(
|
|
3592
|
+
OseoContext *context,
|
|
3593
|
+
size_t argument_count,
|
|
3594
|
+
const OseoValue *arguments
|
|
3595
|
+
) {
|
|
3596
|
+
OseoValue value = builtin_argument(argument_count, arguments, 0u);
|
|
3597
|
+
if (is_nullish(value)) {
|
|
3598
|
+
return type_error(
|
|
3599
|
+
context,
|
|
3600
|
+
"Cannot convert a nullish value to an object."
|
|
3601
|
+
);
|
|
3602
|
+
}
|
|
3603
|
+
OseoResult converted = oseo_internal_to_object(context, value);
|
|
3604
|
+
if (converted.status != OSEO_STATUS_NORMAL) return converted;
|
|
3605
|
+
size_t key_count = 0u;
|
|
3606
|
+
/* The key frame roots the conversion result, the reported object,
|
|
3607
|
+
* the one synthesized key string, and the whole key snapshot. The
|
|
3608
|
+
* descriptor frame is the four-slot scratch every
|
|
3609
|
+
* FromPropertyDescriptor call reuses. */
|
|
3610
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
3611
|
+
OseoResult result = normal(oseo_undefined());
|
|
3612
|
+
if (is_proxy(converted.value)) {
|
|
3613
|
+
result = proxy_own_key_frame(
|
|
3614
|
+
context, converted.value, &frame, &key_count);
|
|
3615
|
+
} else {
|
|
3616
|
+
key_count = own_key_count(converted.value);
|
|
3617
|
+
if (key_count > SIZE_MAX - 3u) {
|
|
3618
|
+
return failure(
|
|
3619
|
+
context, "OSEO2001", "Own-key snapshot is too large.");
|
|
3620
|
+
}
|
|
3621
|
+
result = oseo_roots_allocate(context, &frame, key_count + 3u);
|
|
3622
|
+
}
|
|
3623
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
3624
|
+
frame.slots[0] = converted.value;
|
|
3625
|
+
OseoRootFrame descriptor = {NULL, NULL, 0u};
|
|
3626
|
+
result = oseo_roots_allocate(context, &descriptor, 4u);
|
|
3627
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
3628
|
+
oseo_roots_release(context, &frame);
|
|
3629
|
+
return result;
|
|
3630
|
+
}
|
|
3631
|
+
if (!is_proxy(frame.slots[0])) {
|
|
3632
|
+
result = snapshot_own_keys(context, &frame, key_count);
|
|
3633
|
+
}
|
|
3634
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
3635
|
+
result = oseo_object_literal_create(context);
|
|
3636
|
+
frame.slots[1] = result.value;
|
|
3637
|
+
}
|
|
3638
|
+
for (size_t index = 0u;
|
|
3639
|
+
result.status == OSEO_STATUS_NORMAL && index < key_count;
|
|
3640
|
+
index += 1u) {
|
|
3641
|
+
OseoValue key = frame.slots[3u + index];
|
|
3642
|
+
OseoValue own = oseo_undefined();
|
|
3643
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
3644
|
+
OseoValue getter = oseo_undefined();
|
|
3645
|
+
OseoValue setter = oseo_undefined();
|
|
3646
|
+
bool exists = false;
|
|
3647
|
+
if (is_proxy(frame.slots[0])) {
|
|
3648
|
+
result = oseo_internal_proxy_get_own_property(
|
|
3649
|
+
context,
|
|
3650
|
+
frame.slots[0],
|
|
3651
|
+
key,
|
|
3652
|
+
&exists,
|
|
3653
|
+
&own,
|
|
3654
|
+
&attributes,
|
|
3655
|
+
&getter,
|
|
3656
|
+
&setter
|
|
3657
|
+
);
|
|
3658
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3659
|
+
} else {
|
|
3660
|
+
result = own_property_query(
|
|
3661
|
+
context,
|
|
3662
|
+
frame.slots[0],
|
|
3663
|
+
key,
|
|
3664
|
+
&exists,
|
|
3665
|
+
&own,
|
|
3666
|
+
&attributes,
|
|
3667
|
+
&getter,
|
|
3668
|
+
&setter
|
|
3669
|
+
);
|
|
3670
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3671
|
+
}
|
|
3672
|
+
if (!exists) continue;
|
|
3673
|
+
descriptor.slots[2] = attributes.accessor ? getter : own;
|
|
3674
|
+
descriptor.slots[3] = setter;
|
|
3675
|
+
if (oseo_internal_cell_backed_property(frame.slots[0], own)) {
|
|
3676
|
+
result = oseo_cell_get(context, own);
|
|
3677
|
+
descriptor.slots[2] = result.value;
|
|
3678
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3679
|
+
}
|
|
3680
|
+
result = from_property_descriptor(context, &descriptor,
|
|
3681
|
+
attributes);
|
|
3682
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3683
|
+
result = oseo_object_define(
|
|
3684
|
+
context,
|
|
3685
|
+
frame.slots[1],
|
|
3686
|
+
key,
|
|
3687
|
+
descriptor.slots[0],
|
|
3688
|
+
(OseoPropertyAttributes){true, true, true, false}
|
|
3689
|
+
);
|
|
3690
|
+
}
|
|
3691
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[1];
|
|
3692
|
+
oseo_roots_release(context, &descriptor);
|
|
3693
|
+
oseo_roots_release(context, &frame);
|
|
3694
|
+
return result;
|
|
3695
|
+
}
|
|
3696
|
+
|
|
3697
|
+
/*
|
|
3698
|
+
* Object.defineProperties (20.1.2.3) over ObjectDefineProperties
|
|
3699
|
+
* (20.1.2.3.1). The target check precedes every read of the properties
|
|
3700
|
+
* argument, and ToObject runs before the own-key walk, so a nullish
|
|
3701
|
+
* properties argument throws and a primitive is read through the
|
|
3702
|
+
* wrapper it converts to, including a String wrapper's index
|
|
3703
|
+
* properties. The walk visits ordinary own keys in order and keeps the
|
|
3704
|
+
* own enumerable ones, reading each descriptor with Get so an accessor
|
|
3705
|
+
* runs, and converts every descriptor through one ToPropertyDescriptor
|
|
3706
|
+
* body before the first definition mutates the target. An abrupt
|
|
3707
|
+
* completion while collecting therefore leaves the target untouched,
|
|
3708
|
+
* while an abrupt definition keeps every definition that preceded it.
|
|
3709
|
+
*/
|
|
3710
|
+
static OseoResult object_define_properties(
|
|
3711
|
+
OseoContext *context,
|
|
3712
|
+
size_t argument_count,
|
|
3713
|
+
const OseoValue *arguments
|
|
3714
|
+
) {
|
|
3715
|
+
OseoValue object_value = builtin_argument(argument_count, arguments, 0u);
|
|
3716
|
+
if (!is_object(object_value)) {
|
|
3717
|
+
return type_error(
|
|
3718
|
+
context,
|
|
3719
|
+
"Object.defineProperties requires an object target."
|
|
3720
|
+
);
|
|
3721
|
+
}
|
|
3722
|
+
OseoResult converted = oseo_internal_to_object(
|
|
3723
|
+
context,
|
|
3724
|
+
builtin_argument(argument_count, arguments, 1u)
|
|
3725
|
+
);
|
|
3726
|
+
if (converted.status != OSEO_STATUS_NORMAL) return converted;
|
|
3727
|
+
size_t key_count = 0u;
|
|
3728
|
+
/* The key frame roots the properties object, the target, the one
|
|
3729
|
+
* synthesized key string, and the whole key snapshot. The collected
|
|
3730
|
+
* frame holds four slots per collected descriptor, in the order
|
|
3731
|
+
* key, value, getter, setter, and one final slot that roots each
|
|
3732
|
+
* descriptor object while its fields are read. */
|
|
3733
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
3734
|
+
OseoResult result = normal(oseo_undefined());
|
|
3735
|
+
if (is_proxy(converted.value)) {
|
|
3736
|
+
result = proxy_own_key_frame(
|
|
3737
|
+
context, converted.value, &frame, &key_count);
|
|
3738
|
+
} else {
|
|
3739
|
+
key_count = own_key_count(converted.value);
|
|
3740
|
+
if (key_count > SIZE_MAX - 3u) {
|
|
3741
|
+
return failure(
|
|
3742
|
+
context, "OSEO2001", "Own-key snapshot is too large.");
|
|
3743
|
+
}
|
|
3744
|
+
result = oseo_roots_allocate(context, &frame, key_count + 3u);
|
|
3745
|
+
}
|
|
3746
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
3747
|
+
if (key_count > (SIZE_MAX - 1u) / 4u) {
|
|
3748
|
+
oseo_roots_release(context, &frame);
|
|
3749
|
+
return failure(
|
|
3750
|
+
context, "OSEO2001", "Own-key snapshot is too large.");
|
|
3751
|
+
}
|
|
3752
|
+
frame.slots[0] = converted.value;
|
|
3753
|
+
frame.slots[1] = object_value;
|
|
3754
|
+
OseoRootFrame collected_frame = {NULL, NULL, 0u};
|
|
3755
|
+
result = oseo_roots_allocate(
|
|
3756
|
+
context,
|
|
3757
|
+
&collected_frame,
|
|
3758
|
+
4u * key_count + 1u
|
|
3759
|
+
);
|
|
3760
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
3761
|
+
oseo_roots_release(context, &frame);
|
|
3762
|
+
return result;
|
|
3763
|
+
}
|
|
3764
|
+
OseoConvertedDescriptor *records = NULL;
|
|
3765
|
+
if (key_count > 0u) {
|
|
3766
|
+
records = malloc(key_count * sizeof(*records));
|
|
3767
|
+
if (records == NULL) {
|
|
3768
|
+
result = failure(
|
|
3769
|
+
context,
|
|
3770
|
+
"OSEO2001",
|
|
3771
|
+
"Descriptor collection allocation failed."
|
|
3772
|
+
);
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
3776
|
+
!is_proxy(frame.slots[0])) {
|
|
3777
|
+
result = snapshot_own_keys(context, &frame, key_count);
|
|
3778
|
+
}
|
|
3779
|
+
size_t collected = 0u;
|
|
3780
|
+
for (size_t index = 0u;
|
|
3781
|
+
result.status == OSEO_STATUS_NORMAL && index < key_count;
|
|
3782
|
+
index += 1u) {
|
|
3783
|
+
OseoValue key = frame.slots[3u + index];
|
|
3784
|
+
OseoValue ignored = oseo_undefined();
|
|
3785
|
+
OseoPropertyAttributes attributes = {false, false, false, false};
|
|
3786
|
+
OseoValue ignored_getter = oseo_undefined();
|
|
3787
|
+
OseoValue ignored_setter = oseo_undefined();
|
|
3788
|
+
/* A getter an earlier key ran may have removed this key or made
|
|
3789
|
+
* it non-enumerable, so the descriptor is re-read per key. */
|
|
3790
|
+
bool exists = false;
|
|
3791
|
+
if (is_proxy(frame.slots[0])) {
|
|
3792
|
+
result = oseo_internal_proxy_get_own_property(
|
|
3793
|
+
context,
|
|
3794
|
+
frame.slots[0],
|
|
3795
|
+
key,
|
|
3796
|
+
&exists,
|
|
3797
|
+
&ignored,
|
|
3798
|
+
&attributes,
|
|
3799
|
+
&ignored_getter,
|
|
3800
|
+
&ignored_setter
|
|
3801
|
+
);
|
|
3802
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3803
|
+
} else {
|
|
3804
|
+
result = own_property_query(
|
|
3805
|
+
context,
|
|
3806
|
+
frame.slots[0],
|
|
3807
|
+
key,
|
|
3808
|
+
&exists,
|
|
3809
|
+
&ignored,
|
|
3810
|
+
&attributes,
|
|
3811
|
+
&ignored_getter,
|
|
3812
|
+
&ignored_setter
|
|
3813
|
+
);
|
|
3814
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3815
|
+
}
|
|
3816
|
+
if (!exists || !attributes.enumerable) {
|
|
3817
|
+
continue;
|
|
3818
|
+
}
|
|
3819
|
+
result = oseo_object_get(context, frame.slots[0], key);
|
|
3820
|
+
collected_frame.slots[4u * key_count] = result.value;
|
|
3821
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3822
|
+
if (!is_object(result.value)) {
|
|
3823
|
+
result = type_error(
|
|
3824
|
+
context,
|
|
3825
|
+
"A property descriptor must be an object."
|
|
3826
|
+
);
|
|
3827
|
+
break;
|
|
3828
|
+
}
|
|
3829
|
+
OseoValue *slots = &collected_frame.slots[4u * collected];
|
|
3830
|
+
slots[0] = key;
|
|
3831
|
+
result = oseo_internal_to_property_descriptor(
|
|
3832
|
+
context,
|
|
3833
|
+
collected_frame.slots[4u * key_count],
|
|
3834
|
+
&slots[1],
|
|
3835
|
+
&slots[2],
|
|
3836
|
+
&slots[3],
|
|
3837
|
+
&records[collected]
|
|
3838
|
+
);
|
|
3839
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
3840
|
+
collected += 1u;
|
|
3841
|
+
}
|
|
3842
|
+
const char *refusal = NULL;
|
|
3843
|
+
for (size_t index = 0u;
|
|
3844
|
+
result.status == OSEO_STATUS_NORMAL && index < collected;
|
|
3845
|
+
index += 1u) {
|
|
3846
|
+
OseoValue *slots = &collected_frame.slots[4u * index];
|
|
3847
|
+
result = oseo_internal_define_converted_property(
|
|
3848
|
+
context,
|
|
3849
|
+
frame.slots[1],
|
|
3850
|
+
slots[0],
|
|
3851
|
+
&records[index],
|
|
3852
|
+
slots[1],
|
|
3853
|
+
slots[2],
|
|
3854
|
+
slots[3],
|
|
3855
|
+
&refusal
|
|
3856
|
+
);
|
|
3857
|
+
if (result.status == OSEO_STATUS_NORMAL && refusal != NULL) {
|
|
3858
|
+
result = type_error(context, refusal);
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[1];
|
|
3862
|
+
free(records);
|
|
3863
|
+
oseo_roots_release(context, &collected_frame);
|
|
3864
|
+
oseo_roots_release(context, &frame);
|
|
3865
|
+
return result;
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
OseoResult oseo_object_builtin_keys(
|
|
3869
|
+
OseoContext *context,
|
|
3870
|
+
size_t argument_count,
|
|
3871
|
+
const OseoValue *arguments
|
|
3872
|
+
) {
|
|
3873
|
+
return object_enumerable_own_properties(
|
|
3874
|
+
context, argument_count, arguments, OSEO_ENUMERABLE_KEYS);
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3877
|
+
OseoResult oseo_object_builtin_set_prototype_of(
|
|
3878
|
+
OseoContext *context,
|
|
3879
|
+
size_t argument_count,
|
|
3880
|
+
const OseoValue *arguments
|
|
3881
|
+
) {
|
|
3882
|
+
OseoValue object_value = builtin_argument(
|
|
3883
|
+
argument_count,
|
|
3884
|
+
arguments,
|
|
3885
|
+
0u
|
|
3886
|
+
);
|
|
3887
|
+
OseoValue prototype = builtin_argument(argument_count, arguments, 1u);
|
|
3888
|
+
if (is_nullish(object_value) ||
|
|
3889
|
+
(tag_of(prototype) != OSEO_TAG_NULL && !is_object(prototype))) {
|
|
3890
|
+
return type_error(
|
|
3891
|
+
context,
|
|
3892
|
+
"Object.setPrototypeOf requires an object prototype."
|
|
3893
|
+
);
|
|
3894
|
+
}
|
|
3895
|
+
if (!is_object(object_value)) return normal(object_value);
|
|
3896
|
+
return oseo_object_set_prototype(
|
|
3897
|
+
context,
|
|
3898
|
+
object_value,
|
|
3899
|
+
prototype
|
|
3900
|
+
);
|
|
3901
|
+
}
|