From kde-commits Sat Aug 23 18:44:29 2008 From: Maks Orlovich Date: Sat, 23 Aug 2008 18:44:29 +0000 To: kde-commits Subject: branches/KDE/4.1/kdelibs/khtml/ecma Message-Id: <1219517069.036990.22243.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=121951751204127 SVN commit 851476 by orlovich: Make the window.frames behavior more Mozilla-like --- frames just returns the Window again, which meanthe properties of the window are available there, too. This kills the FrameArray class. Fixes #168017, and renders #164348 moot, as Window is robust against these cases while FrameArray wasn't BUG:168017 BUG:164348 M +1 -1 kjs_html.cpp M +3 -161 kjs_window.cpp M +1 -4 kjs_window.h --- branches/KDE/4.1/kdelibs/khtml/ecma/kjs_html.cpp #851475:851476 @@ -412,7 +412,7 @@ return body ? jsString(body->getAttribute(ATTR_DIR)) : jsUndefined(); case Frames: if ( win ) - return win->frames(exec); + return win; else return jsUndefined(); } --- branches/KDE/4.1/kdelibs/khtml/ecma/kjs_window.cpp #851475:851476 @@ -104,28 +104,6 @@ private: QPointer part; }; - - - class FrameArray : public JSObject { - public: - FrameArray(ExecState *exec, KHTMLPart *p) - : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()), part(p) { } - virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); - JSValue *getValueProperty(ExecState *exec, int token); - virtual UString toString(ExecState *exec) const; - enum { Length, Location }; - JSValue *indexGetter(ExecState *, unsigned index); - virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args); - virtual bool implementsCall() const { return true; } - private: - static JSValue *nameGetter(ExecState *, JSObject*, const Identifier&, const PropertySlot&); - static JSValue *nameFallBackGetter(ExecState *, JSObject*, const Identifier&, const PropertySlot&); - virtual const ClassInfo* classInfo() const { return &info; } - static const ClassInfo info; - - QPointer part; - }; - } //namespace KJS #include "kjs_window.lut.h" @@ -409,7 +387,7 @@ KJS_IMPLEMENT_PROTOFUNC(WindowFunc) Window::Window(khtml::ChildFrame *p) - : JSObject(/*no proto*/), m_frame(p), screen(0), history(0), external(0), m_frames(0), loc(0), m_evt(0) + : JSObject(/*no proto*/), m_frame(p), screen(0), history(0), external(0), loc(0), m_evt(0) { winq = new WindowQObject(this); //kDebug(6070) << "Window::Window this=" << this << " part=" << m_part << " " << m_part->name(); @@ -480,15 +458,6 @@ return loc; } -JSObject* Window::frames( ExecState* exec ) const -{ - KHTMLPart *part = qobject_cast(m_frame->m_part); - if (part) - return m_frames ? m_frames : - (const_cast(this)->m_frames = new FrameArray(exec, part)); - return 0L; -} - // reference our special objects during garbage collection void Window::mark() { @@ -499,8 +468,6 @@ history->mark(); if (external && !external->marked()) external->mark(); - if (m_frames && !m_frames->marked()) - m_frames->mark(); //kDebug(6070) << "Window::mark " << this << " marking loc=" << loc; if (loc && !loc->marked()) loc->mark(); @@ -711,7 +678,7 @@ return getDOMNode(exec, element); } -JSValue* Window::getValueProperty(ExecState *exec, int token) const +JSValue* Window::getValueProperty(ExecState *exec, int token) { KHTMLPart *part = m_frame.isNull() ? 0 : qobject_cast(m_frame->m_part); if (!part) { @@ -735,7 +702,7 @@ case Self: return retrieve(part); case Frames: - return frames(exec); + return this; case Opener: if (!part->opener()) return jsNull(); // ### a null Window might be better, but == null @@ -1453,7 +1420,6 @@ screen = 0; history = 0; external = 0; - m_frames = 0; loc = 0; setPrototype(jsNull()); @@ -2482,130 +2448,6 @@ parent->closeNow(); } -const ClassInfo FrameArray::info = { "FrameArray", 0, &FrameArrayTable, 0 }; - -/* -@begin FrameArrayTable 2 -length FrameArray::Length DontDelete|ReadOnly -location FrameArray::Location DontDelete|ReadOnly -@end -*/ - -JSValue *FrameArray::getValueProperty(ExecState *exec, int token) -{ - switch (token) { - case Length: - return jsNumber(part->frames().count()); - case Location: - // non-standard property, but works in NS and IE - if (JSObject *obj = Window::retrieveWindow(part)) - return obj->get(exec, "location"); - return jsUndefined(); - default: - assert(0); - return jsUndefined(); - } -} - -JSValue *FrameArray::indexGetter(ExecState *exec, unsigned index) -{ - KParts::ReadOnlyPart *frame = part->frames().at(index); - if (frame) - return Window::retrieve(frame); - - return jsUndefined(); -} - -JSValue *FrameArray::nameGetter(ExecState *exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) -{ - FrameArray *thisObj = static_cast(slot.slotBase()); - KParts::ReadOnlyPart *frame = thisObj->part->findFrame(propertyName.qstring()); - if (frame) - return Window::retrieve(frame); - return jsUndefined(); -} - -JSValue *FrameArray::nameFallBackGetter(ExecState *exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) -{ - FrameArray *thisObj = static_cast(slot.slotBase()); - DOM::DocumentImpl* doc = static_cast(thisObj->part->document().handle()); - if (doc) { - DOM::HTMLCollectionImpl docuAll(doc, DOM::HTMLCollectionImpl::DOC_ALL); - DOM::NodeImpl* node = docuAll.namedItem(propertyName.domString()); - if (node) { - if (node->id() == ID_FRAME || node->id() == ID_IFRAME) { - //Return the Window object. - KHTMLPart* part = static_cast(node)->contentPart(); - if (part) - return Window::retrieveWindow(part); - else - return jsUndefined(); - } else { - //Just a regular node.. - return getDOMNode(exec, node); - } - } - } else { - kWarning(6070) << "Missing own document in FrameArray::get()"; - } - return jsUndefined(); -} - -bool FrameArray::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot) -{ -#ifdef KJS_VERBOSE - kDebug(6070) << "FrameArray::getOwnPropertySlot " << propertyName.qstring() << " part=" << (void*)part; -#endif - - if (part.isNull()) { - slot.setUndefined(this); - return true; - } - - if (getStaticOwnValueSlot(&FrameArrayTable, this, propertyName, slot)) - return true; - - // check for the name or number - KParts::ReadOnlyPart *frame = part->findFrame(propertyName.qstring()); - if (frame) { - slot.setCustom(this, nameGetter); - return true; - } - - if (getIndexSlot(this, part->frames().count(), propertyName, slot)) - return true; - - // Fun IE quirk: name lookup in there is actually done by document.all - // hence, it can find non-frame things (and even let them hide frame ones!) - // We don't quite do that, but do this as a fallback. - DOM::DocumentImpl* doc = static_cast(part->document().handle()); - DOM::HTMLCollectionImpl docuAll(doc, DOM::HTMLCollectionImpl::DOC_ALL); - if (docuAll.namedItem(propertyName.domString())) { - slot.setCustom(this, nameFallBackGetter); - return true; - } - - return JSObject::getOwnPropertySlot(exec, propertyName, slot); -} - -UString FrameArray::toString(ExecState *) const -{ - return "[object FrameArray]"; -} - -JSValue* FrameArray::callAsFunction(ExecState *exec, JSObject * /*thisObj*/, const List &args) -{ - //IE supports a subset of the get functionality as call... - //... basically, when the return is a window, it supports that, otherwise it - //errors out. We do a cheap-and-easy emulation of that, and just do the same - //thing as get does. - if (args.size() == 1) - return get(exec, Identifier(args[0]->toString(exec))); - - return jsUndefined(); -} - - ////////////////////// Location Object //////////////////////// const ClassInfo Location::info = { "Location", 0, &LocationTable, 0 }; --- branches/KDE/4.1/kdelibs/khtml/ecma/kjs_window.h #851475:851476 @@ -56,7 +56,6 @@ class History; class External; class ScheduledAction; - class FrameArray; class JSEventListener; class JSLazyEventListener; @@ -105,7 +104,7 @@ } virtual void mark(); - JSValue* getValueProperty(ExecState *exec, int token) const; + JSValue* getValueProperty(ExecState *exec, int token); virtual bool getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot); virtual void put(ExecState *exec, const Identifier &propertyName, JSValue* value, int attr = None); virtual bool toBoolean(ExecState *exec) const; @@ -125,7 +124,6 @@ return checkIsSafeScript( activePart ); } Location *location() const; - JSObject* frames( ExecState* exec ) const; JSEventListener *getJSEventListener(JSValue* val, bool html = false); JSLazyEventListener *getJSLazyEventListener(const QString &code, const QString& sourceUrl, int lineNo, const QString &name, DOM::NodeImpl* node); @@ -198,7 +196,6 @@ Screen *screen; History *history; External *external; - FrameArray *m_frames; Location *loc; DOM::EventImpl *m_evt;