source: webkit/trunk/JavaScriptCore/kjs/lookup.cpp@ 14094

Last change on this file since 14094 was 14094, checked in by ggaren, 19 years ago

JavaScriptCore:

Reviewed by Maciej

  • Minor fixups I discovered while working on the autogenerator.


  • kjs/lookup.cpp: (findEntry): ASSERT that size is not 0, because otherwise we'll % by 0, compute a garbage address, and possibly crash.
  • kjs/lookup.h: (cacheGlobalObject): Don't enumerate cached objects -- ideally, they would be hidden entirely.

LayoutTests:

  • Updated to remove diff shmutz:
  • fast/dom/Window/window-special-properties-expected.txt:
  • fast/dom/Window/window-special-properties.html:
  • Test for global window properties like window.HTMLDocument:


  • fast/dom/global-constructors-expected.txt: Added.
  • fast/dom/global-constructors.html: Added.

WebCore:

Reviewed by Maciej.

  • Added global constructor autogeneration for the following, many of which are required by *.live.com: Node, Element, Range, CSSRule, CSSValue, CSSPrimitiveValue, CSSStyleDeclaration, Event, MutationEvent, NodeFilter

It works like so:


  • The autogenerator knows about the "Constructor" data type, which gets special treatment because it exists purely in the bindings. It also knows about the "GenerateConstructor" interface attribute, which does just that.
  • The window interface has many Constructor attributes
  • The hash table generator swizzles empty tables to tables with one empty bucket, to prevent crashes in Lookup::findEntry. (The old generator used to work this way, too.)
  • Window object property lookup gets special treatment to allow shadowing of its built-in global constructor properties. We'll need to expand this mechanism in the future and make it more flexible, but it works for now.


  • DerivedSources.make:
  • WebCore.vcproj/WebCore/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/kjs_css.cpp: (KJS::toJS):
  • bindings/js/kjs_css.h:
  • bindings/js/kjs_window.cpp: Removed 'namedFrameGetter' and its use because they were bogus; added FIXME describing what they were attempting to do. (KJS::Window::getValueProperty): (KJS::Window::getOverridePropertySlot): (KJS::Window::getOwnPropertySlot):
  • bindings/js/kjs_window.h: (KJS::Window::):
  • bindings/scripts/CodeGeneratorJS.pm:
  • css/CSSPrimitiveValue.idl:
  • css/CSSRule.idl:
  • css/CSSStyleDeclaration.idl: Added.
  • css/CSSValue.idl:
  • dom/Document.idl:
  • dom/Element.idl:
  • dom/Event.idl:
  • dom/MutationEvent.idl:
  • dom/Node.idl:
  • dom/NodeFilter.idl:
  • dom/Range.idl:
  • page/DOMWindow.idl:
  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
5 * Copyright (C) 2003 Apple Computer, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23#include "config.h"
24#include <stdio.h>
25#include <string.h>
26
27#include "lookup.h"
28#include <kxmlcore/Assertions.h>
29
30using namespace KJS;
31
32static inline bool keysMatch(const UChar *c, unsigned len, const char *s)
33{
34 const char* end = s + len;
35 for (; s != end; c++, s++)
36 if (c->uc != (unsigned char)*s)
37 return false;
38 return *s == 0;
39}
40
41static inline const HashEntry* findEntry(const struct HashTable *table, unsigned int hash,
42 const UChar *c, unsigned int len )
43{
44#ifndef NDEBUG
45 if (table->type != 2) {
46 fprintf(stderr, "KJS: Unknown hash table version.\n");
47 return 0;
48 }
49#endif
50 ASSERT(table->hashSize != 0);
51
52 hash %= table->hashSize;
53
54 const HashEntry *e = &table->entries[hash];
55
56 // empty bucket ?
57 if (!e->s)
58 return 0;
59
60 do {
61 // compare strings
62 if (keysMatch(c, len, e->s))
63 return e;
64
65 // try next bucket
66 e = e->next;
67 } while (e);
68 return 0;
69}
70
71const HashEntry* Lookup::findEntry(const struct HashTable *table,
72 const Identifier &s )
73{
74 const HashEntry* entry = ::findEntry(table, s.ustring().rep()->hash(), s.data(), s.size());
75 return entry;
76}
77
78int Lookup::find(const struct HashTable *table,
79 const UChar *c, unsigned int len)
80{
81 const HashEntry *entry = ::findEntry(table, UString::Rep::computeHash(c, len), c, len);
82 if (entry)
83 return entry->value;
84 return -1;
85}
86
87int Lookup::find(const struct HashTable *table, const Identifier &s)
88{
89 //printf("looking for:%s\n", s.ascii());
90 const HashEntry *entry = ::findEntry(table, s.ustring().rep()->hash(), s.data(), s.size());
91 if (entry)
92 return entry->value;
93 return -1;
94}
Note: See TracBrowser for help on using the repository browser.