From 81ec43cca78c06f9fac05e39fb7e2a9bc4a29552 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Mon, 19 Dec 2016 02:00:14 +0200 Subject: [PATCH] Add object literal ancestor test --- ...t-dev-object-literal-offending-ancestor.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/ecmascript/test-dev-object-literal-offending-ancestor.js diff --git a/tests/ecmascript/test-dev-object-literal-offending-ancestor.js b/tests/ecmascript/test-dev-object-literal-offending-ancestor.js new file mode 100644 index 00000000..2ee074a6 --- /dev/null +++ b/tests/ecmascript/test-dev-object-literal-offending-ancestor.js @@ -0,0 +1,51 @@ +/* + * Properties inherited from Object.prototype must not prevent object + * literal creation. This ensures the internal code setting the object + * properties doesn't accidentally invoke side effects, etc. + */ + +/*=== +{"nonConfigurable":123,"nonWritable":234,"nonConfigurableNonWritable":345,"nonConfigurableSetter":456} +===*/ + +function test() { + Object.defineProperties(Object.prototype, { + nonConfigurable: { + value: 'ancestor', + writable: true, + enumerable: false, + configurable: false + }, + nonWritable: { + value: 'ancestor', + writable: false, + enumerable: false, + configurable: true + }, + nonConfigurableNonWritable: { + value: 'ancestor', + writable: false, + enumerable: false, + configurable: false + }, + nonConfigurableSetter: { + set: function (v) { print('SETTER CALLED!'); }, + enumerable: false, + configurable: false + } + }); + + var obj = { + nonConfigurable: 123, + nonWritable: 234, + nonConfigurableNonWritable: 345, + nonConfigurableSetter: 456 + }; + print(JSON.stringify(obj)); +} + +try { + test(); +} catch (e) { + print(e.stack || e); +}