- // We're in a "new" expression, so we need to skip over the "new.." part
- int startPoint = divotPoint - (startOffset ? startOffset - 4 : 0); // -4 for "new "
- const UChar* data = codeBlock->source()->data();
- while (startPoint < divotPoint && isStrWhiteSpace(data[startPoint]))
- startPoint++;
-
- UString errorMessage = createErrorMessage(exec, codeBlock, line, startPoint, divotPoint, value, "not a constructor");
- JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode()->sourceID(), codeBlock->ownerNode()->sourceURL());
- exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
- exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
- exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete);
+ 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());