js/src/jit-test/tests/proxy/testDirectProxyGet3.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/proxy/testDirectProxyGet3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +load(libdir + "asserts.js");
     1.5 +
     1.6 +/*
     1.7 + * Throw a TypeError if the trap reports a different value for a non-writable,
     1.8 + * non-configurable property
     1.9 + */
    1.10 +var target = {};
    1.11 +Object.defineProperty(target, 'foo', {
    1.12 +    value: 'bar',
    1.13 +    writable: false,
    1.14 +    configurable: false
    1.15 +});
    1.16 +assertThrowsInstanceOf(function () {
    1.17 +    new Proxy(target, {
    1.18 +        get: function (target, name, receiver) {
    1.19 +            return 'baz';
    1.20 +        }
    1.21 +    })['foo'];
    1.22 +}, TypeError);
    1.23 +
    1.24 +/*
    1.25 + * Don't throw a TypeError if the trap reports the same value for a non-writable,
    1.26 + * non-configurable property
    1.27 + */
    1.28 +assertEq(new Proxy(target, {
    1.29 +        get: function (target, name, receiver) {
    1.30 +            return 'bar';
    1.31 +        }
    1.32 +    })['foo'],
    1.33 +    'bar');
    1.34 +
    1.35 +
    1.36 +/*
    1.37 + * Don't throw a TypeError if the trap reports a different value for a writable,
    1.38 + * non-configurable property
    1.39 + */
    1.40 +Object.defineProperty(target, 'prop', {
    1.41 +    value: 'bar',
    1.42 +    writable: true,
    1.43 +    configurable: false
    1.44 +});
    1.45 +assertEq(new Proxy(target, {
    1.46 +        get: function (target, name, receiver) {
    1.47 +            return 'baz';
    1.48 +        }
    1.49 +    })['prop'],
    1.50 +    'baz');
    1.51 +
    1.52 +
    1.53 +/*
    1.54 + * Don't throw a TypeError if the trap reports a different value for a non-writable,
    1.55 + * configurable property
    1.56 + */
    1.57 +Object.defineProperty(target, 'prop2', {
    1.58 +    value: 'bar',
    1.59 +    writable: false,
    1.60 +    configurable: true
    1.61 +});
    1.62 +assertEq(new Proxy(target, {
    1.63 +        get: function (target, name, receiver) {
    1.64 +            return 'baz';
    1.65 +        }
    1.66 +    })['prop2'],
    1.67 +    'baz');

mercurial