From effad0a3306146e891dddd14c70217e49f69cf7c Mon Sep 17 00:00:00 2001 From: "oliver@apple.com" Date: Fri, 23 May 2008 14:23:23 +0000 Subject: [PATCH] SQUIRRELFISH: JavaScript error messages are missing informative text Reviewed by Anders Partial fix. Tidy up error messages, makes a couple of them provide slightly more info. Inexplicably leads to a 1% SunSpider Progression. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@34075 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- JavaScriptCore/ChangeLog | 19 ++++++++++++++++++ JavaScriptCore/VM/ExceptionHelpers.cpp | 36 +++++++++++++++++++++------------- JavaScriptCore/VM/ExceptionHelpers.h | 2 +- JavaScriptCore/VM/Machine.cpp | 4 ++-- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog index c760260..bf4e1a2 100644 --- a/JavaScriptCore/ChangeLog +++ b/JavaScriptCore/ChangeLog @@ -1,5 +1,24 @@ 2008-05-23 Oliver Hunt + Reviewed by Anders. + + SQUIRRELFISH: JavaScript error messages are missing informative text + + Partial fix. + Tidy up error messages, makes a couple of them provide slightly more info. + Inexplicably leads to a 1% SunSpider Progression. + + * VM/ExceptionHelpers.cpp: + (KJS::createError): + (KJS::createInvalidParamError): + (KJS::createNotAConstructorError): + (KJS::createNotAFunctionError): + * VM/ExceptionHelpers.h: + * VM/Machine.cpp: + (KJS::isNotObject): + +2008-05-23 Oliver Hunt + Reviewed by Tim H. Fix call stack reported by profiler when entering event handlers. diff --git a/JavaScriptCore/VM/ExceptionHelpers.cpp b/JavaScriptCore/VM/ExceptionHelpers.cpp index 262fcc0..bdce6c7 100644 --- a/JavaScriptCore/VM/ExceptionHelpers.cpp +++ b/JavaScriptCore/VM/ExceptionHelpers.cpp @@ -47,14 +47,14 @@ static void substitute(UString& string, const UString& substring) JSValue* createError(ExecState* exec, ErrorType e, const char* msg) { - return Error::create(exec, e, msg, -1, -1, 0); // lineNo(), currentSourceId(exec), currentSourceURL(exec) + return Error::create(exec, e, msg, -1, -1, 0); } JSValue* createError(ExecState* exec, ErrorType e, const char* msg, const Identifier& label) { UString message = msg; substitute(message, label.ustring()); - return Error::create(exec, e, message, -1, -1, 0); // lineNo(), currentSourceId(exec), currentSourceURL(exec) + return Error::create(exec, e, message, -1, -1, 0); } JSValue* createError(ExecState* exec, ErrorType e, const char* msg, JSValue* v, Node* expr) @@ -63,9 +63,14 @@ JSValue* createError(ExecState* exec, ErrorType e, const char* msg, JSValue* v, substitute(message, v->toString(exec)); if (expr) substitute(message, expr->toString()); - else - substitute(message, "<>"); - return Error::create(exec, e, message, -1, -1, 0); //, lineNo(), currentSourceId(exec), currentSourceURL(exec)); + return Error::create(exec, e, message, -1, -1, 0); +} + +JSValue* createError(ExecState* exec, ErrorType e, const char* msg, JSValue* v) +{ + UString message = msg; + substitute(message, v->toString(exec)); + return Error::create(exec, e, message, -1, -1, 0); } JSValue* createStackOverflowError(ExecState* exec) @@ -77,24 +82,27 @@ JSValue* createUndefinedVariableError(ExecState* exec, const Identifier& ident) { return createError(exec, ReferenceError, "Can't find variable: %s", ident); } - -JSValue* createNotAnObjectError(ExecState* exec, JSValue* value, Node* expr) + +JSValue* createInvalidParamError(ExecState* exec, const char* op, JSValue* v) { - return createError(exec, TypeError, "Value %s (result of expression %s) is not an object.", value, expr); + UString message = "'%s' is not a valid argument for '%s'"; + substitute(message, v->toString(exec)); + substitute(message, op); + return Error::create(exec, TypeError, message, -1, -1, 0); } JSValue* createNotAConstructorError(ExecState* exec, JSValue* value, Node* expr) { - if (!value->isObject()) - return createNotAnObjectError(exec, value, expr); - return createError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", value, expr); + if (expr) + return createError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", value, expr); + return createError(exec, TypeError, "Value %s is not a constructor. Cannot be used with new.", value); } JSValue* createNotAFunctionError(ExecState* exec, JSValue* value, Node* expr) { - if (!value->isObject()) - return createNotAnObjectError(exec, value, expr); - return createError(exec, TypeError, "Value %s (result of expression %s) does not allow function calls.", value, expr); + if (expr) + return createError(exec, TypeError, "Value %s (result of expression %s) does not allow function calls.", value, expr); + return createError(exec, TypeError, "Value %s does not allow function calls.", value); } } diff --git a/JavaScriptCore/VM/ExceptionHelpers.h b/JavaScriptCore/VM/ExceptionHelpers.h index 259ed46..e425df3 100644 --- a/JavaScriptCore/VM/ExceptionHelpers.h +++ b/JavaScriptCore/VM/ExceptionHelpers.h @@ -35,7 +35,7 @@ namespace KJS { class Node; JSValue* createStackOverflowError(ExecState*); JSValue* createUndefinedVariableError(ExecState*, const Identifier&); - JSValue* createNotAnObjectError(ExecState*, JSValue*, Node*); + JSValue* createInvalidParamError(ExecState*, const char* op, JSValue*); JSValue* createNotAConstructorError(ExecState* exec, JSValue* value, Node* expr); JSValue* createNotAFunctionError(ExecState* exec, JSValue* value, Node* expr); } diff --git a/JavaScriptCore/VM/Machine.cpp b/JavaScriptCore/VM/Machine.cpp index c5976e0..fbf5ff5 100644 --- a/JavaScriptCore/VM/Machine.cpp +++ b/JavaScriptCore/VM/Machine.cpp @@ -429,11 +429,11 @@ ALWAYS_INLINE ScopeChainNode* scopeChainForCall(FunctionBodyNode* functionBodyNo return callDataScopeChain; } -static NEVER_INLINE bool isNotObject(ExecState* exec, const Instruction*, CodeBlock*, JSValue* value, JSValue*& exceptionData) +static NEVER_INLINE bool isNotObject(ExecState* exec, bool forInstanceOf, CodeBlock*, JSValue* value, JSValue*& exceptionData) { if (value->isObject()) return false; - exceptionData = createNotAnObjectError(exec, value, 0); + exceptionData = createInvalidParamError(exec, forInstanceOf ? "instanceof" : "in" , value); return true; } -- 1.8.3.1