Implement Reflect object (#3036)

JerryScript-DCO-1.0-Signed-off-by: Virag Orkenyi orkvi@inf.u-szeged.hu
This commit is contained in:
Virag Orkenyi 2019-10-21 13:46:29 +02:00 committed by Robert Fancsik
parent edf66f4e9b
commit 3fb6f15730
19 changed files with 438 additions and 8 deletions

View File

@ -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."

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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) */

View File

@ -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"

View File

@ -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,

View File

@ -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:
{

View File

@ -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)

View File

@ -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."

View File

@ -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");

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);