source: webkit/trunk/JavaScriptCore/kjs/identifier.h@ 34424

Last change on this file since 34424 was 34412, checked in by [email protected], 17 years ago

Reviewed by Darin.

Combine per-thread objects into one, to make it easier to support legacy clients (for
which they shouldn't be really per-thread).

No change on SunSpider total.

  • kjs/JSGlobalData.cpp: Added. (KJS::JSGlobalData::JSGlobalData): (KJS::JSGlobalData::~JSGlobalData): (KJS::JSGlobalData::threadInstance):
  • kjs/JSGlobalData.h: Added. This class encapsulates all data that should be per-thread (or shared between legacy clients). It will also keep a Heap pointer, but right now, Heap (Collector) methods are all static.
  • kjs/identifier.h: (KJS::Identifier::Identifier): Added a constructor explicitly taking JSGlobalData to access IdentifierTable. Actually, all of them should, but this will be a separate patch.
  • kjs/identifier.cpp: (KJS::IdentifierTable::literalTable): (KJS::createIdentifierTable): (KJS::deleteIdentifierTable): (KJS::Identifier::add): (KJS::Identifier::addSlowCase): Combined IdentifierTable and LiteralIdentifierTable into a single class for simplicity.
  • kjs/grammar.y: kjsyyparse now takes JSGlobalData, not just a Lexer.
  • kjs/nodes.cpp: (KJS::Node::Node): (KJS::EvalFunctionCallNode::emitCode): (KJS::ScopeNode::ScopeNode): Changed to access Lexer and Parser via JSGlobalData::threadInstance(). This is also a temporary measure, they will need to use JSGlobalData explicitly.
  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::CodeGenerator):
  • VM/CodeGenerator.h:
  • VM/Machine.cpp: (KJS::callEval):
  • kjs/CommonIdentifiers.cpp: (KJS::CommonIdentifiers::CommonIdentifiers):
  • kjs/CommonIdentifiers.h:
  • kjs/DebuggerCallFrame.cpp: (KJS::DebuggerCallFrame::evaluate):
  • kjs/ExecState.cpp: (KJS::ExecState::ExecState):
  • kjs/ExecState.h: (KJS::ExecState::globalData): (KJS::ExecState::identifierTable): (KJS::ExecState::propertyNames): (KJS::ExecState::emptyList): (KJS::ExecState::lexer): (KJS::ExecState::parser): (KJS::ExecState::arrayTable): (KJS::ExecState::dateTable): (KJS::ExecState::mathTable): (KJS::ExecState::numberTable): (KJS::ExecState::RegExpImpTable): (KJS::ExecState::RegExpObjectImpTable): (KJS::ExecState::stringTable):
  • kjs/InitializeThreading.cpp: (KJS::initializeThreadingOnce):
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::init):
  • kjs/JSGlobalObject.h: (KJS::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData): (KJS::JSGlobalObject::head): (KJS::JSGlobalObject::globalData):
  • kjs/Parser.cpp: (KJS::Parser::parse):
  • kjs/Parser.h:
  • kjs/function.cpp: (KJS::FunctionImp::getParameterName): (KJS::IndexToNameMap::unMap): (KJS::globalFuncEval):
  • kjs/function_object.cpp: (KJS::FunctionObjectImp::construct):
  • kjs/interpreter.cpp: (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate):
  • kjs/lexer.cpp: (kjsyylex):
  • kjs/lexer.h:
  • kjs/testkjs.cpp: (prettyPrintScript): Updated for the above changes. Most of threadInstance uses here will need to be replaced with explicitly passed pointers to support legacy JSC clients.
  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/*
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef KJS_IDENTIFIER_H
22#define KJS_IDENTIFIER_H
23
24#include "JSGlobalData.h"
25#include "ustring.h"
26
27namespace KJS {
28
29 class Identifier {
30 friend class PropertyMap;
31 public:
32 Identifier() { }
33 Identifier(const char* s) : _ustring(add(s)) { } // Only to be used with string literals.
34 Identifier(const UChar* s, int length) : _ustring(add(s, length)) { }
35 explicit Identifier(UString::Rep* rep) : _ustring(add(rep)) { }
36 explicit Identifier(const UString& s) : _ustring(add(s.rep())) { }
37
38 Identifier(JSGlobalData* globalData, const char* s) : _ustring(add(globalData, s)) { } // Only to be used with string literals.
39
40 // Special constructor for cases where we overwrite an object in place.
41 Identifier(PlacementNewAdoptType) : _ustring(PlacementNewAdopt) { }
42
43 const UString& ustring() const { return _ustring; }
44 DOM::DOMString domString() const;
45
46 const UChar* data() const { return _ustring.data(); }
47 int size() const { return _ustring.size(); }
48
49 const char* ascii() const { return _ustring.ascii(); }
50
51 static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
52
53 bool isNull() const { return _ustring.isNull(); }
54 bool isEmpty() const { return _ustring.isEmpty(); }
55
56 uint32_t toUInt32(bool* ok) const { return _ustring.toUInt32(ok); }
57 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return _ustring.toUInt32(ok, tolerateEmptyString); };
58 uint32_t toStrictUInt32(bool* ok) const { return _ustring.toStrictUInt32(ok); }
59 unsigned toArrayIndex(bool* ok) const { return _ustring.toArrayIndex(ok); }
60 double toDouble() const { return _ustring.toDouble(); }
61
62 friend bool operator==(const Identifier&, const Identifier&);
63 friend bool operator!=(const Identifier&, const Identifier&);
64
65 friend bool operator==(const Identifier&, const char*);
66
67 static void remove(UString::Rep*);
68
69 static bool equal(const UString::Rep*, const char*);
70 static bool equal(const UString::Rep*, const UChar*, int length);
71 static bool equal(const UString::Rep* a, const UString::Rep* b) { return KJS::equal(a, b); }
72
73 static PassRefPtr<UString::Rep> add(const char*);
74
75 static void initializeIdentifierThreading();
76
77 private:
78 UString _ustring;
79
80 static bool equal(const Identifier& a, const Identifier& b)
81 { return a._ustring.rep() == b._ustring.rep(); }
82 static bool equal(const Identifier& a, const char* b)
83 { return equal(a._ustring.rep(), b); }
84
85 static PassRefPtr<UString::Rep> add(JSGlobalData*, const char*);
86 static PassRefPtr<UString::Rep> add(const UChar*, int length);
87 static PassRefPtr<UString::Rep> add(UString::Rep* r)
88 {
89 if (r->identifierTable)
90 return r;
91 return addSlowCase(r);
92 }
93 static PassRefPtr<UString::Rep> addSlowCase(UString::Rep *r);
94 };
95
96 inline bool operator==(const Identifier& a, const Identifier& b)
97 { return Identifier::equal(a, b); }
98
99 inline bool operator!=(const Identifier& a, const Identifier& b)
100 { return !Identifier::equal(a, b); }
101
102 inline bool operator==(const Identifier& a, const char* b)
103 { return Identifier::equal(a, b); }
104
105 IdentifierTable* createIdentifierTable();
106 void deleteIdentifierTable(IdentifierTable*);
107
108} // namespace KJS
109
110#endif // KJS_IDENTIFIER_H
Note: See TracBrowser for help on using the repository browser.