Example #1
0
Value DOMStyleSheetList::tryGet(ExecState *exec, const Identifier &p) const
{
#ifdef KJS_VERBOSE
    kdDebug(6070) << "DOMStyleSheetList::tryGet " << p.qstring() << endl;
#endif
    if(p == lengthPropertyName)
        return Number(styleSheetList.length());
    else if(p == "item")
        return lookupOrCreateFunction< DOMStyleSheetListFunc >(exec, p, this, DOMStyleSheetList::Item, 1, DontDelete | Function);

    // Retrieve stylesheet by index
    bool ok;
    long unsigned int u = p.toULong(&ok);
    if(ok)
        return getDOMStyleSheet(exec, DOM::StyleSheetList(styleSheetList).item(u));

// IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag
// (this is consistent with all the other collections)
#if 0
  // Bad implementation because DOM::StyleSheet doesn't inherit DOM::Node
  // so we can't use DOMNamedNodesCollection.....
  // We could duplicate it for stylesheets though - worth it ?
  // Other problem of this implementation: it doesn't look for the ID attribute!
  DOM::NameNodeListImpl namedList( m_doc.documentElement().handle(), p.string() );
  int len = namedList.length();
  if ( len ) {
    QValueList<DOM::Node> styleSheets;
    for ( int i = 0 ; i < len ; ++i ) {
      DOM::HTMLStyleElement elem = DOM::Node(namedList.item(i));
      if (!elem.isNull())
        styleSheets.append(elem.sheet());
    }
    if ( styleSheets.count() == 1 ) // single result
      return getDOMStyleSheet(exec, styleSheets[0]);
    else if ( styleSheets.count() > 1 ) {
      return new DOMNamedItemsCollection(exec,styleSheets);
    }
  }
#endif
    // ### Bad implementation because returns a single element (are IDs always unique?)
    // and doesn't look for name attribute (see implementation above).
    // But unicity of stylesheet ids is good practice anyway ;)
    DOM::DOMString pstr = p.string();
    DOM::HTMLStyleElement styleElem = m_doc.getElementById(pstr);
    if(!styleElem.isNull())
        return getDOMStyleSheet(exec, styleElem.sheet());

    return DOMObject::tryGet(exec, p);
}
Example #2
0
void VM::registerWatchpointForImpureProperty(const Identifier& propertyName, Watchpoint* watchpoint)
{
    auto result = m_impurePropertyWatchpointSets.add(propertyName.string(), nullptr);
    if (result.isNewEntry)
        result.iterator->value = adoptRef(new WatchpointSet(IsWatched));
    result.iterator->value->add(watchpoint);
}
void JSDollarVMPrototype::addFunction(VM& vm, JSGlobalObject* globalObject, const char* name, NativeFunction function, unsigned arguments)
{
    Identifier identifier = Identifier::fromString(&vm, name);
    putDirect(vm, identifier, JSFunction::create(vm, globalObject, arguments, identifier.string(), function));
}