From 637919bc72712125b34ebd9325e063cb7a03d7b7 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Mon, 3 Jul 2017 03:07:49 +0300 Subject: [PATCH] Testcase for + operator coercion order --- .../test-expr-add-coercion-order.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/ecmascript/test-expr-add-coercion-order.js diff --git a/tests/ecmascript/test-expr-add-coercion-order.js b/tests/ecmascript/test-expr-add-coercion-order.js new file mode 100644 index 00000000..b277b16a --- /dev/null +++ b/tests/ecmascript/test-expr-add-coercion-order.js @@ -0,0 +1,37 @@ +/*=== +o1 valueOf +o2 valueOf +foobar +o2 valueOf +o1 valueOf +barfoo +o1 valueOf +o2 valueOf +o3 valueOf +foobarquux +===*/ + +function test() { + var o1 = { + toString: function () { print('o1 toString'); return 'FOO' }, + valueOf: function () { print('o1 valueOf'); return 'foo' }, + }; + var o2 = { + toString: function () { print('o2 toString'); return 'BAR' }, + valueOf: function () { print('o2 valueOf'); return 'bar' }, + }; + var o3 = { + toString: function () { print('o3 toString'); return 'QUUX' }, + valueOf: function () { print('o3 valueOf'); return 'quux' }, + }; + + print(o1 + o2); + print(o2 + o1); + print(o1 + o2 + o3); +} + +try { + test(); +} catch (e) { + print(e.stack || e); +}