Changeset 34075 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
May 23, 2008, 7:23:23 AM (17 years ago)
Author:
[email protected]
Message:

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.

Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r34074 r34075  
     12008-05-23  Oliver Hunt  <[email protected]>
     2
     3        Reviewed by Anders.
     4
     5        SQUIRRELFISH: JavaScript error messages are missing informative text
     6
     7        Partial fix.
     8        Tidy up error messages, makes a couple of them provide slightly more info.
     9        Inexplicably leads to a 1% SunSpider Progression.
     10
     11        * VM/ExceptionHelpers.cpp:
     12        (KJS::createError):
     13        (KJS::createInvalidParamError):
     14        (KJS::createNotAConstructorError):
     15        (KJS::createNotAFunctionError):
     16        * VM/ExceptionHelpers.h:
     17        * VM/Machine.cpp:
     18        (KJS::isNotObject):
     19
    1202008-05-23  Oliver Hunt  <[email protected]>
    221
  • trunk/JavaScriptCore/VM/ExceptionHelpers.cpp

    r33979 r34075  
    4848JSValue* createError(ExecState* exec, ErrorType e, const char* msg)
    4949{
    50     return Error::create(exec, e, msg, -1, -1, 0); // lineNo(), currentSourceId(exec), currentSourceURL(exec)
     50    return Error::create(exec, e, msg, -1, -1, 0);
    5151}
    5252
     
    5555    UString message = msg;
    5656    substitute(message, label.ustring());
    57     return Error::create(exec, e, message, -1, -1, 0); // lineNo(), currentSourceId(exec), currentSourceURL(exec)
     57    return Error::create(exec, e, message, -1, -1, 0);
    5858}
    5959
     
    6464    if (expr)
    6565        substitute(message, expr->toString());
    66     else
    67         substitute(message, "<<no string for expression>>");
    68     return Error::create(exec, e, message, -1, -1, 0); //, lineNo(), currentSourceId(exec), currentSourceURL(exec));
     66    return Error::create(exec, e, message, -1, -1, 0);
     67}
     68
     69JSValue* createError(ExecState* exec, ErrorType e, const char* msg, JSValue* v)
     70{
     71    UString message = msg;
     72    substitute(message, v->toString(exec));
     73    return Error::create(exec, e, message, -1, -1, 0);
    6974}
    7075
     
    7883    return createError(exec, ReferenceError, "Can't find variable: %s", ident);
    7984}
    80 
    81 JSValue* createNotAnObjectError(ExecState* exec, JSValue* value, Node* expr)
     85   
     86JSValue* createInvalidParamError(ExecState* exec, const char* op, JSValue* v)
    8287{
    83     return createError(exec, TypeError, "Value %s (result of expression %s) is not an object.", value, expr);
     88    UString message = "'%s' is not a valid argument for '%s'";
     89    substitute(message,  v->toString(exec));
     90    substitute(message, op);
     91    return Error::create(exec, TypeError, message, -1, -1, 0);
    8492}
    8593
    8694JSValue* createNotAConstructorError(ExecState* exec, JSValue* value, Node* expr)
    8795{
    88     if (!value->isObject())
    89         return createNotAnObjectError(exec, value, expr);
    90     return createError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", value, expr);
     96    if (expr)
     97        return createError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", value, expr);
     98    return createError(exec, TypeError, "Value %s is not a constructor. Cannot be used with new.", value);
    9199}
    92100
    93101JSValue* createNotAFunctionError(ExecState* exec, JSValue* value, Node* expr)
    94102{
    95     if (!value->isObject())
    96         return createNotAnObjectError(exec, value, expr);
    97     return createError(exec, TypeError, "Value %s (result of expression %s) does not allow function calls.", value, expr);
     103    if (expr)
     104        return createError(exec, TypeError, "Value %s (result of expression %s) does not allow function calls.", value, expr);
     105    return createError(exec, TypeError, "Value %s does not allow function calls.", value);
    98106}
    99107
  • trunk/JavaScriptCore/VM/ExceptionHelpers.h

    r33979 r34075  
    3636    JSValue* createStackOverflowError(ExecState*);
    3737    JSValue* createUndefinedVariableError(ExecState*, const Identifier&);
    38     JSValue* createNotAnObjectError(ExecState*, JSValue*, Node*);
     38    JSValue* createInvalidParamError(ExecState*, const char* op, JSValue*);
    3939    JSValue* createNotAConstructorError(ExecState* exec, JSValue* value, Node* expr);
    4040    JSValue* createNotAFunctionError(ExecState* exec, JSValue* value, Node* expr);
  • trunk/JavaScriptCore/VM/Machine.cpp

    r34069 r34075  
    430430}
    431431
    432 static NEVER_INLINE bool isNotObject(ExecState* exec, const Instruction*, CodeBlock*, JSValue* value, JSValue*& exceptionData)
     432static NEVER_INLINE bool isNotObject(ExecState* exec, bool forInstanceOf, CodeBlock*, JSValue* value, JSValue*& exceptionData)
    433433{
    434434    if (value->isObject())
    435435        return false;
    436     exceptionData = createNotAnObjectError(exec, value, 0);
     436    exceptionData = createInvalidParamError(exec, forInstanceOf ? "instanceof" : "in" , value);
    437437    return true;
    438438}
Note: See TracChangeset for help on using the changeset viewer.