From 8ed0454332beae12e7ff1704530500f342048c71 Mon Sep 17 00:00:00 2001 From: "franziska.hinkelmann" Date: Wed, 14 Oct 2015 12:22:17 -0700 Subject: [PATCH] Emit better error message about writable properties Section 8.10.5 9a specifies that a property descriptor cannot both have accessors and specify the writability of the property. The previous error message was misleading because it referred to writable rather than specifying the writability (which includes writable: false). BUG=v8:2536 LOG=N Review URL: https://codereview.chromium.org/1399693003 Cr-Commit-Position: refs/heads/master@{#31273} --- AUTHORS | 1 + src/messages.h | 4 ++-- test/mjsunit/messages.js | 4 ++-- test/webkit/Object-defineProperties-expected.txt | 2 +- test/webkit/fast/js/Object-defineProperty-expected.txt | 10 +++++----- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9dfb07328e..b588084044 100644 --- a/AUTHORS +++ b/AUTHORS @@ -54,6 +54,7 @@ Erich Ocean Fedor Indutny Felix Geisendörfer Filipe David Manana +Franziska Hinkelmann Geoffrey Garside Han Choongwoo Hirofumi Mako diff --git a/src/messages.h b/src/messages.h index a47bf57d45..12bc86d5cb 100644 --- a/src/messages.h +++ b/src/messages.h @@ -237,8 +237,8 @@ class CallSite { T(SimdToNumber, "Cannot convert a SIMD value to a number") \ T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \ T(ValueAndAccessor, \ - "Invalid property. A property cannot both have accessors and be " \ - "writable or have a value, %") \ + "Invalid property descriptor. Cannot both specify accessors and a value " \ + "or writable attribute, %") \ T(VarRedeclaration, "Identifier '%' has already been declared") \ T(WithExpression, "% has no properties") \ T(WrongArgs, "%: Arguments list has wrong type") \ diff --git a/test/mjsunit/messages.js b/test/mjsunit/messages.js index bb0d0e664a..cb1d016ab0 100644 --- a/test/mjsunit/messages.js +++ b/test/mjsunit/messages.js @@ -332,8 +332,8 @@ test(function() { // kValueAndAccessor test(function() { Object.defineProperty({}, "x", { get: function(){}, value: 1}); -}, "Invalid property. A property cannot both have accessors and be " + - "writable or have a value, #", TypeError); +}, "Invalid property descriptor. Cannot both specify accessors " + + "and a value or writable attribute, #", TypeError); // kWithExpression test(function() { diff --git a/test/webkit/Object-defineProperties-expected.txt b/test/webkit/Object-defineProperties-expected.txt index 50178b9064..ae3fc313ca 100644 --- a/test/webkit/Object-defineProperties-expected.txt +++ b/test/webkit/Object-defineProperties-expected.txt @@ -34,7 +34,7 @@ PASS JSON.stringify(Object.defineProperties({},{property:{value:'foo'}, property PASS JSON.stringify(Object.defineProperties({property:'foo'},{property:{value:'foo', enumerable:true}, property2:{value:'foo', enumerable:true}})) is '{"property":"foo","property2":"foo"}' PASS JSON.stringify(Object.defineProperties({property:'foo'},{property:{value:'foo', enumerable:false}, property2:{value:'foo', enumerable:true}})) is '{"property2":"foo"}' PASS JSON.stringify(Object.defineProperties({property:'foo'},{property:{value:'foo'}, property2:{value:'foo', enumerable:true}})) is '{"property":"foo","property2":"foo"}' -PASS Object.defineProperties(emptyObject, {foo:{value: true}, bar:{get:function(){}, writable:true}}) threw exception TypeError: Invalid property. A property cannot both have accessors and be writable or have a value, #. +PASS Object.defineProperties(emptyObject, {foo:{value: true}, bar:{get:function(){}, writable:true}}) threw exception TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #. PASS 'foo' in emptyObject is false PASS successfullyParsed is true diff --git a/test/webkit/fast/js/Object-defineProperty-expected.txt b/test/webkit/fast/js/Object-defineProperty-expected.txt index 561b7a7601..3687dd458d 100644 --- a/test/webkit/fast/js/Object-defineProperty-expected.txt +++ b/test/webkit/fast/js/Object-defineProperty-expected.txt @@ -45,17 +45,17 @@ PASS Object.defineProperty(null) threw exception TypeError: Object.definePropert PASS Object.defineProperty('foo') threw exception TypeError: Object.defineProperty called on non-object. PASS Object.defineProperty({}) threw exception TypeError: Property description must be an object: undefined. PASS Object.defineProperty({}, 'foo') threw exception TypeError: Property description must be an object: undefined. -PASS Object.defineProperty({}, 'foo', {get:undefined, value:true}).foo threw exception TypeError: Invalid property. A property cannot both have accessors and be writable or have a value, #. +PASS Object.defineProperty({}, 'foo', {get:undefined, value:true}).foo threw exception TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #. PASS Object.defineProperty({get foo() { return true; } }, 'foo', {configurable:false}).foo is true PASS Object.defineProperty(createUnconfigurableProperty({}, 'foo'), 'foo', {configurable: true}) threw exception TypeError: Cannot redefine property: foo. PASS Object.defineProperty(createUnconfigurableProperty({}, 'foo'), 'foo', {writable: true}) threw exception TypeError: Cannot redefine property: foo. PASS Object.defineProperty(createUnconfigurableProperty({}, 'foo'), 'foo', {enumerable: true}) threw exception TypeError: Cannot redefine property: foo. PASS Object.defineProperty(createUnconfigurableProperty({}, 'foo', false, true), 'foo', {enumerable: false}), 'foo' threw exception TypeError: Cannot redefine property: foo. PASS JSON.stringify(Object.getOwnPropertyDescriptor(Object.defineProperty(createUnconfigurableProperty({}, 'foo', true), 'foo', {writable: false}), 'foo')) is JSON.stringify({value: 1, writable: false, enumerable: false, configurable: false}) -PASS Object.defineProperty({}, 'foo', {value:1, get: function(){}}) threw exception TypeError: Invalid property. A property cannot both have accessors and be writable or have a value, #. -PASS Object.defineProperty({}, 'foo', {value:1, set: function(){}}) threw exception TypeError: Invalid property. A property cannot both have accessors and be writable or have a value, #. -PASS Object.defineProperty({}, 'foo', {writable:true, get: function(){}}) threw exception TypeError: Invalid property. A property cannot both have accessors and be writable or have a value, #. -PASS Object.defineProperty({}, 'foo', {writable:true, set: function(){}}) threw exception TypeError: Invalid property. A property cannot both have accessors and be writable or have a value, #. +PASS Object.defineProperty({}, 'foo', {value:1, get: function(){}}) threw exception TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #. +PASS Object.defineProperty({}, 'foo', {value:1, set: function(){}}) threw exception TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #. +PASS Object.defineProperty({}, 'foo', {writable:true, get: function(){}}) threw exception TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #. +PASS Object.defineProperty({}, 'foo', {writable:true, set: function(){}}) threw exception TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #. PASS Object.defineProperty({}, 'foo', {get: null}) threw exception TypeError: Getter must be a function: null. PASS Object.defineProperty({}, 'foo', {set: null}) threw exception TypeError: Setter must be a function: null. PASS Object.defineProperty({}, 'foo', {set: setter}).foo='test' threw exception called setter.