source: webkit/trunk/JavaScriptCore/kjs/IndexToNameMap.cpp@ 36100

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

JavaScriptCore:

2008-07-16 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.


First step toward putting doubles in registers: Turned Register into a
proper abstraction layer. It is no longer possible to cast a Register
to a JSValue*, or a Register& to a JSValue*&, or to access the union
inside a Register directly.


SunSpider reports no change.


In support of this change, I had to make the following mechanical changes
in a lot of places:


  1. Clients now use explicit accessors to read data out of Registers, and implicit copy constructors to write data into registers.


So, assignment that used to look like


x.u.jsValue = y;


now looks like


x = y;


And access that used to look like


x = y.u.jsValue;


now looks like


x = y.jsValue();

  1. I made generic flow control specific in opcodes that made their flow control generic by treating a Register& as a JSValue*&. This had the added benefit of removing some exception checking branches from immediate number code.
  1. I beefed up PropertySlot to support storing a Register* in a property slot. For now, only JSVariableObject's symbolTableGet and symbolTablePut use this functionality, but I expect more clients to use it in the future.


  1. I changed ArgList to be a buffer of Registers, not JSValue*'s, and I changed ArgList iterator clients to iterate Registers, not JSValue*'s.

WebCore:

2008-07-16 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.

Support for JavaScriptCore's first step toward putting doubles in
registers: Treat ArgList iterators as Register*'s, not JSValue*'s.

  • bindings/js/ScheduledAction.cpp: (WebCore::ScheduledAction::ScheduledAction):
  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1/*
2 * Copyright (C) 1999-2002 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Cameron Zwarich ([email protected])
6 * Copyright (C) 2007 Maks Orlovich
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "config.h"
26#include "IndexToNameMap.h"
27
28#include "ArgList.h"
29#include "JSFunction.h"
30#include "identifier.h"
31
32namespace KJS {
33
34// We map indexes in the arguments array to their corresponding argument names.
35// Example: function f(x, y, z): arguments[0] = x, so we map 0 to Identifier("x").
36
37// Once we have an argument name, we can get and set the argument's value in the
38// activation object.
39
40// We use Identifier::null to indicate that a given argument's value
41// isn't stored in the activation object.
42
43IndexToNameMap::IndexToNameMap(JSFunction* func, const ArgList& args)
44 : m_size(args.size())
45 , m_map(new Identifier[args.size()])
46{
47 size_t size = args.size();
48 for (size_t i = 0; i < size; ++i)
49 m_map[i] = func->getParameterName(i); // null if there is no corresponding parameter
50}
51
52IndexToNameMap::~IndexToNameMap()
53{
54 delete [] m_map;
55}
56
57bool IndexToNameMap::isMapped(const Identifier& index) const
58{
59 bool indexIsNumber;
60 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber);
61
62 if (!indexIsNumber)
63 return false;
64
65 if (indexAsNumber >= m_size)
66 return false;
67
68 if (m_map[indexAsNumber].isNull())
69 return false;
70
71 return true;
72}
73
74void IndexToNameMap::unMap(ExecState* exec, const Identifier& index)
75{
76 bool indexIsNumber;
77 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber);
78
79 ASSERT(indexIsNumber && indexAsNumber < m_size);
80
81 m_map[indexAsNumber] = exec->propertyNames().nullIdentifier;
82}
83
84Identifier& IndexToNameMap::operator[](const Identifier& index)
85{
86 bool indexIsNumber;
87 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber);
88
89 ASSERT(indexIsNumber && indexAsNumber < m_size);
90
91 return m_map[indexAsNumber];
92}
93
94} // namespace KJS
Note: See TracBrowser for help on using the repository browser.