Changeset 34843 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jun 27, 2008, 9:29:48 PM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 21 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r34842 r34843 1 2008-06-27 Sam Weinig <[email protected]> 2 3 Rubber-stamped by Oliver Hunt. 4 5 Splits ArrayConstructor out of ArrayPrototype.h/cpp 6 Splits BooleanConstructor and BooleanPrototype out of BooleanObject.h/cpp 7 8 * GNUmakefile.am: 9 * JavaScriptCore.pri: 10 * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: 11 * JavaScriptCore.xcodeproj/project.pbxproj: 12 * JavaScriptCoreSources.bkl: 13 * VM/Machine.cpp: 14 * kjs/AllInOneFile.cpp: 15 * kjs/ArrayConstructor.cpp: Copied from kjs/ArrayPrototype.cpp. 16 * kjs/ArrayConstructor.h: Copied from kjs/ArrayPrototype.h. 17 * kjs/ArrayPrototype.cpp: 18 * kjs/ArrayPrototype.h: 19 * kjs/BooleanConstructor.cpp: Copied from kjs/BooleanObject.cpp. 20 * kjs/BooleanConstructor.h: Copied from kjs/BooleanObject.h. 21 * kjs/BooleanObject.cpp: 22 * kjs/BooleanObject.h: 23 * kjs/BooleanPrototype.cpp: Copied from kjs/BooleanObject.cpp. 24 * kjs/BooleanPrototype.h: Copied from kjs/BooleanObject.h. 25 * kjs/CommonIdentifiers.h: 26 * kjs/FunctionPrototype.cpp: 27 * kjs/JSArray.cpp: 28 * kjs/JSGlobalObject.cpp: 29 * kjs/JSImmediate.cpp: 30 * kjs/Shell.cpp: 31 * kjs/internal.cpp: 32 * kjs/nodes.cpp: 33 * kjs/string_object.cpp: 34 1 35 2008-06-27 Oliver Hunt <[email protected]> 2 36 -
trunk/JavaScriptCore/GNUmakefile.am
r34840 r34843 86 86 JavaScriptCore/kjs/PropertyNameArray.cpp \ 87 87 JavaScriptCore/kjs/JSArray.cpp \ 88 JavaScriptCore/kjs/ArrayConstructor.cpp \ 88 89 JavaScriptCore/kjs/ArrayPrototype.cpp \ 90 JavaScriptCore/kjs/BooleanConstructor.cpp \ 89 91 JavaScriptCore/kjs/BooleanObject.cpp \ 92 JavaScriptCore/kjs/BooleanPrototype.cpp \ 90 93 JavaScriptCore/kjs/collector.cpp \ 91 94 JavaScriptCore/kjs/date_object.cpp \ -
trunk/JavaScriptCore/JavaScriptCore.pri
r34840 r34843 68 68 kjs/debugger.cpp \ 69 69 kjs/JSArray.cpp \ 70 kjs/ArrayConstructor.cpp \ 70 71 kjs/ArrayPrototype.cpp \ 72 kjs/BooleanConstructor.cpp \ 71 73 kjs/BooleanObject.cpp \ 74 kjs/BooleanPrototype.cpp \ 72 75 kjs/collector.cpp \ 73 76 kjs/CommonIdentifiers.cpp \ -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
r34839 r34843 274 274 </File> 275 275 <File 276 RelativePath="..\..\kjs\ArrayConstructor.cpp" 277 > 278 </File> 279 <File 280 RelativePath="..\..\kjs\ArrayConstructor.h" 281 > 282 </File> 283 <File 276 284 RelativePath="..\..\kjs\ArrayPrototype.cpp" 277 285 > … … 282 290 </File> 283 291 <File 292 RelativePath="..\..\kjs\BooleanConstructor.cpp" 293 > 294 </File> 295 <File 296 RelativePath="..\..\kjs\BooleanConstructor.h" 297 > 298 </File> 299 <File 284 300 RelativePath="..\..\kjs\BooleanObject.cpp" 285 301 > … … 287 303 <File 288 304 RelativePath="..\..\kjs\BooleanObject.h" 305 > 306 </File> 307 <File 308 RelativePath="..\..\kjs\BooleanPrototype.cpp" 309 > 310 </File> 311 <File 312 RelativePath="..\..\kjs\BooleanPrototype.h" 289 313 > 290 314 </File> -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r34838 r34843 225 225 A8E894320CD0602400367179 /* JSCallbackObjectFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = A8E894310CD0602400367179 /* JSCallbackObjectFunctions.h */; }; 226 226 A8E894340CD0603F00367179 /* JSGlobalObject.h in Headers */ = {isa = PBXBuildFile; fileRef = A8E894330CD0603F00367179 /* JSGlobalObject.h */; settings = {ATTRIBUTES = (Private, ); }; }; 227 BC7952090E15E8A800A898AB /* ArrayConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7952070E15E8A800A898AB /* ArrayConstructor.h */; }; 227 228 BC8F3CED0DAF1A8000577A80 /* ConstructData.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8F3CCF0DAF17BA00577A80 /* ConstructData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 228 229 BCF655590A2049710038A194 /* MathExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF6553B0A2048DE0038A194 /* MathExtras.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 584 585 A8E894310CD0602400367179 /* JSCallbackObjectFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCallbackObjectFunctions.h; sourceTree = "<group>"; }; 585 586 A8E894330CD0603F00367179 /* JSGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGlobalObject.h; sourceTree = "<group>"; }; 587 BC7952060E15E8A800A898AB /* ArrayConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayConstructor.cpp; sourceTree = "<group>"; }; 588 BC7952070E15E8A800A898AB /* ArrayConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayConstructor.h; sourceTree = "<group>"; }; 589 BC7952320E15EB5600A898AB /* BooleanConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BooleanConstructor.cpp; sourceTree = "<group>"; }; 590 BC7952330E15EB5600A898AB /* BooleanConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BooleanConstructor.h; sourceTree = "<group>"; }; 591 BC7952340E15EB5600A898AB /* BooleanPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BooleanPrototype.cpp; sourceTree = "<group>"; }; 592 BC7952350E15EB5600A898AB /* BooleanPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BooleanPrototype.h; sourceTree = "<group>"; }; 586 593 BC8F3CCF0DAF17BA00577A80 /* ConstructData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConstructData.h; sourceTree = "<group>"; }; 587 594 BCF6553B0A2048DE0038A194 /* MathExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MathExtras.h; sourceTree = "<group>"; }; … … 978 985 isa = PBXGroup; 979 986 children = ( 980 65E866ED0DD59AFA00A2B2A1 /* SourceProvider.h */,981 65E866EE0DD59AFA00A2B2A1 /* SourceRange.h */,982 987 659126BC0BDD1728001921FB /* AllInOneFile.cpp */, 983 93ADFCE60CCBD7AC00D30B08 /* JSArray.cpp */,984 938772E5038BFE19008635CE /* JSArray.h */,988 BC7952060E15E8A800A898AB /* ArrayConstructor.cpp */, 989 BC7952070E15E8A800A898AB /* ArrayConstructor.h */, 985 990 F692A84D0255597D01FF60F7 /* ArrayPrototype.cpp */, 986 991 F692A84E0255597D01FF60F7 /* ArrayPrototype.h */, 992 BC7952320E15EB5600A898AB /* BooleanConstructor.cpp */, 993 BC7952330E15EB5600A898AB /* BooleanConstructor.h */, 987 994 F692A8500255597D01FF60F7 /* BooleanObject.cpp */, 988 995 704FD35305697E6D003DBED9 /* BooleanObject.h */, 996 BC7952340E15EB5600A898AB /* BooleanPrototype.cpp */, 997 BC7952350E15EB5600A898AB /* BooleanPrototype.h */, 989 998 145C507F0D9DF63B0088F6B9 /* CallData.h */, 990 999 F692A8520255597D01FF60F7 /* collector.cpp */, … … 1008 1017 14BD53F40A3E12D800BAF59C /* ExecState.cpp */, 1009 1018 14BD53F30A3E12D800BAF59C /* ExecState.h */, 1010 F692A85E0255597D01FF60F7 /* JSFunction.cpp */,1011 F692A85F0255597D01FF60F7 /* JSFunction.h */,1012 1019 F692A85C0255597D01FF60F7 /* FunctionPrototype.cpp */, 1013 1020 F692A85D0255597D01FF60F7 /* FunctionPrototype.h */, … … 1018 1025 E178633F0D9BEC0000D74E75 /* InitializeThreading.h */, 1019 1026 F692A8610255597D01FF60F7 /* internal.cpp */, 1020 F692A8620255597D01FF60F7 /* JSString.h */,1021 1027 F692A8630255597D01FF60F7 /* interpreter.cpp */, 1022 1028 F692A8640255597D01FF60F7 /* interpreter.h */, 1023 1029 14DA818F0D99FD2000B0A4FB /* JSActivation.cpp */, 1024 1030 14DA818E0D99FD2000B0A4FB /* JSActivation.h */, 1031 93ADFCE60CCBD7AC00D30B08 /* JSArray.cpp */, 1032 938772E5038BFE19008635CE /* JSArray.h */, 1033 F692A85E0255597D01FF60F7 /* JSFunction.cpp */, 1034 F692A85F0255597D01FF60F7 /* JSFunction.h */, 1035 E18E3A570DF9278C00D90B34 /* JSGlobalData.cpp */, 1025 1036 E18E3A560DF9278C00D90B34 /* JSGlobalData.h */, 1026 E18E3A570DF9278C00D90B34 /* JSGlobalData.cpp */,1027 1037 14DE0D680D02431400AACCA2 /* JSGlobalObject.cpp */, 1028 1038 A8E894330CD0603F00367179 /* JSGlobalObject.h */, … … 1031 1041 65EA4C99092AF9E20093D800 /* JSLock.cpp */, 1032 1042 65EA4C9A092AF9E20093D800 /* JSLock.h */, 1043 A72700780DAC605600E548D7 /* JSNotAnObject.cpp */, 1044 A72700770DAC605600E548D7 /* JSNotAnObject.h */, 1045 F692A8750255597D01FF60F7 /* JSObject.cpp */, 1046 F692A8760255597D01FF60F7 /* JSObject.h */, 1047 F692A8620255597D01FF60F7 /* JSString.h */, 1033 1048 14ABB454099C2A0F00E2A24F /* JSType.h */, 1034 14F252600D08DF2F004ECFFF /* JSVariableObject.cpp */, 1049 F692A8870255597D01FF60F7 /* JSValue.cpp */, 1050 14ABB36E099C076400E2A24F /* JSValue.h */, 1035 1051 14F252600D08DF2F004ECFFF /* JSVariableObject.cpp */, 1036 1052 14F252560D08DD8D004ECFFF /* JSVariableObject.h */, … … 1067 1083 9374D3A7038D9D74008635CE /* ScopeChain.h */, 1068 1084 7E2C6C980D31C6B6002D44E2 /* ScopeChainMark.h */, 1085 65E866ED0DD59AFA00A2B2A1 /* SourceProvider.h */, 1086 65E866EE0DD59AFA00A2B2A1 /* SourceRange.h */, 1069 1087 F692A87F0255597D01FF60F7 /* string_object.cpp */, 1070 1088 F692A8800255597D01FF60F7 /* string_object.h */, … … 1072 1090 F692A8850255597D01FF60F7 /* ustring.cpp */, 1073 1091 F692A8860255597D01FF60F7 /* ustring.h */, 1074 F692A8870255597D01FF60F7 /* JSValue.cpp */, 1075 14ABB36E099C076400E2A24F /* JSValue.h */, 1076 A72700770DAC605600E548D7 /* JSNotAnObject.h */, 1077 A72700780DAC605600E548D7 /* JSNotAnObject.cpp */, 1092 14F252600D08DF2F004ECFFF /* JSVariableObject.cpp */, 1078 1093 ); 1079 1094 path = kjs; … … 1308 1323 1480DB9D0DDC227F003CFDF2 /* DebuggerCallFrame.h in Headers */, 1309 1324 E18E3A580DF9278C00D90B34 /* JSGlobalData.h in Headers */, 1325 BC7952090E15E8A800A898AB /* ArrayConstructor.h in Headers */, 1310 1326 ); 1311 1327 runOnlyForDeploymentPostprocessing = 0; -
trunk/JavaScriptCore/JavaScriptCoreSources.bkl
r34582 r34843 45 45 DerivedSources/JavaScriptCore/grammar.cpp 46 46 kjs/JSArray.cpp 47 kjs/ArrayConstructor.cpp 47 48 kjs/ArrayPrototype.cpp 49 kjs/BooleanConstructor.cpp 48 50 kjs/BooleanObject.cpp 51 kjs/BooleanPrototype.cpp 49 52 kjs/collector.cpp 50 53 kjs/CommonIdentifiers.cpp -
trunk/JavaScriptCore/VM/Machine.cpp
r34842 r34843 41 41 #include "Profiler.h" 42 42 #include "Register.h" 43 #include " ArrayPrototype.h"43 #include "JSArray.h" 44 44 #include "debugger.h" 45 45 #include "JSFunction.h" 46 46 #include "JSString.h" 47 47 #include "object_object.h" 48 #include "operations.h"49 48 #include "operations.h" 50 49 #include "RegExpObject.h" -
trunk/JavaScriptCore/kjs/AllInOneFile.cpp
r34659 r34843 30 30 #include "debugger.cpp" 31 31 #include "JSArray.cpp" 32 #include "ArrayConstructor.cpp" 32 33 #include "ArrayPrototype.cpp" 34 #include "BooleanConstructor.cpp" 33 35 #include "BooleanObject.cpp" 36 #include "BooleanPrototype.cpp" 34 37 #include "collector.cpp" 35 38 #if PLATFORM(DARWIN) -
trunk/JavaScriptCore/kjs/ArrayConstructor.cpp
r34842 r34843 23 23 24 24 #include "config.h" 25 #include "ArrayConstructor.h" 26 25 27 #include "ArrayPrototype.h" 26 27 #include "Machine.h" 28 #include "JSArray.h" 28 29 #include "error_object.h" 29 30 #include "lookup.h" 30 #include "operations.h"31 #include <stdio.h>32 #include <wtf/Assertions.h>33 #include <wtf/HashSet.h>34 35 #include <algorithm> // for std::min36 31 37 32 namespace KJS { 38 39 static JSValue* arrayProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&);40 static JSValue* arrayProtoFuncToLocaleString(ExecState*, JSObject*, JSValue*, const ArgList&);41 static JSValue* arrayProtoFuncConcat(ExecState*, JSObject*, JSValue*, const ArgList&);42 static JSValue* arrayProtoFuncJoin(ExecState*, JSObject*, JSValue*, const ArgList&);43 static JSValue* arrayProtoFuncPop(ExecState*, JSObject*, JSValue*, const ArgList&);44 static JSValue* arrayProtoFuncPush(ExecState*, JSObject*, JSValue*, const ArgList&);45 static JSValue* arrayProtoFuncReverse(ExecState*, JSObject*, JSValue*, const ArgList&);46 static JSValue* arrayProtoFuncShift(ExecState*, JSObject*, JSValue*, const ArgList&);47 static JSValue* arrayProtoFuncSlice(ExecState*, JSObject*, JSValue*, const ArgList&);48 static JSValue* arrayProtoFuncSort(ExecState*, JSObject*, JSValue*, const ArgList&);49 static JSValue* arrayProtoFuncSplice(ExecState*, JSObject*, JSValue*, const ArgList&);50 static JSValue* arrayProtoFuncUnShift(ExecState*, JSObject*, JSValue*, const ArgList&);51 static JSValue* arrayProtoFuncEvery(ExecState*, JSObject*, JSValue*, const ArgList&);52 static JSValue* arrayProtoFuncForEach(ExecState*, JSObject*, JSValue*, const ArgList&);53 static JSValue* arrayProtoFuncSome(ExecState*, JSObject*, JSValue*, const ArgList&);54 static JSValue* arrayProtoFuncIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&);55 static JSValue* arrayProtoFuncFilter(ExecState*, JSObject*, JSValue*, const ArgList&);56 static JSValue* arrayProtoFuncMap(ExecState*, JSObject*, JSValue*, const ArgList&);57 static JSValue* arrayProtoFuncLastIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&);58 59 }60 61 #include "ArrayPrototype.lut.h"62 63 namespace KJS {64 65 // ------------------------------ ArrayPrototype ----------------------------66 67 const ClassInfo ArrayPrototype::info = {"Array", &JSArray::info, 0, ExecState::arrayTable};68 69 /* Source for ArrayPrototype.lut.h70 @begin arrayTable 1671 toString arrayProtoFuncToString DontEnum|Function 072 toLocaleString arrayProtoFuncToLocaleString DontEnum|Function 073 concat arrayProtoFuncConcat DontEnum|Function 174 join arrayProtoFuncJoin DontEnum|Function 175 pop arrayProtoFuncPop DontEnum|Function 076 push arrayProtoFuncPush DontEnum|Function 177 reverse arrayProtoFuncReverse DontEnum|Function 078 shift arrayProtoFuncShift DontEnum|Function 079 slice arrayProtoFuncSlice DontEnum|Function 280 sort arrayProtoFuncSort DontEnum|Function 181 splice arrayProtoFuncSplice DontEnum|Function 282 unshift arrayProtoFuncUnShift DontEnum|Function 183 every arrayProtoFuncEvery DontEnum|Function 184 forEach arrayProtoFuncForEach DontEnum|Function 185 some arrayProtoFuncSome DontEnum|Function 186 indexOf arrayProtoFuncIndexOf DontEnum|Function 187 lastIndexOf arrayProtoFuncLastIndexOf DontEnum|Function 188 filter arrayProtoFuncFilter DontEnum|Function 189 map arrayProtoFuncMap DontEnum|Function 190 @end91 */92 93 // ECMA 15.4.494 ArrayPrototype::ArrayPrototype(ExecState*, ObjectPrototype* objProto)95 : JSArray(objProto, 0)96 {97 }98 99 bool ArrayPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)100 {101 return getStaticFunctionSlot<JSArray>(exec, ExecState::arrayTable(exec), this, propertyName, slot);102 }103 104 105 // ------------------------------ Array Functions ----------------------------106 107 // Helper function108 static JSValue* getProperty(ExecState* exec, JSObject* obj, unsigned index)109 {110 PropertySlot slot(obj);111 if (!obj->getPropertySlot(exec, index, slot))112 return 0;113 return slot.getValue(exec, index);114 }115 116 JSValue* arrayProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)117 {118 if (!thisValue->isObject(&JSArray::info))119 return throwError(exec, TypeError);120 JSObject* thisObj = static_cast<JSArray*>(thisValue);121 122 HashSet<JSObject*>& arrayVisitedElements = exec->dynamicGlobalObject()->arrayVisitedElements();123 if (arrayVisitedElements.size() > MaxReentryDepth)124 return throwError(exec, RangeError, "Maximum call stack size exceeded.");125 126 bool alreadyVisited = !arrayVisitedElements.add(thisObj).second;127 Vector<UChar, 256> strBuffer;128 if (alreadyVisited)129 return jsString(exec, UString(0, 0)); // return an empty string, avoding infinite recursion.130 131 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);132 for (unsigned k = 0; k < length; k++) {133 if (k >= 1)134 strBuffer.append(',');135 if (!strBuffer.data()) {136 JSObject* error = Error::create(exec, GeneralError, "Out of memory");137 exec->setException(error);138 break;139 }140 141 JSValue* element = thisObj->get(exec, k);142 if (element->isUndefinedOrNull())143 continue;144 145 UString str = element->toString(exec);146 strBuffer.append(str.data(), str.size());147 148 if (!strBuffer.data()) {149 JSObject* error = Error::create(exec, GeneralError, "Out of memory");150 exec->setException(error);151 }152 153 if (exec->hadException())154 break;155 }156 exec->dynamicGlobalObject()->arrayVisitedElements().remove(thisObj);157 return jsString(exec, UString(strBuffer.data(), strBuffer.data() ? strBuffer.size() : 0));158 }159 160 JSValue* arrayProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)161 {162 if (!thisValue->isObject(&JSArray::info))163 return throwError(exec, TypeError);164 JSObject* thisObj = static_cast<JSArray*>(thisValue);165 166 HashSet<JSObject*>& arrayVisitedElements = exec->dynamicGlobalObject()->arrayVisitedElements();167 if (arrayVisitedElements.size() > MaxReentryDepth)168 return throwError(exec, RangeError, "Maximum call stack size exceeded.");169 170 bool alreadyVisited = !arrayVisitedElements.add(thisObj).second;171 Vector<UChar, 256> strBuffer;172 if (alreadyVisited)173 return jsString(exec, UString(0, 0)); // return an empty string, avoding infinite recursion.174 175 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);176 for (unsigned k = 0; k < length; k++) {177 if (k >= 1)178 strBuffer.append(',');179 if (!strBuffer.data()) {180 JSObject* error = Error::create(exec, GeneralError, "Out of memory");181 exec->setException(error);182 break;183 }184 185 JSValue* element = thisObj->get(exec, k);186 if (element->isUndefinedOrNull())187 continue;188 189 JSObject* o = element->toObject(exec);190 JSValue* conversionFunction = o->get(exec, exec->propertyNames().toLocaleString);191 UString str;192 CallData callData;193 CallType callType = conversionFunction->getCallData(callData);194 if (callType != CallTypeNone)195 str = call(exec, conversionFunction, callType, callData, element, exec->emptyList())->toString(exec);196 else197 str = element->toString(exec);198 strBuffer.append(str.data(), str.size());199 200 if (!strBuffer.data()) {201 JSObject* error = Error::create(exec, GeneralError, "Out of memory");202 exec->setException(error);203 }204 205 if (exec->hadException())206 break;207 }208 exec->dynamicGlobalObject()->arrayVisitedElements().remove(thisObj);209 return jsString(exec, UString(strBuffer.data(), strBuffer.data() ? strBuffer.size() : 0));210 }211 212 JSValue* arrayProtoFuncJoin(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)213 {214 JSObject* thisObj = thisValue->toThisObject(exec);215 216 HashSet<JSObject*>& arrayVisitedElements = exec->dynamicGlobalObject()->arrayVisitedElements();217 if (arrayVisitedElements.size() > MaxReentryDepth)218 return throwError(exec, RangeError, "Maximum call stack size exceeded.");219 220 bool alreadyVisited = !arrayVisitedElements.add(thisObj).second;221 Vector<UChar, 256> strBuffer;222 if (alreadyVisited)223 return jsString(exec, UString(0, 0)); // return an empty string, avoding infinite recursion.224 225 UChar comma = ',';226 UString separator = args[0]->isUndefined() ? UString(&comma, 1) : args[0]->toString(exec);227 228 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);229 for (unsigned k = 0; k < length; k++) {230 if (k >= 1)231 strBuffer.append(separator.data(), separator.size());232 if (!strBuffer.data()) {233 JSObject* error = Error::create(exec, GeneralError, "Out of memory");234 exec->setException(error);235 break;236 }237 238 JSValue* element = thisObj->get(exec, k);239 if (element->isUndefinedOrNull())240 continue;241 242 UString str = element->toString(exec);243 strBuffer.append(str.data(), str.size());244 245 if (!strBuffer.data()) {246 JSObject* error = Error::create(exec, GeneralError, "Out of memory");247 exec->setException(error);248 }249 250 if (exec->hadException())251 break;252 }253 exec->dynamicGlobalObject()->arrayVisitedElements().remove(thisObj);254 return jsString(exec, UString(strBuffer.data(), strBuffer.data() ? strBuffer.size() : 0));255 }256 257 JSValue* arrayProtoFuncConcat(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)258 {259 JSArray* arr = constructEmptyArray(exec);260 int n = 0;261 JSValue* curArg = thisValue->toThisObject(exec);262 ArgList::const_iterator it = args.begin();263 ArgList::const_iterator end = args.end();264 while (1) {265 if (curArg->isObject(&JSArray::info)) {266 JSArray* curArray = static_cast<JSArray*>(curArg);267 unsigned length = curArray->getLength();268 for (unsigned k = 0; k < length; ++k) {269 if (JSValue* v = curArray->getItem(k))270 arr->put(exec, n, v);271 n++;272 }273 } else {274 arr->put(exec, n, curArg);275 n++;276 }277 if (it == end)278 break;279 curArg = *it;280 ++it;281 }282 arr->setLength(n);283 return arr;284 }285 286 JSValue* arrayProtoFuncPop(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)287 {288 JSObject* thisObj = thisValue->toThisObject(exec);289 JSValue* result = 0;290 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);291 if (length == 0) {292 thisObj->put(exec, exec->propertyNames().length, jsNumber(exec, length));293 result = jsUndefined();294 } else {295 result = thisObj->get(exec, length - 1);296 thisObj->deleteProperty(exec, length - 1);297 thisObj->put(exec, exec->propertyNames().length, jsNumber(exec, length - 1));298 }299 return result;300 }301 302 JSValue* arrayProtoFuncPush(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)303 {304 JSObject* thisObj = thisValue->toThisObject(exec);305 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);306 for (unsigned n = 0; n < args.size(); n++)307 thisObj->put(exec, length + n, args[n]);308 length += args.size();309 thisObj->put(exec, exec->propertyNames().length, jsNumber(exec, length));310 return jsNumber(exec, length);311 }312 313 JSValue* arrayProtoFuncReverse(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)314 {315 JSObject* thisObj = thisValue->toThisObject(exec);316 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);317 unsigned middle = length / 2;318 319 for (unsigned k = 0; k < middle; k++) {320 unsigned lk1 = length - k - 1;321 JSValue* obj2 = getProperty(exec, thisObj, lk1);322 JSValue* obj = getProperty(exec, thisObj, k);323 324 if (obj2)325 thisObj->put(exec, k, obj2);326 else327 thisObj->deleteProperty(exec, k);328 329 if (obj)330 thisObj->put(exec, lk1, obj);331 else332 thisObj->deleteProperty(exec, lk1);333 }334 return thisObj;335 }336 337 JSValue* arrayProtoFuncShift(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)338 {339 JSObject* thisObj = thisValue->toThisObject(exec);340 JSValue* result = 0;341 342 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);343 if (length == 0) {344 thisObj->put(exec, exec->propertyNames().length, jsNumber(exec, length));345 result = jsUndefined();346 } else {347 result = thisObj->get(exec, 0);348 for (unsigned k = 1; k < length; k++) {349 if (JSValue* obj = getProperty(exec, thisObj, k))350 thisObj->put(exec, k - 1, obj);351 else352 thisObj->deleteProperty(exec, k - 1);353 }354 thisObj->deleteProperty(exec, length - 1);355 thisObj->put(exec, exec->propertyNames().length, jsNumber(exec, length - 1));356 }357 return result;358 }359 360 JSValue* arrayProtoFuncSlice(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)361 {362 // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10363 364 JSObject* thisObj = thisValue->toThisObject(exec);365 366 // We return a new array367 JSArray* resObj = constructEmptyArray(exec);368 JSValue* result = resObj;369 double begin = args[0]->toInteger(exec);370 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);371 if (begin >= 0) {372 if (begin > length)373 begin = length;374 } else {375 begin += length;376 if (begin < 0)377 begin = 0;378 }379 double end;380 if (args[1]->isUndefined())381 end = length;382 else {383 end = args[1]->toInteger(exec);384 if (end < 0) {385 end += length;386 if (end < 0)387 end = 0;388 } else {389 if (end > length)390 end = length;391 }392 }393 394 int n = 0;395 int b = static_cast<int>(begin);396 int e = static_cast<int>(end);397 for (int k = b; k < e; k++, n++) {398 if (JSValue* v = getProperty(exec, thisObj, k))399 resObj->put(exec, n, v);400 }401 resObj->setLength(n);402 return result;403 }404 405 JSValue* arrayProtoFuncSort(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)406 {407 JSObject* thisObj = thisValue->toThisObject(exec);408 409 JSValue* function = args[0];410 CallData callData;411 CallType callType = function->getCallData(callData);412 413 if (thisObj->classInfo() == &JSArray::info) {414 if (callType != CallTypeNone)415 static_cast<JSArray*>(thisObj)->sort(exec, function, callType, callData);416 else417 static_cast<JSArray*>(thisObj)->sort(exec);418 return thisObj;419 }420 421 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);422 423 if (!length)424 return thisObj;425 426 // "Min" sort. Not the fastest, but definitely less code than heapsort427 // or quicksort, and much less swapping than bubblesort/insertionsort.428 for (unsigned i = 0; i < length - 1; ++i) {429 JSValue* iObj = thisObj->get(exec, i);430 unsigned themin = i;431 JSValue* minObj = iObj;432 for (unsigned j = i + 1; j < length; ++j) {433 JSValue* jObj = thisObj->get(exec, j);434 double compareResult;435 if (jObj->isUndefined())436 compareResult = 1; // don't check minObj because there's no need to differentiate == (0) from > (1)437 else if (minObj->isUndefined())438 compareResult = -1;439 else if (callType != CallTypeNone) {440 ArgList l;441 l.append(jObj);442 l.append(minObj);443 compareResult = call(exec, function, callType, callData, exec->globalThisValue(), l)->toNumber(exec);444 } else445 compareResult = (jObj->toString(exec) < minObj->toString(exec)) ? -1 : 1;446 447 if (compareResult < 0) {448 themin = j;449 minObj = jObj;450 }451 }452 // Swap themin and i453 if (themin > i) {454 thisObj->put(exec, i, minObj);455 thisObj->put(exec, themin, iObj);456 }457 }458 return thisObj;459 }460 461 JSValue* arrayProtoFuncSplice(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)462 {463 JSObject* thisObj = thisValue->toThisObject(exec);464 465 // 15.4.4.12466 JSArray* resObj = constructEmptyArray(exec);467 JSValue* result = resObj;468 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);469 if (!args.size())470 return jsUndefined();471 int begin = args[0]->toUInt32(exec);472 if (begin < 0)473 begin = std::max<int>(begin + length, 0);474 else475 begin = std::min<int>(begin, length);476 477 unsigned deleteCount;478 if (args.size() > 1)479 deleteCount = std::min<int>(std::max<int>(args[1]->toUInt32(exec), 0), length - begin);480 else481 deleteCount = length - begin;482 483 for (unsigned k = 0; k < deleteCount; k++) {484 if (JSValue* v = getProperty(exec, thisObj, k + begin))485 resObj->put(exec, k, v);486 }487 resObj->setLength(deleteCount);488 489 unsigned additionalArgs = std::max<int>(args.size() - 2, 0);490 if (additionalArgs != deleteCount) {491 if (additionalArgs < deleteCount) {492 for (unsigned k = begin; k < length - deleteCount; ++k) {493 if (JSValue* v = getProperty(exec, thisObj, k + deleteCount))494 thisObj->put(exec, k + additionalArgs, v);495 else496 thisObj->deleteProperty(exec, k + additionalArgs);497 }498 for (unsigned k = length; k > length - deleteCount + additionalArgs; --k)499 thisObj->deleteProperty(exec, k - 1);500 } else {501 for (unsigned k = length - deleteCount; (int)k > begin; --k) {502 if (JSValue* obj = getProperty(exec, thisObj, k + deleteCount - 1))503 thisObj->put(exec, k + additionalArgs - 1, obj);504 else505 thisObj->deleteProperty(exec, k + additionalArgs - 1);506 }507 }508 }509 for (unsigned k = 0; k < additionalArgs; ++k)510 thisObj->put(exec, k + begin, args[k + 2]);511 512 thisObj->put(exec, exec->propertyNames().length, jsNumber(exec, length - deleteCount + additionalArgs));513 return result;514 }515 516 JSValue* arrayProtoFuncUnShift(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)517 {518 JSObject* thisObj = thisValue->toThisObject(exec);519 520 // 15.4.4.13521 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);522 unsigned nrArgs = args.size();523 if (nrArgs) {524 for (unsigned k = length; k > 0; --k) {525 if (JSValue* v = getProperty(exec, thisObj, k - 1))526 thisObj->put(exec, k + nrArgs - 1, v);527 else528 thisObj->deleteProperty(exec, k + nrArgs - 1);529 }530 }531 for (unsigned k = 0; k < nrArgs; ++k)532 thisObj->put(exec, k, args[k]);533 JSValue* result = jsNumber(exec, length + nrArgs);534 thisObj->put(exec, exec->propertyNames().length, result);535 return result;536 }537 538 JSValue* arrayProtoFuncFilter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)539 {540 JSObject* thisObj = thisValue->toThisObject(exec);541 542 JSValue* function = args[0];543 CallData callData;544 CallType callType = function->getCallData(callData);545 if (callType == CallTypeNone)546 return throwError(exec, TypeError);547 548 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec);549 JSArray* resultArray = constructEmptyArray(exec);550 551 unsigned filterIndex = 0;552 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);553 for (unsigned k = 0; k < length && !exec->hadException(); ++k) {554 PropertySlot slot(thisObj);555 556 if (!thisObj->getPropertySlot(exec, k, slot))557 continue;558 559 JSValue* v = slot.getValue(exec, k);560 561 ArgList eachArguments;562 563 eachArguments.append(v);564 eachArguments.append(jsNumber(exec, k));565 eachArguments.append(thisObj);566 567 JSValue* result = call(exec, function, callType, callData, applyThis, eachArguments);568 569 if (result->toBoolean(exec))570 resultArray->put(exec, filterIndex++, v);571 }572 return resultArray;573 }574 575 JSValue* arrayProtoFuncMap(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)576 {577 JSObject* thisObj = thisValue->toThisObject(exec);578 579 JSValue* function = args[0];580 CallData callData;581 CallType callType = function->getCallData(callData);582 if (callType == CallTypeNone)583 return throwError(exec, TypeError);584 585 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec);586 587 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);588 589 JSArray* resultArray = constructEmptyArray(exec, length);590 591 for (unsigned k = 0; k < length && !exec->hadException(); ++k) {592 PropertySlot slot(thisObj);593 if (!thisObj->getPropertySlot(exec, k, slot))594 continue;595 596 JSValue* v = slot.getValue(exec, k);597 598 ArgList eachArguments;599 600 eachArguments.append(v);601 eachArguments.append(jsNumber(exec, k));602 eachArguments.append(thisObj);603 604 JSValue* result = call(exec, function, callType, callData, applyThis, eachArguments);605 resultArray->put(exec, k, result);606 }607 608 return resultArray;609 }610 611 // Documentation for these three is available at:612 // http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:every613 // http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:forEach614 // http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:some615 616 JSValue* arrayProtoFuncEvery(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)617 {618 JSObject* thisObj = thisValue->toThisObject(exec);619 620 JSValue* function = args[0];621 CallData callData;622 CallType callType = function->getCallData(callData);623 if (callType == CallTypeNone)624 return throwError(exec, TypeError);625 626 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec);627 628 JSValue* result = jsBoolean(true);629 630 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);631 for (unsigned k = 0; k < length && !exec->hadException(); ++k) {632 PropertySlot slot(thisObj);633 634 if (!thisObj->getPropertySlot(exec, k, slot))635 continue;636 637 ArgList eachArguments;638 639 eachArguments.append(slot.getValue(exec, k));640 eachArguments.append(jsNumber(exec, k));641 eachArguments.append(thisObj);642 643 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec);644 645 if (!predicateResult) {646 result = jsBoolean(false);647 break;648 }649 }650 651 return result;652 }653 654 JSValue* arrayProtoFuncForEach(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)655 {656 JSObject* thisObj = thisValue->toThisObject(exec);657 658 JSValue* function = args[0];659 CallData callData;660 CallType callType = function->getCallData(callData);661 if (callType == CallTypeNone)662 return throwError(exec, TypeError);663 664 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec);665 666 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);667 for (unsigned k = 0; k < length && !exec->hadException(); ++k) {668 PropertySlot slot(thisObj);669 if (!thisObj->getPropertySlot(exec, k, slot))670 continue;671 672 ArgList eachArguments;673 eachArguments.append(slot.getValue(exec, k));674 eachArguments.append(jsNumber(exec, k));675 eachArguments.append(thisObj);676 677 call(exec, function, callType, callData, applyThis, eachArguments);678 }679 return jsUndefined();680 }681 682 JSValue* arrayProtoFuncSome(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)683 {684 JSObject* thisObj = thisValue->toThisObject(exec);685 686 JSValue* function = args[0];687 CallData callData;688 CallType callType = function->getCallData(callData);689 if (callType == CallTypeNone)690 return throwError(exec, TypeError);691 692 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec);693 694 JSValue* result = jsBoolean(false);695 696 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);697 for (unsigned k = 0; k < length && !exec->hadException(); ++k) {698 PropertySlot slot(thisObj);699 if (!thisObj->getPropertySlot(exec, k, slot))700 continue;701 702 ArgList eachArguments;703 eachArguments.append(slot.getValue(exec, k));704 eachArguments.append(jsNumber(exec, k));705 eachArguments.append(thisObj);706 707 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec);708 709 if (predicateResult) {710 result = jsBoolean(true);711 break;712 }713 }714 return result;715 }716 717 JSValue* arrayProtoFuncIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)718 {719 // JavaScript 1.5 Extension by Mozilla720 // Documentation: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf721 722 JSObject* thisObj = thisValue->toThisObject(exec);723 724 unsigned index = 0;725 double d = args[1]->toInteger(exec);726 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);727 if (d < 0)728 d += length;729 if (d > 0) {730 if (d > length)731 index = length;732 else733 index = static_cast<unsigned>(d);734 }735 736 JSValue* searchElement = args[0];737 for (; index < length; ++index) {738 JSValue* e = getProperty(exec, thisObj, index);739 if (!e)740 continue;741 if (strictEqual(searchElement, e))742 return jsNumber(exec, index);743 }744 745 return jsNumber(exec, -1);746 }747 748 JSValue* arrayProtoFuncLastIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)749 {750 // JavaScript 1.6 Extension by Mozilla751 // Documentation: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:lastIndexOf752 753 JSObject* thisObj = thisValue->toThisObject(exec);754 755 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);756 int index = length - 1;757 double d = args[1]->toIntegerPreserveNaN(exec);758 759 if (d < 0) {760 d += length;761 if (d < 0)762 return jsNumber(exec, -1);763 }764 if (d < length)765 index = static_cast<int>(d);766 767 JSValue* searchElement = args[0];768 for (; index >= 0; --index) {769 JSValue* e = getProperty(exec, thisObj, index);770 if (!e)771 continue;772 if (strictEqual(searchElement, e))773 return jsNumber(exec, index);774 }775 776 return jsNumber(exec, -1);777 }778 779 // ------------------------------ ArrayConstructor -------------------------------780 33 781 34 ArrayConstructor::ArrayConstructor(ExecState* exec, FunctionPrototype* funcProto, ArrayPrototype* arrayProto) -
trunk/JavaScriptCore/kjs/ArrayConstructor.h
r34842 r34843 19 19 */ 20 20 21 #ifndef Array Prototype_h22 #define Array Prototype_h21 #ifndef ArrayConstructor_h 22 #define ArrayConstructor_h 23 23 24 #include "JSArray.h"25 24 #include "FunctionPrototype.h" 26 #include "lookup.h"27 25 28 26 namespace KJS { 29 27 30 class ArrayPrototype : public JSArray { 31 public: 32 ArrayPrototype(ExecState*, ObjectPrototype*); 33 34 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 35 virtual const ClassInfo* classInfo() const { return &info; } 36 static const ClassInfo info; 37 }; 28 class ArrayPrototype; 38 29 39 30 class ArrayConstructor : public InternalFunction { … … 46 37 } // namespace KJS 47 38 48 #endif // Array Prototype_h39 #endif // ArrayConstructor_h -
trunk/JavaScriptCore/kjs/ArrayPrototype.cpp
r34754 r34843 29 29 #include "lookup.h" 30 30 #include "operations.h" 31 #include <stdio.h>32 31 #include <wtf/Assertions.h> 33 32 #include <wtf/HashSet.h> … … 777 776 } 778 777 779 // ------------------------------ ArrayConstructor ------------------------------- 780 781 ArrayConstructor::ArrayConstructor(ExecState* exec, FunctionPrototype* funcProto, ArrayPrototype* arrayProto) 782 : InternalFunction(funcProto, Identifier(exec, arrayProto->classInfo()->className)) 783 { 784 // ECMA 15.4.3.1 Array.prototype 785 putDirect(exec->propertyNames().prototype, arrayProto, DontEnum|DontDelete|ReadOnly); 786 787 // no. of arguments for constructor 788 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); 789 } 790 791 static JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args) 792 { 793 // a single numeric argument denotes the array size (!) 794 if (args.size() == 1 && args[0]->isNumber()) { 795 uint32_t n = args[0]->toUInt32(exec); 796 if (n != args[0]->toNumber(exec)) 797 return throwError(exec, RangeError, "Array size is not a small enough positive integer."); 798 return new (exec) JSArray(exec->lexicalGlobalObject()->arrayPrototype(), n); 799 } 800 801 // otherwise the array is constructed with the arguments in it 802 return new (exec) JSArray(exec->lexicalGlobalObject()->arrayPrototype(), args); 803 } 804 805 static JSObject* constructWithArrayConstructor(ExecState* exec, JSObject*, const ArgList& args) 806 { 807 return constructArrayWithSizeQuirk(exec, args); 808 } 809 810 // ECMA 15.4.2 811 ConstructType ArrayConstructor::getConstructData(ConstructData& constructData) 812 { 813 constructData.native.function = constructWithArrayConstructor; 814 return ConstructTypeNative; 815 } 816 817 static JSValue* callArrayConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 818 { 819 return constructArrayWithSizeQuirk(exec, args); 820 } 821 822 // ECMA 15.6.1 823 CallType ArrayConstructor::getCallData(CallData& callData) 824 { 825 // equivalent to 'new Array(....)' 826 callData.native.function = callArrayConstructor; 827 return CallTypeNative; 828 } 829 830 } 778 } -
trunk/JavaScriptCore/kjs/ArrayPrototype.h
r34754 r34843 23 23 24 24 #include "JSArray.h" 25 #include "FunctionPrototype.h"26 25 #include "lookup.h" 27 26 … … 37 36 }; 38 37 39 class ArrayConstructor : public InternalFunction {40 public:41 ArrayConstructor(ExecState*, FunctionPrototype*, ArrayPrototype*);42 virtual ConstructType getConstructData(ConstructData&);43 virtual CallType getCallData(CallData&);44 };45 46 38 } // namespace KJS 47 39 -
trunk/JavaScriptCore/kjs/BooleanConstructor.cpp
r34842 r34843 20 20 21 21 #include "config.h" 22 #include "Boolean Object.h"22 #include "BooleanConstructor.h" 23 23 24 #include "BooleanPrototype.h" 24 25 #include "JSGlobalObject.h" 25 #include "error_object.h"26 #include "operations.h"27 #include <wtf/Assertions.h>28 26 29 27 namespace KJS { 30 31 // ------------------------------ BooleanObject ---------------------------32 33 const ClassInfo BooleanObject::info = { "Boolean", 0, 0, 0 };34 35 BooleanObject::BooleanObject(JSObject* proto)36 : JSWrapperObject(proto)37 {38 }39 40 // ------------------------------ BooleanPrototype --------------------------41 42 // Functions43 static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&);44 static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&);45 46 // ECMA 15.6.447 48 BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)49 : BooleanObject(objectPrototype)50 {51 setInternalValue(jsBoolean(false));52 53 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, booleanProtoFuncToString), DontEnum);54 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().valueOf, booleanProtoFuncValueOf), DontEnum);55 }56 57 58 // ------------------------------ Functions --------------------------59 60 // ECMA 15.6.4.2 + 15.6.4.361 62 JSValue* booleanProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)63 {64 if (thisValue == jsBoolean(false))65 return jsString(exec, "false");66 67 if (thisValue == jsBoolean(true))68 return jsString(exec, "true");69 70 if (!thisValue->isObject(&BooleanObject::info))71 return throwError(exec, TypeError);72 73 if (static_cast<BooleanObject*>(thisValue)->internalValue() == jsBoolean(false))74 return jsString(exec, "false");75 76 ASSERT(static_cast<BooleanObject*>(thisValue)->internalValue() == jsBoolean(true));77 return jsString(exec, "true");78 }79 80 JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)81 {82 if (JSImmediate::isBoolean(thisValue))83 return thisValue;84 85 if (!thisValue->isObject(&BooleanObject::info))86 return throwError(exec, TypeError);87 88 return static_cast<BooleanObject*>(thisValue)->internalValue();89 }90 91 // ------------------------------ BooleanConstructor -----------------------------92 93 28 94 29 BooleanConstructor::BooleanConstructor(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype) -
trunk/JavaScriptCore/kjs/BooleanConstructor.h
r34842 r34843 19 19 */ 20 20 21 #ifndef Boolean Object_h22 #define Boolean Object_h21 #ifndef BooleanConstructor_h 22 #define BooleanConstructor_h 23 23 24 24 #include "FunctionPrototype.h" 25 #include "JSWrapperObject.h"26 25 27 26 namespace KJS { 28 29 class BooleanObject : public JSWrapperObject {30 public:31 BooleanObject(JSObject* proto);32 33 virtual const ClassInfo* classInfo() const { return &info; }34 static const ClassInfo info;35 };36 37 /**38 * @internal39 *40 * The initial value of Boolean.prototype (and thus all objects created41 * with the Boolean constructor42 */43 class BooleanPrototype : public BooleanObject {44 public:45 BooleanPrototype(ExecState*, ObjectPrototype*, FunctionPrototype*);46 };47 27 48 28 /** … … 64 44 } // namespace KJS 65 45 66 #endif // Boolean Object_h46 #endif // BooleanConstructor_h -
trunk/JavaScriptCore/kjs/BooleanObject.cpp
r34821 r34843 22 22 #include "BooleanObject.h" 23 23 24 #include "JSGlobalObject.h"25 #include "error_object.h"26 #include "operations.h"27 #include <wtf/Assertions.h>28 29 24 namespace KJS { 30 31 // ------------------------------ BooleanObject ---------------------------32 25 33 26 const ClassInfo BooleanObject::info = { "Boolean", 0, 0, 0 }; … … 38 31 } 39 32 40 // ------------------------------ BooleanPrototype --------------------------41 42 // Functions43 static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&);44 static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&);45 46 // ECMA 15.6.447 48 BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)49 : BooleanObject(objectPrototype)50 {51 setInternalValue(jsBoolean(false));52 53 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, booleanProtoFuncToString), DontEnum);54 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().valueOf, booleanProtoFuncValueOf), DontEnum);55 }56 57 58 // ------------------------------ Functions --------------------------59 60 // ECMA 15.6.4.2 + 15.6.4.361 62 JSValue* booleanProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)63 {64 if (thisValue == jsBoolean(false))65 return jsString(exec, "false");66 67 if (thisValue == jsBoolean(true))68 return jsString(exec, "true");69 70 if (!thisValue->isObject(&BooleanObject::info))71 return throwError(exec, TypeError);72 73 if (static_cast<BooleanObject*>(thisValue)->internalValue() == jsBoolean(false))74 return jsString(exec, "false");75 76 ASSERT(static_cast<BooleanObject*>(thisValue)->internalValue() == jsBoolean(true));77 return jsString(exec, "true");78 }79 80 JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)81 {82 if (JSImmediate::isBoolean(thisValue))83 return thisValue;84 85 if (!thisValue->isObject(&BooleanObject::info))86 return throwError(exec, TypeError);87 88 return static_cast<BooleanObject*>(thisValue)->internalValue();89 }90 91 // ------------------------------ BooleanConstructor -----------------------------92 93 94 BooleanConstructor::BooleanConstructor(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype)95 : InternalFunction(functionPrototype, Identifier(exec, booleanPrototype->classInfo()->className))96 {97 putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);98 99 // no. of arguments for constructor100 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontDelete | DontEnum);101 }102 103 // ECMA 15.6.2104 JSObject* constructBoolean(ExecState* exec, const ArgList& args)105 {106 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype());107 obj->setInternalValue(jsBoolean(args[0]->toBoolean(exec)));108 return obj;109 }110 111 static JSObject* constructWithBooleanConstructor(ExecState* exec, JSObject*, const ArgList& args)112 {113 return constructBoolean(exec, args);114 }115 116 ConstructType BooleanConstructor::getConstructData(ConstructData& constructData)117 {118 constructData.native.function = constructWithBooleanConstructor;119 return ConstructTypeNative;120 }121 122 // ECMA 15.6.1123 static JSValue* callBooleanConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args)124 {125 return jsBoolean(args[0]->toBoolean(exec));126 }127 128 CallType BooleanConstructor::getCallData(CallData& callData)129 {130 callData.native.function = callBooleanConstructor;131 return CallTypeNative;132 }133 134 JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSValue* immediateBooleanValue)135 {136 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype());137 obj->setInternalValue(immediateBooleanValue);138 return obj;139 }140 141 33 } // namespace KJS -
trunk/JavaScriptCore/kjs/BooleanObject.h
r34754 r34843 22 22 #define BooleanObject_h 23 23 24 #include "FunctionPrototype.h"25 24 #include "JSWrapperObject.h" 26 25 … … 35 34 }; 36 35 37 /**38 * @internal39 *40 * The initial value of Boolean.prototype (and thus all objects created41 * with the Boolean constructor42 */43 class BooleanPrototype : public BooleanObject {44 public:45 BooleanPrototype(ExecState*, ObjectPrototype*, FunctionPrototype*);46 };47 48 /**49 * @internal50 *51 * The initial value of the the global variable's "Boolean" property52 */53 class BooleanConstructor : public InternalFunction {54 public:55 BooleanConstructor(ExecState*, FunctionPrototype*, BooleanPrototype*);56 private:57 virtual ConstructType getConstructData(ConstructData&);58 virtual CallType getCallData(CallData&);59 };60 61 JSObject* constructBooleanFromImmediateBoolean(ExecState*, JSValue*);62 JSObject* constructBoolean(ExecState*, const ArgList&);63 64 36 } // namespace KJS 65 37 -
trunk/JavaScriptCore/kjs/BooleanPrototype.cpp
r34842 r34843 20 20 21 21 #include "config.h" 22 #include "Boolean Object.h"22 #include "BooleanPrototype.h" 23 23 24 #include "JSGlobalObject.h"25 24 #include "error_object.h" 26 #include "operations.h"27 #include <wtf/Assertions.h>28 25 29 26 namespace KJS { 30 31 // ------------------------------ BooleanObject ---------------------------32 33 const ClassInfo BooleanObject::info = { "Boolean", 0, 0, 0 };34 35 BooleanObject::BooleanObject(JSObject* proto)36 : JSWrapperObject(proto)37 {38 }39 40 // ------------------------------ BooleanPrototype --------------------------41 27 42 28 // Functions … … 89 75 } 90 76 91 // ------------------------------ BooleanConstructor -----------------------------92 93 94 BooleanConstructor::BooleanConstructor(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype)95 : InternalFunction(functionPrototype, Identifier(exec, booleanPrototype->classInfo()->className))96 {97 putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);98 99 // no. of arguments for constructor100 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontDelete | DontEnum);101 }102 103 // ECMA 15.6.2104 JSObject* constructBoolean(ExecState* exec, const ArgList& args)105 {106 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype());107 obj->setInternalValue(jsBoolean(args[0]->toBoolean(exec)));108 return obj;109 }110 111 static JSObject* constructWithBooleanConstructor(ExecState* exec, JSObject*, const ArgList& args)112 {113 return constructBoolean(exec, args);114 }115 116 ConstructType BooleanConstructor::getConstructData(ConstructData& constructData)117 {118 constructData.native.function = constructWithBooleanConstructor;119 return ConstructTypeNative;120 }121 122 // ECMA 15.6.1123 static JSValue* callBooleanConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args)124 {125 return jsBoolean(args[0]->toBoolean(exec));126 }127 128 CallType BooleanConstructor::getCallData(CallData& callData)129 {130 callData.native.function = callBooleanConstructor;131 return CallTypeNative;132 }133 134 JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSValue* immediateBooleanValue)135 {136 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype());137 obj->setInternalValue(immediateBooleanValue);138 return obj;139 }140 141 77 } // namespace KJS -
trunk/JavaScriptCore/kjs/BooleanPrototype.h
r34842 r34843 19 19 */ 20 20 21 #ifndef Boolean Object_h22 #define Boolean Object_h21 #ifndef BooleanPrototype_h 22 #define BooleanPrototype_h 23 23 24 #include "FunctionPrototype.h" 25 #include "JSWrapperObject.h" 24 #include "BooleanObject.h" 26 25 27 26 namespace KJS { 28 29 class BooleanObject : public JSWrapperObject {30 public:31 BooleanObject(JSObject* proto);32 33 virtual const ClassInfo* classInfo() const { return &info; }34 static const ClassInfo info;35 };36 27 37 28 /** … … 46 37 }; 47 38 48 /**49 * @internal50 *51 * The initial value of the the global variable's "Boolean" property52 */53 class BooleanConstructor : public InternalFunction {54 public:55 BooleanConstructor(ExecState*, FunctionPrototype*, BooleanPrototype*);56 private:57 virtual ConstructType getConstructData(ConstructData&);58 virtual CallType getCallData(CallData&);59 };60 61 JSObject* constructBooleanFromImmediateBoolean(ExecState*, JSValue*);62 JSObject* constructBoolean(ExecState*, const ArgList&);63 64 39 } // namespace KJS 65 40 66 #endif // Boolean Object_h41 #endif // BooleanPrototype_h -
trunk/JavaScriptCore/kjs/CommonIdentifiers.h
r34587 r34843 69 69 70 70 class CommonIdentifiers : Noncopyable { 71 72 71 private: 73 72 CommonIdentifiers(JSGlobalData*); -
trunk/JavaScriptCore/kjs/FunctionPrototype.cpp
r34821 r34843 24 24 #include "JSGlobalObject.h" 25 25 #include "Parser.h" 26 #include "ArrayPrototype.h"27 26 #include "debugger.h" 28 27 #include "JSFunction.h" -
trunk/JavaScriptCore/kjs/JSArray.cpp
r34809 r34843 26 26 #include "ArrayPrototype.h" 27 27 #include "PropertyNameArray.h" 28 #include <wtf/AVLTree.h> 28 29 #include <wtf/Assertions.h> 29 #include <wtf/AVLTree.h>30 30 31 31 #define CHECK_ARRAY_CONSISTENCY 0 -
trunk/JavaScriptCore/kjs/JSGlobalObject.cpp
r34842 r34843 33 33 #include "CodeBlock.h" 34 34 #include "ArrayPrototype.h" 35 #include "BooleanObject.h" 35 #include "ArrayConstructor.h" 36 #include "BooleanPrototype.h" 37 #include "BooleanConstructor.h" 36 38 #include "date_object.h" 37 39 #include "debugger.h" -
trunk/JavaScriptCore/kjs/JSImmediate.cpp
r34825 r34843 22 22 #include "JSImmediate.h" 23 23 24 #include "Boolean Object.h"24 #include "BooleanConstructor.h" 25 25 #include "JSGlobalObject.h" 26 26 #include "JSNotAnObject.h" -
trunk/JavaScriptCore/kjs/Shell.cpp
r34793 r34843 24 24 25 25 #include "CodeGenerator.h" 26 #include "InitializeThreading.h" 27 #include "JSArray.h" 28 #include "JSFunction.h" 26 29 #include "JSGlobalObject.h" 27 30 #include "JSLock.h" 31 #include "JSObject.h" 28 32 #include "Parser.h" 29 #include "ArrayPrototype.h"30 33 #include "collector.h" 31 34 #include "completion.h" 32 #include "JSFunction.h"33 #include "InitializeThreading.h"34 35 #include "interpreter.h" 35 36 #include "nodes.h" 36 #include "JSObject.h"37 37 #include "protect.h" 38 38 #include <math.h> -
trunk/JavaScriptCore/kjs/internal.cpp
r34821 r34843 25 25 26 26 #include "ExecState.h" 27 #include "ArrayPrototype.h"28 #include "BooleanObject.h"29 27 #include "collector.h" 30 28 #include "date_object.h" -
trunk/JavaScriptCore/kjs/nodes.cpp
r34838 r34843 27 27 #include "nodes.h" 28 28 29 #include "ArrayPrototype.h"30 29 #include "CodeGenerator.h" 31 30 #include "ExecState.h" -
trunk/JavaScriptCore/kjs/string_object.cpp
r34821 r34843 23 23 #include "string_object.h" 24 24 25 #include "JSArray.h" 25 26 #include "JSWrapperObject.h" 26 27 #include "PropertyNameArray.h" 27 #include " ArrayPrototype.h"28 #include "RegExpObject.h" 28 29 #include "error_object.h" 29 30 #include "operations.h" 30 #include "RegExpObject.h"31 31 #include <wtf/MathExtras.h> 32 32 #include <wtf/unicode/Collator.h>
Note:
See TracChangeset
for help on using the changeset viewer.