本文整理汇总了C++中PropertyDescriptor::setWritable方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertyDescriptor::setWritable方法的具体用法?C++ PropertyDescriptor::setWritable怎么用?C++ PropertyDescriptor::setWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyDescriptor
的用法示例。
在下文中一共展示了PropertyDescriptor::setWritable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: objectConstructorFreeze
EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState* exec)
{
// 1. If Type(O) is not Object throw a TypeError exception.
JSValue obj = exec->argument(0);
if (!obj.isObject())
return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.freeze can only be called on Objects.")));
JSObject* object = asObject(obj);
if (isJSFinalObject(object) && !hasIndexedProperties(object->structure()->indexingType())) {
object->freeze(exec->vm());
return JSValue::encode(obj);
}
// 2. For each named own property name P of O,
PropertyNameArray properties(exec);
object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties);
PropertyNameArray::const_iterator end = properties.end();
for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
// a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P.
PropertyDescriptor desc;
if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc))
continue;
// b. If IsDataDescriptor(desc) is true, then
// i. If desc.[[Writable]] is true, set desc.[[Writable]] to false.
if (desc.isDataDescriptor())
desc.setWritable(false);
// c. If desc.[[Configurable]] is true, set desc.[[Configurable]] to false.
desc.setConfigurable(false);
// d. Call the [[DefineOwnProperty]] internal method of O with P, desc, and true as arguments.
object->methodTable()->defineOwnProperty(object, exec, *iter, desc, true);
if (exec->hadException())
return JSValue::encode(obj);
}
// 3. Set the [[Extensible]] internal property of O to false.
object->preventExtensions(exec->vm());
// 4. Return O.
return JSValue::encode(obj);
}
示例2: toPropertyDescriptor
// ES5 8.10.5 ToPropertyDescriptor
static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)
{
if (!in.isObject()) {
throwError(exec, createTypeError(exec, ASCIILiteral("Property description must be an object.")));
return false;
}
JSObject* description = asObject(in);
PropertySlot enumerableSlot(description);
if (description->getPropertySlot(exec, exec->propertyNames().enumerable, enumerableSlot)) {
desc.setEnumerable(enumerableSlot.getValue(exec, exec->propertyNames().enumerable).toBoolean(exec));
if (exec->hadException())
return false;
}
PropertySlot configurableSlot(description);
if (description->getPropertySlot(exec, exec->propertyNames().configurable, configurableSlot)) {
desc.setConfigurable(configurableSlot.getValue(exec, exec->propertyNames().configurable).toBoolean(exec));
if (exec->hadException())
return false;
}
JSValue value;
PropertySlot valueSlot(description);
if (description->getPropertySlot(exec, exec->propertyNames().value, valueSlot)) {
desc.setValue(valueSlot.getValue(exec, exec->propertyNames().value));
if (exec->hadException())
return false;
}
PropertySlot writableSlot(description);
if (description->getPropertySlot(exec, exec->propertyNames().writable, writableSlot)) {
desc.setWritable(writableSlot.getValue(exec, exec->propertyNames().writable).toBoolean(exec));
if (exec->hadException())
return false;
}
PropertySlot getSlot(description);
if (description->getPropertySlot(exec, exec->propertyNames().get, getSlot)) {
JSValue get = getSlot.getValue(exec, exec->propertyNames().get);
if (exec->hadException())
return false;
if (!get.isUndefined()) {
CallData callData;
if (getCallData(get, callData) == CallTypeNone) {
throwError(exec, createTypeError(exec, ASCIILiteral("Getter must be a function.")));
return false;
}
}
desc.setGetter(get);
}
PropertySlot setSlot(description);
if (description->getPropertySlot(exec, exec->propertyNames().set, setSlot)) {
JSValue set = setSlot.getValue(exec, exec->propertyNames().set);
if (exec->hadException())
return false;
if (!set.isUndefined()) {
CallData callData;
if (getCallData(set, callData) == CallTypeNone) {
throwError(exec, createTypeError(exec, ASCIILiteral("Setter must be a function.")));
return false;
}
}
desc.setSetter(set);
}
if (!desc.isAccessorDescriptor())
return true;
if (desc.value()) {
throwError(exec, createTypeError(exec, ASCIILiteral("Invalid property. 'value' present on property with getter or setter.")));
return false;
}
if (desc.writablePresent()) {
throwError(exec, createTypeError(exec, ASCIILiteral("Invalid property. 'writable' present on property with getter or setter.")));
return false;
}
return true;
}