diff --git a/jerry-core/config.h b/jerry-core/config.h index 68ef170bf..ba23e2952 100644 --- a/jerry-core/config.h +++ b/jerry-core/config.h @@ -103,6 +103,10 @@ # define JERRY_ES2015_BUILTIN_PROMISE JERRY_ES2015 #endif /* !defined (JERRY_ES2015_BUILTIN_PROMISE) */ +#ifndef JERRY_ES2015_BUILTIN_REFLECT +# define JERRY_ES2015_BUILTIN_REFLECT JERRY_ES2015 +#endif /* !defined (JERRY_ES2016_BUILTIN_REFLECT) */ + #ifndef JERRY_ES2015_BUILTIN_SYMBOL # define JERRY_ES2015_BUILTIN_SYMBOL JERRY_ES2015 #endif /* !defined (JERRY_ES2015_BUILTIN_SYMBOL) */ @@ -555,6 +559,10 @@ || ((JERRY_ES2015_BUILTIN_MAP != 0) && (JERRY_ES2015_BUILTIN_MAP != 1)) # error "Invalid value for JERRY_ES2015_BUILTIN_MAP macro." #endif +#if !defined (JERRY_ES2015_BUILTIN_REFLECT) \ +|| ((JERRY_ES2015_BUILTIN_REFLECT != 0) && (JERRY_ES2015_BUILTIN_REFLECT != 1)) +# error "Invalid value for JERRY_ES2015_BUILTIN_REFLECT macro." +#endif #if !defined (JERRY_ES2015_BUILTIN_SET) \ || ((JERRY_ES2015_BUILTIN_SET != 0) && (JERRY_ES2015_BUILTIN_SET != 1)) # error "Invalid value for JERRY_ES2015_BUILTIN_SET macro." diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c index fb22e59be..95afa332f 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c @@ -25,6 +25,7 @@ #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" +#include "ecma-builtin-function-prototype.h" #define ECMA_BUILTINS_INTERNAL #include "ecma-builtins-internal.h" @@ -92,7 +93,7 @@ ecma_builtin_function_prototype_object_to_string (void) * @return ecma value * Returned value must be freed with ecma_free_value. */ -static ecma_value_t +ecma_value_t ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, /**< this argument object */ ecma_value_t arg1, /**< first argument */ ecma_value_t arg2) /**< second argument */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.h b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.h new file mode 100644 index 000000000..97ba3137b --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.h @@ -0,0 +1,23 @@ +/* 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. + */ + +#ifndef ECMA_BUILTIN_FUNCTION_PROTOTYPE_H +#define ECMA_BUILTIN_FUNCTION_PROTOTYPE_H + +ecma_value_t ecma_builtin_function_prototype_object_apply (ecma_object_t *func_obj_p, + ecma_value_t arg1, + ecma_value_t arg2); + +#endif /* !ECMA_BUILTIN_FUNCTION_PROTOTYPE_H */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h index 4964887f2..03170f3a2 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h @@ -139,6 +139,13 @@ OBJECT_VALUE (LIT_MAGIC_STRING_MATH_UL, ECMA_BUILTIN_ID_MATH, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) #endif /* ENABLED (JERRY_BUILTIN_MATH) */ +#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT) +/* ECMA-262 v6, 26.1 */ +OBJECT_VALUE (LIT_MAGIC_STRING_REFLECT_UL, + ECMA_BUILTIN_ID_REFLECT, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* ENABLED (JERRY_ES2015_BUILTIN_REFLECT) */ + #if ENABLED (JERRY_BUILTIN_JSON) /* ECMA-262 v5, 15.1.5.2 */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c index e7e4dc33b..bf12b61fb 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c @@ -24,6 +24,7 @@ #include "ecma-objects.h" #include "ecma-objects-general.h" #include "jrt.h" +#include "ecma-builtin-object.h" #define ECMA_BUILTINS_INTERNAL #include "ecma-builtins-internal.h" @@ -122,7 +123,7 @@ ecma_builtin_object_dispatch_construct (const ecma_value_t *arguments_list_p, /* * @return ecma value * Returned value must be freed with ecma_free_value. */ -static ecma_value_t +ecma_value_t ecma_builtin_object_object_get_prototype_of (ecma_value_t arg) /**< routine's argument */ { ecma_value_t ret_value = ECMA_VALUE_EMPTY; @@ -247,7 +248,7 @@ ecma_set_prototype_of (ecma_value_t o_value, /**< O */ * @return ecma value * Returned value must be freed with ecma_free_value. */ -static ecma_value_t +ecma_value_t ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, /**< routine's first argument */ ecma_value_t arg2) /**< routine's second argument */ { @@ -441,7 +442,7 @@ ecma_builtin_object_object_freeze (ecma_object_t *obj_p) /**< routine's argument * @return ecma value * Returned value must be freed with ecma_free_value. */ -static ecma_value_t +ecma_value_t ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p) /**< routine's argument */ { ecma_set_object_extensible (obj_p, false); @@ -521,7 +522,7 @@ ecma_builtin_object_frozen_or_sealed_helper (ecma_object_t *obj_p, /**< routine' * @return ecma value * Returned value must be freed with ecma_free_value. */ -static ecma_value_t +ecma_value_t ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p) /**< routine's argument */ { return ecma_make_boolean_value (ecma_get_object_extensible (obj_p)); @@ -551,7 +552,7 @@ ecma_builtin_object_object_keys (ecma_object_t *obj_p) /**< routine's argument * * @return ecma value * Returned value must be freed with ecma_free_value. */ -static ecma_value_t +ecma_value_t ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, /**< routine's first argument */ ecma_string_t *name_str_p) /**< routine's second argument */ { @@ -724,7 +725,7 @@ ecma_builtin_object_object_create (ecma_value_t arg1, /**< routine's first argum * @return ecma value * Returned value must be freed with ecma_free_value. */ -static ecma_value_t +ecma_value_t ecma_builtin_object_object_define_property (ecma_object_t *obj_p, /**< routine's first argument */ ecma_string_t *name_str_p, /**< routine's second argument */ ecma_value_t arg3) /**< routine's third argument */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object.h b/jerry-core/ecma/builtin-objects/ecma-builtin-object.h new file mode 100644 index 000000000..0ffe8336d --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object.h @@ -0,0 +1,32 @@ +/* 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. + */ +#ifndef ECMA_BUILTIN_OBJECT_H +#define ECMA_BUILTIN_OBJECT_H + +ecma_value_t ecma_builtin_object_object_get_prototype_of (ecma_value_t arg); + +ecma_value_t ecma_builtin_object_object_set_prototype_of (ecma_value_t arg1, + ecma_value_t arg2); +ecma_value_t ecma_builtin_object_object_prevent_extensions (ecma_object_t *obj_p); + +ecma_value_t ecma_builtin_object_object_is_extensible (ecma_object_t *obj_p); + +ecma_value_t ecma_builtin_object_object_get_own_property_descriptor (ecma_object_t *obj_p, + ecma_string_t *name_str_p); +ecma_value_t ecma_builtin_object_object_define_property (ecma_object_t *obj_p, + ecma_string_t *name_str_p, + ecma_value_t arg3); + +#endif /* !ECMA_BUILTIN_OBJECT_H */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.c b/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.c new file mode 100644 index 000000000..0559a3493 --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.c @@ -0,0 +1,163 @@ +/* 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-builtins.h" +#include "ecma-builtin-function-prototype.h" +#include "ecma-builtin-object.h" +#include "ecma-exceptions.h" +#include "ecma-function-object.h" +#include "ecma-gc.h" +#include "jcontext.h" + +#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT) + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** + * This object has a custom dispatch function. + */ +#define BUILTIN_CUSTOM_DISPATCH + +/** + * List of built-in routine identifiers. + */ +enum +{ + ECMA_REFLECT_OBJECT_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1, + ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF_UL, /* ECMA-262 v6, 26.1.8 */ + ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF_UL, /* ECMA-262 v6, 26.1.14 */ + ECMA_REFLECT_OBJECT_APPLY, /* ECMA-262 v6, 26.1.1 */ + ECMA_REFLECT_OBJECT_DEFINE_PROPERTY, /* ECMA-262 v6, 26.1.3 */ + ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_UL, /* ECMA-262 v5, 26.1.7 */ + ECMA_REFLECT_OBJECT_IS_EXTENSIBLE, /* ECMA-262 v6, 26.1.10 */ + ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS_UL, /* ECMA-262 v6, 26.1.12 */ +}; + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-reflect.inc.h" +#define BUILTIN_UNDERSCORED_ID reflect +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup object ECMA Reflect object built-in + * @{ + */ + +/** + * Dispatcher for the built-in's routines. + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine + * identifier */ + ecma_value_t this_arg, /**< 'this' argument value */ + const ecma_value_t arguments_list[], /**< list of arguments + * passed to routine */ + ecma_length_t arguments_number) /**< length of arguments' list */ +{ + JERRY_UNUSED (this_arg); + JERRY_UNUSED (arguments_number); + + if (!ecma_is_value_object (arguments_list[0]) + && builtin_routine_id > ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF_UL) + { + return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an Object.")); + } + + switch (builtin_routine_id) + { + case ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF_UL: + { + return ecma_builtin_object_object_get_prototype_of (arguments_list[0]); + } + case ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF_UL: + { + ecma_value_t result = ecma_builtin_object_object_set_prototype_of (arguments_list[0], arguments_list[1]); + bool is_error = ECMA_IS_VALUE_ERROR (result); + + ecma_free_value (is_error ? JERRY_CONTEXT (error_value) : result); + + return ecma_make_boolean_value (!is_error); + } + case ECMA_REFLECT_OBJECT_APPLY: + { + if (!ecma_op_is_callable (arguments_list[0])) + { + return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a function.")); + } + + ecma_object_t *func_obj_p = ecma_get_object_from_value (arguments_list[0]); + return ecma_builtin_function_prototype_object_apply (func_obj_p, arguments_list[1], arguments_list[2]); + } + case ECMA_REFLECT_OBJECT_DEFINE_PROPERTY: + { + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + ecma_string_t *name_str_p = ecma_op_to_prop_name (arguments_list[1]); + + if (name_str_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t result = ecma_builtin_object_object_define_property (obj_p, name_str_p, arguments_list[2]); + ecma_deref_ecma_string (name_str_p); + bool is_error = ECMA_IS_VALUE_ERROR (result); + + ecma_free_value (is_error ? JERRY_CONTEXT (error_value) : result); + + return ecma_make_boolean_value (!is_error); + } + case ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_UL: + { + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + ecma_string_t *name_str_p = ecma_op_to_prop_name (arguments_list[1]); + + if (name_str_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_value_t ret_val = ecma_builtin_object_object_get_own_property_descriptor (obj_p, name_str_p); + ecma_deref_ecma_string (name_str_p); + return ret_val; + } + case ECMA_REFLECT_OBJECT_IS_EXTENSIBLE: + { + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + return ecma_builtin_object_object_is_extensible (obj_p); + } + default: + { + JERRY_ASSERT (builtin_routine_id == ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS_UL); + ecma_object_t *obj_p = ecma_get_object_from_value (arguments_list[0]); + return ecma_builtin_object_object_prevent_extensions (obj_p); + } + } +} /* ecma_builtin_reflect_dispatch_routine */ + +/** + * @} + * @} + * @} + */ + +#endif /* ENABLED (JERRY_ES2015_BUILTIN_REFLECT) */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.inc.h new file mode 100644 index 000000000..68aef6023 --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-reflect.inc.h @@ -0,0 +1,32 @@ +/* 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-builtin-helpers-macro-defines.inc.h" + +#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_APPLY, ECMA_REFLECT_OBJECT_APPLY, 3, 3) +ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ECMA_REFLECT_OBJECT_DEFINE_PROPERTY, 3, 3) +ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ECMA_REFLECT_OBJECT_GET_OWN_PROPERTY_DESCRIPTOR_UL, 2, 2) +ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_GET_PROTOTYPE_OF_UL, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_EXTENSIBLE, ECMA_REFLECT_OBJECT_IS_EXTENSIBLE, 1, 1) +ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ECMA_REFLECT_OBJECT_PREVENT_EXTENSIONS_UL, 1, 1) +ROUTINE (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, ECMA_REFLECT_OBJECT_SET_PROTOTYPE_OF_UL, 2, 2) + +#endif /* ENABLED (JERRY_ES2015_BUILTIN_REFLECT) */ + +#include "ecma-builtin-helpers-macro-undefs.inc.h" diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h index ddd19606f..d9f73293b 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h @@ -117,6 +117,16 @@ BUILTIN (ECMA_BUILTIN_ID_MATH, math) #endif /* ENABLED (JERRY_BUILTIN_MATH) */ +#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT) + +/* The Reflect object (26.1) */ +BUILTIN (ECMA_BUILTIN_ID_REFLECT, + ECMA_OBJECT_TYPE_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + reflect) +#endif /* ENABLED (JERRY_ES2015_BUILTIN_REFLECT) */ + #if ENABLED (JERRY_BUILTIN_JSON) /* The JSON object (15.12) */ BUILTIN (ECMA_BUILTIN_ID_JSON, diff --git a/jerry-core/ecma/operations/ecma-objects.c b/jerry-core/ecma/operations/ecma-objects.c index 69e190483..e0d95373b 100644 --- a/jerry-core/ecma/operations/ecma-objects.c +++ b/jerry-core/ecma/operations/ecma-objects.c @@ -2322,6 +2322,12 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */ return LIT_MAGIC_STRING_MATH_UL; } #endif /* ENABLED (JERRY_BUILTIN_MATH) */ +#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT) + case ECMA_BUILTIN_ID_REFLECT: + { + return LIT_MAGIC_STRING_REFLECT_UL; + } +#endif /* ENABLED (JERRY_ES2015_BUILTIN_REFLECT) */ #if ENABLED (JERRY_BUILTIN_JSON) case ECMA_BUILTIN_ID_JSON: { diff --git a/jerry-core/lit/lit-magic-strings.inc.h b/jerry-core/lit/lit-magic-strings.inc.h index 9213b85cb..66d6affc0 100644 --- a/jerry-core/lit/lit-magic-strings.inc.h +++ b/jerry-core/lit/lit-magic-strings.inc.h @@ -349,6 +349,9 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BOOLEAN_UL, "Boolean") #if ENABLED (JERRY_ES2015_BUILTIN_PROMISE) LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PROMISE_UL, "Promise") #endif +#if ENABLED (JERRY_ES2015_BUILTIN_REFLECT) +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REFLECT_UL, "Reflect") +#endif #if ENABLED (JERRY_BUILTIN_MATH) LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SQRT1_2_U, "SQRT1_2") #endif @@ -709,7 +712,8 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, "getPrototypeOf") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_FULL_YEAR_UL, "getUTCFullYear") #endif LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_HAS_OWN_PROPERTY_UL, "hasOwnProperty") -#if ENABLED (JERRY_ES2015_BUILTIN) +#if ENABLED (JERRY_ES2015_BUILTIN) \ +|| ENABLED (JERRY_ES2015_BUILTIN_REFLECT) LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_PROTOTYPE_OF_UL, "setPrototypeOf") #endif #if ENABLED (JERRY_BUILTIN_DATE) diff --git a/jerry-core/lit/lit-magic-strings.ini b/jerry-core/lit/lit-magic-strings.ini index 6662ffcf5..d1429df66 100644 --- a/jerry-core/lit/lit-magic-strings.ini +++ b/jerry-core/lit/lit-magic-strings.ini @@ -154,6 +154,7 @@ LIT_MAGIC_STRING_TO_JSON_UL = "toJSON" LIT_MAGIC_STRING_VALUES = "values" LIT_MAGIC_STRING_BOOLEAN_UL = "Boolean" LIT_MAGIC_STRING_PROMISE_UL = "Promise" +LIT_MAGIC_STRING_REFLECT_UL = "Reflect" LIT_MAGIC_STRING_SQRT1_2_U = "SQRT1_2" LIT_MAGIC_STRING_SYMBOL_LEFT_PAREN_UL = "Symbol(" LIT_MAGIC_STRING_SYMBOL_DOT_UL = "Symbol." diff --git a/tests/jerry/es2015/reflect-apply.js b/tests/jerry/es2015/reflect-apply.js new file mode 100644 index 000000000..531d997bf --- /dev/null +++ b/tests/jerry/es2015/reflect-apply.js @@ -0,0 +1,18 @@ +// 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. + +assert (Reflect['apply'](Math.floor, undefined, [1.75]) === 1); +assert (Reflect['apply'](String.fromCharCode, undefined, [104, 101, 108, 108, 111]) === "hello"); +assert (Reflect['apply'](RegExp.prototype.exec, /ab/, ['confabulation']).index === 4); +assert (Reflect['apply'](''.charAt, 'ponies', [3]) === "i"); diff --git a/tests/jerry/es2015/reflect-define-Property.js b/tests/jerry/es2015/reflect-define-Property.js new file mode 100644 index 000000000..7bca09967 --- /dev/null +++ b/tests/jerry/es2015/reflect-define-Property.js @@ -0,0 +1,23 @@ +// 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 obj = {}; +assert(Reflect['defineProperty'](obj, 'x', {value: 7}) === true); +assert(Reflect['defineProperty'](obj, 'y', {value: function() {throw 5}}) === true); +try { + Reflect['defineProperty'](obj, {toString: function() {throw new TypeError(5)}}, {value: 8}); + assert(false); +} catch (e) { + assert(e instanceof TypeError); +} diff --git a/tests/jerry/es2015/reflect-get-own-property-description.js b/tests/jerry/es2015/reflect-get-own-property-description.js new file mode 100644 index 000000000..caca9b1c6 --- /dev/null +++ b/tests/jerry/es2015/reflect-get-own-property-description.js @@ -0,0 +1,21 @@ +// 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 object1 = { + property1: 42 +}; + +assert(Reflect.getOwnPropertyDescriptor(object1, 'property1').value === 42); +assert(Reflect.getOwnPropertyDescriptor(object1, 'property2') === undefined); +assert(Reflect.getOwnPropertyDescriptor(object1, 'property1').writable === true); diff --git a/tests/jerry/es2015/reflect-getPrototypeOf.js b/tests/jerry/es2015/reflect-getPrototypeOf.js new file mode 100644 index 000000000..a0a59990d --- /dev/null +++ b/tests/jerry/es2015/reflect-getPrototypeOf.js @@ -0,0 +1,17 @@ +// 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. + +assert (Reflect['getPrototypeOf']({}) === Object.prototype); +assert (Reflect['getPrototypeOf'](Object.create(null)) === null); +assert (Reflect['getPrototypeOf'](Object.prototype) === null); diff --git a/tests/jerry/es2015/reflect-isextensible.js b/tests/jerry/es2015/reflect-isextensible.js new file mode 100644 index 000000000..a954b663d --- /dev/null +++ b/tests/jerry/es2015/reflect-isextensible.js @@ -0,0 +1,22 @@ +// 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 empty = {}; +assert (Reflect['isExtensible'](empty) === true); + +Reflect.preventExtensions(empty); +assert (Reflect['isExtensible'](empty) === false); + +var sealed = Object.seal({}); +assert (Reflect['isExtensible'](sealed) === false); diff --git a/tests/jerry/es2015/reflect-preventextensions.js b/tests/jerry/es2015/reflect-preventextensions.js new file mode 100644 index 000000000..5af6589e3 --- /dev/null +++ b/tests/jerry/es2015/reflect-preventextensions.js @@ -0,0 +1,20 @@ +// 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 object1 = {}; + +assert (Reflect['isExtensible'](object1) === true); + +Reflect.preventExtensions(object1); +assert (Reflect['isExtensible'](object1) === false); diff --git a/tests/jerry/es2015/reflect-setPrototypeOf.js b/tests/jerry/es2015/reflect-setPrototypeOf.js new file mode 100644 index 000000000..c3e07a882 --- /dev/null +++ b/tests/jerry/es2015/reflect-setPrototypeOf.js @@ -0,0 +1,21 @@ +// 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 object1 = {}; + +assert(Reflect.setPrototypeOf(object1, Object.prototype) === true); +assert(Reflect.setPrototypeOf(object1, null) === true); + +var object2 = {}; +assert(Reflect.setPrototypeOf(Object.freeze(object2), null) === false);