Changeset 4363 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
May 13, 2003, 2:19:57 PM (22 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Darin.

  • fixed 3254484 - Add a way to print JavaScript exceptions to the console via the debug menu
  • improved JavaScript error message format
  • kjs/error_object.cpp: (ErrorProtoFuncImp::call): Include line number in toString output.
  • kjs/internal.cpp: (Parser::parse): Remove redundant fprintf.
  • kjs/interpreter.cpp: (Interpreter::evaluate): Log if the flag is on. Include filename in log output. (Interpreter::shouldPrintExceptions): Check the global flag. (Interpreter::setShouldPrintExceptions): Set the global flag.
  • kjs/interpreter.h:
  • kjs/nodes.cpp: (Node::throwError): Add variants that include value and expression or label in format. (NewExprNode::evaluate): Improve error message. (FunctionCallNode::evaluate): Improve error message. (RelationalNode::evaluate): Improve error message. (ContinueNode::execute): Improve error message. (BreakNode::execute): Improve error message. (LabelNode::execute): Improve error message.
  • kjs/nodes.h:

WebCore:

Reviewed by Darin.

  • fixed 3254484 - Add a way to print JavaScript exceptions to the console via the debug menu
  • khtml/ecma/kjs_proxy.cpp: (KJSProxyImpl::evaluate): Pass the filename.
  • kwq/WebCoreJavaScript.h:
  • kwq/WebCoreJavaScript.mm: (+[WebCoreJavaScript shouldPrintExceptions]): Call through to JavaScriptCore. (+[WebCoreJavaScript setShouldPrintExceptions:]): Call through to JavaScriptCore.
  • khtml/ecma/kjs_events.cpp: (JSEventListener::handleEvent): Print exception if there is one.
  • khtml/ecma/kjs_window.cpp: (ScheduledAction::execute): Print exception in the function case.

WebKit:

Reviewed by Darin.

  • fixed 3254484 - Add a way to print JavaScript exceptions to the console via the debug menu
  • Misc.subproj/WebCoreStatistics.h:
  • Misc.subproj/WebCoreStatistics.m: (+[WebCoreStatistics shouldPrintExceptions]): Call through to WebCore. (+[WebCoreStatistics setShouldPrintExceptions:]): Call through to WebCore.

WebBrowser:

Reviewed by Darin.

  • fixed 3254484 - Add a way to print JavaScript exceptions to the console via the debug menu
  • Debug/DebugUtilities.m: (-[DebugUtilities createDebugMenu]): Include "Log JavaScript Exceptions" item. (-[BrowserDocument toggleLogJavaScriptExceptions:]): Call WebKit to do the toggle. (-[BrowserDocument validate_toggleLogJavaScriptExceptions:]): Set state properly.
Location:
trunk/JavaScriptCore/kjs
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/error_object.cpp

    r3373 r4363  
    6565{
    6666  // toString()
    67   UString s = "Error";
     67  UString s;
    6868
    69   Value v = thisObj.get(exec, namePropertyName);
     69  Value v = thisObj.get(exec, "line");
    7070  if (v.type() != UndefinedType) {
    71     s = v.toString(exec);
     71    s += v.toString(exec) += ": ";
     72  }
     73
     74
     75  v = thisObj.get(exec, namePropertyName);
     76  if (v.type() != UndefinedType) {
     77    s += v.toString(exec);
    7278  }
    7379
    7480  v = thisObj.get(exec, messagePropertyName);
    7581  if (v.type() != UndefinedType) {
    76     s += ": "+v.toString(exec);
     82    s += " - " + v.toString(exec);
    7783  }
    7884
  • trunk/JavaScriptCore/kjs/internal.cpp

    r4206 r4363  
    456456    if (errMsg)
    457457      *errMsg = "Parse error at line " + UString::from(eline);
    458 #ifndef NDEBUG
    459     fprintf(stderr, "KJS: JavaScript parse error at line %d.\n", eline);
    460 #endif
    461458    delete prog;
    462459    return 0;
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r4087 r4363  
    116116}
    117117
    118 Completion Interpreter::evaluate(const UString &code, const Value &thisV)
     118Completion Interpreter::evaluate(const UString &code, const Value &thisV, const UString &filename)
    119119{
    120120  Completion comp = rep->evaluate(code,thisV);
    121 #ifndef NDEBUG
    122   if (comp.complType() == Throw) {
     121
     122#if APPLE_CHANGES
     123  if (shouldPrintExceptions() && comp.complType() == Throw) {
    123124    lock();
    124125    ExecState *exec = rep->globalExec();
    125     printf("Uncaught exception: %s\n", comp.value().toObject(exec).toString(exec).ascii());
     126    char *f = strdup(filename.ascii());
     127    const char *message = comp.value().toObject(exec).toString(exec).ascii();
     128    printf("%s:%s\n", f, message);
     129    free(f);
    126130    unlock();
    127131  }
    128132#endif
     133
    129134  return comp;
    130135}
     
    313318#endif
    314319
     320#if APPLE_CHANGES
     321static bool printExceptions = false;
     322
     323bool Interpreter::shouldPrintExceptions()
     324{
     325  return printExceptions;
     326}
     327
     328void Interpreter::setShouldPrintExceptions(bool print)
     329{
     330  printExceptions = print;
     331}
     332#endif
     333
    315334void Interpreter::virtual_hook( int, void* )
    316335{ /*BASE::virtual_hook( id, data );*/ }
  • trunk/JavaScriptCore/kjs/interpreter.h

    r4087 r4363  
    187187     * @return A completion object representing the result of the execution.
    188188     */
    189     Completion evaluate(const UString &code, const Value &thisV = Value());
     189    Completion evaluate(const UString &code, const Value &thisV = Value(), const UString &filename = UString());
    190190
    191191    /**
     
    339339    static void finalCheck();
    340340#endif
     341
     342#if APPLE_CHANGES
     343    static bool shouldPrintExceptions();
     344    static void setShouldPrintExceptions(bool);
     345#endif
     346
    341347  private:
    342348    InterpreterImp *rep;
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r4282 r4363  
    131131}
    132132
     133Value Node::throwError(ExecState *exec, ErrorType e, const char *msg, Value v, Node *expr)
     134{
     135  char *vStr = strdup(v.toString(exec).ascii());
     136  char *exprStr = strdup(expr->toString().ascii());
     137 
     138  int length =  strlen(msg) - 4 /* two %s */ + strlen(vStr) + strlen(exprStr) + 1 /* null terminator */;
     139  char *str = new char[length];
     140  sprintf(str, msg, vStr, exprStr);
     141  free(vStr);
     142  free(exprStr);
     143
     144  Value result = throwError(exec, e, str);
     145  delete [] str;
     146 
     147  return result;
     148}
     149
     150
     151Value Node::throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label)
     152{
     153  const char *l = label.ascii();
     154  int length = strlen(msg) - 2 /* %s */ + strlen(l) + 1 /* null terminator */;
     155  char *message = new char[length];
     156  sprintf(message, msg, l);
     157
     158  Value result = throwError(exec, e, message);
     159  delete [] message;
     160
     161  return result;
     162}
     163
    133164// ------------------------------ StatementNode --------------------------------
    134165StatementNode::StatementNode() : l0(-1), l1(-1), sid(-1), breakPoint(false)
     
    658689
    659690  if (v.type() != ObjectType) {
    660     return throwError(exec, TypeError, "Value used with new is not object.");
     691    return throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with new.", v, expr);
    661692  }
    662693
    663694  Object constr = Object(static_cast<ObjectImp*>(v.imp()));
    664695  if (!constr.implementsConstruct()) {
    665     return throwError(exec, TypeError, "Value asked to construct is not a constructor.");
     696    return throwError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", v, expr);
    666697  }
    667698
     
    704735
    705736  if (v.type() != ObjectType) {
    706 #ifndef NDEBUG
    707     printInfo(exec, "WARNING: Failed function call attempt on", v, line);
    708 #endif
    709     return throwError(exec, TypeError, "Value is not object. Cannot be called.");
     737    return throwError(exec, TypeError, "Value %s (result of expression %s) is not object. Cannot be called.", v, expr);
    710738  }
    711739
     
    713741
    714742  if (!func.implementsCall()) {
    715 #ifndef NDEBUG
    716     printInfo(exec, "Failed function call attempt on", v, line);
    717 #endif
    718     return throwError(exec, TypeError, "Object does not allow calls.");
     743    return throwError(exec, TypeError, "Object %s (result of expression %s) does not allow calls.", v, expr);
    719744  }
    720745
     
    722747  static int depth = 0; // sum of all concurrent interpreters
    723748  if (++depth > KJS_MAX_STACK) {
    724 #ifndef NDEBUG
    725     printInfo(exec, "Exceeded maximum function call depth", v, line);
    726 #endif
    727     return throwError(exec, RangeError, "Exceeded maximum function call depth.");
     749    return throwError(exec, RangeError, "Exceeded maximum function call depth calling %s (result of expression %s).", v, expr);
    728750  }
    729751#endif
     
    11921214      if (v2.type() != ObjectType)
    11931215          return throwError(exec,  TypeError,
    1194                              "Used IN expression with non-object." );
     1216                             "Value %s (result of expression %s) is not an object. Cannot be used with IN expression.", v2, expr2);
    11951217      Object o2(static_cast<ObjectImp*>(v2.imp()));
    11961218      b = o2.hasProperty(exec, Identifier(v1.toString(exec)));
     
    11981220    if (v2.type() != ObjectType)
    11991221        return throwError(exec,  TypeError,
    1200                            "Used instanceof operator on non-object." );
     1222                           "Value %s (result of expression %s) is not an object. Cannot be used with instanceof operator.", v2, expr2);
    12011223
    12021224    Object o2(static_cast<ObjectImp*>(v2.imp()));
     
    21482170  Value dummy;
    21492171  return exec->context().imp()->seenLabels()->contains(ident) ?
    2150     Completion(Continue, dummy, ident) :
     2172    Completion(Break, dummy, ident) :
    21512173    Completion(Throw,
    2152                throwError(exec, SyntaxError, "Label not found in containing block"));
     2174               throwError(exec, SyntaxError, "Label %s not found in containing block. Can't continue.", ident));
    21532175}
    21542176
     
    21642186    Completion(Break, dummy, ident) :
    21652187    Completion(Throw,
    2166                throwError(exec, SyntaxError, "Label not found in containing block"));
     2188               throwError(exec, SyntaxError, "Label %s not found in containing block. Can't break.", ident));
    21672189}
    21682190
     
    25192541  if (!exec->context().imp()->seenLabels()->push(label)) {
    25202542    return Completion( Throw,
    2521                        throwError(exec, SyntaxError, "Duplicated label found" ));
     2543                       throwError(exec, SyntaxError, "Duplicated label %s found.", label));
    25222544  };
    25232545  e = statement->execute(exec);
  • trunk/JavaScriptCore/kjs/nodes.h

    r3373 r4363  
    100100  protected:
    101101    Value throwError(ExecState *exec, ErrorType e, const char *msg);
     102    Value throwError(ExecState *exec, ErrorType e, const char *msg, Value v, Node *expr);
     103    Value throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label);
    102104    int line;
    103105    unsigned int refcount;
Note: See TracChangeset for help on using the changeset viewer.