本文整理汇总了C++中PropertyDescriptor::setGetter方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertyDescriptor::setGetter方法的具体用法?C++ PropertyDescriptor::setGetter怎么用?C++ PropertyDescriptor::setGetter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyDescriptor
的用法示例。
在下文中一共展示了PropertyDescriptor::setGetter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: objectProtoFuncDefineGetter
EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState* exec)
{
JSObject* thisObject = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
JSValue get = exec->argument(1);
CallData callData;
if (getCallData(get, callData) == CallTypeNone)
return throwVMError(exec, createTypeError(exec, ASCIILiteral("invalid getter usage")));
auto propertyName = exec->argument(0).toPropertyKey(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
PropertyDescriptor descriptor;
descriptor.setGetter(get);
descriptor.setEnumerable(true);
descriptor.setConfigurable(true);
bool shouldThrow = false;
thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
return JSValue::encode(jsUndefined());
}
示例2: finishCreation
void ReferencePrototype::finishCreation(VM& vm, JSGlobalObject* globalObject) {
Base::finishCreation(vm);
this->putDirectNativeFunction(vm, globalObject, vm.propertyNames->toString, 0, referenceProtoFuncToString, NoIntrinsic, DontEnum);
PropertyDescriptor descriptor;
descriptor.setEnumerable(true);
descriptor.setGetter(JSFunction::create(vm, globalObject, 0, WTF::emptyString(), &referenceProtoFuncGetValue));
descriptor.setSetter(JSFunction::create(vm, globalObject, 1, WTF::emptyString(), &referenceProtoFuncSetValue));
Base::defineOwnProperty(this, globalObject->globalExec(), vm.propertyNames->value, descriptor, false);
}
示例3: objectProtoFuncDefineGetter
EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState* exec)
{
JSObject* thisObject = exec->hostThisValue().toObject(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
JSValue get = exec->argument(1);
CallData callData;
if (getCallData(get, callData) == CallTypeNone)
return throwVMError(exec, createTypeError(exec, ASCIILiteral("invalid getter usage")));
PropertyDescriptor descriptor;
descriptor.setGetter(get);
descriptor.setEnumerable(true);
descriptor.setConfigurable(true);
thisObject->methodTable()->defineOwnProperty(thisObject, exec, Identifier(exec, exec->argument(0).toString(exec)->value(exec)), descriptor, false);
return JSValue::encode(jsUndefined());
}
示例4: 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;
}