js/src/jit-test/tests/arguments/args-attributes.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 function strictArgs() {
     2     return (function (a, b, c) {'use strict'; return arguments; })(1, 2);
     3 }
     5 function normalArgs() {
     6     return (function (a, b, c) { return arguments; })(1, 2);
     7 }
     9 function checkProperty(options, prop, shouldThrow) {
    10     var desc, orig;
    11     var obj = options.strict ? strictArgs() : normalArgs();
    12     var objType = options.strict ? "strict arguments." : "normal arguments.";
    14     function check() {
    15         orig = Object.getOwnPropertyDescriptor(obj, prop);
    17         var threw = false;
    18         try {
    19             obj[prop] = obj[prop];
    20         }
    21         catch (e) {
    22             threw = true;
    23         }
    24         assertEq(threw, shouldThrow, objType + prop + " threw");
    26         if (orig === undefined) {
    27             // The property wasn't defined, so we can skip it.
    28             return;
    29         }
    31         desc = Object.getOwnPropertyDescriptor(obj, prop);
    32         if ("value" in orig) {
    33             assertEq(desc.value, orig.value, objType + prop + " value");
    34         } else {
    35             assertEq(desc.get, orig.get, objType + prop + " get");
    36             assertEq(desc.set, orig.set, objType + prop + " set");
    37         }
    38         assertEq(desc.writable, orig.writable, objType + prop + " writable");
    39         assertEq(desc.enumerable, orig.enumerable, objType + prop + " enumerable");
    40         assertEq(desc.configurable, orig.configurable, objType + prop + " configurable");
    41     }
    43     check();
    45     if (orig && orig.configurable) {
    46         if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }
    47         Object.defineProperty(obj, prop, {writable: false, enumerable: true});
    48         check();
    50         if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }
    51         Object.defineProperty(obj, prop, {writable: true, enumerable: false});
    52         check();
    54         if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }
    55         Object.defineProperty(obj, prop, {writable: false, configurable: false});
    56         check();
    57     }
    58 }
    60 checkProperty({strict: true, refresh: true}, 'callee', true);
    61 checkProperty({strict: true, refresh: false}, 'callee', true);
    62 checkProperty({strict: false, refresh: true}, 'callee', false);
    63 checkProperty({strict: false, refresh: false}, 'callee', false);
    65 checkProperty({strict: true, refresh: true}, 'length', false);
    66 checkProperty({strict: true, refresh: false}, 'length', false);
    67 checkProperty({strict: false, refresh: true}, 'length', false);
    68 checkProperty({strict: false, refresh: false}, 'length', false);
    70 for (var i = 0; i <= 5; i++) {
    71     checkProperty({strict: true, refresh: true}, "" + i, false);
    72     checkProperty({strict: true, refresh: false}, "" + i, false);
    73     checkProperty({strict: false, refresh: true}, "" + i, false);
    74     checkProperty({strict: false, refresh: false}, "" + i, false);
    75 }

mercurial