From 9408792f1e3427fd052119f4c13d7e275cc7eb28 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Sat, 3 Aug 2024 16:25:39 +0700 Subject: [PATCH] replace a regex with a simple comparison --- packages/core-js/modules/esnext.json.raw-json.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core-js/modules/esnext.json.raw-json.js b/packages/core-js/modules/esnext.json.raw-json.js index bb249d95b7fd..34d8734e99f6 100644 --- a/packages/core-js/modules/esnext.json.raw-json.js +++ b/packages/core-js/modules/esnext.json.raw-json.js @@ -22,13 +22,15 @@ var create = getBuiltIn('Object', 'create'); var freeze = getBuiltIn('Object', 'freeze'); var at = uncurryThis(''.charAt); var slice = uncurryThis(''.slice); -var exec = uncurryThis(/./.exec); var push = uncurryThis([].push); var MARK = uid(); var MARK_LENGTH = MARK.length; var ERROR_MESSAGE = 'Unacceptable as raw JSON'; -var IS_WHITESPACE = /^[\t\n\r ]$/; + +var isWhitespace = function (it) { + return it === ' ' || it === '\t' || it === '\n' || it === '\r'; +}; // `JSON.parse` method // https://tc39.es/proposal-json-parse-with-source/#sec-json.israwjson @@ -36,7 +38,7 @@ var IS_WHITESPACE = /^[\t\n\r ]$/; $({ target: 'JSON', stat: true, forced: !NATIVE_RAW_JSON }, { rawJSON: function rawJSON(text) { var jsonString = toString(text); - if (jsonString === '' || exec(IS_WHITESPACE, at(jsonString, 0)) || exec(IS_WHITESPACE, at(jsonString, jsonString.length - 1))) { + if (jsonString === '' || isWhitespace(at(jsonString, 0)) || isWhitespace(at(jsonString, jsonString.length - 1))) { throw new $SyntaxError(ERROR_MESSAGE); } var parsed = parse(jsonString);