Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.oracle.truffle.js.runtime;
import java.time.DateTimeException;
import java.time.ZoneId;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import org.graalvm.options.OptionCategory;
import org.graalvm.options.OptionDescriptor;
import org.graalvm.options.OptionKey;
import org.graalvm.options.OptionStability;
import org.graalvm.options.OptionType;
import org.graalvm.options.OptionValues;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.Option;
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
import com.oracle.truffle.api.utilities.CyclicAssumption;
public final class JSContextOptions {
public static final String JS_OPTION_PREFIX = "js.";
@CompilationFinal private JSParserOptions parserOptions;
@CompilationFinal private OptionValues optionValues;
public static final String ECMASCRIPT_VERSION_NAME = JS_OPTION_PREFIX + "ecmascript-version";
@Option(name = ECMASCRIPT_VERSION_NAME, category = OptionCategory.USER, stability = OptionStability.STABLE, help = "ECMAScript Version.") //
public static final OptionKey ECMASCRIPT_VERSION = new OptionKey<>(
JSConfig.CurrentECMAScriptVersion,
new OptionType<>(
"ecmascript-version",
new Function() {
@Override
public Integer apply(String t) {
try {
int version = Integer.parseInt(t);
int minYearVersion = JSConfig.ECMAScript6 + JSConfig.ECMAScriptNumberYearDelta;
int maxYearVersion = JSConfig.MaxECMAScriptVersion + JSConfig.ECMAScriptNumberYearDelta;
if (minYearVersion <= version && version <= maxYearVersion) {
version -= JSConfig.ECMAScriptNumberYearDelta;
}
if (version < 5 || version > JSConfig.MaxECMAScriptVersion) {
throw new IllegalArgumentException(
"Supported values are 5 to " + JSConfig.MaxECMAScriptVersion + " or " + minYearVersion + " to " + maxYearVersion + ".");
}
return version;
} catch (NumberFormatException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}));
@CompilationFinal private int ecmascriptVersion;
public static final String ANNEX_B_NAME = JS_OPTION_PREFIX + "annex-b";
@Option(name = ANNEX_B_NAME, category = OptionCategory.USER, help = "Enable ECMAScript Annex B features.") //
public static final OptionKey ANNEX_B = new OptionKey<>(JSConfig.AnnexB);
@CompilationFinal private boolean annexB;
public static final String SYNTAX_EXTENSIONS_NAME = JS_OPTION_PREFIX + "syntax-extensions";
@Option(name = SYNTAX_EXTENSIONS_NAME, category = OptionCategory.USER, help = "Enable Nashorn syntax extensions.") //
public static final OptionKey SYNTAX_EXTENSIONS = new OptionKey<>(false);
public static final String SCRIPTING_NAME = JS_OPTION_PREFIX + "scripting";
@Option(name = SCRIPTING_NAME, category = OptionCategory.USER, help = "Enable scripting features (Nashorn compatibility option).") //
public static final OptionKey SCRIPTING = new OptionKey<>(false);
public static final String SHEBANG_NAME = JS_OPTION_PREFIX + "shebang";
@Option(name = SHEBANG_NAME, category = OptionCategory.USER, help = "Allow parsing files starting with #!.") //
public static final OptionKey SHEBANG = new OptionKey<>(false);
public static final String STRICT_NAME = JS_OPTION_PREFIX + "strict";
@Option(name = STRICT_NAME, category = OptionCategory.USER, stability = OptionStability.STABLE, help = "Enforce strict mode.") //
public static final OptionKey STRICT = new OptionKey<>(false);
public static final String CONST_AS_VAR_NAME = JS_OPTION_PREFIX + "const-as-var";
@Option(name = CONST_AS_VAR_NAME, category = OptionCategory.EXPERT, help = "Parse const declarations as a var (legacy compatibility option).") //
public static final OptionKey CONST_AS_VAR = new OptionKey<>(false);
public static final String FUNCTION_STATEMENT_ERROR_NAME = JS_OPTION_PREFIX + "function-statement-error";
@Option(name = FUNCTION_STATEMENT_ERROR_NAME, category = OptionCategory.EXPERT, help = "Treat hoistable function statements in blocks as an error (in ES5 mode).") //
public static final OptionKey FUNCTION_STATEMENT_ERROR = new OptionKey<>(false);
public static final String INTL_402_NAME = JS_OPTION_PREFIX + "intl-402";
@Option(name = INTL_402_NAME, category = OptionCategory.USER, stability = OptionStability.STABLE, help = "Enable ECMAScript Internationalization API.") //
public static final OptionKey INTL_402 = new OptionKey<>(false);
@CompilationFinal private boolean intl402;
public static final String REGEXP_MATCH_INDICES_NAME = JS_OPTION_PREFIX + "regexp-match-indices";
@Option(name = REGEXP_MATCH_INDICES_NAME, category = OptionCategory.USER, help = "Enable RegExp Match Indices property.") //
public static final OptionKey REGEXP_MATCH_INDICES = new OptionKey<>(false);
@CompilationFinal private boolean regexpMatchIndices;
public static final String REGEXP_STATIC_RESULT_NAME = JS_OPTION_PREFIX + "regexp-static-result";
@Option(name = REGEXP_STATIC_RESULT_NAME, category = OptionCategory.USER, help = "Provide last RegExp match in RegExp global var, e.g. RegExp.$1.") //
public static final OptionKey REGEXP_STATIC_RESULT = new OptionKey<>(true);
private final CyclicAssumption regexpStaticResultCyclicAssumption = new CyclicAssumption("The " + REGEXP_STATIC_RESULT_NAME + " option is stable.");
@CompilationFinal private Assumption regexpStaticResultCurrentAssumption = regexpStaticResultCyclicAssumption.getAssumption();
@CompilationFinal private boolean regexpStaticResult;
public static final String ARRAY_SORT_INHERITED_NAME = JS_OPTION_PREFIX + "array-sort-inherited";
@Option(name = ARRAY_SORT_INHERITED_NAME, category = OptionCategory.USER, help = "Sort inherited keys in Array.protoype.sort.") //
public static final OptionKey ARRAY_SORT_INHERITED = new OptionKey<>(true);
private final CyclicAssumption arraySortInheritedCyclicAssumption = new CyclicAssumption("The " + ARRAY_SORT_INHERITED_NAME + " option is stable.");
@CompilationFinal private Assumption arraySortInheritedCurrentAssumption = arraySortInheritedCyclicAssumption.getAssumption();
@CompilationFinal private boolean arraySortInherited;
public static final String SHARED_ARRAY_BUFFER_NAME = JS_OPTION_PREFIX + "shared-array-buffer";
@Option(name = SHARED_ARRAY_BUFFER_NAME, category = OptionCategory.USER, help = "Enable ES2017 SharedArrayBuffer.") //
public static final OptionKey SHARED_ARRAY_BUFFER = new OptionKey<>(true);
@CompilationFinal private boolean sharedArrayBuffer;
public static final String ATOMICS_NAME = JS_OPTION_PREFIX + "atomics";
@Option(name = ATOMICS_NAME, category = OptionCategory.USER, help = "Enable ES2017 Atomics.") //
public static final OptionKey ATOMICS = new OptionKey<>(true);
public static final String V8_COMPATIBILITY_MODE_NAME = JS_OPTION_PREFIX + "v8-compat";
@Option(name = V8_COMPATIBILITY_MODE_NAME, category = OptionCategory.USER, help = "Provide compatibility with the Google V8 engine.") //
public static final OptionKey V8_COMPATIBILITY_MODE = new OptionKey<>(false);
private final CyclicAssumption v8CompatibilityModeCyclicAssumption = new CyclicAssumption("The " + V8_COMPATIBILITY_MODE_NAME + " option is stable.");
@CompilationFinal private Assumption v8CompatibilityModeCurrentAssumption = v8CompatibilityModeCyclicAssumption.getAssumption();
@CompilationFinal private boolean v8CompatibilityMode;
public static final String V8_REALM_BUILTIN_NAME = JS_OPTION_PREFIX + "v8-realm-builtin";
@Option(name = V8_REALM_BUILTIN_NAME, category = OptionCategory.INTERNAL, help = "Provide Realm builtin compatible with V8's d8 shell.") //
public static final OptionKey V8_REALM_BUILTIN = new OptionKey<>(false);
@CompilationFinal private boolean v8RealmBuiltin;
public static final String V8_LEGACY_CONST_NAME = JS_OPTION_PREFIX + "v8-legacy-const";
@Option(name = V8_LEGACY_CONST_NAME, category = OptionCategory.INTERNAL, help = "Emulate v8 behavior when trying to mutate const variables in non-strict mode.") //
public static final OptionKey V8_LEGACY_CONST = new OptionKey<>(false);
@CompilationFinal private boolean v8LegacyConst;
public static final String NASHORN_COMPATIBILITY_MODE_NAME = JS_OPTION_PREFIX + "nashorn-compat";
@Option(name = NASHORN_COMPATIBILITY_MODE_NAME, category = OptionCategory.USER, help = "Provide compatibility with the OpenJDK Nashorn engine. Do not use with untrusted code.") //
public static final OptionKey NASHORN_COMPATIBILITY_MODE = new OptionKey<>(false);
@CompilationFinal private boolean nashornCompatibilityMode;
public static final String STACK_TRACE_LIMIT_NAME = JS_OPTION_PREFIX + "stack-trace-limit";
@Option(name = STACK_TRACE_LIMIT_NAME, category = OptionCategory.USER, help = "Number of stack frames to capture.") //
public static final OptionKey STACK_TRACE_LIMIT = new OptionKey<>(JSConfig.StackTraceLimit);
@CompilationFinal private int stackTraceLimit;
public static final String DEBUG_BUILTIN_NAME = JS_OPTION_PREFIX + "debug-builtin";
@Option(name = DEBUG_BUILTIN_NAME, category = OptionCategory.INTERNAL, help = "Provide a non-API Debug builtin. Behaviour will likely change. Don't depend on this in production code.") //
public static final OptionKey DEBUG_BUILTIN = new OptionKey<>(false);
@CompilationFinal private boolean debug;
public static final String DIRECT_BYTE_BUFFER_NAME = JS_OPTION_PREFIX + "direct-byte-buffer";
@Option(name = DIRECT_BYTE_BUFFER_NAME, category = OptionCategory.USER, help = "Use direct (off-heap) byte buffer for typed arrays.") //
public static final OptionKey DIRECT_BYTE_BUFFER = new OptionKey<>(false);
private final CyclicAssumption directByteBufferCyclicAssumption = new CyclicAssumption("The " + DIRECT_BYTE_BUFFER_NAME + " option is stable.");
@CompilationFinal private Assumption directByteBufferCurrentAssumption = directByteBufferCyclicAssumption.getAssumption();
@CompilationFinal private boolean directByteBuffer;
public static final String PARSE_ONLY_NAME = JS_OPTION_PREFIX + "parse-only";
@Option(name = PARSE_ONLY_NAME, category = OptionCategory.INTERNAL, help = "Only parse source code, do not run it.") //
public static final OptionKey PARSE_ONLY = new OptionKey<>(false);
@CompilationFinal private boolean parseOnly;
public static final String TIME_ZONE_NAME = JS_OPTION_PREFIX + "timezone";
@Option(name = TIME_ZONE_NAME, category = OptionCategory.USER, help = "Set custom time zone ID.") //
public static final OptionKey TIME_ZONE = new OptionKey<>("", new OptionType<>("ZoneId", new Function() {
@Override
public String apply(String tz) {
// Validate the time zone ID and convert legacy short IDs to long IDs.
try {
return ZoneId.of(tz, ZoneId.SHORT_IDS).getId();
} catch (DateTimeException e) {
throw new IllegalArgumentException(e);
}
}
}));
public static final String TIMER_RESOLUTION_NAME = JS_OPTION_PREFIX + "timer-resolution";
@Option(name = TIMER_RESOLUTION_NAME, category = OptionCategory.USER, help = "Resolution of timers (performance.now() and Date built-ins) in nanoseconds. Fuzzy time is used when set to 0.") //
public static final OptionKey TIMER_RESOLUTION = new OptionKey<>(1000000L);
private final CyclicAssumption timerResolutionCyclicAssumption = new CyclicAssumption("The " + TIMER_RESOLUTION_NAME + " option is stable.");
@CompilationFinal private Assumption timerResolutionCurrentAssumption = timerResolutionCyclicAssumption.getAssumption();
@CompilationFinal private long timerResolution;
public static final String AGENT_CAN_BLOCK_NAME = JS_OPTION_PREFIX + "agent-can-block";
@Option(name = AGENT_CAN_BLOCK_NAME, category = OptionCategory.INTERNAL, help = "Determines whether agents can block or not.") //
public static final OptionKey AGENT_CAN_BLOCK = new OptionKey<>(true);
@CompilationFinal private boolean agentCanBlock;
public static final String JAVA_PACKAGE_GLOBALS_NAME = JS_OPTION_PREFIX + "java-package-globals";
@Option(name = JAVA_PACKAGE_GLOBALS_NAME, category = OptionCategory.USER, help = "Provide Java package globals: Packages, java, javafx, javax, com, org, edu.") //
public static final OptionKey JAVA_PACKAGE_GLOBALS = new OptionKey<>(true);
public static final String GLOBAL_PROPERTY_NAME = JS_OPTION_PREFIX + "global-property";
@Option(name = GLOBAL_PROPERTY_NAME, category = OptionCategory.USER, help = "Provide 'global' global property.") //
public static final OptionKey GLOBAL_PROPERTY = new OptionKey<>(false);
public static final String GLOBAL_ARGUMENTS_NAME = JS_OPTION_PREFIX + "global-arguments";
@Option(name = GLOBAL_ARGUMENTS_NAME, category = OptionCategory.USER, help = "Provide 'arguments' global property.") //
public static final OptionKey GLOBAL_ARGUMENTS = new OptionKey<>(true);
public static final String CONSOLE_NAME = JS_OPTION_PREFIX + "console";
@Option(name = CONSOLE_NAME, category = OptionCategory.USER, help = "Provide 'console' global property.") //
public static final OptionKey CONSOLE = new OptionKey<>(true);
public static final String PERFORMANCE_NAME = JS_OPTION_PREFIX + "performance";
@Option(name = PERFORMANCE_NAME, category = OptionCategory.USER, help = "Provide 'performance' global property.") //
public static final OptionKey PERFORMANCE = new OptionKey<>(false);
public static final String SHELL_NAME = JS_OPTION_PREFIX + "shell";
@Option(name = SHELL_NAME, category = OptionCategory.USER, help = "Provide global functions for js shell.") //
public static final OptionKey SHELL = new OptionKey<>(false);
public static final String PRINT_NAME = JS_OPTION_PREFIX + "print";
@Option(name = PRINT_NAME, category = OptionCategory.USER, help = "Provide 'print' global function.") //
public static final OptionKey PRINT = new OptionKey<>(true);
public static final String LOAD_NAME = JS_OPTION_PREFIX + "load";
@Option(name = LOAD_NAME, category = OptionCategory.USER, help = "Provide 'load' global function.") //
public static final OptionKey LOAD = new OptionKey<>(true);
public static final String LOAD_FROM_URL_NAME = JS_OPTION_PREFIX + "load-from-url";
@Option(name = LOAD_FROM_URL_NAME, category = OptionCategory.USER, help = "Allow 'load' to access URLs. Do not use with untrusted code.") //
public static final OptionKey LOAD_FROM_URL = new OptionKey<>(false);
public static final String LOAD_FROM_CLASSPATH_NAME = JS_OPTION_PREFIX + "load-from-classpath";
@Option(name = LOAD_FROM_CLASSPATH_NAME, category = OptionCategory.USER, help = "Allow 'load' to access 'classpath:' URLs. Do not use with untrusted code.") //
public static final OptionKey LOAD_FROM_CLASSPATH = new OptionKey<>(false);
public static final String COMMONJS_REQUIRE_NAME = JS_OPTION_PREFIX + "commonjs-require";
@Option(name = COMMONJS_REQUIRE_NAME, category = OptionCategory.USER, help = "Enable CommonJS require emulation.") //
public static final OptionKey COMMONJS_REQUIRE = new OptionKey<>(false);
@CompilationFinal private boolean commonJSRequire;
public static final String COMMONJS_REQUIRE_CWD_NAME = JS_OPTION_PREFIX + "commonjs-require-cwd";
@Option(name = COMMONJS_REQUIRE_CWD_NAME, category = OptionCategory.USER, help = "CommonJS default current working directory.") //
public static final OptionKey COMMONJS_REQUIRE_CWD = new OptionKey<>("");
public static final String COMMONJS_CORE_MODULES_REPLACEMENTS_NAME = JS_OPTION_PREFIX + "commonjs-core-modules-replacements";
@Option(name = COMMONJS_CORE_MODULES_REPLACEMENTS_NAME, category = OptionCategory.USER, help = "Npm packages used to replace global Node.js builtins. Syntax: name1:module1,name2:module2,...") //
public static final OptionKey