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

Changeset 264160 in webkit


Ignore:
Timestamp:
Jul 9, 2020, 1:23:36 AM (6 years ago)
Author:
Alexey Shvayka
Message:

ErrorInstance::finishCreation() puts "message" twice, with different attributes
​https://bugs.webkit.org/show_bug.cgi?id=214089

Reviewed by Yusuke Suzuki.

JSTests:

  • microbenchmarks/error-source-appender.js: Added.

Source/JavaScriptCore:

This change refactors appendSourceToError() to return new message, making it almost pure
and eliminating extra JSString -> String -> JSString conversion and {get,put}Direct() calls
from ErrorInstance::finishCreation(). Also, moves null message check as early as possible.

Removed putDirect() call didn't pass PropertyAttribute::DontEnum. An implementation detail,
that is about to change in ​https://webkit.org/b/142933, prevented "message" property from
beind redefined with PropertyAttribute::None.

No behavior change. Advances provided microbenchmark by 5%.

  • runtime/ErrorInstance.cpp:

(JSC::appendSourceToErrorMessage):
(JSC::ErrorInstance::finishCreation):
(JSC::appendSourceToError): Deleted.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r264059 r264160  
     12020-07-09  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        ErrorInstance::finishCreation() puts "message" twice, with different attributes
     4        https://bugs.webkit.org/show_bug.cgi?id=214089
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * microbenchmarks/error-source-appender.js: Added.
     9
    1102020-07-07  Yusuke Suzuki  <ysuzuki@apple.com>
    211
  • trunk/Source/JavaScriptCore/ChangeLog

    r264152 r264160  
     12020-07-09  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        ErrorInstance::finishCreation() puts "message" twice, with different attributes
     4        https://bugs.webkit.org/show_bug.cgi?id=214089
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        This change refactors appendSourceToError() to return new message, making it almost pure
     9        and eliminating extra JSString -> String -> JSString conversion and {get,put}Direct() calls
     10        from ErrorInstance::finishCreation(). Also, moves null message check as early as possible.
     11
     12        Removed putDirect() call didn't pass PropertyAttribute::DontEnum. An implementation detail,
     13        that is about to change in https://webkit.org/b/142933, prevented "message" property from
     14        beind redefined with PropertyAttribute::None.
     15
     16        No behavior change. Advances provided microbenchmark by 5%.
     17
     18        * runtime/ErrorInstance.cpp:
     19        (JSC::appendSourceToErrorMessage):
     20        (JSC::ErrorInstance::finishCreation):
     21        (JSC::appendSourceToError): Deleted.
     22
    1232020-07-08  Yusuke Suzuki  <ysuzuki@apple.com>
    224
  • trunk/Source/JavaScriptCore/runtime/ErrorInstance.cpp

    r261755 r264160  
    4949}
    5050
    51 static void appendSourceToError(JSGlobalObject* globalObject, CallFrame* callFrame, ErrorInstance* exception, BytecodeIndex bytecodeIndex)
     51static String appendSourceToErrorMessage(CallFrame* callFrame, ErrorInstance* exception, BytecodeIndex bytecodeIndex, const String& message)
    5252{
    5353    ErrorInstance::SourceAppender appender = exception->sourceAppender();
    … …  
    5656    exception->clearRuntimeTypeForCause();
    5757
    58     if (!callFrame->codeBlock()->hasExpressionInfo())
    59         return;
     58    if (!callFrame->codeBlock()->hasExpressionInfo() || message.isNull())
     59        return message;
    6060   
    6161    int startOffset = 0;
    … …  
    7979    StringView sourceString = codeBlock->source().provider()->source();
    8080    if (!expressionStop || expressionStart > static_cast<int>(sourceString.length()))
    81         return;
     81        return message;
    8282   
    83     VM& vm = globalObject->vm();
    84     JSValue jsMessage = exception->getDirect(vm, vm.propertyNames->message);
    85     if (!jsMessage || !jsMessage.isString())
    86         return;
    87    
    88     String message = asString(jsMessage)->value(globalObject);
    8983    if (expressionStart < expressionStop)
    90         message = appender(message, codeBlock->source().provider()->getRange(expressionStart, expressionStop).toString(), type, ErrorInstance::FoundExactSource);
    91     else {
    92         // No range information, so give a few characters of context.
    93         int dataLength = sourceString.length();
    94         int start = expressionStart;
    95         int stop = expressionStart;
    96         // Get up to 20 characters of context to the left and right of the divot, clamping to the line.
    97         // Then strip whitespace.
    98         while (start > 0 && (expressionStart - start < 20) && sourceString[start - 1] != '\n')
    99             start--;
    100         while (start < (expressionStart - 1) && isStrWhiteSpace(sourceString[start]))
    101             start++;
    102         while (stop < dataLength && (stop - expressionStart < 20) && sourceString[stop] != '\n')
    103             stop++;
    104         while (stop > expressionStart && isStrWhiteSpace(sourceString[stop - 1]))
    105             stop--;
    106         message = appender(message, codeBlock->source().provider()->getRange(start, stop).toString(), type, ErrorInstance::FoundApproximateSource);
    107     }
    108     exception->putDirect(vm, vm.propertyNames->message, jsString(vm, message));
    109 
     84        return appender(message, codeBlock->source().provider()->getRange(expressionStart, expressionStop).toString(), type, ErrorInstance::FoundExactSource);
     85
     86    // No range information, so give a few characters of context.
     87    int dataLength = sourceString.length();
     88    int start = expressionStart;
     89    int stop = expressionStart;
     90    // Get up to 20 characters of context to the left and right of the divot, clamping to the line.
     91    // Then strip whitespace.
     92    while (start > 0 && (expressionStart - start < 20) && sourceString[start - 1] != '\n')
     93        start--;
     94    while (start < (expressionStart - 1) && isStrWhiteSpace(sourceString[start]))
     95        start++;
     96    while (stop < dataLength && (stop - expressionStart < 20) && sourceString[stop] != '\n')
     97        stop++;
     98    while (stop > expressionStart && isStrWhiteSpace(sourceString[stop - 1]))
     99        stop--;
     100    return appender(message, codeBlock->source().provider()->getRange(start, stop).toString(), type, ErrorInstance::FoundApproximateSource);
    110101}
    111102
    … …  
    117108    m_sourceAppender = appender;
    118109    m_runtimeTypeForCause = type;
    119 
    120     if (!message.isNull())
    121         putDirect(vm, vm.propertyNames->message, jsString(vm, message), static_cast<unsigned>(PropertyAttribute::DontEnum));
    122110
    123111    std::unique_ptr<Vector<StackFrame>> stackTrace = getStackTrace(globalObject, vm, this, useCurrentFrame);
    … …  
    128116    vm.heap.writeBarrier(this);
    129117
     118    String messageWithSource = message;
    130119    if (m_stackTrace && !m_stackTrace->isEmpty() && hasSourceAppender()) {
    131120        BytecodeIndex bytecodeIndex;
    … …  
    133122        getBytecodeIndex(vm, vm.topCallFrame, m_stackTrace.get(), callFrame, bytecodeIndex);
    134123        if (callFrame && callFrame->codeBlock() && !callFrame->callee().isWasm())
    135             appendSourceToError(globalObject, callFrame, this, bytecodeIndex);
    136     }
     124            messageWithSource = appendSourceToErrorMessage(callFrame, this, bytecodeIndex, message);
     125    }
     126
     127    if (!messageWithSource.isNull())
     128        putDirect(vm, vm.propertyNames->message, jsString(vm, messageWithSource), static_cast<unsigned>(PropertyAttribute::DontEnum));
    137129}
    138130
Note: See TracChangeset for help on using the changeset viewer.