Title: [283293] trunk
Revision
283293
Author
[email protected]
Date
2021-09-29 18:39:22 -0700 (Wed, 29 Sep 2021)

Log 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/_javascript_Core:

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:

Modified Paths

Diff

Modified: trunk/JSTests/ChakraCore/test/jsc-lib.js (283292 => 283293)


--- trunk/JSTests/ChakraCore/test/jsc-lib.js	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/JSTests/ChakraCore/test/jsc-lib.js	2021-09-30 01:39:22 UTC (rev 283293)
@@ -1,3 +1,5 @@
+print = legacyPrint;
+
 WScript = {
     _jscGC: gc,
     _jscLoad: load,

Modified: trunk/JSTests/ChangeLog (283292 => 283293)


--- trunk/JSTests/ChangeLog	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/JSTests/ChangeLog	2021-09-30 01:39:22 UTC (rev 283293)
@@ -1,5 +1,14 @@
 2021-09-29  Saam Barati  <[email protected]>
 
+        Print values in a nicer way in the jsc shell
+        https://bugs.webkit.org/show_bug.cgi?id=230931
+
+        Reviewed by Tadeu Zagallo.
+
+        * ChakraCore/test/jsc-lib.js:
+
+2021-09-29  Saam Barati  <[email protected]>
+
         We need to load the baseline JIT's constant pool register after OSR exit to checkpoints if we return to baseline code
         https://bugs.webkit.org/show_bug.cgi?id=230972
         <rdar://83659469>

Modified: trunk/JSTests/exceptionFuzz/3d-cube.js (283292 => 283293)


--- trunk/JSTests/exceptionFuzz/3d-cube.js	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/JSTests/exceptionFuzz/3d-cube.js	2021-09-30 01:39:22 UTC (rev 283293)
@@ -358,5 +358,5 @@
 
 })();
 } catch (e) {
-    print("JSC EXCEPTION FUZZ: Caught exception: " + e);
+    legacyPrint("JSC EXCEPTION FUZZ: Caught exception: " + e);
 }

Modified: trunk/JSTests/exceptionFuzz/date-format-xparb.js (283292 => 283293)


--- trunk/JSTests/exceptionFuzz/date-format-xparb.js	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/JSTests/exceptionFuzz/date-format-xparb.js	2021-09-30 01:39:22 UTC (rev 283293)
@@ -424,5 +424,5 @@
 
 })();
 } catch (e) {
-    print("JSC EXCEPTION FUZZ: Caught exception: " + e);
+    legacyPrint("JSC EXCEPTION FUZZ: Caught exception: " + e);
 }

Modified: trunk/JSTests/exceptionFuzz/earley-boyer.js (283292 => 283293)


--- trunk/JSTests/exceptionFuzz/earley-boyer.js	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/JSTests/exceptionFuzz/earley-boyer.js	2021-09-30 01:39:22 UTC (rev 283293)
@@ -4684,6 +4684,6 @@
 }
 })();
 } catch (e) {
-    print("JSC EXCEPTION FUZZ: Caught exception: " + e);
+    legacyPrint("JSC EXCEPTION FUZZ: Caught exception: " + e);
 }
 

Modified: trunk/LayoutTests/ChangeLog (283292 => 283293)


--- trunk/LayoutTests/ChangeLog	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/LayoutTests/ChangeLog	2021-09-30 01:39:22 UTC (rev 283293)
@@ -1,3 +1,12 @@
+2021-09-29  Saam Barati  <[email protected]>
+
+        Print values in a nicer way in the jsc shell
+        https://bugs.webkit.org/show_bug.cgi?id=230931
+
+        Reviewed by Tadeu Zagallo.
+
+        * resources/standalone-pre.js:
+
 2021-09-29  Chris Dumez  <[email protected]>
 
         [ iOS Debug ] http/tests/xmlhttprequest/access-control-preflight-credential-sync.html is a flaky crash

Modified: trunk/LayoutTests/resources/standalone-pre.js (283292 => 283293)


--- trunk/LayoutTests/resources/standalone-pre.js	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/LayoutTests/resources/standalone-pre.js	2021-09-30 01:39:22 UTC (rev 283293)
@@ -13,6 +13,8 @@
 didPassSomeTestsSilently = false;
 didFailSomeTests = false;
 
+print = legacyPrint;
+
 function description(msg)
 {
     print(msg);

Modified: trunk/Source/_javascript_Core/ChangeLog (283292 => 283293)


--- trunk/Source/_javascript_Core/ChangeLog	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-09-30 01:39:22 UTC (rev 283293)
@@ -1,5 +1,30 @@
 2021-09-29  Saam Barati  <[email protected]>
 
+        Print values in a nicer way in the jsc shell
+        https://bugs.webkit.org/show_bug.cgi?id=230931
+
+        Reviewed by Tadeu Zagallo.
+
+        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:
+
+2021-09-29  Saam Barati  <[email protected]>
+
         We need to load the baseline JIT's constant pool register after OSR exit to checkpoints if we return to baseline code
         https://bugs.webkit.org/show_bug.cgi?id=230972
         <rdar://83659469>

Modified: trunk/Source/_javascript_Core/jsc.cpp (283292 => 283293)


--- trunk/Source/_javascript_Core/jsc.cpp	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/Source/_javascript_Core/jsc.cpp	2021-09-30 01:39:22 UTC (rev 283293)
@@ -278,6 +278,7 @@
 
 static JSC_DECLARE_HOST_FUNCTION(functionPrintStdOut);
 static JSC_DECLARE_HOST_FUNCTION(functionPrintStdErr);
+static JSC_DECLARE_HOST_FUNCTION(functionLegacyPrint);
 static JSC_DECLARE_HOST_FUNCTION(functionDebug);
 static JSC_DECLARE_HOST_FUNCTION(functionDescribe);
 static JSC_DECLARE_HOST_FUNCTION(functionDescribeArray);
@@ -527,6 +528,7 @@
         addFunction(vm, "describeArray", functionDescribeArray, 1);
         addFunction(vm, "print", functionPrintStdOut, 1);
         addFunction(vm, "printErr", functionPrintStdErr, 1);
+        addFunction(vm, "legacyPrint", functionLegacyPrint, 1);
         addFunction(vm, "quit", functionQuit, 0);
         addFunction(vm, "gc", functionGCAndSweep, 0);
         addFunction(vm, "fullGC", functionFullGC, 0);
@@ -1238,9 +1240,10 @@
     return metaProperties;
 }
 
-static CString cStringFromViewWithString(JSGlobalObject* globalObject, ThrowScope& scope, StringViewWithUnderlyingString& viewWithString)
+template <typename T>
+static CString toCString(JSGlobalObject* globalObject, ThrowScope& scope, T& string)
 {
-    Expected<CString, UTF8ConversionError> expectedString = viewWithString.view.tryGetUtf8();
+    Expected<CString, UTF8ConversionError> expectedString = string.tryGetUtf8();
     if (expectedString)
         return expectedString.value();
     switch (expectedString.error()) {
@@ -1259,7 +1262,7 @@
     return { };
 }
 
-static EncodedJSValue printInternal(JSGlobalObject* globalObject, CallFrame* callFrame, FILE* out)
+static EncodedJSValue printInternal(JSGlobalObject* globalObject, CallFrame* callFrame, FILE* out, bool legacy)
 {
     VM& vm = globalObject->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
@@ -1277,13 +1280,11 @@
             if (EOF == fputc(' ', out))
                 goto fail;
 
-        auto* jsString = callFrame->uncheckedArgument(i).toString(globalObject);
+        String string = legacy ? callFrame->uncheckedArgument(i).toWTFString(globalObject) : callFrame->uncheckedArgument(i).toWTFStringForConsole(globalObject);
         RETURN_IF_EXCEPTION(scope, { });
-        auto viewWithString = jsString->viewWithUnderlyingString(globalObject);
+        auto cString = toCString(globalObject, scope, string);
         RETURN_IF_EXCEPTION(scope, { });
-        auto string = cStringFromViewWithString(globalObject, scope, viewWithString);
-        RETURN_IF_EXCEPTION(scope, { });
-        fwrite(string.data(), sizeof(char), string.length(), out);
+        fwrite(cString.data(), sizeof(char), cString.length(), out);
         if (ferror(out))
             goto fail;
     }
@@ -1296,14 +1297,19 @@
 
 JSC_DEFINE_HOST_FUNCTION(functionPrintStdOut, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    return printInternal(globalObject, callFrame, stdout);
+    return printInternal(globalObject, callFrame, stdout, false);
 }
 
 JSC_DEFINE_HOST_FUNCTION(functionPrintStdErr, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    return printInternal(globalObject, callFrame, stderr);
+    return printInternal(globalObject, callFrame, stderr, false);
 }
 
+JSC_DEFINE_HOST_FUNCTION(functionLegacyPrint, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+    return printInternal(globalObject, callFrame, stdout, true);
+}
+
 JSC_DEFINE_HOST_FUNCTION(functionDebug, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     VM& vm = globalObject->vm();
@@ -1312,7 +1318,7 @@
     RETURN_IF_EXCEPTION(scope, { });
     auto viewWithString = jsString->viewWithUnderlyingString(globalObject);
     RETURN_IF_EXCEPTION(scope, { });
-    auto string = cStringFromViewWithString(globalObject, scope, viewWithString);
+    auto string = toCString(globalObject, scope, viewWithString.view);
     RETURN_IF_EXCEPTION(scope, { });
     fputs("--> ", stderr);
     fwrite(string.data(), sizeof(char), string.length(), stderr);
@@ -3271,7 +3277,7 @@
             fputs("Exception: ", stdout);
             utf8 = evaluationException->value().toWTFString(globalObject).tryGetUtf8();
         } else
-            utf8 = returnValue.toWTFString(globalObject).tryGetUtf8();
+            utf8 = returnValue.toWTFStringForConsole(globalObject).tryGetUtf8();
 
         CString result;
         if (utf8)

Modified: trunk/Source/_javascript_Core/runtime/JSCJSValue.cpp (283292 => 283293)


--- trunk/Source/_javascript_Core/runtime/JSCJSValue.cpp	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValue.cpp	2021-09-30 01:39:22 UTC (rev 283293)
@@ -471,4 +471,19 @@
 }
 #endif
 
+WTF::String JSValue::toWTFStringForConsole(JSGlobalObject* globalObject) const
+{
+    VM& vm = globalObject->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+    JSString* string = toString(globalObject);
+    RETURN_IF_EXCEPTION(scope, { });
+    String result = string->value(globalObject);
+    RETURN_IF_EXCEPTION(scope, { });
+    if (isString())
+        return makeString("\"", result, "\"");
+    if (jsDynamicCast<JSArray*>(vm, *this))
+        return makeString("[", result, "]");
+    return result;
+}
+
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/JSCJSValue.h (283292 => 283293)


--- trunk/Source/_javascript_Core/runtime/JSCJSValue.h	2021-09-30 01:25:13 UTC (rev 283292)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValue.h	2021-09-30 01:39:22 UTC (rev 283293)
@@ -289,6 +289,7 @@
     Identifier toPropertyKey(JSGlobalObject*) const;
     JSValue toPropertyKeyValue(JSGlobalObject*) const;
     WTF::String toWTFString(JSGlobalObject*) const;
+    JS_EXPORT_PRIVATE WTF::String toWTFStringForConsole(JSGlobalObject*) const;
     JSObject* toObject(JSGlobalObject*) const;
 
     // Integer conversions.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to