Title: [235627] trunk/Source/_javascript_Core
Revision
235627
Author
[email protected]
Date
2018-09-04 12:48:39 -0700 (Tue, 04 Sep 2018)

Log Message

Make the jsc shell print, printErr, and debug functions more robust.
https://bugs.webkit.org/show_bug.cgi?id=189268
<rdar://problem/41192690>

Reviewed by Keith Miller.

We'll now check for UTF8 conversion errors.

* jsc.cpp:
(cStringFromViewWithString):
(printInternal):
(functionDebug):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (235626 => 235627)


--- trunk/Source/_javascript_Core/ChangeLog	2018-09-04 19:38:33 UTC (rev 235626)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-09-04 19:48:39 UTC (rev 235627)
@@ -1,3 +1,18 @@
+2018-09-04  Mark Lam  <[email protected]>
+
+        Make the jsc shell print, printErr, and debug functions more robust.
+        https://bugs.webkit.org/show_bug.cgi?id=189268
+        <rdar://problem/41192690>
+
+        Reviewed by Keith Miller.
+
+        We'll now check for UTF8 conversion errors.
+
+        * jsc.cpp:
+        (cStringFromViewWithString):
+        (printInternal):
+        (functionDebug):
+
 2018-09-04  Michael Catanzaro  <[email protected]>
 
         [WPE][GTK] Add more unused result warnings to JSC API

Modified: trunk/Source/_javascript_Core/jsc.cpp (235626 => 235627)


--- trunk/Source/_javascript_Core/jsc.cpp	2018-09-04 19:38:33 UTC (rev 235626)
+++ trunk/Source/_javascript_Core/jsc.cpp	2018-09-04 19:48:39 UTC (rev 235627)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 1999-2000 Harri Porten ([email protected])
- *  Copyright (C) 2004-2017 Apple Inc. All rights reserved.
+ *  Copyright (C) 2004-2018 Apple Inc. All rights reserved.
  *  Copyright (C) 2006 Bjoern Graf ([email protected])
  *
  *  This library is free software; you can redistribute it and/or
@@ -1014,6 +1014,27 @@
     return metaProperties;
 }
 
+static CString cStringFromViewWithString(ExecState* exec, ThrowScope& scope, StringViewWithUnderlyingString& viewWithString)
+{
+    Expected<CString, UTF8ConversionError> expectedString = viewWithString.view.tryGetUtf8();
+    if (expectedString)
+        return expectedString.value();
+    switch (expectedString.error()) {
+    case UTF8ConversionError::OutOfMemory:
+        throwOutOfMemoryError(exec, scope);
+        break;
+    case UTF8ConversionError::IllegalSource:
+        scope.throwException(exec, createError(exec, "Illegal source encountered during UTF8 conversion"));
+        break;
+    case UTF8ConversionError::SourceExhausted:
+        scope.throwException(exec, createError(exec, "Source exhausted during UTF8 conversion"));
+        break;
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+    return { };
+}
+
 static EncodedJSValue printInternal(ExecState* exec, FILE* out)
 {
     VM& vm = exec->vm();
@@ -1034,7 +1055,9 @@
 
         auto viewWithString = exec->uncheckedArgument(i).toString(exec)->viewWithUnderlyingString(exec);
         RETURN_IF_EXCEPTION(scope, encodedJSValue());
-        if (fprintf(out, "%s", viewWithString.view.utf8().data()) < 0)
+        auto string = cStringFromViewWithString(exec, scope, viewWithString);
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
+        if (fprintf(out, "%s", string.data()) < 0)
             goto fail;
     }
 
@@ -1053,7 +1076,9 @@
     auto scope = DECLARE_THROW_SCOPE(vm);
     auto viewWithString = exec->argument(0).toString(exec)->viewWithUnderlyingString(exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    fprintf(stderr, "--> %s\n", viewWithString.view.utf8().data());
+    auto string = cStringFromViewWithString(exec, scope, viewWithString);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    fprintf(stderr, "--> %s\n", string.data());
     return JSValue::encode(jsUndefined());
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to