fix(ext/node): use primordials in ext/node/polyfills/internal/options.ts (#29119)

Towards #24236. This PR replaces `Map` and `String` methods with their
primordial versions.
This commit is contained in:
James Bronder 2025-05-02 01:08:43 -07:00 committed by GitHub
parent 9b633bfa85
commit 8786d39d4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,10 +20,13 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { getOptions } from "ext:deno_node/internal_binding/node_options.ts";
import { primordials } from "ext:core/mod.js";
const {
MapPrototypeGet,
StringPrototypeSlice,
StringPrototypeStartsWith,
} = primordials;
let optionsMap: Map<string, { value: string }>;
@ -38,11 +41,14 @@ function getOptionsFromBinding() {
export function getOptionValue(optionName: string) {
const options = getOptionsFromBinding();
if (optionName.startsWith("--no-")) {
const option = options.get("--" + optionName.slice(5));
if (StringPrototypeStartsWith(optionName, "--no-")) {
const option = MapPrototypeGet(
options,
"--" + StringPrototypeSlice(optionName, 5),
);
return option && !option.value;
}
return options.get(optionName)?.value;
return MapPrototypeGet(options, optionName)?.value;
}