+ ASSERT(type != TypeFunction);
+
+ if (occurrence == ErrorInstance::FoundApproximateSource)
+ return defaultApproximateSourceError(originalMessage, sourceText);
+
+ ASSERT(occurrence == ErrorInstance::FoundExactSource);
+ auto notAFunctionIndex = originalMessage.reverseFind("is not a function");
+ RELEASE_ASSERT(notAFunctionIndex != notFound);
+ StringView displayValue;
+ if (originalMessage.is8Bit())
+ displayValue = StringView(originalMessage.characters8(), notAFunctionIndex - 1);
+ else
+ displayValue = StringView(originalMessage.characters16(), notAFunctionIndex - 1);
+
+ String base = functionCallBase(sourceText);
+ StringBuilder builder;
+ builder.append(base);
+ builder.appendLiteral(" is not a function. (In '");
+ builder.append(sourceText);
+ builder.appendLiteral("', '");
+ builder.append(base);
+ builder.appendLiteral("' is ");
+ if (type == TypeObject)
+ builder.appendLiteral("an instance of ");
+ builder.append(displayValue);
+ builder.appendLiteral(")");
+
+ return builder.toString();
+}
+
+static String invalidParameterInSourceAppender(const String& originalMessage, const String& sourceText, RuntimeType type, ErrorInstance::SourceTextWhereErrorOccurred occurrence)
+{
+ ASSERT_UNUSED(type, type != TypeObject);
+
+ if (occurrence == ErrorInstance::FoundApproximateSource)
+ return defaultApproximateSourceError(originalMessage, sourceText);
+
+ ASSERT(occurrence == ErrorInstance::FoundExactSource);
+ auto inIndex = sourceText.reverseFind("in");
+ RELEASE_ASSERT(inIndex != notFound);
+ if (sourceText.find("in") != inIndex)
+ return makeString(originalMessage, " (evaluating '", sourceText, "')");
+
+ static const unsigned inLength = 2;
+ String rightHandSide = sourceText.substring(inIndex + inLength).simplifyWhiteSpace();
+ return makeString(rightHandSide, " is not an Object. (evaluating '", sourceText, "')");
+}
+
+static String invalidParameterInstanceofSourceAppender(const String& originalMessage, const String& sourceText, RuntimeType, ErrorInstance::SourceTextWhereErrorOccurred occurrence)
+{
+ if (occurrence == ErrorInstance::FoundApproximateSource)
+ return defaultApproximateSourceError(originalMessage, sourceText);
+
+ ASSERT(occurrence == ErrorInstance::FoundExactSource);
+ auto instanceofIndex = sourceText.reverseFind("instanceof");
+ RELEASE_ASSERT(instanceofIndex != notFound);
+ if (sourceText.find("instanceof") != instanceofIndex)
+ return makeString(originalMessage, " (evaluating '", sourceText, "')");
+
+ static const unsigned instanceofLength = 10;
+ String rightHandSide = sourceText.substring(instanceofIndex + instanceofLength).simplifyWhiteSpace();
+ return makeString(rightHandSide, " is not a function. (evaluating '", sourceText, "')");
+}
+
+JSObject* createError(ExecState* exec, JSValue value, const String& message, ErrorInstance::SourceAppender appender)
+{
+ String errorMessage = makeString(errorDescriptionForValue(exec, value)->value(exec), ' ', message);
+ JSObject* exception = createTypeError(exec, errorMessage, appender, runtimeTypeForValue(value));
+ ASSERT(exception->isErrorInstance());
+ return exception;
+}
+
+JSObject* createInvalidFunctionApplyParameterError(ExecState* exec, JSValue value)
+{
+ JSObject* exception = createTypeError(exec, makeString("second argument to Function.prototype.apply must be an Array-like object"), defaultSourceAppender, runtimeTypeForValue(value));