Skip to content

Commit aedd55b

Browse files
szilagyiadamrerobika
authored andcommitted
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
1 parent 003694d commit aedd55b

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

jerry-core/ecma/operations/ecma-get-put-value.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ecma-function-object.h"
2727
#include "ecma-objects-general.h"
2828
#include "ecma-try-catch-macro.h"
29+
#include "ecma-reference.h"
2930

3031
/** \addtogroup ecma ECMA
3132
* @{
@@ -92,7 +93,29 @@ ecma_op_get_value_lex_env_base (ecma_object_t *lex_env_p, /**< lexical environme
9293
if (ecma_is_value_found (result))
9394
{
9495
*ref_base_lex_env_p = lex_env_p;
96+
97+
#if ENABLED (JERRY_ES2015)
98+
ecma_value_t blocked = ecma_op_is_prop_unscopable (lex_env_p, name_p);
99+
100+
if (ECMA_IS_VALUE_ERROR (blocked))
101+
{
102+
ecma_free_value (result);
103+
return blocked;
104+
}
105+
106+
if (ecma_is_value_true (blocked))
107+
{
108+
*ref_base_lex_env_p = NULL;
109+
ecma_free_value (result);
110+
}
111+
else
112+
{
113+
return result;
114+
}
115+
#else /* !ENABLED (JERRY_ES2015) */
95116
return result;
117+
#endif /* ENABLED (JERRY_ES2015) */
118+
96119
}
97120

98121
break;

jerry-core/ecma/operations/ecma-reference.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ecma_op_resolve_super_reference_value (ecma_object_t *lex_env_p) /**< starting l
102102
* ECMA_VALUE_FALSE - if a the property is not unscopable
103103
* ECMA_VALUE_ERROR - otherwise
104104
*/
105-
static ecma_value_t
105+
ecma_value_t
106106
ecma_op_is_prop_unscopable (ecma_object_t *lex_env_p, /**< lexical environment */
107107
ecma_string_t *prop_name_p) /**< property's name */
108108
{

jerry-core/ecma/operations/ecma-reference.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ecma_object_t *ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, ecma_st
3030
ecma_value_t ecma_op_resolve_reference_value (ecma_object_t *lex_env_p, ecma_string_t *name_p);
3131
#if ENABLED (JERRY_ES2015)
3232
ecma_object_t *ecma_op_resolve_super_reference_value (ecma_object_t *lex_env_p);
33+
ecma_value_t ecma_op_is_prop_unscopable (ecma_object_t *lex_env_p, ecma_string_t *prop_name_p);
3334
#endif /* ENABLED (JERRY_ES2015) */
3435

3536
/**

tests/jerry/es2015/symbol-unscopables.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ with (obj2) {
7070
}
7171
}
7272

73+
var obj3 = { foo: 12 };
74+
Object.defineProperty(obj3, Symbol.unscopables, { get: function () { throw 42; } });
75+
76+
with (obj3) {
77+
try {
78+
typeof foo;
79+
} catch (e) {
80+
assert(e === 42);
81+
}
82+
}
83+
7384
var symbol_obj = Array.prototype[Symbol.unscopables];
7485
assert(symbol_obj.copyWithin === true);
7586
assert(symbol_obj.entries === true);
@@ -86,3 +97,10 @@ assert(obj3.value === true);
8697
assert(obj3.writable === true);
8798
assert(obj3.enumerable == true);
8899
assert(obj3.configurable == true);
100+
101+
var a = { foo: 1, bar: 2 };
102+
a[Symbol.unscopables] = { bar: true };
103+
with (a) {
104+
assert(foo === 1);
105+
assert(typeof bar === "undefined");
106+
}

0 commit comments

Comments
 (0)