Add unscopables check to ecma_op_get_value_lex_env_base (#3476)
Also added a special test case for this to symbol-unscopables.js JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
committed by
Robert Fancsik
parent
003694d259
commit
aedd55b1f8
@@ -26,6 +26,7 @@
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "ecma-reference.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
@@ -92,7 +93,29 @@ ecma_op_get_value_lex_env_base (ecma_object_t *lex_env_p, /**< lexical environme
|
||||
if (ecma_is_value_found (result))
|
||||
{
|
||||
*ref_base_lex_env_p = lex_env_p;
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_value_t blocked = ecma_op_is_prop_unscopable (lex_env_p, name_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (blocked))
|
||||
{
|
||||
ecma_free_value (result);
|
||||
return blocked;
|
||||
}
|
||||
|
||||
if (ecma_is_value_true (blocked))
|
||||
{
|
||||
*ref_base_lex_env_p = NULL;
|
||||
ecma_free_value (result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
return result;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -102,7 +102,7 @@ ecma_op_resolve_super_reference_value (ecma_object_t *lex_env_p) /**< starting l
|
||||
* ECMA_VALUE_FALSE - if a the property is not unscopable
|
||||
* ECMA_VALUE_ERROR - otherwise
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_value_t
|
||||
ecma_op_is_prop_unscopable (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@ ecma_object_t *ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, ecma_st
|
||||
ecma_value_t ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, ecma_string_t *name_p);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_object_t *ecma_op_resolve_super_reference_value (ecma_object_t *lex_env_p);
|
||||
ecma_value_t ecma_op_is_prop_unscopable (ecma_object_t *lex_env_p, ecma_string_t *prop_name_p);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,6 +70,17 @@ with (obj2) {
|
||||
}
|
||||
}
|
||||
|
||||
var obj3 = { foo: 12 };
|
||||
Object.defineProperty(obj3, Symbol.unscopables, { get: function () { throw 42; } });
|
||||
|
||||
with (obj3) {
|
||||
try {
|
||||
typeof foo;
|
||||
} catch (e) {
|
||||
assert(e === 42);
|
||||
}
|
||||
}
|
||||
|
||||
var symbol_obj = Array.prototype[Symbol.unscopables];
|
||||
assert(symbol_obj.copyWithin === true);
|
||||
assert(symbol_obj.entries === true);
|
||||
@@ -86,3 +97,10 @@ assert(obj3.value === true);
|
||||
assert(obj3.writable === true);
|
||||
assert(obj3.enumerable == true);
|
||||
assert(obj3.configurable == true);
|
||||
|
||||
var a = { foo: 1, bar: 2 };
|
||||
a[Symbol.unscopables] = { bar: true };
|
||||
with (a) {
|
||||
assert(foo === 1);
|
||||
assert(typeof bar === "undefined");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user