tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

setter-argument.html (6353B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>Setter should treat no arguments as undefined</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <body>
      7 <script>
      8 const invalidThisValues = [undefined, null, 1, {}, new Image()];
      9 
     10 // String attribute.
     11 
     12 test(() => {
     13  const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
     14 
     15  for (const thisValue of invalidThisValues) {
     16    assert_throws_js(TypeError, () => { setter.call(thisValue); });
     17    assert_throws_js(TypeError, () => { setter.call(thisValue, undefined); });
     18    assert_throws_js(TypeError, () => { setter.call(thisValue, "foo"); });
     19  }
     20 }, `String attribute setter should throw if this value is invalid`);
     21 
     22 test(() => {
     23  const thisValue = new Animation();
     24  const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
     25 
     26  assert_equals(thisValue.id, "");
     27 
     28  setter.call(thisValue);
     29  assert_equals(thisValue.id, "undefined",
     30               "undefined value should be stringified");
     31 }, `String attribute setter should treat no arguments as undefined`);
     32 
     33 test(() => {
     34  const thisValue = new Animation();
     35  const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
     36 
     37  assert_equals(thisValue.id, "");
     38 
     39  setter.call(thisValue, undefined);
     40  assert_equals(thisValue.id, "undefined",
     41               "undefined value should be stringified");
     42 }, `String attribute setter called with undefined should behave in the same way as no arguments`);
     43 
     44 test(() => {
     45  const thisValue = new Animation();
     46  const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
     47 
     48  assert_equals(thisValue.id, "");
     49 
     50  setter.call(thisValue, "foo");
     51  assert_equals(thisValue.id, "foo");
     52 }, `String attribute setter called with string should just work`);
     53 
     54 // Object attribute.
     55 
     56 test(() => {
     57  const setter = Object.getOwnPropertyDescriptor(Document.prototype, "body").set;
     58 
     59  for (const thisValue of invalidThisValues) {
     60    assert_throws_js(TypeError, () => { setter.call(thisValue); });
     61    assert_throws_js(TypeError, () => { setter.call(thisValue, undefined); });
     62    assert_throws_js(TypeError, () => { setter.call(thisValue, "foo"); });
     63  }
     64 }, `Object attribute setter should throw if this value is invalid`);
     65 
     66 test(() => {
     67  const thisValue = new Document();
     68  const setter = Object.getOwnPropertyDescriptor(Document.prototype, "body").set;
     69 
     70  assert_throws_dom("HierarchyRequestError", () => { setter.call(thisValue); });
     71 }, `Object attribute setter should treat no arguments as undefined`);
     72 
     73 test(() => {
     74  const thisValue = new Document();
     75  const setter = Object.getOwnPropertyDescriptor(Document.prototype, "body").set;
     76 
     77  assert_throws_dom("HierarchyRequestError", () => { setter.call(thisValue, undefined); });
     78 }, `Object attribute setter called with undefined should behave in the same way as no arguments`);
     79 
     80 // [Replaceable] attribute.
     81 
     82 test(() => {
     83  const thisValue = window;
     84  const setter = Object.getOwnPropertyDescriptor(window, "scrollX").set;
     85 
     86  setter.call(thisValue);
     87  assert_equals(thisValue.scrollX, undefined);
     88 }, `[Replaceable] setter should treat no arguments as undefined`);
     89 
     90 test(() => {
     91  const thisValue = window;
     92  const setter = Object.getOwnPropertyDescriptor(window, "screenLeft").set;
     93 
     94  setter.call(thisValue, undefined);
     95  assert_equals(thisValue.screenLeft, undefined);
     96 }, `[Replaceable] setter called with undefined should behave in the same way as no arguments`);
     97 
     98 test(() => {
     99  const thisValue = window;
    100  const setter = Object.getOwnPropertyDescriptor(window, "screenTop").set;
    101 
    102  setter.call(thisValue, "foo");
    103  assert_equals(thisValue.screenTop, "foo");
    104 }, `[Replaceable] setter called with other value should just work`);
    105 
    106 // [LegacyLenientThis] attribute.
    107 
    108 test(() => {
    109  const setter = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onmouseenter").set;
    110 
    111  for (const thisValue of invalidThisValues) {
    112    setter.call(thisValue);
    113    setter.call(thisValue, undefined);
    114    setter.call(thisValue, "foo");
    115  }
    116 }, `[LegacyLenientThis] setter should not throw even if this value is invalid, regardless of the arguments count`);
    117 
    118 test(() => {
    119  const thisValue = document.createElement("div");
    120  const setter = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onmouseenter").set;
    121 
    122  setter.call(thisValue);
    123  assert_equals(thisValue.onmouseenter, null);
    124 }, `[LegacyLenientThis] setter should treat no arguments as undefined`);
    125 
    126 test(() => {
    127  const thisValue = document.createElement("div");
    128  const setter = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onmouseenter").set;
    129 
    130  setter.call(thisValue, undefined);
    131  assert_equals(thisValue.onmouseenter, null);
    132 }, `[LegacyLenientThis] setter called with undefined should behave in the same way as no arguments`);
    133 
    134 // [LegacyLenientSetter] attribute.
    135 
    136 test(() => {
    137  const thisValue = new Document();
    138  const setter = Object.getOwnPropertyDescriptor(Document.prototype, "fullscreenEnabled").set;
    139 
    140  setter.call(thisValue);
    141  assert_equals(thisValue.fullscreenEnabled, false);
    142 }, `[LegacyLenientSetter] setter should treat no arguments as undefined`);
    143 
    144 test(() => {
    145  const thisValue = new Document();
    146  const setter = Object.getOwnPropertyDescriptor(Document.prototype, "fullscreenEnabled").set;
    147 
    148  setter.call(thisValue, undefined);
    149  assert_equals(thisValue.fullscreenEnabled, false);
    150 }, `[LegacyLenientSetter] setter called with undefined should behave in the same way as no arguments`);
    151 
    152 // [PutForward] attribute.
    153 
    154 test(() => {
    155  const thisValue = document.createElement("a");
    156  const setter = Object.getOwnPropertyDescriptor(HTMLAnchorElement.prototype, "relList").set;
    157 
    158  assert_equals(thisValue.relList.length, 0);
    159 
    160  setter.call(thisValue);
    161  assert_equals(thisValue.relList.length, 1);
    162  assert_equals(thisValue.relList[0], "undefined");
    163 }, `[PutForward] setter should treat no arguments as undefined`);
    164 
    165 test(() => {
    166  const thisValue = document.createElement("a");
    167  const setter = Object.getOwnPropertyDescriptor(HTMLAnchorElement.prototype, "relList").set;
    168 
    169  assert_equals(thisValue.relList.length, 0);
    170 
    171  setter.call(thisValue, undefined);
    172 
    173  assert_equals(thisValue.relList.length, 1);
    174  assert_equals(thisValue.relList[0], "undefined");
    175 }, `[PutForward] setter called with undefined should behave in the same way as no arguments`);
    176 </script>