source: webkit/trunk/JavaScriptCore/kjs/function.h@ 15526

Last change on this file since 15526 was 15526, checked in by andersca, 19 years ago

JavaScriptCore:

2006-07-19 Anders Carlsson <[email protected]>

Reviewed by Darin.

<rdar://problem/4620655> REGRESSION(10.4.7-10.5): preview button for a blogger.com post doesn't work


  • kjs/nodes2string.cpp: (StringNode::streamTo): Return the escaped string.


(RegExpNode::streamTo):
Use the correct syntax.


  • kjs/function.cpp: (KJS::escapeStringForPrettyPrinting):
  • kjs/function.h: Add escape function which escapes a string for pretty-printing so it can be parsed again.


  • wtf/unicode/icu/UnicodeIcu.h: (WTF::Unicode::isPrintableChar): New function.

LayoutTests:

2006-07-19 Anders Carlsson <[email protected]>

Reviewed by Darin.

<rdar://problem/4620655> REGRESSION(10.4.7-10.5): preview button for a blogger.com post doesn't work


  • fast/js/pretty-print-expected.txt: Added.
  • fast/js/pretty-print.html: Added.
  • fast/js/resources/pretty-print.js: Added.
  • Property svn:eol-style set to native
File size: 5.7 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, 2006 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 Library 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 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef KJS_FUNCTION_H
25#define KJS_FUNCTION_H
26
27#include "internal.h"
28#include <wtf/OwnPtr.h>
29
30namespace KJS {
31
32 class ActivationImp;
33 class FunctionBodyNode;
34 class Parameter;
35
36 /**
37 * @short Implementation class for internal Functions.
38 */
39 class FunctionImp : public InternalFunctionImp {
40 friend class ActivationImp;
41 public:
42 FunctionImp(ExecState* exec, const Identifier& n, FunctionBodyNode* b);
43 virtual ~FunctionImp();
44
45 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&);
46 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
47 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
48
49 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
50
51 void addParameter(const Identifier &n);
52 Identifier getParameterName(int index);
53 // parameters in string representation, e.g. (a, b, c)
54 UString parameterString() const;
55 virtual CodeType codeType() const = 0;
56
57 virtual Completion execute(ExecState *exec) = 0;
58
59 virtual const ClassInfo *classInfo() const { return &info; }
60 static const ClassInfo info;
61
62 RefPtr<FunctionBodyNode> body;
63
64 protected:
65 OwnPtr<Parameter> param;
66
67 private:
68 static JSValue *argumentsGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot&);
69 static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot&);
70
71 void processParameters(ExecState *exec, const List &);
72 virtual void processVarDecls(ExecState *exec);
73 };
74
75 class DeclaredFunctionImp : public FunctionImp {
76 public:
77 DeclaredFunctionImp(ExecState *exec, const Identifier &n,
78 FunctionBodyNode *b, const ScopeChain &sc);
79
80 bool implementsConstruct() const;
81 JSObject *construct(ExecState *exec, const List &args);
82
83 virtual Completion execute(ExecState *exec);
84 CodeType codeType() const { return FunctionCode; }
85
86 virtual const ClassInfo *classInfo() const { return &info; }
87 static const ClassInfo info;
88
89 private:
90 virtual void processVarDecls(ExecState *exec);
91 };
92
93 class IndexToNameMap {
94 public:
95 IndexToNameMap(FunctionImp *func, const List &args);
96 ~IndexToNameMap();
97
98 Identifier& operator[](int index);
99 Identifier& operator[](const Identifier &indexIdentifier);
100 bool isMapped(const Identifier &index) const;
101 void unMap(const Identifier &index);
102
103 private:
104 IndexToNameMap(); // prevent construction w/o parameters
105 int size;
106 Identifier * _map;
107 };
108
109 class Arguments : public JSObject {
110 public:
111 Arguments(ExecState *exec, FunctionImp *func, const List &args, ActivationImp *act);
112 virtual void mark();
113 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&);
114 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
115 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
116 virtual const ClassInfo *classInfo() const { return &info; }
117 static const ClassInfo info;
118 private:
119 static JSValue *mappedIndexGetter(ExecState *exec, JSObject *, const Identifier &, const PropertySlot& slot);
120
121 ActivationImp *_activationObject;
122 mutable IndexToNameMap indexToNameMap;
123 };
124
125 class ActivationImp : public JSObject {
126 public:
127 ActivationImp(FunctionImp *function, const List &arguments);
128
129 virtual bool getOwnPropertySlot(ExecState *exec, const Identifier &, PropertySlot&);
130 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
131 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
132
133 virtual const ClassInfo *classInfo() const { return &info; }
134 static const ClassInfo info;
135
136 virtual void mark();
137
138 bool isActivation() { return true; }
139 private:
140 static PropertySlot::GetValueFunc getArgumentsGetter();
141 static JSValue *argumentsGetter(ExecState *exec, JSObject *, const Identifier &, const PropertySlot& slot);
142 void createArgumentsObject(ExecState *exec) const;
143
144 FunctionImp *_function;
145 List _arguments;
146 mutable Arguments *_argumentsObject;
147 };
148
149 class GlobalFuncImp : public InternalFunctionImp {
150 public:
151 GlobalFuncImp(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
152 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
153 virtual CodeType codeType() const;
154 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape,
155 DecodeURI, DecodeURIComponent, EncodeURI, EncodeURIComponent
156#ifndef NDEBUG
157 , KJSPrint
158#endif
159};
160 private:
161 int id;
162 };
163
164UString escapeStringForPrettyPrinting(const UString& s);
165
166} // namespace
167
168#endif
Note: See TracBrowser for help on using the repository browser.