tor-browser

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

methods-restricted-properties.js (2281B)


      1 // Copyright (C) 2015 Caitlin Potter. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: >
      6    Functions created using MethodDefinition syntactic form do not have own
      7    properties "caller" or "arguments", but inherit them from
      8    %FunctionPrototype%.
      9 es6id: 16.1
     10 ---*/
     11 
     12 class Class {
     13  method() {}
     14  get accessor() {}
     15  set accessor(x) {}
     16 };
     17 
     18 var instance = new Class;
     19 var accessor = Object.getOwnPropertyDescriptor(Class.prototype, "accessor");
     20 
     21 assert.sameValue(
     22  instance.method.hasOwnProperty('caller'),
     23  false,
     24  'No "caller" own property (method)'
     25 );
     26 assert.sameValue(
     27  instance.method.hasOwnProperty('arguments'),
     28  false,
     29  'No "arguments" own property (method)'
     30 );
     31 assert.sameValue(
     32  accessor.get.hasOwnProperty('caller'),
     33  false,
     34  'No "caller" own property ("get" accessor)'
     35 );
     36 assert.sameValue(
     37  accessor.get.hasOwnProperty('arguments'),
     38  false,
     39  'No "arguments" own property ("get" accessor)'
     40 );
     41 assert.sameValue(
     42  accessor.set.hasOwnProperty('caller'),
     43  false,
     44  'No "caller" own property ("set" accessor)'
     45 );
     46 assert.sameValue(
     47  accessor.set.hasOwnProperty('arguments'),
     48  false,
     49  'No "arguments" own property ("set" accessor)'
     50 );
     51 
     52 // --- Test method restricted properties throw
     53 
     54 assert.throws(TypeError, function() {
     55  return instance.method.caller;
     56 });
     57 
     58 assert.throws(TypeError, function() {
     59  instance.method.caller = {};
     60 });
     61 
     62 assert.throws(TypeError, function() {
     63  return instance.method.arguments;
     64 });
     65 
     66 assert.throws(TypeError, function() {
     67  instance.method.arguments = {};
     68 });
     69 
     70 // --- Test getter restricted properties throw
     71 
     72 assert.throws(TypeError, function() {
     73  return accessor.get.caller;
     74 });
     75 
     76 assert.throws(TypeError, function() {
     77  accessor.get.caller = {};
     78 });
     79 
     80 assert.throws(TypeError, function() {
     81  return accessor.get.arguments;
     82 });
     83 
     84 assert.throws(TypeError, function() {
     85  accessor.get.arguments = {};
     86 });
     87 
     88 // --- Test setter restricted properties throw
     89 
     90 assert.throws(TypeError, function() {
     91  return accessor.set.caller;
     92 });
     93 
     94 assert.throws(TypeError, function() {
     95  accessor.set.caller = {};
     96 });
     97 
     98 assert.throws(TypeError, function() {
     99  return accessor.set.arguments;
    100 });
    101 
    102 assert.throws(TypeError, function() {
    103  accessor.set.arguments = {};
    104 });
    105 
    106 reportCompare(0, 0);