193 public final boolean _strict;
194
195 /** print version info of Nashorn */
196 public final boolean _version;
197
198 /** should code verification be done of generated bytecode */
199 public final boolean _verify_code;
200
201 /** time zone for this environment */
202 public final TimeZone _timezone;
203
204 /** Local for error messages */
205 public final Locale _locale;
206
207 /** Logging */
208 public final Map<String, LoggerInfo> _loggers;
209
210 /** Timing */
211 public final Timing _timing;
212
213 /**
214 * Constructor
215 *
216 * @param options a Options object
217 * @param out output print writer
218 * @param err error print writer
219 */
220 @SuppressWarnings("unused")
221 public ScriptEnvironment(final Options options, final PrintWriter out, final PrintWriter err) {
222 this.out = out;
223 this.err = err;
224 this.namespace = new Namespace();
225 this.options = options;
226
227 _class_cache_size = options.getInteger("class.cache.size");
228 _compile_only = options.getBoolean("compile.only");
229 _const_as_var = options.getBoolean("const.as.var");
230 _debug_lines = options.getBoolean("debug.lines");
231 _dest_dir = options.getString("d");
232 _dump_on_error = options.getBoolean("doe");
258 }
259 _loader_per_compile = options.getBoolean("loader.per.compile");
260 _no_java = options.getBoolean("no.java");
261 _no_syntax_extensions = options.getBoolean("no.syntax.extensions");
262 _no_typed_arrays = options.getBoolean("no.typed.arrays");
263 _parse_only = options.getBoolean("parse.only");
264 _persistent_cache = options.getBoolean("persistent.code.cache");
265 _print_ast = options.getBoolean("print.ast");
266 _print_lower_ast = options.getBoolean("print.lower.ast");
267 _print_code = options.getString("print.code") != null;
268 _print_mem_usage = options.getBoolean("print.mem.usage");
269 _print_no_newline = options.getBoolean("print.no.newline");
270 _print_parse = options.getBoolean("print.parse");
271 _print_lower_parse = options.getBoolean("print.lower.parse");
272 _print_symbols = options.getBoolean("print.symbols");
273 _scripting = options.getBoolean("scripting");
274 _strict = options.getBoolean("strict");
275 _version = options.getBoolean("version");
276 _verify_code = options.getBoolean("verify.code");
277
278 final String language = options.getString("language");
279 if (language == null || language.equals("es5")) {
280 _es6 = false;
281 } else if (language.equals("es6")) {
282 _es6 = true;
283 } else {
284 throw new RuntimeException("Unsupported language: " + language);
285 }
286
287 String dir = null;
288 String func = null;
289 final String pc = options.getString("print.code");
290 if (pc != null) {
291 final StringTokenizer st = new StringTokenizer(pc, ",");
292 while (st.hasMoreTokens()) {
293 final StringTokenizer st2 = new StringTokenizer(st.nextToken(), ":");
294 while (st2.hasMoreTokens()) {
295 final String cmd = st2.nextToken();
296 if ("dir".equals(cmd)) {
297 dir = st2.nextToken();
390
391 /**
392 * Check if there is a logger registered for a particular name: typically
393 * the "name" attribute of a Loggable annotation on a class
394 *
395 * @param name logger name
396 * @return true, if a logger exists for that name, false otherwise
397 */
398 public boolean hasLogger(final String name) {
399 return _loggers.get(name) != null;
400 }
401
402 /**
403 * Check if compilation/runtime timings are enabled
404 * @return true if enabled
405 */
406 public boolean isTimingEnabled() {
407 return _timing != null ? _timing.isEnabled() : false;
408 }
409
410 }
|
193 public final boolean _strict;
194
195 /** print version info of Nashorn */
196 public final boolean _version;
197
198 /** should code verification be done of generated bytecode */
199 public final boolean _verify_code;
200
201 /** time zone for this environment */
202 public final TimeZone _timezone;
203
204 /** Local for error messages */
205 public final Locale _locale;
206
207 /** Logging */
208 public final Map<String, LoggerInfo> _loggers;
209
210 /** Timing */
211 public final Timing _timing;
212
213 /** Whether to use anonymous classes. See {@link #useAnonymousClasses(int)}. */
214 private final AnonymousClasses _anonymousClasses;
215 private enum AnonymousClasses {
216 AUTO,
217 OFF,
218 ON
219 }
220
221 /** Size threshold up to which we use anonymous classes in {@link AnonymousClasses#AUTO} setting */
222 private final int _anonymous_classes_threshold;
223
224 /** Default value for anonymous class threshold */
225 private final static int DEFAULT_ANON_CLASS_THRESHOLD = 512;
226
227 /**
228 * Constructor
229 *
230 * @param options a Options object
231 * @param out output print writer
232 * @param err error print writer
233 */
234 @SuppressWarnings("unused")
235 public ScriptEnvironment(final Options options, final PrintWriter out, final PrintWriter err) {
236 this.out = out;
237 this.err = err;
238 this.namespace = new Namespace();
239 this.options = options;
240
241 _class_cache_size = options.getInteger("class.cache.size");
242 _compile_only = options.getBoolean("compile.only");
243 _const_as_var = options.getBoolean("const.as.var");
244 _debug_lines = options.getBoolean("debug.lines");
245 _dest_dir = options.getString("d");
246 _dump_on_error = options.getBoolean("doe");
272 }
273 _loader_per_compile = options.getBoolean("loader.per.compile");
274 _no_java = options.getBoolean("no.java");
275 _no_syntax_extensions = options.getBoolean("no.syntax.extensions");
276 _no_typed_arrays = options.getBoolean("no.typed.arrays");
277 _parse_only = options.getBoolean("parse.only");
278 _persistent_cache = options.getBoolean("persistent.code.cache");
279 _print_ast = options.getBoolean("print.ast");
280 _print_lower_ast = options.getBoolean("print.lower.ast");
281 _print_code = options.getString("print.code") != null;
282 _print_mem_usage = options.getBoolean("print.mem.usage");
283 _print_no_newline = options.getBoolean("print.no.newline");
284 _print_parse = options.getBoolean("print.parse");
285 _print_lower_parse = options.getBoolean("print.lower.parse");
286 _print_symbols = options.getBoolean("print.symbols");
287 _scripting = options.getBoolean("scripting");
288 _strict = options.getBoolean("strict");
289 _version = options.getBoolean("version");
290 _verify_code = options.getBoolean("verify.code");
291
292 final String anonClasses = options.getString("anonymous.classes");
293 if (anonClasses == null || anonClasses.equals("auto")) {
294 _anonymousClasses = AnonymousClasses.AUTO;
295 } else if (anonClasses.equals("true")) {
296 _anonymousClasses = AnonymousClasses.ON;
297 } else if (anonClasses.equals("false")) {
298 _anonymousClasses = AnonymousClasses.OFF;
299 } else {
300 throw new RuntimeException("Unsupported value for anonymous classes: " + anonClasses);
301 }
302
303 this._anonymous_classes_threshold = Options.getIntProperty(
304 "nashorn.anonymous.classes.threshold", DEFAULT_ANON_CLASS_THRESHOLD);
305
306 final String language = options.getString("language");
307 if (language == null || language.equals("es5")) {
308 _es6 = false;
309 } else if (language.equals("es6")) {
310 _es6 = true;
311 } else {
312 throw new RuntimeException("Unsupported language: " + language);
313 }
314
315 String dir = null;
316 String func = null;
317 final String pc = options.getString("print.code");
318 if (pc != null) {
319 final StringTokenizer st = new StringTokenizer(pc, ",");
320 while (st.hasMoreTokens()) {
321 final StringTokenizer st2 = new StringTokenizer(st.nextToken(), ":");
322 while (st2.hasMoreTokens()) {
323 final String cmd = st2.nextToken();
324 if ("dir".equals(cmd)) {
325 dir = st2.nextToken();
418
419 /**
420 * Check if there is a logger registered for a particular name: typically
421 * the "name" attribute of a Loggable annotation on a class
422 *
423 * @param name logger name
424 * @return true, if a logger exists for that name, false otherwise
425 */
426 public boolean hasLogger(final String name) {
427 return _loggers.get(name) != null;
428 }
429
430 /**
431 * Check if compilation/runtime timings are enabled
432 * @return true if enabled
433 */
434 public boolean isTimingEnabled() {
435 return _timing != null ? _timing.isEnabled() : false;
436 }
437
438 /**
439 * Returns true if compilation should use anonymous classes.
440 * @param sourceLength length of source being compiled.
441 * @return true if anonymous classes should be used
442 */
443 public boolean useAnonymousClasses(final int sourceLength) {
444 return _anonymousClasses == AnonymousClasses.ON
445 || (_anonymousClasses == AnonymousClasses.AUTO && sourceLength <= _anonymous_classes_threshold);
446 }
447
448 }
|