source: webkit/trunk/JavaScriptCore/runtime/RegExpObject.cpp@ 38137

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

2008-10-31 Cameron Zwarich <[email protected]>

Rubber-stamped by Sam Weinig.

Move more files from the kjs subdirectory of JavaScriptCore to the
runtime subdirectory.

  • GNUmakefile.am:
  • JavaScriptCore.pri:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • kjs/AllInOneFile.cpp:
  • kjs/RegExpConstructor.cpp: Removed.
  • kjs/RegExpConstructor.h: Removed.
  • kjs/RegExpMatchesArray.h: Removed.
  • kjs/RegExpObject.cpp: Removed.
  • kjs/RegExpObject.h: Removed.
  • kjs/RegExpPrototype.cpp: Removed.
  • kjs/RegExpPrototype.h: Removed.
  • runtime/RegExpConstructor.cpp: Copied from kjs/RegExpConstructor.cpp.
  • runtime/RegExpConstructor.h: Copied from kjs/RegExpConstructor.h.
  • runtime/RegExpMatchesArray.h: Copied from kjs/RegExpMatchesArray.h.
  • runtime/RegExpObject.cpp: Copied from kjs/RegExpObject.cpp.
  • runtime/RegExpObject.h: Copied from kjs/RegExpObject.h.
  • runtime/RegExpPrototype.cpp: Copied from kjs/RegExpPrototype.cpp.
  • runtime/RegExpPrototype.h: Copied from kjs/RegExpPrototype.h.
  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2003, 2007, 2008 Apple Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#include "config.h"
22#include "RegExpObject.h"
23
24#include "JSArray.h"
25#include "JSGlobalObject.h"
26#include "JSString.h"
27#include "RegExpConstructor.h"
28#include "RegExpPrototype.h"
29
30namespace JSC {
31
32static JSValue* regExpObjectGlobal(ExecState*, const Identifier&, const PropertySlot&);
33static JSValue* regExpObjectIgnoreCase(ExecState*, const Identifier&, const PropertySlot&);
34static JSValue* regExpObjectMultiline(ExecState*, const Identifier&, const PropertySlot&);
35static JSValue* regExpObjectSource(ExecState*, const Identifier&, const PropertySlot&);
36static JSValue* regExpObjectLastIndex(ExecState*, const Identifier&, const PropertySlot&);
37static void setRegExpObjectLastIndex(ExecState*, JSObject*, JSValue*);
38
39} // namespace JSC
40
41#include "RegExpObject.lut.h"
42
43namespace JSC {
44
45ASSERT_CLASS_FITS_IN_CELL(RegExpObject);
46
47const ClassInfo RegExpObject::info = { "RegExp", 0, 0, ExecState::regExpTable };
48
49/* Source for RegExpObject.lut.h
50@begin regExpTable
51 global regExpObjectGlobal DontDelete|ReadOnly|DontEnum
52 ignoreCase regExpObjectIgnoreCase DontDelete|ReadOnly|DontEnum
53 multiline regExpObjectMultiline DontDelete|ReadOnly|DontEnum
54 source regExpObjectSource DontDelete|ReadOnly|DontEnum
55 lastIndex regExpObjectLastIndex DontDelete|DontEnum
56@end
57*/
58
59RegExpObject::RegExpObject(PassRefPtr<StructureID> structure, PassRefPtr<RegExp> regExp)
60 : JSObject(structure)
61 , d(new RegExpObjectData(regExp, 0))
62{
63}
64
65RegExpObject::~RegExpObject()
66{
67}
68
69bool RegExpObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
70{
71 return getStaticValueSlot<RegExpObject, JSObject>(exec, ExecState::regExpTable(exec), this, propertyName, slot);
72}
73
74JSValue* regExpObjectGlobal(ExecState*, const Identifier&, const PropertySlot& slot)
75{
76 return jsBoolean(asRegExpObject(slot.slotBase())->regExp()->global());
77}
78
79JSValue* regExpObjectIgnoreCase(ExecState*, const Identifier&, const PropertySlot& slot)
80{
81 return jsBoolean(asRegExpObject(slot.slotBase())->regExp()->ignoreCase());
82}
83
84JSValue* regExpObjectMultiline(ExecState*, const Identifier&, const PropertySlot& slot)
85{
86 return jsBoolean(asRegExpObject(slot.slotBase())->regExp()->multiline());
87}
88
89JSValue* regExpObjectSource(ExecState* exec, const Identifier&, const PropertySlot& slot)
90{
91 return jsString(exec, asRegExpObject(slot.slotBase())->regExp()->pattern());
92}
93
94JSValue* regExpObjectLastIndex(ExecState* exec, const Identifier&, const PropertySlot& slot)
95{
96 return jsNumber(exec, asRegExpObject(slot.slotBase())->lastIndex());
97}
98
99void RegExpObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
100{
101 lookupPut<RegExpObject, JSObject>(exec, propertyName, value, ExecState::regExpTable(exec), this, slot);
102}
103
104void setRegExpObjectLastIndex(ExecState* exec, JSObject* baseObject, JSValue* value)
105{
106 asRegExpObject(baseObject)->setLastIndex(value->toInteger(exec));
107}
108
109bool RegExpObject::match(ExecState* exec, const ArgList& args)
110{
111 RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
112
113 UString input;
114 if (!args.isEmpty())
115 input = args.at(exec, 0)->toString(exec);
116 else {
117 input = regExpObj->input();
118 if (input.isNull()) {
119 throwError(exec, GeneralError, "No input.");
120 return false;
121 }
122 }
123
124 bool global = get(exec, exec->propertyNames().global)->toBoolean(exec);
125 int lastIndex = 0;
126 if (global) {
127 if (d->lastIndex < 0 || d->lastIndex > input.size()) {
128 d->lastIndex = 0;
129 return false;
130 }
131 lastIndex = static_cast<int>(d->lastIndex);
132 }
133
134 int foundIndex;
135 int foundLength;
136 regExpObj->performMatch(d->regExp.get(), input, lastIndex, foundIndex, foundLength);
137
138 if (global) {
139 lastIndex = foundIndex < 0 ? 0 : foundIndex + foundLength;
140 d->lastIndex = lastIndex;
141 }
142
143 return foundIndex >= 0;
144}
145
146JSValue* RegExpObject::test(ExecState* exec, const ArgList& args)
147{
148 return jsBoolean(match(exec, args));
149}
150
151JSValue* RegExpObject::exec(ExecState* exec, const ArgList& args)
152{
153 if (match(exec, args))
154 return exec->lexicalGlobalObject()->regExpConstructor()->arrayOfMatches(exec);
155 return jsNull();
156}
157
158static JSValue* callRegExpObject(ExecState* exec, JSObject* function, JSValue*, const ArgList& args)
159{
160 return asRegExpObject(function)->exec(exec, args);
161}
162
163CallType RegExpObject::getCallData(CallData& callData)
164{
165 callData.native.function = callRegExpObject;
166 return CallTypeHost;
167}
168
169} // namespace JSC
Note: See TracBrowser for help on using the repository browser.