Changeset 4363 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.