Changeset 48565 in webkit for trunk/JavaScriptCore/runtime/ObjectConstructor.cpp
- Timestamp:
- Sep 19, 2009, 3:14:56 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/ObjectConstructor.cpp
r48542 r48565 39 39 static JSValue JSC_HOST_CALL objectConstructorKeys(ExecState*, JSObject*, JSValue, const ArgList&); 40 40 static JSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState*, JSObject*, JSValue, const ArgList&); 41 static JSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState*, JSObject*, JSValue, const ArgList&); 41 42 42 43 ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype, Structure* prototypeFunctionStructure) … … 52 53 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 2, exec->propertyNames().getOwnPropertyDescriptor, objectConstructorGetOwnPropertyDescriptor), DontEnum); 53 54 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().keys, objectConstructorKeys), DontEnum); 54 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 3, exec->propertyNames().defineProperty, objectConstructorDefineProperty), DontEnum); 55 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 3, exec->propertyNames().defineProperty, objectConstructorDefineProperty), DontEnum); 56 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 2, exec->propertyNames().defineProperties, objectConstructorDefineProperties), DontEnum); 55 57 } 56 58 … … 238 240 } 239 241 242 static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* properties) 243 { 244 PropertyNameArray propertyNames(exec); 245 asObject(properties)->getOwnPropertyNames(exec, propertyNames); 246 size_t numProperties = propertyNames.size(); 247 Vector<PropertyDescriptor> descriptors; 248 MarkedArgumentBuffer markBuffer; 249 for (size_t i = 0; i < numProperties; i++) { 250 PropertySlot slot; 251 JSValue prop = properties->get(exec, propertyNames[i]); 252 if (exec->hadException()) 253 return jsNull(); 254 PropertyDescriptor descriptor; 255 if (!toPropertyDescriptor(exec, prop, descriptor)) 256 return jsNull(); 257 descriptors.append(descriptor); 258 // Ensure we mark all the values that we're accumulating 259 if (descriptor.isDataDescriptor() && descriptor.value()) 260 markBuffer.append(descriptor.value()); 261 if (descriptor.isAccessorDescriptor()) { 262 if (descriptor.getter()) 263 markBuffer.append(descriptor.getter()); 264 if (descriptor.setter()) 265 markBuffer.append(descriptor.setter()); 266 } 267 } 268 for (size_t i = 0; i < numProperties; i++) { 269 object->defineOwnProperty(exec, propertyNames[i], descriptors[i], true); 270 if (exec->hadException()) 271 return jsNull(); 272 } 273 return object; 274 } 275 276 JSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState* exec, JSObject*, JSValue, const ArgList& args) 277 { 278 if (!args.at(0).isObject()) 279 return throwError(exec, TypeError, "Properties can only be defined on Objects."); 280 if (!args.at(1).isObject()) 281 return throwError(exec, TypeError, "Property descriptor list must be an Object."); 282 return defineProperties(exec, asObject(args.at(0)), asObject(args.at(1))); 283 } 284 240 285 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.