From 2aa04859ef04d08654f6e8839a61106c84b0c6cb Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 29 Jun 2015 22:58:45 +0300 Subject: [PATCH] Fix handling of an exception raised during arguments list evaluation. Related issues: #260, #261, #262, #263, #264, #265, #266, #267 JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com --- jerry-core/vm/opcodes-varg.cpp | 8 ++--- tests/jerry/function-args.js | 9 +++++ tests/jerry/regression-test-issue-260.js | 18 ++++++++++ tests/jerry/regression-test-issue-261.js | 19 ++++++++++ tests/jerry/regression-test-issue-262.js | 19 ++++++++++ tests/jerry/regression-test-issue-263.js | 43 ++++++++++++++++++++++ tests/jerry/regression-test-issue-264.js | 45 ++++++++++++++++++++++++ tests/jerry/regression-test-issue-265.js | 28 +++++++++++++++ tests/jerry/regression-test-issue-266.js | 23 ++++++++++++ tests/jerry/regression-test-issue-267.js | 22 ++++++++++++ 10 files changed, 229 insertions(+), 5 deletions(-) create mode 100644 tests/jerry/regression-test-issue-260.js create mode 100644 tests/jerry/regression-test-issue-261.js create mode 100644 tests/jerry/regression-test-issue-262.js create mode 100644 tests/jerry/regression-test-issue-263.js create mode 100644 tests/jerry/regression-test-issue-264.js create mode 100644 tests/jerry/regression-test-issue-265.js create mode 100644 tests/jerry/regression-test-issue-266.js create mode 100644 tests/jerry/regression-test-issue-267.js diff --git a/jerry-core/vm/opcodes-varg.cpp b/jerry-core/vm/opcodes-varg.cpp index 3dc0d37f8..84da3b960 100644 --- a/jerry-core/vm/opcodes-varg.cpp +++ b/jerry-core/vm/opcodes-varg.cpp @@ -37,8 +37,8 @@ fill_varg_list (int_data_t *int_data, /**< interpreter context */ ecma_length_t arg_index; for (arg_index = 0; - arg_index < args_number; - arg_index++) + arg_index < args_number && ecma_is_completion_value_empty (ret_value); + ) { ecma_completion_value_t evaluate_arg_completion = vm_loop (int_data, NULL); @@ -54,7 +54,7 @@ fill_varg_list (int_data_t *int_data, /**< interpreter context */ if (ecma_is_completion_value_normal (get_arg_completion)) { - arg_values[arg_index] = ecma_get_completion_value_value (get_arg_completion); + arg_values[arg_index++] = ecma_get_completion_value_value (get_arg_completion); } else { @@ -68,8 +68,6 @@ fill_varg_list (int_data_t *int_data, /**< interpreter context */ JERRY_ASSERT (ecma_is_completion_value_throw (evaluate_arg_completion)); ret_value = evaluate_arg_completion; - - break; } int_data->pos++; diff --git a/tests/jerry/function-args.js b/tests/jerry/function-args.js index 96f45d628..e69bcb060 100644 --- a/tests/jerry/function-args.js +++ b/tests/jerry/function-args.js @@ -44,3 +44,12 @@ for(i = 11; i <= 20; i++) { f1(i); } + +try { + f1 ({}); + f1 (undefined_variable); + assert (false); +} +catch (e) { + assert (e instanceof ReferenceError); +} diff --git a/tests/jerry/regression-test-issue-260.js b/tests/jerry/regression-test-issue-260.js new file mode 100644 index 000000000..e72713187 --- /dev/null +++ b/tests/jerry/regression-test-issue-260.js @@ -0,0 +1,18 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try { + isNaN(__proto__); +} catch (e) {} diff --git a/tests/jerry/regression-test-issue-261.js b/tests/jerry/regression-test-issue-261.js new file mode 100644 index 000000000..1f5d92da9 --- /dev/null +++ b/tests/jerry/regression-test-issue-261.js @@ -0,0 +1,19 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try { + SyntaxError(RegExp()); + isFinite(foo); +} catch (e) {} diff --git a/tests/jerry/regression-test-issue-262.js b/tests/jerry/regression-test-issue-262.js new file mode 100644 index 000000000..61deb4f55 --- /dev/null +++ b/tests/jerry/regression-test-issue-262.js @@ -0,0 +1,19 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try { + RegExp(""); + eval(encodeURI(isNaN(__proto__))); +} catch (e) { } diff --git a/tests/jerry/regression-test-issue-263.js b/tests/jerry/regression-test-issue-263.js new file mode 100644 index 000000000..04bcf9627 --- /dev/null +++ b/tests/jerry/regression-test-issue-263.js @@ -0,0 +1,43 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try { + Boolean(decodeURI(decodeURIComponent(Number()))); +} catch(err) {} + try { + ReferenceError(isNaN(__proto__)); + } catch(err) {} + try { + isNaN(__proto__); + } catch(err) {} + try { + load(); + } catch(err) {} + try { + RegExp("\n"); + } catch(err) {} + try {} catch(err) {} + try { + ReferenceError(performance.__proto__.isPrototypeOf(arguments.map(os))); + } catch(err) {} + try { + Float64Array(performance,WeakSet(),Infinity.valueOf()); + } catch(err) {} + try { + arguments.push(Int8Array(Boolean(isFinite(quit())),ArrayBuffer(os.system()),Array(read()))); + } catch(err) {} + try { + Boolean(encodeURI(DataView(ArrayBuffer(os),parseFloat(Set()),URIError(Object(Int8Array(Function(parseInt(write(),RangeError(__proto__.valueOf()))),Int16Array(Map(),__proto__.valueOf(),readbuffer()),Math)))))); + } catch(err) {} diff --git a/tests/jerry/regression-test-issue-264.js b/tests/jerry/regression-test-issue-264.js new file mode 100644 index 000000000..23417b9c4 --- /dev/null +++ b/tests/jerry/regression-test-issue-264.js @@ -0,0 +1,45 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try { + Boolean(decodeURI(decodeURIComponent(Number()))); + } catch(err) {} + try { + ReferenceError(isNaN(__proto__)); + } catch(err) {} + try { + isNaN(__proto__); + } catch(err) {} + try { + load(); + } catch(err) {} + try { + RegExp("\n"); + } catch(err) {} + try { + Set(); + } catch(err) {} + try { + ReferenceError(performance.__proto__.isPrototypeOf(arguments.map(os))); + } catch(err) {} + try { + Float64Array(performance,WeakSet(),Infinity.valueOf()); + } catch(err) {} + try { + arguments.push(Int8Array(Boolean(isFinite(quit())),ArrayBuffer(os.system()),Array(read()))); + } catch(err) {} + try { + Boolean(encodeURI(DataView(ArrayBuffer(os),parseFloat(Set()),URIError(Object(Int8Array(Function(parseInt(write(),RangeError(__proto__.valueOf()))),Int16Array(Map(),__proto__.valueOf(),readbuffer()),Math)))))); + } catch(err) {} diff --git a/tests/jerry/regression-test-issue-265.js b/tests/jerry/regression-test-issue-265.js new file mode 100644 index 000000000..942b5813d --- /dev/null +++ b/tests/jerry/regression-test-issue-265.js @@ -0,0 +1,28 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +parseInt(NaN,RegExp("54")); + +try { + parseInt(ArrayBuffer()); +} catch(err) {} + +try { + isNaN(__proto__); +} catch(err) {} + +try { + RangeError(parseInt(Infinity,readbuffer())); +} catch (err) {} diff --git a/tests/jerry/regression-test-issue-266.js b/tests/jerry/regression-test-issue-266.js new file mode 100644 index 000000000..14a9473a1 --- /dev/null +++ b/tests/jerry/regression-test-issue-266.js @@ -0,0 +1,23 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try { + String("test"); + isNaN(__proto__); +} catch(err) {} + +try { + SyntaxError(RegExp("[/]")); +} catch(err) {} diff --git a/tests/jerry/regression-test-issue-267.js b/tests/jerry/regression-test-issue-267.js new file mode 100644 index 000000000..763a8eaea --- /dev/null +++ b/tests/jerry/regression-test-issue-267.js @@ -0,0 +1,22 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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. + +try { + RegExp("\u2029"); +} catch(err) {} + +try { + URIError(isNaN(__proto__)); +} catch(err) {}