[GLIB] Handle strings containing null characters
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 06:59:35 +0000 (06:59 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 06:59:35 +0000 (06:59 +0000)
commit5a13ef53ca915aa3be7b26bc44bb0965b2583cd1
tree1c2a5a09da894adf9f04ab4043b4df9ab8628a06
parent6e09fc69d6f56ffad0da16439994d9ec6d372e11
[GLIB] Handle strings containing null characters
https://bugs.webkit.org/show_bug.cgi?id=184450

Reviewed by Michael Catanzaro.

Source/JavaScriptCore:

We should be able to evaluate scripts containing null characters and to handle strings that contains them
too. In JavaScript strings are not null-terminated, they can contain null characters. This patch adds a length
parameter to jsc_context_valuate() to pass the script length (or -1 if it's null terminated), and new functions
jsc_value_new_string_from_bytes() and jsc_value_to_string_as_bytes() using GBytes to store strings that might
contain null characters.

* API/OpaqueJSString.cpp:
(OpaqueJSString::create): Add a create constructor that takes the String.
* API/OpaqueJSString.h:
(OpaqueJSString::OpaqueJSString): Add a constructor that takes the String.
* API/glib/JSCContext.cpp:
(jsc_context_evaluate): Add length parameter.
(jsc_context_evaluate_with_source_uri): Ditto.
* API/glib/JSCContext.h:
* API/glib/JSCValue.cpp:
(jsc_value_new_string_from_bytes):
(jsc_value_to_string):
(jsc_value_to_string_as_bytes):
(jsc_value_object_is_instance_of): Pass length to evaluate.
* API/glib/JSCValue.h:
* API/glib/docs/jsc-glib-4.0-sections.txt:

Tools:

Add test case for strings with null characters and update all calls to evaluate to pass the script length.

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/PlatformWPE.cmake:
* TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp:
(testJSCBasic):
(testJSCFunction):
(testJSCObject):
(testJSCClass):
(testJSCPrototypes):
(testJSCExceptions):
(testJSCPromises):
(testJSCGarbageCollector):
(testJSCWeakValue):
(testsJSCVirtualMachine):
(testsJSCAutocleanups):
* TestWebKitAPI/Tests/JavaScriptCore/glib/script.js: Added.
* TestWebKitAPI/Tests/WebKitGLib/DOMElementTest.cpp:
(DOMElementTest::testAutoFill):
* TestWebKitAPI/Tests/WebKitGLib/EditorTest.cpp:
(WebKitWebEditorTest::testSelectionChanged):
* TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp:
(WebKitFrameTest::testJavaScriptValues):
* TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:
(consoleMessageSentCallback):
(methodCallCallback):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230558 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
Source/JavaScriptCore/API/OpaqueJSString.cpp
Source/JavaScriptCore/API/OpaqueJSString.h
Source/JavaScriptCore/API/glib/JSCContext.cpp
Source/JavaScriptCore/API/glib/JSCContext.h
Source/JavaScriptCore/API/glib/JSCValue.cpp
Source/JavaScriptCore/API/glib/JSCValue.h
Source/JavaScriptCore/API/glib/docs/jsc-glib-4.0-sections.txt
Source/JavaScriptCore/ChangeLog
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/PlatformWPE.cmake
Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp
Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/script.js [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitGLib/DOMElementTest.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/EditorTest.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp