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, 2024, 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.nio.charset.Charset;
import java.time.DateTimeException;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.graalvm.options.OptionCategory;
import org.graalvm.options.OptionDescriptor;
import org.graalvm.options.OptionDescriptors;
import org.graalvm.options.OptionKey;
import org.graalvm.options.OptionStability;
import org.graalvm.options.OptionType;
import org.graalvm.options.OptionValues;
import org.graalvm.polyglot.SandboxPolicy;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.Option;
import com.oracle.truffle.api.TruffleOptionDescriptors;
import com.oracle.truffle.js.lang.JavaScriptLanguage;
/**
* Defines, and provides access to, all JS (context and language) options.
*
* Option values are per-context, and cached values may be constant-folded when running with a bound
* Engine, as long as no other contexts have been spawned, but have to be reread every time from the
* context in "multi-context mode", i.e., if code sharing is enabled via a shared Engine.
*
* {@link JSLanguageOptions} captures a subset of these options that are immutable and shared per
* language instance (polyglot sharing layer) and always treated as constant in compiled code, but
* will prevent code sharing between contexts that differ in these options.
*
* {@link JSParserOptions} captures the subset of both {@link JSContextOptions} and
* {@link JSLanguageOptions} that is used by the parser.
*
* Select context options are treated as stable and/or patchable in the preinitialized context.
* Stable options will be read from the language and treated as constant while stable but once the
* option's value has changed, it has to be looked up from the context. This gives fast access by
* default without preventing code sharing. Similarly, patchable options allow code and the
* preinitialized context to be reused even if the option changes.
*
* @see JSLanguageOptions
* @see JSParserOptions
* @see com.oracle.truffle.js.runtime.util.StableContextOptionValue
*/
public final class JSContextOptions {
public static final String JS_OPTION_PREFIX = JavaScriptLanguage.ID + ".";
@CompilationFinal private JSParserOptions parserOptions;
@CompilationFinal private OptionValues optionValues;
public static final String ECMASCRIPT_VERSION_LATEST = "latest";
public static final String ECMASCRIPT_VERSION_STAGING = "staging";
public static final String ECMASCRIPT_VERSION_NAME = JS_OPTION_PREFIX + "ecmascript-version";
@Option(name = ECMASCRIPT_VERSION_NAME, category = OptionCategory.USER, stability = OptionStability.STABLE, sandbox = SandboxPolicy.UNTRUSTED, //
usageSyntax = ECMASCRIPT_VERSION_LATEST + "|" + ECMASCRIPT_VERSION_STAGING + "|" +
"[5, " + JSConfig.LatestECMAScriptVersion + "]|" +
"[2015, " + (JSConfig.LatestECMAScriptVersion + JSConfig.ECMAScriptVersionYearDelta) + "]", //
help = "ECMAScript version to be compatible with. Default is '" + ECMASCRIPT_VERSION_LATEST + "' (latest supported version), staged features are in '" +
ECMASCRIPT_VERSION_STAGING + "'.") //
public static final OptionKey ECMASCRIPT_VERSION = new OptionKey<>(JSConfig.LatestECMAScriptVersion, new OptionType<>("ecmascript-version", new Function() {
@Override
public Integer apply(String in) {
if (ECMASCRIPT_VERSION_LATEST.equals(in)) {
return JSConfig.LatestECMAScriptVersion;
} else if (ECMASCRIPT_VERSION_STAGING.equals(in)) {
return JSConfig.StagingECMAScriptVersion;
}
try {
final int minVersion = 5;
final int maxVersion = JSConfig.LatestECMAScriptVersion;
final int minYearVersion = JSConfig.ECMAScript6 + JSConfig.ECMAScriptVersionYearDelta;
final int maxYearVersion = maxVersion + JSConfig.ECMAScriptVersionYearDelta;
int version = Integer.parseInt(in);
if (minYearVersion <= version && version <= maxYearVersion) {
version -= JSConfig.ECMAScriptVersionYearDelta;
}
if (version < minVersion || version > maxVersion) {
throw new IllegalArgumentException("Supported values are " + minVersion + " to " + maxVersion + " 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, sandbox = SandboxPolicy.UNTRUSTED, 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<>(true);
@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.", deprecated = true) //
public static final OptionKey REGEXP_MATCH_INDICES = new OptionKey<>(false);
@CompilationFinal private boolean regexpMatchIndices;
public static final String REGEXP_UNICODE_SETS_NAME = JS_OPTION_PREFIX + "regexp-unicode-sets";
@Option(name = REGEXP_UNICODE_SETS_NAME, category = OptionCategory.USER, help = "Enable RegExp Unicode sets proposal (v flag).") //
public static final OptionKey REGEXP_UNICODE_SETS = new OptionKey<>(false);
@CompilationFinal private boolean regexpUnicodeSets;
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);
@CompilationFinal private boolean regexpStaticResult;
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 ECMAScript 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 ECMAScript 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);
@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 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, usageSyntax = "[0, inf)", 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);
@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, usageSyntax = "", 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) {
if (tz.isEmpty()) {
return "";
}
// 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 ZONE_RULES_BASED_TIME_ZONES_NAME = JS_OPTION_PREFIX + "zone-rules-based-time-zones";
@Option(name = ZONE_RULES_BASED_TIME_ZONES_NAME, category = OptionCategory.EXPERT, help = "Use ZoneRulesProvider instead of time-zone data from ICU4J.") //
public static final OptionKey ZONE_RULES_BASED_TIME_ZONES = new OptionKey<>(false);
@CompilationFinal private boolean zoneRulesBasedTimeZones;
public static final String TIMER_RESOLUTION_NAME = JS_OPTION_PREFIX + "timer-resolution";
@Option(name = TIMER_RESOLUTION_NAME, category = OptionCategory.USER, stability = OptionStability.STABLE, sandbox = SandboxPolicy.UNTRUSTED, usageSyntax = "", //
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);
@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, stability = OptionStability.STABLE, sandbox = SandboxPolicy.UNTRUSTED, 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 PRINT_NO_NEWLINE_NAME = JS_OPTION_PREFIX + "print-no-newline";
@Option(name = PRINT_NO_NEWLINE_NAME, category = OptionCategory.USER, help = "Print function will not print new line char.") //
public static final OptionKey PRINT_NO_NEWLINE = new OptionKey<>(false);
@CompilationFinal private boolean printNoNewline;
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, usageSyntax = "", 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, usageSyntax = ":,...", help = "Npm packages used to replace global Node.js builtins.") //
public static final OptionKey