Changeset 264160 in webkit
- Timestamp:
- Jul 9, 2020, 1:23:36 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/microbenchmarks/error-source-appender.js (added)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/runtime/ErrorInstance.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r264059 r264160 1 2020-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 1 10 2020-07-07 Yusuke Suzuki <ysuzuki@apple.com> 2 11 -
trunk/Source/JavaScriptCore/ChangeLog
r264152 r264160 1 2020-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 1 23 2020-07-08 Yusuke Suzuki <ysuzuki@apple.com> 2 24 -
trunk/Source/JavaScriptCore/runtime/ErrorInstance.cpp
r261755 r264160 49 49 } 50 50 51 static void appendSourceToError(JSGlobalObject* globalObject, CallFrame* callFrame, ErrorInstance* exception, BytecodeIndex bytecodeIndex)51 static String appendSourceToErrorMessage(CallFrame* callFrame, ErrorInstance* exception, BytecodeIndex bytecodeIndex, const String& message) 52 52 { 53 53 ErrorInstance::SourceAppender appender = exception->sourceAppender(); … … 56 56 exception->clearRuntimeTypeForCause(); 57 57 58 if (!callFrame->codeBlock()->hasExpressionInfo() )59 return ;58 if (!callFrame->codeBlock()->hasExpressionInfo() || message.isNull()) 59 return message; 60 60 61 61 int startOffset = 0; … … 79 79 StringView sourceString = codeBlock->source().provider()->source(); 80 80 if (!expressionStop || expressionStart > static_cast<int>(sourceString.length())) 81 return ;81 return message; 82 82 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);89 83 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); 110 101 } 111 102 … … 117 108 m_sourceAppender = appender; 118 109 m_runtimeTypeForCause = type; 119 120 if (!message.isNull())121 putDirect(vm, vm.propertyNames->message, jsString(vm, message), static_cast<unsigned>(PropertyAttribute::DontEnum));122 110 123 111 std::unique_ptr<Vector<StackFrame>> stackTrace = getStackTrace(globalObject, vm, this, useCurrentFrame); … … 128 116 vm.heap.writeBarrier(this); 129 117 118 String messageWithSource = message; 130 119 if (m_stackTrace && !m_stackTrace->isEmpty() && hasSourceAppender()) { 131 120 BytecodeIndex bytecodeIndex; … … 133 122 getBytecodeIndex(vm, vm.topCallFrame, m_stackTrace.get(), callFrame, bytecodeIndex); 134 123 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)); 137 129 } 138 130
Note:
See TracChangeset
for help on using the changeset viewer.