This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 202956

Summary: Customizable JavaScript target environments (e.g. browser, Nashorn, Node.js, ...)
Product: javascript Reporter: pekarna <pekarna>
Component: EditorAssignee: Petr Pisl <ppisl>
Status: NEW ---    
Severity: normal CC: terje7601
Priority: P3    
Version: 7.1   
Hardware: PC   
OS: Linux   
Issue Type: ENHANCEMENT Exception Reporter:

Description pekarna 2011-10-02 23:33:43 UTC
NetBeans' support for JavaScript is currently focused on browsers' target environments.
That means, it assumes user is interested in objects like window, document etc. and offers their properties and methods for completion.

It would be nice if these target environments could be defined by user, by providing sets of JavaScript files with definitions of objects available in particular context.
For example, "browser" context would have a .js file for standard browser objects, for DOM, ...

   var window = {
      document: {
         write: function( text ){ /* Empty - just a "header". }
         ...
      }
      alert: function( text ){ }
      ...
   }
   var document = window.document;

For WSH, there would be different context:

   var WScript = {
       Echo: function( text ) { }
   }

Etc.

Such treatment would make NetBeans more universal regarding editing of JavaScropt files. Currently, the code completion is rather annoying and misleading when editing JS files for different target environment.

I'd implement a "target environment" simply as a subdir of some dir in NetBeans with a set of .js files. The target environment could be switchable per project, evt. per-file, with per-project default.

Thanks for considering.
Comment 1 terje7601 2015-06-11 17:26:37 UTC
I fully agree with this report.

There are numerous different host environments for ECMAScript, each adding their own extensions (syntax extensions, global objects, ...). I think the most important ones to support are: "browsers", Node.js, Nashorn.

For example, if I want to write a Nashorn script, there's currently no support for many of its extensions: no syntax highlighting (issue 248105), parsing/formatting issues (cf. issue 252936 & issue 252937), code completion which proposes global objects that don't exist (e.g. document) & doesn't know about global objects that do (e.g. Java.type("...")).

As the reporter already says: NetBeans should allow users to specify a specific host environment for JavaScript files. I believe an easy way would be by using a naming convention:
myScript.js for browsers
myScript.node.js for Node.js
myScript.nashorn.js or myScript.jjs for Nashorn
This convention could be "enforced" by adding new entries in the "New File" wizard.

Another idea would be to have an option on the project-level to specify what environment the .js files target. Or to have a comment at the start of the file to denote the target environment.