Repository: jerryscript-project/jerryscript
File: tests/jerry/es.next/proxy-evil-recursion.js (JavaScript)

Code before:
// 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.

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/* Stack limit check must be enabled to run this test correctly! */

function expect_error(error_type, method) {
  try {
    method();
    assert(false);
  } catch (ex) {
    assert (ex instanceof error_type);
  }
}

/**
 * Create a proxy with recursion via prototype
 */
var proxy_one = new Proxy({length:2}, {});

Reflect.setPrototypeOf(proxy_one, proxy_one); /* [[SetPrototypeOf]] does not trigger recursion */
// aka. proxy_one.__proto__ = proxy_one; /* [[SetPrototypeOf]] */

function test_proxy_internals_using_proto(proxy_obj) {
  /* These methods can be recursive calls via prototype */
  expect_error(RangeError, function() { proxy_obj[1]; /* [[Get]] */ });
  expect_error(RangeError, function() { proxy_obj[1] = 2; /* [[Set]] */ });
  expect_error(RangeError, function() { 3 in proxy_obj; /* [[Has]] */ });

Review comment (refactor):
I think that this should be handled. Copy-pasting these 3 lines here has no real meaning as there is no LICENSE file that is referred. Most probably the whole contents of the original LICENSE file should be copied here, similarly to jerry-core/ecma/base/ecma-helpers-errol.c or jerry-math/acos.c .

Code after:
// 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.

/* Stack limit check must be enabled to run this test correctly! */

function expect_error(error_type, method) {
  try {
    method();
    assert(false);
  } catch (ex) {
    assert (ex instanceof error_type);
  }
}

/**
 * Create a proxy with recursion via prototype
 */
var proxy_one = new Proxy({length:2}, {});

Reflect.setPrototypeOf(proxy_one, proxy_one); /* [[SetPrototypeOf]] does not trigger recursion */
// aka. proxy_one.__proto__ = proxy_one; /* [[SetPrototypeOf]] */

function test_proxy_internals_using_proto(proxy_obj) {
  /* These methods can be recursive calls via prototype */
  expect_error(RangeError, function() { proxy_obj[1]; /* [[Get]] */ });
  expect_error(RangeError, function() { proxy_obj[1] = 2; /* [[Set]] */ });
  expect_error(RangeError, function() { 3 in proxy_obj; /* [[Has]] */ });
  expect_error(RangeError, function() { Reflect.has(proxy_obj, 3); /* [[Has]] */ });
}

test_proxy_internals_using_proto(proxy_one);