Skip to content
Snippets Groups Projects
function-constructor.js 832 B
Newer Older
  • Learn to ignore specific revisions
  • /*---
    esid: pending
    description: >
        Hashbang comments should not be allowed in function evaluator contexts.
    info: |
        HashbangComment::
          #! SingleLineCommentChars[opt]
    
    features: [hashbang]
    
    const AsyncFunction = (async function (){}).constructor;
    const GeneratorFunction = (function *(){}).constructor;
    const AsyncGeneratorFunction = (async function *(){}).constructor;
    
    for (const ctor of [
    
      Function,
      AsyncFunction,
      GeneratorFunction,
      AsyncGeneratorFunction,
    ]) {
    
    Leo Balter's avatar
    Leo Balter committed
      assert.throws(SyntaxError, () => ctor('#!\n_', ''), `${ctor.name} Call argument`);
    
      assert.throws(SyntaxError, () => ctor('#!\n_'), `${ctor.name} Call body`);
    
    Leo Balter's avatar
    Leo Balter committed
      assert.throws(SyntaxError, () => new ctor('#!\n_', ''), `${ctor.name} Construct argument`);
    
      assert.throws(SyntaxError, () => new ctor('#!\n_'), `${ctor.name} Construct body`);
    }