本文整理汇总了C++中PropertyDescriptor类的典型用法代码示例。如果您正苦于以下问题:C++ PropertyDescriptor类的具体用法?C++ PropertyDescriptor怎么用?C++ PropertyDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PropertyDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createStrictModeCalleeIfNecessary
bool Arguments::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
bool isArrayIndex;
unsigned i = propertyName.toArrayIndex(isArrayIndex);
if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
if (i < d->numParameters) {
descriptor.setDescriptor(d->registers[d->firstParameterIndex + i].get(), None);
} else
descriptor.setDescriptor(d->extraArguments[i - d->numParameters].get(), None);
return true;
}
if (propertyName == exec->propertyNames().length && LIKELY(!d->overrodeLength)) {
descriptor.setDescriptor(jsNumber(d->numArguments), DontEnum);
return true;
}
if (propertyName == exec->propertyNames().callee && LIKELY(!d->overrodeCallee)) {
if (!d->isStrictMode) {
descriptor.setDescriptor(d->callee.get(), DontEnum);
return true;
}
createStrictModeCalleeIfNecessary(exec);
}
if (propertyName == exec->propertyNames().caller && d->isStrictMode)
createStrictModeCallerIfNecessary(exec);
return JSObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
}
示例2: getOwnPropertySlot
bool AJFunction::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
if (isHostFunction())
return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
if (propertyName == exec->propertyNames().prototype) {
PropertySlot slot;
getOwnPropertySlot(exec, propertyName, slot);
return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
}
if (propertyName == exec->propertyNames().arguments) {
descriptor.setDescriptor(exec->interpreter()->retrieveArguments(exec, this), ReadOnly | DontEnum | DontDelete);
return true;
}
if (propertyName == exec->propertyNames().length) {
descriptor.setDescriptor(jsNumber(exec, jsExecutable()->parameterCount()), ReadOnly | DontEnum | DontDelete);
return true;
}
if (propertyName == exec->propertyNames().caller) {
descriptor.setDescriptor(exec->interpreter()->retrieveCaller(exec, this), ReadOnly | DontEnum | DontDelete);
return true;
}
return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
}
示例3: length
bool JSArray::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
if (propertyName == exec->propertyNames().length) {
descriptor.setDescriptor(jsNumber(exec, length()), DontDelete | DontEnum);
return true;
}
bool isArrayIndex;
unsigned i = propertyName.toArrayIndex(&isArrayIndex);
if (isArrayIndex) {
if (i >= m_storage->m_length)
return false;
if (i < m_vectorLength) {
JSValue& value = m_storage->m_vector[i];
if (value) {
descriptor.setDescriptor(value, 0);
return true;
}
} else if (SparseArrayValueMap* map = m_storage->m_sparseValueMap) {
if (i >= MIN_SPARSE_ARRAY_INDEX) {
SparseArrayValueMap::iterator it = map->find(i);
if (it != map->end()) {
descriptor.setDescriptor(it->second, 0);
return true;
}
}
}
}
return JSObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
}
示例4: objectConstructorIsFrozen
EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(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.isFrozen can only be called on Objects.")));
JSObject* object = asObject(obj);
if (isJSFinalObject(object))
return JSValue::encode(jsBoolean(object->isFrozen(exec->vm())));
// 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, return false. c. If desc.[[Configurable]] is true, then return false.
if ((desc.isDataDescriptor() && desc.writable()) || desc.configurable())
return JSValue::encode(jsBoolean(false));
}
// 3. If the [[Extensible]] internal property of O is false, then return true.
// 4. Otherwise, return false.
return JSValue::encode(jsBoolean(!object->isExtensible()));
}
示例5: getOwnPropertyDescriptor
bool JSNPObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
{
JSNPObject* thisObject = jsCast<JSNPObject*>(object);
ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
if (!thisObject->m_npObject) {
throwInvalidAccessError(exec);
return false;
}
NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName);
// Calling NPClass::invoke will call into plug-in code, and there's no telling what the plug-in can do.
// (including destroying the plug-in). Because of this, we make sure to keep the plug-in alive until
// the call has finished.
NPRuntimeObjectMap::PluginProtector protector(thisObject->m_objectMap);
// First, check if the NPObject has a property with this name.
if (thisObject->m_npObject->_class->hasProperty && thisObject->m_npObject->_class->hasProperty(thisObject->m_npObject, npIdentifier)) {
PropertySlot slot;
slot.setCustom(thisObject, propertyGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete);
return true;
}
// Second, check if the NPObject has a method with this name.
if (thisObject->m_npObject->_class->hasMethod && thisObject->m_npObject->_class->hasMethod(thisObject->m_npObject, npIdentifier)) {
PropertySlot slot;
slot.setCustom(thisObject, methodGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly);
return true;
}
return false;
}
示例6: reflectObjectDefineProperty
// https://tc39.github.io/ecma262/#sec-reflect.defineproperty
EncodedJSValue JSC_HOST_CALL reflectObjectDefineProperty(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue target = exec->argument(0);
if (!target.isObject())
return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.defineProperty requires the first argument be an object")));
auto propertyName = exec->argument(1).toPropertyKey(exec);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
PropertyDescriptor descriptor;
bool success = toPropertyDescriptor(exec, exec->argument(2), descriptor);
ASSERT(!scope.exception() == success);
if (UNLIKELY(!success))
return encodedJSValue();
ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor()));
ASSERT(!scope.exception());
// Reflect.defineProperty should not throw an error when the defineOwnProperty operation fails.
bool shouldThrow = false;
JSObject* targetObject = asObject(target);
scope.release();
return JSValue::encode(jsBoolean(targetObject->methodTable(vm)->defineOwnProperty(targetObject, exec, propertyName, descriptor, shouldThrow)));
}
示例7: objectConstructorGetOwnPropertyDescriptor
EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec)
{
if (!exec->argument(0).isObject())
return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested property descriptor of a value that is not an object.")));
String propertyName = exec->argument(1).toString(exec)->value(exec);
if (exec->hadException())
return JSValue::encode(jsNull());
JSObject* object = asObject(exec->argument(0));
PropertyDescriptor descriptor;
if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, Identifier(exec, propertyName), descriptor))
return JSValue::encode(jsUndefined());
if (exec->hadException())
return JSValue::encode(jsUndefined());
JSObject* description = constructEmptyObject(exec);
if (!descriptor.isAccessorDescriptor()) {
description->putDirect(exec->vm(), exec->propertyNames().value, descriptor.value() ? descriptor.value() : jsUndefined(), 0);
description->putDirect(exec->vm(), exec->propertyNames().writable, jsBoolean(descriptor.writable()), 0);
} else {
ASSERT(descriptor.getter());
ASSERT(descriptor.setter());
description->putDirect(exec->vm(), exec->propertyNames().get, descriptor.getter(), 0);
description->putDirect(exec->vm(), exec->propertyNames().set, descriptor.setter(), 0);
}
description->putDirect(exec->vm(), exec->propertyNames().enumerable, jsBoolean(descriptor.enumerable()), 0);
description->putDirect(exec->vm(), exec->propertyNames().configurable, jsBoolean(descriptor.configurable()), 0);
return JSValue::encode(description);
}
示例8: getOwnPropertyDescriptor
bool JSNamedNodeMap::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
ASSERT_GC_OBJECT_INHERITS(this, &s_info);
JSValue proto = prototype();
if (proto.isObject() && static_cast<JSObject*>(asObject(proto))->hasProperty(exec, propertyName))
return false;
const HashEntry* entry = JSNamedNodeMapTable.entry(exec, propertyName);
if (entry) {
PropertySlot slot;
slot.setCustom(this, entry->propertyGetter());
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
}
bool ok;
unsigned index = propertyName.toUInt32(ok);
if (ok && index < static_cast<NamedNodeMap*>(impl())->length()) {
PropertySlot slot;
slot.setCustomIndex(this, index, indexGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly);
return true;
}
if (canGetItemsForName(exec, static_cast<NamedNodeMap*>(impl()), propertyName)) {
PropertySlot slot;
slot.setCustom(this, nameGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
return true;
}
return getStaticValueDescriptor<JSNamedNodeMap, Base>(exec, &JSNamedNodeMapTable, this, propertyName, descriptor);
}
示例9: ASSERT
bool Arguments::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
{
Arguments* thisObject = jsCast<Arguments*>(object);
unsigned i = propertyName.asIndex();
if (i < thisObject->d->numArguments && (!thisObject->d->deletedArguments || !thisObject->d->deletedArguments[i])) {
ASSERT(i < PropertyName::NotAnIndex);
descriptor.setDescriptor(thisObject->argument(i).get(), None);
return true;
}
if (propertyName == exec->propertyNames().length && LIKELY(!thisObject->d->overrodeLength)) {
descriptor.setDescriptor(jsNumber(thisObject->d->numArguments), DontEnum);
return true;
}
if (propertyName == exec->propertyNames().callee && LIKELY(!thisObject->d->overrodeCallee)) {
if (!thisObject->d->isStrictMode) {
descriptor.setDescriptor(thisObject->d->callee.get(), DontEnum);
return true;
}
thisObject->createStrictModeCalleeIfNecessary(exec);
}
if (propertyName == exec->propertyNames().caller && thisObject->d->isStrictMode)
thisObject->createStrictModeCallerIfNecessary(exec);
return JSObject::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
}
示例10: propertyIsEnumerable
bool JSObject::propertyIsEnumerable(ExecState* exec, const Identifier& propertyName) const
{
PropertyDescriptor descriptor;
if (!const_cast<JSObject*>(this)->getOwnPropertyDescriptor(exec, propertyName, descriptor))
return false;
return descriptor.enumerable();
}
示例11: SerializableNodeArray
void BaseEntity::SerializeProperties(IPropertyContainer *container, SerializableNodeObject *parent)
{
int count = container->GetNumProperties();
auto props = container->GetProperties();
SerializableNodeArray* nPropContainer = new SerializableNodeArray("properties");
for (int i = 0; i < count; ++i)
{
auto p = props[i];
PropertyDescriptor* desc = p->GetDescriptor();
if (desc->CanSerialize)
{
auto propObject = new SerializableNodeObject();
desc->Serialize(propObject);
propObject->AddChild(new SerializableProperty("Value", p->GetString().c_str()));
nPropContainer->AddChild(propObject);
}
}
parent->AddChild(nPropContainer);
}
示例12: objectProtoFuncDefineSetter
EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState* exec)
{
JSObject* thisObject = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
JSValue set = exec->argument(1);
CallData callData;
if (getCallData(set, callData) == CallTypeNone)
return throwVMError(exec, createTypeError(exec, ASCIILiteral("invalid setter usage")));
auto propertyName = exec->argument(0).toPropertyKey(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
PropertyDescriptor descriptor;
descriptor.setSetter(set);
descriptor.setEnumerable(true);
descriptor.setConfigurable(true);
bool shouldThrow = false;
thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
return JSValue::encode(jsUndefined());
}
示例13: getOwnPropertyDescriptor
bool JSCSSStyleDeclaration::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
ASSERT_GC_OBJECT_INHERITS(this, &s_info);
const HashEntry* entry = JSCSSStyleDeclarationTable.entry(exec, propertyName);
if (entry) {
PropertySlot slot;
slot.setCustom(this, entry->propertyGetter());
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
}
bool ok;
unsigned index = propertyName.toUInt32(ok);
if (ok && index < static_cast<CSSStyleDeclaration*>(impl())->length()) {
PropertySlot slot;
slot.setCustomIndex(this, index, indexGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly);
return true;
}
if (canGetItemsForName(exec, static_cast<CSSStyleDeclaration*>(impl()), propertyName)) {
PropertySlot slot;
slot.setCustom(this, nameGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
return true;
}
return getStaticValueDescriptor<JSCSSStyleDeclaration, Base>(exec, &JSCSSStyleDeclarationTable, this, propertyName, descriptor);
}
示例14: createStrictModeCalleeIfNecessary
void Arguments::createStrictModeCalleeIfNecessary(ExecState* exec)
{
if (d->overrodeCallee)
return;
d->overrodeCallee = true;
PropertyDescriptor descriptor;
descriptor.setAccessorDescriptor(globalObject()->throwTypeErrorGetterSetter(exec), DontEnum | DontDelete | Accessor);
methodTable()->defineOwnProperty(this, exec, exec->propertyNames().callee, descriptor, false);
}
示例15: defineProperties
static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* properties)
{
PropertyNameArray propertyNames(exec);
asObject(properties)->methodTable()->getOwnPropertyNames(asObject(properties), exec, propertyNames, ExcludeDontEnumProperties);
size_t numProperties = propertyNames.size();
Vector<PropertyDescriptor> descriptors;
MarkedArgumentBuffer markBuffer;
for (size_t i = 0; i < numProperties; i++) {
PropertySlot slot;
JSValue prop = properties->get(exec, propertyNames[i]);
if (exec->hadException())
return jsNull();
PropertyDescriptor descriptor;
if (!toPropertyDescriptor(exec, prop, descriptor))
return jsNull();
descriptors.append(descriptor);
// Ensure we mark all the values that we're accumulating
if (descriptor.isDataDescriptor() && descriptor.value())
markBuffer.append(descriptor.value());
if (descriptor.isAccessorDescriptor()) {
if (descriptor.getter())
markBuffer.append(descriptor.getter());
if (descriptor.setter())
markBuffer.append(descriptor.setter());
}
}
for (size_t i = 0; i < numProperties; i++) {
object->methodTable()->defineOwnProperty(object, exec, propertyNames[i], descriptors[i], true);
if (exec->hadException())
return jsNull();
}
return object;
}