⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 283293 in webkit


Ignore:
Timestamp:
Sep 29, 2021, 6:39:22 PM (5 years ago)
Author:
sbarati@apple.com
Message:

Print values in a nicer way in the jsc shell
https://bugs.webkit.org/show_bug.cgi?id=230931

Reviewed by Tadeu Zagallo.

JSTests:

  • ChakraCore/test/jsc-lib.js:

Source/JavaScriptCore:

Currently, print(1), print("1"), and print([1]) all print to stdout
simply as "1" (without the quotes). Same for values when running the
REPL. This isn't super helpful. Let's print quotes for strings, and
brackets for arrays.

Some tests rely on the old print behavior. Those tests now use the legacyPrint
instead.

  • jsc.cpp:

(toCString):
(printInternal):
(JSC_DEFINE_HOST_FUNCTION):
(runInteractive):
(cStringFromViewWithString): Deleted.

  • runtime/JSCJSValue.cpp:

(JSC::JSValue::toWTFStringForConsole const):

  • runtime/JSCJSValue.h:

LayoutTests:

  • resources/standalone-pre.js:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChakraCore/test/jsc-lib.js

    r205387 r283293  
     1print = legacyPrint;
     2
    13WScript = {
    24    _jscGC: gc,
  • trunk/JSTests/ChangeLog

    r283288 r283293  
     12021-09-29  Saam Barati  <sbarati@apple.com>
     2
     3        Print values in a nicer way in the jsc shell
     4        https://bugs.webkit.org/show_bug.cgi?id=230931
     5
     6        Reviewed by Tadeu Zagallo.
     7
     8        * ChakraCore/test/jsc-lib.js:
     9
    1102021-09-29  Saam Barati  <sbarati@apple.com>
    211
  • trunk/JSTests/exceptionFuzz/3d-cube.js

    r262383 r283293  
    359359})();
    360360} catch (e) {
    361     print("JSC EXCEPTION FUZZ: Caught exception: " + e);
    362 }
     361    legacyPrint("JSC EXCEPTION FUZZ: Caught exception: " + e);
     362}
  • trunk/JSTests/exceptionFuzz/date-format-xparb.js

    r262383 r283293  
    425425})();
    426426} catch (e) {
    427     print("JSC EXCEPTION FUZZ: Caught exception: " + e);
    428 }
     427    legacyPrint("JSC EXCEPTION FUZZ: Caught exception: " + e);
     428}
  • trunk/JSTests/exceptionFuzz/earley-boyer.js

    r262383 r283293  
    46854685})();
    46864686} catch (e) {
    4687     print("JSC EXCEPTION FUZZ: Caught exception: " + e);
    4688 }
    4689 
     4687    legacyPrint("JSC EXCEPTION FUZZ: Caught exception: " + e);
     4688}
     4689
  • trunk/LayoutTests/ChangeLog

    r283283 r283293  
     12021-09-29  Saam Barati  <sbarati@apple.com>
     2
     3        Print values in a nicer way in the jsc shell
     4        https://bugs.webkit.org/show_bug.cgi?id=230931
     5
     6        Reviewed by Tadeu Zagallo.
     7
     8        * resources/standalone-pre.js:
     9
    1102021-09-29  Chris Dumez  <cdumez@apple.com>
    211
  • trunk/LayoutTests/resources/standalone-pre.js

    r252196 r283293  
    1313didPassSomeTestsSilently = false;
    1414didFailSomeTests = false;
     15
     16print = legacyPrint;
    1517
    1618function description(msg)
  • trunk/Source/JavaScriptCore/ChangeLog

    r283288 r283293  
     12021-09-29  Saam Barati  <sbarati@apple.com>
     2
     3        Print values in a nicer way in the jsc shell
     4        https://bugs.webkit.org/show_bug.cgi?id=230931
     5
     6        Reviewed by Tadeu Zagallo.
     7
     8        Currently, print(1), print("1"), and print([1]) all print to stdout
     9        simply as "1" (without the quotes). Same for values when running the
     10        REPL. This isn't super helpful. Let's print quotes for strings, and
     11        brackets for arrays.
     12
     13        Some tests rely on the old print behavior. Those tests now use the legacyPrint
     14        instead.
     15
     16        * jsc.cpp:
     17        (toCString):
     18        (printInternal):
     19        (JSC_DEFINE_HOST_FUNCTION):
     20        (runInteractive):
     21        (cStringFromViewWithString): Deleted.
     22        * runtime/JSCJSValue.cpp:
     23        (JSC::JSValue::toWTFStringForConsole const):
     24        * runtime/JSCJSValue.h:
     25
    1262021-09-29  Saam Barati  <sbarati@apple.com>
    227
  • trunk/Source/JavaScriptCore/jsc.cpp

    r283286 r283293  
    279279static JSC_DECLARE_HOST_FUNCTION(functionPrintStdOut);
    280280static JSC_DECLARE_HOST_FUNCTION(functionPrintStdErr);
     281static JSC_DECLARE_HOST_FUNCTION(functionLegacyPrint);
    281282static JSC_DECLARE_HOST_FUNCTION(functionDebug);
    282283static JSC_DECLARE_HOST_FUNCTION(functionDescribe);
     
    528529        addFunction(vm, "print", functionPrintStdOut, 1);
    529530        addFunction(vm, "printErr", functionPrintStdErr, 1);
     531        addFunction(vm, "legacyPrint", functionLegacyPrint, 1);
    530532        addFunction(vm, "quit", functionQuit, 0);
    531533        addFunction(vm, "gc", functionGCAndSweep, 0);
     
    12391241}
    12401242
    1241 static CString cStringFromViewWithString(JSGlobalObject* globalObject, ThrowScope& scope, StringViewWithUnderlyingString& viewWithString)
    1242 {
    1243     Expected<CString, UTF8ConversionError> expectedString = viewWithString.view.tryGetUtf8();
     1243template <typename T>
     1244static CString toCString(JSGlobalObject* globalObject, ThrowScope& scope, T& string)
     1245{
     1246    Expected<CString, UTF8ConversionError> expectedString = string.tryGetUtf8();
    12441247    if (expectedString)
    12451248        return expectedString.value();
     
    12601263}
    12611264
    1262 static EncodedJSValue printInternal(JSGlobalObject* globalObject, CallFrame* callFrame, FILE* out)
     1265static EncodedJSValue printInternal(JSGlobalObject* globalObject, CallFrame* callFrame, FILE* out, bool legacy)
    12631266{
    12641267    VM& vm = globalObject->vm();
     
    12781281                goto fail;
    12791282
    1280         auto* jsString = callFrame->uncheckedArgument(i).toString(globalObject);
     1283        String string = legacy ? callFrame->uncheckedArgument(i).toWTFString(globalObject) : callFrame->uncheckedArgument(i).toWTFStringForConsole(globalObject);
    12811284        RETURN_IF_EXCEPTION(scope, { });
    1282         auto viewWithString = jsString->viewWithUnderlyingString(globalObject);
     1285        auto cString = toCString(globalObject, scope, string);
    12831286        RETURN_IF_EXCEPTION(scope, { });
    1284         auto string = cStringFromViewWithString(globalObject, scope, viewWithString);
    1285         RETURN_IF_EXCEPTION(scope, { });
    1286         fwrite(string.data(), sizeof(char), string.length(), out);
     1287        fwrite(cString.data(), sizeof(char), cString.length(), out);
    12871288        if (ferror(out))
    12881289            goto fail;
     
    12971298JSC_DEFINE_HOST_FUNCTION(functionPrintStdOut, (JSGlobalObject* globalObject, CallFrame* callFrame))
    12981299{
    1299     return printInternal(globalObject, callFrame, stdout);
     1300    return printInternal(globalObject, callFrame, stdout, false);
    13001301}
    13011302
    13021303JSC_DEFINE_HOST_FUNCTION(functionPrintStdErr, (JSGlobalObject* globalObject, CallFrame* callFrame))
    13031304{
    1304     return printInternal(globalObject, callFrame, stderr);
     1305    return printInternal(globalObject, callFrame, stderr, false);
     1306}
     1307
     1308JSC_DEFINE_HOST_FUNCTION(functionLegacyPrint, (JSGlobalObject* globalObject, CallFrame* callFrame))
     1309{
     1310    return printInternal(globalObject, callFrame, stdout, true);
    13051311}
    13061312
     
    13131319    auto viewWithString = jsString->viewWithUnderlyingString(globalObject);
    13141320    RETURN_IF_EXCEPTION(scope, { });
    1315     auto string = cStringFromViewWithString(globalObject, scope, viewWithString);
     1321    auto string = toCString(globalObject, scope, viewWithString.view);
    13161322    RETURN_IF_EXCEPTION(scope, { });
    13171323    fputs("--> ", stderr);
     
    32723278            utf8 = evaluationException->value().toWTFString(globalObject).tryGetUtf8();
    32733279        } else
    3274             utf8 = returnValue.toWTFString(globalObject).tryGetUtf8();
     3280            utf8 = returnValue.toWTFStringForConsole(globalObject).tryGetUtf8();
    32753281
    32763282        CString result;
  • trunk/Source/JavaScriptCore/runtime/JSCJSValue.cpp

    r282664 r283293  
    472472#endif
    473473
     474WTF::String JSValue::toWTFStringForConsole(JSGlobalObject* globalObject) const
     475{
     476    VM& vm = globalObject->vm();
     477    auto scope = DECLARE_THROW_SCOPE(vm);
     478    JSString* string = toString(globalObject);
     479    RETURN_IF_EXCEPTION(scope, { });
     480    String result = string->value(globalObject);
     481    RETURN_IF_EXCEPTION(scope, { });
     482    if (isString())
     483        return makeString("\"", result, "\"");
     484    if (jsDynamicCast<JSArray*>(vm, *this))
     485        return makeString("[", result, "]");
     486    return result;
     487}
     488
    474489} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSCJSValue.h

    r278253 r283293  
    290290    JSValue toPropertyKeyValue(JSGlobalObject*) const;
    291291    WTF::String toWTFString(JSGlobalObject*) const;
     292    JS_EXPORT_PRIVATE WTF::String toWTFStringForConsole(JSGlobalObject*) const;
    292293    JSObject* toObject(JSGlobalObject*) const;
    293294
Note: See TracChangeset for help on using the changeset viewer.