Ignore:
Timestamp:
Apr 11, 2018, 11:59:35 PM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/OpaqueJSString.h

    r185346 r230558  
    5353
    5454    JS_EXPORT_PRIVATE static RefPtr<OpaqueJSString> create(const String&);
     55    JS_EXPORT_PRIVATE static RefPtr<OpaqueJSString> create(String&&);
    5556
    5657    JS_EXPORT_PRIVATE ~OpaqueJSString();
     
    8283    }
    8384
     85    explicit OpaqueJSString(String&& string)
     86        : m_string(WTFMove(string))
     87        , m_characters(m_string.impl() && m_string.is8Bit() ? nullptr : const_cast<UChar*>(m_string.characters16()))
     88    {
     89    }
     90
    8491    OpaqueJSString(const LChar* characters, unsigned length)
    8592        : m_string(characters, length)
Note: See TracChangeset for help on using the changeset viewer.