@@ -178,10 +178,75 @@ ecma_builtin_object_object_get_own_property_names (ecma_value_t this_arg __attr_
178
178
* Returned value must be freed with ecma_free_completion_value.
179
179
*/
180
180
static ecma_completion_value_t
181
- ecma_builtin_object_object_seal (ecma_value_t this_arg, /* *< 'this' argument */
181
+ ecma_builtin_object_object_seal (ecma_value_t this_arg __attr_unused___ , /* *< 'this' argument */
182
182
ecma_value_t arg) /* *< routine's argument */
183
183
{
184
- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
184
+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
185
+
186
+ // 1.
187
+ if (!ecma_is_value_object (arg))
188
+ {
189
+ ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
190
+ }
191
+ else
192
+ {
193
+ // 2.
194
+ ecma_object_t *obj_p = ecma_get_object_from_value (arg);
195
+
196
+ ecma_property_t *property_p;
197
+ for (property_p = ecma_get_property_list (obj_p);
198
+ property_p != NULL && ecma_is_completion_value_empty (ret_value);
199
+ property_p = ECMA_GET_POINTER (ecma_property_t , property_p->next_property_p ))
200
+ {
201
+ ecma_string_t *property_name_p;
202
+
203
+ if (property_p->type == ECMA_PROPERTY_NAMEDDATA)
204
+ {
205
+ property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t ,
206
+ property_p->u .named_data_property .name_p );
207
+ }
208
+ else if (property_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
209
+ {
210
+ property_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t ,
211
+ property_p->u .named_accessor_property .name_p );
212
+ }
213
+ else
214
+ {
215
+ continue ;
216
+ }
217
+
218
+ // 2.a
219
+ ecma_property_descriptor_t prop_desc = ecma_get_property_descriptor_from_property (property_p);
220
+
221
+ // 2.b
222
+ if (ecma_is_property_configurable (property_p))
223
+ {
224
+ prop_desc.is_configurable = false ;
225
+ }
226
+
227
+ // 2.c
228
+ ECMA_TRY_CATCH (define_own_prop_ret,
229
+ ecma_op_object_define_own_property (obj_p,
230
+ property_name_p,
231
+ &prop_desc,
232
+ true ),
233
+ ret_value);
234
+ ECMA_FINALIZE (define_own_prop_ret);
235
+
236
+ ecma_free_property_descriptor (&prop_desc);
237
+ }
238
+
239
+ if (ecma_is_completion_value_empty (ret_value))
240
+ {
241
+ // 3.
242
+ ecma_set_object_extensible (obj_p, false );
243
+
244
+ // 4.
245
+ ret_value = ecma_make_normal_completion_value (ecma_copy_value (arg, true ));
246
+ }
247
+ }
248
+
249
+ return ret_value;
185
250
} /* ecma_builtin_object_object_seal */
186
251
187
252
/* *
@@ -240,10 +305,59 @@ ecma_builtin_object_object_prevent_extensions (ecma_value_t this_arg __attr_unus
240
305
* Returned value must be freed with ecma_free_completion_value.
241
306
*/
242
307
static ecma_completion_value_t
243
- ecma_builtin_object_object_is_sealed (ecma_value_t this_arg, /* *< 'this' argument */
308
+ ecma_builtin_object_object_is_sealed (ecma_value_t this_arg __attr_unused___ , /* *< 'this' argument */
244
309
ecma_value_t arg) /* *< routine's argument */
245
310
{
246
- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
311
+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
312
+
313
+ // 1.
314
+ if (!ecma_is_value_object (arg))
315
+ {
316
+ ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
317
+ }
318
+ else
319
+ {
320
+ ecma_object_t *obj_p = ecma_get_object_from_value (arg);
321
+ ecma_property_t *property_p;
322
+
323
+ // This will be the result if the other steps doesn't change it.
324
+ bool sealed = false ;
325
+
326
+ // 3.
327
+ // The pseudo code contains multiple early return but this way we get the same
328
+ // result.
329
+ if (!ecma_get_object_extensible (obj_p))
330
+ {
331
+ sealed = true ;
332
+ }
333
+
334
+ // 2.
335
+ for (property_p = ecma_get_property_list (obj_p);
336
+ property_p != NULL && sealed;
337
+ property_p = ECMA_GET_POINTER (ecma_property_t , property_p->next_property_p ))
338
+ {
339
+ if (property_p->type == ECMA_PROPERTY_INTERNAL)
340
+ {
341
+ continue ;
342
+ }
343
+
344
+ JERRY_ASSERT (property_p->type == ECMA_PROPERTY_NAMEDDATA || property_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
345
+
346
+ // 2.b
347
+ if (ecma_is_property_configurable (property_p))
348
+ {
349
+ sealed = false ;
350
+ break ;
351
+ }
352
+ }
353
+
354
+ // 4.
355
+ ret_value = ecma_make_simple_completion_value (sealed
356
+ ? ECMA_SIMPLE_VALUE_TRUE
357
+ : ECMA_SIMPLE_VALUE_FALSE);
358
+ }
359
+
360
+ return ret_value;
247
361
} /* ecma_builtin_object_object_is_sealed */
248
362
249
363
/* *
0 commit comments