From 3ddcec6e64a63a3aa8e688d3699e0ec7e153579e Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Mon, 3 Dec 2018 15:55:42 -0600 Subject: [PATCH 1/3] Add tests for Hashbang comments --- test/language/comments/hashbang-eval.js | 10 ++++++++ .../comments/hashbang-function-constructor.js | 23 +++++++++++++++++++ test/language/comments/hashbang-module.js | 10 ++++++++ .../comments/hashbang-multi-line-comment.js | 15 ++++++++++++ .../comments/hashbang-no-line-separator.js | 10 ++++++++ test/language/comments/hashbang-not-empty.js | 10 ++++++++ .../hashbang-preceding-directive-prologue.js | 14 +++++++++++ .../hashbang-preceding-empty-statement.js | 13 +++++++++++ .../comments/hashbang-preceding-hashbang.js | 14 +++++++++++ .../hashbang-preceding-line-comment.js | 14 +++++++++++ .../hashbang-preceding-multi-line-comment.js | 14 +++++++++++ .../comments/hashbang-preceding-whitespace.js | 13 +++++++++++ .../comments/hashbang-statement-block.js | 15 ++++++++++++ test/language/comments/hashbang-use-strict.js | 11 +++++++++ 14 files changed, 186 insertions(+) create mode 100644 test/language/comments/hashbang-eval.js create mode 100644 test/language/comments/hashbang-function-constructor.js create mode 100644 test/language/comments/hashbang-module.js create mode 100644 test/language/comments/hashbang-multi-line-comment.js create mode 100644 test/language/comments/hashbang-no-line-separator.js create mode 100644 test/language/comments/hashbang-not-empty.js create mode 100644 test/language/comments/hashbang-preceding-directive-prologue.js create mode 100644 test/language/comments/hashbang-preceding-empty-statement.js create mode 100644 test/language/comments/hashbang-preceding-hashbang.js create mode 100644 test/language/comments/hashbang-preceding-line-comment.js create mode 100644 test/language/comments/hashbang-preceding-multi-line-comment.js create mode 100644 test/language/comments/hashbang-preceding-whitespace.js create mode 100644 test/language/comments/hashbang-statement-block.js create mode 100644 test/language/comments/hashbang-use-strict.js diff --git a/test/language/comments/hashbang-eval.js b/test/language/comments/hashbang-eval.js new file mode 100644 index 00000000000..a4052eb060d --- /dev/null +++ b/test/language/comments/hashbang-eval.js @@ -0,0 +1,10 @@ +/*--- +esid: pending +description: > + Hashbang comments should be available in Script evaluator contexts. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +---*/ + +eval('#!\n'); diff --git a/test/language/comments/hashbang-function-constructor.js b/test/language/comments/hashbang-function-constructor.js new file mode 100644 index 00000000000..62430556f15 --- /dev/null +++ b/test/language/comments/hashbang-function-constructor.js @@ -0,0 +1,23 @@ +/*--- +esid: pending +description: > + Hashbang comments should not be allowed in function evaluator contexts. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [module] +---*/ +const AsyncFunction = (async function (){}).constructor; +const GeneratorFunction = (function *(){}).constructor; +const AsyncGeneratorFunction = (async function *(){}).constructor; +for (ctor of [ + Function, + AsyncFunction, + GeneratorFunction, + AsyncGeneratorFunction, +]) { + assert.throws(SyntaxError, () => ctor('#!\n_','')); + assert.throws(SyntaxError, () => ctor('#!\n_')); + assert.throws(SyntaxError, () => new ctor('#!\n_','')); + assert.throws(SyntaxError, () => new ctor('#!\n_')); +} diff --git a/test/language/comments/hashbang-module.js b/test/language/comments/hashbang-module.js new file mode 100644 index 00000000000..ea30c700f69 --- /dev/null +++ b/test/language/comments/hashbang-module.js @@ -0,0 +1,10 @@ +#! +/*--- +esid: pending +description: > + Hashbang comments should be allowed in Modules. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [module] +---*/ diff --git a/test/language/comments/hashbang-multi-line-comment.js b/test/language/comments/hashbang-multi-line-comment.js new file mode 100644 index 00000000000..b681ef2407c --- /dev/null +++ b/test/language/comments/hashbang-multi-line-comment.js @@ -0,0 +1,15 @@ +#!/* +these characters should not be considered within a comment +*/ +/*--- +esid: pending +description: > + Hashbang comments should not interpret multi-line comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-no-line-separator.js b/test/language/comments/hashbang-no-line-separator.js new file mode 100644 index 00000000000..bf49dd53b1d --- /dev/null +++ b/test/language/comments/hashbang-no-line-separator.js @@ -0,0 +1,10 @@ +/*--- +esid: pending +description: > + Hashbang comments should not require a newline afterwards +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +---*/ + +eval('#!'); diff --git a/test/language/comments/hashbang-not-empty.js b/test/language/comments/hashbang-not-empty.js new file mode 100644 index 00000000000..f9ba96554ff --- /dev/null +++ b/test/language/comments/hashbang-not-empty.js @@ -0,0 +1,10 @@ +#! these characters should be treated as a comment +/*--- +esid: pending +description: > + Hashbang comments should be allowed in Scripts and should not be required to be empty. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +---*/ + diff --git a/test/language/comments/hashbang-preceding-directive-prologue.js b/test/language/comments/hashbang-preceding-directive-prologue.js new file mode 100644 index 00000000000..5c1a84c7c4d --- /dev/null +++ b/test/language/comments/hashbang-preceding-directive-prologue.js @@ -0,0 +1,14 @@ +"use strict" +#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at start of source texts and should not be preceded by DirectivePrologues. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-empty-statement.js b/test/language/comments/hashbang-preceding-empty-statement.js new file mode 100644 index 00000000000..4adc4c8cab3 --- /dev/null +++ b/test/language/comments/hashbang-preceding-empty-statement.js @@ -0,0 +1,13 @@ +;#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by empty statements. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-hashbang.js b/test/language/comments/hashbang-preceding-hashbang.js new file mode 100644 index 00000000000..a5435b7a600 --- /dev/null +++ b/test/language/comments/hashbang-preceding-hashbang.js @@ -0,0 +1,14 @@ +#! +#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by Hashbang comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-line-comment.js b/test/language/comments/hashbang-preceding-line-comment.js new file mode 100644 index 00000000000..f50b1ca2bb7 --- /dev/null +++ b/test/language/comments/hashbang-preceding-line-comment.js @@ -0,0 +1,14 @@ +// +#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by line comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-multi-line-comment.js b/test/language/comments/hashbang-preceding-multi-line-comment.js new file mode 100644 index 00000000000..72b19c23d0d --- /dev/null +++ b/test/language/comments/hashbang-preceding-multi-line-comment.js @@ -0,0 +1,14 @@ +/* +*/#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by multi-line comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-whitespace.js b/test/language/comments/hashbang-preceding-whitespace.js new file mode 100644 index 00000000000..43250755262 --- /dev/null +++ b/test/language/comments/hashbang-preceding-whitespace.js @@ -0,0 +1,13 @@ + #!/bin/sh +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by whitespace. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-statement-block.js b/test/language/comments/hashbang-statement-block.js new file mode 100644 index 00000000000..397f0fe2aec --- /dev/null +++ b/test/language/comments/hashbang-statement-block.js @@ -0,0 +1,15 @@ +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be allowed within blocks. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] + +negative: + phase: parse + type: SyntaxError +---*/ +{ + #! +} \ No newline at end of file diff --git a/test/language/comments/hashbang-use-strict.js b/test/language/comments/hashbang-use-strict.js new file mode 100644 index 00000000000..26a018408a7 --- /dev/null +++ b/test/language/comments/hashbang-use-strict.js @@ -0,0 +1,11 @@ +#!"use strict" +/*--- +esid: pending +description: > + Hashbang comments should not be interpretted and should not generate DirectivePrologues. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +---*/ + +with ({}) {} From 1f84c8fc36dc33fba74338231f3648f04e81014b Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Mon, 3 Dec 2018 16:32:30 -0600 Subject: [PATCH 2/3] nits --- test/language/comments/hashbang-eval.js | 2 +- test/language/comments/hashbang-function-constructor.js | 8 ++++---- test/language/comments/hashbang-multi-line-comment.js | 2 +- test/language/comments/hashbang-no-line-separator.js | 1 + test/language/comments/hashbang-not-empty.js | 1 + .../comments/hashbang-preceding-directive-prologue.js | 2 +- .../comments/hashbang-preceding-empty-statement.js | 2 +- test/language/comments/hashbang-preceding-hashbang.js | 2 +- test/language/comments/hashbang-preceding-line-comment.js | 2 +- .../comments/hashbang-preceding-multi-line-comment.js | 2 +- test/language/comments/hashbang-preceding-whitespace.js | 4 ++-- test/language/comments/hashbang-statement-block.js | 2 +- test/language/comments/hashbang-use-strict.js | 1 + 13 files changed, 17 insertions(+), 14 deletions(-) diff --git a/test/language/comments/hashbang-eval.js b/test/language/comments/hashbang-eval.js index a4052eb060d..8f69cd81bcb 100644 --- a/test/language/comments/hashbang-eval.js +++ b/test/language/comments/hashbang-eval.js @@ -7,4 +7,4 @@ info: | #! SingleLineCommentChars[opt] ---*/ -eval('#!\n'); +assert.sameValue(eval('#!\n'), undefined); diff --git a/test/language/comments/hashbang-function-constructor.js b/test/language/comments/hashbang-function-constructor.js index 62430556f15..1e48cf23c9d 100644 --- a/test/language/comments/hashbang-function-constructor.js +++ b/test/language/comments/hashbang-function-constructor.js @@ -16,8 +16,8 @@ for (ctor of [ GeneratorFunction, AsyncGeneratorFunction, ]) { - assert.throws(SyntaxError, () => ctor('#!\n_','')); - assert.throws(SyntaxError, () => ctor('#!\n_')); - assert.throws(SyntaxError, () => new ctor('#!\n_','')); - assert.throws(SyntaxError, () => new ctor('#!\n_')); + assert.throws(SyntaxError, () => ctor('#!\n_',''), `${ctor.name} Call argument`); + assert.throws(SyntaxError, () => ctor('#!\n_'), `${ctor.name} Call body`); + assert.throws(SyntaxError, () => new ctor('#!\n_',''), `${ctor.name} Construct argument`); + assert.throws(SyntaxError, () => new ctor('#!\n_'), `${ctor.name} Construct body`); } diff --git a/test/language/comments/hashbang-multi-line-comment.js b/test/language/comments/hashbang-multi-line-comment.js index b681ef2407c..27bc551e4f5 100644 --- a/test/language/comments/hashbang-multi-line-comment.js +++ b/test/language/comments/hashbang-multi-line-comment.js @@ -8,7 +8,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-no-line-separator.js b/test/language/comments/hashbang-no-line-separator.js index bf49dd53b1d..824d903d9fe 100644 --- a/test/language/comments/hashbang-no-line-separator.js +++ b/test/language/comments/hashbang-no-line-separator.js @@ -5,6 +5,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] +flags: [raw] ---*/ eval('#!'); diff --git a/test/language/comments/hashbang-not-empty.js b/test/language/comments/hashbang-not-empty.js index f9ba96554ff..b005a3f290c 100644 --- a/test/language/comments/hashbang-not-empty.js +++ b/test/language/comments/hashbang-not-empty.js @@ -6,5 +6,6 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] +flags: [raw] ---*/ diff --git a/test/language/comments/hashbang-preceding-directive-prologue.js b/test/language/comments/hashbang-preceding-directive-prologue.js index 5c1a84c7c4d..edd975cfb7d 100644 --- a/test/language/comments/hashbang-preceding-directive-prologue.js +++ b/test/language/comments/hashbang-preceding-directive-prologue.js @@ -7,7 +7,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-preceding-empty-statement.js b/test/language/comments/hashbang-preceding-empty-statement.js index 4adc4c8cab3..bff2aa6d8f0 100644 --- a/test/language/comments/hashbang-preceding-empty-statement.js +++ b/test/language/comments/hashbang-preceding-empty-statement.js @@ -6,7 +6,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-preceding-hashbang.js b/test/language/comments/hashbang-preceding-hashbang.js index a5435b7a600..27d079ddf52 100644 --- a/test/language/comments/hashbang-preceding-hashbang.js +++ b/test/language/comments/hashbang-preceding-hashbang.js @@ -7,7 +7,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-preceding-line-comment.js b/test/language/comments/hashbang-preceding-line-comment.js index f50b1ca2bb7..365b5dc4ddd 100644 --- a/test/language/comments/hashbang-preceding-line-comment.js +++ b/test/language/comments/hashbang-preceding-line-comment.js @@ -7,7 +7,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-preceding-multi-line-comment.js b/test/language/comments/hashbang-preceding-multi-line-comment.js index 72b19c23d0d..5145019f044 100644 --- a/test/language/comments/hashbang-preceding-multi-line-comment.js +++ b/test/language/comments/hashbang-preceding-multi-line-comment.js @@ -7,7 +7,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-preceding-whitespace.js b/test/language/comments/hashbang-preceding-whitespace.js index 43250755262..7be73bd36a5 100644 --- a/test/language/comments/hashbang-preceding-whitespace.js +++ b/test/language/comments/hashbang-preceding-whitespace.js @@ -1,4 +1,4 @@ - #!/bin/sh + #! /*--- esid: pending description: > @@ -6,7 +6,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-statement-block.js b/test/language/comments/hashbang-statement-block.js index 397f0fe2aec..62ce7af3cc9 100644 --- a/test/language/comments/hashbang-statement-block.js +++ b/test/language/comments/hashbang-statement-block.js @@ -5,7 +5,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] - +flags: [raw] negative: phase: parse type: SyntaxError diff --git a/test/language/comments/hashbang-use-strict.js b/test/language/comments/hashbang-use-strict.js index 26a018408a7..d8a7a5e8b9c 100644 --- a/test/language/comments/hashbang-use-strict.js +++ b/test/language/comments/hashbang-use-strict.js @@ -6,6 +6,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] +flags: [raw] ---*/ with ({}) {} From ea92b44e6afe305771254dd55f25d80c5bee448f Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Mon, 3 Dec 2018 16:41:26 -0600 Subject: [PATCH 3/3] nits --- test/language/comments/hashbang-encoded-bang.js | 10 ++++++++++ test/language/comments/hashbang-encoded-hash.js | 10 ++++++++++ .../language/comments/hashbang-encoded-hashbang.js | 10 ++++++++++ test/language/comments/hashbang-function-body.js | 14 ++++++++++++++ .../comments/hashbang-function-constructor.js | 1 - 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/language/comments/hashbang-encoded-bang.js create mode 100644 test/language/comments/hashbang-encoded-hash.js create mode 100644 test/language/comments/hashbang-encoded-hashbang.js create mode 100644 test/language/comments/hashbang-function-body.js diff --git a/test/language/comments/hashbang-encoded-bang.js b/test/language/comments/hashbang-encoded-bang.js new file mode 100644 index 00000000000..0d8f8d9fabc --- /dev/null +++ b/test/language/comments/hashbang-encoded-bang.js @@ -0,0 +1,10 @@ +#\u0021 +/*--- +esid: pending +description: > + Hashbang comments should not be allowed to have encoded characters +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ diff --git a/test/language/comments/hashbang-encoded-hash.js b/test/language/comments/hashbang-encoded-hash.js new file mode 100644 index 00000000000..6d29abd2fc0 --- /dev/null +++ b/test/language/comments/hashbang-encoded-hash.js @@ -0,0 +1,10 @@ +\u0023! +/*--- +esid: pending +description: > + Hashbang comments should not be allowed to have encoded characters +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ diff --git a/test/language/comments/hashbang-encoded-hashbang.js b/test/language/comments/hashbang-encoded-hashbang.js new file mode 100644 index 00000000000..629bda6a780 --- /dev/null +++ b/test/language/comments/hashbang-encoded-hashbang.js @@ -0,0 +1,10 @@ +\u0023\u0021 +/*--- +esid: pending +description: > + Hashbang comments should not be allowed to have encoded characters +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ diff --git a/test/language/comments/hashbang-function-body.js b/test/language/comments/hashbang-function-body.js new file mode 100644 index 00000000000..2bb5130902a --- /dev/null +++ b/test/language/comments/hashbang-function-body.js @@ -0,0 +1,14 @@ +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be allowed within function bodies. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ +function fn() {#! +} diff --git a/test/language/comments/hashbang-function-constructor.js b/test/language/comments/hashbang-function-constructor.js index 1e48cf23c9d..fdc3f85bab7 100644 --- a/test/language/comments/hashbang-function-constructor.js +++ b/test/language/comments/hashbang-function-constructor.js @@ -5,7 +5,6 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] -flags: [module] ---*/ const AsyncFunction = (async function (){}).constructor; const GeneratorFunction = (function *(){}).constructor;