Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashbang tests update #2065

Merged
merged 8 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ Function | Purpose
`assert.sameValue(actual, expected, message)` | throw a new Test262Error instance if the first two arguments are not [the same value](https://tc39.github.io/ecma262/#sec-samevalue); accepts an optional string message for use in creating the error
`assert.notSameValue(actual, unexpected, message)` | throw a new Test262Error instance if the first two arguments are [the same value](https://tc39.github.io/ecma262/#sec-samevalue); accepts an optional string message for use in creating the error
`assert.throws(expectedErrorConstructor, fn, message)` | throw a new Test262Error instance if the provided function does not throw an error, or if the constructor of the value thrown does not match the provided constructor
`$DONOTEVALUATE()` | throw an exception if the code gets evaluated. This is useful for [negative test cases for parsing errors](#handling-errors-and-negative-test-cases)
`$DONOTEVALUATE()` | throw an exception if the code gets evaluated. This is useful for [negative test cases for parsing errors](#handling-errors-and-negative-test-cases).
`throw "Test262: This statement should not be evaluated.";` | throw an exception if the code gets evaluated. Use this if the test file has the `raw` flag and it's a negative test case for parsing error.
`$ERROR(message)` | construct a Test262Error object and throw it <br>**DEPRECATED** -- Do not use in new tests. Use `assert`, `assert.*`, or `throw new Test262Error` instead.

```javascript
Expand All @@ -223,6 +224,21 @@ $DONOTEVALUATE();
var var = var;
```

If the test case has the `raw` flag, this disallows the test to load any harness file including `$DONOTEVALUATE`. In this case, include a direct `throw "Test262: This statement should not be evaluated.";` statement:

```javascript
/*---
flags: [raw]
negative:
phase: parse
type: SyntaxError
---*/

throw "Test262: This statement should not be evaluated.";

var var = var;
```

Expectations for **runtime errors** should be defined using the `assert.throws` method and the appropriate JavaScript Error constructor function:

```javascript
Expand Down
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#
# https://github.com/tc39/process-document

# Hashbang Grammar
# https://github.com/tc39/proposal-hashbang
hashbang

# Object.fromEntries
# https://github.com/tc39/proposal-object-from-entries
Object.fromEntries
Expand Down
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-bang-041.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#\041
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \041
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-bang-u0021.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#\u0021
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \u0021
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-bang-u21.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#\u{21}
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \u{21}
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-bang-x21.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#\x21
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \x21
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-hash-043.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\043!
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \043
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-hash-u0023.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\u0023!
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \u0023
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-hash-u23.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\u{23}!
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \u{23}
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-hash-x23.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\x23!
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters \x23
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/encoded-hashbang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\u0023\u0021
/*---
esid: pending
description: >
Hashbang comments should not be allowed to have encoded characters
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
13 changes: 13 additions & 0 deletions test/language/comments/hashbang/eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*---
esid: pending
description: >
Hashbang comments should be available in Script evaluator contexts.
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
features: [hashbang]
---*/

assert.sameValue(eval('#!\n'), undefined);
assert.sameValue(eval('#!\n1'), 1)
assert.sameValue(eval('#!2\n'), undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s try both direct and indirect eval.

17 changes: 17 additions & 0 deletions test/language/comments/hashbang/function-body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*---
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]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

$DONOTEVALUATE();

function fn() {#!
}
24 changes: 24 additions & 0 deletions test/language/comments/hashbang/function-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---
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,
]) {
assert.throws(SyntaxError, () => ctor('#!\n_',''), `${ctor.name} Call argument`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space after comma

assert.throws(SyntaxError, () => ctor('#!\n_'), `${ctor.name} Call body`);
assert.throws(SyntaxError, () => new ctor('#!\n_',''), `${ctor.name} Construct argument`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space after comma

assert.throws(SyntaxError, () => new ctor('#!\n_'), `${ctor.name} Construct body`);
}
11 changes: 11 additions & 0 deletions test/language/comments/hashbang/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!
/*---
esid: pending
description: >
Hashbang comments should be allowed in Modules.
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [module, raw]
features: [hashbang]
---*/
17 changes: 17 additions & 0 deletions test/language/comments/hashbang/multi-line-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/*
throw "Test262: This statement should not be evaluated.";
these characters should not be considered within a comment
*/
/*---
esid: pending
description: >
Hashbang comments should not interpret multi-line comments.
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/
11 changes: 11 additions & 0 deletions test/language/comments/hashbang/no-line-separator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*---
esid: pending
description: >
Hashbang comments should not require a newline afterwards
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
features: [hashbang]
---*/

assert.sameValue(eval('#!'), undefined);
11 changes: 11 additions & 0 deletions test/language/comments/hashbang/not-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! 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]
flags: [raw]
features: [hashbang]
---*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"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]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
17 changes: 17 additions & 0 deletions test/language/comments/hashbang/preceding-directive-prologue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"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]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
16 changes: 16 additions & 0 deletions test/language/comments/hashbang/preceding-empty-statement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;#!
/*---
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]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
17 changes: 17 additions & 0 deletions test/language/comments/hashbang/preceding-hashbang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!
#!
/*---
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]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
17 changes: 17 additions & 0 deletions test/language/comments/hashbang/preceding-line-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
#!
/*---
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]
flags: [raw]
negative:
phase: parse
type: SyntaxError
features: [hashbang]
---*/

throw "Test262: This statement should not be evaluated.";
Loading