Reviewed by Maciej.
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7726
REGRESSION: orbitz calendar fails (JavaScript function serialization/parsing)
* kjs/object.h: Take function name, as well as source URL and line number, when
using the special overloaded construct for making functions.
* kjs/object.cpp: (KJS::JSObject::construct): Ditto.
* kjs/function_object.h: Ditto.
* kjs/function_object.cpp: (FunctionObjectImp::construct): Pass a name when
constructing the function rather than null. Use "anonymous" when making a
function using the default function constructor.
* kjs/nodes2string.cpp: (FuncDeclNode::streamTo): Put a line break just before
a function declaration.
- unrelated fix
* kxmlcore/HashMapPtrSpec.h: Add missing needed friend declaration.
LayoutTests:
- test for http://bugzilla.opendarwin.org/show_bug.cgi?id=7726
REGRESSION: orbitz calendar fails (JavaScript function serialization/parsing)
* fast/js/resources/function-names.js: Added.
* fast/js/function-names.html: Generated.
* fast/js/function-names-expected.txt: Generated.
WebCore:
Reviewed by Maciej.
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7726
REGRESSION: orbitz calendar fails (JavaScript function serialization/parsing)
Test: fast/js/function-names.html
* dom/Document.h: Add function name parameter to createHTMLEventListener.
* dom/Document.cpp:
(WebCore::Document::createHTMLEventListener): Pass function name when calling
createHTMLEventHandler.
(WebCore::Document::setHTMLWindowEventListener): Pass attribute name as function name
when calling createHTMLEventListener.
* html/HTMLElement.cpp: (WebCore::HTMLElement::setHTMLEventListener): Pass attribute
name as function name when calling createHTMLEventListener.
* khtml/ecma/kjs_events.h: Add a function name parameter to JSLazyEventListener.
* khtml/ecma/kjs_events.cpp:
(KJS::JSLazyEventListener::JSLazyEventListener): Take and store a function name.
(KJS::JSLazyEventListener::parseCode): Pass function name when constructing the function.
* khtml/ecma/kjs_proxy.h: Add a function name parameter to createHTMLEventHandler and
createSVGEventHandler.
* khtml/ecma/kjs_proxy.cpp:
(WebCore::KJSProxy::createHTMLEventHandler): Pass function name when creating
a JSLazyEventListener.
(WebCore::KJSProxy::createSVGEventHandler): Ditto.
* ksvg2/events/JSSVGLazyEventListener.h: Add a function name parameter to
JSSVGLazyEventListener.
* ksvg2/events/JSSVGLazyEventListener.cpp:
(WebCore::JSSVGLazyEventListener::JSSVGLazyEventListener): Pass the function name
on to the base class constructor.
* ksvg2/misc/SVGDocumentExtensions.h: Add function name parameter to createSVGEventListener.
* ksvg2/misc/SVGDocumentExtensions.cpp:
(WebCore::SVGDocumentExtensions::createSVGEventListener): Pass function name when
calling createSVGEventHandler.
* ksvg2/svg/SVGElement.cpp: (WebCore::SVGElement::addSVGEventListener):
* ksvg2/svg/SVGSVGElement.cpp: (WebCore::SVGSVGElement::addSVGWindowEventListner):
Pass attribute name as function name when calling createSVGEventListener.
* WebCore.xcodeproj/project.pbxproj: Moved generation script to the top.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13465
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-03-23 Darin Adler <darin@apple.com>
+
+ Reviewed by Maciej.
+
+ - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7726
+ REGRESSION: orbitz calendar fails (JavaScript function serialization/parsing)
+
+ * kjs/object.h: Take function name, as well as source URL and line number, when
+ using the special overloaded construct for making functions.
+ * kjs/object.cpp: (KJS::JSObject::construct): Ditto.
+ * kjs/function_object.h: Ditto.
+ * kjs/function_object.cpp: (FunctionObjectImp::construct): Pass a name when
+ constructing the function rather than null. Use "anonymous" when making a
+ function using the default function constructor.
+
+ * kjs/nodes2string.cpp: (FuncDeclNode::streamTo): Put a line break just before
+ a function declaration.
+
+ - unrelated fix
+
+ * kxmlcore/HashMapPtrSpec.h: Add missing needed friend declaration.
+
2006-03-23 Darin Adler <darin@apple.com>
Reviewed by Maciej.
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
- * Copyright (C) 2003 Apple Computer, Inc.
+ * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
}
// ECMA 15.3.2 The Function Constructor
-JSObject *FunctionObjectImp::construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber)
+JSObject* FunctionObjectImp::construct(ExecState* exec, const List& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
{
UString p("");
UString body;
scopeChain.push(exec->dynamicInterpreter()->globalObject());
FunctionBodyNode *bodyNode = progNode.get();
- FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode, scopeChain);
+ FunctionImp* fimp = new DeclaredFunctionImp(exec, functionName, bodyNode, scopeChain);
// parse parameter list. throw syntax error on illegal identifiers
int len = p.size();
}
// ECMA 15.3.2 The Function Constructor
-JSObject *FunctionObjectImp::construct(ExecState *exec, const List &args)
+JSObject* FunctionObjectImp::construct(ExecState* exec, const List& args)
{
- return FunctionObjectImp::construct(exec, args, UString(), 0);
+ return construct(exec, args, "anonymous", UString(), 0);
}
// ECMA 15.3.1 The Function Constructor Called as a Function
-JSValue *FunctionObjectImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, const List &args)
+JSValue* FunctionObjectImp::callAsFunction(ExecState* exec, JSObject* /*thisObj*/, const List &args)
{
- return construct(exec,args);
+ return construct(exec, args);
}
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*/
class FunctionObjectImp : public InternalFunctionImp {
public:
- FunctionObjectImp(ExecState *exec, FunctionPrototype *funcProto);
+ FunctionObjectImp(ExecState*, FunctionPrototype*);
virtual ~FunctionObjectImp();
virtual bool implementsConstruct() const;
- virtual JSObject *construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber);
- virtual JSObject *construct(ExecState *exec, const List &args);
- virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
+ virtual JSObject* construct(ExecState*, const List& args);
+ virtual JSObject* construct(ExecState*, const List& args, const Identifier& functionName, const UString& sourceURL, int lineNumber);
+ virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
};
} // namespace
void FuncDeclNode::streamTo(SourceStream &s) const
{
- s << "function " << ident << "(" << param << ")" << body;
+ s << SourceStream::Endl << "function " << ident << "(" << param << ")" << body;
}
void FuncExprNode::streamTo(SourceStream &s) const
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003 Apple Computer, Inc.
+ * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
return false;
}
-JSObject *JSObject::construct(ExecState */*exec*/, const List &/*args*/)
+JSObject* JSObject::construct(ExecState*, const List& /*args*/)
{
assert(false);
return NULL;
}
-JSObject *JSObject::construct(ExecState *exec, const List &args, const UString &/*sourceURL*/, int /*lineNumber*/)
+JSObject* JSObject::construct(ExecState* exec, const List& args, const Identifier& /*functionName*/, const UString& /*sourceURL*/, int /*lineNumber*/)
{
return construct(exec, args);
}
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003 Apple Computer, Inc.
+ * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
/**
* Implementation of the [[Construct]] internal property
*/
- virtual JSObject *construct(ExecState *exec, const List &args);
- virtual JSObject *construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber);
+ virtual JSObject* construct(ExecState* exec, const List& args);
+ virtual JSObject* construct(ExecState* exec, const List& args, const Identifier& functionName, const UString& sourceURL, int lineNumber);
/**
* Whether or not the object implements the call() method. If this returns
{
};
+ template<typename P, typename Mapped> class PtrHashConstIteratorAdapter;
+
template<typename P, typename Mapped>
class PtrHashIteratorAdapter {
private:
typedef ValueType *PointerType;
friend class HashMap<P *, Mapped, PtrHash<P *>, HashTraits<P *>, HashTraits<Mapped> >;
+ friend class PtrHashConstIteratorAdapter<P, Mapped>;
public:
PtrHashIteratorAdapter() {}
+2006-03-23 Darin Adler <darin@apple.com>
+
+ - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=7726
+ REGRESSION: orbitz calendar fails (JavaScript function serialization/parsing)
+
+ * fast/js/resources/function-names.js: Added.
+ * fast/js/function-names.html: Generated.
+ * fast/js/function-names-expected.txt: Generated.
+
2006-03-23 Tim Omernick <timo@apple.com>
Reviewed by Darin.
--- /dev/null
+This test checks the names of functions constructed two different ways.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new Function('1').toString().replace(/[ \n]+/g, ' ') is 'function anonymous() { 1; }'
+PASS document.documentElement.onclick.toString().replace(/[ \n]+/g, ' ') is 'function onclick(event) { 2; }'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/function-names.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
--- /dev/null
+description(
+"This test checks the names of functions constructed two different ways."
+);
+
+document.documentElement.setAttribute("onclick", "2");
+
+shouldBe("new Function('1').toString().replace(/[ \\n]+/g, ' ')", "'function anonymous() { 1; }'");
+shouldBe("document.documentElement.onclick.toString().replace(/[ \\n]+/g, ' ')", "'function onclick(event) { 2; }'");
+
+var successfullyParsed = true;
+2006-03-23 Darin Adler <darin@apple.com>
+
+ Reviewed by Maciej.
+
+ - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7726
+ REGRESSION: orbitz calendar fails (JavaScript function serialization/parsing)
+
+ Test: fast/js/function-names.html
+
+ * dom/Document.h: Add function name parameter to createHTMLEventListener.
+ * dom/Document.cpp:
+ (WebCore::Document::createHTMLEventListener): Pass function name when calling
+ createHTMLEventHandler.
+ (WebCore::Document::setHTMLWindowEventListener): Pass attribute name as function name
+ when calling createHTMLEventListener.
+
+ * html/HTMLElement.cpp: (WebCore::HTMLElement::setHTMLEventListener): Pass attribute
+ name as function name when calling createHTMLEventListener.
+
+ * khtml/ecma/kjs_events.h: Add a function name parameter to JSLazyEventListener.
+ * khtml/ecma/kjs_events.cpp:
+ (KJS::JSLazyEventListener::JSLazyEventListener): Take and store a function name.
+ (KJS::JSLazyEventListener::parseCode): Pass function name when constructing the function.
+
+ * khtml/ecma/kjs_proxy.h: Add a function name parameter to createHTMLEventHandler and
+ createSVGEventHandler.
+ * khtml/ecma/kjs_proxy.cpp:
+ (WebCore::KJSProxy::createHTMLEventHandler): Pass function name when creating
+ a JSLazyEventListener.
+ (WebCore::KJSProxy::createSVGEventHandler): Ditto.
+
+ * ksvg2/events/JSSVGLazyEventListener.h: Add a function name parameter to
+ JSSVGLazyEventListener.
+ * ksvg2/events/JSSVGLazyEventListener.cpp:
+ (WebCore::JSSVGLazyEventListener::JSSVGLazyEventListener): Pass the function name
+ on to the base class constructor.
+
+ * ksvg2/misc/SVGDocumentExtensions.h: Add function name parameter to createSVGEventListener.
+ * ksvg2/misc/SVGDocumentExtensions.cpp:
+ (WebCore::SVGDocumentExtensions::createSVGEventListener): Pass function name when
+ calling createSVGEventHandler.
+
+ * ksvg2/svg/SVGElement.cpp: (WebCore::SVGElement::addSVGEventListener):
+ * ksvg2/svg/SVGSVGElement.cpp: (WebCore::SVGSVGElement::addSVGWindowEventListner):
+ Pass attribute name as function name when calling createSVGEventListener.
+
+ * WebCore.xcodeproj/project.pbxproj: Moved generation script to the top.
+
2006-03-23 Tim Omernick <timo@apple.com>
Reviewed by Darin.
isa = PBXGroup;
children = (
65C97AF208EA908800ACD273 /* config.h */,
+ 651B2B6209D12891008808C6 /* generate-derived-sources */,
F58EF58E02DFDFB7018635CA /* WebCore.exp */,
BC1A3790097C6F970019F3D8 /* bindings */,
65BF021F097480EF00C43196 /* bridge */,
F523D2F302DE443B018635CA /* rendering */,
A8C0F6DC089701F100BA5114 /* WebCore+SVG */,
E1F0424309839389006694EA /* xml */,
- 651B2B6209D12891008808C6 /* generate-derived-sources */,
656580EC09D12B20000E61D7 /* Derived Sources */,
089C1665FE841158C02AAC07 /* Resources */,
0867D69AFE84028FC02AAC07 /* Frameworks */,
return false;
}
-PassRefPtr<EventListener> Document::createHTMLEventListener(const String& code, Node *node)
+PassRefPtr<EventListener> Document::createHTMLEventListener(const String& functionName, const String& code, Node *node)
{
- if (Frame *frm = frame()) {
- if (KJSProxy *proxy = frm->jScript())
- return proxy->createHTMLEventHandler(code, node);
- }
+ if (Frame* frm = frame())
+ if (KJSProxy* proxy = frm->jScript())
+ return proxy->createHTMLEventHandler(functionName, code, node);
return 0;
}
void Document::setHTMLWindowEventListener(const AtomicString& eventType, Attribute* attr)
{
- setHTMLWindowEventListener(eventType, createHTMLEventListener(attr->value(), 0));
+ setHTMLWindowEventListener(eventType,
+ createHTMLEventListener(attr->localName().domString(), attr->value(), 0));
}
void Document::dispatchImageLoadEventSoon(HTMLImageLoader *image)
void removeWindowEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
bool hasWindowEventListener(const AtomicString& eventType);
- PassRefPtr<EventListener> createHTMLEventListener(const String& code, Node*);
+ PassRefPtr<EventListener> createHTMLEventListener(const String& functionName, const String& code, Node*);
/**
* Searches through the document, starting from fromNode, for the next selectable element that comes after fromNode.
void HTMLElement::setHTMLEventListener(const AtomicString& eventType, Attribute* attr)
{
- Element::setHTMLEventListener(eventType, getDocument()->createHTMLEventListener(attr->value(), this));
+ Element::setHTMLEventListener(eventType,
+ getDocument()->createHTMLEventListener(attr->localName().domString(), attr->value(), this));
}
}
// -------------------------------------------------------------------------
-JSLazyEventListener::JSLazyEventListener(const String& _code, Window* _win, Node* _originalNode, int lineno)
- : JSEventListener(0, _win, true),
- code(_code),
- parsed(false)
-{
- lineNumber = lineno;
-
- // We don't retain the original node, because we assume it
+JSLazyEventListener::JSLazyEventListener(const String& functionName, const String& code, Window* win, Node* node, int lineno)
+ : JSEventListener(0, win, true)
+ , m_functionName(functionName)
+ , code(code)
+ , parsed(false)
+ , lineNumber(lineno)
+ , originalNode(node)
+{
+ // We don't retain the original node because we assume it
// will stay alive as long as this handler object is around
// and we need to avoid a reference cycle. If JS transfers
// this handler to another node, parseCode will be called and
// then originalNode is no longer needed.
-
- originalNode = _originalNode;
}
JSObject* JSLazyEventListener::listenerObj() const
UString sourceURL(frame->url().url());
args.append(eventParameterName());
args.append(jsString(code));
- listener = constr->construct(exec, args, sourceURL, lineNumber); // ### is globalExec ok ?
+ listener = constr->construct(exec, args, m_functionName, sourceURL, lineNumber); // ### is globalExec ok ?
if (exec->hadException()) {
exec->clearException();
}
// no more need to keep the unparsed code around
+ m_functionName = String();
code = String();
if (listener)
class JSLazyEventListener : public JSEventListener {
public:
- JSLazyEventListener(const WebCore::String& code, Window*, WebCore::Node*, int lineno = 0);
- virtual JSObject *listenerObj() const;
+ JSLazyEventListener(const WebCore::String& functionName, const WebCore::String& code, Window*, WebCore::Node*, int lineno = 0);
+ virtual JSObject* listenerObj() const;
private:
- virtual JSValue *eventParameterName() const;
+ virtual JSValue* eventParameterName() const;
void parseCode() const;
+ mutable WebCore::String m_functionName;
mutable WebCore::String code;
mutable bool parsed;
int lineNumber;
}
}
-EventListener *KJSProxy::createHTMLEventHandler(const String& code, Node *node)
+EventListener* KJSProxy::createHTMLEventHandler(const String& functionName, const String& code, Node *node)
{
initScriptIfNeeded();
JSLock lock;
- return new JSLazyEventListener(code, Window::retrieveWindow(m_frame), node, m_handlerLineno);
+ return new JSLazyEventListener(functionName, code, Window::retrieveWindow(m_frame), node, m_handlerLineno);
}
#if SVG_SUPPORT
-EventListener *KJSProxy::createSVGEventHandler(const String& code, Node *node)
+EventListener* KJSProxy::createSVGEventHandler(const String& functionName, const String& code, Node *node)
{
initScriptIfNeeded();
JSLock lock;
- return new JSSVGLazyEventListener(code, Window::retrieveWindow(m_frame), node, m_handlerLineno);
+ return new JSSVGLazyEventListener(functionName, code, Window::retrieveWindow(m_frame), node, m_handlerLineno);
}
#endif
~KJSProxy();
KJS::JSValue* evaluate(const String& filename, int baseLine, const String& code, Node*);
void clear();
- EventListener* createHTMLEventHandler(const String& code, Node*);
+ EventListener* createHTMLEventHandler(const String& functionName, const String& code, Node*);
#if SVG_SUPPORT
- EventListener* createSVGEventHandler(const String& code, Node*);
+ EventListener* createSVGEventHandler(const String& functionName, const String& code, Node*);
#endif
void finishedWithEvent(Event*);
KJS::ScriptInterpreter *interpreter();
namespace WebCore {
-JSSVGLazyEventListener::JSSVGLazyEventListener(const String& code, KJS::Window* win, Node* node, int lineno)
- : JSLazyEventListener(code, win, node, lineno)
+JSSVGLazyEventListener::JSSVGLazyEventListener(const String& functionName, const String& code, KJS::Window* win, Node* node, int lineno)
+ : JSLazyEventListener(functionName, code, win, node, lineno)
{
}
class JSSVGLazyEventListener : public KJS::JSLazyEventListener {
public:
- JSSVGLazyEventListener(const String& code, KJS::Window*, Node*, int lineno = 0);
+ JSSVGLazyEventListener(const String& functionName, const String& code, KJS::Window*, Node*, int lineno = 0);
private:
- virtual KJS::JSValue *eventParameterName() const;
+ virtual KJS::JSValue* eventParameterName() const;
};
+
}
#endif // SVG_SUPPORT
delete m_timeScheduler;
}
-PassRefPtr<EventListener> SVGDocumentExtensions::createSVGEventListener(const String& code, Node *node)
+PassRefPtr<EventListener> SVGDocumentExtensions::createSVGEventListener(const String& functionName, const String& code, Node *node)
{
- if (Frame *frame = m_doc->frame()) {
- if (KJSProxy *proxy = frame->jScript())
- return proxy->createSVGEventHandler(code, node);
- }
+ if (Frame* frame = m_doc->frame())
+ if (KJSProxy* proxy = frame->jScript())
+ return proxy->createSVGEventHandler(functionName, code, node);
return 0;
}
namespace WebCore {
-class TimeScheduler;
class Document;
class EventListener;
-class String;
class Node;
+class String;
+class TimeScheduler;
class SVGDocumentExtensions {
public:
SVGDocumentExtensions(Document*);
~SVGDocumentExtensions();
- PassRefPtr<EventListener> createSVGEventListener(const String& code, Node*);
+ PassRefPtr<EventListener> createSVGEventListener(const String& functionName, const String& code, Node*);
TimeScheduler* timeScheduler() const { return m_timeScheduler; }
void SVGElement::addSVGEventListener(const AtomicString& eventType, const Attribute* attr)
{
- Element::setHTMLEventListener(eventType, getDocument()->accessSVGExtensions()->createSVGEventListener(attr->value(), this));
+ Element::setHTMLEventListener(eventType, getDocument()->accessSVGExtensions()->
+ createSVGEventListener(attr->localName().domString(), attr->value(), this));
}
void SVGElement::parseMappedAttribute(MappedAttribute *attr)
{
// FIXME: None of these should be window events long term.
// Once we propertly support SVGLoad, etc.
- RefPtr<EventListener> listener = getDocument()->accessSVGExtensions()->createSVGEventListener(attr->value(), this);
+ RefPtr<EventListener> listener = getDocument()->accessSVGExtensions()->
+ createSVGEventListener(attr->localName().domString(), attr->value(), this);
getDocument()->setHTMLWindowEventListener(eventType, listener.release());
}