eval-gtbndng-indirect-faux-assertion.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2021 the V8 project authors. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. description: >
  5. AssertClause in ImportDeclaration may not be preceded by a line terminator
  6. esid: sec-modules
  7. info: |
  8. ImportDeclaration:
  9. import ModuleSpecifier[no LineTerminator here] AssertClause;
  10. AssertClause:
  11. assert {}
  12. assert {AssertEntries ,opt}
  13. AssertEntries:
  14. AssertionKey : StringLiteral
  15. AssertionKey : StringLiteral , AssertEntries
  16. AssertionKey:
  17. IdentifierName
  18. StringLiteral
  19. The restriction LineTerminator could be verified more simply with a negative
  20. syntax test. This test is designed to parse successfully in order to verify
  21. the restriction more precisely.
  22. features: [import-assertions, globalThis]
  23. flags: [module, raw]
  24. ---*/
  25. var callCount = 0;
  26. // Define a property on the global "this" value so that the effect of the
  27. // expected IdentifierReference can be observed.
  28. Object.defineProperty(globalThis, 'assert', {
  29. get: function() {
  30. callCount += 1;
  31. }
  32. });
  33. import x from './import-assertion-1_FIXTURE.js'
  34. assert
  35. {test262:''};
  36. if (x !== 262.1) {
  37. throw 'module value incorrectly imported - first declaration';
  38. }
  39. if (callCount !== 1) {
  40. throw 'IdentifierReference not recognized - first declaration';
  41. }
  42. import './import-assertion-2_FIXTURE.js'
  43. assert
  44. {test262:''};
  45. if (globalThis.test262 !== 262.2) {
  46. throw 'module value incorrectly imported - second declaration';
  47. }
  48. if (callCount !== 2) {
  49. throw 'IdentifierReference not recognized - second declaration';
  50. }
  51. export * from './import-assertion-3_FIXTURE.js'
  52. assert
  53. {test262:''};
  54. if (callCount !== 3) {
  55. throw 'IdentifierReference not recognized - third declaration';
  56. }