Ignore:
Timestamp:
Sep 4, 2018, 12:48:39 PM (7 years ago)
Author:
[email protected]
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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r235450 r235627  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    3  *  Copyright (C) 2004-2017 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2004-2018 Apple Inc. All rights reserved.
    44 *  Copyright (C) 2006 Bjoern Graf ([email protected])
    55 *
     
    10151015}
    10161016
     1017static CString cStringFromViewWithString(ExecState* exec, ThrowScope& scope, StringViewWithUnderlyingString& viewWithString)
     1018{
     1019    Expected<CString, UTF8ConversionError> expectedString = viewWithString.view.tryGetUtf8();
     1020    if (expectedString)
     1021        return expectedString.value();
     1022    switch (expectedString.error()) {
     1023    case UTF8ConversionError::OutOfMemory:
     1024        throwOutOfMemoryError(exec, scope);
     1025        break;
     1026    case UTF8ConversionError::IllegalSource:
     1027        scope.throwException(exec, createError(exec, "Illegal source encountered during UTF8 conversion"));
     1028        break;
     1029    case UTF8ConversionError::SourceExhausted:
     1030        scope.throwException(exec, createError(exec, "Source exhausted during UTF8 conversion"));
     1031        break;
     1032    default:
     1033        RELEASE_ASSERT_NOT_REACHED();
     1034    }
     1035    return { };
     1036}
     1037
    10171038static EncodedJSValue printInternal(ExecState* exec, FILE* out)
    10181039{
     
    10351056        auto viewWithString = exec->uncheckedArgument(i).toString(exec)->viewWithUnderlyingString(exec);
    10361057        RETURN_IF_EXCEPTION(scope, encodedJSValue());
    1037         if (fprintf(out, "%s", viewWithString.view.utf8().data()) < 0)
     1058        auto string = cStringFromViewWithString(exec, scope, viewWithString);
     1059        RETURN_IF_EXCEPTION(scope, encodedJSValue());
     1060        if (fprintf(out, "%s", string.data()) < 0)
    10381061            goto fail;
    10391062    }
     
    10541077    auto viewWithString = exec->argument(0).toString(exec)->viewWithUnderlyingString(exec);
    10551078    RETURN_IF_EXCEPTION(scope, encodedJSValue());
    1056     fprintf(stderr, "--> %s\n", viewWithString.view.utf8().data());
     1079    auto string = cStringFromViewWithString(exec, scope, viewWithString);
     1080    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     1081    fprintf(stderr, "--> %s\n", string.data());
    10571082    return JSValue::encode(jsUndefined());
    10581083}
Note: See TracChangeset for help on using the changeset viewer.