[JSC] Implement JSON.parse source text access proposal by Constellation · Pull Request #7057 · WebKit/WebKit

kmiller68

hyjorc1

@Constellation

https://bugs.webkit.org/show_bug.cgi?id=248031
rdar://131579181

Reviewed by Yijia Huang.

This patch implements JSON.parse source text access proposal[1], which is now stage-3.
This patch implements two major things in the proposal.
The most important part of this patch is not regressing the existing
extremely optimized JSON implementation for the fast path. Thus this
patch adds template parameter to LiteralParser and disable all the
slight changes when we are using the fast path.

1. JSON.rawJSON mechaism. Now new object type is integrated, and JSON.rawJSON can wrap JSON text
   with this object, which is a tool to inject raw JSON text into JSON.stringify. JSON.stringify
   uses held string from rawJSON-created object.
2. JSON.parse collects source information during parsing, and offer substring of text as a third parameter
   of JSON.parse reviver function.

[1]: https://github.com/tc39/proposal-json-parse-with-source

* JSTests/stress/json-parse-source-text-access.js: Added.
(shouldBe):
* JSTests/stress/json-raw-json-stringify.js: Added.
(shouldBe):
(shouldBe.JSON.stringify):
* JSTests/stress/json-raw-json.js: Added.
(shouldBe):
(shouldThrow):
(SyntaxError.JSON.Parse.error.Single.quotes.shouldThrow):
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/heap/Heap.cpp:
* Source/JavaScriptCore/heap/Heap.h:
* Source/JavaScriptCore/runtime/CommonIdentifiers.h:
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::createJSONProperty):
(JSC::JSGlobalObject::init):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::rawJSONObjectStructure const):
* Source/JavaScriptCore/runtime/JSONObject.cpp:
(JSC::JSONObject::finishCreation):
(JSC::Stringifier::appendStringifiedValue):
(JSC::Walker::Walker):
(JSC::Walker::callReviver):
(JSC::Walker::walk):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/JSONObject.h:
* Source/JavaScriptCore/runtime/JSRawJSONObject.cpp: Added.
(JSC::JSRawJSONObject::JSRawJSONObject):
(JSC::JSRawJSONObject::finishCreation):
(JSC::JSRawJSONObject::createStructure):
(JSC::JSRawJSONObject::rawJSON):
* Source/JavaScriptCore/runtime/JSRawJSONObject.h: Copied from Source/JavaScriptCore/runtime/JSONObject.h.
* Source/JavaScriptCore/runtime/LiteralParser.cpp:
(JSC::LiteralParser<CharType>::tryJSONPParse):
(JSC::LiteralParser<CharType>::parse):
* Source/JavaScriptCore/runtime/LiteralParser.h:
(JSC::JSONRanges::JSONRanges):
(JSC::JSONRanges::root const):
(JSC::LiteralParser::tryLiteralParse):
(JSC::LiteralParser::tryLiteralParsePrimitiveValue):
(JSC::LiteralParser::Lexer::Lexer):
(JSC::LiteralParser::Lexer::start const):
* Source/JavaScriptCore/runtime/OptionsList.h:

Canonical link: https://commits.webkit.org/288223@main

@Constellation Constellation deleted the eng/Implement-JSON-parse-source-text-access-proposal branch

December 22, 2024 00:59