Skip to content

Commit

Permalink
Fixed Object.defineProperty() when a recursive descriptor is provided.
Browse files Browse the repository at this point in the history
This closes #481 issue on Github.
  • Loading branch information
xeioex committed May 7, 2022
1 parent 99239ae commit 81af263
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/njs_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ njs_array_convert_to_slow_array(njs_vm_t *vm, njs_array_t *array)
njs_value_t index, value;
njs_object_prop_t *prop;

if (njs_slow_path(!array->object.fast_array)) {
return NJS_OK;
}

njs_set_array(&value, array);
array->object.fast_array = 0;

Expand Down
10 changes: 10 additions & 0 deletions src/test/njs_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13837,6 +13837,16 @@ static njs_unit_test_t njs_test[] =
"d.enumerable && d.writable && d.configurable"),
njs_str("true") },

{ njs_str("const arr = [1,2];"
"function f(arg) {"
" const desc = {get: arg};"
" Object.defineProperty(desc, 'set', desc);"
" Object.defineProperty(arr, 1, desc);"
"}"
"f(f);"
"njs.dump(arr)"),
njs_str("[1,'[Getter]']") },

{ njs_str("Object.defineProperties()"),
njs_str("TypeError: Object.defineProperties is called on non-object") },

Expand Down

0 comments on commit 81af263

Please sign in to comment.