Reviewed by Dave.
- ObjC bindings do not (yet) pass along sourceurl or line numbers
- we don't have a way as of yet to accomidate line numbers and urls for dynamic javascript
- changed the wording of an error message
- the lexer, parser, and interpreter have been made "sourceURL aware"
- stored the url into Error
* bindings/NP_jsobject.cpp:
(NPN_Evaluate):
* bindings/jni/jni_jsobject.cpp:
(JSObject::eval):
* bindings/objc/WebScriptObject.mm:
(-[WebScriptObject evaluateWebScript:]):
* kjs/function.cpp:
(GlobalFuncImp::call):
* kjs/function_object.cpp:
(FunctionObjectImp::construct):
* kjs/internal.cpp:
(Parser::parse):
(InterpreterImp::checkSyntax):
(InterpreterImp::evaluate):
* kjs/internal.h:
* kjs/interpreter.cpp:
(Interpreter::evaluate):
* kjs/interpreter.h:
* kjs/lexer.cpp:
(Lexer::setCode):
* kjs/lexer.h:
(KJS::Lexer::sourceURL):
* kjs/nodes.cpp:
(Node::Node):
(Node::throwError):
(FunctionCallNode::evaluate):
* kjs/nodes.h:
* kjs/object.cpp:
(KJS::Error::create):
* kjs/object.h:
WebCore:
Reviewed by Dave.
- kwq/KWQKHTMLPart.mm: addMessagetoConsole places sourceURL in the dictionary
- khtml/xml/dom_docimpl.cpp: right now, we don't have a way to get a url,
so we leave this blank
- khtml/ecma/kjs_window.cpp: still need to get the real line number and sourceURL
- khtml/ecma/kjs_proxy.cpp: now passing the sourceURL to addMessageToConsole
- khtml/ecma/kjs_events.cpp: still need to grab an accurate line number and sourceURL
* khtml/ecma/kjs_events.cpp:
(JSEventListener::handleEvent):
(JSLazyEventListener::handleEvent):
* khtml/ecma/kjs_proxy.cpp:
(KJSProxyImpl::evaluate):
* khtml/ecma/kjs_window.cpp:
(Window::isSafeScript):
(ScheduledAction::execute):
* khtml/xml/dom_docimpl.cpp:
(DocumentImpl::open):
* kwq/KWQKHTMLPart.h:
* kwq/KWQKHTMLPart.mm:
(KWQKHTMLPart::addMessageToConsole):
WebBrowser:
Reviewed by Dave.
- model is now source url aware
- refined the ui with custom NSCells that now display error messages,
line numbers, and source urls
- increased the row size to 35 pixels to accomimdate for ErrorCells
* Debug/ErrorCell.h: Added.
* Debug/ErrorCell.m: Added.
(-[ErrorCell setURL:]):
(-[ErrorCell setErrorMessasge:]):
(-[ErrorCell setLineNumber:]):
(-[ErrorCell drawInteriorWithFrame:inView:]):
* Debug/ErrorConsole.nib:
* Debug/ErrorConsoleController.m:
(-[ErrorConsoleController init]):
(-[ErrorConsoleController awakeFromNib]):
* Debug/ErrorConsoleModel.h:
* Debug/ErrorConsoleModel.m:
(-[ErrorConsoleModel tableView:willDisplayCell:forTableColumn:row:]):
(-[ErrorConsoleModel count]):
(-[ErrorConsoleModel selectedURL]):
* WebBrowser.pbproj/project.pbxproj:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@6768
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2004-06-04 Kevin Decker <kdecker@apple.com>
+
+ Reviewed by Dave.
+
+ - ObjC bindings do not (yet) pass along sourceurl or line numbers
+ - we don't have a way as of yet to accomidate line numbers and urls for dynamic javascript
+ - changed the wording of an error message
+ - the lexer, parser, and interpreter have been made "sourceURL aware"
+ - stored the url into Error
+
+ * bindings/NP_jsobject.cpp:
+ (NPN_Evaluate):
+ * bindings/jni/jni_jsobject.cpp:
+ (JSObject::eval):
+ * bindings/objc/WebScriptObject.mm:
+ (-[WebScriptObject evaluateWebScript:]):
+ * kjs/function.cpp:
+ (GlobalFuncImp::call):
+ * kjs/function_object.cpp:
+ (FunctionObjectImp::construct):
+ * kjs/internal.cpp:
+ (Parser::parse):
+ (InterpreterImp::checkSyntax):
+ (InterpreterImp::evaluate):
+ * kjs/internal.h:
+ * kjs/interpreter.cpp:
+ (Interpreter::evaluate):
+ * kjs/interpreter.h:
+ * kjs/lexer.cpp:
+ (Lexer::setCode):
+ * kjs/lexer.h:
+ (KJS::Lexer::sourceURL):
+ * kjs/nodes.cpp:
+ (Node::Node):
+ (Node::throwError):
+ (FunctionCallNode::evaluate):
+ * kjs/nodes.h:
+ * kjs/object.cpp:
+ (KJS::Error::create):
+ * kjs/object.h:
+
2004-06-04 Richard Williamson <rjw@apple.com>
Fixed crash when attempting to access properties on nil
NPUTF16 *scriptString;
unsigned int UTF16Length;
convertNPStringToUTF16 (s, &scriptString, &UTF16Length); // requires free() of returned memory.
- KJS::Value result = obj->root->interpreter()->evaluate(UString((const UChar *)scriptString,UTF16Length)).value();
+ KJS::Value result = obj->root->interpreter()->evaluate(UString(), 0, UString((const UChar *)scriptString,UTF16Length)).value();
Interpreter::unlock();
free ((void *)scriptString);
Object thisObj = Object(const_cast<ObjectImp*>(_imp));
Interpreter::lock();
- KJS::Value result = _root->interpreter()->evaluate(JavaString(script).ustring(),thisObj).value();
+ KJS::Value result = _root->interpreter()->evaluate(UString(), 0, JavaString(script).ustring(),thisObj).value();
Interpreter::unlock();
return convertValueToJObject (result);
}
Object thisObj = Object(const_cast<ObjectImp*>([self _imp]));
Interpreter::lock();
Value v = convertObjcValueToValue(exec, &script, ObjcObjectType);
- KJS::Value result = _private->root->interpreter()->evaluate(v.toString(exec)).value();
+ KJS::Value result = _private->root->interpreter()->evaluate(UString(), 0, v.toString(exec)).value();
Interpreter::unlock();
if (exec->hadException()) {
int sid;
int errLine;
UString errMsg;
- ProgramNode *progNode = Parser::parse(s.data(),s.size(),&sid,&errLine,&errMsg);
+ ProgramNode *progNode = Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg);
// no program node means a syntax occurred
if (!progNode) {
int sid;
int errLine;
UString errMsg;
- ProgramNode *progNode = Parser::parse(body.data(),body.size(),&sid,&errLine,&errMsg);
+ ProgramNode *progNode = Parser::parse(UString(), 0, body.data(),body.size(),&sid,&errLine,&errMsg);
// notify debugger that source has been parsed
Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger();
ProgramNode *Parser::progNode = 0;
int Parser::sid = 0;
-ProgramNode *Parser::parse(const UChar *code, unsigned int length, int *sourceId,
+ProgramNode *Parser::parse(const UString &sourceURL, int startingLineNumber,
+ const UChar *code, unsigned int length, int *sourceId,
int *errLine, UString *errMsg)
{
if (errLine)
*errLine = -1;
if (errMsg)
*errMsg = 0;
-
- Lexer::curr()->setCode(code, length);
+
+ Lexer::curr()->setCode(sourceURL, startingLineNumber, code, length);
progNode = 0;
sid++;
if (sourceId)
bool InterpreterImp::checkSyntax(const UString &code)
{
// Parser::parse() returns 0 in a syntax error occurs, so we just check for that
- ProgramNode *progNode = Parser::parse(code.data(),code.size(),0,0,0);
+ ProgramNode *progNode = Parser::parse(UString(), 0, code.data(),code.size(),0,0,0);
bool ok = (progNode != 0);
if (progNode) {
// must ref and deref to clean up properly
return ok;
}
-Completion InterpreterImp::evaluate(const UString &code, const Value &thisV)
+Completion InterpreterImp::evaluate(const UString &code, const Value &thisV, const UString &sourceURL, int startingLineNumber)
{
#if APPLE_CHANGES
lockInterpreter();
return Completion(Throw,Error::create(globExec,GeneralError,"Recursion too deep"));
#endif
}
-
+
// parse the source code
int sid;
int errLine;
UString errMsg;
- ProgramNode *progNode = Parser::parse(code.data(),code.size(),&sid,&errLine,&errMsg);
+ ProgramNode *progNode = Parser::parse(sourceURL, startingLineNumber, code.data(),code.size(),&sid,&errLine,&errMsg);
// notify debugger that source has been parsed
if (dbg) {
return Completion(Break);
#endif
}
-
+
// no program node means a syntax error occurred
if (!progNode) {
- Object err = Error::create(globExec,SyntaxError,errMsg.ascii(),errLine);
+ Object err = Error::create(globExec,SyntaxError,errMsg.ascii(),errLine, -1, &sourceURL);
err.put(globExec,"sid",Number(sid));
#if APPLE_CHANGES
unlockInterpreter();
*/
class Parser {
public:
- static ProgramNode *parse(const UChar *code, unsigned int length, int *sourceId = 0,
+ static ProgramNode *parse(const UString &sourceURL, int startingLineNumber,
+ const UChar *code, unsigned int length, int *sourceId = 0,
int *errLine = 0, UString *errMsg = 0);
static ProgramNode *progNode;
ExecState *globalExec() { return globExec; }
bool checkSyntax(const UString &code);
- Completion evaluate(const UString &code, const Value &thisV);
+ Completion evaluate(const UString &code, const Value &thisV, const UString &sourceURL, int startingLineNumber);
Debugger *debugger() const { return dbg; }
void setDebugger(Debugger *d);
return rep->checkSyntax(code);
}
-Completion Interpreter::evaluate(const UString &code, const Value &thisV, const UString &filename)
+Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, const Value &thisV)
{
- Completion comp = rep->evaluate(code,thisV);
+ Completion comp = rep->evaluate(code,thisV, sourceURL, startingLineNumber);
#if APPLE_CHANGES
if (shouldPrintExceptions() && comp.complType() == Throw) {
lock();
ExecState *exec = rep->globalExec();
- char *f = strdup(filename.ascii());
+ char *f = strdup(sourceURL.ascii());
const char *message = comp.value().toObject(exec).toString(exec).ascii();
printf("%s:%s\n", f, message);
free(f);
* execution. This should either be Null() or an Object.
* @return A completion object representing the result of the execution.
*/
- Completion evaluate(const UString &code, const Value &thisV = Value(), const UString &filename = UString());
+ Completion evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, const Value &thisV = Value());
/**
* @internal
}
#endif
-void Lexer::setCode(const UChar *c, unsigned int len)
+void Lexer::setCode(const UString &sourceURL, int startingLineNumber, const UChar *c, unsigned int len)
{
yylineno = 1;
+ m_sourceURL = sourceURL;
restrKeyword = false;
delimited = false;
eatNextIdentifier = false;
~Lexer();
static Lexer *curr();
- void setCode(const UChar *c, unsigned int len);
+ void setCode(const UString &sourceURL, int startingLineNumber, const UChar *c, unsigned int len);
int lex();
int lineNo() const { return yylineno + 1; }
+ UString sourceURL() const { return m_sourceURL; }
bool prevTerminator() const { return terminator; }
private:
int yylineno;
+ UString m_sourceURL;
bool done;
char *buffer8;
UChar *buffer16;
Node::Node()
{
line = Lexer::curr()->lineNo();
+ sourceURL = Lexer::curr()->sourceURL();
refcount = 0;
#ifdef KJS_DEBUG_MEM
if (!s_nodes)
Value Node::throwError(ExecState *exec, ErrorType e, const char *msg)
{
- Object err = Error::create(exec, e, msg, lineNo(), sourceId());
+ Object err = Error::create(exec, e, msg, lineNo(), sourceId(), &sourceURL);
exec->setException(err);
return err;
}
Value v = ref.getValue(exec);
if (v.type() != ObjectType) {
- return throwError(exec, TypeError, "Value %s (result of expression %s) is not object. Cannot be called.", v, expr);
+ return throwError(exec, TypeError, "Value %s (result of expression %s) is not object.", v, expr);
}
Object func = Object(static_cast<ObjectImp*>(v.imp()));
Value throwError(ExecState *exec, ErrorType e, const char *msg, Value v, Node *expr);
Value throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label);
int line;
+ UString sourceURL;
unsigned int refcount;
virtual int sourceId() const { return -1; }
private:
const char * const * const Error::errorNames = errorNamesArr;
Object Error::create(ExecState *exec, ErrorType errtype, const char *message,
- int lineno, int sourceId)
+ int lineno, int sourceId, const UString *sourceURL)
{
Object cons;
switch (errtype) {
if (sourceId != -1)
err.put(exec, "sourceId", Number(sourceId));
+ err.put(exec,"sourceURL", String(*sourceURL));
+
return err;
/*
*/
static Object create(ExecState *exec, ErrorType errtype = GeneralError,
const char *message = 0, int lineno = -1,
- int sourceId = -1);
+ int sourceId = -1, const UString *sourceURL = 0);
/**
* Array of error names corresponding to @ref ErrorType
+2004-06-04 Kevin Decker <kdecker@apple.com>
+
+ Reviewed by Dave.
+
+ - kwq/KWQKHTMLPart.mm: addMessagetoConsole places sourceURL in the dictionary
+ - khtml/xml/dom_docimpl.cpp: right now, we don't have a way to get a url,
+ so we leave this blank
+ - khtml/ecma/kjs_window.cpp: still need to get the real line number and sourceURL
+ - khtml/ecma/kjs_proxy.cpp: now passing the sourceURL to addMessageToConsole
+ - khtml/ecma/kjs_events.cpp: still need to grab an accurate line number and sourceURL
+
+ * khtml/ecma/kjs_events.cpp:
+ (JSEventListener::handleEvent):
+ (JSLazyEventListener::handleEvent):
+ * khtml/ecma/kjs_proxy.cpp:
+ (KJSProxyImpl::evaluate):
+ * khtml/ecma/kjs_window.cpp:
+ (Window::isSafeScript):
+ (ScheduledAction::execute):
+ * khtml/xml/dom_docimpl.cpp:
+ (DocumentImpl::open):
+ * kwq/KWQKHTMLPart.h:
+ * kwq/KWQKHTMLPart.mm:
+ (KWQKHTMLPart::addMessageToConsole):
+
2004-06-04 Ken Kocienda <kocienda@apple.com>
Reviewed by Hyatt
KJS::Interpreter::lock();
char *message = exec->exception().toObject(exec).get(exec, messagePropertyName).toString(exec).ascii();
int lineNumber = exec->exception().toObject(exec).get(exec, "line").toInt32(exec);
+ UString sourceURL = exec->exception().toObject(exec).get(exec, "sourceURL").toString(exec);
KJS::Interpreter::unlock();
if (Interpreter::shouldPrintExceptions()) {
printf("(event handler):%s\n", message);
}
- KWQ(part)->addMessageToConsole(message, lineNumber );
+ KWQ(part)->addMessageToConsole(message, lineNumber, sourceURL.qstring());
exec->clearException();
}
#else
void JSLazyEventListener::handleEvent(DOM::Event &evt, bool isWindowEvent)
{
parseCode();
- if (!listener.isNull()) {
+ if (!listener.isNull()) {
JSEventListener::handleEvent(evt, isWindowEvent);
}
}
KJS::Value thisNode = n.isNull() ? Window::retrieve( m_part ) : getDOMNode(m_script->globalExec(),n);
UString code( str );
- Completion comp = m_script->evaluate(code, thisNode, filename);
+ Completion comp = m_script->evaluate(filename, baseLine, code, thisNode);
bool success = ( comp.complType() == Normal ) || ( comp.complType() == ReturnValue );
#ifdef KJS_DEBUGGER
// KJSDebugWin::instance()->setCode(QString::null);
if ( comp.complType() == Throw )
{
KJS::Interpreter::lock();
- UString msg = comp.value().toString(m_script->globalExec());
+ UString errorMessage = comp.value().toString(m_script->globalExec());
int lineNumber = comp.value().toObject(m_script->globalExec()).get(m_script->globalExec(), "line").toInt32(m_script->globalExec());
+ UString sourceURL = comp.value().toObject(m_script->globalExec()).get(m_script->globalExec(), "sourceURL").toString(m_script->globalExec());
KJS::Interpreter::unlock();
+
#if APPLE_CHANGES
- KWQ(m_part)->addMessageToConsole(msg.qstring(), lineNumber);
+ KWQ(m_part)->addMessageToConsole(errorMessage.qstring(), lineNumber, sourceURL.qstring());
#else
- kdWarning(6070) << "Script threw exception: " << msg.qstring() << endl;
+ kdWarning(6070) << "Script threw exception: " << errorMessage.qstring() << endl;
#endif
}
return QVariant();
QString message;
message.sprintf("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains must match.\n",
thisDocument->URL().latin1(), actDocument->URL().latin1());
- KWQ(m_part)->addMessageToConsole(message, 1);
+ KWQ(m_part)->addMessageToConsole(message, 1, QString()); //fixme: provide a real line number and sourceurl
}
#endif
if (Interpreter::shouldPrintExceptions()) {
printf("(timer):%s\n", message);
}
- KWQ(window->m_part)->addMessageToConsole(message, lineNumber);
+ KWQ(window->m_part)->addMessageToConsole(message, lineNumber, QString());
#endif
exec->clearException();
}
connect(m_tokenizer,SIGNAL(finishedParsing()),this,SIGNAL(finishedParsing()));
m_tokenizer->begin();
- if (m_view && m_view->part()->jScript())
- m_view->part()->jScript()->setSourceFile(m_url,"");
+ if (m_view && m_view->part()->jScript()) {
+ m_view->part()->jScript()->setSourceFile(m_url,""); //fixme
+ }
}
HTMLElementImpl* DocumentImpl::body()
void runJavaScriptAlert(const QString &message);
bool runJavaScriptConfirm(const QString &message);
bool runJavaScriptPrompt(const QString &message, const QString &defaultValue, QString &result);
- void KWQKHTMLPart::addMessageToConsole(const QString &message, const unsigned int lineNumber);
+ void KWQKHTMLPart::addMessageToConsole(const QString &message, unsigned int lineNumber, const QString &sourceID);
using KHTMLPart::xmlDocImpl;
khtml::RenderObject *renderer();
void forceLayout();
return false;
}
-void KWQKHTMLPart::addMessageToConsole(const QString &message, const unsigned int lineNumber)
+void KWQKHTMLPart::addMessageToConsole(const QString &message, unsigned lineNumber, const QString &sourceURL)
{
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
- message.getNSString(), @"message",[NSNumber numberWithInt: lineNumber], @"lineNumber", NULL];
+ message.getNSString(), @"message",
+ [NSNumber numberWithInt: lineNumber], @"lineNumber",
+ sourceURL.getNSString(), @"sourceURL",
+ NULL];
[_bridge addMessageToConsole:dictionary];
}