skip to main content
research-article

Formal specification of a JavaScript module system

Published:19 October 2012Publication History
Skip Abstract Section

Abstract

The JavaScript programming language, originally developed as a simple scripting language, is now the language of choice for web applications. All the top 100 sites on the web use JavaScript and its use outside web pages is rapidly growing. However, JavaScript is not yet ready for programming in the large: it does not support a module system. Lack of namespaces introduces module patterns, and makes it difficult to use multiple JavaScript frameworks together.

In this paper, we propose a formal specification of a JavaScript module system. A module system for JavaScript will allow safe and incremental development of JavaScript web applications. While the next version of the JavaScript standard proposes a module system, it informally describes its design in prose. We formally specify a module system as an extension to the existing JavaScript language, and rigorously describe its semantics via desugaring to LambdaJS, a prior core calculus for JavaScript. We implement the desugaring process and show its faithfulness using real-world test suites. Finally, we define a set of properties for valid JavaScript programs using modules and formally prove that the proposed module system satisfies the validity properties.

References

  1. HTML5: A vocabulary and associated APIs for HTML and XHTML. http://www.w3.org/TR/html5/.Google ScholarGoogle Scholar
  2. JavaScript. http://en.wikipedia.org/wiki/JavaScript.Google ScholarGoogle Scholar
  3. Alexa the Web Information Company. http://www.alexa.com/, 2011.Google ScholarGoogle Scholar
  4. Ericsson AB. Erlang Reference Manual User's Guide. http://www.erlang.org/doc/reference_manual/users_guide.html.Google ScholarGoogle Scholar
  5. Gilad Bracha, Guy Steele, Bill Joy, and James Gosling. Java#8482; Language Specification, The 3rd Edition (Java Series). Addison-Wesley Professional, July 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. CommonJS contributors. Modules. http://wiki.commonjs.org/wiki/Modules.Google ScholarGoogle Scholar
  7. Douglas Crockford. ADsafe: Making JavaScript safe for advertising. http://www.adsafe.org, 2008.Google ScholarGoogle Scholar
  8. Dave Herman and Sam Tobin-Hochstadt. Harmony Proposals -- Modules. ECMAScript Wiki, http://wiki.ecmascript.org/doku.php?id=harmony:modules.Google ScholarGoogle Scholar
  9. Dave Herman and Sam Tobin-Hochstadt. Module Loaders, Harmony Proposals. ECMAScript Wiki, http://wiki.ecmascript.org/doku.php?id=harmony:module_loaders.Google ScholarGoogle Scholar
  10. ECMA. ECMA-262: ECMAScript Language Specification. 5th edition, December 2009.Google ScholarGoogle Scholar
  11. Brendan Eich. http://brendaneich.com/2011/05/my-jsconf-us-presentation/, 2011.Google ScholarGoogle Scholar
  12. ES4 working group. Proposed ECMAScript 4th Edition -- Language Overview. http://www.ecmascript.org/es4/spec/overview.pdf, October 2007.Google ScholarGoogle Scholar
  13. David Flanagan. JavaScript: The Definitive Guide. O'Reilly, 5th edition, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Matthew Flatt. Composable and compilable macros:: you want it when? In Proceedings of the 7th ACM SIGPLAN International Conference on Functional Programming, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Matthew Flatt and PLT. The Racket Reference. http://docs.racket-lang.org/reference/index.html.Google ScholarGoogle Scholar
  16. Python Software Foundation. The Python Language Reference. http://docs.python.org/py3k/reference/index.html.Google ScholarGoogle Scholar
  17. Philippa Gardner, Sergio Maffeis, and Gareth Smith. A program logic for JavaScript. In Proceedings of the 39th ACM Symposium on Principles of Programming Languages, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Danny Goodman. Dynamic HTML: The Definitive Reference. O'Reilly Media, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Arjun Guha. lambda_JS 1.0. https://github.com/brownplt/LambdaJS, 2011.Google ScholarGoogle Scholar
  20. Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. The Essence of Javascript. In Proceedings of the 24th European Conference on Object-Oriented Programming, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. David Herman and Sam Tobin-Hochstadt. Modules for JavaScript. Preprint, April 2011.Google ScholarGoogle Scholar
  22. jQuery Team. jQuery. http://jquery.com/.Google ScholarGoogle Scholar
  23. Seonghoon Kang and Sukyoung Ryu. lambdajs with modules. Technical report, KAIST, 2011.Google ScholarGoogle Scholar
  24. Sergio Maffeis, John C. Mitchell, and Ankur Taly. An Operational Semantics for JavaScript. In Proceedings of the 6th Asian Symposium on Programming Languages and Systems, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Sergio Maffeis, John C. Mitchell, and Ankur Taly. Object Capabilities and Isolation of Untrusted Web Applications. In Proceedings of IEEE Security & Privacy, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Sergio Maffeis and Ankur Taly. Language-Based Isolation of Untrusted JavaScript. In Proceedings of the 22nd IEEE Computer Security Foundations Symposium, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Eric Miraglia. A JavaScript Module Pattern. Yahoo! User Interface Blog, http://yuiblog.com/blog/2007/06/12/module-pattern/, June 2007.Google ScholarGoogle Scholar
  28. Mozilla Developer Network. Harmony modules. https://bugzilla.mozilla.org/show_bug.cgi?id=568953.Google ScholarGoogle Scholar
  29. Mozilla Developer Network. JavaScript code modules. https://developer.mozilla.org/en/JavaScript_modules.Google ScholarGoogle Scholar
  30. Tim O'Reilly. What Is Web 2.0. http://oreilly.com/web2/archive/what-is-web-20.html.Google ScholarGoogle Scholar
  31. PLT. DrRacket language levels. http://docs.racket-lang.org/unstable/DrRacket_Language_Levels.html.Google ScholarGoogle Scholar
  32. Joe Politz and Matt Carroll. lambda_JS semantics for ecmascript 5.0 (work in progress). https://github.com/brownplt/LambdaS5, 2011.Google ScholarGoogle Scholar
  33. Joe Gibbs Politz, Spiridon Aristides Eliopoulos, Arjun Guha, and Shriram Krishnamurthi. Adsafety: Type-based verification of javascript sandboxing. In USENIX Security, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Ankur Taly, Ulfar Erlingsson, Mark S. Miller, John C. Mitchell, and Jasvir Nagra. Automated analysis of security-critical JavaScript APIs. In Proceedings of IEEE Security & Privacy, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Google Caja Team. Google-Caja: A Source-to-source translator for securing JavaScript-based web content. http://code.google.com/p/google-caja/.Google ScholarGoogle Scholar
  36. The Facebook Team. FBJS (Facebook JavaScript). http://developers.facebook.com/docs/fbjs/.Google ScholarGoogle Scholar
  37. Sam Tobin-Hochstadt and Dave Herman. Modules for JavaScript, 2011.Google ScholarGoogle Scholar

Index Terms

  1. Formal specification of a JavaScript module system

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 47, Issue 10
      OOPSLA '12
      October 2012
      1011 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2398857
      Issue’s Table of Contents
      • cover image ACM Conferences
        OOPSLA '12: Proceedings of the ACM international conference on Object oriented programming systems languages and applications
        October 2012
        1052 pages
        ISBN:9781450315616
        DOI:10.1145/2384616

      Copyright © 2012 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 19 October 2012

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!