Changeset 48336 in webkit for trunk/JavaScriptCore
- Timestamp:
- Sep 12, 2009, 7:44:32 PM (16 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSCallbackObject.h
r43372 r48336 67 67 virtual bool hasInstance(ExecState* exec, JSValue value, JSValue proto); 68 68 69 virtual void get PropertyNames(ExecState*, PropertyNameArray&);69 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&); 70 70 71 71 virtual double toNumber(ExecState*) const; -
trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h
r46598 r48336 374 374 375 375 template <class Base> 376 void JSCallbackObject<Base>::get PropertyNames(ExecState* exec, PropertyNameArray& propertyNames)376 void JSCallbackObject<Base>::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 377 377 { 378 378 JSContextRef execRef = toRef(exec); … … 408 408 } 409 409 410 Base::get PropertyNames(exec, propertyNames);410 Base::getOwnPropertyNames(exec, propertyNames); 411 411 } 412 412 -
trunk/JavaScriptCore/ChangeLog
r48331 r48336 1 2009-09-12 Oliver Hunt <[email protected]> 2 3 Reviewed by Maciej Stachowiak. 4 5 [ES5] Implement Object.keys 6 https://bugs.webkit.org/show_bug.cgi?id=29170 7 8 This patch basically requires two separate steps, the first is to split getPropertyNames 9 into two functions -- getOwnPropertyNames and getPropertyNames, basically making them behave 10 in the same way as getOwnPropertySlot and getPropertySlot. In essence getOwnPropertyNames 11 produces the list of properties on an object excluding its prototype chain and getPropertyNames 12 just iterates the the object and its prototype chain calling getOwnPropertyNames at each level. 13 14 * API/JSCallbackObject.h: 15 * API/JSCallbackObjectFunctions.h: 16 (JSC::::getOwnPropertyNames): 17 * JavaScriptCore.exp: 18 * debugger/DebuggerActivation.cpp: 19 (JSC::DebuggerActivation::getOwnPropertyNames): 20 * debugger/DebuggerActivation.h: 21 * runtime/CommonIdentifiers.h: 22 * runtime/JSArray.cpp: 23 (JSC::JSArray::getOwnPropertyNames): 24 * runtime/JSArray.h: 25 * runtime/JSByteArray.cpp: 26 (JSC::JSByteArray::getOwnPropertyNames): 27 * runtime/JSByteArray.h: 28 * runtime/JSNotAnObject.cpp: 29 (JSC::JSNotAnObject::getOwnPropertyNames): 30 * runtime/JSNotAnObject.h: 31 * runtime/JSObject.cpp: 32 (JSC::JSObject::getOwnPropertyNames): 33 * runtime/JSObject.h: 34 * runtime/JSVariableObject.cpp: 35 (JSC::JSVariableObject::getOwnPropertyNames): 36 * runtime/JSVariableObject.h: 37 * runtime/ObjectConstructor.cpp: 38 (JSC::ObjectConstructor::ObjectConstructor): 39 (JSC::objectConstructorKeys): 40 * runtime/RegExpMatchesArray.h: 41 (JSC::RegExpMatchesArray::getOwnPropertyNames): 42 * runtime/StringObject.cpp: 43 (JSC::StringObject::getOwnPropertyNames): 44 * runtime/StringObject.h: 45 * runtime/Structure.cpp: 46 (JSC::Structure::getOwnEnumerablePropertyNames): 47 (JSC::Structure::getEnumerablePropertyNames): 48 * runtime/Structure.h: 49 1 50 2009-09-11 Oliver Hunt <[email protected]> 2 51 -
trunk/JavaScriptCore/JavaScriptCore.exp
r48270 r48336 114 114 __ZN3JSC12SmallStrings17createEmptyStringEPNS_12JSGlobalDataE 115 115 __ZN3JSC12StringObject14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE 116 __ZN3JSC12StringObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE117 116 __ZN3JSC12StringObject18getOwnPropertySlotEPNS_9ExecStateERKNS_10IdentifierERNS_12PropertySlotE 118 117 __ZN3JSC12StringObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE 118 __ZN3JSC12StringObject19getOwnPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE 119 119 __ZN3JSC12StringObject24getOwnPropertyDescriptorEPNS_9ExecStateERKNS_10IdentifierERNS_18PropertyDescriptorE 120 120 __ZN3JSC12StringObject3putEPNS_9ExecStateERKNS_10IdentifierENS_7JSValueERNS_15PutPropertySlotE … … 148 148 __ZN3JSC16JSVariableObject14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE 149 149 __ZN3JSC16JSVariableObject14symbolTableGetERKNS_10IdentifierERNS_18PropertyDescriptorE 150 __ZN3JSC16JSVariableObject1 6getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE150 __ZN3JSC16JSVariableObject19getOwnPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE 151 151 __ZN3JSC16toUInt32SlowCaseEdRb 152 152 __ZN3JSC17BytecodeGenerator21setDumpsGeneratedCodeEb … … 251 251 __ZN3JSC8JSObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE 252 252 __ZN3JSC8JSObject18getPrimitiveNumberEPNS_9ExecStateERdRNS_7JSValueE 253 __ZN3JSC8JSObject19getOwnPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE 253 254 __ZN3JSC8JSObject21getPropertyDescriptorEPNS_9ExecStateERKNS_10IdentifierERNS_18PropertyDescriptorE 254 255 __ZN3JSC8JSObject22fillGetterPropertySlotERNS_12PropertySlotEPNS_7JSValueE -
trunk/JavaScriptCore/debugger/DebuggerActivation.cpp
r47022 r48336 72 72 } 73 73 74 void DebuggerActivation::get PropertyNames(ExecState* exec, PropertyNameArray& propertyNames)74 void DebuggerActivation::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 75 75 { 76 76 m_activation->getPropertyNames(exec, propertyNames); -
trunk/JavaScriptCore/debugger/DebuggerActivation.h
r48331 r48336 43 43 virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue, unsigned attributes); 44 44 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 45 virtual void get PropertyNames(ExecState*, PropertyNameArray&);45 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&); 46 46 virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const; 47 47 virtual void defineGetter(ExecState*, const Identifier& propertyName, JSObject* getterFunction); -
trunk/JavaScriptCore/runtime/CommonIdentifiers.h
r47780 r48336 54 54 macro(isArray) \ 55 55 macro(isPrototypeOf) \ 56 macro(keys) \ 56 57 macro(length) \ 57 58 macro(message) \ -
trunk/JavaScriptCore/runtime/JSArray.cpp
r47780 r48336 465 465 } 466 466 467 void JSArray::get PropertyNames(ExecState* exec, PropertyNameArray& propertyNames)467 void JSArray::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 468 468 { 469 469 // FIXME: Filling PropertyNameArray with an identifier for every integer … … 485 485 } 486 486 487 JSObject::get PropertyNames(exec, propertyNames);487 JSObject::getOwnPropertyNames(exec, propertyNames); 488 488 } 489 489 -
trunk/JavaScriptCore/runtime/JSArray.h
r48068 r48336 92 92 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 93 93 virtual bool deleteProperty(ExecState*, unsigned propertyName); 94 virtual void get PropertyNames(ExecState*, PropertyNameArray&);94 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&); 95 95 virtual void markChildren(MarkStack&); 96 96 -
trunk/JavaScriptCore/runtime/JSByteArray.cpp
r47780 r48336 97 97 } 98 98 99 void JSByteArray::get PropertyNames(ExecState* exec, PropertyNameArray& propertyNames)99 void JSByteArray::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 100 100 { 101 101 unsigned length = m_storage->length(); 102 102 for (unsigned i = 0; i < length; ++i) 103 103 propertyNames.add(Identifier::from(exec, i)); 104 JSObject::get PropertyNames(exec, propertyNames);104 JSObject::getOwnPropertyNames(exec, propertyNames); 105 105 } 106 106 -
trunk/JavaScriptCore/runtime/JSByteArray.h
r47780 r48336 83 83 virtual void put(JSC::ExecState*, unsigned propertyName, JSC::JSValue); 84 84 85 virtual void get PropertyNames(JSC::ExecState*, JSC::PropertyNameArray&);85 virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&); 86 86 87 87 virtual const ClassInfo* classInfo() const { return m_classInfo; } -
trunk/JavaScriptCore/runtime/JSNotAnObject.cpp
r47780 r48336 122 122 } 123 123 124 void JSNotAnObject::get PropertyNames(ExecState* exec, PropertyNameArray&)124 void JSNotAnObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray&) 125 125 { 126 126 ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); -
trunk/JavaScriptCore/runtime/JSNotAnObject.h
r47780 r48336 89 89 virtual bool deleteProperty(ExecState*, unsigned propertyName); 90 90 91 virtual void get PropertyNames(ExecState*, PropertyNameArray&);91 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&); 92 92 93 93 JSNotAnObjectErrorStub* m_exception; -
trunk/JavaScriptCore/runtime/JSObject.cpp
r48068 r48336 428 428 } 429 429 430 void JSObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 431 { 432 m_structure->getOwnEnumerablePropertyNames(exec, propertyNames, this); 433 } 434 430 435 bool JSObject::toBoolean(ExecState*) const 431 436 { -
trunk/JavaScriptCore/runtime/JSObject.h
r48331 r48336 124 124 125 125 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 126 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&); 126 127 127 128 virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const; -
trunk/JavaScriptCore/runtime/JSVariableObject.cpp
r47780 r48336 43 43 } 44 44 45 void JSVariableObject::get PropertyNames(ExecState* exec, PropertyNameArray& propertyNames)45 void JSVariableObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 46 46 { 47 47 SymbolTable::const_iterator end = symbolTable().end(); … … 51 51 } 52 52 53 JSObject::get PropertyNames(exec, propertyNames);53 JSObject::getOwnPropertyNames(exec, propertyNames); 54 54 } 55 55 -
trunk/JavaScriptCore/runtime/JSVariableObject.h
r48331 r48336 50 50 51 51 virtual bool deleteProperty(ExecState*, const Identifier&); 52 virtual void get PropertyNames(ExecState*, PropertyNameArray&);52 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&); 53 53 54 54 virtual bool isVariableObject() const; -
trunk/JavaScriptCore/runtime/ObjectConstructor.cpp
r47780 r48336 35 35 static JSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*, JSObject*, JSValue, const ArgList&); 36 36 static JSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*, JSObject*, JSValue, const ArgList&); 37 static JSValue JSC_HOST_CALL objectConstructorKeys(ExecState*, JSObject*, JSValue, const ArgList&); 37 38 38 39 ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype, Structure* prototypeFunctionStructure) … … 47 48 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().getPrototypeOf, objectConstructorGetPrototypeOf), DontEnum); 48 49 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 2, exec->propertyNames().getOwnPropertyDescriptor, objectConstructorGetOwnPropertyDescriptor), DontEnum); 50 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().keys, objectConstructorKeys), DontEnum); 49 51 } 50 52 … … 117 119 } 118 120 121 JSValue JSC_HOST_CALL objectConstructorKeys(ExecState* exec, JSObject*, JSValue, const ArgList& args) 122 { 123 if (!args.at(0).isObject()) 124 return throwError(exec, TypeError, "Requested keys of a value that is not an object."); 125 PropertyNameArray properties(exec); 126 asObject(args.at(0))->getOwnPropertyNames(exec, properties); 127 JSArray* keys = constructEmptyArray(exec); 128 size_t numProperties = properties.size(); 129 for (size_t i = 0; i < numProperties; i++) 130 keys->push(exec, jsOwnedString(exec, properties[i].ustring())); 131 return keys; 132 } 133 119 134 } // namespace JSC -
trunk/JavaScriptCore/runtime/RegExpMatchesArray.h
r47780 r48336 80 80 } 81 81 82 virtual void get PropertyNames(ExecState* exec, PropertyNameArray& arr)82 virtual void getOwnPropertyNames(ExecState* exec, PropertyNameArray& arr) 83 83 { 84 84 if (lazyCreationData()) 85 85 fillArrayInstance(exec); 86 JSArray::get PropertyNames(exec, arr);86 JSArray::getOwnPropertyNames(exec, arr); 87 87 } 88 88 -
trunk/JavaScriptCore/runtime/StringObject.cpp
r48083 r48336 83 83 } 84 84 85 void StringObject::get PropertyNames(ExecState* exec, PropertyNameArray& propertyNames)85 void StringObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 86 86 { 87 87 int size = internalValue()->value().size(); 88 88 for (int i = 0; i < size; ++i) 89 89 propertyNames.add(Identifier(exec, UString::from(i))); 90 return JSObject::get PropertyNames(exec, propertyNames);90 return JSObject::getOwnPropertyNames(exec, propertyNames); 91 91 } 92 92 -
trunk/JavaScriptCore/runtime/StringObject.h
r48083 r48336 40 40 virtual void put(ExecState* exec, const Identifier& propertyName, JSValue, PutPropertySlot&); 41 41 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 42 virtual void get PropertyNames(ExecState*, PropertyNameArray&);42 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&); 43 43 44 44 virtual const ClassInfo* classInfo() const { return &info; } -
trunk/JavaScriptCore/runtime/Structure.cpp
r48264 r48336 274 274 } 275 275 276 void Structure::getOwnEnumerablePropertyNames(ExecState* exec, PropertyNameArray& propertyNames, JSObject* baseObject) 277 { 278 getEnumerableNamesFromPropertyTable(propertyNames); 279 getEnumerableNamesFromClassInfoTable(exec, baseObject->classInfo(), propertyNames); 280 } 281 276 282 void Structure::getEnumerablePropertyNames(ExecState* exec, PropertyNameArray& propertyNames, JSObject* baseObject) 277 283 { … … 286 292 } 287 293 288 getEnumerableNamesFromPropertyTable(propertyNames); 289 getEnumerableNamesFromClassInfoTable(exec, baseObject->classInfo(), propertyNames); 294 baseObject->getOwnPropertyNames(exec, propertyNames); 290 295 291 296 if (m_prototype.isObject()) { 292 297 propertyNames.setShouldCache(false); // No need for our prototypes to waste memory on caching, since they're not being enumerated directly. 293 asObject(m_prototype)->getPropertyNames(exec, propertyNames); 298 JSObject* prototype = asObject(m_prototype); 299 while(1) { 300 if (!prototype->structure()->typeInfo().hasDefaultGetPropertyNames()) { 301 prototype->getPropertyNames(exec, propertyNames); 302 break; 303 } 304 prototype->getOwnPropertyNames(exec, propertyNames); 305 JSValue nextProto = prototype->prototype(); 306 if (!nextProto.isObject()) 307 break; 308 prototype = asObject(nextProto); 309 } 294 310 } 295 311 -
trunk/JavaScriptCore/runtime/Structure.h
r48264 r48336 115 115 116 116 void getEnumerablePropertyNames(ExecState*, PropertyNameArray&, JSObject*); 117 void getOwnEnumerablePropertyNames(ExecState*, PropertyNameArray&, JSObject*); 117 118 118 119 bool hasGetterSetterProperties() const { return m_hasGetterSetterProperties; }
Note:
See TracChangeset
for help on using the changeset viewer.