Continue working on realms (#4356)

- Rework symbols to have the same value across realms
- Support realms for native functions
- Support test262
- Use new.target realms for constructing intrinsics

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg 2020-12-09 17:44:21 +01:00 committed by GitHub
parent df92c86ecf
commit cc1e8d2dee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 593 additions and 284 deletions

View File

@ -164,10 +164,10 @@ Container object types:
Well-known symbols:
- JERRY_SYMBOL_ASYNC_ITERATOR - @@asyncIterator well-known symbol
- JERRY_SYMBOL_HAS_INSTANCE - @@hasInstance well-known symbol
- JERRY_SYMBOL_IS_CONCAT_SPREADABLE - @@isConcatSpreadable well-known symbol
- JERRY_SYMBOL_ITERATOR - @@iterator well-known symbol
- JERRY_SYMBOL_ASYNC_ITERATOR - @@asyncIterator well-known symbol
- JERRY_SYMBOL_MATCH - @@match well-known symbol
- JERRY_SYMBOL_REPLACE - @@replace well-known symbol
- JERRY_SYMBOL_SEARCH - @@search well-known symbol
@ -9118,6 +9118,59 @@ main (int argc, char** argv)
- [jerry_construct_object](#jerry_construct_object)
## jerry_set_realm
**Summary**
Replaces the currently active realm (including the global object) with another realm.
The replacement should be temporary, and the original realm must be restored after
the tasks are completed. During the replacement, the realm must be referenced
by the application (i.e. the gc must not reclaim it). This is also true to
the returned previously active realm, so there is no need to free the value
after the restoration. The function can only fail if realms are not supported
or the passed argument is not a realm. In this case the returned exception must
be freed by [jerry_release_value](#jerry_release_value).
This function is useful to parse a script, create a native function, load a snapshot
or create an exception in another realm. Each ECMAScript code runs in the realm
which was active when the code was parsed or loaded regardless of the current realm.
*Notes*:
- This feature depends on build option (`JERRY_BUILTIN_REALMS`) and can be checked
in runtime with the `JERRY_FEATURE_REALM` feature enum value,
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
**Prototype**
```c
jerry_value_t
jerry_set_realm (jerry_value_t realm_value);
```
- `realm_value` - the new realm value
- return
- previous realm value - if the passed value is a realm
- exception - otherwise
*New in version [[NEXT_RELEASE]]*.
**Example**
```c
{
jerry_value_t realm_value = jerry_create_realm ();
jerry_value_t old_realm = jerry_set_realm (realm_value);
... // usage of the realm
jerry_set_realm (old_realm);
}
```
**See also**
- [jerry_create_realm](#jerry_create_realm)
# ArrayBuffer and TypedArray functions
These APIs all depend on the es.next profile.

View File

@ -4204,7 +4204,7 @@ jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol) /**< jerry_well_k
jerry_assert_api_available ();
#if ENABLED (JERRY_ESNEXT)
lit_magic_string_id_t id = (lit_magic_string_id_t) (LIT_GLOBAL_SYMBOL__FISRT + symbol);
lit_magic_string_id_t id = (lit_magic_string_id_t) (LIT_GLOBAL_SYMBOL__FIRST + symbol);
if (!LIT_IS_GLOBAL_SYMBOL (id))
{
@ -4564,6 +4564,44 @@ jerry_get_new_target (void)
#endif /* ENABLED (JERRY_ESNEXT) */
} /* jerry_get_new_target */
/**
* Replaces the currently active realm with another realm.
*
* The replacement should be temporary, and the original realm must be
* restored after the tasks are completed. During the replacement, the
* realm must be referenced by the application (i.e. the gc must not
* reclaim it). This is also true to the returned previously active
* realm, so there is no need to free the value after the restoration.
*
* @return previous realm value - if the passed value is a realm
* exception - otherwise
*/
jerry_value_t
jerry_set_realm (jerry_value_t realm_value) /**< jerry api value */
{
jerry_assert_api_available ();
#if ENABLED (JERRY_BUILTIN_REALMS)
if (ecma_is_value_object (realm_value))
{
ecma_object_t *object_p = ecma_get_object_from_value (realm_value);
if (ecma_get_object_is_builtin (object_p)
&& ecma_builtin_is_global (object_p))
{
ecma_global_object_t *previous_global_object_p = JERRY_CONTEXT (global_object_p);
JERRY_CONTEXT (global_object_p) = (ecma_global_object_t *) object_p;
return ecma_make_object_value ((ecma_object_t *) previous_global_object_p);
}
}
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Passed argument is not a realm")));
#else /* !ENABLED (JERRY_BUILTIN_REALMS) */
JERRY_UNUSED (realm_value);
return jerry_throw (ecma_raise_reference_error (ECMA_ERR_MSG ("Realm is not available")));
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
} /* jerry_set_realm */
/**
* Check if the given value is an ArrayBuffer object.
*

View File

@ -936,13 +936,25 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
break;
}
#if ENABLED (JERRY_ESNEXT)
#if ENABLED (JERRY_ESNEXT) || ENABLED (JERRY_BUILTIN_REALMS)
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
{
#endif /* ENABLED (JERRY_ESNEXT) || ENABLED (JERRY_BUILTIN_REALMS) */
if (!ecma_get_object_is_builtin (object_p))
{
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p;
ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
native_function_p->realm_value));
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
break;
}
#if ENABLED (JERRY_ESNEXT)
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
if (ecma_get_object_is_builtin (object_p)
&& ext_func_p->u.built_in.id == ECMA_BUILTIN_ID_HANDLER)
if (ext_func_p->u.built_in.id == ECMA_BUILTIN_ID_HANDLER)
{
switch (ext_func_p->u.built_in.routine_id)
{
@ -1005,10 +1017,12 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
}
}
}
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_ESNEXT) || ENABLED (JERRY_BUILTIN_REALMS)
break;
}
#endif /* ENABLED (JERRY_ESNEXT) */
#endif /* ENABLED (JERRY_ESNEXT) || ENABLED (JERRY_BUILTIN_REALMS) */
default:
{
break;
@ -1496,6 +1510,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
}
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
{
ext_object_size = sizeof (ecma_native_function_t);
break;
}
case ECMA_OBJECT_TYPE_CLASS:

View File

@ -994,8 +994,6 @@ typedef struct
jmem_cpointer_tag_t target_function; /**< target function */
ecma_value_t args_len_or_this; /**< length of arguments or this value */
} bound_function;
ecma_native_handler_t external_handler_cb; /**< external function */
} u;
} ecma_extended_object_t;
@ -1014,6 +1012,18 @@ typedef struct
#define ECMA_BUILTIN_IS_EXTENDED_BUILT_IN(object_type) \
((object_type) == ECMA_OBJECT_TYPE_CLASS || (object_type) == ECMA_OBJECT_TYPE_ARRAY)
/**
* Description of native functions
*/
typedef struct
{
ecma_extended_object_t extended_object; /**< extended object part */
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_value_t realm_value; /**< realm value */
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
ecma_native_handler_t native_handler_cb; /**< external function */
} ecma_native_function_t;
/**
* Flags for array.length_prop_and_hole_count
*/

View File

@ -88,6 +88,18 @@ ecma_finalize (void)
}
while (JERRY_CONTEXT (ecma_gc_new_objects) != 0);
#if ENABLED (JERRY_ESNEXT)
jmem_cpointer_t *global_symbols_cp = JERRY_CONTEXT (global_symbols_cp);
for (uint32_t i = 0; i < ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT; i++)
{
if (global_symbols_cp[i] != JMEM_CP_NULL)
{
ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (ecma_string_t, global_symbols_cp[i]));
}
}
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_finalize_lit_storage ();
} /* ecma_finalize */

View File

@ -190,12 +190,12 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
magic_string_id \
},
#if ENABLED (JERRY_ESNEXT)
#define SYMBOL_VALUE(symbol, desc_magic_string_id) \
#define SYMBOL_VALUE(name, symbol) \
{ \
symbol, \
name, \
ECMA_BUILTIN_PROPERTY_SYMBOL, \
ECMA_PROPERTY_FIXED, \
desc_magic_string_id \
symbol \
},
#define INTRINSIC_PROPERTY(name, magic_string_id, prop_attributes) \
{ \

View File

@ -21,53 +21,6 @@
#if ENABLED (JERRY_ESNEXT)
/* ECMA-262 v10, 19.4.2.1 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR,
LIT_MAGIC_STRING_ASYNC_ITERATOR)
/* ECMA-262 v6, 19.4.2.2 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_HAS_INSTANCE,
LIT_MAGIC_STRING_HAS_INSTANCE)
/* ECMA-262 v6, 19.4.2.3 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE,
LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE)
/* ECMA-262 v6, 19.4.2.4 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_ITERATOR,
LIT_MAGIC_STRING_ITERATOR)
/* ECMA-262 v6, 19.4.2.6 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_MATCH,
LIT_MAGIC_STRING_MATCH)
/* ECMA-262 v6, 19.4.2.8 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_REPLACE,
LIT_MAGIC_STRING_REPLACE)
/* ECMA-262 v6, 19.4.2.9 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_SEARCH,
LIT_MAGIC_STRING_SEARCH)
/* ECMA-262 v6, 19.4.2.10 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_SPECIES,
LIT_MAGIC_STRING_SPECIES)
/* ECMA-262 v6, 19.4.2.11 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_SPLIT,
LIT_MAGIC_STRING_SPLIT)
/* ECMA-262 v6, 19.4.2.12 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_TO_PRIMITIVE,
LIT_MAGIC_STRING_TO_PRIMITIVE)
/* ECMA-262 v6, 19.4.2.13 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
LIT_MAGIC_STRING_TO_STRING_TAG)
/* ECMA-262 v6, 19.4.2.14 */
SYMBOL_VALUE (LIT_GLOBAL_SYMBOL_UNSCOPABLES,
LIT_MAGIC_STRING_UNSCOPABLES)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, ECMA_INTRINSIC_ARRAY_PROTOTYPE_VALUES, 0, 0)

View File

@ -42,64 +42,52 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_PROPERTY_FIXED)
/* ECMA-262 v10, 19.4.2.1 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_ASYNC_ITERATOR,
LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_ASYNC_ITERATOR,
LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR)
/* ECMA-262 v6, 19.4.2.2 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_HAS_INSTANCE,
LIT_GLOBAL_SYMBOL_HAS_INSTANCE,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_HAS_INSTANCE,
LIT_GLOBAL_SYMBOL_HAS_INSTANCE)
/* ECMA-262 v6, 19.4.2.3 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE,
LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE,
LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE)
/* ECMA-262 v6, 19.4.2.4 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_ITERATOR,
LIT_GLOBAL_SYMBOL_ITERATOR,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_ITERATOR,
LIT_GLOBAL_SYMBOL_ITERATOR)
/* ECMA-262 v6, 19.4.2.6 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_MATCH,
LIT_GLOBAL_SYMBOL_MATCH,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_MATCH,
LIT_GLOBAL_SYMBOL_MATCH)
/* ECMA-262 v6, 19.4.2.8 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_REPLACE,
LIT_GLOBAL_SYMBOL_REPLACE,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_REPLACE,
LIT_GLOBAL_SYMBOL_REPLACE)
/* ECMA-262 v6, 19.4.2.9 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_SEARCH,
LIT_GLOBAL_SYMBOL_SEARCH,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_SEARCH,
LIT_GLOBAL_SYMBOL_SEARCH)
/* ECMA-262 v6, 19.4.2.10 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_SPECIES,
LIT_GLOBAL_SYMBOL_SPECIES,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_SPECIES,
LIT_GLOBAL_SYMBOL_SPECIES)
/* ECMA-262 v6, 19.4.2.11 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_SPLIT,
LIT_GLOBAL_SYMBOL_SPLIT,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_SPLIT,
LIT_GLOBAL_SYMBOL_SPLIT)
/* ECMA-262 v6, 19.4.2.12 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_PRIMITIVE,
LIT_GLOBAL_SYMBOL_TO_PRIMITIVE,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_TO_PRIMITIVE,
LIT_GLOBAL_SYMBOL_TO_PRIMITIVE)
/* ECMA-262 v6, 19.4.2.13 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_TO_STRING_TAG,
LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_TO_STRING_TAG,
LIT_GLOBAL_SYMBOL_TO_STRING_TAG)
/* ECMA-262 v6, 19.4.2.14 */
INTRINSIC_PROPERTY (LIT_MAGIC_STRING_UNSCOPABLES,
LIT_GLOBAL_SYMBOL_UNSCOPABLES,
ECMA_PROPERTY_FIXED)
SYMBOL_VALUE (LIT_MAGIC_STRING_UNSCOPABLES,
LIT_GLOBAL_SYMBOL_UNSCOPABLES)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */

View File

@ -668,6 +668,8 @@ ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on
return ECMA_GET_NON_NULL_POINTER (ecma_object_t, *builtin_p);
} /* ecma_builtin_get */
#if ENABLED (JERRY_BUILTIN_REALMS)
/**
* Get reference to specified built-in object using the realm provided by another built-in object
*
@ -676,14 +678,12 @@ ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on
*
* @return pointer to the object's instance
*/
static ecma_object_t *
ecma_builtin_get_from_realm (ecma_object_t *builtin_object_p, /**< built-in object */
ecma_object_t *
ecma_builtin_get_from_realm (ecma_global_object_t *global_object_p, /**< global object */
ecma_builtin_id_t builtin_id) /**< id of built-in to check on */
{
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_OBJECTS_COUNT);
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_global_object_t *global_object_p = ecma_builtin_get_realm (builtin_object_p);
jmem_cpointer_t *builtin_p = global_object_p->builtin_objects + builtin_id;
if (JERRY_UNLIKELY (*builtin_p == JMEM_CP_NULL))
@ -692,11 +692,31 @@ ecma_builtin_get_from_realm (ecma_object_t *builtin_object_p, /**< built-in obje
}
return ECMA_GET_NON_NULL_POINTER (ecma_object_t, *builtin_p);
} /* ecma_builtin_get_from_realm */
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
/**
* Get reference to specified built-in object using the realm provided by another built-in object
*
* Note:
* Does not increase the reference counter.
*
* @return pointer to the object's instance
*/
static inline ecma_object_t * JERRY_ATTR_ALWAYS_INLINE
ecma_builtin_get_from_builtin (ecma_object_t *builtin_object_p, /**< built-in object */
ecma_builtin_id_t builtin_id) /**< id of built-in to check on */
{
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_OBJECTS_COUNT);
#if ENABLED (JERRY_BUILTIN_REALMS)
return ecma_builtin_get_from_realm (ecma_builtin_get_realm (builtin_object_p), builtin_id);
#else /* !ENABLED (JERRY_BUILTIN_REALMS) */
JERRY_UNUSED (builtin_object_p);
return ecma_builtin_get (builtin_id);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
} /* ecma_builtin_get_from_realm */
} /* ecma_builtin_get_from_builtin */
/**
* Construct a Function object for specified built-in routine
@ -712,8 +732,8 @@ ecma_builtin_make_function_object_for_routine (ecma_object_t *builtin_object_p,
uint32_t routine_index, /**< property descriptor index of routine */
uint8_t flags) /**< see also: ecma_builtin_routine_flags */
{
ecma_object_t *prototype_obj_p = ecma_builtin_get_from_realm (builtin_object_p,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
ecma_object_t *prototype_obj_p = ecma_builtin_get_from_builtin (builtin_object_p,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
size_t ext_object_size = sizeof (ecma_extended_object_t);
@ -1169,20 +1189,14 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
#if ENABLED (JERRY_ESNEXT)
case ECMA_BUILTIN_PROPERTY_SYMBOL:
{
ecma_string_t *symbol_dot_p = ecma_get_magic_string (LIT_MAGIC_STRING_SYMBOL_DOT_UL);
ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) curr_property_p->value);
ecma_string_t *descriptor_p = ecma_concat_ecma_strings (symbol_dot_p, name_p);
lit_magic_string_id_t symbol_id = (lit_magic_string_id_t) curr_property_p->value;
ecma_string_t *symbol_p = ecma_new_symbol_from_descriptor_string (ecma_make_string_value (descriptor_p));
lit_magic_string_id_t symbol_id = (lit_magic_string_id_t) curr_property_p->magic_string_id;
symbol_p->u.hash = (uint16_t) ((symbol_id << ECMA_GLOBAL_SYMBOL_SHIFT) | ECMA_GLOBAL_SYMBOL_FLAG);
value = ecma_make_symbol_value (symbol_p);
value = ecma_make_symbol_value (ecma_op_get_global_symbol (symbol_id));
break;
}
case ECMA_BUILTIN_PROPERTY_INTRINSIC_PROPERTY:
{
ecma_object_t *intrinsic_object_p = ecma_builtin_get_from_realm (object_p, ECMA_BUILTIN_ID_INTRINSIC_OBJECT);
ecma_object_t *intrinsic_object_p = ecma_builtin_get_from_builtin (object_p, ECMA_BUILTIN_ID_INTRINSIC_OBJECT);
value = ecma_op_object_get_by_magic_id (intrinsic_object_p, (lit_magic_string_id_t) curr_property_p->value);
break;
}
@ -1191,8 +1205,8 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
is_accessor = true;
uint16_t getter_id = ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID (curr_property_p->value);
uint16_t setter_id = ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID (curr_property_p->value);
getter_p = ecma_builtin_get_from_realm (object_p, getter_id);
setter_p = ecma_builtin_get_from_realm (object_p, setter_id);
getter_p = ecma_builtin_get_from_builtin (object_p, getter_id);
setter_p = ecma_builtin_get_from_builtin (object_p, setter_id);
ecma_ref_object (getter_p);
ecma_ref_object (setter_p);
break;
@ -1201,7 +1215,7 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
case ECMA_BUILTIN_PROPERTY_OBJECT:
{
ecma_object_t *builtin_object_p;
builtin_object_p = ecma_builtin_get_from_realm (object_p, (ecma_builtin_id_t) curr_property_p->value);
builtin_object_p = ecma_builtin_get_from_builtin (object_p, (ecma_builtin_id_t) curr_property_p->value);
ecma_ref_object (builtin_object_p);
value = ecma_make_object_value (builtin_object_p);
break;

View File

@ -56,6 +56,12 @@ typedef enum
*/
#define ECMA_BUILTIN_ID_HANDLER ECMA_BUILTIN_ID__COUNT
/**
* Number of global symbols
*/
#define ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT \
(LIT_GLOBAL_SYMBOL__LAST - LIT_GLOBAL_SYMBOL__FIRST + 1)
#endif /* ENABLED (JERRY_ESNEXT) */
/**
@ -143,4 +149,9 @@ ecma_builtin_get_global (void);
bool
ecma_builtin_function_is_routine (ecma_object_t *func_obj_p);
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_object_t *
ecma_builtin_get_from_realm (ecma_global_object_t *global_object_p, ecma_builtin_id_t builtin_id);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
#endif /* !ECMA_BUILTINS_H */

View File

@ -708,13 +708,22 @@ ecma_op_array_species_create (ecma_object_t *original_array_p, /**< The object f
return NULL;
}
if (ecma_is_constructor (constructor)
&& ecma_get_object_from_value (constructor) == ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY))
#if ENABLED (JERRY_BUILTIN_REALMS)
if (ecma_is_constructor (constructor))
{
ecma_free_value (constructor);
constructor = ECMA_VALUE_UNDEFINED;
ecma_object_t *constructor_p = ecma_get_object_from_value (constructor);
ecma_global_object_t *global_object_p = ecma_op_function_get_function_realm (constructor_p);
if ((ecma_object_t *) global_object_p != ecma_builtin_get_global ()
&& constructor_p == ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_ARRAY))
{
ecma_deref_object (constructor_p);
constructor = ECMA_VALUE_UNDEFINED;
}
}
else if (ecma_is_value_object (constructor))
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
if (ecma_is_value_object (constructor))
{
ecma_object_t *ctor_object_p = ecma_get_object_from_value (constructor);
constructor = ecma_op_object_get_by_symbol_id (ctor_object_p, LIT_GLOBAL_SYMBOL_SPECIES);

View File

@ -672,10 +672,9 @@ ecma_op_create_external_function_object (ecma_native_handler_t handler_cb) /**<
{
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
ecma_object_t *function_obj_p;
function_obj_p = ecma_create_object (prototype_obj_p,
sizeof (ecma_extended_object_t),
ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
ecma_object_t *function_obj_p = ecma_create_object (prototype_obj_p,
sizeof (ecma_native_function_t),
ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
/*
* [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_NATIVE_FUNCTION type.
@ -683,8 +682,12 @@ ecma_op_create_external_function_object (ecma_native_handler_t handler_cb) /**<
* See also: ecma_object_get_class_name
*/
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) function_obj_p;
ext_func_obj_p->u.external_handler_cb = handler_cb;
ecma_native_function_t *native_function_p = (ecma_native_function_t *) function_obj_p;
#if ENABLED (JERRY_BUILTIN_REALMS)
ECMA_SET_INTERNAL_VALUE_POINTER (native_function_p->realm_value,
ecma_builtin_get_global ());
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
native_function_p->native_handler_cb = handler_cb;
return function_obj_p;
} /* ecma_op_create_external_function_object */
@ -782,6 +785,39 @@ ecma_op_function_get_realm (const ecma_compiled_code_t *bytecode_header_p) /**<
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
} /* ecma_op_function_get_realm */
/**
* Get realm from a function
*
* Note:
* Does not increase the reference counter.
*
* @return realm (global) object
*/
ecma_global_object_t *
ecma_op_function_get_function_realm (ecma_object_t *func_obj_p) /**< function object */
{
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
{
ecma_extended_object_t *ext_function_obj_p = (ecma_extended_object_t *) func_obj_p;
const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_function_obj_p);
ecma_value_t realm_value = ecma_op_function_get_realm (bytecode_data_p);
return (ecma_global_object_t *) ecma_get_object_from_value (realm_value);
}
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
if (ecma_get_object_is_builtin (func_obj_p))
{
ecma_extended_object_t *ext_function_obj_p = (ecma_extended_object_t *) func_obj_p;
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t,
ext_function_obj_p->u.built_in.realm_value);
}
ecma_native_function_t *native_function_p = (ecma_native_function_t *) func_obj_p;
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t,
native_function_p->realm_value);
} /* ecma_op_function_get_function_realm */
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
/**
@ -986,7 +1022,11 @@ ecma_op_get_prototype_from_constructor (ecma_object_t *ctor_obj_p, /**< construc
}
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
#if ENABLED (JERRY_BUILTIN_REALMS)
proto_obj_p = ecma_builtin_get_from_realm (ecma_op_function_get_function_realm (ctor_obj_p), default_proto_id);
#else /* !ENABLED (JERRY_BUILTIN_REALMS) */
proto_obj_p = ecma_builtin_get (default_proto_id);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
ecma_ref_object (proto_obj_p);
}
else
@ -1171,14 +1211,15 @@ ecma_op_function_call_native (ecma_object_t *func_obj_p, /**< Function object */
{
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
if (ecma_get_object_is_builtin (func_obj_p))
{
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p);
ecma_value_t realm_value = ((ecma_extended_object_t *) func_obj_p)->u.built_in.realm_value;
JERRY_CONTEXT (global_object_p) = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, realm_value);
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
JERRY_CONTEXT (global_object_p) = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t,
ext_func_obj_p->u.built_in.realm_value);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
ecma_value_t ret_value = ecma_builtin_dispatch_call (func_obj_p,
@ -1192,11 +1233,23 @@ ecma_op_function_call_native (ecma_object_t *func_obj_p, /**< Function object */
return ret_value;
}
JERRY_ASSERT (ext_func_obj_p->u.external_handler_cb != NULL);
ecma_value_t ret_value = ext_func_obj_p->u.external_handler_cb (ecma_make_object_value (func_obj_p),
this_arg_value,
arguments_list_p,
arguments_list_len);
ecma_native_function_t *native_function_p = (ecma_native_function_t *) func_obj_p;
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p);
JERRY_CONTEXT (global_object_p) = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t,
native_function_p->realm_value);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
JERRY_ASSERT (native_function_p->native_handler_cb != NULL);
ecma_value_t ret_value = native_function_p->native_handler_cb (ecma_make_object_value (func_obj_p),
this_arg_value,
arguments_list_p,
arguments_list_len);
#if ENABLED (JERRY_BUILTIN_REALMS)
JERRY_CONTEXT (global_object_p) = saved_global_object_p;
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
if (JERRY_UNLIKELY (ecma_is_value_error_reference (ret_value)))
{
ecma_raise_error_from_error_reference (ret_value);
@ -1573,6 +1626,26 @@ ecma_op_lazy_instantiate_prototype_object (ecma_object_t *object_p) /**< the fun
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_global_object_t *global_object_p;
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
{
const ecma_compiled_code_t *bytecode_data_p;
bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p);
ecma_value_t realm_value = ecma_op_function_get_realm (bytecode_data_p);
global_object_p = (ecma_global_object_t *) ecma_get_object_from_value (realm_value);
}
else
{
ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p;
global_object_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t,
native_function_p->realm_value);
}
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
/* ECMA-262 v5, 13.2, 16-18 */
ecma_object_t *proto_object_p = NULL;
@ -1590,17 +1663,29 @@ ecma_op_lazy_instantiate_prototype_object (ecma_object_t *object_p) /**< the fun
if (CBC_FUNCTION_GET_TYPE (byte_code_p->status_flags) == CBC_FUNCTION_GENERATOR)
{
proto_object_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE),
0,
ECMA_OBJECT_TYPE_GENERAL);
ecma_object_t *prototype_p;
#if ENABLED (JERRY_BUILTIN_REALMS)
prototype_p = ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE);
#else /* !ENABLED (JERRY_BUILTIN_REALMS) */
prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
proto_object_p = ecma_create_object (prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL);
init_constructor = false;
}
if (CBC_FUNCTION_GET_TYPE (byte_code_p->status_flags) == CBC_FUNCTION_ASYNC_GENERATOR)
{
proto_object_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE),
0,
ECMA_OBJECT_TYPE_GENERAL);
ecma_object_t *prototype_p;
#if ENABLED (JERRY_BUILTIN_REALMS)
prototype_p = ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE);
#else /* !ENABLED (JERRY_BUILTIN_REALMS) */
prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_GENERATOR_PROTOTYPE);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
proto_object_p = ecma_create_object (prototype_p, 0, ECMA_OBJECT_TYPE_GENERAL);
init_constructor = false;
}
}
@ -1610,7 +1695,15 @@ ecma_op_lazy_instantiate_prototype_object (ecma_object_t *object_p) /**< the fun
if (proto_object_p == NULL)
#endif /* ENABLED (JERRY_ESNEXT) */
{
proto_object_p = ecma_op_create_object_object_noarg ();
ecma_object_t *prototype_p;
#if ENABLED (JERRY_BUILTIN_REALMS)
prototype_p = ecma_builtin_get_from_realm (global_object_p, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
#else /* !ENABLED (JERRY_BUILTIN_REALMS) */
prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
proto_object_p = ecma_op_create_object_object_noarg_and_set_prototype (prototype_p);
}
/* 17. */

View File

@ -59,6 +59,9 @@ ecma_op_function_get_compiled_code (ecma_extended_object_t *function_p);
#if ENABLED (JERRY_BUILTIN_REALMS)
ecma_value_t
ecma_op_function_get_realm (const ecma_compiled_code_t *bytecode_header_p);
ecma_global_object_t *
ecma_op_function_get_function_realm (ecma_object_t *func_obj_p);
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
ecma_value_t

View File

@ -882,6 +882,29 @@ ecma_op_object_get_by_magic_id (ecma_object_t *object_p, /**< the object */
} /* ecma_op_object_get_by_magic_id */
#if ENABLED (JERRY_ESNEXT)
/**
* Descriptor string for each global symbol
*/
static const uint16_t ecma_global_symbol_descriptions[] =
{
LIT_MAGIC_STRING_ASYNC_ITERATOR,
LIT_MAGIC_STRING_HAS_INSTANCE,
LIT_MAGIC_STRING_IS_CONCAT_SPREADABLE,
LIT_MAGIC_STRING_ITERATOR,
LIT_MAGIC_STRING_MATCH,
LIT_MAGIC_STRING_REPLACE,
LIT_MAGIC_STRING_SEARCH,
LIT_MAGIC_STRING_SPECIES,
LIT_MAGIC_STRING_SPLIT,
LIT_MAGIC_STRING_TO_PRIMITIVE,
LIT_MAGIC_STRING_TO_STRING_TAG,
LIT_MAGIC_STRING_UNSCOPABLES
};
JERRY_STATIC_ASSERT (sizeof (ecma_global_symbol_descriptions) / sizeof (uint16_t) == ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT,
ecma_global_symbol_descriptions_must_have_global_symbol_count_elements);
/**
* [[Get]] a well-known symbol by the given property id
*
@ -890,11 +913,30 @@ ecma_op_object_get_by_magic_id (ecma_object_t *object_p, /**< the object */
ecma_string_t *
ecma_op_get_global_symbol (lit_magic_string_id_t property_id) /**< property symbol id */
{
ecma_value_t symbol_value = ecma_op_object_get_by_magic_id (ecma_builtin_get (ECMA_BUILTIN_ID_INTRINSIC_OBJECT),
property_id);
JERRY_ASSERT (ecma_is_value_symbol (symbol_value));
JERRY_ASSERT (LIT_IS_GLOBAL_SYMBOL (property_id));
return ecma_get_symbol_from_value (symbol_value);
uint32_t symbol_index = (uint32_t) property_id - (uint32_t) LIT_GLOBAL_SYMBOL__FIRST;
jmem_cpointer_t symbol_cp = JERRY_CONTEXT (global_symbols_cp)[symbol_index];
if (symbol_cp != JMEM_CP_NULL)
{
ecma_string_t *symbol_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, symbol_cp);
ecma_ref_ecma_string (symbol_p);
return symbol_p;
}
ecma_string_t *symbol_dot_p = ecma_get_magic_string (LIT_MAGIC_STRING_SYMBOL_DOT_UL);
uint16_t description = ecma_global_symbol_descriptions[symbol_index];
ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) description);
ecma_string_t *descriptor_p = ecma_concat_ecma_strings (symbol_dot_p, name_p);
ecma_string_t *symbol_p = ecma_new_symbol_from_descriptor_string (ecma_make_string_value (descriptor_p));
symbol_p->u.hash = (uint16_t) ((property_id << ECMA_GLOBAL_SYMBOL_SHIFT) | ECMA_GLOBAL_SYMBOL_FLAG);
ECMA_SET_NON_NULL_POINTER (JERRY_CONTEXT (global_symbols_cp)[symbol_index], symbol_p);
ecma_ref_ecma_string (symbol_p);
return symbol_p;
} /* ecma_op_get_global_symbol */
/**

View File

@ -691,10 +691,10 @@ jerry_promise_state_t jerry_get_promise_state (const jerry_value_t promise);
*/
typedef enum
{
JERRY_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well-known symbol */
JERRY_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well-known symbol */
JERRY_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well-known symbol */
JERRY_SYMBOL_ITERATOR, /**< @@iterator well-known symbol */
JERRY_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well-known symbol */
JERRY_SYMBOL_MATCH, /**< @@match well-known symbol */
JERRY_SYMBOL_REPLACE, /**< @@replace well-known symbol */
JERRY_SYMBOL_SEARCH, /**< @@search well-known symbol */
@ -739,6 +739,7 @@ void jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, voi
jerry_value_t jerry_get_backtrace (uint32_t max_depth);
jerry_value_t jerry_get_resource_name (const jerry_value_t value);
jerry_value_t jerry_get_new_target (void);
jerry_value_t jerry_set_realm (jerry_value_t realm_value);
/**
* Array buffer components.

View File

@ -145,6 +145,9 @@ struct jerry_context_t
#if ENABLED (JERRY_BUILTIN_BIGINT)
jmem_cpointer_t bigint_list_first_cp; /**< first item of the literal bigint list */
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
#if ENABLED (JERRY_ESNEXT)
jmem_cpointer_t global_symbols_cp[ECMA_BUILTIN_GLOBAL_SYMBOL_COUNT]; /**< global symbols */
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_MODULE_SYSTEM)
ecma_module_t *ecma_modules_p; /**< list of referenced modules */

View File

@ -42,11 +42,11 @@ typedef enum
LIT_INTERNAL_MAGIC_STRING_MAP_PROTOTYPE_ENTRIES, /**< Map.prototype entries and [@@iterator] routines */
LIT_INTERNAL_MAGIC_PROMISE_CAPABILITY, /**< PromiseCapability record */
/* List of well known symbols */
LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well known symbol */
LIT_GLOBAL_SYMBOL__FIRST = LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< first global symbol */
LIT_GLOBAL_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well known symbol */
LIT_GLOBAL_SYMBOL__FISRT = LIT_GLOBAL_SYMBOL_HAS_INSTANCE, /**< first global symbol */
LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well known symbol */
LIT_GLOBAL_SYMBOL_ITERATOR, /**< @@iterator well known symbol */
LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well known symbol */
LIT_GLOBAL_SYMBOL_MATCH, /**< @@match well known symbol */
LIT_GLOBAL_SYMBOL_REPLACE, /**< @@replace well known symbol */
LIT_GLOBAL_SYMBOL_SEARCH, /**< @@search well known symbol */
@ -73,7 +73,7 @@ typedef enum
/**
* Checks whether the given id corresponds to a global symbol
*/
#define LIT_IS_GLOBAL_SYMBOL(id) ((id) >= LIT_GLOBAL_SYMBOL__FISRT && (id) <= LIT_GLOBAL_SYMBOL__LAST)
#define LIT_IS_GLOBAL_SYMBOL(id) ((id) >= LIT_GLOBAL_SYMBOL__FIRST && (id) <= LIT_GLOBAL_SYMBOL__LAST)
/**
* Identifiers of implementation-defined external magic string constants

View File

@ -1219,32 +1219,37 @@ ecma_value_t
opfunc_create_implicit_class_constructor (uint8_t opcode) /**< current cbc opcode */
{
/* 8. */
ecma_object_t *func_obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE),
sizeof (ecma_extended_object_t),
ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
ecma_object_t *function_obj_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE),
sizeof (ecma_native_function_t),
ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
ecma_native_function_t *native_function_p = (ecma_native_function_t *) function_obj_p;
#if ENABLED (JERRY_BUILTIN_REALMS)
ECMA_SET_INTERNAL_VALUE_POINTER (native_function_p->realm_value,
ecma_builtin_get_global ());
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */
/* 10.a.i */
if (opcode == CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE)
{
ext_func_obj_p->u.external_handler_cb = ecma_op_implicit_constructor_handler_heritage_cb;
native_function_p->native_handler_cb = ecma_op_implicit_constructor_handler_heritage_cb;
}
/* 10.b.i */
else
{
ext_func_obj_p->u.external_handler_cb = ecma_op_implicit_constructor_handler_cb;
native_function_p->native_handler_cb = ecma_op_implicit_constructor_handler_cb;
}
ecma_property_value_t *prop_value_p;
prop_value_p = ecma_create_named_data_property (func_obj_p,
prop_value_p = ecma_create_named_data_property (function_obj_p,
ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH),
ECMA_PROPERTY_FLAG_CONFIGURABLE,
NULL);
prop_value_p->value = ecma_make_uint32_value (0);
return ecma_make_object_value (func_obj_p);
return ecma_make_object_value (function_obj_p);
} /* opfunc_create_implicit_class_constructor */
/**

View File

@ -148,17 +148,50 @@ test262_eval_script (const jerry_value_t func_obj_val, /**< function object */
return ret_value;
} /* test262_eval_script */
static jerry_value_t
create_test262 (jerry_value_t global_obj);
/**
* Init the $262 object
* $262.createRealm
*
* A function which creates a new realm object, and returns a newly created $262 object
*
* @return a new $262 object
*/
static void
register_test262 (void)
static jerry_value_t
test262_create_realm (const jerry_value_t func_obj_val, /**< function object */
const jerry_value_t this_p, /**< this arg */
const jerry_value_t args_p[], /**< function arguments */
const jerry_length_t args_cnt) /**< number of function arguments */
{
(void) func_obj_val; /* unused */
(void) this_p; /* unused */
(void) args_p; /* unused */
(void) args_cnt; /* unused */
jerry_value_t realm_object = jerry_create_realm ();
jerry_value_t previous_realm = jerry_set_realm (realm_object);
assert (!jerry_value_is_error (previous_realm));
jerry_value_t test262_object = create_test262 (realm_object);
jerry_set_realm (previous_realm);
jerry_release_value (realm_object);
return test262_object;
} /* test262_create_realm */
/**
* Create a new $262 object
*
* @return a new $262 object
*/
static jerry_value_t
create_test262 (jerry_value_t global_obj) /**< global object */
{
jerry_value_t global_obj = jerry_get_global_object ();
jerry_value_t test262_object = jerry_create_object ();
test262_register_function (test262_object, "detachArrayBuffer", test262_detach_array_buffer);
test262_register_function (test262_object, "evalScript", test262_eval_script);
test262_register_function (test262_object, "createRealm", test262_create_realm);
test262_register_function (test262_object, "gc", jerryx_handler_gc);
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "global");
@ -171,17 +204,16 @@ register_test262 (void)
jerry_release_value (prop_name);
assert (!jerry_value_is_error (result));
jerry_release_value (global_obj);
jerry_release_value (test262_object);
jerry_release_value (result);
} /* register_test262 */
return test262_object;
} /* create_test262 */
/**
* Inits the engine and the debugger
*/
void
main_init_engine (main_args_t *arguments_p) /** main arguments */
main_init_engine (main_args_t *arguments_p) /**< main arguments */
{
jerry_init (arguments_p->init_flags);
@ -211,7 +243,10 @@ main_init_engine (main_args_t *arguments_p) /** main arguments */
}
if (arguments_p->option_flags & OPT_FLAG_TEST262_OBJECT)
{
register_test262 ();
jerry_value_t global_obj = jerry_get_global_object ();
jerry_value_t test262_object = create_test262 (global_obj);
jerry_release_value (test262_object);
jerry_release_value (global_obj);
}
main_register_global_function ("assert", jerryx_handler_assert);
main_register_global_function ("gc", jerryx_handler_gc);

View File

@ -0,0 +1,35 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var realm = createRealm()
function compare(a, b)
{
assert (a === b)
assert (typeof a === "symbol")
assert (typeof b === "symbol")
}
compare(Symbol.asyncIterator, realm.Symbol.asyncIterator)
compare(Symbol.hasInstance, realm.Symbol.hasInstance)
compare(Symbol.isConcatSpreadable, realm.Symbol.isConcatSpreadable)
compare(Symbol.iterator, realm.Symbol.iterator)
compare(Symbol.match, realm.Symbol.match)
compare(Symbol.replace, realm.Symbol.replace)
compare(Symbol.search, realm.Symbol.search)
compare(Symbol.species, realm.Symbol.species)
compare(Symbol.split, realm.Symbol.split)
compare(Symbol.toPrimitive, realm.Symbol.toPrimitive)
compare(Symbol.toStringTag, realm.Symbol.toStringTag)
compare(Symbol.unscopables, realm.Symbol.unscopables)

View File

@ -7932,8 +7932,6 @@
<test id="built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorFunction/instance-await-expr-in-param.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorFunction/instance-yield-expr-in-param.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorFunction/proto-from-ctor-realm-prototype.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorFunction/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/next/request-queue-await-order.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/next/request-queue-promise-resolve-order.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorPrototype/next/this-val-not-async-generator.js"><reason></reason></test>
@ -8012,7 +8010,6 @@
<test id="language/expressions/async-generator/dstr/named-dflt-ary-ptrn-rest-not-final-ary.js"><reason></reason></test>
<test id="language/expressions/async-generator/dstr/named-dflt-ary-ptrn-rest-not-final-id.js"><reason></reason></test>
<test id="language/expressions/async-generator/dstr/named-dflt-ary-ptrn-rest-not-final-obj.js"><reason></reason></test>
<test id="language/expressions/async-generator/eval-body-proto-realm.js"><reason></reason></test>
<test id="language/expressions/async-generator/eval-var-scope-syntax-err.js"><reason></reason></test>
<test id="language/expressions/async-generator/named-eval-var-scope-syntax-err.js"><reason></reason></test>
<test id="language/expressions/async-generator/named-yield-promise-reject-next-catch.js"><reason></reason></test>
@ -9532,26 +9529,8 @@
<test id="annexB/language/statements/const/dstr/object-pattern-emulates-undefined.js"><reason></reason></test>
<test id="annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js"><reason></reason></test>
<test id="annexB/language/statements/function/default-parameters-emulates-undefined.js"><reason></reason></test>
<test id="built-ins/Array/from/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Array/length/define-own-prop-length-overflow-realm.js"><reason></reason></test>
<test id="built-ins/Array/of/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Array/proto-from-ctor-realm-one.js"><reason></reason></test>
<test id="built-ins/Array/proto-from-ctor-realm-two.js"><reason></reason></test>
<test id="built-ins/Array/proto-from-ctor-realm-zero.js"><reason></reason></test>
<test id="built-ins/Array/prototype/concat/create-proto-from-ctor-realm-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/concat/create-proto-from-ctor-realm-non-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/filter/create-proto-from-ctor-realm-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/filter/create-proto-from-ctor-realm-non-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/map/create-proto-from-ctor-realm-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/map/create-proto-from-ctor-realm-non-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/slice/create-proto-from-ctor-realm-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/slice/create-proto-from-ctor-realm-non-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/splice/create-proto-from-ctor-realm-array.js"><reason></reason></test>
<test id="built-ins/Array/prototype/splice/create-proto-from-ctor-realm-non-array.js"><reason></reason></test>
<test id="built-ins/ArrayBuffer/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/AsyncFunction/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorFunction/proto-from-ctor-realm-prototype.js"><reason></reason></test>
<test id="built-ins/AsyncGeneratorFunction/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Atomics/notify/bigint/notify-all-on-loc.js"><reason></reason></test>
<test id="built-ins/Atomics/notify/count-defaults-to-infinity-missing.js"><reason></reason></test>
<test id="built-ins/Atomics/notify/count-defaults-to-infinity-undefined.js"><reason></reason></test>
@ -9663,34 +9642,14 @@
<test id="built-ins/Atomics/waitAsync/value-not-equal-agent.js"><reason></reason></test>
<test id="built-ins/Atomics/waitAsync/waiterlist-block-indexedposition-wake.js"><reason></reason></test>
<test id="built-ins/Atomics/waitAsync/was-woken-before-timeout.js"><reason></reason></test>
<test id="built-ins/BigInt/prototype/valueOf/cross-realm.js"><reason></reason></test>
<test id="built-ins/Boolean/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/DataView/proto-from-ctor-realm-sab.js"><reason></reason></test>
<test id="built-ins/DataView/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Date/proto-from-ctor-realm-one.js"><reason></reason></test>
<test id="built-ins/Date/proto-from-ctor-realm-two.js"><reason></reason></test>
<test id="built-ins/Date/proto-from-ctor-realm-zero.js"><reason></reason></test>
<test id="built-ins/Error/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js"><reason></reason></test>
<test id="built-ins/FinalizationRegistry/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Function/call-bind-this-realm-undef.js"><reason></reason></test>
<test id="built-ins/Function/call-bind-this-realm-value.js"><reason></reason></test>
<test id="built-ins/Function/internals/Call/class-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Function/internals/Construct/base-ctor-revoked-proxy-realm.js"><reason></reason></test>
<test id="built-ins/Function/internals/Construct/derived-return-val-realm.js"><reason></reason></test>
<test id="built-ins/Function/internals/Construct/derived-this-uninitialized-realm.js"><reason></reason></test>
<test id="built-ins/Function/proto-from-ctor-realm-prototype.js"><reason></reason></test>
<test id="built-ins/Function/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Function/prototype/apply/argarray-not-object-realm.js"><reason></reason></test>
<test id="built-ins/Function/prototype/apply/this-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Function/prototype/bind/get-fn-realm-recursive.js"><reason></reason></test>
<test id="built-ins/Function/prototype/bind/get-fn-realm.js"><reason></reason></test>
<test id="built-ins/Function/prototype/bind/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/GeneratorFunction/proto-from-ctor-realm-prototype.js"><reason></reason></test>
<test id="built-ins/GeneratorFunction/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/JSON/stringify/replacer-array-proxy-revoked-realm.js"><reason></reason></test>
<test id="built-ins/JSON/stringify/value-bigint-cross-realm.js"><reason></reason></test>
<test id="built-ins/Map/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/NativeErrors/AggregateError/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/NativeErrors/EvalError/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/NativeErrors/RangeError/proto-from-ctor-realm.js"><reason></reason></test>
@ -9699,46 +9658,9 @@
<test id="built-ins/NativeErrors/TypeError/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/NativeErrors/URIError/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Number/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Object/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Promise/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/apply/arguments-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/apply/null-handler-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/apply/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/arguments-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/null-handler-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/return-not-object-throws-boolean-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/return-not-object-throws-null-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/return-not-object-throws-number-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/return-not-object-throws-string-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/return-not-object-throws-symbol-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/return-not-object-throws-undefined-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/trap-is-undefined-proto-from-cross-realm-newtarget.js"><reason></reason></test>
<test id="built-ins/Proxy/construct/trap-is-undefined-proto-from-newtarget-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/desc-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/null-handler-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/defineProperty/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/deleteProperty/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/get-fn-realm-recursive.js"><reason></reason></test>
<test id="built-ins/Proxy/get-fn-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/get/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/getPrototypeOf/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/has/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/isExtensible/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/ownKeys/return-not-list-object-throws-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/ownKeys/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/preventExtensions/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/set/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/Proxy/setPrototypeOf/trap-is-not-callable-realm.js"><reason></reason></test>
<test id="built-ins/RegExp/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/Symbol.split/splitter-proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/dotAll/cross-realm.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/global/cross-realm.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/ignoreCase/cross-realm.js"><reason></reason></test>
@ -9746,43 +9668,20 @@
<test id="built-ins/RegExp/prototype/source/cross-realm.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/sticky/cross-realm.js"><reason></reason></test>
<test id="built-ins/RegExp/prototype/unicode/cross-realm.js"><reason></reason></test>
<test id="built-ins/Set/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/SharedArrayBuffer/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/String/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/String/prototype/toString/non-generic-realm.js"><reason></reason></test>
<test id="built-ins/String/prototype/valueOf/non-generic-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/asyncIterator/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/for/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/hasInstance/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/isConcatSpreadable/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/iterator/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/keyFor/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/match/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/matchAll/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/replace/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/search/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/species/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/split/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/toPrimitive/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/toStringTag/cross-realm.js"><reason></reason></test>
<test id="built-ins/Symbol/unscopables/cross-realm.js"><reason></reason></test>
<test id="built-ins/ThrowTypeError/distinct-cross-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/no-args/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/object-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm-sab.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/length-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/no-args/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/typedarray-arg/other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/typedarray-arg/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.js"><reason></reason></test>
@ -9793,9 +9692,7 @@
<test id="built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js"><reason></reason></test>
<test id="built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js"><reason></reason></test>
<test id="built-ins/WeakMap/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/WeakRef/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/WeakSet/proto-from-ctor-realm.js"><reason></reason></test>
<test id="intl402/Collator/proto-from-ctor-realm.js"><reason></reason></test>
<test id="intl402/DateTimeFormat/proto-from-ctor-realm.js"><reason></reason></test>
<test id="intl402/DisplayNames/proto-from-ctor-realm.js"><reason></reason></test>
@ -9805,8 +9702,6 @@
<test id="intl402/PluralRules/proto-from-ctor-realm.js"><reason></reason></test>
<test id="intl402/RelativeTimeFormat/constructor/constructor/proto-from-ctor-realm.js"><reason></reason></test>
<test id="intl402/Segmenter/constructor/constructor/proto-from-ctor-realm.js"><reason></reason></test>
<test id="language/eval-code/indirect/realm.js"><reason></reason></test>
<test id="language/expressions/async-generator/eval-body-proto-realm.js"><reason></reason></test>
<test id="language/expressions/call/eval-realm-indirect.js"><reason></reason></test>
<test id="language/expressions/call/tco-cross-realm-class-construct.js"><reason></reason></test>
<test id="language/expressions/call/tco-cross-realm-class-derived-construct.js"><reason></reason></test>
@ -9822,10 +9717,6 @@
<test id="language/expressions/class/private-static-getter-multiple-evaluations-of-class-realm.js"><reason></reason></test>
<test id="language/expressions/class/private-static-method-brand-check-multiple-evaluations-of-class-realm.js"><reason></reason></test>
<test id="language/expressions/class/private-static-setter-multiple-evaluations-of-class-realm.js"><reason></reason></test>
<test id="language/expressions/generators/eval-body-proto-realm.js"><reason></reason></test>
<test id="language/expressions/new/non-ctor-err-realm.js"><reason></reason></test>
<test id="language/expressions/super/realm.js"><reason></reason></test>
<test id="language/expressions/tagged-template/cache-realm.js"><reason></reason></test>
<test id="language/global-code/script-decl-func-err-non-configurable.js"><reason></reason></test>
<test id="language/global-code/script-decl-func-err-non-extensible.js"><reason></reason></test>
<test id="language/global-code/script-decl-func.js"><reason></reason></test>
@ -9833,8 +9724,6 @@
<test id="language/global-code/script-decl-lex-restricted-global.js"><reason></reason></test>
<test id="language/global-code/script-decl-lex.js"><reason></reason></test>
<test id="language/global-code/script-decl-var-err.js"><reason></reason></test>
<test id="language/types/reference/get-value-prop-base-primitive-realm.js"><reason></reason></test>
<test id="language/types/reference/put-value-prop-base-primitive-realm.js"><reason></reason></test>
<!-- Missing test262 support in JerryScript REPL - missing $262 object -->
<!-- Missing test262 support in JerryScript REPL - missing $262.detachArrayBuffer function

View File

@ -0,0 +1,100 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "test-common.h"
static void
create_number_property (jerry_value_t object_value,
char *name_p,
double number)
{
jerry_value_t name_value = jerry_create_string ((const jerry_char_t *) name_p);
jerry_value_t number_value = jerry_create_number (number);
jerry_value_t result_value = jerry_set_property (object_value, name_value, number_value);
TEST_ASSERT (!jerry_value_is_error (result_value));
jerry_release_value (result_value);
jerry_release_value (number_value);
jerry_release_value (name_value);
} /* create_number_property */
static double
eval_and_get_number (char *script_p)
{
jerry_value_t result_value;
result_value = jerry_eval ((const jerry_char_t *) script_p, strlen (script_p), JERRY_PARSE_NO_OPTS);
TEST_ASSERT (jerry_value_is_number (result_value));
double result = jerry_get_number_value (result_value);
jerry_release_value (result_value);
return result;
} /* eval_and_get_number */
/**
* Unit test's main function.
*/
int
main (void)
{
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
if (!jerry_is_feature_enabled (JERRY_FEATURE_REALM))
{
printf ("Skipping test, Realms not enabled\n");
return 0;
}
jerry_value_t global_value = jerry_get_global_object ();
jerry_value_t realm_value = jerry_create_realm ();
create_number_property (global_value, "a", 3.5);
create_number_property (global_value, "b", 7.25);
create_number_property (realm_value, "a", -1.25);
create_number_property (realm_value, "b", -6.75);
TEST_ASSERT (eval_and_get_number ("a") == 3.5);
jerry_value_t result_value = jerry_set_realm (realm_value);
TEST_ASSERT (result_value == global_value);
TEST_ASSERT (eval_and_get_number ("a") == -1.25);
result_value = jerry_set_realm (global_value);
TEST_ASSERT (result_value == realm_value);
TEST_ASSERT (eval_and_get_number ("b") == 7.25);
result_value = jerry_set_realm (realm_value);
TEST_ASSERT (result_value == global_value);
TEST_ASSERT (eval_and_get_number ("b") == -6.75);
result_value = jerry_set_realm (global_value);
TEST_ASSERT (result_value == realm_value);
jerry_value_t object_value = jerry_create_object ();
result_value = jerry_set_realm (object_value);
TEST_ASSERT (jerry_value_is_error (result_value));
jerry_release_value (result_value);
jerry_release_value (object_value);
jerry_release_value (global_value);
jerry_release_value (realm_value);
jerry_cleanup ();
return 0;
} /* main */

View File

@ -220,10 +220,10 @@ main (void)
const jerry_char_t obj_src[] = ""
"({"
" [Symbol.hasInstance]: 1,"
" [Symbol.isConcatSpreadable]: 2,"
" [Symbol.iterator]: 3,"
" [Symbol.asyncIterator]: 4,"
" [Symbol.asyncIterator]: 1,"
" [Symbol.hasInstance]: 2,"
" [Symbol.isConcatSpreadable]: 3,"
" [Symbol.iterator]: 4,"
" [Symbol.match]: 5,"
" [Symbol.replace]: 6,"
" [Symbol.search]: 7,"
@ -236,10 +236,10 @@ main (void)
const char *symbols[] =
{
"asyncIterator",
"hasInstance",
"isConcatSpreadable",
"iterator",
"asyncIterator",
"match",
"replace",
"search",
@ -261,7 +261,7 @@ main (void)
double expected = 1.0;
uint32_t prop_index = 0;
for (jerry_well_known_symbol_t id = JERRY_SYMBOL_HAS_INSTANCE;
for (jerry_well_known_symbol_t id = JERRY_SYMBOL_ASYNC_ITERATOR;
id <= JERRY_SYMBOL_UNSCOPABLES;
id++, expected++, prop_index++)
{
@ -315,7 +315,7 @@ main (void)
expected = 1.0;
prop_index = 0;
for (jerry_well_known_symbol_t id = JERRY_SYMBOL_HAS_INSTANCE;
for (jerry_well_known_symbol_t id = JERRY_SYMBOL_ASYNC_ITERATOR;
id <= JERRY_SYMBOL_UNSCOPABLES;
id++, expected++, prop_index++)
{
@ -335,7 +335,7 @@ main (void)
TEST_ASSERT (jerry_value_is_undefined (invalid_well_known_symbol));
jerry_release_value (invalid_well_known_symbol);
invalid_symbol = (jerry_well_known_symbol_t) (JERRY_SYMBOL_HAS_INSTANCE - 1);
invalid_symbol = (jerry_well_known_symbol_t) (JERRY_SYMBOL_ASYNC_ITERATOR - 1);
invalid_well_known_symbol = jerry_get_well_known_symbol (invalid_symbol);
TEST_ASSERT (jerry_value_is_undefined (invalid_well_known_symbol));
jerry_release_value (invalid_well_known_symbol);